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