Search in sources :

Example 6 with EncumbranceRelationsHolder

use of org.folio.models.EncumbranceRelationsHolder in project mod-orders by folio-org.

the class EncumbranceRelationsHoldersBuilderTest method testShouldPopulateHoldersWithFiscalYearData.

@Test
void testShouldPopulateHoldersWithFiscalYearData() {
    // given
    String fiscalYearId = UUID.randomUUID().toString();
    FiscalYear fiscalYear = new FiscalYear().withId(fiscalYearId).withCurrency("RUB");
    Budget budget1 = new Budget().withId(UUID.randomUUID().toString()).withFundId(holder1.getFundId()).withFiscalYearId(fiscalYearId);
    Budget budget2 = new Budget().withId(UUID.randomUUID().toString()).withFundId(holder2.getFundId()).withFiscalYearId(fiscalYearId);
    Budget budget3 = new Budget().withId(UUID.randomUUID().toString()).withFundId(holder3.getFundId()).withFiscalYearId(fiscalYearId);
    List<EncumbranceRelationsHolder> holders = new ArrayList<>();
    holders.add(holder1.withBudget(budget1));
    holders.add(holder2.withBudget(budget2));
    holders.add(holder3.withBudget(budget3));
    when(fiscalYearService.getFiscalYearById(anyString(), any())).thenReturn(CompletableFuture.completedFuture(fiscalYear));
    // When
    List<EncumbranceRelationsHolder> resultHolders = encumbranceRelationsHoldersBuilder.withFiscalYearData(holders, requestContextMock).join();
    // Then
    assertThat(resultHolders, everyItem(hasProperty("newEncumbrance", allOf(hasProperty("fiscalYearId", is(fiscalYear.getId())), hasProperty("currency", is(fiscalYear.getCurrency()))))));
}
Also used : FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) EncumbranceRelationsHolder(org.folio.models.EncumbranceRelationsHolder) ArrayList(java.util.ArrayList) Budget(org.folio.rest.acq.model.finance.Budget) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 7 with EncumbranceRelationsHolder

use of org.folio.models.EncumbranceRelationsHolder in project mod-orders by folio-org.

the class BudgetRestrictionServiceTest method checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceGreaterThanBudgetRemainingAmountAndBudgetAllowableExpenditureIsNull.

@Test
void checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceGreaterThanBudgetRemainingAmountAndBudgetAllowableExpenditureIsNull() {
    String fiscalYearId = UUID.randomUUID().toString();
    String fundId = UUID.randomUUID().toString();
    String budgetId = UUID.randomUUID().toString();
    Transaction existingTransaction = new Transaction().withTransactionType(Transaction.TransactionType.ENCUMBRANCE).withAmount(50d).withFiscalYearId(fiscalYearId).withFromFundId(fundId).withCurrency("USD");
    Transaction newTransaction = new Transaction().withTransactionType(Transaction.TransactionType.ENCUMBRANCE).withAmount(60d).withFiscalYearId(fiscalYearId).withFromFundId(fundId).withCurrency("USD");
    Budget budget = new Budget().withId(budgetId).withFiscalYearId(fiscalYearId).withFundId(fundId).withAllocated(59d).withTotalFunding(59d).withAvailable(0d).withUnavailable(50d).withAwaitingPayment(50D).withAllowableEncumbrance(null);
    List<EncumbranceRelationsHolder> holders = new ArrayList<>();
    EncumbranceRelationsHolder holder = new EncumbranceRelationsHolder().withOldEncumbrance(existingTransaction).withNewEncumbrance(newTransaction).withBudget(budget).withRestrictEncumbrances(true).withCurrentFiscalYearId(fiscalYearId).withCurrency("USD");
    holders.add(holder);
    assertDoesNotThrow(() -> restrictionService.checkEncumbranceRestrictions(holders));
}
Also used : Transaction(org.folio.rest.acq.model.finance.Transaction) EncumbranceRelationsHolder(org.folio.models.EncumbranceRelationsHolder) ArrayList(java.util.ArrayList) Budget(org.folio.rest.acq.model.finance.Budget) Test(org.junit.jupiter.api.Test)

Example 8 with EncumbranceRelationsHolder

use of org.folio.models.EncumbranceRelationsHolder in project mod-orders by folio-org.

the class BudgetRestrictionServiceTest method checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceLessThanBudgetRemainingAmount.

