Search in sources :

Example 31 with BankDetails

use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.

the class EbicsPartnerServiceImpl method checkBankDetailsMissingCurrency.

public void checkBankDetailsMissingCurrency(EbicsPartner ebicsPartner) throws AxelorException {
    List<com.axelor.apps.bankpayment.db.EbicsPartnerService> ebicsPartnerServiceSet = ebicsPartner.getBoEbicsPartnerServiceList();
    if (ebicsPartnerServiceSet == null) {
        return;
    }
    boolean allowOrderCurrDiffFromBankDetails = false;
    for (com.axelor.apps.bankpayment.db.EbicsPartnerService ebicsPartnerService : ebicsPartnerServiceSet) {
        allowOrderCurrDiffFromBankDetails = ebicsPartnerService.getBankOrderFileFormat().getAllowOrderCurrDiffFromBankDetails();
        if (allowOrderCurrDiffFromBankDetails) {
            break;
        }
    }
    if (!allowOrderCurrDiffFromBankDetails) {
        return;
    }
    Set<BankDetails> bankDetailsSet = ebicsPartner.getBankDetailsSet();
    if (bankDetailsSet == null) {
        return;
    }
    List<String> bankDetailsWithoutCurrency = new ArrayList<>();
    for (BankDetails bankDetails : bankDetailsSet) {
        if (bankDetails.getCurrency() == null) {
            bankDetailsWithoutCurrency.add(bankDetails.getFullName());
        }
    }
    if (!bankDetailsWithoutCurrency.isEmpty()) {
        Function<String, String> addLi = s -> "<li>".concat(s).concat("</li>");
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, String.format(I18n.get(IExceptionMessage.EBICS_PARTNER_BANK_DETAILS_WARNING), "<ul>" + Joiner.on("").join(Iterables.transform(bankDetailsWithoutCurrency, addLi)) + "<ul>"), ebicsPartner);
    }
}
Also used : EbicsUser(com.axelor.apps.bankpayment.db.EbicsUser) Iterables(com.google.common.collect.Iterables) BankStatementFileFormat(com.axelor.apps.bankpayment.db.BankStatementFileFormat) Date(java.util.Date) Inject(com.google.inject.Inject) LocalDateTime(java.time.LocalDateTime) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) BankStatementRepository(com.axelor.apps.bankpayment.db.repo.BankStatementRepository) Lists(com.google.common.collect.Lists) AxelorException(com.axelor.exception.AxelorException) I18n(com.axelor.i18n.I18n) IExceptionMessage(com.axelor.apps.bankpayment.exception.IExceptionMessage) DateTool(com.axelor.apps.tool.date.DateTool) Function(com.google.common.base.Function) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) EbicsPartner(com.axelor.apps.bankpayment.db.EbicsPartner) Collection(java.util.Collection) TraceBackService(com.axelor.exception.service.TraceBackService) Set(java.util.Set) IOException(java.io.IOException) File(java.io.File) EbicsPartnerRepository(com.axelor.apps.bankpayment.db.repo.EbicsPartnerRepository) List(java.util.List) Beans(com.axelor.inject.Beans) BankStatement(com.axelor.apps.bankpayment.db.BankStatement) LocalDate(java.time.LocalDate) BankStatementCreateService(com.axelor.apps.bankpayment.service.bankstatement.BankStatementCreateService) BankDetails(com.axelor.apps.base.db.BankDetails) Joiner(com.google.common.base.Joiner) AxelorException(com.axelor.exception.AxelorException) BankDetails(com.axelor.apps.base.db.BankDetails) ArrayList(java.util.ArrayList)

Example 32 with BankDetails

use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.

the class PaymentVoucherConfirmService method createMoveAndConfirm.

