use of com.axelor.apps.bankpayment.db.BankOrder in project axelor-open-suite by axelor.
the class BankOrderLineController method fillBankDetail.
public void fillBankDetail(ActionRequest request, ActionResponse response) {
BankOrderLine bankOrderLine = request.getContext().asType(BankOrderLine.class);
BankOrder bankOrder = request.getContext().getParent().asType(BankOrder.class);
BankDetails bankDetails = Beans.get(BankOrderLineService.class).getDefaultBankDetails(bankOrderLine, bankOrder);
response.setValue("receiverBankDetails", bankDetails);
}
use of com.axelor.apps.bankpayment.db.BankOrder 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.bankpayment.db.BankOrder in project axelor-open-suite by axelor.
the class ExpenseServiceImpl method cancelPayment.
@Override
@Transactional(rollbackOn = { Exception.class })
public void cancelPayment(Expense expense) throws AxelorException {
BankOrder bankOrder = expense.getBankOrder();
if (bankOrder != null) {
if (bankOrder.getStatusSelect() == BankOrderRepository.STATUS_CARRIED_OUT || bankOrder.getStatusSelect() == BankOrderRepository.STATUS_REJECTED) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.EXPENSE_PAYMENT_CANCEL));
} else if (bankOrder.getStatusSelect() != BankOrderRepository.STATUS_CANCELED) {
Beans.get(BankOrderService.class).cancelBankOrder(bankOrder);
}
}
Move paymentMove = expense.getPaymentMove();
if (paymentMove != null) {
expense.setPaymentMove(null);
Beans.get(MoveCancelService.class).cancel(paymentMove);
}
expense.setPaymentStatusSelect(InvoicePaymentRepository.STATUS_CANCELED);
expense.setStatusSelect(ExpenseRepository.STATUS_VALIDATED);
expense.setPaymentDate(null);
expense.setPaymentAmount(BigDecimal.ZERO);
expenseRepository.save(expense);
}
use of com.axelor.apps.bankpayment.db.BankOrder in project axelor-open-suite by axelor.
the class BankOrderCreateServiceHr method createBankOrder.
/**
* Method to create a bank order for an expense
*
* @param expense An expense
* @throws AxelorException
*/
public BankOrder createBankOrder(Expense expense, BankDetails bankDetails) throws AxelorException {
Company company = expense.getCompany();
Partner partner = expense.getUser().getPartner();
PaymentMode paymentMode = expense.getPaymentMode();
BigDecimal amount = expense.getInTaxTotal().subtract(expense.getAdvanceAmount()).subtract(expense.getWithdrawnCash()).subtract(expense.getPersonalExpenseAmount());
Currency currency = company.getCurrency();
LocalDate paymentDate = Beans.get(AppBaseService.class).getTodayDate(company);
BankOrder bankOrder = super.createBankOrder(paymentMode, BankOrderRepository.PARTNER_TYPE_EMPLOYEE, paymentDate, company, bankDetails, currency, expense.getFullName(), expense.getFullName(), BankOrderRepository.TECHNICAL_ORIGIN_AUTOMATIC);
bankOrder.addBankOrderLineListItem(bankOrderLineService.createBankOrderLine(paymentMode.getBankOrderFileFormat(), partner, amount, currency, paymentDate, expense.getExpenseSeq(), expense.getFullName(), expense));
bankOrder = bankOrderRepo.save(bankOrder);
return bankOrder;
}
use of com.axelor.apps.bankpayment.db.BankOrder in project axelor-open-suite by axelor.
the class BankOrderMergeHRServiceImpl method mergeBankOrders.
@Transactional(rollbackOn = { AxelorException.class, Exception.class })
@Override
public BankOrder mergeBankOrders(Collection<BankOrder> bankOrders) throws AxelorException {
if (!Beans.get(AppService.class).isApp("employee")) {
return super.mergeBankOrders(bankOrders);
}
List<Expense> expenseList = expenseHRRepository.all().filter("self.bankOrder.id IN (?)", bankOrders.stream().map(BankOrder::getId).collect(Collectors.toList())).fetch();
for (Expense expense : expenseList) {
expense.setBankOrder(null);
expenseHRRepository.save(expense);
}
BankOrder bankOrder = super.mergeBankOrders(bankOrders);
for (Expense expense : expenseList) {
expense.setBankOrder(bankOrder);
expenseHRRepository.save(expense);
}
return bankOrder;
}
Aggregations