Search in sources :

Example 1 with FiscalYear

use of org.folio.rest.acq.model.finance.FiscalYear 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());
}
Also used : FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) Transaction(org.folio.rest.acq.model.finance.Transaction) Fund(org.folio.rest.acq.model.finance.Fund) InvoiceWorkflowDataHolder(org.folio.models.InvoiceWorkflowDataHolder) ArrayList(java.util.ArrayList) Error(org.folio.rest.jaxrs.model.Error) Budget(org.folio.rest.acq.model.finance.Budget) HttpException(org.folio.invoices.rest.exceptions.HttpException) Test(org.junit.jupiter.api.Test)

Example 2 with FiscalYear

use of org.folio.rest.acq.model.finance.FiscalYear 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));
}
Also used : FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) Transaction(org.folio.rest.acq.model.finance.Transaction) Fund(org.folio.rest.acq.model.finance.Fund) InvoiceWorkflowDataHolder(org.folio.models.InvoiceWorkflowDataHolder) ArrayList(java.util.ArrayList) Budget(org.folio.rest.acq.model.finance.Budget) Test(org.junit.jupiter.api.Test)

Example 3 with FiscalYear

use of org.folio.rest.acq.model.finance.FiscalYear 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());
}
Also used : FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) Fund(org.folio.rest.acq.model.finance.Fund) Transaction(org.folio.rest.acq.model.finance.Transaction) InvoiceWorkflowDataHolder(org.folio.models.InvoiceWorkflowDataHolder) ArrayList(java.util.ArrayList) Error(org.folio.rest.jaxrs.model.Error) Budget(org.folio.rest.acq.model.finance.Budget) HttpException(org.folio.invoices.rest.exceptions.HttpException) AwaitingPayment(org.folio.rest.acq.model.finance.AwaitingPayment) Test(org.junit.jupiter.api.Test)

Example 4 with FiscalYear

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

the class MockServer method handleFiscalYearById.

private void handleFiscalYearById(RoutingContext ctx) {
    logger.info("handleFiscalYearById got: GET " + ctx.request().path());
    String id = ctx.request().getParam(AbstractHelper.ID);
    logger.info("id: " + id);
    if (ID_FOR_INTERNAL_SERVER_ERROR.equals(id)) {
        serverResponse(ctx, 500, APPLICATION_JSON, Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase());
    } else if (FISCAL_YEAR_ID.equals(id)) {
        FiscalYear fiscalYear = new FiscalYear();
        fiscalYear.setId(FISCAL_YEAR_ID);
        fiscalYear.setCode("test2020");
        fiscalYear.setName("test");
        fiscalYear.setSeries("FY");
        fiscalYear.setPeriodStart(Date.from(Instant.now().minus(365, DAYS)));
        fiscalYear.setPeriodEnd(Date.from(Instant.now().plus(365, DAYS)));
        fiscalYear.setCurrency(SYSTEM_CURRENCY);
        serverResponse(ctx, 200, APPLICATION_JSON, JsonObject.mapFrom(fiscalYear).encodePrettily());
    } else {
        serverResponse(ctx, 404, APPLICATION_JSON, id);
    }
}
Also used : FiscalYear(org.folio.rest.acq.model.finance.FiscalYear)

Example 5 with FiscalYear

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

the class CurrentFiscalYearServiceTest method shouldReturnErrorResponseIfFundDoesNotExist.

@Test
void shouldReturnErrorResponseIfFundDoesNotExist() {
    // Given
    String fundId = UUID.randomUUID().toString();
    CompletableFuture<Fund> failedFuture = new CompletableFuture<>();
    failedFuture.completeExceptionally(new HttpException(404, FUNDS_NOT_FOUND));
    doReturn(failedFuture).when(fundService).getFundById(fundId, requestContextMock);
    CompletableFuture<FiscalYear> resultFuture = currentFiscalYearService.getCurrentFiscalYearByFund(fundId, requestContextMock);
    // When
    ExecutionException e = assertThrows(ExecutionException.class, resultFuture::get);
    // Then
    assertThat(e.getCause(), instanceOf(HttpException.class));
    HttpException httpException = (HttpException) e.getCause();
    Assertions.assertEquals(404, httpException.getCode());
    Error error = httpException.getErrors().getErrors().get(0);
    Assertions.assertEquals(FUNDS_NOT_FOUND.toError().getMessage(), error.getMessage());
    Assertions.assertEquals(FUNDS_NOT_FOUND.toError().getCode(), error.getCode());
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) Fund(org.folio.rest.acq.model.finance.Fund) Error(org.folio.rest.jaxrs.model.Error) HttpException(org.folio.invoices.rest.exceptions.HttpException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test)

Aggregations

FiscalYear (org.folio.rest.acq.model.finance.FiscalYear)26 Test (org.junit.jupiter.api.Test)22 Fund (org.folio.rest.acq.model.finance.Fund)11 ArrayList (java.util.ArrayList)9 Transaction (org.folio.rest.acq.model.finance.Transaction)9 InvoiceWorkflowDataHolder (org.folio.models.InvoiceWorkflowDataHolder)7 Budget (org.folio.rest.acq.model.finance.Budget)7 HttpException (org.folio.invoices.rest.exceptions.HttpException)4 CompositeOrderRetrieveHolder (org.folio.models.CompositeOrderRetrieveHolder)4 ReEncumbranceHolder (org.folio.models.ReEncumbranceHolder)4 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)4 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)4 Error (org.folio.rest.jaxrs.model.Error)4 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 TransactionCollection (org.folio.rest.acq.model.finance.TransactionCollection)3 HttpException (org.folio.rest.core.exceptions.HttpException)3 JsonObject (io.vertx.core.json.JsonObject)2 LocalDate (java.time.LocalDate)2 Date (java.util.Date)2