Search in sources :

Example 11 with BankDetails

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

the class InvoiceController method fillCompanyBankDetails.

/**
 * Called on load and in partner, company or payment mode change. Fill the bank details with a
 * default value.
 *
 * @param request
 * @param response
 * @throws AxelorException
 */
public void fillCompanyBankDetails(ActionRequest request, ActionResponse response) throws AxelorException {
    Invoice invoice = request.getContext().asType(Invoice.class);
    PaymentMode paymentMode = invoice.getPaymentMode();
    Company company = invoice.getCompany();
    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, invoice.getOperationTypeSelect());
    response.setValue("companyBankDetails", defaultBankDetails);
}
Also used : BankDetailsService(com.axelor.apps.base.service.BankDetailsService) Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) BankDetails(com.axelor.apps.base.db.BankDetails) Partner(com.axelor.apps.base.db.Partner) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 12 with BankDetails

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

the class InvoicePaymentController method filterBankDetails.

/**
 * Create the domain for companyBankDetails field.
 *
 * @param request
 * @param response
 */
@SuppressWarnings("unchecked")
public void filterBankDetails(ActionRequest request, ActionResponse response) {
    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());
    Company company = invoice.getCompany();
    List<BankDetails> bankDetailsList = Beans.get(InvoicePaymentToolService.class).findCompatibleBankDetails(company, invoicePayment);
    if (bankDetailsList.isEmpty()) {
        response.setAttr("companyBankDetails", "domain", "self.id IN (0)");
    } else {
        String idList = StringTool.getIdListString(bankDetailsList);
        response.setAttr("companyBankDetails", "domain", "self.id IN (" + idList + ")");
    }
}
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) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) InvoicePaymentToolService(com.axelor.apps.account.service.payment.invoice.payment.InvoicePaymentToolService) Map(java.util.Map)

Example 13 with BankDetails

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

the class PaymentVoucherController method fillCompanyBankDetails.

/**
 * Called on load and in partner, company or payment mode change. Fill the bank details with a
 * default value.
 *
 * @param request
 * @param response
 * @throws AxelorException
 */
public void fillCompanyBankDetails(ActionRequest request, ActionResponse response) throws AxelorException {
    PaymentVoucher paymentVoucher = request.getContext().asType(PaymentVoucher.class);
    PaymentMode paymentMode = paymentVoucher.getPaymentMode();
    Company company = paymentVoucher.getCompany();
    Partner partner = paymentVoucher.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("companyBankDetails", defaultBankDetails);
}
Also used : BankDetailsService(com.axelor.apps.base.service.BankDetailsService) Company(com.axelor.apps.base.db.Company) BankDetails(com.axelor.apps.base.db.BankDetails) Partner(com.axelor.apps.base.db.Partner) PaymentVoucher(com.axelor.apps.account.db.PaymentVoucher) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 14 with BankDetails

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

the class PaymentVoucherController method askPaymentVoucher.

public void askPaymentVoucher(ActionRequest request, ActionResponse response) {
    PaymentVoucher paymentVoucher = request.getContext().asType(PaymentVoucher.class);
    if (paymentVoucher.getHasAutoInput()) {
        PaymentMode paymentMode = paymentVoucher.getPaymentMode();
        Company company = paymentVoucher.getCompany();
        BankDetails companyBankDetails = paymentVoucher.getCompanyBankDetails();
        try {
            Journal journal = Beans.get(PaymentModeService.class).getPaymentModeJournal(paymentMode, company, companyBankDetails);
            if (journal.getExcessPaymentOk()) {
                response.setAlert(I18n.get("No items have been selected. Do you want to continue?"));
            }
        } catch (Exception e) {
            TraceBackService.trace(response, e);
        }
    }
}
Also used : Company(com.axelor.apps.base.db.Company) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) BankDetails(com.axelor.apps.base.db.BankDetails) Journal(com.axelor.apps.account.db.Journal) PaymentVoucher(com.axelor.apps.account.db.PaymentVoucher) AxelorException(com.axelor.exception.AxelorException) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 15 with BankDetails

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

the class BatchCreditTransferExpensePaymentHR method processExpenses.

/**
 * Process expenses that need to be paid.
 *
 * @return
 */
protected List<Expense> processExpenses() {
    List<Expense> doneList = new ArrayList<>();
    // Can't pass an empty collection to the query
    List<Long> anomalyList = Lists.newArrayList(0L);
    AccountingBatch accountingBatch = batch.getAccountingBatch();
    boolean manageMultiBanks = appAccountService.getAppBase().getManageMultiBanks();
    String filter = "self.ventilated = true " + "AND self.paymentStatusSelect = :paymentStatusSelect " + "AND self.company = :company " + "AND self.user.partner.outPaymentMode = :paymentMode " + "AND self.id NOT IN (:anomalyList)";
    if (manageMultiBanks) {
        filter += " AND self.bankDetails IN (:bankDetailsSet)";
    }
    Query<Expense> query = expenseRepo.all().filter(filter).bind("paymentStatusSelect", InvoicePaymentRepository.STATUS_DRAFT).bind("company", accountingBatch.getCompany()).bind("paymentMode", accountingBatch.getPaymentMode()).bind("anomalyList", anomalyList);
    if (manageMultiBanks) {
        Set<BankDetails> bankDetailsSet = Sets.newHashSet(accountingBatch.getBankDetails());
        if (accountingBatch.getIncludeOtherBankAccounts()) {
            bankDetailsSet.addAll(accountingBatch.getCompany().getBankDetailsList());
        }
        query.bind("bankDetailsSet", bankDetailsSet);
    }
    for (List<Expense> expenseList; !(expenseList = query.fetch(FETCH_LIMIT)).isEmpty(); JPA.clear()) {
        for (Expense expense : expenseList) {
            try {
                addPayment(expense, accountingBatch.getBankDetails());
                doneList.add(expense);
                incrementDone();
            } catch (Exception ex) {
                incrementAnomaly();
                anomalyList.add(expense.getId());
                query.bind("anomalyList", anomalyList);
                TraceBackService.trace(ex, ExceptionOriginRepository.CREDIT_TRANSFER, batch.getId());
                ex.printStackTrace();
                log.error(String.format("Credit transfer batch for expense payment: anomaly for expense %s", expense.getExpenseSeq()));
                break;
            }
        }
    }
    return doneList;
}
Also used : Expense(com.axelor.apps.hr.db.Expense) BankDetails(com.axelor.apps.base.db.BankDetails) ArrayList(java.util.ArrayList) AccountingBatch(com.axelor.apps.account.db.AccountingBatch) AxelorException(com.axelor.exception.AxelorException)

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