Search in sources :

Example 16 with BankOrder

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);
}
Also used : BankOrderLineService(com.axelor.apps.bankpayment.service.bankorder.BankOrderLineService) BankOrderLine(com.axelor.apps.bankpayment.db.BankOrderLine) BankDetails(com.axelor.apps.base.db.BankDetails) BankOrder(com.axelor.apps.bankpayment.db.BankOrder)

Example 17 with BankOrder

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));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AxelorException(com.axelor.exception.AxelorException) InvoicePayment(com.axelor.apps.account.db.InvoicePayment) ArrayList(java.util.ArrayList) BankOrder(com.axelor.apps.bankpayment.db.BankOrder) LocalDate(java.time.LocalDate) Transactional(com.google.inject.persist.Transactional)

Example 18 with BankOrder

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);
}
Also used : AxelorException(com.axelor.exception.AxelorException) MoveCancelService(com.axelor.apps.account.service.move.MoveCancelService) Move(com.axelor.apps.account.db.Move) BankOrder(com.axelor.apps.bankpayment.db.BankOrder) Transactional(com.google.inject.persist.Transactional)

Example 19 with BankOrder

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;
}
Also used : Company(com.axelor.apps.base.db.Company) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Currency(com.axelor.apps.base.db.Currency) BankOrder(com.axelor.apps.bankpayment.db.BankOrder) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 20 with 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;
}
Also used : Expense(com.axelor.apps.hr.db.Expense) BankOrder(com.axelor.apps.bankpayment.db.BankOrder) Transactional(com.google.inject.persist.Transactional)

Aggregations

BankOrder (com.axelor.apps.bankpayment.db.BankOrder)33 AxelorException (com.axelor.exception.AxelorException)16 Transactional (com.google.inject.persist.Transactional)11 BankOrderService (com.axelor.apps.bankpayment.service.bankorder.BankOrderService)10 BankOrderLine (com.axelor.apps.bankpayment.db.BankOrderLine)8 PaymentMode (com.axelor.apps.account.db.PaymentMode)6 BankDetails (com.axelor.apps.base.db.BankDetails)6 LocalDate (java.time.LocalDate)6 Company (com.axelor.apps.base.db.Company)4 Currency (com.axelor.apps.base.db.Currency)4 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)3 EbicsUser (com.axelor.apps.bankpayment.db.EbicsUser)3 Partner (com.axelor.apps.base.db.Partner)3 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3 AccountingBatch (com.axelor.apps.account.db.AccountingBatch)2 PaymentScheduleLine (com.axelor.apps.account.db.PaymentScheduleLine)2 BankOrderRepository (com.axelor.apps.bankpayment.db.repo.BankOrderRepository)2 BankOrderLineService (com.axelor.apps.bankpayment.service.bankorder.BankOrderLineService)2 BankOrderMergeService (com.axelor.apps.bankpayment.service.bankorder.BankOrderMergeService)2