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