Search in sources :

Example 26 with PaymentMode

use of com.axelor.apps.account.db.PaymentMode 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 27 with PaymentMode

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

the class InvoiceController method mergeInvoice.

// Generate single invoice from several
@SuppressWarnings({ "rawtypes", "unchecked" })
public void mergeInvoice(ActionRequest request, ActionResponse response) {
    List<Invoice> invoiceList = new ArrayList<>();
    List<Long> invoiceIdList = new ArrayList<>();
    boolean fromPopup = false;
    if (request.getContext().get("invoiceToMerge") != null) {
        if (request.getContext().get("invoiceToMerge") instanceof List) {
            // No confirmation popup, invoices are content in a parameter list
            List<Map> invoiceMap = (List<Map>) request.getContext().get("invoiceToMerge");
            for (Map map : invoiceMap) {
                invoiceIdList.add(new Long((Integer) map.get("id")));
            }
        } else {
            // After confirmation popup, invoice's id are in a string separated by ","
            String invoiceIdListStr = (String) request.getContext().get("invoiceToMerge");
            for (String invoiceId : invoiceIdListStr.split(",")) {
                invoiceIdList.add(new Long(invoiceId));
            }
            fromPopup = true;
        }
    }
    // Check if company, currency and partner are the same for all selected invoices
    Company commonCompany = null;
    Currency commonCurrency = null;
    Partner commonPartner = null;
    PaymentCondition commonPaymentCondition = null;
    // Useful to determine if a difference exists between payment conditions of all invoices
    boolean existPaymentConditionDiff = false;
    Partner commonContactPartner = null;
    // Useful to determine if a difference exists between contact partners of all purchase orders
    boolean existContactPartnerDiff = false;
    PriceList commonPriceList = null;
    // Useful to determine if a difference exists between price lists of all purchase orders
    boolean existPriceListDiff = false;
    PaymentMode commonPaymentMode = null;
    // Useful to determine if a difference exists between locations of all purchase orders
    boolean existPaymentModeDiff = false;
    Invoice invoiceTemp;
    int count = 1;
    for (Long invoiceId : invoiceIdList) {
        invoiceTemp = Beans.get(InvoiceRepository.class).find(invoiceId);
        invoiceList.add(invoiceTemp);
        if (count == 1) {
            commonCompany = invoiceTemp.getCompany();
            commonCurrency = invoiceTemp.getCurrency();
            commonPartner = invoiceTemp.getPartner();
            commonPaymentCondition = invoiceTemp.getPaymentCondition();
            commonContactPartner = invoiceTemp.getContactPartner();
            commonPriceList = invoiceTemp.getPriceList();
            commonPaymentMode = invoiceTemp.getPaymentMode();
        } else {
            if (commonCompany != null && !commonCompany.equals(invoiceTemp.getCompany())) {
                commonCompany = null;
            }
            if (commonCurrency != null && !commonCurrency.equals(invoiceTemp.getCurrency())) {
                commonCurrency = null;
            }
            if (commonPartner != null && !commonPartner.equals(invoiceTemp.getPartner())) {
                commonPartner = null;
            }
            if (commonPaymentCondition != null && !commonPaymentCondition.equals(invoiceTemp.getPaymentCondition())) {
                commonPaymentCondition = null;
                existPaymentConditionDiff = true;
            }
            if (commonContactPartner != null && !commonContactPartner.equals(invoiceTemp.getContactPartner())) {
                commonContactPartner = null;
                existContactPartnerDiff = true;
            }
            if (commonPriceList != null && !commonPriceList.equals(invoiceTemp.getPriceList())) {
                commonPriceList = null;
                existPriceListDiff = true;
            }
            if (commonPaymentMode != null && !commonPaymentMode.equals(invoiceTemp.getPaymentMode())) {
                commonPaymentMode = null;
                existPaymentModeDiff = true;
            }
        }
        count++;
    }
    StringBuilder fieldErrors = new StringBuilder();
    if (commonCurrency == null) {
        fieldErrors.append(I18n.get(IExceptionMessage.INVOICE_MERGE_ERROR_CURRENCY));
    }
    if (commonCompany == null) {
        if (fieldErrors.length() > 0) {
            fieldErrors.append("<br/>");
        }
        fieldErrors.append(I18n.get(IExceptionMessage.INVOICE_MERGE_ERROR_COMPANY));
    }
    if (commonPartner == null) {
        if (fieldErrors.length() > 0) {
            fieldErrors.append("<br/>");
        }
        fieldErrors.append(I18n.get(IExceptionMessage.INVOICE_MERGE_ERROR_PARTNER));
    }
    if (fieldErrors.length() > 0) {
        response.setFlash(fieldErrors.toString());
        return;
    }
    // content in parameters
    if (request.getContext().get("contactPartner") != null) {
        commonContactPartner = JPA.em().find(Partner.class, new Long((Integer) ((Map) request.getContext().get("contactPartner")).get("id")));
    }
    if (request.getContext().get("priceList") != null) {
        commonPriceList = JPA.em().find(PriceList.class, new Long((Integer) ((Map) request.getContext().get("priceList")).get("id")));
    }
    if (request.getContext().get("paymentMode") != null) {
        commonPaymentMode = JPA.em().find(PaymentMode.class, new Long((Integer) ((Map) request.getContext().get("paymentMode")).get("id")));
    }
    if (request.getContext().get("paymentCondition") != null) {
        commonPaymentCondition = JPA.em().find(PaymentCondition.class, new Long((Integer) ((Map) request.getContext().get("paymentCondition")).get("id")));
    }
    if (!fromPopup && (existPaymentConditionDiff || existContactPartnerDiff || existPriceListDiff || existPaymentModeDiff)) {
        // Need to display intermediate screen to select some values
        ActionViewBuilder confirmView = ActionView.define("Confirm merge invoice").model(Wizard.class.getName()).add("form", "customer-invoices-merge-confirm-form").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true");
        if (existContactPartnerDiff) {
            confirmView.context("contextContactPartnerToCheck", "true");
            confirmView.context("contextPartnerId", commonPartner.getId().toString());
        }
        if (existPriceListDiff) {
            confirmView.context("contextPriceListToCheck", "true");
        }
        if (existPaymentModeDiff) {
            confirmView.context("contextPaymentModeToCheck", "true");
        }
        if (existPaymentConditionDiff) {
            confirmView.context("contextPaymentConditionToCheck", "true");
        }
        confirmView.context("invoiceToMerge", Joiner.on(",").join(invoiceIdList));
        response.setView(confirmView.map());
        return;
    }
    try {
        Invoice invoice = Beans.get(InvoiceService.class).mergeInvoiceProcess(invoiceList, commonCompany, commonCurrency, commonPartner, commonContactPartner, commonPriceList, commonPaymentMode, commonPaymentCondition);
        if (invoice != null) {
            // Open the generated invoice in a new tab
            response.setView(ActionView.define("Invoice").model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(invoice.getId())).map());
            response.setCanClose(true);
        }
    } catch (Exception e) {
        response.setFlash(e.getLocalizedMessage());
    }
}
Also used : PaymentCondition(com.axelor.apps.account.db.PaymentCondition) Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) ArrayList(java.util.ArrayList) InvoiceService(com.axelor.apps.account.service.invoice.InvoiceService) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) AxelorException(com.axelor.exception.AxelorException) Currency(com.axelor.apps.base.db.Currency) List(java.util.List) PriceList(com.axelor.apps.base.db.PriceList) ArrayList(java.util.ArrayList) Map(java.util.Map) Partner(com.axelor.apps.base.db.Partner) PriceList(com.axelor.apps.base.db.PriceList) Wizard(com.axelor.apps.base.db.Wizard) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 28 with PaymentMode

