Search in sources :

Example 11 with StockCardDto

use of org.openlmis.stockmanagement.dto.StockCardDto in project openlmis-stockmanagement by OpenLMIS.

the class StockCardService method findStockCardById.

/**
 * Find stock card by stock card id.
 *
 * @param stockCardId stock card id.
 * @return the found stock card.
 */
public StockCardDto findStockCardById(UUID stockCardId) {
    StockCard card = cardRepository.findOne(stockCardId);
    if (card == null) {
        return null;
    }
    StockCard foundCard = card.shallowCopy();
    LOGGER.debug("Stock card found");
    permissionService.canViewStockCard(foundCard.getProgramId(), foundCard.getFacilityId());
    StockCardDto cardDto = createDtos(singletonList(foundCard)).get(0);
    cardDto.setOrderable(orderableRefDataService.findOne(foundCard.getOrderableId()));
    if (cardDto.hasLot()) {
        cardDto.setLot(lotReferenceDataService.findOne(cardDto.getLot().getId()));
    }
    assignSourceDestinationReasonNameForLineItems(cardDto);
    return cardDto;
}
Also used : StockCard(org.openlmis.stockmanagement.domain.card.StockCard) StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto)

Example 12 with StockCardDto

use of org.openlmis.stockmanagement.dto.StockCardDto in project openlmis-stockmanagement by OpenLMIS.

the class JasperReportService method getStockCardSummariesReportView.

/**
 * Generate stock card summary report in PDF format.
 *
 * @param program  program id
 * @param facility facility id
 * @return generated stock card summary report.
 */
public ModelAndView getStockCardSummariesReportView(UUID program, UUID facility) {
    List<StockCardDto> cards = stockCardSummariesService.findStockCards(program, facility);
    StockCardDto firstCard = cards.get(0);
    Map<String, Object> params = new HashMap<>();
    params.put("stockCardSummaries", cards);
    params.put("program", firstCard.getProgram());
    params.put("facility", firstCard.getFacility());
    // right now, each report can only be about one program, one facility
    // in the future we may want to support one reprot for multiple programs
    params.put("showProgram", getCount(cards, card -> card.getProgram().getId().toString()) > 1);
    params.put("showFacility", getCount(cards, card -> card.getFacility().getId().toString()) > 1);
    params.put("showLot", cards.stream().anyMatch(card -> card.getLotId() != null));
    return generateReport(CARD_SUMMARY_REPORT_URL, params);
}
Also used : JasperCompileManager(net.sf.jasperreports.engine.JasperCompileManager) JasperReport(net.sf.jasperreports.engine.JasperReport) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File.createTempFile(java.io.File.createTempFile) JRException(net.sf.jasperreports.engine.JRException) ObjectInputStream(java.io.ObjectInputStream) ERROR_JASPER_FILE_CREATION(org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_JASPER_FILE_CREATION) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) Function(java.util.function.Function) Collections.singletonList(java.util.Collections.singletonList) JasperDesign(net.sf.jasperreports.engine.design.JasperDesign) StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto) ByteArrayInputStream(java.io.ByteArrayInputStream) Service(org.springframework.stereotype.Service) Map(java.util.Map) DataSource(javax.sql.DataSource) ERROR_REPORT_ID_NOT_FOUND(org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_REPORT_ID_NOT_FOUND) ObjectOutputStream(java.io.ObjectOutputStream) ERROR_GENERATE_REPORT_FAILED(org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_GENERATE_REPORT_FAILED) JasperReportsMultiFormatView(org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView) FileUtils.writeByteArrayToFile(org.apache.commons.io.FileUtils.writeByteArrayToFile) JasperTemplate(org.openlmis.stockmanagement.domain.JasperTemplate) ERROR_IO(org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_IO) JasperReportsPdfView(org.springframework.web.servlet.view.jasperreports.JasperReportsPdfView) IOException(java.io.IOException) UUID(java.util.UUID) ApplicationContext(org.springframework.context.ApplicationContext) File(java.io.File) JRXmlLoader(net.sf.jasperreports.engine.xml.JRXmlLoader) ModelAndView(org.springframework.web.servlet.ModelAndView) Message(org.openlmis.stockmanagement.util.Message) List(java.util.List) ResourceNotFoundException(org.openlmis.stockmanagement.exception.ResourceNotFoundException) JasperReportViewException(org.openlmis.stockmanagement.exception.JasperReportViewException) Collections(java.util.Collections) ERROR_CLASS_NOT_FOUND(org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_CLASS_NOT_FOUND) InputStream(java.io.InputStream) HashMap(java.util.HashMap) StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto)

Example 13 with StockCardDto

use of org.openlmis.stockmanagement.dto.StockCardDto in project openlmis-stockmanagement by OpenLMIS.

the class StockCardBaseService method createDtos.

