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;
}
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);
}
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());
}
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"));
}
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);
}
}
Aggregations