@Test public void shouldPopulateAllLotQuantitiesAndCalculateNewSOHForStockItem() throws ParseException { LotMovementViewModel lotMovementViewModel1 = new LotMovementViewModel("ABC", "Dec 2016", "10", MovementReasonManager.MovementType.ISSUE); lotMovementViewModel1.setQuantity("10"); LotMovementViewModel lotMovementViewModel2 = new LotMovementViewModel("DEF", "Nov 2016", "20", MovementReasonManager.MovementType.ISSUE); lotMovementViewModel2.setQuantity("15"); LotMovementViewModel lotMovementViewModel3 = new LotMovementViewModel("HIJ", "Oct 2016", "30", MovementReasonManager.MovementType.ISSUE); lotMovementViewModel3.setQuantity("5"); List<LotMovementViewModel> lotMovementViewModelList = newArrayList(lotMovementViewModel1, lotMovementViewModel2, lotMovementViewModel3); StockCard stockCard = StockCardBuilder.buildStockCard(); StockMovementItem stockMovementItem = new StockMovementItemBuilder().withMovementDate("2016-11-30").withStockOnHand(100).build(); stockMovementItem.setStockCard(stockCard); stockMovementItem.populateLotQuantitiesAndCalculateNewSOH(lotMovementViewModelList, MovementReasonManager.MovementType.ISSUE); assertThat(stockMovementItem.getStockOnHand(), is(70L)); assertThat(stockMovementItem.getMovementQuantity(), is(30L)); }
public void populateLotQuantitiesAndCalculateNewSOH(List<LotMovementViewModel> lotMovementViewModelList, MovementReasonManager.MovementType movementType) { final StockMovementItem stockMovementItem = this; if (!lotMovementViewModelList.isEmpty()) { long movementQuantity = 0; for (LotMovementViewModel lotMovementViewModel : lotMovementViewModelList) { if (!StringUtils.isBlank(lotMovementViewModel.getQuantity())) { movementQuantity += Long.parseLong(lotMovementViewModel.getQuantity()); } } setMovementQuantity(movementQuantity); if (isNegativeMovement()) { setStockOnHand(getStockOnHand() - movementQuantity); } else { setStockOnHand(getStockOnHand() + movementQuantity); } setLotMovementItemListWrapper(FluentIterable.from(lotMovementViewModelList) .transform(lotMovementViewModel -> { LotMovementItem lotItem = lotMovementViewModel.convertViewToModel(getStockCard().getProduct()); lotItem.setStockMovementItemAndUpdateMovementQuantity(stockMovementItem); return lotItem; }).toList()); } }
StockMovementItem extends BaseModel { public void populateLotQuantitiesAndCalculateNewSOH(List<LotMovementViewModel> lotMovementViewModelList, MovementReasonManager.MovementType movementType) { final StockMovementItem stockMovementItem = this; if (!lotMovementViewModelList.isEmpty()) { long movementQuantity = 0; for (LotMovementViewModel lotMovementViewModel : lotMovementViewModelList) { if (!StringUtils.isBlank(lotMovementViewModel.getQuantity())) { movementQuantity += Long.parseLong(lotMovementViewModel.getQuantity()); } } setMovementQuantity(movementQuantity); if (isNegativeMovement()) { setStockOnHand(getStockOnHand() - movementQuantity); } else { setStockOnHand(getStockOnHand() + movementQuantity); } setLotMovementItemListWrapper(FluentIterable.from(lotMovementViewModelList) .transform(lotMovementViewModel -> { LotMovementItem lotItem = lotMovementViewModel.convertViewToModel(getStockCard().getProduct()); lotItem.setStockMovementItemAndUpdateMovementQuantity(stockMovementItem); return lotItem; }).toList()); } } }
StockMovementItem extends BaseModel { public void populateLotQuantitiesAndCalculateNewSOH(List<LotMovementViewModel> lotMovementViewModelList, MovementReasonManager.MovementType movementType) { final StockMovementItem stockMovementItem = this; if (!lotMovementViewModelList.isEmpty()) { long movementQuantity = 0; for (LotMovementViewModel lotMovementViewModel : lotMovementViewModelList) { if (!StringUtils.isBlank(lotMovementViewModel.getQuantity())) { movementQuantity += Long.parseLong(lotMovementViewModel.getQuantity()); } } setMovementQuantity(movementQuantity); if (isNegativeMovement()) { setStockOnHand(getStockOnHand() - movementQuantity); } else { setStockOnHand(getStockOnHand() + movementQuantity); } setLotMovementItemListWrapper(FluentIterable.from(lotMovementViewModelList) .transform(lotMovementViewModel -> { LotMovementItem lotItem = lotMovementViewModel.convertViewToModel(getStockCard().getProduct()); lotItem.setStockMovementItemAndUpdateMovementQuantity(stockMovementItem); return lotItem; }).toList()); } } StockMovementItem(StockCard stockCard, InventoryViewModel model);  StockMovementItem(StockCard stockCard, InventoryViewModel model, boolean fromInitialInventory);  StockMovementItem(StockCard stockCard); }
StockMovementItem extends BaseModel { public void populateLotQuantitiesAndCalculateNewSOH(List<LotMovementViewModel> lotMovementViewModelList, MovementReasonManager.MovementType movementType) { final StockMovementItem stockMovementItem = this; if (!lotMovementViewModelList.isEmpty()) { long movementQuantity = 0; for (LotMovementViewModel lotMovementViewModel : lotMovementViewModelList) { if (!StringUtils.isBlank(lotMovementViewModel.getQuantity())) { movementQuantity += Long.parseLong(lotMovementViewModel.getQuantity()); } } setMovementQuantity(movementQuantity); if (isNegativeMovement()) { setStockOnHand(getStockOnHand() - movementQuantity); } else { setStockOnHand(getStockOnHand() + movementQuantity); } setLotMovementItemListWrapper(FluentIterable.from(lotMovementViewModelList) .transform(lotMovementViewModel -> { LotMovementItem lotItem = lotMovementViewModel.convertViewToModel(getStockCard().getProduct()); lotItem.setStockMovementItemAndUpdateMovementQuantity(stockMovementItem); return lotItem; }).toList()); } } StockMovementItem(StockCard stockCard, InventoryViewModel model);  StockMovementItem(StockCard stockCard, InventoryViewModel model, boolean fromInitialInventory);  StockMovementItem(StockCard stockCard); boolean isPositiveMovement(); boolean isNegativeMovement(); Period getMovementPeriod(); long calculatePreviousSOH(); List<LotMovementItem> getLotMovementItemListWrapper(); List<LotMovementItem> getNewAddedLotMovementItemListWrapper(); void populateLotQuantitiesAndCalculateNewSOH(List<LotMovementViewModel> lotMovementViewModelList,
                                                        MovementReasonManager.MovementType movementType); void populateLotAndResetStockOnHandOfLotAccordingPhysicalAdjustment(List<LotMovementViewModel> existingLotMovementList,
                                                                               List<LotMovementViewModel> newAddedLotMovementList); @Override String toString(); }
