Search in sources :

Example 1 with AwaitingPayment

use of org.folio.rest.acq.model.finance.AwaitingPayment in project mod-invoice by folio-org.

the class FundAvailabilityHolderValidatorTest method shouldPassValidationWhenBudgetRestrictedAndFinalExpendedValueGreaterThenMaxBudgetExpended.

@Test
void shouldPassValidationWhenBudgetRestrictedAndFinalExpendedValueGreaterThenMaxBudgetExpended() {
    String fiscalYearId = UUID.randomUUID().toString();
    String fundId = UUID.randomUUID().toString();
    String budgetId = UUID.randomUUID().toString();
    String ledgerId = UUID.randomUUID().toString();
    FiscalYear fiscalYear = new FiscalYear().withCurrency("USD").withId(fiscalYearId);
    Fund fund = new Fund().withId(fundId).withName("TestFund").withLedgerId(ledgerId).withCode("FC").withFundStatus(Fund.FundStatus.ACTIVE);
    Budget budget = new Budget().withId(budgetId).withFiscalYearId(fiscalYearId).withFundId(fundId).withAllocated(260d).withTotalFunding(260d).withAvailable(0d).withUnavailable(290d).withEncumbered(250d).withAwaitingPayment(30d).withExpenditures(10d).withAllowableExpenditure(100d).withAllowableExpenditure(110d);
    List<InvoiceWorkflowDataHolder> holders = new ArrayList<>();
    Transaction encumbrance = new Transaction().withId(UUID.randomUUID().toString()).withAmount(250d).withCurrency("USD");
    Transaction linePendingPayment = new Transaction().withAmount(245d).withAwaitingPayment(new AwaitingPayment().withEncumbranceId(encumbrance.getId()).withReleaseEncumbrance(false)).withCurrency("USD");
    InvoiceWorkflowDataHolder holder = new InvoiceWorkflowDataHolder().withFund(fund).withBudget(budget).withRestrictExpenditures(true).withFiscalYear(fiscalYear).withNewTransaction(linePendingPayment).withEncumbrance(encumbrance);
    holders.add(holder);
    HttpException httpException = assertThrows(HttpException.class, () -> fundAvailabilityValidator.validate(holders));
    assertEquals(422, httpException.getCode());
    Error error = httpException.getErrors().getErrors().get(0);
    assertEquals(FUND_CANNOT_BE_PAID.getCode(), error.getCode());
    assertEquals(Collections.singletonList("FC").toString(), error.getParameters().get(0).getValue());
}
Also used : FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) Fund(org.folio.rest.acq.model.finance.Fund) Transaction(org.folio.rest.acq.model.finance.Transaction) InvoiceWorkflowDataHolder(org.folio.models.InvoiceWorkflowDataHolder) ArrayList(java.util.ArrayList) Error(org.folio.rest.jaxrs.model.Error) Budget(org.folio.rest.acq.model.finance.Budget) HttpException(org.folio.invoices.rest.exceptions.HttpException) AwaitingPayment(org.folio.rest.acq.model.finance.AwaitingPayment) Test(org.junit.jupiter.api.Test)

Example 2 with AwaitingPayment

use of org.folio.rest.acq.model.finance.AwaitingPayment in project mod-invoice by folio-org.

the class PendingPaymentWorkflowService method buildTransaction.

private Transaction buildTransaction(InvoiceWorkflowDataHolder holder) {
    MonetaryAmount amount = getFundDistributionAmount(holder.getFundDistribution(), holder.getTotal(), holder.getInvoiceCurrency()).with(holder.getConversion());
    AwaitingPayment awaitingPayment = null;
    FundDistribution fundDistribution = holder.getFundDistribution();
    if (fundDistribution.getEncumbrance() != null) {
        boolean releaseEncumbrance = Optional.ofNullable(holder.getInvoiceLine()).map(InvoiceLine::getReleaseEncumbrance).orElse(false);
        awaitingPayment = new AwaitingPayment().withEncumbranceId(fundDistribution.getEncumbrance()).withReleaseEncumbrance(releaseEncumbrance);
    }
    String transactionId = Optional.ofNullable(holder.getExistingTransaction()).map(Transaction::getId).orElse(null);
    return buildBaseTransaction(holder).withId(transactionId).withTransactionType(Transaction.TransactionType.PENDING_PAYMENT).withAwaitingPayment(awaitingPayment).withAmount(convertToDoubleWithRounding(amount)).withSourceInvoiceLineId(holder.getInvoiceLineId());
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) MonetaryAmount(javax.money.MonetaryAmount) AwaitingPayment(org.folio.rest.acq.model.finance.AwaitingPayment)

