Search in sources :

Example 21 with BankOrder

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

the class BankOrderCreateService method createBankOrder.

/**
 * Method to create a bank order for an invoice Payment
 *
 * @param invoicePayment An invoice payment
 * @throws AxelorException
 */
public BankOrder createBankOrder(InvoicePayment invoicePayment) throws AxelorException {
    Invoice invoice = invoicePayment.getInvoice();
    Company company = invoice.getCompany();
    PaymentMode paymentMode = invoicePayment.getPaymentMode();
    Partner partner = invoice.getPartner();
    BigDecimal amount = invoicePayment.getAmount();
    Currency currency = invoicePayment.getCurrency();
    LocalDate paymentDate = invoicePayment.getPaymentDate();
    BankDetails companyBankDetails = invoicePayment.getCompanyBankDetails() != null ? invoicePayment.getCompanyBankDetails() : this.getSenderBankDetails(invoice);
    String reference = InvoiceToolService.isPurchase(invoice) ? invoice.getSupplierInvoiceNb() : invoice.getInvoiceId();
    BankOrder bankOrder = this.createBankOrder(paymentMode, this.getBankOrderPartnerType(invoice), paymentDate, company, companyBankDetails, currency, reference, null, BankOrderRepository.TECHNICAL_ORIGIN_AUTOMATIC);
    BankDetails receiverBankDetails = invoiceService.getBankDetails(invoice);
    BankOrderLine bankOrderLine = bankOrderLineService.createBankOrderLine(paymentMode.getBankOrderFileFormat(), null, partner, receiverBankDetails, amount, currency, paymentDate, reference, null, invoice);
    bankOrder.addBankOrderLineListItem(bankOrderLine);
    bankOrder = bankOrderRepo.save(bankOrder);
    return bankOrder;
}
Also used : Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) BankOrderLine(com.axelor.apps.bankpayment.db.BankOrderLine) BankDetails(com.axelor.apps.base.db.BankDetails) 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 22 with BankOrder

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

the class BankOrderCreateService method createBankOrder.

/**
 * Créer un ordre bancaire avec tous les paramètres
 *
 * @param
 * @return
 * @throws AxelorException
 */
public BankOrder createBankOrder(PaymentMode paymentMode, Integer partnerType, LocalDate bankOrderDate, Company senderCompany, BankDetails senderBankDetails, Currency currency, String senderReference, String senderLabel, int technicalOriginSelect) throws AxelorException {
    BankOrderFileFormat bankOrderFileFormat = paymentMode.getBankOrderFileFormat();
    BankOrder bankOrder = new BankOrder();
    bankOrder.setOrderTypeSelect(paymentMode.getOrderTypeSelect());
    bankOrder.setPaymentMode(paymentMode);
    bankOrder.setPartnerTypeSelect(partnerType);
    if (!bankOrderFileFormat.getIsMultiDate()) {
        bankOrder.setBankOrderDate(bankOrderDate);
    }
    bankOrder.setStatusSelect(BankOrderRepository.STATUS_DRAFT);
    bankOrder.setRejectStatusSelect(BankOrderRepository.REJECT_STATUS_NOT_REJECTED);
    bankOrder.setSenderCompany(senderCompany);
    bankOrder.setSenderBankDetails(senderBankDetails);
    EbicsUser signatoryEbicsUser = bankOrderService.getDefaultEbicsUserFromBankDetails(senderBankDetails);
    User signatoryUser = null;
    if (signatoryEbicsUser != null) {
        signatoryUser = signatoryEbicsUser.getAssociatedUser();
        bankOrder.setSignatoryEbicsUser(signatoryEbicsUser);
    }
    if (signatoryUser != null) {
        bankOrder.setSignatoryUser(signatoryUser);
    }
    if (!bankOrderFileFormat.getIsMultiCurrency()) {
        bankOrder.setBankOrderCurrency(currency);
    }
    bankOrder.setCompanyCurrency(senderCompany.getCurrency());
    bankOrder.setSenderReference(senderReference);
    bankOrder.setSenderLabel(senderLabel);
    bankOrder.setBankOrderLineList(new ArrayList<BankOrderLine>());
    bankOrder.setBankOrderFileFormat(bankOrderFileFormat);
    bankOrder.setTechnicalOriginSelect(technicalOriginSelect);
    return bankOrder;
}
Also used : EbicsUser(com.axelor.apps.bankpayment.db.EbicsUser) User(com.axelor.auth.db.User) BankOrderLine(com.axelor.apps.bankpayment.db.BankOrderLine) EbicsUser(com.axelor.apps.bankpayment.db.EbicsUser) BankOrderFileFormat(com.axelor.apps.bankpayment.db.BankOrderFileFormat) BankOrder(com.axelor.apps.bankpayment.db.BankOrder)