/**
 * Confirm payment voucher and create move.
 *
 * @param paymentVoucher
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public void createMoveAndConfirm(PaymentVoucher paymentVoucher) throws AxelorException {
    Partner payerPartner = paymentVoucher.getPartner();
    PaymentMode paymentMode = paymentVoucher.getPaymentMode();
    Company company = paymentVoucher.getCompany();
    BankDetails companyBankDetails = paymentVoucher.getCompanyBankDetails();
    Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
    LocalDate paymentDate = paymentVoucher.getPaymentDate();
    boolean scheduleToBePaid = false;
    Account paymentModeAccount = paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails);
    // If paid by a moveline check if all the lines selected have the same account + company
    // Excess payment
    boolean allRight = paymentVoucherControlService.checkIfSameAccount(paymentVoucher.getPayVoucherElementToPayList(), paymentVoucher.getMoveLine());
    // Check if allright=true (means companies and accounts in lines are all the same and same as in
    // move line selected for paying
    log.debug("allRight : {}", allRight);
    if (allRight) {
        scheduleToBePaid = this.toPayWithExcessPayment(paymentVoucher.getPayVoucherElementToPayList(), paymentVoucher.getMoveLine(), scheduleToBePaid, paymentDate);
    }
    if (paymentVoucher.getMoveLine() == null || (paymentVoucher.getMoveLine() != null && !allRight) || (scheduleToBePaid && !allRight && paymentVoucher.getMoveLine() != null)) {
        // Manage all the cases in the same way. As if a move line (Excess payment) is selected, we
        // cancel it first
        Move move = moveService.getMoveCreateService().createMoveWithPaymentVoucher(journal, company, paymentVoucher, payerPartner, paymentDate, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
        move.setPaymentVoucher(paymentVoucher);
        move.setTradingName(paymentVoucher.getTradingName());
        paymentVoucher.setGeneratedMove(move);
        // Create move lines for payment lines
        BigDecimal paidLineTotal = BigDecimal.ZERO;
        int moveLineNo = 1;
        boolean isDebitToPay = paymentVoucherToolService.isDebitToPay(paymentVoucher);
        for (PayVoucherElementToPay payVoucherElementToPay : this.getPayVoucherElementToPayList(paymentVoucher)) {
            MoveLine moveLineToPay = payVoucherElementToPay.getMoveLine();
            log.debug("PV moveLineToPay debit : {}", moveLineToPay.getDebit());
            log.debug("PV moveLineToPay amountPaid : {}", moveLineToPay.getAmountPaid());
            BigDecimal amountToPay = payVoucherElementToPay.getAmountToPayCurrency();
            if (amountToPay.compareTo(BigDecimal.ZERO) > 0) {
                paidLineTotal = paidLineTotal.add(amountToPay);
                this.payMoveLine(move, moveLineNo++, payerPartner, moveLineToPay, amountToPay, payVoucherElementToPay, isDebitToPay, paymentDate);
            }
        }
        // Create move line for the payment amount
        MoveLine moveLine = null;
        // in the else case we create a classical balance on the bank account of the payment mode
        if (paymentVoucher.getMoveLine() != null) {
            moveLine = moveLineService.createMoveLine(move, paymentVoucher.getPartner(), paymentVoucher.getMoveLine().getAccount(), paymentVoucher.getPaidAmount(), isDebitToPay, paymentDate, moveLineNo++, paymentVoucher.getRef(), null);
            Reconcile reconcile = reconcileService.createReconcile(moveLine, paymentVoucher.getMoveLine(), moveLine.getDebit(), !isDebitToPay);
            if (reconcile != null) {
                reconcileService.confirmReconcile(reconcile, true);
            }
        } else {
            moveLine = moveLineService.createMoveLine(move, payerPartner, paymentModeAccount, paymentVoucher.getPaidAmount(), isDebitToPay, paymentDate, moveLineNo++, paymentVoucher.getRef(), null);
        }
        move.getMoveLineList().add(moveLine);
        // Then Use Excess payment on old invoices / moveLines
        if (paymentVoucher.getPaidAmount().compareTo(paidLineTotal) > 0) {
            BigDecimal remainingPaidAmount = paymentVoucher.getRemainingAmount();
            // TODO rajouter le process d'imputation automatique
            // if(paymentVoucher.getHasAutoInput())  {
            // 
            // List<MoveLine> debitMoveLines =
            // Lists.newArrayList(pas.getDebitLinesToPay(contractLine,
            // paymentVoucher.getPaymentScheduleToPay()));
            // pas.createExcessPaymentWithAmount(debitMoveLines, remainingPaidAmount,
            // move, moveLineNo,
            // paymentVoucher.getPayerPartner(), company, contractLine, null,
            // paymentDate, updateCustomerAccount);
            // }
            // else  {
            Account partnerAccount = Beans.get(AccountCustomerService.class).getPartnerAccount(payerPartner, company, paymentVoucherToolService.isPurchase(paymentVoucher));
            moveLine = moveLineService.createMoveLine(move, paymentVoucher.getPartner(), partnerAccount, remainingPaidAmount, !isDebitToPay, paymentDate, moveLineNo++, paymentVoucher.getRef(), null);
            move.getMoveLineList().add(moveLine);
            if (isDebitToPay) {
                reconcileService.balanceCredit(moveLine);
            }
        }
        moveService.getMoveValidateService().validate(move);
        paymentVoucher.setGeneratedMove(move);
    }
    paymentVoucher.setStatusSelect(PaymentVoucherRepository.STATUS_CONFIRMED);
    deleteUnPaidLines(paymentVoucher);
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) AccountCustomerService(com.axelor.apps.account.service.AccountCustomerService) BankDetails(com.axelor.apps.base.db.BankDetails) Journal(com.axelor.apps.account.db.Journal) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) PayVoucherElementToPay(com.axelor.apps.account.db.PayVoucherElementToPay) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) Partner(com.axelor.apps.base.db.Partner) PaymentMode(com.axelor.apps.account.db.PaymentMode) Reconcile(com.axelor.apps.account.db.Reconcile) Transactional(com.google.inject.persist.Transactional)

Example 33 with BankDetails

use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.

the class PaymentVoucherConfirmService method confirmPaymentVoucher.

/**
 * Confirms the payment voucher if the selected lines PiToPay 2nd O2M belongs to different
 * companies -> error I - Payment with an amount If we pay a classical moveLine (invoice, reject
 * ..) -> just create a payment If we pay a schedule 2 payments are created 1st reconciled with
 * the invoice and the second reconciled with the schedule II - Payment with an excess Payment If
 * we pay a moveLine having the same account, we just reconcile If we pay a with different account
 * -> 1- switch money to the good account 2- reconcile then
 *
 * @param paymentVoucher
 */
