Search in sources :

Example 6 with Budget

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);
    });
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Budget(org.folio.rest.acq.model.finance.Budget) RequestEntry(org.folio.rest.core.models.RequestEntry) BudgetExpenseClassCollection(org.folio.rest.acq.model.finance.BudgetExpenseClassCollection)

Example 7 with Budget

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()))));
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Fund(org.folio.rest.acq.model.finance.Fund) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) Budget(org.folio.rest.acq.model.finance.Budget) Test(org.junit.jupiter.api.Test)

Example 8 with Budget

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();
    }
}
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 9 with Budget

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()))))));
}
Also used : FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) EncumbranceRelationsHolder(org.folio.models.EncumbranceRelationsHolder) ArrayList(java.util.ArrayList) Budget(org.folio.rest.acq.model.finance.Budget) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 10 with Budget

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

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