Search in sources :

Example 1 with PayVoucherElementToPay

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

the class PaymentVoucherCreateService method createPaymentVoucherIPO.

@Transactional(rollbackOn = { Exception.class })
public PaymentVoucher createPaymentVoucherIPO(Invoice invoice, LocalDate date, BigDecimal amount, PaymentMode paymentMode) throws AxelorException {
    MoveLine customerMoveLine = moveToolService.getCustomerMoveLineByQuery(invoice);
    log.debug("Création d'une saisie paiement par TIP ou TIP chèque - facture : {}", invoice.getInvoiceId());
    log.debug("Création d'une saisie paiement par TIP ou TIP chèque - mode de paiement : {}", paymentMode.getCode());
    log.debug("Création d'une saisie paiement par TIP ou TIP chèque - société : {}", invoice.getCompany().getName());
    log.debug("Création d'une saisie paiement par TIP ou TIP chèque - tiers payeur : {}", invoice.getPartner().getName());
    PaymentVoucher paymentVoucher = this.createPaymentVoucher(invoice.getCompany(), null, paymentMode, date, invoice.getPartner(), amount, null, invoice, null, null, null);
    paymentVoucher.setHasAutoInput(true);
    List<PayVoucherElementToPay> lines = new ArrayList<PayVoucherElementToPay>();
    lines.add(payVoucherElementToPayService.createPayVoucherElementToPay(paymentVoucher, 1, invoice, customerMoveLine, customerMoveLine.getDebit(), customerMoveLine.getAmountRemaining(), amount));
    paymentVoucher.setPayVoucherElementToPayList(lines);
    paymentVoucherRepository.save(paymentVoucher);
    paymentVoucherConfirmService.confirmPaymentVoucher(paymentVoucher);
    return paymentVoucher;
}
Also used : PayVoucherElementToPay(com.axelor.apps.account.db.PayVoucherElementToPay) MoveLine(com.axelor.apps.account.db.MoveLine) ArrayList(java.util.ArrayList) PaymentVoucher(com.axelor.apps.account.db.PaymentVoucher) Transactional(com.google.inject.persist.Transactional)

Example 2 with PayVoucherElementToPay

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

the class PaymentVoucherLoadService method completeElementToPay.

/**
 * Allows to load selected lines (from 1st 02M) to the 2nd O2M and dispatching amounts according
 * to amountRemainnig for the loaded move and the paid amount remaining of the paymentVoucher
 *
 * @param paymentVoucher
 * @param paymentVoucherContext
 * @return
 * @return
 * @return values Map of data
 * @throws AxelorException
 */
public void completeElementToPay(PaymentVoucher paymentVoucher) throws AxelorException {
    int sequence = paymentVoucher.getPayVoucherElementToPayList().size() + 1;
    List<PayVoucherDueElement> toRemove = new ArrayList<>();
    for (PayVoucherDueElement payVoucherDueElement : paymentVoucher.getPayVoucherDueElementList()) {
        if (payVoucherDueElement.isSelected()) {
            PayVoucherElementToPay payVoucherElementToPay = this.createPayVoucherElementToPay(paymentVoucher, payVoucherDueElement, sequence++);
            paymentVoucher.addPayVoucherElementToPayListItem(payVoucherElementToPay);
            if (payVoucherElementToPay != null) {
                paymentVoucher.setRemainingAmount(paymentVoucher.getRemainingAmount().subtract(payVoucherElementToPay.getAmountToPay()));
            }
            // Remove the line from the due elements lists
            toRemove.add(payVoucherDueElement);
        }
    }
    for (PayVoucherDueElement payVoucherDueElement : toRemove) {
        paymentVoucher.removePayVoucherDueElementListItem(payVoucherDueElement);
    }
}
Also used : PayVoucherElementToPay(com.axelor.apps.account.db.PayVoucherElementToPay) ArrayList(java.util.ArrayList) PayVoucherDueElement(com.axelor.apps.account.db.PayVoucherDueElement)

Example 3 with PayVoucherElementToPay

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

the class PaymentVoucherConfirmService method deleteUnPaidLines.