Example 23 with BankOrder

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

the class BankOrderMergeServiceImpl method checkSameElements.

protected void checkSameElements(Collection<BankOrder> bankOrders) throws AxelorException {
    BankOrder refBankOrder = bankOrders.iterator().next();
    int refStatusSelect = refBankOrder.getStatusSelect();
    int orderTypeSelect = refBankOrder.getOrderTypeSelect();
    PaymentMode refPaymentMode = refBankOrder.getPaymentMode();
    int refPartnerTypeSelect = refBankOrder.getPartnerTypeSelect();
    Company refSenderCompany = refBankOrder.getSenderCompany();
    BankDetails refSenderBankDetails = refBankOrder.getSenderBankDetails();
    Currency refCurrency = refBankOrder.getBankOrderCurrency();
    boolean isMultiCurrency = refBankOrder.getIsMultiCurrency();
    for (BankOrder bankOrder : bankOrders) {
        int statusSelect = bankOrder.getStatusSelect();
        if (statusSelect != BankOrderRepository.STATUS_DRAFT && statusSelect != BankOrderRepository.STATUS_AWAITING_SIGNATURE) {
            throw new AxelorException(bankOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_MERGE_STATUS));
        }
        if (statusSelect != refStatusSelect) {
            throw new AxelorException(bankOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_MERGE_SAME_STATUS));
        }
        if (!bankOrder.getOrderTypeSelect().equals(orderTypeSelect)) {
            throw new AxelorException(bankOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_MERGE_SAME_ORDER_TYPE_SELECT));
        }
        if (!bankOrder.getPaymentMode().equals(refPaymentMode)) {
            throw new AxelorException(bankOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_MERGE_SAME_PAYMENT_MODE));
        }
        if (!bankOrder.getPartnerTypeSelect().equals(refPartnerTypeSelect)) {
            throw new AxelorException(bankOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_MERGE_SAME_PARTNER_TYPE_SELECT));
        }
        if (!bankOrder.getSenderCompany().equals(refSenderCompany)) {
            throw new AxelorException(bankOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_MERGE_SAME_SENDER_COMPANY));
        }
        if (bankOrder.getSenderBankDetails() == null && refSenderBankDetails != null || (bankOrder.getSenderBankDetails() != null && !bankOrder.getSenderBankDetails().equals(refSenderBankDetails))) {
            throw new AxelorException(bankOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_MERGE_SAME_SENDER_BANK_DETAILS));
        }
        if (bankOrder.getIsMultiCurrency() != isMultiCurrency || !bankOrder.getIsMultiCurrency() && !bankOrder.getBankOrderCurrency().equals(refCurrency)) {
            throw new AxelorException(bankOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_MERGE_SAME_CURRENCY));
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) BankDetails(com.axelor.apps.base.db.BankDetails) Currency(com.axelor.apps.base.db.Currency) BankOrder(com.axelor.apps.bankpayment.db.BankOrder) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 24 with BankOrder

use of com.axelor.apps.bankpayment.db.BankOrder 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 25 with BankOrder

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

the class BankOrderController method setBankDetailDomain.

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

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