Search in sources :

Example 11 with Transaction

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

the class RestClientTest method testPostShouldCreateEntity.

@Test
public void testPostShouldCreateEntity() throws Exception {
    RestClient restClient = Mockito.spy(new RestClient());
    String uuid = UUID.randomUUID().toString();
    Transaction expTransaction = new Transaction().withId(uuid);
    Response response = new Response();
    response.setBody(JsonObject.mapFrom(expTransaction));
    response.setCode(201);
    RequestEntry requestEntry = new RequestEntry(resourcesPath(FINANCE_STORAGE_TRANSACTIONS));
    doReturn(httpClient).when(restClient).getHttpClient(okapiHeaders);
    doReturn(completedFuture(response)).when(httpClient).request(eq(HttpMethod.POST), any(), eq(resourcesPath(FINANCE_STORAGE_TRANSACTIONS)), eq(okapiHeaders));
    Transaction actTransaction = restClient.post(requestEntry, expTransaction, requestContext, Transaction.class).join();
    assertThat(actTransaction, equalTo(expTransaction));
}
Also used : Response(org.folio.rest.tools.client.Response) Transaction(org.folio.rest.acq.model.finance.Transaction) RequestEntry(org.folio.rest.core.models.RequestEntry) Test(org.junit.jupiter.api.Test)

Example 12 with Transaction

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

the class RestClientTest method testGetShouldSearchById.

@Test
public void testGetShouldSearchById() throws Exception {
    RestClient restClient = Mockito.spy(new RestClient());
    String uuid = UUID.randomUUID().toString();
    String endpoint = resourcesPath(FINANCE_STORAGE_TRANSACTIONS) + "/" + uuid;
    Transaction expTransaction = new Transaction().withId(uuid);
    Response response = new Response();
    response.setBody(JsonObject.mapFrom(expTransaction));
    response.setCode(200);
    doReturn(httpClient).when(restClient).getHttpClient(okapiHeaders);
    doReturn(completedFuture(response)).when(httpClient).request(HttpMethod.GET, endpoint, okapiHeaders);
    RequestEntry requestEntry = new RequestEntry(resourcesPath(FINANCE_STORAGE_TRANSACTIONS) + "/{id}").withId(uuid);
    Transaction actTransaction = restClient.get(requestEntry, requestContext, Transaction.class).join();
    assertThat(actTransaction, equalTo(expTransaction));
}
Also used : Response(org.folio.rest.tools.client.Response) Transaction(org.folio.rest.acq.model.finance.Transaction) RequestEntry(org.folio.rest.core.models.RequestEntry) Test(org.junit.jupiter.api.Test)

Example 13 with Transaction

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

the class PaymentCreditWorkflowService method createTransactions.

private CompletionStage<Void> createTransactions(List<InvoiceWorkflowDataHolder> holders, RequestContext requestContext) {
    CompletableFuture<Void> future = completedFuture(null);
    for (InvoiceWorkflowDataHolder holder : holders) {
        Transaction tr = holder.getNewTransaction();
        future = future.thenCompose(v -> baseTransactionService.createTransaction(tr, requestContext).thenAccept(t -> {
        }).exceptionally(t -> {
            logger.error("Failed to create transaction for invoice with id - {}", tr.getSourceInvoiceId(), t);
            List<Parameter> parameters = new ArrayList<>();
            parameters.add(new Parameter().withKey("invoiceLineId").withValue(tr.getSourceInvoiceLineId()));
            parameters.add(new Parameter().withKey(FUND_ID).withValue((tr.getTransactionType() == Transaction.TransactionType.PAYMENT) ? tr.getFromFundId() : tr.getToFundId()));
            throw new HttpException(400, TRANSACTION_CREATION_FAILURE.toError().withParameters(parameters));
        }));
    }
    return future;
}
Also used : HelperUtils.convertToDoubleWithRounding(org.folio.invoices.utils.HelperUtils.convertToDoubleWithRounding) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) CompletableFuture(java.util.concurrent.CompletableFuture) InvoiceWorkflowDataHolder(org.folio.models.InvoiceWorkflowDataHolder) Transaction(org.folio.rest.acq.model.finance.Transaction) FundsDistributionService.distributeFunds(org.folio.services.FundsDistributionService.distributeFunds) ArrayList(java.util.ArrayList) HttpException(org.folio.invoices.rest.exceptions.HttpException) Collectors.toList(java.util.stream.Collectors.toList) HelperUtils.getFundDistributionAmount(org.folio.invoices.utils.HelperUtils.getFundDistributionAmount) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Logger(org.apache.logging.log4j.Logger) RequestContext(org.folio.rest.core.models.RequestContext) Parameter(org.folio.rest.jaxrs.model.Parameter) LogManager(org.apache.logging.log4j.LogManager) MonetaryAmount(javax.money.MonetaryAmount) TRANSACTION_CREATION_FAILURE(org.folio.invoices.utils.ErrorCodes.TRANSACTION_CREATION_FAILURE) Transaction(org.folio.rest.acq.model.finance.Transaction) InvoiceWorkflowDataHolder(org.folio.models.InvoiceWorkflowDataHolder) ArrayList(java.util.ArrayList) Parameter(org.folio.rest.jaxrs.model.Parameter) HttpException(org.folio.invoices.rest.exceptions.HttpException)

