Search in sources :

Example 1 with EncumbranceRollover

use of org.folio.rest.jaxrs.model.EncumbranceRollover in project mod-orders by folio-org.

the class OrderRolloverServiceTest method shouldUpdateOrderLinesCostAndEncumbranceLinksAndPolCurrencyVsSystemCurrencyTheSame.

@Test
@DisplayName("Should update order lines cost And Encumbrance Links where Pol Currency equals systemCurrency")
void shouldUpdateOrderLinesCostAndEncumbranceLinksAndPolCurrencyVsSystemCurrencyTheSame() {
    String fromFiscalYearId = UUID.randomUUID().toString();
    String ledgerId = UUID.randomUUID().toString();
    String toFiscalYearId = UUID.randomUUID().toString();
    String fundId1 = UUID.randomUUID().toString();
    String fundId2 = UUID.randomUUID().toString();
    String fundId3 = UUID.randomUUID().toString();
    String orderId1 = UUID.randomUUID().toString();
    String orderId2 = UUID.randomUUID().toString();
    String orderId3 = UUID.randomUUID().toString();
    String poLineId1 = UUID.randomUUID().toString();
    String poLineId2 = UUID.randomUUID().toString();
    String poLineId3 = UUID.randomUUID().toString();
    String prevEncumbrId1 = UUID.randomUUID().toString();
    String prevEncumbrId2 = UUID.randomUUID().toString();
    String prevEncumbrId3 = UUID.randomUUID().toString();
    String currEncumbrId1 = UUID.randomUUID().toString();
    String currEncumbrId2 = UUID.randomUUID().toString();
    String currEncumbrId3 = UUID.randomUUID().toString();
    String expClassId2 = UUID.randomUUID().toString();
    String expClassId3 = UUID.randomUUID().toString();
    EncumbranceRollover ongoingEncumbranceBasedOnExpended = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONGOING).withBasedOn(EncumbranceRollover.BasedOn.EXPENDED);
    EncumbranceRollover oneTimeEncumbrance = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONE_TIME).withBasedOn(EncumbranceRollover.BasedOn.REMAINING);
    EncumbranceRollover ongoingEncumbranceBasedOnInitialAmount = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONGOING).withBasedOn(EncumbranceRollover.BasedOn.INITIAL_AMOUNT);
    LedgerFiscalYearRollover ledgerFiscalYearRollover = new LedgerFiscalYearRollover().withId(UUID.randomUUID().toString()).withFromFiscalYearId(fromFiscalYearId).withLedgerId(ledgerId).withToFiscalYearId(toFiscalYearId).withEncumbrancesRollover(List.of(ongoingEncumbranceBasedOnExpended, oneTimeEncumbrance, ongoingEncumbranceBasedOnInitialAmount));
    List<Fund> funds = List.of(new Fund().withId(fundId1).withLedgerId(ledgerId), new Fund().withId(fundId2).withLedgerId(ledgerId), new Fund().withId(fundId3).withLedgerId(ledgerId));
    PurchaseOrder purchaseOrder1 = new PurchaseOrder().withId(orderId1).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
    PurchaseOrder purchaseOrder2 = new PurchaseOrder().withId(orderId2).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
    PurchaseOrder purchaseOrder3 = new PurchaseOrder().withId(orderId3).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
    List<PurchaseOrder> orders = List.of(purchaseOrder1, purchaseOrder2, purchaseOrder3);
    PurchaseOrderCollection purchaseOrderCollection = new PurchaseOrderCollection().withPurchaseOrders(orders).withTotalRecords(3);
    FundDistribution fundDistributionOneTime = new FundDistribution().withFundId(fundId1).withValue(100d).withEncumbrance(prevEncumbrId1);
    FundDistribution fundDistributionOngoing2 = new FundDistribution().withFundId(fundId2).withValue(100d).withEncumbrance(prevEncumbrId2).withExpenseClassId(expClassId2);
    FundDistribution fundDistributionOngoing3 = new FundDistribution().withFundId(fundId3).withValue(100d).withEncumbrance(prevEncumbrId3).withExpenseClassId(expClassId3);
    Cost costOneTime = new Cost().withListUnitPrice(100d).withQuantityPhysical(1).withCurrency("USD").withPoLineEstimatedPrice(100d);
    PoLine poLineOneTime = new PoLine().withId(poLineId1).withPurchaseOrderId(orderId1).withCost(costOneTime).withFundDistribution(List.of(fundDistributionOneTime));
    Cost costOngoing2 = new Cost().withListUnitPrice(100d).withQuantityPhysical(1).withCurrency("USD").withPoLineEstimatedPrice(100d);
    PoLine poLineOngoing2 = new PoLine().withId(poLineId2).withPurchaseOrderId(orderId2).withCost(costOngoing2).withFundDistribution(List.of(fundDistributionOngoing2));
    Cost costOngoing3 = new Cost().withListUnitPrice(100d).withQuantityPhysical(1).withCurrency("USD").withPoLineEstimatedPrice(100d);
    PoLine poLineOngoing3 = new PoLine().withId(poLineId3).withPurchaseOrderId(orderId3).withCost(costOngoing3).withFundDistribution(List.of(fundDistributionOngoing3));
    List<PoLine> poLines = List.of(poLineOneTime, poLineOngoing2, poLineOngoing3);
    doReturn(completedFuture(funds)).when(fundService).getFundsByLedgerId(ledgerId, requestContext);
    doReturn(completedFuture(purchaseOrderCollection)).when(purchaseOrderStorageService).getPurchaseOrders(anyString(), anyInt(), anyInt(), any());
    doReturn(completedFuture(poLines)).when(purchaseOrderLineService).getOrderLines(anyString(), anyInt(), anyInt(), any());
    doReturn(completedFuture(null)).when(purchaseOrderLineService).saveOrderLines(eq(poLines), any());
    Encumbrance encumbranceOneTime = new Encumbrance().withSourcePurchaseOrderId(orderId1).withSourcePoLineId(poLineId1).withOrderType(Encumbrance.OrderType.ONE_TIME).withInitialAmountEncumbered(60d);
    Transaction transactionOneTime = new Transaction().withId(currEncumbrId1).withFromFundId(fundId1).withEncumbrance(encumbranceOneTime);
    Encumbrance encumbranceOngoing2 = new Encumbrance().withSourcePurchaseOrderId(orderId2).withSourcePoLineId(poLineId2).withOrderType(Encumbrance.OrderType.ONGOING).withInitialAmountEncumbered(90d);
    Transaction transactionOngoing2 = new Transaction().withId(currEncumbrId2).withFromFundId(fundId2).withEncumbrance(encumbranceOngoing2).withExpenseClassId(expClassId2);
    Encumbrance encumbranceOngoing3 = new Encumbrance().withSourcePurchaseOrderId(orderId3).withSourcePoLineId(poLineId3).withOrderType(Encumbrance.OrderType.ONGOING).withInitialAmountEncumbered(95d);
    Transaction transactionOngoing3 = new Transaction().withId(currEncumbrId3).withFromFundId(fundId3).withEncumbrance(encumbranceOngoing3).withExpenseClassId(expClassId3);
    List<Transaction> encumbrances = List.of(transactionOneTime, transactionOngoing2, transactionOngoing3);
    TransactionCollection encumbranceCollection = new TransactionCollection().withTransactions(encumbrances).withTotalRecords(3);
    doReturn(completedFuture(encumbranceCollection)).when(transactionService).getTransactions(anyString(), anyInt(), anyInt(), any());
    double exchangeEurToUsdRate = 1.0d;
    doReturn(completedFuture(systemCurrency)).when(configurationEntriesService).getSystemCurrency(requestContext);
    String polCurrency = systemCurrency;
    ConversionQuery actQuery = ConversionQueryBuilder.of().setBaseCurrency(polCurrency).setTermCurrency(systemCurrency).set(RATE_KEY, exchangeEurToUsdRate).build();
    ExchangeRateProvider exchangeRateProvider = Mockito.mock(ManualExchangeRateProvider.class);
    ManualCurrencyConversion manualCurrencyConversion = new ManualCurrencyConversion(actQuery, exchangeRateProvider, ConversionContext.of());
    ExchangeRate exchangeRate = mock(ExchangeRate.class);
    doReturn(exchangeRateProvider).when(exchangeRateProviderResolver).resolve(any(ConversionQuery.class), eq(requestContext));
    doReturn(manualCurrencyConversion).when(exchangeRateProvider).getCurrencyConversion(any(ConversionQuery.class));
    doReturn(exchangeRate).when(exchangeRateProvider).getExchangeRate(any(ConversionQuery.class));
    when(exchangeRate.getContext()).thenReturn(ConversionContext.of());
    when(exchangeRate.getCurrency()).thenReturn(Monetary.getCurrency(systemCurrency));
    when(exchangeRate.getBaseCurrency()).thenReturn(Monetary.getCurrency(polCurrency));
    when(exchangeRate.getFactor()).thenReturn(new DefaultNumberValue(exchangeEurToUsdRate));
    CompletableFuture<Void> future = orderRolloverService.rollover(ledgerFiscalYearRollover, requestContext);
    future.join();
    assertFalse(future.isCompletedExceptionally());
    assertThat(fundDistributionOneTime.getEncumbrance(), equalTo(currEncumbrId1));
    assertThat(fundDistributionOngoing2.getEncumbrance(), equalTo(currEncumbrId2));
    assertThat(fundDistributionOngoing3.getEncumbrance(), equalTo(currEncumbrId3));
    assertThat(costOneTime.getPoLineEstimatedPrice(), equalTo(60d));
    assertThat(costOngoing2.getPoLineEstimatedPrice(), equalTo(90d));
    assertThat(costOngoing3.getPoLineEstimatedPrice(), equalTo(95d));
    assertThat(costOneTime.getFyroAdjustmentAmount(), equalTo(-40d));
    assertThat(costOngoing2.getFyroAdjustmentAmount(), equalTo(-10d));
    assertThat(costOngoing3.getFyroAdjustmentAmount(), equalTo(-5d));
}
Also used : EncumbranceRollover(org.folio.rest.jaxrs.model.EncumbranceRollover) DefaultNumberValue(org.javamoney.moneta.spi.DefaultNumberValue) TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) ExchangeRate(javax.money.convert.ExchangeRate) PurchaseOrderCollection(org.folio.rest.jaxrs.model.PurchaseOrderCollection) ExchangeRateProvider(javax.money.convert.ExchangeRateProvider) ManualExchangeRateProvider(org.folio.service.exchange.ManualExchangeRateProvider) Fund(org.folio.rest.acq.model.finance.Fund) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LedgerFiscalYearRollover(org.folio.rest.jaxrs.model.LedgerFiscalYearRollover) Cost(org.folio.rest.jaxrs.model.Cost) ManualCurrencyConversion(org.folio.service.exchange.ManualCurrencyConversion) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) ConversionQuery(javax.money.convert.ConversionQuery) Transaction(org.folio.rest.acq.model.finance.Transaction) PoLine(org.folio.rest.jaxrs.model.PoLine) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with EncumbranceRollover

