use of org.openlmis.stockmanagement.domain.card.StockCardLineItem in project openlmis-stockmanagement by OpenLMIS.
the class StockCardService method assignSourceDestinationReasonNameForLineItems.
private void assignSourceDestinationReasonNameForLineItems(StockCardDto stockCardDto) {
stockCardDto.getLineItems().forEach(lineItemDto -> {
StockCardLineItem lineItem = lineItemDto.getLineItem();
assignReasonName(lineItem);
lineItemDto.setSource(getFromRefDataOrConvertOrg(lineItem.getSource()));
lineItemDto.setDestination(getFromRefDataOrConvertOrg(lineItem.getDestination()));
});
}
use of org.openlmis.stockmanagement.domain.card.StockCardLineItem in project openlmis-stockmanagement by OpenLMIS.
the class StockEventNotificationProcessor method callNotifications.
private void callNotifications(StockEventDto event, StockEventLineItemDto eventLine) {
XLOGGER.entry(event, eventLine);
Profiler profiler = new Profiler("CALL_NOTIFICATION_FOR_LINE_ITEM");
profiler.setLogger(XLOGGER);
profiler.start("COPY_STOCK_CARD");
OrderableLotIdentity identity = OrderableLotIdentity.identityOf(eventLine);
StockCard card = event.getContext().findCard(identity);
StockCard copy = card.shallowCopy();
for (StockCardLineItem line : copy.getLineItems()) {
StockCardLineItemReason reason = line.getReason();
if (null != reason) {
line.setReason(event.getContext().findCardReason(reason.getId()));
}
}
profiler.start("CALCULATE_STOCK_ON_HAND");
copy.calculateStockOnHand();
profiler.start("NOTIFY_STOCK_CARD_EDITORS");
if (copy.getStockOnHand() == 0) {
stockoutNotifier.notifyStockEditors(copy);
}
profiler.stop().log();
XLOGGER.exit();
}
use of org.openlmis.stockmanagement.domain.card.StockCardLineItem in project openlmis-stockmanagement by OpenLMIS.
the class StockoutNotifier method getValuesMap.
private Map<String, String> getValuesMap(StockCard stockCard) {
Map<String, String> valuesMap = new HashMap<>();
valuesMap.put("facilityName", getFacilityName(stockCard.getFacilityId()));
valuesMap.put("orderableName", getOrderableName(stockCard.getOrderableId()));
valuesMap.put("orderableNameLotInformation", getOrderableNameLotInformation(valuesMap.get("orderableName"), stockCard.getLotId()));
valuesMap.put("programName", getProgramName(stockCard.getProgramId()));
List<StockCardLineItem> lineItems = stockCard.getLineItems();
LocalDate stockoutDate = lineItems.get(lineItems.size() - 1).getOccurredDate();
valuesMap.put("stockoutDate", getDateFormatter().format(stockoutDate));
long numberOfDaysOfStockout = getNumberOfDaysOfStockout(stockoutDate);
valuesMap.put("numberOfDaysOfStockout", numberOfDaysOfStockout + (numberOfDaysOfStockout == 1 ? " day" : " days"));
valuesMap.put("urlToViewBinCard", getUrlToViewBinCard(stockCard));
valuesMap.put("urlToInitiateRequisition", getUrlToInitiateRequisition(stockCard));
return valuesMap;
}
use of org.openlmis.stockmanagement.domain.card.StockCardLineItem in project openlmis-stockmanagement by OpenLMIS.
the class StockCardServiceIntegrationTest method shouldSaveLineItemsWithProgramFacilityOrderableForNonFirstMovement.
@Test
public void shouldSaveLineItemsWithProgramFacilityOrderableForNonFirstMovement() throws Exception {
// given
// 1. there is an existing event that caused a stock card to exist
StockEventDto existingEventDto = createStockEventDto();
final StockEvent existingEvent = save(existingEventDto, randomUUID());
UUID orderableId = existingEventDto.getLineItems().get(0).getOrderableId();
// 2. and there is a new event coming
StockEventDto newEventDto = createStockEventDto();
newEventDto.setProgramId(existingEventDto.getProgramId());
newEventDto.setFacilityId(existingEventDto.getFacilityId());
newEventDto.getLineItems().get(0).setOrderableId(orderableId);
// when
long cardAmountBeforeSave = stockCardRepository.count();
UUID userId = randomUUID();
StockEvent savedNewEvent = save(newEventDto, userId);
long cardAmountAfterSave = stockCardRepository.count();
// then
StockCard savedCard = stockCardRepository.findByOriginEvent(existingEvent);
List<StockCardLineItem> lineItems = savedCard.getLineItems();
lineItems.sort(Comparator.comparing(StockCardLineItem::getProcessedDate));
StockCardLineItem latestLineItem = lineItems.get(lineItems.size() - 1);
assertThat(cardAmountAfterSave, is(cardAmountBeforeSave));
assertThat(latestLineItem.getOriginEvent().getId(), is(savedNewEvent.getId()));
assertThat(latestLineItem.getStockCard().getId(), is(savedCard.getId()));
assertThat(latestLineItem.getUserId(), is(userId));
}
use of org.openlmis.stockmanagement.domain.card.StockCardLineItem in project openlmis-stockmanagement by OpenLMIS.
the class StockCardServiceIntegrationTest method shouldSaveStockCardLineItemsAndCreateStockCardForFirstMovement.
@Test
public void shouldSaveStockCardLineItemsAndCreateStockCardForFirstMovement() throws Exception {
// given
UUID userId = randomUUID();
StockEventDto stockEventDto = createStockEventDto();
StockEvent savedEvent = save(stockEventDto, userId);
// when
stockCardService.saveFromEvent(stockEventDto, savedEvent.getId());
// then
StockCard savedCard = stockCardRepository.findByOriginEvent(savedEvent);
StockCardLineItem firstLineItem = savedCard.getLineItems().get(0);
assertThat(firstLineItem.getUserId(), is(userId));
assertThat(firstLineItem.getSource().isRefDataFacility(), is(true));
assertThat(firstLineItem.getDestination().isRefDataFacility(), is(false));
assertThat(firstLineItem.getStockCard().getOriginEvent().getId(), is(savedEvent.getId()));
assertThat(firstLineItem.getStockCard().getFacilityId(), is(savedEvent.getFacilityId()));
assertThat(firstLineItem.getStockCard().getProgramId(), is(savedEvent.getProgramId()));
UUID orderableId = savedEvent.getLineItems().get(0).getOrderableId();
assertThat(firstLineItem.getStockCard().getOrderableId(), is(orderableId));
}
Aggregations