Search in sources :

Example 11 with InvoicePayment

use of com.axelor.apps.account.db.InvoicePayment in project axelor-open-suite by axelor.

the class BankOrderMergeServiceImpl method mergeBankOrders.

@Transactional(rollbackOn = { Exception.class })
public BankOrder mergeBankOrders(Collection<BankOrder> bankOrders) throws AxelorException {
    if (bankOrders == null || bankOrders.size() <= 1) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, IExceptionMessage.BANK_ORDER_MERGE_AT_LEAST_TWO_BANK_ORDERS);
    }
    this.checkSameElements(bankOrders);
    BankOrder bankOrder = bankOrders.iterator().next();
    bankOrders.remove(bankOrder);
    bankOrder.setSenderLabel(null);
    bankOrder.setSenderReference(null);
    bankOrder.setBankOrderDate(Beans.get(AppBaseService.class).getTodayDate(bankOrder.getSenderCompany()));
    bankOrder.setSignatoryUser(null);
    bankOrder.setSignatoryEbicsUser(null);
    PaymentMode paymentMode = bankOrder.getPaymentMode();
    for (BankOrderLine bankOrderLine : this.getAllBankOrderLineList(bankOrders)) {
        bankOrder.addBankOrderLineListItem(bankOrderLine);
    }
    bankOrderRepo.save(bankOrder);
    for (BankOrder bankOrderToRemove : bankOrders) {
        bankOrderToRemove = bankOrderRepo.find(bankOrderToRemove.getId());
        List<InvoicePayment> invoicePaymentList = invoicePaymentRepo.findByBankOrder(bankOrderToRemove).fetch();
        for (InvoicePayment invoicePayment : invoicePaymentList) {
            invoicePayment.setBankOrder(bankOrder);
        }
        bankOrderRepo.remove(bankOrderToRemove);
    }
    if (paymentMode.getConsoBankOrderLinePerPartner()) {
        consolidatePerPartner(bankOrder);
    }
    bankOrderService.updateTotalAmounts(bankOrder);
    return bankOrderRepo.save(bankOrder);
}
Also used : AxelorException(com.axelor.exception.AxelorException) InvoicePayment(com.axelor.apps.account.db.InvoicePayment) BankOrderLine(com.axelor.apps.bankpayment.db.BankOrderLine) BankOrder(com.axelor.apps.bankpayment.db.BankOrder) PaymentMode(com.axelor.apps.account.db.PaymentMode) Transactional(com.google.inject.persist.Transactional)

Example 12 with InvoicePayment

use of com.axelor.apps.account.db.InvoicePayment in project axelor-open-suite by axelor.

the class BatchDirectDebitCustomerInvoice method process.