use of org.folio.rest.jaxrs.model.EncumbranceRollover in project mod-orders by folio-org.

the class OrderRolloverServiceTest method shouldUpdateOrderLinesCostAndEncumbranceLinksWithExchangeRateAndPolCurrencyVsSystemCurrencyAreDifferent.

@Test
@DisplayName("Should update order lines cost And Encumbrance Links where Pol Currency and systemCurrency are different")
void shouldUpdateOrderLinesCostAndEncumbranceLinksWithExchangeRateAndPolCurrencyVsSystemCurrencyAreDifferent() {
    String fromFiscalYearId = UUID.randomUUID().toString();
    String ledgerId = UUID.randomUUID().toString();
    String toFiscalYearId = UUID.randomUUID().toString();
    String fundId1 = UUID.randomUUID().toString();
    String fundId2 = UUID.randomUUID().toString();
    String fundId3 = UUID.randomUUID().toString();
    String orderId1 = UUID.randomUUID().toString();
    String orderId2 = UUID.randomUUID().toString();
    String orderId3 = UUID.randomUUID().toString();
    String poLineId1 = UUID.randomUUID().toString();
    String poLineId2 = UUID.randomUUID().toString();
    String poLineId3 = UUID.randomUUID().toString();
    String prevEncumbrId1 = UUID.randomUUID().toString();
    String prevEncumbrId2 = UUID.randomUUID().toString();
    String prevEncumbrId3 = UUID.randomUUID().toString();
    String currEncumbrId1 = UUID.randomUUID().toString();
    String currEncumbrId2 = UUID.randomUUID().toString();
    String currEncumbrId3 = UUID.randomUUID().toString();
    String expClassId2 = UUID.randomUUID().toString();
    String expClassId3 = UUID.randomUUID().toString();
    EncumbranceRollover ongoingEncumbranceBasedOnExpended = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONGOING).withBasedOn(EncumbranceRollover.BasedOn.EXPENDED);
    EncumbranceRollover oneTimeEncumbrance = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONE_TIME).withBasedOn(EncumbranceRollover.BasedOn.REMAINING);
    EncumbranceRollover ongoingEncumbranceBasedOnInitialAmount = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONGOING).withBasedOn(EncumbranceRollover.BasedOn.INITIAL_AMOUNT);
    LedgerFiscalYearRollover ledgerFiscalYearRollover = new LedgerFiscalYearRollover().withId(UUID.randomUUID().toString()).withFromFiscalYearId(fromFiscalYearId).withLedgerId(ledgerId).withToFiscalYearId(toFiscalYearId).withEncumbrancesRollover(List.of(ongoingEncumbranceBasedOnExpended, oneTimeEncumbrance, ongoingEncumbranceBasedOnInitialAmount));
    List<Fund> funds = List.of(new Fund().withId(fundId1).withLedgerId(ledgerId), new Fund().withId(fundId2).withLedgerId(ledgerId), new Fund().withId(fundId3).withLedgerId(ledgerId));
    PurchaseOrder purchaseOrder1 = new PurchaseOrder().withId(orderId1).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
    PurchaseOrder purchaseOrder2 = new PurchaseOrder().withId(orderId2).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
    PurchaseOrder purchaseOrder3 = new PurchaseOrder().withId(orderId3).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
    List<PurchaseOrder> orders = List.of(purchaseOrder1, purchaseOrder2, purchaseOrder3);
    PurchaseOrderCollection purchaseOrderCollection = new PurchaseOrderCollection().withPurchaseOrders(orders).withTotalRecords(3);
    FundDistribution fundDistributionOneTime = new FundDistribution().withFundId(fundId1).withValue(100d).withEncumbrance(prevEncumbrId1);
    FundDistribution fundDistributionOngoing2 = new FundDistribution().withFundId(fundId2).withValue(100d).withEncumbrance(prevEncumbrId2).withExpenseClassId(expClassId2);
    FundDistribution fundDistributionOngoing3 = new FundDistribution().withFundId(fundId3).withValue(100d).withEncumbrance(prevEncumbrId3).withExpenseClassId(expClassId3);
    String polCurrency = "EUR";
    Cost costOneTime = new Cost().withListUnitPrice(24.99d).withQuantityPhysical(1).withCurrency(polCurrency).withPoLineEstimatedPrice(24.99d);
    PoLine poLineOneTime = new PoLine().withId(poLineId1).withPurchaseOrderId(orderId1).withCost(costOneTime).withFundDistribution(List.of(fundDistributionOneTime));
    Cost costOngoing2 = new Cost().withListUnitPrice(24.99d).withQuantityPhysical(1).withCurrency(polCurrency).withPoLineEstimatedPrice(24.99d);
    PoLine poLineOngoing2 = new PoLine().withId(poLineId2).withPurchaseOrderId(orderId2).withCost(costOngoing2).withFundDistribution(List.of(fundDistributionOngoing2));
    Cost costOngoing3 = new Cost().withListUnitPrice(24.99d).withQuantityPhysical(1).withCurrency(polCurrency).withPoLineEstimatedPrice(24.99d);
    PoLine poLineOngoing3 = new PoLine().withId(poLineId3).withPurchaseOrderId(orderId3).withCost(costOngoing3).withFundDistribution(List.of(fundDistributionOngoing3));
    List<PoLine> poLines = List.of(poLineOneTime, poLineOngoing2, poLineOngoing3);
    doReturn(completedFuture(funds)).when(fundService).getFundsByLedgerId(ledgerId, requestContext);
    doReturn(completedFuture(purchaseOrderCollection)).when(purchaseOrderStorageService).getPurchaseOrders(anyString(), anyInt(), anyInt(), any());
    doReturn(completedFuture(poLines)).when(purchaseOrderLineService).getOrderLines(anyString(), anyInt(), anyInt(), any());
    doReturn(completedFuture(null)).when(purchaseOrderLineService).saveOrderLines(eq(poLines), any());
    Encumbrance encumbranceOneTime = new Encumbrance().withSourcePurchaseOrderId(orderId1).withSourcePoLineId(poLineId1).withOrderType(Encumbrance.OrderType.ONE_TIME).withInitialAmountEncumbered(30.16d);
    Transaction transactionOneTime = new Transaction().withId(currEncumbrId1).withFromFundId(fundId1).withEncumbrance(encumbranceOneTime);
    Encumbrance encumbranceOngoing2 = new Encumbrance().withSourcePurchaseOrderId(orderId2).withSourcePoLineId(poLineId2).withOrderType(Encumbrance.OrderType.ONGOING).withInitialAmountEncumbered(30.16d);
    Transaction transactionOngoing2 = new Transaction().withId(currEncumbrId2).withFromFundId(fundId2).withEncumbrance(encumbranceOngoing2).withExpenseClassId(expClassId2);
    Encumbrance encumbranceOngoing3 = new Encumbrance().withSourcePurchaseOrderId(orderId3).withSourcePoLineId(poLineId3).withOrderType(Encumbrance.OrderType.ONGOING).withInitialAmountEncumbered(30.16d);
    Transaction transactionOngoing3 = new Transaction().withId(currEncumbrId3).withFromFundId(fundId3).withEncumbrance(encumbranceOngoing3).withExpenseClassId(expClassId3);
    List<Transaction> encumbrances = List.of(transactionOneTime, transactionOngoing2, transactionOngoing3);
    TransactionCollection encumbranceCollection = new TransactionCollection().withTransactions(encumbrances).withTotalRecords(3);
    doReturn(completedFuture(encumbranceCollection)).when(transactionService).getTransactions(anyString(), anyInt(), anyInt(), any());
    double exchangeEurToUsdRate = 0.82858d;
    doReturn(completedFuture(systemCurrency)).when(configurationEntriesService).getSystemCurrency(requestContext);
    ConversionQuery actQuery = ConversionQueryBuilder.of().setBaseCurrency(polCurrency).setTermCurrency(systemCurrency).set(RATE_KEY, exchangeEurToUsdRate).build();
    ExchangeRateProvider exchangeRateProvider = Mockito.mock(ManualExchangeRateProvider.class);
    ManualCurrencyConversion manualCurrencyConversion = new ManualCurrencyConversion(actQuery, exchangeRateProvider, ConversionContext.of());
    ExchangeRate exchangeRate = mock(ExchangeRate.class);
    doReturn(exchangeRateProvider).when(exchangeRateProviderResolver).resolve(any(ConversionQuery.class), eq(requestContext));
    doReturn(manualCurrencyConversion).when(exchangeRateProvider).getCurrencyConversion(any(ConversionQuery.class));
    doReturn(exchangeRate).when(exchangeRateProvider).getExchangeRate(any(ConversionQuery.class));
    when(exchangeRate.getContext()).thenReturn(ConversionContext.of());
    when(exchangeRate.getCurrency()).thenReturn(Monetary.getCurrency(systemCurrency));
    when(exchangeRate.getBaseCurrency()).thenReturn(Monetary.getCurrency(polCurrency));
    when(exchangeRate.getFactor()).thenReturn(new DefaultNumberValue(exchangeEurToUsdRate));
    CompletableFuture<Void> future = orderRolloverService.rollover(ledgerFiscalYearRollover, requestContext);
    future.join();
    assertFalse(future.isCompletedExceptionally());
    assertThat(fundDistributionOneTime.getEncumbrance(), equalTo(currEncumbrId1));
    assertThat(fundDistributionOngoing2.getEncumbrance(), equalTo(currEncumbrId2));
    assertThat(fundDistributionOngoing3.getEncumbrance(), equalTo(currEncumbrId3));
    assertThat(new BigDecimal(costOneTime.getPoLineEstimatedPrice()).setScale(2, RoundingMode.HALF_EVEN), equalTo(new BigDecimal(24.99d).setScale(2, RoundingMode.HALF_EVEN)));
    assertThat(new BigDecimal(costOngoing2.getPoLineEstimatedPrice()).setScale(2, RoundingMode.HALF_EVEN), equalTo(new BigDecimal(24.99d).setScale(2, RoundingMode.HALF_EVEN)));
    assertThat(new BigDecimal(costOngoing3.getPoLineEstimatedPrice()).setScale(2, RoundingMode.HALF_EVEN), equalTo(new BigDecimal(24.99d).setScale(2, RoundingMode.HALF_EVEN)));
    assertThat(costOneTime.getFyroAdjustmentAmount(), equalTo(0.0d));
    assertThat(costOngoing2.getFyroAdjustmentAmount(), equalTo(0.0d));
    assertThat(costOngoing3.getFyroAdjustmentAmount(), equalTo(0.0d));
}
Also used : DefaultNumberValue(org.javamoney.moneta.spi.DefaultNumberValue) TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) ExchangeRate(javax.money.convert.ExchangeRate) Fund(org.folio.rest.acq.model.finance.Fund) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LedgerFiscalYearRollover(org.folio.rest.jaxrs.model.LedgerFiscalYearRollover) Cost(org.folio.rest.jaxrs.model.Cost) ManualCurrencyConversion(org.folio.service.exchange.ManualCurrencyConversion) EncumbranceRollover(org.folio.rest.jaxrs.model.EncumbranceRollover) PurchaseOrderCollection(org.folio.rest.jaxrs.model.PurchaseOrderCollection) ExchangeRateProvider(javax.money.convert.ExchangeRateProvider) ManualExchangeRateProvider(org.folio.service.exchange.ManualExchangeRateProvider) BigDecimal(java.math.BigDecimal) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) ConversionQuery(javax.money.convert.ConversionQuery) Transaction(org.folio.rest.acq.model.finance.Transaction) PoLine(org.folio.rest.jaxrs.model.PoLine) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with EncumbranceRollover