Example 14 with Transaction

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

the class PendingPaymentWorkflowService method createPendingPayments.

private CompletableFuture<Void> createPendingPayments(List<InvoiceWorkflowDataHolder> holders, RequestContext requestContext) {
    CompletableFuture<Void> future = completedFuture(null);
    for (InvoiceWorkflowDataHolder holder : holders) {
        Transaction pendingPayment = holder.getNewTransaction();
        future = future.thenCompose(v -> baseTransactionService.createTransaction(pendingPayment, requestContext).thenAccept(t -> {
        }).exceptionally(t -> {
            logger.error("Failed to create pending payment with id {}", pendingPayment.getId(), t);
            throw new HttpException(400, PENDING_PAYMENT_ERROR.toError());
        }));
    }
    return future;
}
Also used : HelperUtils.convertToDoubleWithRounding(org.folio.invoices.utils.HelperUtils.convertToDoubleWithRounding) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) CompletableFuture(java.util.concurrent.CompletableFuture) FolioVertxCompletableFuture(org.folio.completablefuture.FolioVertxCompletableFuture) InvoiceWorkflowDataHolder(org.folio.models.InvoiceWorkflowDataHolder) Transaction(org.folio.rest.acq.model.finance.Transaction) HolderValidator(org.folio.services.validator.HolderValidator) FundsDistributionService.distributeFunds(org.folio.services.FundsDistributionService.distributeFunds) ArrayList(java.util.ArrayList) HttpException(org.folio.invoices.rest.exceptions.HttpException) InvoiceTransactionSummary(org.folio.rest.acq.model.finance.InvoiceTransactionSummary) RequestContext(org.folio.rest.core.models.RequestContext) HelperUtils.collectResultsOnSuccess(org.folio.invoices.utils.HelperUtils.collectResultsOnSuccess) PENDING_PAYMENT_ERROR(org.folio.invoices.utils.ErrorCodes.PENDING_PAYMENT_ERROR) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) AwaitingPayment(org.folio.rest.acq.model.finance.AwaitingPayment) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Collectors.toList(java.util.stream.Collectors.toList) HelperUtils.getFundDistributionAmount(org.folio.invoices.utils.HelperUtils.getFundDistributionAmount) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Optional(java.util.Optional) LogManager(org.apache.logging.log4j.LogManager) MonetaryAmount(javax.money.MonetaryAmount) Invoice(org.folio.rest.jaxrs.model.Invoice) Transaction(org.folio.rest.acq.model.finance.Transaction) InvoiceWorkflowDataHolder(org.folio.models.InvoiceWorkflowDataHolder) HttpException(org.folio.invoices.rest.exceptions.HttpException)

Example 15 with Transaction

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

