RequisitionPeriodService { public Period generateNextPeriod(String programCode, Date physicalInventoryDate) throws LMISException { return generateNextPeriod(programCode, physicalInventoryDate, reportTypeFormRepository.getReportType(programCode)); }  Period generateNextPeriod(String programCode, Date physicalInventoryDate); Period generateNextPeriod(String programCode, Date physicalInventoryDate, ReportTypeForm typeForm); Period generateNextPeriod(List<RnRForm> rnRForms, String programCode, Date physicalInventoryDate); boolean hasMissedPeriod(String programCode); boolean hasMissedPeriod(String programCode, ReportTypeForm reportTypeForm); int getMissedPeriodOffsetMonth(String programCode); int getMissedPeriodOffsetMonth(String programCode, ReportTypeForm typeForm); int getIncompletePeriodOffsetMonth(String programCode); DateTime getCurrentMonthInventoryBeginDate();  }
@Test public void shouldGeneratePeriodWithPreviousRnrEndDateAsBeginAndNextMonthAsEndDate() throws Exception { RnRForm previousRnrForm = new RnRForm(); previousRnrForm.setProgram(programMMIA); previousRnrForm.setPeriodEnd(DateUtil.parseString("2020-10-18", DateUtil.DB_DATE_FORMAT)); DateTime dateTime = new DateTime(previousRnrForm.getPeriodEnd()).plusMonths(1); DateTime expectedPeriodEnd = DateUtil.cutTimeStamp(dateTime.withDate(dateTime.getYear(), dateTime.getMonthOfYear(), Period.END_DAY)); when(mockRnrFormRepository.listInclude(any(), anyString(), any(ReportTypeForm.class))).thenReturn(newArrayList(previousRnrForm)); Period period = requisitionPeriodService.generateNextPeriod(programMMIA.getProgramCode(), null); assertThat(period.getBegin().toDate(), is(previousRnrForm.getPeriodEnd())); assertThat(new DateTime(period.getEnd()).getMonthOfYear(), is(11)); assertThat(period.getEnd(), is(expectedPeriodEnd)); }
@Test @Ignore public void shouldGeneratePeriodOfJan21ToFebWhenRnrNotExists() throws Exception { when(mockStockMovementRepository.queryEarliestStockMovementDateByProgram(anyString())).thenReturn(new DateTime("2016-02-17").toDate()); when(mockProgramRepository.queryByCode(anyString())).thenReturn(programMMIA); ReportTypeForm reportTypeForm = new ReportTypeFormBuilder(). setActive(true). setCode(Constants.MMIA_REPORT). setName(Constants.MMIA_PROGRAM_CODE). setStartTime(new DateTime(DateUtil.parseString("2015-01-01", DateUtil.DB_DATE_FORMAT)).toDate()). build(); when(mockReportTypeFormRepository.queryByCode(Constants.MMIA_REPORT)) .thenReturn(reportTypeForm); when(mockReportTypeFormRepository.getReportType(anyString())).thenReturn(reportTypeForm); Period period = requisitionPeriodService.generateNextPeriod(programMMIA.getProgramCode(), null); assertThat(period.getBegin(), is(new DateTime("2016-01-21"))); assertThat(new DateTime(period.getEnd()).getMonthOfYear(), is(2)); }
@Test @Ignore public void shouldGeneratePeriodOfFeb18ToMarWhenRnrNotExists() throws Exception { when(mockStockMovementRepository.queryEarliestStockMovementDateByProgram(anyString())).thenReturn(DateUtil.parseString("2016-02-18 13:00:00", DateUtil.DATE_TIME_FORMAT)); Period period = requisitionPeriodService.generateNextPeriod(programMMIA.getProgramCode(), null); assertThat(period.getBegin(), is(new DateTime(DateUtil.parseString("2016-02-18 00:00:00", DateUtil.DATE_TIME_FORMAT)))); assertThat(new DateTime(period.getEnd()).getMonthOfYear(), is(3)); }
@Test @Ignore public void shouldGeneratePeriodOfFeb21ToMarWhenRnrNotExists() throws Exception { when(mockStockMovementRepository.queryEarliestStockMovementDateByProgram(anyString())).thenReturn(new DateTime("2016-02-26").toDate()); Period period = requisitionPeriodService.generateNextPeriod(programMMIA.getProgramCode(), null); assertThat(period.getBegin(), is(new DateTime("2016-02-21"))); assertThat(new DateTime(period.getEnd()).getMonthOfYear(), is(3)); }
@Test @Ignore public void shouldGeneratePeriodOfDes21ToJanWhenRnrNotExists() throws Exception { when(mockStockMovementRepository.queryEarliestStockMovementDateByProgram(anyString())).thenReturn(new DateTime("2016-01-06").toDate()); Period period = requisitionPeriodService.generateNextPeriod(programMMIA.getProgramCode(), null); assertThat(period.getBegin(), is(new DateTime("2015-12-21"))); assertThat(new DateTime(period.getEnd()).getMonthOfYear(), is(1)); }
@Test @Ignore public void shouldGeneratePeriodOfDes19ToJanWhenRnrNotExists() throws Exception { DateTime dateTime = new DateTime("2015-12-19").plusMonths(1); DateTime expectedPeriodEnd = DateUtil.cutTimeStamp(dateTime.withDate(dateTime.getYear(), dateTime.getMonthOfYear(), Period.END_DAY)); when(mockStockMovementRepository.queryEarliestStockMovementDateByProgram(anyString())).thenReturn(new DateTime("2015-12-19").toDate()); Period period = requisitionPeriodService.generateNextPeriod(programMMIA.getProgramCode(), null); assertThat(period.getBegin(), is(new DateTime("2015-12-19"))); assertThat(new DateTime(period.getEnd()).getMonthOfYear(), is(1)); assertThat(period.getEnd(), is(expectedPeriodEnd)); }