use of org.folio.rest.jaxrs.model.EncumbranceRollover in project mod-orders by folio-org.

the class ReEncumbranceHoldersBuilderTest method shouldPopulateReEncumbranceHoldersWithOneTimeEncumbranceRolloverWhenOrderTypeOneTime.

@Test
void shouldPopulateReEncumbranceHoldersWithOneTimeEncumbranceRolloverWhenOrderTypeOneTime() {
    EncumbranceRollover oneTimeEncumbranceRollover = new EncumbranceRollover().withBasedOn(EncumbranceRollover.BasedOn.REMAINING).withOrderType(EncumbranceRollover.OrderType.ONE_TIME).withIncreaseBy(10d);
    EncumbranceRollover ongoingEncumbranceRollover = new EncumbranceRollover().withBasedOn(EncumbranceRollover.BasedOn.EXPENDED).withOrderType(EncumbranceRollover.OrderType.ONGOING).withIncreaseBy(10d);
    EncumbranceRollover subscriptionEncumbranceRollover = new EncumbranceRollover().withBasedOn(EncumbranceRollover.BasedOn.REMAINING).withOrderType(EncumbranceRollover.OrderType.ONGOING_SUBSCRIPTION).withIncreaseBy(10d);
    CompositePurchaseOrder compPO = new CompositePurchaseOrder().withOrderType(CompositePurchaseOrder.OrderType.ONE_TIME);
    LedgerFiscalYearRollover rollover = new LedgerFiscalYearRollover().withEncumbrancesRollover(Arrays.asList(oneTimeEncumbranceRollover, ongoingEncumbranceRollover, subscriptionEncumbranceRollover));
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withPurchaseOrder(compPO).withRollover(rollover);
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withPurchaseOrder(compPO).withRollover(rollover);
    List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2);
    List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withEncumbranceRollover(holders);
    assertThat(resultHolders, everyItem(hasProperty("encumbranceRollover", is(oneTimeEncumbranceRollover))));
}
Also used : EncumbranceRollover(org.folio.rest.jaxrs.model.EncumbranceRollover) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) LedgerFiscalYearRollover(org.folio.rest.jaxrs.model.LedgerFiscalYearRollover) Test(org.junit.jupiter.api.Test)

