@Test public void shouldPreventInversionDateOrTimeInsert() { String signature = "signature"; presenter.getInventoryViewModelList().addAll(getStockCardViewModels()); when(stockMovementRepositoryMock.queryEachStockCardNewestMovement()).thenReturn(getInversionDateOrTimeStockMovementItem()); TestSubscriber<Object> subscriber = new TestSubscriber<>(); Subscription subscription = presenter.doInventory(signature).subscribe(subscriber); subscriber.awaitTerminalEvent(); presenter.subscriptions.add(subscription); assertThat(subscriber.getOnErrorEvents().get(0).getMessage(), is(LMISTestApp.getContext().getResources().getString(R.string.msg_invalid_stock_movement))); }
public Observable<Object> doInventory(final String sign) { return Observable.create(subscriber -> { try { List<StockMovementItem> newestEachMovementItems = movementRepository.queryEachStockCardNewestMovement(); Date now = new Date(); for (InventoryViewModel viewModel : inventoryViewModelList) { viewModel.setSignature(sign); StockCard stockCard = viewModel.getStockCard(); stockCard.setStockOnHand(viewModel.getLotListQuantityTotalAmount()); if (stockCard.getStockOnHand() == 0) { stockCard.setExpireDates(""); } if (!hasInversionDateBetweenMovementAndDB(newestEachMovementItems, now)) { stockRepository.addStockMovementAndUpdateStockCard(calculateAdjustment(viewModel, stockCard)); } else { throw new LMISException(LMISApp.getContext().getString(R.string.msg_invalid_stock_movement)); } } inventoryRepository.clearDraft(); sharedPreferenceMgr.setLatestPhysicInventoryTime(DateUtil.formatDate(new Date(), DateUtil.DATE_TIME_FORMAT)); saveInventoryDate(); subscriber.onNext(null); subscriber.onCompleted(); } catch (LMISException e) { subscriber.onError(e); new LMISException(e, "doInventory").reportToFabric(); } }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()); }
PhysicalInventoryPresenter extends InventoryPresenter { public Observable<Object> doInventory(final String sign) { return Observable.create(subscriber -> { try { List<StockMovementItem> newestEachMovementItems = movementRepository.queryEachStockCardNewestMovement(); Date now = new Date(); for (InventoryViewModel viewModel : inventoryViewModelList) { viewModel.setSignature(sign); StockCard stockCard = viewModel.getStockCard(); stockCard.setStockOnHand(viewModel.getLotListQuantityTotalAmount()); if (stockCard.getStockOnHand() == 0) { stockCard.setExpireDates(""); } if (!hasInversionDateBetweenMovementAndDB(newestEachMovementItems, now)) { stockRepository.addStockMovementAndUpdateStockCard(calculateAdjustment(viewModel, stockCard)); } else { throw new LMISException(LMISApp.getContext().getString(R.string.msg_invalid_stock_movement)); } } inventoryRepository.clearDraft(); sharedPreferenceMgr.setLatestPhysicInventoryTime(DateUtil.formatDate(new Date(), DateUtil.DATE_TIME_FORMAT)); saveInventoryDate(); subscriber.onNext(null); subscriber.onCompleted(); } catch (LMISException e) { subscriber.onError(e); new LMISException(e, "doInventory").reportToFabric(); } }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()); } }
PhysicalInventoryPresenter extends InventoryPresenter { public Observable<Object> doInventory(final String sign) { return Observable.create(subscriber -> { try { List<StockMovementItem> newestEachMovementItems = movementRepository.queryEachStockCardNewestMovement(); Date now = new Date(); for (InventoryViewModel viewModel : inventoryViewModelList) { viewModel.setSignature(sign); StockCard stockCard = viewModel.getStockCard(); stockCard.setStockOnHand(viewModel.getLotListQuantityTotalAmount()); if (stockCard.getStockOnHand() == 0) { stockCard.setExpireDates(""); } if (!hasInversionDateBetweenMovementAndDB(newestEachMovementItems, now)) { stockRepository.addStockMovementAndUpdateStockCard(calculateAdjustment(viewModel, stockCard)); } else { throw new LMISException(LMISApp.getContext().getString(R.string.msg_invalid_stock_movement)); } } inventoryRepository.clearDraft(); sharedPreferenceMgr.setLatestPhysicInventoryTime(DateUtil.formatDate(new Date(), DateUtil.DATE_TIME_FORMAT)); saveInventoryDate(); subscriber.onNext(null); subscriber.onCompleted(); } catch (LMISException e) { subscriber.onError(e); new LMISException(e, "doInventory").reportToFabric(); } }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()); }  }
PhysicalInventoryPresenter extends InventoryPresenter { public Observable<Object> doInventory(final String sign) { return Observable.create(subscriber -> { try { List<StockMovementItem> newestEachMovementItems = movementRepository.queryEachStockCardNewestMovement(); Date now = new Date(); for (InventoryViewModel viewModel : inventoryViewModelList) { viewModel.setSignature(sign); StockCard stockCard = viewModel.getStockCard(); stockCard.setStockOnHand(viewModel.getLotListQuantityTotalAmount()); if (stockCard.getStockOnHand() == 0) { stockCard.setExpireDates(""); } if (!hasInversionDateBetweenMovementAndDB(newestEachMovementItems, now)) { stockRepository.addStockMovementAndUpdateStockCard(calculateAdjustment(viewModel, stockCard)); } else { throw new LMISException(LMISApp.getContext().getString(R.string.msg_invalid_stock_movement)); } } inventoryRepository.clearDraft(); sharedPreferenceMgr.setLatestPhysicInventoryTime(DateUtil.formatDate(new Date(), DateUtil.DATE_TIME_FORMAT)); saveInventoryDate(); subscriber.onNext(null); subscriber.onCompleted(); } catch (LMISException e) { subscriber.onError(e); new LMISException(e, "doInventory").reportToFabric(); } }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()); }  @Override Observable<List<InventoryViewModel>> loadInventory(); Observable<Object> saveDraftInventoryObservable(); Observable<Object> doInventory(final String sign); void updateAvgMonthlyConsumption(); int getCompleteCount(); }
PhysicalInventoryPresenter extends InventoryPresenter { public Observable<Object> doInventory(final String sign) { return Observable.create(subscriber -> { try { List<StockMovementItem> newestEachMovementItems = movementRepository.queryEachStockCardNewestMovement(); Date now = new Date(); for (InventoryViewModel viewModel : inventoryViewModelList) { viewModel.setSignature(sign); StockCard stockCard = viewModel.getStockCard(); stockCard.setStockOnHand(viewModel.getLotListQuantityTotalAmount()); if (stockCard.getStockOnHand() == 0) { stockCard.setExpireDates(""); } if (!hasInversionDateBetweenMovementAndDB(newestEachMovementItems, now)) { stockRepository.addStockMovementAndUpdateStockCard(calculateAdjustment(viewModel, stockCard)); } else { throw new LMISException(LMISApp.getContext().getString(R.string.msg_invalid_stock_movement)); } } inventoryRepository.clearDraft(); sharedPreferenceMgr.setLatestPhysicInventoryTime(DateUtil.formatDate(new Date(), DateUtil.DATE_TIME_FORMAT)); saveInventoryDate(); subscriber.onNext(null); subscriber.onCompleted(); } catch (LMISException e) { subscriber.onError(e); new LMISException(e, "doInventory").reportToFabric(); } }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()); }  @Override Observable<List<InventoryViewModel>> loadInventory(); Observable<Object> saveDraftInventoryObservable(); Observable<Object> doInventory(final String sign); void updateAvgMonthlyConsumption(); int getCompleteCount();  }