use of com.axelor.apps.account.db.InvoicePayment in project axelor-open-suite by axelor.
the class BankOrderMergeServiceImpl method mergeBankOrders.
@Transactional(rollbackOn = { Exception.class })
public BankOrder mergeBankOrders(Collection<BankOrder> bankOrders) throws AxelorException {
if (bankOrders == null || bankOrders.size() <= 1) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, IExceptionMessage.BANK_ORDER_MERGE_AT_LEAST_TWO_BANK_ORDERS);
}
this.checkSameElements(bankOrders);
BankOrder bankOrder = bankOrders.iterator().next();
bankOrders.remove(bankOrder);
bankOrder.setSenderLabel(null);
bankOrder.setSenderReference(null);
bankOrder.setBankOrderDate(Beans.get(AppBaseService.class).getTodayDate(bankOrder.getSenderCompany()));
bankOrder.setSignatoryUser(null);
bankOrder.setSignatoryEbicsUser(null);
PaymentMode paymentMode = bankOrder.getPaymentMode();
for (BankOrderLine bankOrderLine : this.getAllBankOrderLineList(bankOrders)) {
bankOrder.addBankOrderLineListItem(bankOrderLine);
}
bankOrderRepo.save(bankOrder);
for (BankOrder bankOrderToRemove : bankOrders) {
bankOrderToRemove = bankOrderRepo.find(bankOrderToRemove.getId());
List<InvoicePayment> invoicePaymentList = invoicePaymentRepo.findByBankOrder(bankOrderToRemove).fetch();
for (InvoicePayment invoicePayment : invoicePaymentList) {
invoicePayment.setBankOrder(bankOrder);
}
bankOrderRepo.remove(bankOrderToRemove);
}
if (paymentMode.getConsoBankOrderLinePerPartner()) {
consolidatePerPartner(bankOrder);
}
bankOrderService.updateTotalAmounts(bankOrder);
return bankOrderRepo.save(bankOrder);
}
use of com.axelor.apps.account.db.InvoicePayment in project axelor-open-suite by axelor.
the class BatchDirectDebitCustomerInvoice method process.
@Override
protected void process() {
AccountingBatch accountingBatch = batch.getAccountingBatch();
List<String> filterList = new ArrayList<>();
List<Pair<String, Object>> bindingList = new ArrayList<>();
filterList.add("self.operationTypeSelect = :operationTypeSelect");
bindingList.add(Pair.of("operationTypeSelect", (Object) InvoiceRepository.OPERATION_TYPE_CLIENT_SALE));
filterList.add("self.statusSelect = :statusSelect");
bindingList.add(Pair.of("statusSelect", (Object) InvoiceRepository.STATUS_VENTILATED));
filterList.add("self.amountRemaining > 0");
filterList.add("self.hasPendingPayments = FALSE");
LocalDate dueDate = accountingBatch.getDueDate() != null ? accountingBatch.getDueDate() : Beans.get(AppBaseService.class).getTodayDate(accountingBatch.getCompany());
filterList.add("self.dueDate <= :dueDate");
bindingList.add(Pair.of("dueDate", (Object) dueDate));
if (accountingBatch.getCompany() != null) {
filterList.add("self.company = :company");
bindingList.add(Pair.of("company", (Object) accountingBatch.getCompany()));
}
filterList.add("self.partner.id NOT IN (SELECT DISTINCT partner.id FROM Partner partner LEFT JOIN partner.blockingList blocking WHERE blocking.blockingSelect = :blockingSelect AND blocking.blockingToDate >= :blockingToDate)");
bindingList.add(Pair.of("blockingSelect", BlockingRepository.DEBIT_BLOCKING));
bindingList.add(Pair.of("blockingToDate", Beans.get(AppBaseService.class).getTodayDate(accountingBatch.getCompany())));
if (accountingBatch.getBankDetails() != null) {
Set<BankDetails> bankDetailsSet = Sets.newHashSet(accountingBatch.getBankDetails());
if (accountingBatch.getIncludeOtherBankAccounts() && appBaseService.getAppBase().getManageMultiBanks()) {
bankDetailsSet.addAll(accountingBatch.getCompany().getBankDetailsList());
}
filterList.add("self.companyBankDetails IN (:bankDetailsSet)");
bindingList.add(Pair.of("bankDetailsSet", (Object) bankDetailsSet));
}
if (accountingBatch.getPaymentMode() != null) {
filterList.add("self.paymentMode = :paymentMode");
bindingList.add(Pair.of("paymentMode", (Object) accountingBatch.getPaymentMode()));
}
List<InvoicePayment> invoicePaymentList = processQuery(filterList, bindingList);
if (!invoicePaymentList.isEmpty()) {
try {
final BankOrder bankOrder = Beans.get(BankOrderMergeService.class).mergeFromInvoicePayments(invoicePaymentList);
findBatch().setBankOrder(bankOrder);
} catch (AxelorException e) {
TraceBackService.trace(e, ExceptionOriginRepository.DIRECT_DEBIT, batch.getId());
LOG.error(e.getMessage());
}
}
}
use of com.axelor.apps.account.db.InvoicePayment in project axelor-open-suite by axelor.
the class BankOrderMergeServiceImpl method mergeFromInvoicePayments.
@Override
@Transactional(rollbackOn = { Exception.class })
public BankOrder mergeFromInvoicePayments(Collection<InvoicePayment> invoicePayments) throws AxelorException {
if (invoicePayments == null || invoicePayments.isEmpty()) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_MERGE_NO_BANK_ORDERS));
}
Collection<InvoicePayment> invoicePaymentsWithBankOrders = new ArrayList<>();
Collection<BankOrder> bankOrders = new LinkedHashSet<>();
for (InvoicePayment invoicePayment : invoicePayments) {
BankOrder bankOrder = invoicePayment.getBankOrder();
if (bankOrder != null) {
invoicePaymentsWithBankOrders.add(invoicePayment);
bankOrders.add(bankOrder);
}
}
if (bankOrders.size() > 1) {
LocalDate bankOrderDate = bankOrders.iterator().next().getBankOrderDate();
BankOrder mergedBankOrder = mergeBankOrders(bankOrders);
mergedBankOrder.setBankOrderDate(bankOrderDate);
for (InvoicePayment invoicePayment : invoicePaymentsWithBankOrders) {
invoicePayment.setBankOrder(mergedBankOrder);
}
return mergedBankOrder;
}
if (!bankOrders.isEmpty()) {
return bankOrders.iterator().next();
}
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_MERGE_NO_BANK_ORDERS));
}
use of com.axelor.apps.account.db.InvoicePayment in project axelor-open-suite by axelor.
the class InvoicePaymentController method validateMassPayment.
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());
}
});
Beans.get(InvoicePaymentCreateService.class).createMassInvoicePayment(invoiceIdList, invoicePayment.getPaymentMode(), invoicePayment.getCompanyBankDetails(), invoicePayment.getPaymentDate(), invoicePayment.getBankDepositDate(), invoicePayment.getChequeNumber());
}
} 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 InvoicePaymentController method checkConditionBeforeSave.
/**
* Method that check the invoice payment before save and save. Only use when add payment is used
* in invoice
*
* @param request
* @param response
*/
public void checkConditionBeforeSave(ActionRequest request, ActionResponse response) {
try {
InvoicePayment invoicePayment = request.getContext().asType(InvoicePayment.class);
Beans.get(InvoicePaymentToolService.class).checkConditionBeforeSave(invoicePayment);
} catch (Exception e) {
TraceBackService.trace(response, e, ResponseMessageType.ERROR);
}
}
Aggregations