Search in sources :

Example 41 with PaymentMode

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

the class AccountingSituationInitServiceImpl method createAccountingSituation.

@Override
@Transactional(rollbackOn = { Exception.class })
public AccountingSituation createAccountingSituation(Partner partner, Company company) throws AxelorException {
    AccountingSituation accountingSituation = new AccountingSituation();
    accountingSituation.setCompany(company);
    partner.addCompanySetItem(company);
    PaymentMode inPaymentMode = partner.getInPaymentMode();
    PaymentMode outPaymentMode = partner.getOutPaymentMode();
    BankDetails defaultBankDetails = company.getDefaultBankDetails();
    if (inPaymentMode != null) {
        List<BankDetails> authorizedInBankDetails = paymentModeService.getCompatibleBankDetailsList(inPaymentMode, company);
        if (authorizedInBankDetails.contains(defaultBankDetails)) {
            accountingSituation.setCompanyInBankDetails(defaultBankDetails);
        }
    }
    if (outPaymentMode != null) {
        List<BankDetails> authorizedOutBankDetails = paymentModeService.getCompatibleBankDetailsList(outPaymentMode, company);
        if (authorizedOutBankDetails.contains(defaultBankDetails)) {
            accountingSituation.setCompanyOutBankDetails(defaultBankDetails);
        }
    }
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    accountingSituation.setInvoiceAutomaticMail(accountConfig.getInvoiceAutomaticMail());
    accountingSituation.setInvoiceMessageTemplate(accountConfig.getInvoiceMessageTemplate());
    partner.addAccountingSituationListItem(accountingSituation);
    return accountingSituationRepository.save(accountingSituation);
}
Also used : BankDetails(com.axelor.apps.base.db.BankDetails) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) PaymentMode(com.axelor.apps.account.db.PaymentMode) AccountConfig(com.axelor.apps.account.db.AccountConfig) Transactional(com.google.inject.persist.Transactional)

Example 42 with PaymentMode

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

the class BatchBankPaymentServiceImpl method createBankOrderFromMonthlyPaymentScheduleLines.

@Override
@Transactional(rollbackOn = { Exception.class })
public BankOrder createBankOrderFromMonthlyPaymentScheduleLines(Batch batch) throws AxelorException, JAXBException, IOException, DatatypeConfigurationException {
    AccountingBatch accountingBatch = batch.getAccountingBatch();
    LocalDate bankOrderDate = accountingBatch.getDueDate();
    Company senderCompany = accountingBatch.getCompany();
    BankDetails senderBankDetails = accountingBatch.getBankDetails();
    if (senderBankDetails == null) {
        senderBankDetails = accountingBatch.getCompany().getDefaultBankDetails();
    }
    PaymentMode paymentMode = accountingBatch.getPaymentMode();
    Currency currency = senderCompany.getCurrency();
    int partnerType = BankOrderRepository.PARTNER_TYPE_CUSTOMER;
    String senderReference = "";
    String senderLabel = "";
    if (bankOrderDate == null) {
        bankOrderDate = appBaseService.getTodayDate(senderCompany);
    }
    BankOrder bankOrder = bankOrderCreateService.createBankOrder(paymentMode, partnerType, bankOrderDate, senderCompany, senderBankDetails, currency, senderReference, senderLabel, BankOrderRepository.TECHNICAL_ORIGIN_AUTOMATIC);
    bankOrder = JPA.save(bankOrder);
    List<PaymentScheduleLine> paymentScheduleLineList;
    int offset = 0;
    try {
        while (!(paymentScheduleLineList = fetchPaymentScheduleLineDoneList(batch, offset)).isEmpty()) {
            bankOrder = bankOrderRepo.find(bankOrder.getId());
            for (PaymentScheduleLine paymentScheduleLine : paymentScheduleLineList) {
                PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
                Partner partner = paymentSchedule.getPartner();
                BankDetails bankDetails = paymentScheduleService.getBankDetails(paymentSchedule);
                BigDecimal amount = paymentScheduleLine.getInTaxAmount();
                String receiverReference = paymentScheduleLine.getName();
                String receiverLabel = paymentScheduleLine.getDebitNumber();
                BankOrderLine bankOrderLine = bankOrderLineService.createBankOrderLine(paymentMode.getBankOrderFileFormat(), null, partner, bankDetails, amount, currency, bankOrderDate, receiverReference, receiverLabel, paymentScheduleLine);
                bankOrder.addBankOrderLineListItem(bankOrderLine);
            }
            bankOrder = JPA.save(bankOrder);
            offset += paymentScheduleLineList.size();
            JPA.clear();
        }
    } catch (Exception e) {
        bankOrder = bankOrderRepo.find(bankOrder.getId());
        bankOrderRepo.remove(bankOrder);
        throw e;
    }
    bankOrder = bankOrderRepo.find(bankOrder.getId());
    bankOrder = bankOrderRepo.save(bankOrder);
    bankOrderService.confirm(bankOrder);
    batch = batchRepo.find(batch.getId());
    batch.setBankOrder(bankOrder);
    return bankOrder;
}
Also used : Company(com.axelor.apps.base.db.Company) BankOrderLine(com.axelor.apps.bankpayment.db.BankOrderLine) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) BankDetails(com.axelor.apps.base.db.BankDetails) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) Currency(com.axelor.apps.base.db.Currency) AccountingBatch(com.axelor.apps.account.db.AccountingBatch) BankOrder(com.axelor.apps.bankpayment.db.BankOrder) Partner(com.axelor.apps.base.db.Partner) PaymentMode(com.axelor.apps.account.db.PaymentMode) Transactional(com.google.inject.persist.Transactional)

