@Test public void shouldSetBeginningBalanceToCurrentStockInHandIfAvailable() throws Exception { ProcessingPeriod processingPeriod = make(a(defaultProcessingPeriod, with(numberOfMonths, 3))); Rnr requisition = make(a(RequisitionBuilder.defaultRequisition, with(RequisitionBuilder.period, processingPeriod))); Integer nullInteger = null; requisition.setFullSupplyLineItems(asList(make(a(defaultRnrLineItem, with(productCode, "P121"), with(stockInHand, 56), with(beginningBalance, nullInteger))))); when(processingScheduleService.findM(requisition.getPeriod())).thenReturn(1); when(processingScheduleService.getNPreviousPeriodsInDescOrder(processingPeriod, 2)).thenReturn(emptyPeriodList); when(requisitionService.getNRnrLineItems("P121", requisition, 1, processingPeriod.getStartDate())).thenReturn(emptyLineItemList); Rnr filledRequisition = restRequisitionCalculator.setDefaultValues(requisition); assertThat(filledRequisition.getFullSupplyLineItems().get(0).getBeginningBalance(), is(56)); }
public Rnr setDefaultValues(Rnr requisition) { Integer M = processingScheduleService.findM(requisition.getPeriod()); List<ProcessingPeriod> nPreviousPeriods = processingScheduleService.getNPreviousPeriodsInDescOrder(requisition.getPeriod(), 2); Date trackingDate = requisition.getPeriod().getStartDate(); if (!nPreviousPeriods.isEmpty()) { trackingDate = M >= 3 ? nPreviousPeriods.get(0).getStartDate() : nPreviousPeriods.get(nPreviousPeriods.size() - 1).getStartDate(); } for (RnrLineItem rnrLineItem : requisition.getNonSkippedLineItems()) { setBeginningBalance(rnrLineItem, requisition, trackingDate); setQuantityReceived(rnrLineItem, requisition, trackingDate); } return requisition; }
RestRequisitionCalculator { public Rnr setDefaultValues(Rnr requisition) { Integer M = processingScheduleService.findM(requisition.getPeriod()); List<ProcessingPeriod> nPreviousPeriods = processingScheduleService.getNPreviousPeriodsInDescOrder(requisition.getPeriod(), 2); Date trackingDate = requisition.getPeriod().getStartDate(); if (!nPreviousPeriods.isEmpty()) { trackingDate = M >= 3 ? nPreviousPeriods.get(0).getStartDate() : nPreviousPeriods.get(nPreviousPeriods.size() - 1).getStartDate(); } for (RnrLineItem rnrLineItem : requisition.getNonSkippedLineItems()) { setBeginningBalance(rnrLineItem, requisition, trackingDate); setQuantityReceived(rnrLineItem, requisition, trackingDate); } return requisition; } }
RestRequisitionCalculator { public Rnr setDefaultValues(Rnr requisition) { Integer M = processingScheduleService.findM(requisition.getPeriod()); List<ProcessingPeriod> nPreviousPeriods = processingScheduleService.getNPreviousPeriodsInDescOrder(requisition.getPeriod(), 2); Date trackingDate = requisition.getPeriod().getStartDate(); if (!nPreviousPeriods.isEmpty()) { trackingDate = M >= 3 ? nPreviousPeriods.get(0).getStartDate() : nPreviousPeriods.get(nPreviousPeriods.size() - 1).getStartDate(); } for (RnrLineItem rnrLineItem : requisition.getNonSkippedLineItems()) { setBeginningBalance(rnrLineItem, requisition, trackingDate); setQuantityReceived(rnrLineItem, requisition, trackingDate); } return requisition; }  }
RestRequisitionCalculator { public Rnr setDefaultValues(Rnr requisition) { Integer M = processingScheduleService.findM(requisition.getPeriod()); List<ProcessingPeriod> nPreviousPeriods = processingScheduleService.getNPreviousPeriodsInDescOrder(requisition.getPeriod(), 2); Date trackingDate = requisition.getPeriod().getStartDate(); if (!nPreviousPeriods.isEmpty()) { trackingDate = M >= 3 ? nPreviousPeriods.get(0).getStartDate() : nPreviousPeriods.get(nPreviousPeriods.size() - 1).getStartDate(); } for (RnrLineItem rnrLineItem : requisition.getNonSkippedLineItems()) { setBeginningBalance(rnrLineItem, requisition, trackingDate); setQuantityReceived(rnrLineItem, requisition, trackingDate); } return requisition; }  void validatePeriod(Facility reportingFacility, Program reportingProgram); void validateCustomPeriod(Facility reportingFacility, Program reportingProgram, ProcessingPeriod period, Long userId); void validateProducts(List<RnrLineItem> products, Rnr savedRequisition); Rnr setDefaultValues(Rnr requisition); }
RestRequisitionCalculator { public Rnr setDefaultValues(Rnr requisition) { Integer M = processingScheduleService.findM(requisition.getPeriod()); List<ProcessingPeriod> nPreviousPeriods = processingScheduleService.getNPreviousPeriodsInDescOrder(requisition.getPeriod(), 2); Date trackingDate = requisition.getPeriod().getStartDate(); if (!nPreviousPeriods.isEmpty()) { trackingDate = M >= 3 ? nPreviousPeriods.get(0).getStartDate() : nPreviousPeriods.get(nPreviousPeriods.size() - 1).getStartDate(); } for (RnrLineItem rnrLineItem : requisition.getNonSkippedLineItems()) { setBeginningBalance(rnrLineItem, requisition, trackingDate); setQuantityReceived(rnrLineItem, requisition, trackingDate); } return requisition; }  void validatePeriod(Facility reportingFacility, Program reportingProgram); void validateCustomPeriod(Facility reportingFacility, Program reportingProgram, ProcessingPeriod period, Long userId); void validateProducts(List<RnrLineItem> products, Rnr savedRequisition); Rnr setDefaultValues(Rnr requisition);  }