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;
}
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);
}
}
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);
}
}
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();
}
}
}
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;
}
Aggregations