@Test
void checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceLessThanBudgetRemainingAmount() {
    String fiscalYearId = UUID.randomUUID().toString();
    String fundId = UUID.randomUUID().toString();
    String ledgerId = UUID.randomUUID().toString();
    String budgetId = UUID.randomUUID().toString();
    Transaction existingTransaction = new Transaction().withTransactionType(Transaction.TransactionType.ENCUMBRANCE).withAmount(50d).withFiscalYearId(fiscalYearId).withFromFundId(fundId).withCurrency("USD");
    Transaction newTransaction = new Transaction().withTransactionType(Transaction.TransactionType.ENCUMBRANCE).withAmount(60d).withFiscalYearId(fiscalYearId).withFromFundId(fundId).withCurrency("USD");
    Budget budget = new Budget().withId(budgetId).withFiscalYearId(fiscalYearId).withFundId(fundId).withAllocated(59d).withAvailable(9d).withTotalFunding(59d).withUnavailable(50d).withAwaitingPayment(50D).withAllowableEncumbrance(150d);
    Fund fund = new Fund().withId(fundId).withLedgerId(ledgerId);
    Ledger ledger = new Ledger().withId(ledgerId).withRestrictEncumbrance(true);
    List<EncumbranceRelationsHolder> holders = new ArrayList<>();
    EncumbranceRelationsHolder holder = new EncumbranceRelationsHolder().withOldEncumbrance(existingTransaction).withNewEncumbrance(newTransaction).withBudget(budget).withLedgerId(fund.getLedgerId()).withRestrictEncumbrances(ledger.getRestrictExpenditures()).withCurrentFiscalYearId(fiscalYearId).withCurrency("USD");
    holders.add(holder);
    assertDoesNotThrow(() -> restrictionService.checkEncumbranceRestrictions(holders));
}
Also used : Transaction(org.folio.rest.acq.model.finance.Transaction) Fund(org.folio.rest.acq.model.finance.Fund) Ledger(org.folio.rest.acq.model.finance.Ledger) EncumbranceRelationsHolder(org.folio.models.EncumbranceRelationsHolder) ArrayList(java.util.ArrayList) Budget(org.folio.rest.acq.model.finance.Budget) Test(org.junit.jupiter.api.Test)

Example 9 with EncumbranceRelationsHolder

use of org.folio.models.EncumbranceRelationsHolder in project mod-orders by folio-org.

the class PendingToPendingEncumbranceStrategy method distributeHoldersByOperation.

private EncumbrancesProcessingHolder distributeHoldersByOperation(List<EncumbranceRelationsHolder> encumbranceRelationsHolders) {
    EncumbrancesProcessingHolder holder = new EncumbrancesProcessingHolder();
    holder.withEncumbrancesFromStorage(encumbranceRelationsHolders.stream().map(EncumbranceRelationsHolder::getOldEncumbrance).filter(Objects::nonNull).collect(toList()));
    List<EncumbranceRelationsHolder> toDelete = getTransactionsToDelete(encumbranceRelationsHolders);
    List<Transaction> toRelease = toDelete.stream().map(EncumbranceRelationsHolder::getOldEncumbrance).collect(toList());
    holder.withEncumbrancesForRelease(toRelease);
    holder.withEncumbrancesForDelete(toDelete);
    return holder;
}
Also used : Transaction(org.folio.rest.acq.model.finance.Transaction) Objects(java.util.Objects) EncumbranceRelationsHolder(org.folio.models.EncumbranceRelationsHolder) EncumbrancesProcessingHolder(org.folio.models.EncumbrancesProcessingHolder)

Example 10 with EncumbranceRelationsHolder

use of org.folio.models.EncumbranceRelationsHolder in project mod-orders by folio-org.

the class EncumbrancesProcessingHolderBuilder method distributeHoldersByOperation.

protected EncumbrancesProcessingHolder distributeHoldersByOperation(List<EncumbranceRelationsHolder> encumbranceRelationsHolders) {
    EncumbrancesProcessingHolder holder = new EncumbrancesProcessingHolder();
    holder.withEncumbrancesForCreate(getToBeCreatedHolders(encumbranceRelationsHolders));
    holder.withEncumbrancesForUpdate(getToBeUpdatedHolders(encumbranceRelationsHolders));
    List<EncumbranceRelationsHolder> toDelete = getTransactionsToDelete(encumbranceRelationsHolders);
    holder.withEncumbrancesForDelete(toDelete);
    // also release transaction before delete
    List<Transaction> toRelease = toDelete.stream().map(EncumbranceRelationsHolder::getOldEncumbrance).collect(toList());
    holder.withEncumbrancesForRelease(toRelease);
    holder.withEncumbrancesFromStorage(encumbranceRelationsHolders.stream().map(EncumbranceRelationsHolder::getOldEncumbrance).filter(Objects::nonNull).collect(toList()));
    return holder;
}
Also used : Transaction(org.folio.rest.acq.model.finance.Transaction) EncumbranceRelationsHolder(org.folio.models.EncumbranceRelationsHolder) Objects(java.util.Objects) EncumbrancesProcessingHolder(org.folio.models.EncumbrancesProcessingHolder)

Aggregations

EncumbranceRelationsHolder (org.folio.models.EncumbranceRelationsHolder)24 Transaction (org.folio.rest.acq.model.finance.Transaction)18 Test (org.junit.jupiter.api.Test)15 ArrayList (java.util.ArrayList)13 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)12 Budget (org.folio.rest.acq.model.finance.Budget)11 Encumbrance (org.folio.rest.acq.model.finance.Encumbrance)10 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)9 Objects (java.util.Objects)8 List (java.util.List)7 MonetaryAmount (javax.money.MonetaryAmount)7 Map (java.util.Map)6 CurrencyConversion (javax.money.convert.CurrencyConversion)6 Cost (org.folio.rest.jaxrs.model.Cost)6 Optional (java.util.Optional)5 Collectors (java.util.stream.Collectors)5 Collectors.toList (java.util.stream.Collectors.toList)5 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)5 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)4 Fund (org.folio.rest.acq.model.finance.Fund)4