@Transactional(rollbackOn = { Exception.class })
public void confirmPaymentVoucher(PaymentVoucher paymentVoucher) throws AxelorException {
    log.debug("In confirmPaymentVoucherService ....");
    paymentVoucherSequenceService.setReference(paymentVoucher);
    PaymentMode paymentMode = paymentVoucher.getPaymentMode();
    Company company = paymentVoucher.getCompany();
    BankDetails companyBankDetails = paymentVoucher.getCompanyBankDetails();
    Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
    Account paymentModeAccount = paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails);
    paymentVoucherControlService.checkPaymentVoucherField(paymentVoucher, company, paymentModeAccount, journal);
    if (paymentVoucher.getRemainingAmount().compareTo(BigDecimal.ZERO) > 0 && !journal.getExcessPaymentOk()) {
        throw new AxelorException(paymentVoucher, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.PAYMENT_AMOUNT_EXCEEDING), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
    }
    // TODO VEIRIFER QUE LES ELEMENTS A PAYER NE CONCERNE QU'UNE SEULE DEVISE
    // TODO RECUPERER DEVISE DE LA PREMIERE DETTE
    // Currency currencyToPay = null;
    AppAccountService appAccountService = Beans.get(AppAccountService.class);
    if (appAccountService.getAppAccount().getPaymentVouchersOnInvoice() && paymentVoucher.getPaymentMode().getValidatePaymentByDepositSlipPublication()) {
        waitForDepositSlip(paymentVoucher);
    } else {
        createMoveAndConfirm(paymentVoucher);
    }
    paymentVoucherSequenceService.setReceiptNo(paymentVoucher, company, journal);
    paymentVoucherRepository.save(paymentVoucher);
}
Also used : Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) BankDetails(com.axelor.apps.base.db.BankDetails) Journal(com.axelor.apps.account.db.Journal) PaymentMode(com.axelor.apps.account.db.PaymentMode) AppAccountService(com.axelor.apps.account.service.app.AppAccountService) Transactional(com.google.inject.persist.Transactional)

Example 34 with BankDetails

use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.

the class PaymentVoucherLoadService method initFromInvoice.

/**
 * Initialize a payment voucher from an invoice.
 *
 * @param paymentVoucher
 * @param invoice
 * @throws AxelorException
 */
