Search in sources :

Example 6 with StockCardLineItem

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()));
    });
}
Also used : StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem)

Example 7 with StockCardLineItem

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();
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) Profiler(org.slf4j.profiler.Profiler) StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem) OrderableLotIdentity(org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity) StockCard(org.openlmis.stockmanagement.domain.card.StockCard)

Example 8 with StockCardLineItem

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;
}
Also used : HashMap(java.util.HashMap) StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem) LocalDate(java.time.LocalDate)

Example 9 with StockCardLineItem

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));
}
Also used : StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) 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 10 with StockCardLineItem

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));
}
Also used : StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) 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)

Aggregations

StockCardLineItem (org.openlmis.stockmanagement.domain.card.StockCardLineItem)15 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)9 Test (org.junit.Test)6 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)6 StockEventDtoDataBuilder.createStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto)6 LocalDate (java.time.LocalDate)5 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)3 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 UUID.randomUUID (java.util.UUID.randomUUID)2 BaseIntegrationTest (org.openlmis.stockmanagement.BaseIntegrationTest)2 StockCardLineItemReason (org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 UUID.fromString (java.util.UUID.fromString)1 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)1 StockCardLineItemDto (org.openlmis.stockmanagement.dto.StockCardLineItemDto)1 StockEventLineItemDto (org.openlmis.stockmanagement.dto.StockEventLineItemDto)1 StockCardDataBuilder (org.openlmis.stockmanagement.testutils.StockCardDataBuilder)1 StockCardLineItemDataBuilder (org.openlmis.stockmanagement.testutils.StockCardLineItemDataBuilder)1 StockEventDataBuilder (org.openlmis.stockmanagement.testutils.StockEventDataBuilder)1