Search in sources :

Example 1 with InvoicePayment

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

the class ReconcileServiceImpl method updateInvoicePayments.

public void updateInvoicePayments(Reconcile reconcile) throws AxelorException {
    MoveLine debitMoveLine = reconcile.getDebitMoveLine();
    MoveLine creditMoveLine = reconcile.getCreditMoveLine();
    Move debitMove = debitMoveLine.getMove();
    Move creditMove = creditMoveLine.getMove();
    Invoice debitInvoice = debitMove.getInvoice();
    Invoice creditInvoice = creditMove.getInvoice();
    BigDecimal amount = reconcile.getAmount();
    if (debitInvoice != null && debitMoveLine.getAccount().getUseForPartnerBalance() && creditMoveLine.getAccount().getUseForPartnerBalance()) {
        InvoicePayment debitInvoicePayment = invoicePaymentCreateService.createInvoicePayment(debitInvoice, amount, creditMove);
        debitInvoicePayment.setReconcile(reconcile);
    }
    if (creditInvoice != null && debitMoveLine.getAccount().getUseForPartnerBalance() && creditMoveLine.getAccount().getUseForPartnerBalance()) {
        InvoicePayment creditInvoicePayment = invoicePaymentCreateService.createInvoicePayment(creditInvoice, amount, debitMove);
        creditInvoicePayment.setReconcile(reconcile);
    }
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) Invoice(com.axelor.apps.account.db.Invoice) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) BigDecimal(java.math.BigDecimal)

Example 2 with InvoicePayment

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

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

the class InvoicePaymentController method cancelInvoicePayment.

public void cancelInvoicePayment(ActionRequest request, ActionResponse response) {
    InvoicePayment invoicePayment = request.getContext().asType(InvoicePayment.class);
    invoicePayment = Beans.get(InvoicePaymentRepository.class).find(invoicePayment.getId());
    try {
        Move move = invoicePayment.getMove();
        Beans.get(InvoicePaymentCancelService.class).cancel(invoicePayment);
        if (ObjectUtils.notEmpty(move)) {
            Beans.get(MoveCustAccountService.class).updateCustomerAccount(move);
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
    response.setReload(true);
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) Move(com.axelor.apps.account.db.Move) InvoicePaymentCancelService(com.axelor.apps.account.service.payment.invoice.payment.InvoicePaymentCancelService) MoveCustAccountService(com.axelor.apps.account.service.move.MoveCustAccountService) AxelorException(com.axelor.exception.AxelorException)

Example 4 with InvoicePayment

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

the class AccountingSituationSupplychainServiceImpl method computeUsedCredit.

@Override
public AccountingSituation computeUsedCredit(AccountingSituation accountingSituation) throws AxelorException {
    BigDecimal sum = BigDecimal.ZERO;
    List<SaleOrder> saleOrderList = saleOrderRepository.all().filter("self.company = ?1 AND self.clientPartner = ?2 AND self.statusSelect > ?3 AND self.statusSelect < ?4", accountingSituation.getCompany(), accountingSituation.getPartner(), SaleOrderRepository.STATUS_DRAFT_QUOTATION, SaleOrderRepository.STATUS_CANCELED).fetch();
    for (SaleOrder saleOrder : saleOrderList) {
        sum = sum.add(saleOrder.getInTaxTotal().subtract(getInTaxInvoicedAmount(saleOrder)));
    }
    // invoice payments
    if (!accountConfigService.getAccountConfig(accountingSituation.getCompany()).getGenerateMoveForInvoicePayment()) {
        List<InvoicePayment> invoicePaymentList = invoicePaymentRepository.all().filter("self.invoice.company = :company" + " AND self.invoice.partner = :partner" + " AND self.statusSelect = :validated" + " AND self.typeSelect != :imputation").bind("company", accountingSituation.getCompany()).bind("partner", accountingSituation.getPartner()).bind("validated", InvoicePaymentRepository.STATUS_VALIDATED).bind("imputation", InvoicePaymentRepository.TYPE_ADV_PAYMENT_IMPUTATION).fetch();
        if (invoicePaymentList != null) {
            for (InvoicePayment invoicePayment : invoicePaymentList) {
                sum = sum.subtract(invoicePayment.getAmount());
            }
        }
    }
    sum = accountingSituation.getBalanceCustAccount().add(sum);
    accountingSituation.setUsedCredit(sum.setScale(2, RoundingMode.HALF_UP));
    return accountingSituation;
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) SaleOrder(com.axelor.apps.sale.db.SaleOrder) BigDecimal(java.math.BigDecimal)

Example 5 with InvoicePayment

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

the class WorkflowVentilationServiceImpl method copyAdvancePaymentToInvoice.

/**
 * Copy payments from selected advance payment invoices to this invoice.
 *
 * @param invoice
 */
protected void copyAdvancePaymentToInvoice(Invoice invoice) throws AxelorException {
    Set<Invoice> advancePaymentInvoiceSet = invoice.getAdvancePaymentInvoiceSet();
    if (advancePaymentInvoiceSet == null) {
        return;
    }
    for (Invoice advancePaymentInvoice : advancePaymentInvoiceSet) {
        List<InvoicePayment> advancePayments = advancePaymentInvoice.getInvoicePaymentList();
        if (advancePayments == null) {
            continue;
        }
        for (InvoicePayment advancePayment : advancePayments) {
            InvoicePayment imputationPayment = invoicePaymentCreateService.createInvoicePayment(invoice, advancePayment.getAmount(), advancePayment.getPaymentDate(), advancePayment.getCurrency(), advancePayment.getPaymentMode(), InvoicePaymentRepository.TYPE_ADV_PAYMENT_IMPUTATION);
            advancePayment.setImputedBy(imputationPayment);
            imputationPayment.setCompanyBankDetails(advancePayment.getCompanyBankDetails());
            invoice.addInvoicePaymentListItem(imputationPayment);
            invoicePaymentRepo.save(imputationPayment);
        }
    }
    // if the sum of amounts in advance payment is greater than the amount
    // of the invoice, then we cancel the ventilation.
    List<InvoicePayment> invoicePayments = invoice.getInvoicePaymentList();
    if (invoicePayments == null || invoicePayments.isEmpty()) {
        return;
    }
    BigDecimal totalPayments = invoicePayments.stream().map(InvoicePayment::getAmount).reduce(BigDecimal::add).get();
    if (totalPayments.compareTo(invoice.getInTaxTotal()) > 0) {
        throw new AxelorException(invoice, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.AMOUNT_ADVANCE_PAYMENTS_TOO_HIGH));
    }
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) AxelorException(com.axelor.exception.AxelorException) Invoice(com.axelor.apps.account.db.Invoice) BigDecimal(java.math.BigDecimal)

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