use of org.folio.services.voucher.VoucherCommandService.VOUCHER_NUMBER_PREFIX_CONFIG_QUERY in project mod-invoice by folio-org.
the class InvoiceHelper method approveInvoice.
/**
* Handles transition of given invoice to {@link Invoice.Status#APPROVED} status.
* Transition triggers if the current {@link Invoice.Status} is {@link Invoice.Status#REVIEWED} or {@link Invoice.Status#OPEN}
* and exist at least one {@link InvoiceLine} associated with this invoice
*
* @param invoice {@link Invoice}to be approved
* @return CompletableFuture that indicates when transition is completed
*/
private CompletableFuture<Void> approveInvoice(Invoice invoice, List<InvoiceLine> lines) {
invoice.setApprovalDate(new Date());
invoice.setApprovedBy(invoice.getMetadata().getUpdatedByUserId());
RequestContext requestContext = new RequestContext(ctx, okapiHeaders);
return configurationService.getConfigurationsEntries(requestContext, SYSTEM_CONFIG_QUERY, VOUCHER_NUMBER_PREFIX_CONFIG_QUERY).thenCompose(ok -> updateInvoiceLinesWithEncumbrances(lines, requestContext)).thenCompose(v -> invoiceLineService.persistInvoiceLines(lines, requestContext)).thenCompose(v -> vendorService.getVendor(invoice.getVendorId(), requestContext)).thenAccept(organization -> validateBeforeApproval(organization, invoice, lines)).thenCompose(aVoid -> getInvoiceWorkflowDataHolders(invoice, lines, requestContext)).thenCompose(holders -> budgetExpenseClassService.checkExpenseClasses(holders, requestContext)).thenCompose(holders -> pendingPaymentWorkflowService.handlePendingPaymentsCreation(holders, requestContext)).thenCompose(v -> prepareVoucher(invoice)).thenCompose(voucher -> updateVoucherWithSystemCurrency(voucher, lines)).thenCompose(voucher -> voucherCommandService.updateVoucherWithExchangeRate(voucher, invoice, requestContext)).thenCompose(voucher -> getAllFundDistributions(lines, invoice).thenCompose(fundDistributions -> handleVoucherWithLines(fundDistributions, voucher)));
}
Aggregations