@Test public void shouldListLastFiveStockMovementsOrderByDateInDescOrder() throws Exception { StockCard stockCard = saveStockCardWithOneMovement(stockRepository, productRepository); createMovementItem(MovementReasonManager.MovementType.PHYSICAL_INVENTORY, 1000, stockCard, DateUtil.parseString("2015-12-12", DateUtil.DB_DATE_FORMAT), DateUtil.parseString("2015-12-11", DateUtil.DB_DATE_FORMAT), false); createMovementItem(MovementReasonManager.MovementType.PHYSICAL_INVENTORY, 1001, stockCard, DateUtil.parseString("2015-12-13", DateUtil.DB_DATE_FORMAT), DateUtil.parseString("2015-12-12", DateUtil.DB_DATE_FORMAT), false); createMovementItem(MovementReasonManager.MovementType.PHYSICAL_INVENTORY, 1002, stockCard, DateUtil.parseString("2015-12-14", DateUtil.DB_DATE_FORMAT), DateUtil.parseString("2015-12-13", DateUtil.DB_DATE_FORMAT), false); List<StockMovementItem> stockMovementItems = stockMovementRepository.listLastFiveStockMovements(stockCard.getId()); assertEquals(4, stockMovementItems.size()); assertEquals(stockCard.getStockMovementItemsWrapper().get(0), stockMovementItems.get(0)); assertEquals(stockCard.getStockMovementItemsWrapper().get(1), stockMovementItems.get(1)); assertEquals(stockCard.getStockMovementItemsWrapper().get(2), stockMovementItems.get(2)); assertEquals(stockCard.getStockMovementItemsWrapper().get(3), stockMovementItems.get(3)); }
public List<StockMovementItem> listLastFiveStockMovements(final long stockCardId) throws LMISException { return dbUtil.withDao(StockMovementItem.class, dao -> Lists.reverse(dao.queryBuilder().limit(5L) .orderBy("movementDate", false) .orderBy("createdTime", false) .orderBy("id", false) .where().eq("stockCard_id", stockCardId).query())); }
StockMovementRepository { public List<StockMovementItem> listLastFiveStockMovements(final long stockCardId) throws LMISException { return dbUtil.withDao(StockMovementItem.class, dao -> Lists.reverse(dao.queryBuilder().limit(5L) .orderBy("movementDate", false) .orderBy("createdTime", false) .orderBy("id", false) .where().eq("stockCard_id", stockCardId).query())); } }
StockMovementRepository { public List<StockMovementItem> listLastFiveStockMovements(final long stockCardId) throws LMISException { return dbUtil.withDao(StockMovementItem.class, dao -> Lists.reverse(dao.queryBuilder().limit(5L) .orderBy("movementDate", false) .orderBy("createdTime", false) .orderBy("id", false) .where().eq("stockCard_id", stockCardId).query())); } @Inject  StockMovementRepository(Context context); }
StockMovementRepository { public List<StockMovementItem> listLastFiveStockMovements(final long stockCardId) throws LMISException { return dbUtil.withDao(StockMovementItem.class, dao -> Lists.reverse(dao.queryBuilder().limit(5L) .orderBy("movementDate", false) .orderBy("createdTime", false) .orderBy("id", false) .where().eq("stockCard_id", stockCardId).query())); } @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 List<StockMovementItem> listLastFiveStockMovements(final long stockCardId) throws LMISException { return dbUtil.withDao(StockMovementItem.class, dao -> Lists.reverse(dao.queryBuilder().limit(5L) .orderBy("movementDate", false) .orderBy("createdTime", false) .orderBy("id", false) .where().eq("stockCard_id", stockCardId).query())); } @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);  }