Example 4 with EncumbranceRollover

use of org.folio.rest.jaxrs.model.EncumbranceRollover in project mod-orders by folio-org.

the class ReEncumbranceHoldersBuilderTest method shouldPopulateReEncumbranceHoldersWithFromFyEncumbrances.

@Test
void shouldPopulateReEncumbranceHoldersWithFromFyEncumbrances() {
    String fromFyId = UUID.randomUUID().toString();
    String toFyId = UUID.randomUUID().toString();
    String orderId = UUID.randomUUID().toString();
    String fund1Id = UUID.randomUUID().toString();
    String fund2Id = UUID.randomUUID().toString();
    EncumbranceRollover encumbranceRollover = new EncumbranceRollover().withBasedOn(EncumbranceRollover.BasedOn.REMAINING).withOrderType(EncumbranceRollover.OrderType.ONE_TIME).withIncreaseBy(10d);
    LedgerFiscalYearRollover rollover = new LedgerFiscalYearRollover().withFromFiscalYearId(fromFyId).withToFiscalYearId(toFyId).withEncumbrancesRollover(Collections.singletonList(encumbranceRollover));
    CompositePurchaseOrder compPO = new CompositePurchaseOrder().withId(orderId).withOrderType(CompositePurchaseOrder.OrderType.ONE_TIME);
    Transaction fromEncumbrance1 = new Transaction().withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId)).withAmount(10d).withFiscalYearId(fromFyId).withFromFundId(fund1Id).withId(UUID.randomUUID().toString()).withCurrency("USD");
    Transaction fromEncumbrance2 = new Transaction().withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId)).withAmount(100d).withFiscalYearId(fromFyId).withFromFundId(fund2Id).withId(UUID.randomUUID().toString()).withCurrency("USD");
    FundDistribution fundDistribution1 = new FundDistribution().withFundId(fund1Id).withEncumbrance(fromEncumbrance1.getId());
    FundDistribution fundDistribution2 = new FundDistribution().withFundId(fund2Id).withEncumbrance(fromEncumbrance2.getId());
    CompositePoLine line1 = new CompositePoLine().withId(UUID.randomUUID().toString()).withFundDistribution(Collections.singletonList(fundDistribution1));
    CompositePoLine line2 = new CompositePoLine().withId(UUID.randomUUID().toString()).withFundDistribution(Collections.singletonList(fundDistribution2));
    Transaction toEncumbrance1 = new Transaction().withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withSourcePoLineId(line1.getId())).withId(UUID.randomUUID().toString()).withFiscalYearId(toFyId).withFromFundId(fund1Id).withCurrency("USD");
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withPurchaseOrder(compPO).withRollover(rollover).withPoLine(line1).withFundDistribution(fundDistribution1).withEncumbranceRollover(encumbranceRollover);
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withPurchaseOrder(compPO).withRollover(rollover).withPoLine(line2).withFundDistribution(fundDistribution2).withEncumbranceRollover(encumbranceRollover);
    List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2);
    TransactionCollection fromTransactionCollection = new TransactionCollection().withTransactions(Arrays.asList(fromEncumbrance1, fromEncumbrance2)).withTotalRecords(2);
    TransactionCollection toTransactionCollection = new TransactionCollection().withTransactions(Collections.singletonList(toEncumbrance1)).withTotalRecords(1);
    when(transactionService.getTransactions(contains(fromFyId), anyInt(), anyInt(), any())).thenReturn(CompletableFuture.completedFuture(fromTransactionCollection));
    when(transactionService.getTransactions(contains(toFyId), anyInt(), anyInt(), any())).thenReturn(CompletableFuture.completedFuture(toTransactionCollection));
    List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withPreviousFyEncumbrances(holders, requestContext).join();
    assertThat(resultHolders, hasItem(hasProperty("previousFyEncumbrance", is(fromEncumbrance1))));
    assertThat(resultHolders, hasItem(hasProperty("previousFyEncumbrance", is(fromEncumbrance2))));
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) EncumbranceRollover(org.folio.rest.jaxrs.model.EncumbranceRollover) TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) Transaction(org.folio.rest.acq.model.finance.Transaction) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LedgerFiscalYearRollover(org.folio.rest.jaxrs.model.LedgerFiscalYearRollover) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) Test(org.junit.jupiter.api.Test)

