use of org.folio.rest.acq.model.finance.Fund in project mod-invoice by folio-org.
the class FundAvailabilityHolderValidatorTest method checkEnoughMoneyInBudgetShouldThrowFundCannotBePaidIfTransactionsAmountDifferenceGreaterThanBudgetRemainingAmount.
@Test
void checkEnoughMoneyInBudgetShouldThrowFundCannotBePaidIfTransactionsAmountDifferenceGreaterThanBudgetRemainingAmount() {
String fiscalYearId = UUID.randomUUID().toString();
String fundId = UUID.randomUUID().toString();
String budgetId = UUID.randomUUID().toString();
String ledgerId = UUID.randomUUID().toString();
Transaction existingTransaction = new Transaction().withTransactionType(Transaction.TransactionType.PENDING_PAYMENT).withAmount(50d).withFiscalYearId(fiscalYearId).withFromFundId(fundId).withCurrency("USD");
Transaction newTransaction = new Transaction().withTransactionType(Transaction.TransactionType.PENDING_PAYMENT).withAmount(60d).withFiscalYearId(fiscalYearId).withFromFundId(fundId).withCurrency("USD");
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(59d).withTotalFunding(59d).withAvailable(9d).withUnavailable(50d).withAwaitingPayment(50D).withAllowableExpenditure(100d);
List<InvoiceWorkflowDataHolder> holders = new ArrayList<>();
InvoiceWorkflowDataHolder holder = new InvoiceWorkflowDataHolder().withFund(fund).withExistingTransaction(existingTransaction).withNewTransaction(newTransaction).withBudget(budget).withRestrictExpenditures(true).withFiscalYear(new FiscalYear().withId(fiscalYearId).withCurrency("USD"));
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());
}
use of org.folio.rest.acq.model.finance.Fund in project mod-invoice by folio-org.
the class FundAvailabilityHolderValidatorTest method checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceGreaterThanBudgetRemainingAmountAndBudgetAllowableExpenditureIsNull.
@Test
void checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceGreaterThanBudgetRemainingAmountAndBudgetAllowableExpenditureIsNull() {
String fiscalYearId = UUID.randomUUID().toString();
String fundId = UUID.randomUUID().toString();
String budgetId = UUID.randomUUID().toString();
String ledgerId = UUID.randomUUID().toString();
Transaction existingTransaction = new Transaction().withTransactionType(Transaction.TransactionType.PENDING_PAYMENT).withAmount(50d).withFiscalYearId(fiscalYearId).withFromFundId(fundId).withCurrency("USD");
Transaction newTransaction = new Transaction().withTransactionType(Transaction.TransactionType.PENDING_PAYMENT).withAmount(60d).withFiscalYearId(fiscalYearId).withFromFundId(fundId).withCurrency("USD");
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(59d).withTotalFunding(59d).withAvailable(0d).withUnavailable(50d).withAwaitingPayment(50D).withAllowableExpenditure(null);
List<InvoiceWorkflowDataHolder> holders = new ArrayList<>();
InvoiceWorkflowDataHolder holder = new InvoiceWorkflowDataHolder().withFund(fund).withExistingTransaction(existingTransaction).withNewTransaction(newTransaction).withBudget(budget).withRestrictExpenditures(true).withFiscalYear(new FiscalYear().withId(fiscalYearId).withCurrency("USD"));
holders.add(holder);
assertDoesNotThrow(() -> fundAvailabilityValidator.validate(holders));
}
use of org.folio.rest.acq.model.finance.Fund 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());
}
use of org.folio.rest.acq.model.finance.Fund in project mod-invoice by folio-org.
the class InvoicesApiTest method testTransitionFromOpenToApprovedWithoutSpecifiedAllowableExpenditure.
@Test
void testTransitionFromOpenToApprovedWithoutSpecifiedAllowableExpenditure() {
Invoice reqData = getMockAsJson(OPEN_INVOICE_SAMPLE_PATH).mapTo(Invoice.class);
String id = reqData.getId();
InvoiceLine invoiceLine = getMinimalContentInvoiceLine(id);
invoiceLine.setSubTotal(50d);
invoiceLine.setId(UUID.randomUUID().toString());
String fundId = UUID.randomUUID().toString();
Budget budget = new Budget().withId(UUID.randomUUID().toString()).withFundId(fundId).withFiscalYearId(FISCAL_YEAR_ID).withAllocated(45d).withAvailable(45d).withBudgetStatus(BudgetStatus.ACTIVE).withUnavailable(0d);
Fund fund = new Fund().withId(fundId).withName("test").withLedgerId(EXISTING_LEDGER_ID).withCode("FC").withExternalAccountNo("1234").withFundStatus(Fund.FundStatus.ACTIVE);
FundDistribution amountDistribution = new FundDistribution().withFundId(fundId).withDistributionType(AMOUNT).withValue(50d);
invoiceLine.getFundDistributions().add(amountDistribution);
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
addMockEntry(BUDGETS, JsonObject.mapFrom(budget));
addMockEntry(FUNDS, JsonObject.mapFrom(fund));
reqData.setStatus(Invoice.Status.APPROVED);
String jsonBody = JsonObject.mapFrom(reqData).encode();
Headers headers = prepareHeaders(X_OKAPI_URL, X_OKAPI_TENANT, X_OKAPI_TOKEN, X_OKAPI_USER_ID);
verifyPut(String.format(INVOICE_ID_PATH, id), jsonBody, headers, "", 204);
}
use of org.folio.rest.acq.model.finance.Fund in project mod-invoice by folio-org.
the class InvoicesApiTest method testTransitionToApprovedWithExistingVoucherAndVoucherLines.
@Test
void testTransitionToApprovedWithExistingVoucherAndVoucherLines() {
logger.info("=== Test transition invoice to Approved with existing voucher and voucherLines ===");
InvoiceLine invoiceLine = getMockAsJson(INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH).mapTo(InvoiceLine.class);
Invoice reqData = getMockAsJson(REVIEWED_INVOICE_WITH_EXISTING_VOUCHER_SAMPLE_PATH).mapTo(Invoice.class);
invoiceLine.setId(UUID.randomUUID().toString());
invoiceLine.setInvoiceId(reqData.getId());
invoiceLine.getFundDistributions().forEach(fundDistribution -> fundDistribution.setCode(null));
prepareMockVoucher(reqData.getId());
VoucherLine voucherLine = new VoucherLine().withVoucherId(EXISTING_VOUCHER_ID);
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
addMockEntry(VOUCHER_LINES, JsonObject.mapFrom(voucherLine));
reqData.setStatus(Invoice.Status.APPROVED);
String id = reqData.getId();
String jsonBody = JsonObject.mapFrom(reqData).encode();
Headers headers = prepareHeaders(X_OKAPI_TENANT, X_OKAPI_USER_ID);
verifyPut(String.format(INVOICE_ID_PATH, id), jsonBody, headers, "", 204);
List<JsonObject> vouchersUpdated = serverRqRs.get(VOUCHERS_STORAGE, HttpMethod.PUT);
List<JsonObject> voucherLinesDeletions = serverRqRs.get(VOUCHER_LINES, HttpMethod.DELETE);
List<JsonObject> voucherLinesSearches = serverRqRs.get(VOUCHER_LINES, HttpMethod.GET);
assertThat(vouchersUpdated, notNullValue());
assertThat(vouchersUpdated, hasSize(1));
assertThat(voucherLinesDeletions, notNullValue());
assertThat(voucherLinesSearches, notNullValue());
assertThat(voucherLinesSearches, hasSize(1));
VoucherLineCollection voucherLineCollection = voucherLinesSearches.get(0).mapTo(VoucherLineCollection.class);
assertThat(voucherLinesDeletions, hasSize(voucherLineCollection.getTotalRecords()));
Voucher updatedVoucher = vouchersUpdated.get(0).mapTo(Voucher.class);
Invoice updatedInvoice = serverRqRs.get(INVOICES, HttpMethod.PUT).get(0).mapTo(Invoice.class);
List<JsonObject> fundsSearches = serverRqRs.get(FUNDS, HttpMethod.GET);
List<Fund> funds = fundsSearches.get(0).mapTo(FundCollection.class).getFunds();
verifyTransitionToApproved(updatedVoucher, Collections.singletonList(invoiceLine), updatedInvoice, getExpectedVoucherLinesQuantity(funds));
}
Aggregations