Search in sources :

Example 21 with BankOrderLine

use of com.axelor.apps.bankpayment.db.BankOrderLine in project axelor-open-suite by axelor.

the class BankOrderServiceImpl method computeCompanyCurrencyTotalAmount.

@Override
public BigDecimal computeCompanyCurrencyTotalAmount(BankOrder bankOrder) throws AxelorException {
    BigDecimal companyCurrencyTotalAmount = BigDecimal.ZERO;
    List<BankOrderLine> bankOrderLines = bankOrder.getBankOrderLineList();
    if (bankOrderLines != null) {
        for (BankOrderLine bankOrderLine : bankOrderLines) {
            BigDecimal amount = bankOrderLine.getCompanyCurrencyAmount();
            if (amount != null) {
                companyCurrencyTotalAmount = companyCurrencyTotalAmount.add(amount);
            }
        }
    }
    return companyCurrencyTotalAmount;
}
Also used : BankOrderLine(com.axelor.apps.bankpayment.db.BankOrderLine) BigDecimal(java.math.BigDecimal)

Example 22 with BankOrderLine

use of com.axelor.apps.bankpayment.db.BankOrderLine in project axelor-open-suite by axelor.

the class BatchBankPaymentServiceImpl method createBankOrderFromMonthlyPaymentScheduleLines.

@Override
@Transactional(rollbackOn = { Exception.class })
public BankOrder createBankOrderFromMonthlyPaymentScheduleLines(Batch batch) throws AxelorException, JAXBException, IOException, DatatypeConfigurationException {
    AccountingBatch accountingBatch = batch.getAccountingBatch();
    LocalDate bankOrderDate = accountingBatch.getDueDate();
    Company senderCompany = accountingBatch.getCompany();
    BankDetails senderBankDetails = accountingBatch.getBankDetails();
    if (senderBankDetails == null) {
        senderBankDetails = accountingBatch.getCompany().getDefaultBankDetails();
    }
    PaymentMode paymentMode = accountingBatch.getPaymentMode();
    Currency currency = senderCompany.getCurrency();
    int partnerType = BankOrderRepository.PARTNER_TYPE_CUSTOMER;
    String senderReference = "";
    String senderLabel = "";
    if (bankOrderDate == null) {
        bankOrderDate = appBaseService.getTodayDate(senderCompany);
    }
    BankOrder bankOrder = bankOrderCreateService.createBankOrder(paymentMode, partnerType, bankOrderDate, senderCompany, senderBankDetails, currency, senderReference, senderLabel, BankOrderRepository.TECHNICAL_ORIGIN_AUTOMATIC);
    bankOrder = JPA.save(bankOrder);
    List<PaymentScheduleLine> paymentScheduleLineList;
    int offset = 0;
    try {
        while (!(paymentScheduleLineList = fetchPaymentScheduleLineDoneList(batch, offset)).isEmpty()) {
            bankOrder = bankOrderRepo.find(bankOrder.getId());
            for (PaymentScheduleLine paymentScheduleLine : paymentScheduleLineList) {
                PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
                Partner partner = paymentSchedule.getPartner();
                BankDetails bankDetails = paymentScheduleService.getBankDetails(paymentSchedule);
                BigDecimal amount = paymentScheduleLine.getInTaxAmount();
                String receiverReference = paymentScheduleLine.getName();
                String receiverLabel = paymentScheduleLine.getDebitNumber();
                BankOrderLine bankOrderLine = bankOrderLineService.createBankOrderLine(paymentMode.getBankOrderFileFormat(), null, partner, bankDetails, amount, currency, bankOrderDate, receiverReference, receiverLabel, paymentScheduleLine);
                bankOrder.addBankOrderLineListItem(bankOrderLine);
            }
            bankOrder = JPA.save(bankOrder);
            offset += paymentScheduleLineList.size();
            JPA.clear();
        }
    } catch (Exception e) {
        bankOrder = bankOrderRepo.find(bankOrder.getId());
        bankOrderRepo.remove(bankOrder);
        throw e;
    }
    bankOrder = bankOrderRepo.find(bankOrder.getId());
    bankOrder = bankOrderRepo.save(bankOrder);
    bankOrderService.confirm(bankOrder);
    batch = batchRepo.find(batch.getId());
    batch.setBankOrder(bankOrder);
    return bankOrder;
}
Also used : Company(com.axelor.apps.base.db.Company) BankOrderLine(com.axelor.apps.bankpayment.db.BankOrderLine) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) BankDetails(com.axelor.apps.base.db.BankDetails) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) Currency(com.axelor.apps.base.db.Currency) AccountingBatch(com.axelor.apps.account.db.AccountingBatch) BankOrder(com.axelor.apps.bankpayment.db.BankOrder) Partner(com.axelor.apps.base.db.Partner) PaymentMode(com.axelor.apps.account.db.PaymentMode) Transactional(com.google.inject.persist.Transactional)

Example 23 with BankOrderLine

use of com.axelor.apps.bankpayment.db.BankOrderLine in project axelor-open-suite by axelor.

the class BankOrderLineController method setBankDetailsDomain.

// settings the domain for the bank details view.
public void setBankDetailsDomain(ActionRequest request, ActionResponse response) {
    BankOrderLine bankOrderLine = request.getContext().asType(BankOrderLine.class);
    BankOrder bankOrder = request.getContext().getParent().asType(BankOrder.class);
    String domain = Beans.get(BankOrderLineService.class).createDomainForBankDetails(bankOrderLine, bankOrder);
    // if nothing was found for the domain, we set it at a default value.
    if (domain.equals("")) {
        response.setAttr("receiverBankDetails", "domain", "self.id IN (0)");
    } else {
        response.setAttr("receiverBankDetails", "domain", domain);
    }
}
Also used : BankOrderLineService(com.axelor.apps.bankpayment.service.bankorder.BankOrderLineService) BankOrderLine(com.axelor.apps.bankpayment.db.BankOrderLine) BankOrder(com.axelor.apps.bankpayment.db.BankOrder)

Aggregations

BankOrderLine (com.axelor.apps.bankpayment.db.BankOrderLine)23 BankOrder (com.axelor.apps.bankpayment.db.BankOrder)8 BankDetails (com.axelor.apps.base.db.BankDetails)7 AxelorException (com.axelor.exception.AxelorException)6 BigDecimal (java.math.BigDecimal)5 LocalDate (java.time.LocalDate)4 DatatypeFactory (javax.xml.datatype.DatatypeFactory)4 PaymentMode (com.axelor.apps.account.db.PaymentMode)3 Transactional (com.google.inject.persist.Transactional)3 Umr (com.axelor.apps.account.db.Umr)2 BankOrderLineService (com.axelor.apps.bankpayment.service.bankorder.BankOrderLineService)2 Company (com.axelor.apps.base.db.Company)2 Currency (com.axelor.apps.base.db.Currency)2 Partner (com.axelor.apps.base.db.Partner)2 AccountingBatch (com.axelor.apps.account.db.AccountingBatch)1 Invoice (com.axelor.apps.account.db.Invoice)1 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)1 PaymentSchedule (com.axelor.apps.account.db.PaymentSchedule)1 PaymentScheduleLine (com.axelor.apps.account.db.PaymentScheduleLine)1 Reimbursement (com.axelor.apps.account.db.Reimbursement)1