Search in sources :

Example 1 with PayVoucherDueElement

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

the class ImportPaymentVoucher method importPaymentVoucher.

@SuppressWarnings("rawtypes")
public Object importPaymentVoucher(Object bean, Map values) {
    assert bean instanceof PaymentVoucher;
    try {
        PaymentVoucher paymentVoucher = (PaymentVoucher) bean;
        Invoice invoiceToPay = getInvoice((String) values.get("orderImport"));
        MoveLine moveLineToPay = this.getMoveLineToPay(paymentVoucher, invoiceToPay);
        if (moveLineToPay != null) {
            PayVoucherDueElement payVoucherDueElement = paymentVoucherLoadService.createPayVoucherDueElement(moveLineToPay);
            paymentVoucher.addPayVoucherElementToPayListItem(paymentVoucherLoadService.createPayVoucherElementToPay(paymentVoucher, payVoucherDueElement, 1));
        }
        if (paymentVoucher.getStatusSelect() == PaymentVoucherRepository.STATUS_CONFIRMED) {
            paymentVoucherConfirmService.confirmPaymentVoucher(paymentVoucher);
        }
        return paymentVoucher;
    } catch (Exception e) {
        TraceBackService.trace(e);
    }
    return bean;
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) MoveLine(com.axelor.apps.account.db.MoveLine) PayVoucherDueElement(com.axelor.apps.account.db.PayVoucherDueElement) PaymentVoucher(com.axelor.apps.account.db.PaymentVoucher) AxelorException(com.axelor.exception.AxelorException)

Example 2 with PayVoucherDueElement

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

the class PaymentVoucherController method loadMoveLines.

// Loading move lines of the selected partner (1st O2M)
public void loadMoveLines(ActionRequest request, ActionResponse response) {
    PaymentVoucher paymentVoucher = request.getContext().asType(PaymentVoucher.class);
    try {
        List<PayVoucherDueElement> pvDueElementList = Beans.get(PaymentVoucherLoadService.class).searchDueElements(paymentVoucher);
        response.setValue("payVoucherDueElementList", pvDueElementList);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : PayVoucherDueElement(com.axelor.apps.account.db.PayVoucherDueElement) PaymentVoucherLoadService(com.axelor.apps.account.service.payment.paymentvoucher.PaymentVoucherLoadService) PaymentVoucher(com.axelor.apps.account.db.PaymentVoucher) AxelorException(com.axelor.exception.AxelorException)

Example 3 with PayVoucherDueElement

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

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

the class PaymentVoucherLoadService method initFromInvoice.

/**
 * Initialize a payment voucher from an invoice.
 *
 * @param paymentVoucher
 * @param invoice
 * @throws AxelorException
 */
public void initFromInvoice(PaymentVoucher paymentVoucher, Invoice invoice) throws AxelorException {
    paymentVoucher.setOperationTypeSelect(invoice.getOperationTypeSelect());
    paymentVoucher.setPartner(invoice.getPartner());
    paymentVoucher.setPaymentMode(invoice.getPaymentMode());
    paymentVoucher.setCurrency(invoice.getCurrency());
    paymentVoucher.clearPayVoucherDueElementList();
    paymentVoucher.clearPayVoucherElementToPayList();
    paymentVoucher.setCompany(invoice.getCompany());
    BankDetails companyBankDetails;
    if (invoice.getCompanyBankDetails() != null) {
        companyBankDetails = invoice.getCompanyBankDetails();
    } else {
        companyBankDetails = Beans.get(BankDetailsService.class).getDefaultCompanyBankDetails(invoice.getCompany(), invoice.getPaymentMode(), invoice.getPartner(), null);
    }
    paymentVoucher.setCompanyBankDetails(companyBankDetails);
    BigDecimal amount = BigDecimal.ZERO;
    List<MoveLine> moveLineList = getMoveLines(paymentVoucher);
    for (MoveLine moveLine : moveLineList) {
        PayVoucherDueElement payVoucherDueElement = createPayVoucherDueElement(moveLine);
        paymentVoucher.addPayVoucherDueElementListItem(payVoucherDueElement);
        if (invoice.equals(payVoucherDueElement.getMoveLine().getMove().getInvoice())) {
            amount = amount.add(payVoucherDueElement.getAmountRemaining());
        }
    }
    paymentVoucher.setPaidAmount(amount);
    paymentVoucher.clearPayVoucherDueElementList();
    for (MoveLine moveLine : moveLineList) {
        paymentVoucher.addPayVoucherDueElementListItem(createPayVoucherDueElement(moveLine));
    }
    if (paymentVoucher.getPayVoucherDueElementList() == null) {
        return;
    }
    int sequence = 0;
    for (Iterator<PayVoucherDueElement> it = paymentVoucher.getPayVoucherDueElementList().iterator(); it.hasNext(); ) {
        PayVoucherDueElement payVoucherDueElement = it.next();
        if (invoice.equals(payVoucherDueElement.getMoveLine().getMove().getInvoice()) && paymentVoucher.getCurrency().equals(payVoucherDueElement.getCurrency())) {
            paymentVoucher.addPayVoucherElementToPayListItem(createPayVoucherElementToPay(paymentVoucher, payVoucherDueElement, ++sequence));
            it.remove();
        }
    }
}
Also used : BankDetails(com.axelor.apps.base.db.BankDetails) MoveLine(com.axelor.apps.account.db.MoveLine) PayVoucherDueElement(com.axelor.apps.account.db.PayVoucherDueElement) BigDecimal(java.math.BigDecimal)

Example 5 with PayVoucherDueElement

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

the class PaymentVoucherLoadService method createPayVoucherDueElement.

public PayVoucherDueElement createPayVoucherDueElement(MoveLine moveLine) throws AxelorException {
    Move move = moveLine.getMove();
    PayVoucherDueElement payVoucherDueElement = new PayVoucherDueElement();
    payVoucherDueElement.setMoveLine(moveLine);
    payVoucherDueElement.setDueAmount(moveLine.getCurrencyAmount());
    BigDecimal paidAmountInElementCurrency = currencyService.getAmountCurrencyConvertedAtDate(move.getCompanyCurrency(), move.getCurrency(), moveLine.getAmountPaid(), moveLine.getDate()).setScale(2, RoundingMode.HALF_UP);
    payVoucherDueElement.setPaidAmount(paidAmountInElementCurrency);
    payVoucherDueElement.setAmountRemaining(payVoucherDueElement.getDueAmount().subtract(payVoucherDueElement.getPaidAmount()));
    payVoucherDueElement.setCurrency(move.getCurrency());
    return payVoucherDueElement;
}
Also used : Move(com.axelor.apps.account.db.Move) PayVoucherDueElement(com.axelor.apps.account.db.PayVoucherDueElement) BigDecimal(java.math.BigDecimal)

Aggregations

PayVoucherDueElement (com.axelor.apps.account.db.PayVoucherDueElement)5 MoveLine (com.axelor.apps.account.db.MoveLine)2 PaymentVoucher (com.axelor.apps.account.db.PaymentVoucher)2 AxelorException (com.axelor.exception.AxelorException)2 BigDecimal (java.math.BigDecimal)2 Invoice (com.axelor.apps.account.db.Invoice)1 Move (com.axelor.apps.account.db.Move)1 PayVoucherElementToPay (com.axelor.apps.account.db.PayVoucherElementToPay)1 PaymentVoucherLoadService (com.axelor.apps.account.service.payment.paymentvoucher.PaymentVoucherLoadService)1 BankDetails (com.axelor.apps.base.db.BankDetails)1 ArrayList (java.util.ArrayList)1