use of com.axelor.apps.bankpayment.db.BankOrderLine 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.bankpayment.db.BankOrderLine in project axelor-open-suite by axelor.
the class BankOrderMoveServiceImpl method generateMoves.
@Override
public void generateMoves(BankOrder bankOrder) throws AxelorException {
if (bankOrder.getBankOrderLineList() == null || bankOrder.getBankOrderLineList().isEmpty()) {
return;
}
paymentMode = bankOrder.getPaymentMode();
if (paymentMode == null || !paymentMode.getGenerateMoveAutoFromBankOrder()) {
return;
}
orderTypeSelect = bankOrder.getOrderTypeSelect();
senderCompany = bankOrder.getSenderCompany();
senderBankDetails = bankOrder.getSenderBankDetails();
partnerTypeSelect = bankOrder.getPartnerTypeSelect();
journal = paymentModeService.getPaymentModeJournal(paymentMode, senderCompany, senderBankDetails);
senderBankAccount = paymentModeService.getPaymentModeAccount(paymentMode, senderCompany, senderBankDetails);
isMultiDate = bankOrder.getIsMultiDate();
isMultiCurrency = bankOrder.getIsMultiCurrency();
if (orderTypeSelect == BankOrderRepository.ORDER_TYPE_INTERNATIONAL_CREDIT_TRANSFER || orderTypeSelect == BankOrderRepository.ORDER_TYPE_SEPA_CREDIT_TRANSFER) {
isDebit = true;
} else {
isDebit = false;
}
for (BankOrderLine bankOrderLine : bankOrder.getBankOrderLineList()) {
if (ObjectUtils.isEmpty(bankOrderLine.getBankOrderLineOriginList())) {
generateMoves(bankOrderLine);
}
}
}
use of com.axelor.apps.bankpayment.db.BankOrderLine in project axelor-open-suite by axelor.
the class BankOrderServiceImpl method computeBankOrderTotalAmount.
@Override
public BigDecimal computeBankOrderTotalAmount(BankOrder bankOrder) throws AxelorException {
BigDecimal bankOrderTotalAmount = BigDecimal.ZERO;
List<BankOrderLine> bankOrderLines = bankOrder.getBankOrderLineList();
if (bankOrderLines != null) {
for (BankOrderLine bankOrderLine : bankOrderLines) {
BigDecimal amount = bankOrderLine.getBankOrderAmount();
if (amount != null) {
bankOrderTotalAmount = bankOrderTotalAmount.add(amount);
}
}
}
return bankOrderTotalAmount;
}
use of com.axelor.apps.bankpayment.db.BankOrderLine in project axelor-open-suite by axelor.
the class BankOrderServiceImpl method resetPartners.
private void resetPartners(BankOrder bankOrder) {
if (bankOrder.getPartnerTypeSelect() == BankOrderRepository.PARTNER_TYPE_COMPANY) {
for (BankOrderLine bankOrderLine : bankOrder.getBankOrderLineList()) {
bankOrderLine.setPartner(null);
}
return;
}
for (BankOrderLine bankOrderLine : bankOrder.getBankOrderLineList()) {
bankOrderLine.setReceiverCompany(null);
Partner partner = bankOrderLine.getPartner();
if (partner == null) {
continue;
}
boolean keep;
switch(bankOrder.getPartnerTypeSelect()) {
case BankOrderRepository.PARTNER_TYPE_SUPPLIER:
keep = partner.getIsSupplier();
break;
case BankOrderRepository.PARTNER_TYPE_EMPLOYEE:
keep = partner.getIsEmployee();
break;
case BankOrderRepository.PARTNER_TYPE_CUSTOMER:
keep = partner.getIsCustomer();
break;
default:
keep = false;
}
if (!keep) {
bankOrderLine.setPartner(null);
}
}
}
use of com.axelor.apps.bankpayment.db.BankOrderLine in project axelor-open-suite by axelor.
the class BankOrderServiceImpl method validateBankOrderLines.
public void validateBankOrderLines(List<BankOrderLine> bankOrderLines, int orderType, BigDecimal arithmeticTotal) throws AxelorException {
BigDecimal totalAmount = BigDecimal.ZERO;
for (BankOrderLine bankOrderLine : bankOrderLines) {
bankOrderLineService.checkPreconditions(bankOrderLine);
totalAmount = totalAmount.add(bankOrderLine.getBankOrderAmount());
bankOrderLineService.checkBankDetails(bankOrderLine.getReceiverBankDetails(), bankOrderLine.getBankOrder());
}
if (!totalAmount.equals(arithmeticTotal)) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_LINE_TOTAL_AMOUNT_INVALID));
}
}
Aggregations