public void deleteUnPaidLines(PaymentVoucher paymentVoucher) {
    if (paymentVoucher.getPayVoucherElementToPayList() == null) {
        return;
    }
    paymentVoucher.getPayVoucherDueElementList().clear();
    List<PayVoucherElementToPay> payVoucherElementToPayToRemove = new ArrayList<>();
    for (PayVoucherElementToPay payVoucherElementToPay : paymentVoucher.getPayVoucherElementToPayList()) {
        if (payVoucherElementToPay.getAmountToPay().compareTo(BigDecimal.ZERO) == 0 && payVoucherElementToPay.getMoveLineGenerated() == null) {
            payVoucherElementToPayToRemove.add(payVoucherElementToPay);
        }
    }
    paymentVoucher.getPayVoucherElementToPayList().removeAll(payVoucherElementToPayToRemove);
}
Also used : PayVoucherElementToPay(com.axelor.apps.account.db.PayVoucherElementToPay) ArrayList(java.util.ArrayList)

Example 4 with PayVoucherElementToPay

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

the class PaymentVoucherConfirmService method waitForDepositSlip.

private void waitForDepositSlip(PaymentVoucher paymentVoucher) {
    for (PayVoucherElementToPay payVoucherElementToPay : paymentVoucher.getPayVoucherElementToPayList()) {
        Invoice invoice = payVoucherElementToPay.getMoveLine().getMove().getInvoice();
        boolean hasPendingPayments = payVoucherElementToPay.getRemainingAmountAfterPayment().signum() <= 0;
        invoice.setHasPendingPayments(hasPendingPayments);
    }
    paymentVoucher.setStatusSelect(PaymentVoucherRepository.STATUS_WAITING_FOR_DEPOSIT_SLIP);
}
Also used : PayVoucherElementToPay(com.axelor.apps.account.db.PayVoucherElementToPay) Invoice(com.axelor.apps.account.db.Invoice)

Example 5 with PayVoucherElementToPay

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

the class PayVoucherElementToPayService method createPayVoucherElementToPay.

/**
 * Generic method for creating invoice to pay lines (2nd O2M in the view)
 *
 * @param pv
 * @param seq
 * @return
 */
public PayVoucherElementToPay createPayVoucherElementToPay(PaymentVoucher paymentVoucher, int seq, Invoice invoice, MoveLine moveLine, BigDecimal totalAmount, BigDecimal remainingAmount, BigDecimal amountToPay) {
    log.debug("In  createPayVoucherElementToPay....");
    if (paymentVoucher != null && moveLine != null) {
        PayVoucherElementToPay piToPay = new PayVoucherElementToPay();
        piToPay.setSequence(seq);
        piToPay.setMoveLine(moveLine);
        piToPay.setTotalAmount(totalAmount);
        piToPay.setRemainingAmount(remainingAmount);
        piToPay.setAmountToPay(amountToPay);
        piToPay.setPaymentVoucher(paymentVoucher);
        log.debug("End createPayVoucherElementToPay IF.");
        return piToPay;
    } else {
        log.debug("End createPayVoucherElementToPay ELSE.");
        return null;
    }
}
Also used : PayVoucherElementToPay(com.axelor.apps.account.db.PayVoucherElementToPay)

Aggregations

PayVoucherElementToPay (com.axelor.apps.account.db.PayVoucherElementToPay)9 ArrayList (java.util.ArrayList)4 MoveLine (com.axelor.apps.account.db.MoveLine)3 Transactional (com.google.inject.persist.Transactional)2 BigDecimal (java.math.BigDecimal)2 LocalDate (java.time.LocalDate)2 Account (com.axelor.apps.account.db.Account)1 Invoice (com.axelor.apps.account.db.Invoice)1 Journal (com.axelor.apps.account.db.Journal)1 Move (com.axelor.apps.account.db.Move)1 PayVoucherDueElement (com.axelor.apps.account.db.PayVoucherDueElement)1 PaymentMode (com.axelor.apps.account.db.PaymentMode)1 PaymentVoucher (com.axelor.apps.account.db.PaymentVoucher)1 Reconcile (com.axelor.apps.account.db.Reconcile)1 PayVoucherElementToPayRepository (com.axelor.apps.account.db.repo.PayVoucherElementToPayRepository)1 AccountCustomerService (com.axelor.apps.account.service.AccountCustomerService)1 PayVoucherElementToPayService (com.axelor.apps.account.service.payment.paymentvoucher.PayVoucherElementToPayService)1 BankDetails (com.axelor.apps.base.db.BankDetails)1 Company (com.axelor.apps.base.db.Company)1 Partner (com.axelor.apps.base.db.Partner)1