Search in sources :

Example 1 with VOUCHER_NUMBER_PREFIX_CONFIG_QUERY

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)));
}
Also used : INVOICES(org.folio.invoices.utils.ResourcePathResolver.INVOICES) FolioVertxCompletableFuture.completedFuture(org.folio.completablefuture.FolioVertxCompletableFuture.completedFuture) ORG_IS_NOT_VENDOR(org.folio.invoices.utils.ErrorCodes.ORG_IS_NOT_VENDOR) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) InvoiceWorkflowDataHolder(org.folio.models.InvoiceWorkflowDataHolder) StringUtils(org.apache.commons.lang3.StringUtils) Context(io.vertx.core.Context) ExchangeRateProviderResolver(org.folio.services.exchange.ExchangeRateProviderResolver) HttpException(org.folio.invoices.rest.exceptions.HttpException) InvoiceService(org.folio.services.invoice.InvoiceService) ExpenseClass(org.folio.rest.acq.model.finance.ExpenseClass) Voucher(org.folio.rest.jaxrs.model.Voucher) AdjustmentsService(org.folio.services.adjusment.AdjustmentsService) VoucherCommandService(org.folio.services.voucher.VoucherCommandService) Collectors.toMap(java.util.stream.Collectors.toMap) Pair(org.apache.commons.lang3.tuple.Pair) InvoicePaymentService(org.folio.services.invoice.InvoicePaymentService) HelperUtils.isPostApproval(org.folio.invoices.utils.HelperUtils.isPostApproval) Map(java.util.Map) ListUtils(org.apache.commons.collections4.ListUtils) InvoiceWorkflowDataHolderBuilder(org.folio.InvoiceWorkflowDataHolderBuilder) CurrentFiscalYearService(org.folio.services.finance.fiscalyear.CurrentFiscalYearService) JsonObject(io.vertx.core.json.JsonObject) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) UserPermissionsUtil.verifyUserHasManagePermission(org.folio.utils.UserPermissionsUtil.verifyUserHasManagePermission) InvoiceCollection(org.folio.rest.jaxrs.model.InvoiceCollection) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) ExpenseClassRetrieveService(org.folio.services.finance.expence.ExpenseClassRetrieveService) BudgetExpenseClassService(org.folio.services.finance.budget.BudgetExpenseClassService) CompositePoLine(org.folio.rest.acq.model.orders.CompositePoLine) VendorRetrieveService(org.folio.services.VendorRetrieveService) Collection(java.util.Collection) InvoiceValidator(org.folio.services.validator.InvoiceValidator) Money(org.javamoney.moneta.Money) VOUCHER_NUMBER_PREFIX_CONFIG_QUERY(org.folio.services.voucher.VoucherCommandService.VOUCHER_NUMBER_PREFIX_CONFIG_QUERY) ConversionQuery(javax.money.convert.ConversionQuery) FOLIO_INVOICE_NUMBER(org.folio.invoices.utils.ResourcePathResolver.FOLIO_INVOICE_NUMBER) InvoiceRestrictionsUtil(org.folio.invoices.utils.InvoiceRestrictionsUtil) HelperUtils.getHttpClient(org.folio.invoices.utils.HelperUtils.getHttpClient) Fund(org.folio.rest.acq.model.finance.Fund) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) SequenceNumber(org.folio.rest.jaxrs.model.SequenceNumber) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) UPDATE(org.folio.invoices.utils.ProtectedOperationType.UPDATE) UserPermissionsUtil.verifyUserHasAssignPermission(org.folio.utils.UserPermissionsUtil.verifyUserHasAssignPermission) HelperUtils.getFundDistributionAmount(org.folio.invoices.utils.HelperUtils.getFundDistributionAmount) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) ExchangeRateProvider(javax.money.convert.ExchangeRateProvider) PendingPaymentWorkflowService(org.folio.services.finance.transaction.PendingPaymentWorkflowService) InvoiceCancelService(org.folio.services.invoice.InvoiceCancelService) Organization(org.folio.rest.acq.model.Organization) Adjustment(org.folio.rest.jaxrs.model.Adjustment) Monetary.getDefaultRounding(javax.money.Monetary.getDefaultRounding) Optional(java.util.Optional) FundExtNoExpenseClassExtNoPair(org.folio.models.FundExtNoExpenseClassExtNoPair) Parameter(org.folio.rest.jaxrs.model.Parameter) Objects.nonNull(java.util.Objects.nonNull) MonetaryAmount(javax.money.MonetaryAmount) Invoice(org.folio.rest.jaxrs.model.Invoice) HelperUtils(org.folio.invoices.utils.HelperUtils) EncumbranceService(org.folio.services.finance.transaction.EncumbranceService) CurrencyConversion(javax.money.convert.CurrencyConversion) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) HelperUtils.combineCqlExpressions(org.folio.invoices.utils.HelperUtils.combineCqlExpressions) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) FolioVertxCompletableFuture(org.folio.completablefuture.FolioVertxCompletableFuture) Transaction(org.folio.rest.acq.model.finance.Transaction) Function(java.util.function.Function) CollectionUtils(org.apache.commons.collections4.CollectionUtils) FundService(org.folio.services.finance.FundService) SpringContextUtil(org.folio.spring.SpringContextUtil) HelperUtils.getAdjustmentFundDistributionAmount(org.folio.invoices.utils.HelperUtils.getAdjustmentFundDistributionAmount) CompletableFuture.allOf(java.util.concurrent.CompletableFuture.allOf) RequestContext(org.folio.rest.core.models.RequestContext) EMPTY(org.apache.commons.lang3.StringUtils.EMPTY) ORG_NOT_FOUND(org.folio.invoices.utils.ErrorCodes.ORG_NOT_FOUND) InvoiceLineService(org.folio.services.invoice.InvoiceLineService) ResourcePathResolver.resourcesPath(org.folio.invoices.utils.ResourcePathResolver.resourcesPath) VoucherRetrieveService(org.folio.services.voucher.VoucherRetrieveService) Vertx(io.vertx.core.Vertx) VoucherLine(org.folio.rest.jaxrs.model.VoucherLine) Error(org.folio.rest.jaxrs.model.Error) UUID.randomUUID(java.util.UUID.randomUUID) Collectors.toList(java.util.stream.Collectors.toList) INVALID_INVOICE_TRANSITION_ON_PAID_STATUS(org.folio.invoices.utils.ErrorCodes.INVALID_INVOICE_TRANSITION_ON_PAID_STATUS) HelperUtils.calculateVoucherLineAmount(org.folio.invoices.utils.HelperUtils.calculateVoucherLineAmount) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) ConfigurationService(org.folio.services.configuration.ConfigurationService) ProtectedOperationType(org.folio.invoices.utils.ProtectedOperationType) RequestContext(org.folio.rest.core.models.RequestContext) Date(java.util.Date)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Context (io.vertx.core.Context)1 Vertx (io.vertx.core.Vertx)1 JsonObject (io.vertx.core.json.JsonObject)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Objects.nonNull (java.util.Objects.nonNull)1 Optional (java.util.Optional)1 UUID.randomUUID (java.util.UUID.randomUUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.allOf (java.util.concurrent.CompletableFuture.allOf)1 CompletionStage (java.util.concurrent.CompletionStage)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)1