Search in sources :

Example 36 with PaymentMode

use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.

the class StockMoveInvoiceController method generateInvoiceConcatOutStockMove.

/**
 * Called from mass invoicing in stock move confirm view. Get parameters entered by the user, then
 * call {@link StockMoveMultiInvoiceService#createInvoiceFromMultiOutgoingStockMove(List,
 * PaymentCondition, PaymentMode, Partner)} and show the generated invoice.
 *
 * @param request
 * @param response
 */
public void generateInvoiceConcatOutStockMove(ActionRequest request, ActionResponse response) {
    try {
        List<StockMove> stockMoveList = new ArrayList<>();
        String stockMoveListStr = (String) request.getContext().get("customerStockMoveToInvoice");
        for (String stockMoveId : stockMoveListStr.split(",")) {
            stockMoveList.add(JPA.em().find(StockMove.class, new Long(stockMoveId)));
        }
        // Check if paymentCondition, paymentMode or contactPartner are content in parameters
        PaymentCondition paymentCondition = null;
        PaymentMode paymentMode = null;
        Partner contactPartner = null;
        // paymentCondition, only for customer stockMove
        if (request.getContext().get("paymentCondition") != null) {
            paymentCondition = JPA.em().find(PaymentCondition.class, Long.valueOf((Integer) ((Map) request.getContext().get("paymentCondition")).get("id")));
        }
        // paymentMode, only for customer stockMove
        if (request.getContext().get("paymentMode") != null) {
            paymentMode = JPA.em().find(PaymentMode.class, Long.valueOf((Integer) ((Map) request.getContext().get("paymentMode")).get("id")));
        }
        if (request.getContext().get("contactPartner") != null) {
            contactPartner = JPA.em().find(Partner.class, Long.valueOf((Integer) ((Map) request.getContext().get("contactPartner")).get("id")));
        }
        Optional<Invoice> invoice = Beans.get(StockMoveMultiInvoiceService.class).createInvoiceFromMultiOutgoingStockMove(stockMoveList, paymentCondition, paymentMode, contactPartner);
        invoice.ifPresent(inv -> response.setView(ActionView.define("Invoice").model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(inv.getId())).context("_operationTypeSelect", inv.getOperationTypeSelect()).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(inv.getCompany())).map()));
        response.setCanClose(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : PaymentCondition(com.axelor.apps.account.db.PaymentCondition) StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) StockMoveMultiInvoiceService(com.axelor.apps.supplychain.service.StockMoveMultiInvoiceService) ArrayList(java.util.ArrayList) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) Partner(com.axelor.apps.base.db.Partner) Map(java.util.Map) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 37 with PaymentMode

use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.

the class PurchaseOrderController method fillCompanyBankDetails.

/**
 * Called on partner, company or payment change. Fill the bank details with a default value.
 *
 * @param request
 * @param response
 */
public void fillCompanyBankDetails(ActionRequest request, ActionResponse response) {
    try {
        PurchaseOrder purchaseOrder = request.getContext().asType(PurchaseOrder.class);
        PaymentMode paymentMode = (PaymentMode) request.getContext().get("paymentMode");
        Company company = purchaseOrder.getCompany();
        Partner partner = purchaseOrder.getSupplierPartner();
        if (company == null) {
            return;
        }
        if (partner != null) {
            partner = Beans.get(PartnerRepository.class).find(partner.getId());
        }
        BankDetails defaultBankDetails = Beans.get(BankDetailsService.class).getDefaultCompanyBankDetails(company, paymentMode, partner, null);
        response.setValue("companyBankDetails", defaultBankDetails);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : BankDetailsService(com.axelor.apps.base.service.BankDetailsService) Company(com.axelor.apps.base.db.Company) BankDetails(com.axelor.apps.base.db.BankDetails) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) Partner(com.axelor.apps.base.db.Partner) AxelorException(com.axelor.exception.AxelorException) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 38 with PaymentMode

use of com.axelor.apps.account.db.PaymentMode 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 39 with PaymentMode

use of com.axelor.apps.account.db.PaymentMode 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 40 with PaymentMode

use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.

the class BankOrderServiceImpl method sendFile.

protected void sendFile(BankOrder bankOrder, File dataFileToSend, File signatureFileToSend) throws AxelorException {
    PaymentMode paymentMode = bankOrder.getPaymentMode();
    if (paymentMode != null && !paymentMode.getAutomaticTransmission()) {
        return;
    }
    EbicsUser signatoryEbicsUser = bankOrder.getSignatoryEbicsUser();
    ebicsService.sendFULRequest(signatoryEbicsUser.getEbicsPartner().getTransportEbicsUser(), signatoryEbicsUser, null, dataFileToSend, bankOrder.getBankOrderFileFormat(), signatureFileToSend);
}
Also used : EbicsUser(com.axelor.apps.bankpayment.db.EbicsUser) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Aggregations

PaymentMode (com.axelor.apps.account.db.PaymentMode)45 Company (com.axelor.apps.base.db.Company)27 Partner (com.axelor.apps.base.db.Partner)26 BankDetails (com.axelor.apps.base.db.BankDetails)21 Invoice (com.axelor.apps.account.db.Invoice)18 AxelorException (com.axelor.exception.AxelorException)17 Transactional (com.google.inject.persist.Transactional)13 BigDecimal (java.math.BigDecimal)11 LocalDate (java.time.LocalDate)10 PaymentCondition (com.axelor.apps.account.db.PaymentCondition)9 Currency (com.axelor.apps.base.db.Currency)9 ArrayList (java.util.ArrayList)8 Journal (com.axelor.apps.account.db.Journal)7 PaymentModeService (com.axelor.apps.account.service.payment.PaymentModeService)7 Map (java.util.Map)7 BankOrder (com.axelor.apps.bankpayment.db.BankOrder)6 BankDetailsService (com.axelor.apps.base.service.BankDetailsService)6 Account (com.axelor.apps.account.db.Account)5 Move (com.axelor.apps.account.db.Move)5 PriceList (com.axelor.apps.base.db.PriceList)5