the class OrderRolloverServiceTest method shouldUpdateOrderLinesCostAndEncumbranceLinksAndPolCurrencyVsSystemCurrencyTheSame.

@Test
@DisplayName("Should update order lines cost And Encumbrance Links where Pol Currency equals systemCurrency")
void shouldUpdateOrderLinesCostAndEncumbranceLinksAndPolCurrencyVsSystemCurrencyTheSame() {
    String fromFiscalYearId = UUID.randomUUID().toString();
    String ledgerId = UUID.randomUUID().toString();
    String toFiscalYearId = UUID.randomUUID().toString();
    String fundId1 = UUID.randomUUID().toString();
    String fundId2 = UUID.randomUUID().toString();
    String fundId3 = UUID.randomUUID().toString();
    String orderId1 = UUID.randomUUID().toString();
    String orderId2 = UUID.randomUUID().toString();
    String orderId3 = UUID.randomUUID().toString();
    String poLineId1 = UUID.randomUUID().toString();
    String poLineId2 = UUID.randomUUID().toString();
    String poLineId3 = UUID.randomUUID().toString();
    String prevEncumbrId1 = UUID.randomUUID().toString();
    String prevEncumbrId2 = UUID.randomUUID().toString();
    String prevEncumbrId3 = UUID.randomUUID().toString();
    String currEncumbrId1 = UUID.randomUUID().toString();
    String currEncumbrId2 = UUID.randomUUID().toString();
    String currEncumbrId3 = UUID.randomUUID().toString();
    String expClassId2 = UUID.randomUUID().toString();
    String expClassId3 = UUID.randomUUID().toString();
    EncumbranceRollover ongoingEncumbranceBasedOnExpended = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONGOING).withBasedOn(EncumbranceRollover.BasedOn.EXPENDED);
    EncumbranceRollover oneTimeEncumbrance = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONE_TIME).withBasedOn(EncumbranceRollover.BasedOn.REMAINING);
    EncumbranceRollover ongoingEncumbranceBasedOnInitialAmount = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONGOING).withBasedOn(EncumbranceRollover.BasedOn.INITIAL_AMOUNT);
    LedgerFiscalYearRollover ledgerFiscalYearRollover = new LedgerFiscalYearRollover().withId(UUID.randomUUID().toString()).withFromFiscalYearId(fromFiscalYearId).withLedgerId(ledgerId).withToFiscalYearId(toFiscalYearId).withEncumbrancesRollover(List.of(ongoingEncumbranceBasedOnExpended, oneTimeEncumbrance, ongoingEncumbranceBasedOnInitialAmount));
    List<Fund> funds = List.of(new Fund().withId(fundId1).withLedgerId(ledgerId), new Fund().withId(fundId2).withLedgerId(ledgerId), new Fund().withId(fundId3).withLedgerId(ledgerId));
    PurchaseOrder purchaseOrder1 = new PurchaseOrder().withId(orderId1).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
    PurchaseOrder purchaseOrder2 = new PurchaseOrder().withId(orderId2).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
    PurchaseOrder purchaseOrder3 = new PurchaseOrder().withId(orderId3).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
    List<PurchaseOrder> orders = List.of(purchaseOrder1, purchaseOrder2, purchaseOrder3);
    PurchaseOrderCollection purchaseOrderCollection = new PurchaseOrderCollection().withPurchaseOrders(orders).withTotalRecords(3);
    FundDistribution fundDistributionOneTime = new FundDistribution().withFundId(fundId1).withValue(100d).withEncumbrance(prevEncumbrId1);
    FundDistribution fundDistributionOngoing2 = new FundDistribution().withFundId(fundId2).withValue(100d).withEncumbrance(prevEncumbrId2).withExpenseClassId(expClassId2);
    FundDistribution fundDistributionOngoing3 = new FundDistribution().withFundId(fundId3).withValue(100d).withEncumbrance(prevEncumbrId3).withExpenseClassId(expClassId3);
    Cost costOneTime = new Cost().withListUnitPrice(100d).withQuantityPhysical(1).withCurrency("USD").withPoLineEstimatedPrice(100d);
    PoLine poLineOneTime = new PoLine().withId(poLineId1).withPurchaseOrderId(orderId1).withCost(costOneTime).withFundDistribution(List.of(fundDistributionOneTime));
    Cost costOngoing2 = new Cost().withListUnitPrice(100d).withQuantityPhysical(1).withCurrency("USD").withPoLineEstimatedPrice(100d);
    PoLine poLineOngoing2 = new PoLine().withId(poLineId2).withPurchaseOrderId(orderId2).withCost(costOngoing2).withFundDistribution(List.of(fundDistributionOngoing2));
    Cost costOngoing3 = new Cost().withListUnitPrice(100d).withQuantityPhysical(1).withCurrency("USD").withPoLineEstimatedPrice(100d);
    PoLine poLineOngoing3 = new PoLine().withId(poLineId3).withPurchaseOrderId(orderId3).withCost(costOngoing3).withFundDistribution(List.of(fundDistributionOngoing3));
    List<PoLine> poLines = List.of(poLineOneTime, poLineOngoing2, poLineOngoing3);
    doReturn(completedFuture(funds)).when(fundService).getFundsByLedgerId(ledgerId, requestContext);
    doReturn(completedFuture(purchaseOrderCollection)).when(purchaseOrderStorageService).getPurchaseOrders(anyString(), anyInt(), anyInt(), any());
    doReturn(completedFuture(poLines)).when(purchaseOrderLineService).getOrderLines(anyString(), anyInt(), anyInt(), any());
    doReturn(completedFuture(null)).when(purchaseOrderLineService).saveOrderLines(eq(poLines), any());
    Encumbrance encumbranceOneTime = new Encumbrance().withSourcePurchaseOrderId(orderId1).withSourcePoLineId(poLineId1).withOrderType(Encumbrance.OrderType.ONE_TIME).withInitialAmountEncumbered(60d);
    Transaction transactionOneTime = new Transaction().withId(currEncumbrId1).withFromFundId(fundId1).withEncumbrance(encumbranceOneTime);
    Encumbrance encumbranceOngoing2 = new Encumbrance().withSourcePurchaseOrderId(orderId2).withSourcePoLineId(poLineId2).withOrderType(Encumbrance.OrderType.ONGOING).withInitialAmountEncumbered(90d);
    Transaction transactionOngoing2 = new Transaction().withId(currEncumbrId2).withFromFundId(fundId2).withEncumbrance(encumbranceOngoing2).withExpenseClassId(expClassId2);
    Encumbrance encumbranceOngoing3 = new Encumbrance().withSourcePurchaseOrderId(orderId3).withSourcePoLineId(poLineId3).withOrderType(Encumbrance.OrderType.ONGOING).withInitialAmountEncumbered(95d);
    Transaction transactionOngoing3 = new Transaction().withId(currEncumbrId3).withFromFundId(fundId3).withEncumbrance(encumbranceOngoing3).withExpenseClassId(expClassId3);
    List<Transaction> encumbrances = List.of(transactionOneTime, transactionOngoing2, transactionOngoing3);
    TransactionCollection encumbranceCollection = new TransactionCollection().withTransactions(encumbrances).withTotalRecords(3);
    doReturn(completedFuture(encumbranceCollection)).when(transactionService).getTransactions(anyString(), anyInt(), anyInt(), any());
    double exchangeEurToUsdRate = 1.0d;
    doReturn(completedFuture(systemCurrency)).when(configurationEntriesService).getSystemCurrency(requestContext);
    String polCurrency = systemCurrency;
    ConversionQuery actQuery = ConversionQueryBuilder.of().setBaseCurrency(polCurrency).setTermCurrency(systemCurrency).set(RATE_KEY, exchangeEurToUsdRate).build();
    ExchangeRateProvider exchangeRateProvider = Mockito.mock(ManualExchangeRateProvider.class);
    ManualCurrencyConversion manualCurrencyConversion = new ManualCurrencyConversion(actQuery, exchangeRateProvider, ConversionContext.of());
    ExchangeRate exchangeRate = mock(ExchangeRate.class);
    doReturn(exchangeRateProvider).when(exchangeRateProviderResolver).resolve(any(ConversionQuery.class), eq(requestContext));
    doReturn(manualCurrencyConversion).when(exchangeRateProvider).getCurrencyConversion(any(ConversionQuery.class));
    doReturn(exchangeRate).when(exchangeRateProvider).getExchangeRate(any(ConversionQuery.class));
    when(exchangeRate.getContext()).thenReturn(ConversionContext.of());
    when(exchangeRate.getCurrency()).thenReturn(Monetary.getCurrency(systemCurrency));
    when(exchangeRate.getBaseCurrency()).thenReturn(Monetary.getCurrency(polCurrency));
    when(exchangeRate.getFactor()).thenReturn(new DefaultNumberValue(exchangeEurToUsdRate));
    CompletableFuture<Void> future = orderRolloverService.rollover(ledgerFiscalYearRollover, requestContext);
    future.join();
    assertFalse(future.isCompletedExceptionally());
    assertThat(fundDistributionOneTime.getEncumbrance(), equalTo(currEncumbrId1));
    assertThat(fundDistributionOngoing2.getEncumbrance(), equalTo(currEncumbrId2));
    assertThat(fundDistributionOngoing3.getEncumbrance(), equalTo(currEncumbrId3));
    assertThat(costOneTime.getPoLineEstimatedPrice(), equalTo(60d));
    assertThat(costOngoing2.getPoLineEstimatedPrice(), equalTo(90d));
    assertThat(costOngoing3.getPoLineEstimatedPrice(), equalTo(95d));
    assertThat(costOneTime.getFyroAdjustmentAmount(), equalTo(-40d));
    assertThat(costOngoing2.getFyroAdjustmentAmount(), equalTo(-10d));
    assertThat(costOngoing3.getFyroAdjustmentAmount(), equalTo(-5d));
}
Also used : EncumbranceRollover(org.folio.rest.jaxrs.model.EncumbranceRollover) DefaultNumberValue(org.javamoney.moneta.spi.DefaultNumberValue) TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) ExchangeRate(javax.money.convert.ExchangeRate) PurchaseOrderCollection(org.folio.rest.jaxrs.model.PurchaseOrderCollection) ExchangeRateProvider(javax.money.convert.ExchangeRateProvider) ManualExchangeRateProvider(org.folio.service.exchange.ManualExchangeRateProvider) Fund(org.folio.rest.acq.model.finance.Fund) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LedgerFiscalYearRollover(org.folio.rest.jaxrs.model.LedgerFiscalYearRollover) Cost(org.folio.rest.jaxrs.model.Cost) ManualCurrencyConversion(org.folio.service.exchange.ManualCurrencyConversion) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) ConversionQuery(javax.money.convert.ConversionQuery) Transaction(org.folio.rest.acq.model.finance.Transaction) PoLine(org.folio.rest.jaxrs.model.PoLine) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

Transaction (org.folio.rest.acq.model.finance.Transaction)79 Test (org.junit.jupiter.api.Test)60 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)31 ArrayList (java.util.ArrayList)29 Encumbrance (org.folio.rest.acq.model.finance.Encumbrance)29 TransactionCollection (org.folio.rest.acq.model.finance.TransactionCollection)25 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)24 List (java.util.List)21 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)19 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 EncumbranceRelationsHolder (org.folio.models.EncumbranceRelationsHolder)16 RequestContext (org.folio.rest.core.models.RequestContext)16 Budget (org.folio.rest.acq.model.finance.Budget)15 Fund (org.folio.rest.acq.model.finance.Fund)15 RequestEntry (org.folio.rest.core.models.RequestEntry)15 MonetaryAmount (javax.money.MonetaryAmount)14 Cost (org.folio.rest.jaxrs.model.Cost)14 JsonObject (io.vertx.core.json.JsonObject)12 Collectors.toList (java.util.stream.Collectors.toList)12 Error (org.folio.rest.jaxrs.model.Error)11