Search in sources :

Example 16 with Budget

use of org.folio.rest.acq.model.finance.Budget in project mod-orders by folio-org.

the class BudgetRestrictionServiceTest method checkEnoughMoneyInBudgetShouldThrowFundCannotBePaidIfTransactionsAmountDifferenceGreaterThanBudgetRemainingAmount.

@Test
void checkEnoughMoneyInBudgetShouldThrowFundCannotBePaidIfTransactionsAmountDifferenceGreaterThanBudgetRemainingAmount() {
    String fiscalYearId = UUID.randomUUID().toString();
    String fundId = UUID.randomUUID().toString();
    String budgetId = UUID.randomUUID().toString();
    String fundCode = "TEST-FUND";
    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(9d).withUnavailable(50d).withAwaitingPayment(50D).withAllowableEncumbrance(100d);
    List<EncumbranceRelationsHolder> holders = new ArrayList<>();
    FundDistribution fundDistribution = new FundDistribution().withFundId(fundId).withCode(fundCode);
    EncumbranceRelationsHolder holder = new EncumbranceRelationsHolder().withOldEncumbrance(existingTransaction).withNewEncumbrance(newTransaction).withBudget(budget).withRestrictEncumbrances(true).withCurrentFiscalYearId(fiscalYearId).withCurrency("USD").withFundDistribution(fundDistribution);
    holders.add(holder);
    HttpException httpException = assertThrows(HttpException.class, () -> restrictionService.checkEncumbranceRestrictions(holders));
    assertEquals(422, httpException.getCode());
    Error error = httpException.getError();
    assertEquals(FUND_CANNOT_BE_PAID.getCode(), error.getCode());
    assertEquals(Collections.singletonList(fundCode).toString(), error.getParameters().get(0).getValue());
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Transaction(org.folio.rest.acq.model.finance.Transaction) EncumbranceRelationsHolder(org.folio.models.EncumbranceRelationsHolder) ArrayList(java.util.ArrayList) Error(org.folio.rest.jaxrs.model.Error) Budget(org.folio.rest.acq.model.finance.Budget) HttpException(org.folio.rest.core.exceptions.HttpException) Test(org.junit.jupiter.api.Test)

Example 17 with Budget

use of org.folio.rest.acq.model.finance.Budget in project mod-orders by folio-org.

the class BudgetRestrictionServiceTest method checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountGreaterThanBudgetRemainingAmountAndBudgetRestricted.

@Test
void checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountGreaterThanBudgetRemainingAmountAndBudgetRestricted() {
    String fiscalYearId = UUID.randomUUID().toString();
    String fundId = UUID.randomUUID().toString();
    String budgetId = UUID.randomUUID().toString();
    String fundCode = "TEST-FUND";
    Transaction newTransaction = new Transaction().withTransactionType(Transaction.TransactionType.ENCUMBRANCE).withAmount(10d).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(100d);
    List<EncumbranceRelationsHolder> holders = new ArrayList<>();
    FundDistribution fundDistribution = new FundDistribution().withFundId(fundId).withCode(fundCode);
    EncumbranceRelationsHolder holder = new EncumbranceRelationsHolder().withOldEncumbrance(null).withNewEncumbrance(newTransaction).withBudget(budget).withRestrictEncumbrances(true).withCurrentFiscalYearId(fiscalYearId).withCurrency("USD").withFundDistribution(fundDistribution);
    holders.add(holder);
    HttpException httpException = assertThrows(HttpException.class, () -> restrictionService.checkEncumbranceRestrictions(holders));
    assertEquals(422, httpException.getCode());
    Error error = httpException.getError();
    assertEquals(FUND_CANNOT_BE_PAID.getCode(), error.getCode());
    assertEquals(Collections.singletonList(fundCode).toString(), error.getParameters().get(0).getValue());
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Transaction(org.folio.rest.acq.model.finance.Transaction) EncumbranceRelationsHolder(org.folio.models.EncumbranceRelationsHolder) ArrayList(java.util.ArrayList) Error(org.folio.rest.jaxrs.model.Error) Budget(org.folio.rest.acq.model.finance.Budget) HttpException(org.folio.rest.core.exceptions.HttpException) Test(org.junit.jupiter.api.Test)

Example 18 with Budget

use of org.folio.rest.acq.model.finance.Budget in project mod-orders by folio-org.

the class BudgetRestrictionServiceTest method checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceGreaterThanBudgetRemainingAmountAndRestrictEncumbranceIsFalse.

@Test
void checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceGreaterThanBudgetRemainingAmountAndRestrictEncumbranceIsFalse() {
    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(100d);
    List<EncumbranceRelationsHolder> holders = new ArrayList<>();
    EncumbranceRelationsHolder holder = new EncumbranceRelationsHolder().withOldEncumbrance(existingTransaction).withNewEncumbrance(newTransaction).withBudget(budget).withRestrictEncumbrances(false).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 19 with Budget

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

the class MockServer method handleGetBudgetByFundId.

private void handleGetBudgetByFundId(RoutingContext ctx) {
    logger.info("handleGetInvoiceDocumentById got: GET " + ctx.request().path());
    String fundId = ctx.request().getParam("id");
    JsonObject collection = getBudgetsByFundIds(Collections.singletonList(fundId));
    BudgetCollection budgetCollection = collection.mapTo(BudgetCollection.class);
    if (fundId.equals(FUND_ID_WITH_NOT_ACTIVE_BUDGET)) {
        ctx.response().setStatusCode(404).end();
    } else if (budgetCollection.getTotalRecords() > 0) {
        Budget budget = budgetCollection.getBudgets().get(0);
        JsonObject budgetJson = JsonObject.mapFrom(budget);
        addServerRqRsData(HttpMethod.GET, CURRENT_BUDGET, budgetJson);
        ctx.response().setStatusCode(200).putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON).end(budgetJson.encodePrettily());
    } else {
        ctx.response().setStatusCode(404).end();
    }
}
Also used : BudgetCollection(org.folio.rest.acq.model.finance.BudgetCollection) JsonObject(io.vertx.core.json.JsonObject) Budget(org.folio.rest.acq.model.finance.Budget)

Example 20 with Budget

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

the class MockServer method getBudgetsByFundIds.

private JsonObject getBudgetsByFundIds(List<String> budgetByFundIds) {
    Supplier<List<Budget>> getFromFile = () -> {
        try {
            return new JsonObject(getMockData(BUDGETS_PATH)).mapTo(BudgetCollection.class).getBudgets();
        } catch (IOException e) {
            return Collections.emptyList();
        }
    };
    List<Budget> budgets = getMockEntries(BUDGETS, Budget.class).orElseGet(getFromFile);
    if (!budgetByFundIds.isEmpty()) {
        budgets.removeIf(item -> !budgetByFundIds.contains(item.getFundId()));
    }
    Object record = new BudgetCollection().withBudgets(budgets).withTotalRecords(budgets.size());
    return JsonObject.mapFrom(record);
}
Also used : BudgetCollection(org.folio.rest.acq.model.finance.BudgetCollection) JsonObject(io.vertx.core.json.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Budget(org.folio.rest.acq.model.finance.Budget) JsonObject(io.vertx.core.json.JsonObject) IOException(java.io.IOException)

Aggregations

Budget (org.folio.rest.acq.model.finance.Budget)26 Test (org.junit.jupiter.api.Test)19 ArrayList (java.util.ArrayList)17 Fund (org.folio.rest.acq.model.finance.Fund)14 Transaction (org.folio.rest.acq.model.finance.Transaction)12 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)10 InvoiceWorkflowDataHolder (org.folio.models.InvoiceWorkflowDataHolder)9 EncumbranceRelationsHolder (org.folio.models.EncumbranceRelationsHolder)8 FiscalYear (org.folio.rest.acq.model.finance.FiscalYear)7 Error (org.folio.rest.jaxrs.model.Error)7 List (java.util.List)6 HttpException (org.folio.invoices.rest.exceptions.HttpException)6 JsonObject (io.vertx.core.json.JsonObject)4 Collections (java.util.Collections)4 Collectors.toList (java.util.stream.Collectors.toList)4 BudgetCollection (org.folio.rest.acq.model.finance.BudgetCollection)4 Ledger (org.folio.rest.acq.model.finance.Ledger)4 Invoice (org.folio.rest.jaxrs.model.Invoice)4 InvoiceLine (org.folio.rest.jaxrs.model.InvoiceLine)4 HttpException (org.folio.rest.core.exceptions.HttpException)3