Example 43 with PaymentMode

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

the class BatchDirectDebitPaymentSchedule method processQuery.

private void processQuery(QueryBuilder<PaymentScheduleLine> queryBuilder) {
    Query<PaymentScheduleLine> query = queryBuilder.build();
    List<PaymentScheduleLine> paymentScheduleLineList;
    PaymentScheduleService paymentScheduleService = Beans.get(PaymentScheduleService.class);
    PaymentScheduleLineService paymentScheduleLineService = Beans.get(PaymentScheduleLineService.class);
    BankDetailsRepository bankDetailsRepo = Beans.get(BankDetailsRepository.class);
    BankDetails companyBankDetails = getCompanyBankDetails(batch.getAccountingBatch());
    while (!(paymentScheduleLineList = query.fetch(FETCH_LIMIT)).isEmpty()) {
        findBatch();
        companyBankDetails = bankDetailsRepo.find(companyBankDetails.getId());
        PaymentMode directDebitPaymentMode = batch.getAccountingBatch().getPaymentMode();
        for (PaymentScheduleLine paymentScheduleLine : paymentScheduleLineList) {
            try {
                if (generateBankOrderFlag) {
                    PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
                    BankDetails bankDetails = paymentScheduleService.getBankDetails(paymentSchedule);
                    Preconditions.checkArgument(bankDetails.getActive(), bankDetails.getPartner() != null ? bankDetails.getPartner().getFullName() + " - " + I18n.get("Bank details are inactive.") : I18n.get("Bank details are inactive."));
                    if (directDebitPaymentMode.getOrderTypeSelect() == PaymentModeRepository.ORDER_TYPE_SEPA_DIRECT_DEBIT) {
                        Partner partner = paymentSchedule.getPartner();
                        Preconditions.checkNotNull(partner, I18n.get("Partner is missing."));
                        Preconditions.checkNotNull(partner.getActiveUmr(), I18n.get("Partner active UMR is missing."));
                    }
                }
                paymentScheduleLineService.createPaymentMove(paymentScheduleLine, companyBankDetails, directDebitPaymentMode);
                incrementDone(paymentScheduleLine);
            } catch (Exception e) {
                TraceBackService.trace(e, ExceptionOriginRepository.DIRECT_DEBIT, batch.getId());
                incrementAnomaly(paymentScheduleLine);
                break;
            }
        }
        JPA.clear();
    }
}
Also used : PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) BankDetailsRepository(com.axelor.apps.base.db.repo.BankDetailsRepository) BankDetails(com.axelor.apps.base.db.BankDetails) PaymentScheduleService(com.axelor.apps.account.service.PaymentScheduleService) PaymentScheduleLineService(com.axelor.apps.account.service.PaymentScheduleLineService) Partner(com.axelor.apps.base.db.Partner) AxelorException(com.axelor.exception.AxelorException) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 44 with PaymentMode

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

