use of org.folio.rest.acq.model.finance.InvoiceTransactionSummary in project mod-invoice by folio-org.
the class InvoiceCancelServiceTest method setupUpdateTransactionSummary.
private void setupUpdateTransactionSummary(Invoice invoice) {
RequestEntry requestEntry = new RequestEntry(INVOICE_TRANSACTION_SUMMARIES_BY_ID_ENDPOINT).withPathParameter("id", invoice.getId());
InvoiceTransactionSummary summary = new InvoiceTransactionSummary().withId(invoice.getId()).withNumPaymentsCredits(3).withNumPendingPayments(1);
doReturn(completedFuture(null)).when(restClient).put(argThat(re -> sameRequestEntry(requestEntry, re)), eq(summary), eq(requestContextMock));
}
use of org.folio.rest.acq.model.finance.InvoiceTransactionSummary in project mod-invoice by folio-org.
the class InvoicesApiTest method verifyTransitionToApproved.
private void verifyTransitionToApproved(Voucher voucherCreated, List<InvoiceLine> invoiceLines, Invoice invoice, int createdVoucherLines) {
List<JsonObject> invoiceLinesSearches = serverRqRs.get(INVOICE_LINES, HttpMethod.GET);
List<JsonObject> invoiceLinesUpdates = serverRqRs.get(INVOICE_LINES, HttpMethod.PUT);
List<JsonObject> voucherLinesCreated = serverRqRs.get(VOUCHER_LINES, HttpMethod.POST);
List<JsonObject> fundsSearches = serverRqRs.get(FUNDS, HttpMethod.GET);
List<JsonObject> invoiceUpdates = serverRqRs.get(INVOICES, HttpMethod.PUT);
List<JsonObject> transactionSummariesCreated = serverRqRs.get(INVOICE_TRANSACTION_SUMMARIES, HttpMethod.POST);
List<JsonObject> pendingPaymentCreated = Optional.ofNullable(serverRqRs.get(FINANCE_PENDING_PAYMENTS, HttpMethod.POST)).orElse(emptyList());
assertThat(invoiceLinesSearches, notNullValue());
assertThat(invoiceLinesUpdates, notNullValue());
assertThat(fundsSearches, notNullValue());
assertThat(voucherLinesCreated, notNullValue());
assertThat(invoiceUpdates, notNullValue());
assertThat(transactionSummariesCreated, notNullValue());
assertThat(invoiceLinesSearches, hasSize(invoiceLines.size() / MAX_IDS_FOR_GET_RQ + 1));
List<InvoiceLine> linesWithUpdatedStatus = invoiceLinesUpdates.stream().map(entries -> entries.mapTo(InvoiceLine.class)).filter(invoiceLine -> invoiceLine.getInvoiceLineStatus() == InvoiceLine.InvoiceLineStatus.APPROVED).collect(toList());
assertThat(linesWithUpdatedStatus, hasSize(invoiceLines.size()));
assertThat(voucherLinesCreated, hasSize(createdVoucherLines));
InvoiceTransactionSummary transactionSummary = transactionSummariesCreated.get(0).mapTo(InvoiceTransactionSummary.class);
Invoice invoiceUpdate = invoiceUpdates.get(0).mapTo(Invoice.class);
List<VoucherLine> voucherLines = voucherLinesCreated.stream().map(json -> json.mapTo(VoucherLine.class)).collect(Collectors.toList());
assertThat(Invoice.Status.APPROVED, equalTo(invoiceUpdate.getStatus()));
assertThat(invoiceUpdate.getVoucherNumber(), equalTo(voucherCreated.getVoucherNumber()));
assertThat(invoiceUpdate.getId(), equalTo(voucherCreated.getInvoiceId()));
assertThat(invoiceUpdate.getCurrency(), equalTo(voucherCreated.getInvoiceCurrency()));
// assertThat(HelperUtils.getInvoiceExchangeRateProvider().getExchangeRate(voucherCreated.getInvoiceCurrency(), voucherCreated.getSystemCurrency()).getFactor().doubleValue(), equalTo(voucherCreated.getExchangeRate()));
assertThat(voucherCreated.getAccountingCode(), equalTo(invoiceUpdate.getAccountingCode()));
assertThat(voucherCreated.getExportToAccounting(), is(false));
assertThat(Voucher.Status.AWAITING_PAYMENT, equalTo(voucherCreated.getStatus()));
assertThat(Voucher.Type.VOUCHER, equalTo(voucherCreated.getType()));
int paymentCreditNumber = invoiceLines.stream().filter(invoiceLine -> invoiceLine.getTotal() >= 0).mapToInt(line -> line.getFundDistributions().size()).sum();
paymentCreditNumber += invoice.getAdjustments().stream().mapToInt(adj -> adj.getFundDistributions().size()).sum();
assertThat(pendingPaymentCreated, hasSize(paymentCreditNumber));
List<Transaction> pendingPayments = pendingPaymentCreated.stream().map(entries -> entries.mapTo(Transaction.class)).collect(toList());
assertThat(pendingPayments, Every.everyItem(hasProperty("sourceInvoiceId", is(invoice.getId()))));
assertThat(transactionSummary.getNumPendingPayments(), is(paymentCreditNumber));
assertThat(transactionSummary.getNumPaymentsCredits(), is(paymentCreditNumber));
assertThat(calculateVoucherAmount(voucherCreated, voucherLines), equalTo(voucherCreated.getAmount()));
assertThat(createdVoucherLines, equalTo(voucherLinesCreated.size()));
invoiceLines.forEach(invoiceLine -> calculateInvoiceLineTotals(invoiceLine, invoiceUpdate));
voucherLines.forEach(voucherLine -> {
assertThat(voucherCreated.getId(), equalTo(voucherLine.getVoucherId()));
assertThat(voucherLine.getFundDistributions(), allOf(Every.everyItem(hasProperty("distributionType", is(AMOUNT))), Every.everyItem(hasProperty("code"))));
assertThat(calculateVoucherLineAmount(voucherLine.getFundDistributions(), voucherCreated), equalTo(voucherLine.getAmount()));
assertThat(voucherLine.getFundDistributions().stream().filter(fundDistribution -> Objects.nonNull(fundDistribution.getInvoiceLineId())).map(FundDistribution::getInvoiceLineId).distinct().collect(Collectors.toList()), hasSize(voucherLine.getSourceIds().size()));
});
}
use of org.folio.rest.acq.model.finance.InvoiceTransactionSummary in project mod-invoice by folio-org.
the class InvoicesApiTest method testTransitionToApprovedWithoutFundDistrEncumbranceId.
@Test
void testTransitionToApprovedWithoutFundDistrEncumbranceId() {
logger.info("=== Test transition invoice to Approved without links to encumbrances ===");
InvoiceLine invoiceLine = getMockAsJson(INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH).mapTo(InvoiceLine.class);
Invoice reqData = getMockAsJson(REVIEWED_INVOICE_WITH_EXISTING_VOUCHER_SAMPLE_PATH).mapTo(Invoice.class);
reqData.setStatus(Invoice.Status.APPROVED);
String id = reqData.getId();
invoiceLine.setId(UUID.randomUUID().toString());
invoiceLine.setInvoiceId(id);
invoiceLine.getFundDistributions().forEach(fundDistribution -> fundDistribution.setEncumbrance(null));
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
String jsonBody = JsonObject.mapFrom(reqData).encode();
Headers headers = prepareHeaders(X_OKAPI_TENANT, X_OKAPI_TOKEN, X_OKAPI_USER_ID);
verifyPut(String.format(INVOICE_ID_PATH, id), jsonBody, headers, "", 204);
List<JsonObject> invoiceSummariesCreated = serverRqRs.get(INVOICE_TRANSACTION_SUMMARIES, HttpMethod.POST);
List<JsonObject> pendingPaymentsCreated = serverRqRs.get(FINANCE_PENDING_PAYMENTS, HttpMethod.POST);
assertThat(invoiceSummariesCreated, hasSize(1));
InvoiceTransactionSummary transactionSummary = invoiceSummariesCreated.get(0).mapTo(InvoiceTransactionSummary.class);
int numPendingPayments = invoiceLine.getFundDistributions().size();
assertThat(transactionSummary.getNumPendingPayments(), is(numPendingPayments));
assertThat(transactionSummary.getNumPaymentsCredits(), is(numPendingPayments));
assertThat(pendingPaymentsCreated, hasSize(numPendingPayments));
}
use of org.folio.rest.acq.model.finance.InvoiceTransactionSummary in project mod-invoice by folio-org.
the class InvoiceCancelService method cancelTransactions.
private CompletableFuture<Void> cancelTransactions(String invoiceId, List<Transaction> transactions, RequestContext requestContext) {
if (transactions.size() == 0)
return completedFuture(null);
transactions.forEach(tr -> tr.setInvoiceCancelled(true));
InvoiceTransactionSummary summary = buildInvoiceTransactionsSummary(invoiceId, transactions);
return invoiceTransactionSummaryService.updateInvoiceTransactionSummary(summary, requestContext).thenCompose(s -> baseTransactionService.updateTransactions(transactions, requestContext)).exceptionally(t -> {
logger.error("Failed to cancel transactions for invoice with id {}", invoiceId, t);
List<Parameter> parameters = Collections.singletonList(new Parameter().withKey("invoiceId").withValue(invoiceId));
throw new HttpException(500, CANCEL_TRANSACTIONS_ERROR.toError().withParameters(parameters));
});
}
use of org.folio.rest.acq.model.finance.InvoiceTransactionSummary in project mod-invoice by folio-org.
the class PendingPaymentWorkflowService method handlePendingPaymentsCreation.
public CompletableFuture<Void> handlePendingPaymentsCreation(List<InvoiceWorkflowDataHolder> dataHolders, RequestContext requestContext) {
List<InvoiceWorkflowDataHolder> holders = withNewPendingPayments(dataHolders);
holderValidator.validate(holders);
InvoiceTransactionSummary summary = buildInvoiceTransactionsSummary(holders);
return invoiceTransactionSummaryService.createInvoiceTransactionSummary(summary, requestContext).thenCompose(s -> createPendingPayments(holders, requestContext)).thenCompose(s -> cleanupOldEncumbrances(holders, requestContext));
}
Aggregations