@Override
protected void process() {
    AccountingBatch accountingBatch = batch.getAccountingBatch();
    List<String> filterList = new ArrayList<>();
    List<Pair<String, Object>> bindingList = new ArrayList<>();
    filterList.add("self.operationTypeSelect = :operationTypeSelect");
    bindingList.add(Pair.of("operationTypeSelect", (Object) InvoiceRepository.OPERATION_TYPE_CLIENT_SALE));
    filterList.add("self.statusSelect = :statusSelect");
    bindingList.add(Pair.of("statusSelect", (Object) InvoiceRepository.STATUS_VENTILATED));
    filterList.add("self.amountRemaining > 0");
    filterList.add("self.hasPendingPayments = FALSE");
    LocalDate dueDate = accountingBatch.getDueDate() != null ? accountingBatch.getDueDate() : Beans.get(AppBaseService.class).getTodayDate(accountingBatch.getCompany());
    filterList.add("self.dueDate <= :dueDate");
    bindingList.add(Pair.of("dueDate", (Object) dueDate));
    if (accountingBatch.getCompany() != null) {
        filterList.add("self.company = :company");
        bindingList.add(Pair.of("company", (Object) accountingBatch.getCompany()));
    }
    filterList.add("self.partner.id NOT IN (SELECT DISTINCT partner.id FROM Partner partner LEFT JOIN partner.blockingList blocking WHERE blocking.blockingSelect = :blockingSelect AND blocking.blockingToDate >= :blockingToDate)");
    bindingList.add(Pair.of("blockingSelect", BlockingRepository.DEBIT_BLOCKING));
    bindingList.add(Pair.of("blockingToDate", Beans.get(AppBaseService.class).getTodayDate(accountingBatch.getCompany())));
    if (accountingBatch.getBankDetails() != null) {
        Set<BankDetails> bankDetailsSet = Sets.newHashSet(accountingBatch.getBankDetails());
        if (accountingBatch.getIncludeOtherBankAccounts() && appBaseService.getAppBase().getManageMultiBanks()) {
            bankDetailsSet.addAll(accountingBatch.getCompany().getBankDetailsList());
        }
        filterList.add("self.companyBankDetails IN (:bankDetailsSet)");
        bindingList.add(Pair.of("bankDetailsSet", (Object) bankDetailsSet));
    }
    if (accountingBatch.getPaymentMode() != null) {
        filterList.add("self.paymentMode = :paymentMode");
        bindingList.add(Pair.of("paymentMode", (Object) accountingBatch.getPaymentMode()));
    }
    List<InvoicePayment> invoicePaymentList = processQuery(filterList, bindingList);
    if (!invoicePaymentList.isEmpty()) {
        try {
            final BankOrder bankOrder = Beans.get(BankOrderMergeService.class).mergeFromInvoicePayments(invoicePaymentList);
            findBatch().setBankOrder(bankOrder);
        } catch (AxelorException e) {
            TraceBackService.trace(e, ExceptionOriginRepository.DIRECT_DEBIT, batch.getId());
            LOG.error(e.getMessage());
        }
    }
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) AxelorException(com.axelor.exception.AxelorException) BankDetails(com.axelor.apps.base.db.BankDetails) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) BankOrderMergeService(com.axelor.apps.bankpayment.service.bankorder.BankOrderMergeService) AccountingBatch(com.axelor.apps.account.db.AccountingBatch) BankOrder(com.axelor.apps.bankpayment.db.BankOrder) Pair(org.apache.commons.lang3.tuple.Pair)

Example 13 with InvoicePayment

use of com.axelor.apps.account.db.InvoicePayment in project axelor-open-suite by axelor.

the class BankOrderMergeServiceImpl method mergeFromInvoicePayments.

@Override
@Transactional(rollbackOn = { Exception.class })
public BankOrder mergeFromInvoicePayments(Collection<InvoicePayment> invoicePayments) throws AxelorException {
    if (invoicePayments == null || invoicePayments.isEmpty()) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_MERGE_NO_BANK_ORDERS));
    }
    Collection<InvoicePayment> invoicePaymentsWithBankOrders = new ArrayList<>();
    Collection<BankOrder> bankOrders = new LinkedHashSet<>();
    for (InvoicePayment invoicePayment : invoicePayments) {
        BankOrder bankOrder = invoicePayment.getBankOrder();
        if (bankOrder != null) {
            invoicePaymentsWithBankOrders.add(invoicePayment);
            bankOrders.add(bankOrder);
        }
    }
    if (bankOrders.size() > 1) {
        LocalDate bankOrderDate = bankOrders.iterator().next().getBankOrderDate();
        BankOrder mergedBankOrder = mergeBankOrders(bankOrders);
        mergedBankOrder.setBankOrderDate(bankOrderDate);
        for (InvoicePayment invoicePayment : invoicePaymentsWithBankOrders) {
            invoicePayment.setBankOrder(mergedBankOrder);
        }
        return mergedBankOrder;
    }
    if (!bankOrders.isEmpty()) {
        return bankOrders.iterator().next();
    }
    throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_MERGE_NO_BANK_ORDERS));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AxelorException(com.axelor.exception.AxelorException) InvoicePayment(com.axelor.apps.account.db.InvoicePayment) ArrayList(java.util.ArrayList) BankOrder(com.axelor.apps.bankpayment.db.BankOrder) LocalDate(java.time.LocalDate) Transactional(com.google.inject.persist.Transactional)