the class InvoicePaymentValidateServiceBankPayImpl method createInvoicePaymentMove.

@Override
protected void createInvoicePaymentMove(InvoicePayment invoicePayment) throws AxelorException, JAXBException, IOException, DatatypeConfigurationException {
    Invoice invoice = invoicePayment.getInvoice();
    Company company = invoice.getCompany();
    PaymentMode paymentMode = invoicePayment.getPaymentMode();
    if (accountConfigService.getAccountConfig(company).getGenerateMoveForInvoicePayment() && !paymentMode.getGenerateBankOrder()) {
        invoicePayment = this.createMoveForInvoicePayment(invoicePayment);
    } else {
        Beans.get(AccountingSituationService.class).updateCustomerCredit(invoicePayment.getInvoice().getPartner());
        invoicePayment = invoicePaymentRepository.save(invoicePayment);
    }
    if (paymentMode.getGenerateBankOrder()) {
        this.createBankOrder(invoicePayment);
    }
}
Also used : Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) AccountingSituationService(com.axelor.apps.account.service.AccountingSituationService) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 45 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<Invoice>();
    List<Long> invoiceIdList = new ArrayList<Long>();
    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;
    SaleOrder commonSaleOrder = null;
    // Useful to check if all sale orders are null (since this field is not required)
    boolean saleOrderIsNull = false;
    Project commonProject = null;
    // Useful to check if all projects are null (since this field is not required)
    boolean projectIsNull = false;
    Invoice invoiceTemp;
    int count = 1;
    for (Long invoiceId : invoiceIdList) {
        invoiceTemp = JPA.em().find(Invoice.class, 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();
            commonSaleOrder = invoiceTemp.getSaleOrder();
            commonProject = invoiceTemp.getProject();
            if (commonSaleOrder == null) {
                saleOrderIsNull = true;
            }
            if (commonProject == null) {
                projectIsNull = true;
            }
        } 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;
            }
            if (commonSaleOrder != null && !commonSaleOrder.equals(invoiceTemp.getSaleOrder())) {
                commonSaleOrder = null;
            }
            if (commonProject != null && !commonProject.equals(invoiceTemp.getProject())) {
                commonProject = null;
            }
            if (invoiceTemp.getSaleOrder() != null) {
                saleOrderIsNull = false;
            }
            if (invoiceTemp.getProject() != null) {
                projectIsNull = false;
            }
        }
        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 (commonSaleOrder == null && saleOrderIsNull == false) {
        if (fieldErrors.length() > 0) {
            fieldErrors.append("<br/>");
        }
        fieldErrors.append(I18n.get(IExceptionMessage.INVOICE_MERGE_ERROR_SALEORDER));
    }
    if (commonProject == null && projectIsNull == false) {
        if (fieldErrors.length() > 0) {
            fieldErrors.append("<br/>");
        }
        fieldErrors.append(I18n.get(IExceptionMessage.INVOICE_MERGE_ERROR_PROJECT));
    }
    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(SaleOrderInvoiceProjectServiceImpl.class).mergeInvoice(invoiceList, commonCompany, commonCurrency, commonPartner, commonContactPartner, commonPriceList, commonPaymentMode, commonPaymentCondition, commonSaleOrder, commonProject);
        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) SaleOrderInvoiceProjectServiceImpl(com.axelor.apps.businessproject.service.SaleOrderInvoiceProjectServiceImpl) Currency(com.axelor.apps.base.db.Currency) ArrayList(java.util.ArrayList) List(java.util.List) PriceList(com.axelor.apps.base.db.PriceList) Partner(com.axelor.apps.base.db.Partner) PriceList(com.axelor.apps.base.db.PriceList) SaleOrder(com.axelor.apps.sale.db.SaleOrder) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) AxelorException(com.axelor.exception.AxelorException) InvoiceServiceProject(com.axelor.apps.businessproject.service.InvoiceServiceProject) Project(com.axelor.apps.project.db.Project) Map(java.util.Map) Wizard(com.axelor.apps.base.db.Wizard) 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