Example 5 with EncumbranceRollover

use of org.folio.rest.jaxrs.model.EncumbranceRollover in project mod-orders by folio-org.

the class ReEncumbranceHoldersBuilderTest method shouldPopulateReEncumbranceHoldersWithFromFyEncumbrancesWhenBasedOnExpended.

@Test
void shouldPopulateReEncumbranceHoldersWithFromFyEncumbrancesWhenBasedOnExpended() {
    String fromFyId = UUID.randomUUID().toString();
    String toFyId = UUID.randomUUID().toString();
    String orderId = UUID.randomUUID().toString();
    String fund1Id = UUID.randomUUID().toString();
    String fund2Id = UUID.randomUUID().toString();
    EncumbranceRollover encumbranceRollover = new EncumbranceRollover().withBasedOn(EncumbranceRollover.BasedOn.EXPENDED).withOrderType(EncumbranceRollover.OrderType.ONE_TIME).withIncreaseBy(0d);
    LedgerFiscalYearRollover rollover = new LedgerFiscalYearRollover().withFromFiscalYearId(fromFyId).withToFiscalYearId(toFyId).withEncumbrancesRollover(Collections.singletonList(encumbranceRollover));
    CompositePurchaseOrder compPO = new CompositePurchaseOrder().withId(orderId).withOrderType(CompositePurchaseOrder.OrderType.ONE_TIME);
    Transaction fromEncumbrance1 = new Transaction().withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withAmountExpended(20d)).withAmount(10d).withFiscalYearId(fromFyId).withFromFundId(fund1Id).withId(UUID.randomUUID().toString()).withCurrency("USD");
    Transaction fromEncumbrance2 = new Transaction().withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withAmountExpended(10d)).withAmount(100d).withFiscalYearId(fromFyId).withFromFundId(fund2Id).withId(UUID.randomUUID().toString()).withCurrency("USD");
    FundDistribution fundDistribution1 = new FundDistribution().withFundId(fund1Id).withEncumbrance(fromEncumbrance1.getId());
    FundDistribution fundDistribution2 = new FundDistribution().withFundId(fund2Id).withEncumbrance(fromEncumbrance2.getId());
    CompositePoLine line1 = new CompositePoLine().withId(UUID.randomUUID().toString()).withFundDistribution(Collections.singletonList(fundDistribution1));
    CompositePoLine line2 = new CompositePoLine().withId(UUID.randomUUID().toString()).withFundDistribution(Collections.singletonList(fundDistribution2));
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withPurchaseOrder(compPO).withRollover(rollover).withPoLine(line1).withFundDistribution(fundDistribution1).withEncumbranceRollover(encumbranceRollover);
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withPurchaseOrder(compPO).withRollover(rollover).withPoLine(line2).withFundDistribution(fundDistribution2).withEncumbranceRollover(encumbranceRollover);
    List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2);
    TransactionCollection fromTransactionCollection = new TransactionCollection().withTransactions(Arrays.asList(fromEncumbrance1, fromEncumbrance2)).withTotalRecords(2);
    TransactionCollection toTransactionCollection = new TransactionCollection().withTransactions(Collections.emptyList()).withTotalRecords(0);
    when(transactionService.getTransactions(contains(fromFyId), anyInt(), anyInt(), any())).thenReturn(CompletableFuture.completedFuture(fromTransactionCollection));
    when(transactionService.getTransactions(contains(toFyId), anyInt(), anyInt(), any())).thenReturn(CompletableFuture.completedFuture(toTransactionCollection));
    List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withPreviousFyEncumbrances(holders, requestContext).join();
    assertThat(resultHolders, hasItem(hasProperty("previousFyEncumbrance", is(fromEncumbrance1))));
    assertThat(resultHolders, hasItem(hasProperty("previousFyEncumbrance", is(fromEncumbrance2))));
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) EncumbranceRollover(org.folio.rest.jaxrs.model.EncumbranceRollover) TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) Transaction(org.folio.rest.acq.model.finance.Transaction) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LedgerFiscalYearRollover(org.folio.rest.jaxrs.model.LedgerFiscalYearRollover) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) Test(org.junit.jupiter.api.Test)