Example 14 with InvoicePayment

use of com.axelor.apps.account.db.InvoicePayment in project axelor-open-suite by axelor.

the class InvoicePaymentController method validateMassPayment.

public void validateMassPayment(ActionRequest request, ActionResponse response) {
    try {
        InvoicePayment invoicePayment = request.getContext().asType(InvoicePayment.class);
        if (!ObjectUtils.isEmpty(request.getContext().get("_selectedInvoices"))) {
            List<Long> invoiceIdList = Lists.transform((List) request.getContext().get("_selectedInvoices"), new Function<Object, Long>() {

                @Nullable
                @Override
                public Long apply(@Nullable Object input) {
                    return Long.parseLong(input.toString());
                }
            });
            Beans.get(InvoicePaymentCreateService.class).createMassInvoicePayment(invoiceIdList, invoicePayment.getPaymentMode(), invoicePayment.getCompanyBankDetails(), invoicePayment.getPaymentDate(), invoicePayment.getBankDepositDate(), invoicePayment.getChequeNumber());
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
    response.setReload(true);
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) Nullable(javax.annotation.Nullable) InvoicePaymentCreateService(com.axelor.apps.account.service.payment.invoice.payment.InvoicePaymentCreateService) AxelorException(com.axelor.exception.AxelorException)

Example 15 with InvoicePayment

use of com.axelor.apps.account.db.InvoicePayment in project axelor-open-suite by axelor.

the class InvoicePaymentController method checkConditionBeforeSave.

/**
 * Method that check the invoice payment before save and save. Only use when add payment is used
 * in invoice
 *
 * @param request
 * @param response
 */
public void checkConditionBeforeSave(ActionRequest request, ActionResponse response) {
    try {
        InvoicePayment invoicePayment = request.getContext().asType(InvoicePayment.class);
        Beans.get(InvoicePaymentToolService.class).checkConditionBeforeSave(invoicePayment);
    } catch (Exception e) {
        TraceBackService.trace(response, e, ResponseMessageType.ERROR);
    }
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) InvoicePaymentToolService(com.axelor.apps.account.service.payment.invoice.payment.InvoicePaymentToolService) AxelorException(com.axelor.exception.AxelorException)

Aggregations

InvoicePayment (com.axelor.apps.account.db.InvoicePayment)31 Invoice (com.axelor.apps.account.db.Invoice)11 AxelorException (com.axelor.exception.AxelorException)9 Transactional (com.google.inject.persist.Transactional)9 BigDecimal (java.math.BigDecimal)8 ArrayList (java.util.ArrayList)7 MoveLine (com.axelor.apps.account.db.MoveLine)6 BankDetails (com.axelor.apps.base.db.BankDetails)6 Move (com.axelor.apps.account.db.Move)5 InvoicePaymentToolService (com.axelor.apps.account.service.payment.invoice.payment.InvoicePaymentToolService)4 LocalDate (java.time.LocalDate)4 PaymentMode (com.axelor.apps.account.db.PaymentMode)3 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)3 InvoicePaymentCreateService (com.axelor.apps.account.service.payment.invoice.payment.InvoicePaymentCreateService)3 BankOrder (com.axelor.apps.bankpayment.db.BankOrder)3 Map (java.util.Map)3 AccountingBatch (com.axelor.apps.account.db.AccountingBatch)2 Reconcile (com.axelor.apps.account.db.Reconcile)2 InvoicePaymentRepository (com.axelor.apps.account.db.repo.InvoicePaymentRepository)2 Company (com.axelor.apps.base.db.Company)2