Search in sources :

Example 16 with InvoicePayment

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

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

the class InvoicePaymentCreateServiceImpl method createMassInvoicePayment.

@Override
@Transactional(rollbackOn = { Exception.class })
public List<InvoicePayment> createMassInvoicePayment(List<Long> invoiceList, PaymentMode paymentMode, BankDetails companyBankDetails, LocalDate paymentDate, LocalDate bankDepositDate, String chequeNumber) throws AxelorException {
    List<InvoicePayment> invoicePaymentList = new ArrayList<>();
    InvoiceRepository invoiceRepository = Beans.get(InvoiceRepository.class);
    for (Long invoiceId : invoiceList) {
        Invoice invoice = invoiceRepository.find(invoiceId);
        InvoicePayment invoicePayment = this.createInvoicePayment(invoice, paymentMode, companyBankDetails, paymentDate, bankDepositDate, chequeNumber);
        invoicePaymentList.add(invoicePayment);
        invoice.addInvoicePaymentListItem(invoicePayment);
        invoicePaymentToolService.updateAmountPaid(invoice);
    }
    return invoicePaymentList;
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) Invoice(com.axelor.apps.account.db.Invoice) ArrayList(java.util.ArrayList) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Transactional(com.google.inject.persist.Transactional)

Example 18 with InvoicePayment

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

the class InvoicePaymentCreateServiceImpl method createInvoicePayment.

@Override
@Transactional
public InvoicePayment createInvoicePayment(Invoice invoice, BankDetails companyBankDetails) {
    InvoicePayment invoicePayment = createInvoicePayment(invoice, invoice.getInTaxTotal().subtract(invoice.getAmountPaid()), appBaseService.getTodayDate(invoice.getCompany()), invoice.getCurrency(), invoice.getPaymentMode(), InvoicePaymentRepository.TYPE_PAYMENT);
    invoicePayment.setCompanyBankDetails(companyBankDetails);
    return invoicePaymentRepository.save(invoicePayment);
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) Transactional(com.google.inject.persist.Transactional)

Example 19 with InvoicePayment

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

the class InvoicePaymentToolServiceImpl method computeAmountPaid.

protected BigDecimal computeAmountPaid(Invoice invoice) throws AxelorException {
    BigDecimal amountPaid = BigDecimal.ZERO;
    if (invoice.getInvoicePaymentList() == null) {
        return amountPaid;
    }
    CurrencyService currencyService = Beans.get(CurrencyService.class);
    Currency invoiceCurrency = invoice.getCurrency();
    for (InvoicePayment invoicePayment : invoice.getInvoicePaymentList()) {
        if (invoicePayment.getStatusSelect() == InvoicePaymentRepository.STATUS_VALIDATED) {
            log.debug("Amount paid without move : {}", invoicePayment.getAmount());
            amountPaid = amountPaid.add(currencyService.getAmountCurrencyConvertedAtDate(invoicePayment.getCurrency(), invoiceCurrency, invoicePayment.getAmount(), invoicePayment.getPaymentDate()));
        }
    }
    boolean isMinus = moveToolService.isMinus(invoice);
    if (isMinus) {
        amountPaid = amountPaid.negate();
    }
    log.debug("Amount paid total : {}", amountPaid);
    return amountPaid;
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) Currency(com.axelor.apps.base.db.Currency) CurrencyService(com.axelor.apps.base.service.CurrencyService) BigDecimal(java.math.BigDecimal)

Example 20 with InvoicePayment

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

the class AdvancePaymentServiceSupplychainImpl method createInvoicePayment.

@Transactional(rollbackOn = { Exception.class })
public InvoicePayment createInvoicePayment(AdvancePayment advancePayment, Invoice invoice, BigDecimal amount) throws AxelorException {
    log.debug("Creating InvoicePayment from SaleOrder AdvancePayment");
    InvoicePayment invoicePayment = new InvoicePayment();
    invoicePayment.setAmount(amount);
    invoicePayment.setPaymentDate(advancePayment.getAdvancePaymentDate());
    invoicePayment.setCurrency(advancePayment.getCurrency());
    invoicePayment.setInvoice(invoice);
    invoicePayment.setPaymentMode(advancePayment.getPaymentMode());
    invoicePayment.setTypeSelect(InvoicePaymentRepository.TYPE_ADVANCEPAYMENT);
    invoicePayment.setMove(advancePayment.getMove());
    invoicePaymentRepository.save(invoicePayment);
    invoice.addInvoicePaymentListItem(invoicePayment);
    return invoicePayment;
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) Transactional(com.google.inject.persist.Transactional)

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