Example 3 with AwaitingPayment

use of org.folio.rest.acq.model.finance.AwaitingPayment in project mod-invoice by folio-org.

the class FundAvailabilityHolderValidatorTest method shouldPassValidationWhenBudgetRestrictedAndAmountGreaterThanAvailableAndRequiredAmountEncumbered.

@Test
void shouldPassValidationWhenBudgetRestrictedAndAmountGreaterThanAvailableAndRequiredAmountEncumbered() {
    String fiscalYearId = UUID.randomUUID().toString();
    String fundId = UUID.randomUUID().toString();
    String budgetId = UUID.randomUUID().toString();
    String ledgerId = UUID.randomUUID().toString();
    FiscalYear fiscalYear = new FiscalYear().withCurrency("USD").withId(fiscalYearId);
    Fund fund = new Fund().withId(fundId).withName("TestFund").withLedgerId(ledgerId).withCode("FC").withFundStatus(Fund.FundStatus.ACTIVE);
    Budget budget = new Budget().withId(budgetId).withFiscalYearId(fiscalYearId).withFundId(fundId).withAllocated(260d).withTotalFunding(260d).withAvailable(20d).withUnavailable(240d).withEncumbered(200d).withAwaitingPayment(40d).withAllowableExpenditure(100d);
    List<InvoiceWorkflowDataHolder> holders = new ArrayList<>();
    Transaction adjustmentPendingPayment = new Transaction().withAmount(20d).withCurrency("USD");
    Transaction encumbrance = new Transaction().withId(UUID.randomUUID().toString()).withAmount(200d).withCurrency("USD");
    Transaction linePendingPayment = new Transaction().withAmount(200d).withAwaitingPayment(new AwaitingPayment().withEncumbranceId(encumbrance.getId()).withReleaseEncumbrance(false)).withCurrency("USD");
    InvoiceWorkflowDataHolder holder1 = new InvoiceWorkflowDataHolder().withFund(fund).withBudget(budget).withRestrictExpenditures(true).withFiscalYear(fiscalYear).withNewTransaction(linePendingPayment).withEncumbrance(encumbrance);
    InvoiceWorkflowDataHolder holder2 = new InvoiceWorkflowDataHolder().withFund(fund).withBudget(budget).withRestrictExpenditures(true).withFiscalYear(fiscalYear).withNewTransaction(adjustmentPendingPayment);
    holders.add(holder1);
    holders.add(holder2);
    assertDoesNotThrow(() -> fundAvailabilityValidator.validate(holders));
}
Also used : FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) Fund(org.folio.rest.acq.model.finance.Fund) Transaction(org.folio.rest.acq.model.finance.Transaction) InvoiceWorkflowDataHolder(org.folio.models.InvoiceWorkflowDataHolder) ArrayList(java.util.ArrayList) Budget(org.folio.rest.acq.model.finance.Budget) AwaitingPayment(org.folio.rest.acq.model.finance.AwaitingPayment) Test(org.junit.jupiter.api.Test)

Aggregations

AwaitingPayment (org.folio.rest.acq.model.finance.AwaitingPayment)3 ArrayList (java.util.ArrayList)2 InvoiceWorkflowDataHolder (org.folio.models.InvoiceWorkflowDataHolder)2 Budget (org.folio.rest.acq.model.finance.Budget)2 FiscalYear (org.folio.rest.acq.model.finance.FiscalYear)2 Fund (org.folio.rest.acq.model.finance.Fund)2 Transaction (org.folio.rest.acq.model.finance.Transaction)2 Test (org.junit.jupiter.api.Test)2 MonetaryAmount (javax.money.MonetaryAmount)1 HttpException (org.folio.invoices.rest.exceptions.HttpException)1 Error (org.folio.rest.jaxrs.model.Error)1 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)1