@Test public void shouldQueryEarliestStockMovementItemCreatedTimeByProgram() throws Exception { Program mmia = new ProgramBuilder().setProgramCode("MMIA").build(); Program via = new ProgramBuilder().setProgramCode("VIA").build(); programRepository.createOrUpdate(mmia); programRepository.createOrUpdate(via); Product mmiaProduct = new ProductBuilder().setCode("B1").build(); productRepository.createOrUpdate(mmiaProduct); Product viaProduct = new ProductBuilder().setCode("A1").build(); productRepository.createOrUpdate(viaProduct); ArrayList<ProductProgram> productPrograms = new ArrayList<>(); ProductProgram viaProductProgram = new ProductProgram(); viaProductProgram.setProductCode(viaProduct.getCode()); viaProductProgram.setProgramCode(via.getProgramCode()); viaProductProgram.setActive(true); productPrograms.add(viaProductProgram); ProductProgram mmiaProductProgram = new ProductProgram(); mmiaProductProgram.setProductCode(viaProduct.getCode()); mmiaProductProgram.setProgramCode(via.getProgramCode()); mmiaProductProgram.setActive(true); productPrograms.add(mmiaProductProgram); productProgramRepository.batchSave(productPrograms); StockCard stockCard = new StockCard(); stockCard.setProduct(mmiaProduct); stockRepository.createOrUpdate(stockCard); StockCard stockCard2 = new StockCard(); stockCard2.setProduct(viaProduct); stockRepository.createOrUpdate(stockCard2); createMovementItem(ISSUE, 100, stockCard, new DateTime("2017-01-01").toDate(), new DateTime("2017-01-01").toDate(), false); createMovementItem(ISSUE, 100, stockCard2, new DateTime("2018-01-01").toDate(), new DateTime("2018-01-01").toDate(), false); DateTime dateTime = new DateTime("2018-01-01"); Date expectedDate = new DateTime().withDate(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth()).toDate(); createMovementItem(ISSUE, 100, stockCard2, new DateTime("2018-03-02").toDate(), new DateTime("2018-03-02").toDate(), false); Date earliestDate = stockMovementRepository.queryEarliestStockMovementDateByProgram(via.getProgramCode()); Assert.assertThat(DateUtil.cutTimeStamp(new DateTime(earliestDate)), is(DateUtil.cutTimeStamp(new DateTime(expectedDate)))); }
public Date queryEarliestStockMovementDateByProgram(final String programCode) { Date earliestDate = null; for (String movementDate : queryStockMovementDatesByProgram(programCode)) { Date date = DateUtil.parseString(movementDate, DateUtil.DB_DATE_FORMAT); if (earliestDate == null || (date != null && date.before(earliestDate))) { earliestDate = date; } } return earliestDate; }
StockMovementRepository { public Date queryEarliestStockMovementDateByProgram(final String programCode) { Date earliestDate = null; for (String movementDate : queryStockMovementDatesByProgram(programCode)) { Date date = DateUtil.parseString(movementDate, DateUtil.DB_DATE_FORMAT); if (earliestDate == null || (date != null && date.before(earliestDate))) { earliestDate = date; } } return earliestDate; } }
StockMovementRepository { public Date queryEarliestStockMovementDateByProgram(final String programCode) { Date earliestDate = null; for (String movementDate : queryStockMovementDatesByProgram(programCode)) { Date date = DateUtil.parseString(movementDate, DateUtil.DB_DATE_FORMAT); if (earliestDate == null || (date != null && date.before(earliestDate))) { earliestDate = date; } } return earliestDate; } @Inject  StockMovementRepository(Context context); }
StockMovementRepository { public Date queryEarliestStockMovementDateByProgram(final String programCode) { Date earliestDate = null; for (String movementDate : queryStockMovementDatesByProgram(programCode)) { Date date = DateUtil.parseString(movementDate, DateUtil.DB_DATE_FORMAT); if (earliestDate == null || (date != null && date.before(earliestDate))) { earliestDate = date; } } return earliestDate; } @Inject  StockMovementRepository(Context context); List<StockMovementItem> listUnSynced(); void batchCreateStockMovementItemAndLotItems(final StockMovementItem stockMovementItem); void batchCreateOrUpdateStockMovementsAndLotMovements(final List<StockMovementItem> stockMovementItems); StockMovementItem getFirstStockMovement(); List<String> queryStockMovementDatesByProgram(final String programCode); Date queryEarliestStockMovementDateByProgram(final String programCode); StockMovementItem queryFirstStockMovementByStockCardId(final long stockCardId); List<StockMovementItem> queryStockMovementHistory(final long stockCardId, final long startIndex, final long maxRows); List<StockMovementItem> queryStockItemsByCreatedDate(final long stockCardId, final Date periodBeginDate, final Date periodEndDate); List<StockMovementItem> queryStockMovementsByMovementDate(final long stockCardId, final Date startDate, final Date endDate); List<StockMovementItem> listLastFiveStockMovements(final long stockCardId); List<StockMovementItem> listLastTwoStockMovements(final long stockCardId); List<StockMovementItem> queryMovementByStockCardId(final long stockCardId); List<StockMovementItem> queryEachStockCardNewestMovement(); void deleteStockMovementItems(final StockCard stockCard); }
StockMovementRepository { public Date queryEarliestStockMovementDateByProgram(final String programCode) { Date earliestDate = null; for (String movementDate : queryStockMovementDatesByProgram(programCode)) { Date date = DateUtil.parseString(movementDate, DateUtil.DB_DATE_FORMAT); if (earliestDate == null || (date != null && date.before(earliestDate))) { earliestDate = date; } } return earliestDate; } @Inject  StockMovementRepository(Context context); List<StockMovementItem> listUnSynced(); void batchCreateStockMovementItemAndLotItems(final StockMovementItem stockMovementItem); void batchCreateOrUpdateStockMovementsAndLotMovements(final List<StockMovementItem> stockMovementItems); StockMovementItem getFirstStockMovement(); List<String> queryStockMovementDatesByProgram(final String programCode); Date queryEarliestStockMovementDateByProgram(final String programCode); StockMovementItem queryFirstStockMovementByStockCardId(final long stockCardId); List<StockMovementItem> queryStockMovementHistory(final long stockCardId, final long startIndex, final long maxRows); List<StockMovementItem> queryStockItemsByCreatedDate(final long stockCardId, final Date periodBeginDate, final Date periodEndDate); List<StockMovementItem> queryStockMovementsByMovementDate(final long stockCardId, final Date startDate, final Date endDate); List<StockMovementItem> listLastFiveStockMovements(final long stockCardId); List<StockMovementItem> listLastTwoStockMovements(final long stockCardId); List<StockMovementItem> queryMovementByStockCardId(final long stockCardId); List<StockMovementItem> queryEachStockCardNewestMovement(); void deleteStockMovementItems(final StockCard stockCard);  }