StockMovementItem extends BaseModel { public void populateLotQuantitiesAndCalculateNewSOH(List<LotMovementViewModel> lotMovementViewModelList, MovementReasonManager.MovementType movementType) { final StockMovementItem stockMovementItem = this; if (!lotMovementViewModelList.isEmpty()) { long movementQuantity = 0; for (LotMovementViewModel lotMovementViewModel : lotMovementViewModelList) { if (!StringUtils.isBlank(lotMovementViewModel.getQuantity())) { movementQuantity += Long.parseLong(lotMovementViewModel.getQuantity()); } } setMovementQuantity(movementQuantity); if (isNegativeMovement()) { setStockOnHand(getStockOnHand() - movementQuantity); } else { setStockOnHand(getStockOnHand() + movementQuantity); } setLotMovementItemListWrapper(FluentIterable.from(lotMovementViewModelList) .transform(lotMovementViewModel -> { LotMovementItem lotItem = lotMovementViewModel.convertViewToModel(getStockCard().getProduct()); lotItem.setStockMovementItemAndUpdateMovementQuantity(stockMovementItem); return lotItem; }).toList()); } } StockMovementItem(StockCard stockCard, InventoryViewModel model);  StockMovementItem(StockCard stockCard, InventoryViewModel model, boolean fromInitialInventory);  StockMovementItem(StockCard stockCard); boolean isPositiveMovement(); boolean isNegativeMovement(); Period getMovementPeriod(); long calculatePreviousSOH(); List<LotMovementItem> getLotMovementItemListWrapper(); List<LotMovementItem> getNewAddedLotMovementItemListWrapper(); void populateLotQuantitiesAndCalculateNewSOH(List<LotMovementViewModel> lotMovementViewModelList,
                                                        MovementReasonManager.MovementType movementType); void populateLotAndResetStockOnHandOfLotAccordingPhysicalAdjustment(List<LotMovementViewModel> existingLotMovementList,
                                                                               List<LotMovementViewModel> newAddedLotMovementList); @Override String toString();  }