use of com.axelor.apps.account.service.payment.invoice.payment.InvoicePaymentCreateService 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;
}
Aggregations