use of com.axelor.apps.base.db.repo.BankDetailsRepository 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.base.db.repo.BankDetailsRepository in project axelor-open-suite by axelor.
the class BatchDirectDebitPaymentSchedule method processQuery.
private void processQuery(QueryBuilder<PaymentScheduleLine> queryBuilder) {
Query<PaymentScheduleLine> query = queryBuilder.build();
List<PaymentScheduleLine> paymentScheduleLineList;
PaymentScheduleService paymentScheduleService = Beans.get(PaymentScheduleService.class);
PaymentScheduleLineService paymentScheduleLineService = Beans.get(PaymentScheduleLineService.class);
BankDetailsRepository bankDetailsRepo = Beans.get(BankDetailsRepository.class);
BankDetails companyBankDetails = getCompanyBankDetails(batch.getAccountingBatch());
while (!(paymentScheduleLineList = query.fetch(FETCH_LIMIT)).isEmpty()) {
findBatch();
companyBankDetails = bankDetailsRepo.find(companyBankDetails.getId());
PaymentMode directDebitPaymentMode = batch.getAccountingBatch().getPaymentMode();
for (PaymentScheduleLine paymentScheduleLine : paymentScheduleLineList) {
try {
if (generateBankOrderFlag) {
PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
BankDetails bankDetails = paymentScheduleService.getBankDetails(paymentSchedule);
Preconditions.checkArgument(bankDetails.getActive(), bankDetails.getPartner() != null ? bankDetails.getPartner().getFullName() + " - " + I18n.get("Bank details are inactive.") : I18n.get("Bank details are inactive."));
if (directDebitPaymentMode.getOrderTypeSelect() == PaymentModeRepository.ORDER_TYPE_SEPA_DIRECT_DEBIT) {
Partner partner = paymentSchedule.getPartner();
Preconditions.checkNotNull(partner, I18n.get("Partner is missing."));
Preconditions.checkNotNull(partner.getActiveUmr(), I18n.get("Partner active UMR is missing."));
}
}
paymentScheduleLineService.createPaymentMove(paymentScheduleLine, companyBankDetails, directDebitPaymentMode);
incrementDone(paymentScheduleLine);
} catch (Exception e) {
TraceBackService.trace(e, ExceptionOriginRepository.DIRECT_DEBIT, batch.getId());
incrementAnomaly(paymentScheduleLine);
break;
}
}
JPA.clear();
}
}
use of com.axelor.apps.base.db.repo.BankDetailsRepository 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;
}
Aggregations