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());
}
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());
}
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));
}
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();
}
}
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);
}
Aggregations