use of org.folio.rest.acq.model.finance.Budget in project mod-invoice by folio-org.
the class BudgetExpenseClassService method checkExpenseClass.
private CompletableFuture<Void> checkExpenseClass(InvoiceWorkflowDataHolder holder, RequestContext requestContext) {
Budget budget = holder.getBudget();
FundDistribution fundDistribution = holder.getFundDistribution();
String query = String.format("budgetId==%s and expenseClassId==%s", budget.getId(), fundDistribution.getExpenseClassId());
RequestEntry requestEntry = new RequestEntry(BUDGET_EXPENSE_CLASS_ENDPOINT).withQuery(query).withOffset(0).withLimit(1);
return restClient.get(requestEntry, requestContext, BudgetExpenseClassCollection.class).thenAccept(budgetExpenseClasses -> {
checkExpenseClassAssignedToBudget(holder, budgetExpenseClasses);
checkExpenseClassActive(holder, budgetExpenseClasses);
});
}
use of org.folio.rest.acq.model.finance.Budget in project mod-orders by folio-org.
the class ReEncumbranceHoldersBuilderTest method shouldPopulateReEncumbranceHoldersWithCorrespondingBudgetsForEveryHolderWithLedgerId.
@Test
void shouldPopulateReEncumbranceHoldersWithCorrespondingBudgetsForEveryHolderWithLedgerId() {
Fund fund1 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(UUID.randomUUID().toString());
Fund fund2 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(UUID.randomUUID().toString());
FundDistribution distribution1 = new FundDistribution().withFundId(fund1.getId());
FundDistribution distribution2 = new FundDistribution().withFundId(fund2.getId());
FundDistribution distribution3 = new FundDistribution().withFundId(UUID.randomUUID().toString());
ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withLedgerId(fund1.getLedgerId()).withFundDistribution(distribution1);
ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withLedgerId(fund2.getLedgerId()).withFundDistribution(distribution2);
ReEncumbranceHolder holder3 = new ReEncumbranceHolder().withFundDistribution(distribution3);
List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2, holder3);
Budget budget1 = new Budget().withId(UUID.randomUUID().toString()).withFundId(fund1.getId());
Budget budget2 = new Budget().withId(UUID.randomUUID().toString()).withFundId(fund2.getId());
when(budgetService.fetchBudgetsByFundIds(anyList(), any())).thenReturn(CompletableFuture.completedFuture(Arrays.asList(budget1, budget2)));
List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withBudgets(holders, requestContext).join();
assertThat(resultHolders, hasItem(allOf(hasProperty("budget", is(budget1)), hasProperty("ledgerId", is(fund1.getLedgerId())))));
assertThat(resultHolders, hasItem(allOf(hasProperty("budget", is(budget2)), hasProperty("ledgerId", is(fund2.getLedgerId())))));
assertThat(resultHolders, hasItem(allOf(hasProperty("budget", nullValue()), hasProperty("ledgerId", nullValue()))));
}
use of org.folio.rest.acq.model.finance.Budget in project mod-orders by folio-org.
the class MockServer method handleGetBudgetByFinanceId.
private void handleGetBudgetByFinanceId(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 (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-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()))))));
}
use of org.folio.rest.acq.model.finance.Budget 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));
}
Aggregations