use of org.folio.rest.jaxrs.model.Voucher in project mod-invoice by folio-org.
the class InvoiceHelper method prepareVoucher.
/**
* Prepares a new voucher or updates existing one for further processing
*
* @param invoice {@link Invoice} to be approved on the basis of which the voucher is prepared
* @return completable future with {@link Voucher} on success
*/
private CompletableFuture<Voucher> prepareVoucher(Invoice invoice) {
return voucherRetrieveService.getVoucherByInvoiceId(invoice.getId(), new RequestContext(ctx, okapiHeaders)).thenCompose(voucher -> {
if (nonNull(voucher)) {
return completedFuture(voucher);
}
return voucherCommandService.buildNewVoucher(invoice, new RequestContext(ctx, okapiHeaders));
}).thenApply(voucher -> {
invoice.setVoucherNumber(voucher.getVoucherNumber());
voucher.setAcqUnitIds(invoice.getAcqUnitIds());
return withRequiredFields(voucher, invoice);
});
}
use of org.folio.rest.jaxrs.model.Voucher 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)));
}
use of org.folio.rest.jaxrs.model.Voucher in project mod-invoice by folio-org.
the class VouchersImpl method getVoucherVoucherNumberStart.
@Override
@Validate
public void getVoucherVoucherNumberStart(String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
logger.info("== Getting the current start value of the voucher number sequence ==");
voucherNumberService.getStartValue(new RequestContext(vertxContext, okapiHeaders)).thenAccept(number -> asyncResultHandler.handle(succeededFuture(buildOkResponse(number)))).exceptionally(t -> handleErrorResponse(asyncResultHandler, t));
}
Aggregations