use of com.axelor.apps.account.db.InvoicePayment in project axelor-open-suite by axelor.
the class BatchDirectDebitCustomerInvoice method processQuery.
private List<InvoicePayment> processQuery(List<String> filterList, List<Pair<String, Object>> bindingList) {
List<InvoicePayment> doneList = new ArrayList<>();
List<Long> anomalyList = Lists.newArrayList(0L);
filterList.add("self.id NOT IN (:anomalyList)");
bindingList.add(Pair.of("anomalyList", (Object) anomalyList));
String filter = Joiner.on(" AND ").join(Lists.transform(filterList, new Function<String, String>() {
@Override
public String apply(String input) {
return String.format("(%s)", input);
}
}));
Query<Invoice> query = Beans.get(InvoiceRepository.class).all().filter(filter);
for (Pair<String, Object> binding : bindingList) {
query.bind(binding.getLeft(), binding.getRight());
}
Set<Long> treatedSet = new HashSet<>();
List<Invoice> invoiceList;
InvoicePaymentCreateService invoicePaymentCreateService = Beans.get(InvoicePaymentCreateService.class);
BankDetailsRepository bankDetailsRepo = Beans.get(BankDetailsRepository.class);
BankDetails companyBankDetails = getCompanyBankDetails(batch.getAccountingBatch());
while (!(invoiceList = query.fetch(FETCH_LIMIT)).isEmpty()) {
if (!JPA.em().contains(companyBankDetails)) {
companyBankDetails = bankDetailsRepo.find(companyBankDetails.getId());
}
for (Invoice invoice : invoiceList) {
if (treatedSet.contains(invoice.getId())) {
throw new IllegalArgumentException("Invoice payment generation error");
}
treatedSet.add(invoice.getId());
try {
doneList.add(invoicePaymentCreateService.createInvoicePayment(invoice, companyBankDetails));
incrementDone();
} catch (Exception e) {
incrementAnomaly();
anomalyList.add(invoice.getId());
query.bind("anomalyList", anomalyList);
TraceBackService.trace(e, ExceptionOriginRepository.DIRECT_DEBIT, batch.getId());
LOG.error(e.getMessage());
break;
}
}
JPA.clear();
}
return doneList;
}
use of com.axelor.apps.account.db.InvoicePayment in project axelor-open-suite by axelor.
the class InvoicePaymentBankPayController method validateMassPayment.
@Override
public void validateMassPayment(ActionRequest request, ActionResponse response) {
try {
InvoicePayment invoicePayment = request.getContext().asType(InvoicePayment.class);
if (!ObjectUtils.isEmpty(request.getContext().get("_selectedInvoices"))) {
List<Long> invoiceIdList = Lists.transform((List) request.getContext().get("_selectedInvoices"), new Function<Object, Long>() {
@Nullable
@Override
public Long apply(@Nullable Object input) {
return Long.parseLong(input.toString());
}
});
List<InvoicePayment> invoicePaymentList = Beans.get(InvoicePaymentCreateService.class).createMassInvoicePayment(invoiceIdList, invoicePayment.getPaymentMode(), invoicePayment.getCompanyBankDetails(), invoicePayment.getPaymentDate(), invoicePayment.getBankDepositDate(), invoicePayment.getChequeNumber());
if (!invoicePaymentList.isEmpty() && invoicePaymentList.get(0).getBankOrder() != null) {
response.setView(ActionView.define(I18n.get("Bank order")).model(BankOrder.class.getName()).add("form", "bank-order-form").add("grid", "bank-order-grid").param("search-filters", "bank-order-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(invoicePaymentList.get(0).getBankOrder().getId())).map());
}
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.account.db.InvoicePayment in project axelor-open-suite by axelor.
the class BatchCreditTransferInvoice method processInvoices.
/**
* Process invoices of the specified document type.
*
* @param operationTypeSelect
* @return
*/
protected List<InvoicePayment> processInvoices(int operationTypeSelect) {
List<InvoicePayment> doneList = new ArrayList<>();
// Can't pass an empty collection to the query
List<Long> anomalyList = Lists.newArrayList(0L);
AccountingBatch accountingBatch = batch.getAccountingBatch();
boolean manageMultiBanks = appAccountService.getAppBase().getManageMultiBanks();
StringBuilder filter = new StringBuilder();
filter.append("self.operationTypeSelect = :operationTypeSelect " + "AND self.statusSelect = :statusSelect " + "AND self.amountRemaining > 0 " + "AND self.hasPendingPayments = FALSE " + "AND self.company = :company " + "AND self.dueDate <= :dueDate " + "AND self.paymentMode = :paymentMode " + "AND self.id NOT IN (:anomalyList)" + "AND self.pfpValidateStatusSelect != :pfpValidateStatusSelect");
if (manageMultiBanks) {
filter.append(" AND self.companyBankDetails IN (:bankDetailsSet)");
}
if (accountingBatch.getCurrency() != null) {
filter.append(" AND self.currency = :currency");
}
Query<Invoice> query = invoiceRepo.all().filter(filter.toString()).bind("operationTypeSelect", operationTypeSelect).bind("statusSelect", InvoiceRepository.STATUS_VENTILATED).bind("company", accountingBatch.getCompany()).bind("dueDate", accountingBatch.getDueDate()).bind("paymentMode", accountingBatch.getPaymentMode()).bind("anomalyList", anomalyList).bind("pfpValidateStatusSelect", InvoiceRepository.PFP_STATUS_LITIGATION);
if (manageMultiBanks) {
Set<BankDetails> bankDetailsSet = Sets.newHashSet(accountingBatch.getBankDetails());
if (accountingBatch.getIncludeOtherBankAccounts()) {
bankDetailsSet.addAll(accountingBatch.getCompany().getBankDetailsList());
}
query.bind("bankDetailsSet", bankDetailsSet);
}
if (accountingBatch.getCurrency() != null) {
query.bind("currency", accountingBatch.getCurrency());
}
BankDetailsRepository bankDetailsRepo = Beans.get(BankDetailsRepository.class);
BankDetails companyBankDetails = accountingBatch.getBankDetails();
for (List<Invoice> invoiceList; !(invoiceList = query.fetch(FETCH_LIMIT)).isEmpty(); JPA.clear()) {
if (!JPA.em().contains(companyBankDetails)) {
companyBankDetails = bankDetailsRepo.find(companyBankDetails.getId());
}
for (Invoice invoice : invoiceList) {
try {
doneList.add(invoicePaymentCreateService.createInvoicePayment(invoice, companyBankDetails));
incrementDone();
} catch (Exception ex) {
incrementAnomaly();
anomalyList.add(invoice.getId());
query.bind("anomalyList", anomalyList);
TraceBackService.trace(ex, ExceptionOriginRepository.CREDIT_TRANSFER, batch.getId());
ex.printStackTrace();
log.error(String.format("Credit transfer batch for invoices: anomaly for invoice %s", invoice.getInvoiceId()));
break;
}
}
}
return doneList;
}
use of com.axelor.apps.account.db.InvoicePayment in project axelor-open-suite by axelor.
the class InvoiceServiceImpl method getMoveLinesFromInvoiceAdvancePayments.
@Override
public List<MoveLine> getMoveLinesFromInvoiceAdvancePayments(Invoice invoice) {
List<MoveLine> advancePaymentMoveLines = new ArrayList<>();
Set<Invoice> advancePayments = invoice.getAdvancePaymentInvoiceSet();
List<InvoicePayment> invoicePayments;
if (advancePayments == null || advancePayments.isEmpty()) {
return advancePaymentMoveLines;
}
InvoicePaymentToolService invoicePaymentToolService = Beans.get(InvoicePaymentToolService.class);
for (Invoice advancePayment : advancePayments) {
invoicePayments = advancePayment.getInvoicePaymentList();
List<MoveLine> creditMoveLines = invoicePaymentToolService.getCreditMoveLinesFromPayments(invoicePayments);
advancePaymentMoveLines.addAll(creditMoveLines);
}
return advancePaymentMoveLines;
}
use of com.axelor.apps.account.db.InvoicePayment in project axelor-open-suite by axelor.
the class InvoiceServiceImpl method removeBecauseOfTotalAmount.
protected boolean removeBecauseOfTotalAmount(Invoice invoice, Invoice candidateAdvancePayment) throws AxelorException {
if (accountConfigService.getAccountConfig(invoice.getCompany()).getGenerateMoveForInvoicePayment()) {
return false;
}
BigDecimal invoiceTotal = invoice.getInTaxTotal();
List<InvoicePayment> invoicePayments = candidateAdvancePayment.getInvoicePaymentList();
if (invoicePayments == null) {
return false;
}
BigDecimal totalAmount = invoicePayments.stream().map(InvoicePayment::getAmount).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
return totalAmount.compareTo(invoiceTotal) > 0;
}
Aggregations