use of com.axelor.apps.account.db.PaymentMode 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)

Example 29 with PaymentMode

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

the class InvoicePaymentValidateServiceImpl method createMoveForInvoicePayment.

/**
 * Method to create a payment move for an invoice Payment
 *
 * <p>Create a move and reconcile it with the invoice move
 *
 * @param invoicePayment An invoice payment
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public InvoicePayment createMoveForInvoicePayment(InvoicePayment invoicePayment) throws AxelorException {
    Invoice invoice = invoicePayment.getInvoice();
    Company company = invoice.getCompany();
    PaymentMode paymentMode = invoicePayment.getPaymentMode();
    Partner partner = invoice.getPartner();
    LocalDate paymentDate = invoicePayment.getPaymentDate();
    BigDecimal paymentAmount = invoicePayment.getAmount();
    BankDetails companyBankDetails = invoicePayment.getCompanyBankDetails();
    Account customerAccount;
    Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
    boolean isDebitInvoice = moveService.getMoveToolService().isDebitCustomer(invoice, true);
    MoveLine invoiceMoveLine = moveService.getMoveToolService().getInvoiceCustomerMoveLineByLoop(invoice);
    if (invoice.getOperationSubTypeSelect() == InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE) {
        AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
        customerAccount = accountConfigService.getAdvancePaymentAccount(accountConfig);
    } else {
        if (invoiceMoveLine == null) {
            return null;
        }
        customerAccount = invoiceMoveLine.getAccount();
    }
    String origin = invoicePayment.getInvoice().getInvoiceId();
    if (invoicePayment.getPaymentMode().getTypeSelect() == PaymentModeRepository.TYPE_CHEQUE || invoicePayment.getPaymentMode().getTypeSelect() == PaymentModeRepository.TYPE_IPO_CHEQUE) {
        origin = invoicePayment.getChequeNumber() != null ? invoicePayment.getChequeNumber() : origin;
    } else if (invoicePayment.getPaymentMode().getTypeSelect() == PaymentModeRepository.TYPE_BANK_CARD) {
        origin = invoicePayment.getInvoicePaymentRef() != null ? invoicePayment.getInvoicePaymentRef() : origin;
    }
    if (invoicePayment.getInvoice().getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE || invoicePayment.getInvoice().getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND) {
        origin = invoicePayment.getInvoice().getSupplierInvoiceNb();
    }
    Move move = moveService.getMoveCreateService().createMove(journal, company, invoicePayment.getCurrency(), partner, paymentDate, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
    move.setTradingName(invoice.getTradingName());
    move.addMoveLineListItem(moveLineService.createMoveLine(move, partner, paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails), paymentAmount, isDebitInvoice, paymentDate, null, 1, origin, invoicePayment.getDescription()));
    MoveLine customerMoveLine = moveLineService.createMoveLine(move, partner, customerAccount, paymentAmount, !isDebitInvoice, paymentDate, null, 2, origin, invoicePayment.getDescription());
    move.addMoveLineListItem(customerMoveLine);
    moveService.getMoveValidateService().validate(move);
    if (invoice.getOperationSubTypeSelect() != InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE) {
        Reconcile reconcile = reconcileService.reconcile(invoiceMoveLine, customerMoveLine, true, false);
        invoicePayment.setReconcile(reconcile);
    }
    invoicePayment.setMove(move);
    invoicePaymentRepository.save(invoicePayment);
    return invoicePayment;
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) BankDetails(com.axelor.apps.base.db.BankDetails) Journal(com.axelor.apps.account.db.Journal) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) 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 30 with PaymentMode

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

the class ExpenseServiceImpl method createMoveForExpensePayment.

public Move createMoveForExpensePayment(Expense expense) throws AxelorException {
    Company company = expense.getCompany();
    PaymentMode paymentMode = expense.getPaymentMode();
    Partner partner = expense.getUser().getPartner();
    LocalDate paymentDate = expense.getPaymentDate();
    BigDecimal paymentAmount = expense.getInTaxTotal();
    BankDetails companyBankDetails = company.getDefaultBankDetails();
    Account employeeAccount;
    Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
    MoveLine expenseMoveLine = this.getExpenseEmployeeMoveLineByLoop(expense);
    if (expenseMoveLine == null) {
        return null;
    }
    employeeAccount = expenseMoveLine.getAccount();
    Move move = moveService.getMoveCreateService().createMove(journal, company, expense.getMove().getCurrency(), partner, paymentDate, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
    move.addMoveLineListItem(moveLineService.createMoveLine(move, partner, paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails), paymentAmount, false, paymentDate, null, 1, expense.getExpenseSeq(), null));
    MoveLine employeeMoveLine = moveLineService.createMoveLine(move, partner, employeeAccount, paymentAmount, true, paymentDate, null, 2, expense.getExpenseSeq(), null);
    employeeMoveLine.setTaxAmount(expense.getTaxTotal());
    move.addMoveLineListItem(employeeMoveLine);
    moveService.getMoveValidateService().validate(move);
    expense.setPaymentMove(move);
    Beans.get(ReconcileService.class).reconcile(expenseMoveLine, employeeMoveLine, true, false);
    expenseRepository.save(expense);
    return move;
}
Also used : AnalyticAccount(com.axelor.apps.account.db.AnalyticAccount) Account(com.axelor.apps.account.db.Account) ReconcileService(com.axelor.apps.account.service.ReconcileService) Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) BankDetails(com.axelor.apps.base.db.BankDetails) MoveLine(com.axelor.apps.account.db.MoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) Journal(com.axelor.apps.account.db.Journal) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Aggregations

PaymentMode (com.axelor.apps.account.db.PaymentMode)45 Company (com.axelor.apps.base.db.Company)27 Partner (com.axelor.apps.base.db.Partner)26 BankDetails (com.axelor.apps.base.db.BankDetails)21 Invoice (com.axelor.apps.account.db.Invoice)18 AxelorException (com.axelor.exception.AxelorException)17 Transactional (com.google.inject.persist.Transactional)13 BigDecimal (java.math.BigDecimal)11 LocalDate (java.time.LocalDate)10 PaymentCondition (com.axelor.apps.account.db.PaymentCondition)9 Currency (com.axelor.apps.base.db.Currency)9 ArrayList (java.util.ArrayList)8 Journal (com.axelor.apps.account.db.Journal)7 PaymentModeService (com.axelor.apps.account.service.payment.PaymentModeService)7 Map (java.util.Map)7 BankOrder (com.axelor.apps.bankpayment.db.BankOrder)6 BankDetailsService (com.axelor.apps.base.service.BankDetailsService)6 Account (com.axelor.apps.account.db.Account)5 Move (com.axelor.apps.account.db.Move)5 PriceList (com.axelor.apps.base.db.PriceList)5