protected List<StockCardDto> createDtos(List<StockCard> stockCards) {
    if (stockCards.isEmpty()) {
        return emptyList();
    }
    StockCard firstCard = stockCards.get(0);
    LOGGER.debug("Calling ref data to retrieve facility info for card");
    FacilityDto facility = facilityRefDataService.findOne(firstCard.getFacilityId());
    LOGGER.debug("Calling ref data to retrieve program info for card");
    ProgramDto program = programRefDataService.findOne(firstCard.getProgramId());
    return stockCards.stream().map(card -> cardToDto(facility, program, card)).collect(toList());
}
Also used : CollectionUtils.isEmpty(org.springframework.util.CollectionUtils.isEmpty) FacilityReferenceDataService(org.openlmis.stockmanagement.service.referencedata.FacilityReferenceDataService) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) Logger(org.slf4j.Logger) Collections.emptyList(java.util.Collections.emptyList) ProgramReferenceDataService(org.openlmis.stockmanagement.service.referencedata.ProgramReferenceDataService) LoggerFactory(org.slf4j.LoggerFactory) LotDto(org.openlmis.stockmanagement.dto.referencedata.LotDto) Autowired(org.springframework.beans.factory.annotation.Autowired) ProgramDto(org.openlmis.stockmanagement.dto.referencedata.ProgramDto) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto) OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) Service(org.springframework.stereotype.Service) FacilityDto(org.openlmis.stockmanagement.dto.referencedata.FacilityDto) StockCardLineItemDto(org.openlmis.stockmanagement.dto.StockCardLineItemDto) ProgramDto(org.openlmis.stockmanagement.dto.referencedata.ProgramDto) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) FacilityDto(org.openlmis.stockmanagement.dto.referencedata.FacilityDto)

Example 14 with StockCardDto

use of org.openlmis.stockmanagement.dto.StockCardDto in project openlmis-stockmanagement by OpenLMIS.

the class StockCardServiceIntegrationTest method shouldReassignPhysicalInventoryReasonNames.

@Test
public void shouldReassignPhysicalInventoryReasonNames() throws Exception {
    // given
    StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
    stockEventDto.getLineItems().get(0).setSourceId(null);
    stockEventDto.getLineItems().get(0).setDestinationId(null);
    stockEventDto.getLineItems().get(0).setReasonId(null);
    StockEvent savedEvent = save(stockEventDto, randomUUID());
    // when
    UUID cardId = stockCardRepository.findByOriginEvent(savedEvent).getId();
    StockCardDto card = stockCardService.findStockCardById(cardId);
    // then
    String reasonName = card.getLineItems().get(0).getLineItem().getReason().getName();
    assertThat(reasonName, is("Overstock"));
}
Also used : StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto) UUID.fromString(java.util.UUID.fromString) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) BaseIntegrationTest(org.openlmis.stockmanagement.BaseIntegrationTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 15 with StockCardDto

use of org.openlmis.stockmanagement.dto.StockCardDto in project openlmis-stockmanagement by OpenLMIS.

the class StockCardsController method getStockCard.

/**
 * Get stock card by id.
 *
 * @param stockCardId stock card id.
 * @return found stock card.
 */
@RequestMapping(value = "/stockCards/{stockCardId}")
public ResponseEntity<StockCardDto> getStockCard(@PathVariable("stockCardId") UUID stockCardId) {
    LOGGER.debug("Try to find stock card with id: {}", stockCardId);
    StockCardDto stockCardDto = stockCardService.findStockCardById(stockCardId);
    if (stockCardDto == null) {
        LOGGER.debug("Not found stock card with id: {}", stockCardId);
        return new ResponseEntity<>(NOT_FOUND);
    } else {
        LOGGER.debug("Found stock card with id: {}", stockCardId);
        return new ResponseEntity<>(stockCardDto, OK);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

StockCardDto (org.openlmis.stockmanagement.dto.StockCardDto)16 UUID (java.util.UUID)10 Test (org.junit.Test)8 UUID.randomUUID (java.util.UUID.randomUUID)7 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)5 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)5 BaseIntegrationTest (org.openlmis.stockmanagement.BaseIntegrationTest)4 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)4 List (java.util.List)3 UUID.fromString (java.util.UUID.fromString)3 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)3 StockCardLineItemDto (org.openlmis.stockmanagement.dto.StockCardLineItemDto)3 FacilityDto (org.openlmis.stockmanagement.dto.referencedata.FacilityDto)3 LotDto (org.openlmis.stockmanagement.dto.referencedata.LotDto)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 Collections.singletonList (java.util.Collections.singletonList)2 HashMap (java.util.HashMap)2 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)2 ProgramDto (org.openlmis.stockmanagement.dto.referencedata.ProgramDto)2 StockEventDtoDataBuilder.createStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto)2