Aggregations

EncumbranceRollover (org.folio.rest.jaxrs.model.EncumbranceRollover)12 LedgerFiscalYearRollover (org.folio.rest.jaxrs.model.LedgerFiscalYearRollover)11 Test (org.junit.jupiter.api.Test)11 ReEncumbranceHolder (org.folio.models.ReEncumbranceHolder)9 Transaction (org.folio.rest.acq.model.finance.Transaction)8 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)8 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)8 Encumbrance (org.folio.rest.acq.model.finance.Encumbrance)7 TransactionCollection (org.folio.rest.acq.model.finance.TransactionCollection)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 Cost (org.folio.rest.jaxrs.model.Cost)5 ConversionQuery (javax.money.convert.ConversionQuery)4 Fund (org.folio.rest.acq.model.finance.Fund)4 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)4 ManualCurrencyConversion (org.folio.service.exchange.ManualCurrencyConversion)4 ExchangeRate (javax.money.convert.ExchangeRate)3 ExchangeRateProvider (javax.money.convert.ExchangeRateProvider)3 PoLine (org.folio.rest.jaxrs.model.PoLine)3 PurchaseOrder (org.folio.rest.jaxrs.model.PurchaseOrder)3 PurchaseOrderCollection (org.folio.rest.jaxrs.model.PurchaseOrderCollection)3