public void initFromInvoice(PaymentVoucher paymentVoucher, Invoice invoice) throws AxelorException {
    paymentVoucher.setOperationTypeSelect(invoice.getOperationTypeSelect());
    paymentVoucher.setPartner(invoice.getPartner());
    paymentVoucher.setPaymentMode(invoice.getPaymentMode());
    paymentVoucher.setCurrency(invoice.getCurrency());
    paymentVoucher.clearPayVoucherDueElementList();
    paymentVoucher.clearPayVoucherElementToPayList();
    paymentVoucher.setCompany(invoice.getCompany());
    BankDetails companyBankDetails;
    if (invoice.getCompanyBankDetails() != null) {
        companyBankDetails = invoice.getCompanyBankDetails();
    } else {
        companyBankDetails = Beans.get(BankDetailsService.class).getDefaultCompanyBankDetails(invoice.getCompany(), invoice.getPaymentMode(), invoice.getPartner(), null);
    }
    paymentVoucher.setCompanyBankDetails(companyBankDetails);
    BigDecimal amount = BigDecimal.ZERO;
    List<MoveLine> moveLineList = getMoveLines(paymentVoucher);
    for (MoveLine moveLine : moveLineList) {
        PayVoucherDueElement payVoucherDueElement = createPayVoucherDueElement(moveLine);
        paymentVoucher.addPayVoucherDueElementListItem(payVoucherDueElement);
        if (invoice.equals(payVoucherDueElement.getMoveLine().getMove().getInvoice())) {
            amount = amount.add(payVoucherDueElement.getAmountRemaining());
        }
    }
    paymentVoucher.setPaidAmount(amount);
    paymentVoucher.clearPayVoucherDueElementList();
    for (MoveLine moveLine : moveLineList) {
        paymentVoucher.addPayVoucherDueElementListItem(createPayVoucherDueElement(moveLine));
    }
    if (paymentVoucher.getPayVoucherDueElementList() == null) {
        return;
    }
    int sequence = 0;
    for (Iterator<PayVoucherDueElement> it = paymentVoucher.getPayVoucherDueElementList().iterator(); it.hasNext(); ) {
        PayVoucherDueElement payVoucherDueElement = it.next();
        if (invoice.equals(payVoucherDueElement.getMoveLine().getMove().getInvoice()) && paymentVoucher.getCurrency().equals(payVoucherDueElement.getCurrency())) {
            paymentVoucher.addPayVoucherElementToPayListItem(createPayVoucherElementToPay(paymentVoucher, payVoucherDueElement, ++sequence));
            it.remove();
        }
    }
}
Also used : BankDetails(com.axelor.apps.base.db.BankDetails) MoveLine(com.axelor.apps.account.db.MoveLine) PayVoucherDueElement(com.axelor.apps.account.db.PayVoucherDueElement) BigDecimal(java.math.BigDecimal)

Example 35 with BankDetails

use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.

the class InvoicePaymentController method fillBankDetails.

/**
 * On payment mode change, fill the bank details field if we find precisely one bank details
 * available in the payment mode for the current company.
 *
 * @param request
 * @param response
 * @throws AxelorException
 */
@SuppressWarnings("unchecked")
public void fillBankDetails(ActionRequest request, ActionResponse response) throws AxelorException {
    InvoicePayment invoicePayment = request.getContext().asType(InvoicePayment.class);
    Map<String, Object> partialInvoice = (Map<String, Object>) request.getContext().get("_invoice");
    Invoice invoice = Beans.get(InvoiceRepository.class).find(((Integer) partialInvoice.get("id")).longValue());
    PaymentMode paymentMode = invoicePayment.getPaymentMode();
    Company company = invoice.getCompany();
    List<BankDetails> bankDetailsList = Beans.get(InvoicePaymentToolService.class).findCompatibleBankDetails(company, invoicePayment);
    if (bankDetailsList.size() == 1) {
        response.setValue("companyBankDetails", bankDetailsList.get(0));
    } else {
        response.setValue("companyBankDetails", null);
    }
    Partner partner = invoice.getPartner();
    if (company == null) {
        return;
    }
    if (partner != null) {
        partner = Beans.get(PartnerRepository.class).find(partner.getId());
    }
    BankDetails defaultBankDetails = Beans.get(BankDetailsService.class).getDefaultCompanyBankDetails(company, paymentMode, partner, null);
    response.setValue("bankDetails", defaultBankDetails);
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) BankDetails(com.axelor.apps.base.db.BankDetails) BankDetailsService(com.axelor.apps.base.service.BankDetailsService) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) InvoicePaymentToolService(com.axelor.apps.account.service.payment.invoice.payment.InvoicePaymentToolService) Map(java.util.Map) Partner(com.axelor.apps.base.db.Partner) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Aggregations

BankDetails (com.axelor.apps.base.db.BankDetails)63 Partner (com.axelor.apps.base.db.Partner)26 AxelorException (com.axelor.exception.AxelorException)26 PaymentMode (com.axelor.apps.account.db.PaymentMode)22 Company (com.axelor.apps.base.db.Company)22 BigDecimal (java.math.BigDecimal)14 LocalDate (java.time.LocalDate)13 Transactional (com.google.inject.persist.Transactional)12 ArrayList (java.util.ArrayList)11 Invoice (com.axelor.apps.account.db.Invoice)10 Journal (com.axelor.apps.account.db.Journal)9 BankDetailsService (com.axelor.apps.base.service.BankDetailsService)8 PaymentModeService (com.axelor.apps.account.service.payment.PaymentModeService)7 BankOrderLine (com.axelor.apps.bankpayment.db.BankOrderLine)7 Currency (com.axelor.apps.base.db.Currency)7 Account (com.axelor.apps.account.db.Account)6 AccountConfig (com.axelor.apps.account.db.AccountConfig)6 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)6 Move (com.axelor.apps.account.db.Move)6 MoveLine (com.axelor.apps.account.db.MoveLine)6