Search in sources :

Example 31 with Currency

use of com.axelor.apps.base.db.Currency 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 32 with Currency

use of com.axelor.apps.base.db.Currency in project axelor-open-suite by axelor.

the class BankOrderLineService method createDomainForBankDetails.

public String createDomainForBankDetails(BankOrderLine bankOrderLine, BankOrder bankOrder) {
    String domain = "";
    String bankDetailsIds = "";
    if ((bankOrderLine == null) || (bankOrder == null)) {
        return domain;
    }
    // the case where the bank order is for a company
    if (bankOrder.getPartnerTypeSelect() == BankOrderRepository.PARTNER_TYPE_COMPANY) {
        if (bankOrderLine.getReceiverCompany() != null) {
            bankDetailsIds = StringTool.getIdListString(bankOrderLine.getReceiverCompany().getBankDetailsList());
            if (bankOrderLine.getReceiverCompany().getDefaultBankDetails() != null) {
                bankDetailsIds += bankDetailsIds.equals("") ? "" : ",";
                bankDetailsIds += bankOrderLine.getReceiverCompany().getDefaultBankDetails().getId().toString();
            }
        }
    } else // case where the bank order is for a partner
    if (bankOrderLine.getPartner() != null) {
        bankDetailsIds = StringTool.getIdListString(bankOrderLine.getPartner().getBankDetailsList());
    }
    if (bankDetailsIds.equals("")) {
        return domain = "";
    }
    domain = "self.id IN(" + bankDetailsIds + ")";
    // filter the result on active bank details
    domain += " AND self.active = true";
    // filter on the result from bankPartner if the option is active.
    EbicsPartner ebicsPartner = Beans.get(EbicsPartnerRepository.class).all().filter("? MEMBER OF self.bankDetailsSet", bankOrder.getSenderBankDetails()).fetchOne();
    if (ebicsPartnerIsFiltering(ebicsPartner, bankOrder.getOrderTypeSelect())) {
        domain += " AND self.id IN (" + StringTool.getIdListString(ebicsPartner.getReceiverBankDetailsSet()) + ")";
    }
    // filter on the bank details identifier type from the bank order file format
    if (bankOrder.getBankOrderFileFormat() != null) {
        String acceptedIdentifiers = bankOrder.getBankOrderFileFormat().getBankDetailsTypeSelect();
        if (acceptedIdentifiers != null && !acceptedIdentifiers.equals("")) {
            domain += " AND self.bank.bankDetailsTypeSelect IN (" + acceptedIdentifiers + ")";
        }
    }
    // filter on the currency if it is set in bank order and in the bankdetails
    // and if the bankOrder is not multicurrency
    // and if the partner type select is a company
    Currency currency = bankOrder.getBankOrderCurrency();
    if (!bankOrder.getIsMultiCurrency() && currency != null && bankOrder.getPartnerTypeSelect() == BankOrderRepository.PARTNER_TYPE_COMPANY) {
        String fileFormatCurrencyId = currency.getId().toString();
        domain += " AND (self.currency IS NULL OR self.currency.id = " + fileFormatCurrencyId + ")";
    }
    return domain;
}
Also used : Currency(com.axelor.apps.base.db.Currency) EbicsPartner(com.axelor.apps.bankpayment.db.EbicsPartner) EbicsPartnerRepository(com.axelor.apps.bankpayment.db.repo.EbicsPartnerRepository)

Example 33 with Currency

use of com.axelor.apps.base.db.Currency 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 34 with Currency

use of com.axelor.apps.base.db.Currency in project axelor-open-suite by axelor.

the class BankOrderServiceImpl method createDomainForBankDetails.

@Override
public String createDomainForBankDetails(BankOrder bankOrder) {
    String domain = Beans.get(BankDetailsService.class).getActiveCompanyBankDetails(bankOrder.getSenderCompany());
    // format
    if (bankOrder.getBankOrderFileFormat() != null) {
        String acceptedIdentifiers = bankOrder.getBankOrderFileFormat().getBankDetailsTypeSelect();
        if (acceptedIdentifiers != null && !acceptedIdentifiers.equals("")) {
            domain += " AND self.bank.bankDetailsTypeSelect IN (" + acceptedIdentifiers + ")";
        }
    }
    // filter on the currency if it is set in file format and in the bankdetails
    Currency currency = bankOrder.getBankOrderCurrency();
    if (currency != null && !bankOrder.getBankOrderFileFormat().getAllowOrderCurrDiffFromBankDetails()) {
        String fileFormatCurrencyId = currency.getId().toString();
        domain += " AND (self.currency IS NULL OR self.currency.id = " + fileFormatCurrencyId + ")";
    }
    return domain;
}
Also used : BankDetailsService(com.axelor.apps.base.service.BankDetailsService) Currency(com.axelor.apps.base.db.Currency)

Example 35 with Currency

use of com.axelor.apps.base.db.Currency in project axelor-open-suite by axelor.

the class SopLineController method fillMrpForecast.

public void fillMrpForecast(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    @SuppressWarnings("unchecked") LinkedHashMap<String, Object> productCategoryMap = (LinkedHashMap<String, Object>) context.get("_productCategory");
    @SuppressWarnings("unchecked") LinkedHashMap<String, Object> sopLineMap = (LinkedHashMap<String, Object>) context.get("_sopLine");
    @SuppressWarnings("unchecked") LinkedHashMap<String, Object> currencyMap = (LinkedHashMap<String, Object>) sopLineMap.get("currency");
    BigDecimal sopSalesForecast = new BigDecimal(sopLineMap.get("sopSalesForecast").toString());
    Long productCategoryId = Long.parseLong(productCategoryMap.get("id").toString());
    Currency currency = currencyRepo.find(Long.parseLong(currencyMap.get("id").toString()));
    BigDecimal totalForecast = BigDecimal.ZERO;
    SortedSet<Map<String, Object>> mrpForecastSet = new TreeSet<Map<String, Object>>(Comparator.comparing(m -> (String) m.get("code")));
    List<Product> productList = Beans.get(ProductRepository.class).all().filter("self.productCategory.id = ?1 ", productCategoryId).fetch();
    if (productList != null) {
        for (Product product : productList) {
            Map<String, Object> map = new HashMap<String, Object>();
            MrpForecast mrpForecast = mrpForecastRepo.all().filter("self.product.id = ?1 AND self.technicalOrigin = ?2", product.getId(), MrpForecastRepository.TECHNICAL_ORIGIN_CREATED_FROM_SOP).fetchOne();
            if (mrpForecast != null) {
                map = Mapper.toMap(mrpForecast);
                BigDecimal totalPrice = mrpForecast.getQty().multiply(product.getSalePrice());
                map.put("$totalPrice", totalPrice);
                map.put("$unitPrice", product.getSalePrice());
                map.put("code", product.getCode());
                totalForecast = totalForecast.add(totalPrice);
                mrpForecastSet.add(map);
                continue;
            }
            map.put("product", product);
            map.put("qty", BigDecimal.ZERO);
            map.put("$totalPrice", BigDecimal.ZERO);
            map.put("$unitPrice", product.getSalePrice());
            map.put("code", product.getCode());
            mrpForecastSet.add(map);
        }
    }
    response.setValue("$mrpForecasts", mrpForecastSet);
    response.setValue("$sopSalesForecast", sopSalesForecast);
    response.setValue("$totalForecast", totalForecast);
    response.setValue("$difference", sopSalesForecast.subtract(totalForecast).setScale(Beans.get(AppBaseService.class).getNbDecimalDigitForUnitPrice()));
    response.setValue("$currency", currency);
}
Also used : Context(com.axelor.rpc.Context) CurrencyRepository(com.axelor.apps.base.db.repo.CurrencyRepository) SortedSet(java.util.SortedSet) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) Inject(com.google.inject.Inject) HashMap(java.util.HashMap) MrpForecastRepository(com.axelor.apps.supplychain.db.repo.MrpForecastRepository) Mapper(com.axelor.db.mapper.Mapper) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) MrpForecast(com.axelor.apps.supplychain.db.MrpForecast) Currency(com.axelor.apps.base.db.Currency) TreeSet(java.util.TreeSet) LinkedHashMap(java.util.LinkedHashMap) BigDecimal(java.math.BigDecimal) List(java.util.List) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) ActionRequest(com.axelor.rpc.ActionRequest) Comparator(java.util.Comparator) Context(com.axelor.rpc.Context) Singleton(com.google.inject.Singleton) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal) LinkedHashMap(java.util.LinkedHashMap) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) TreeSet(java.util.TreeSet) Currency(com.axelor.apps.base.db.Currency) MrpForecast(com.axelor.apps.supplychain.db.MrpForecast) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

Currency (com.axelor.apps.base.db.Currency)41 Company (com.axelor.apps.base.db.Company)19 BigDecimal (java.math.BigDecimal)19 AxelorException (com.axelor.exception.AxelorException)17 Partner (com.axelor.apps.base.db.Partner)14 ArrayList (java.util.ArrayList)12 List (java.util.List)10 Invoice (com.axelor.apps.account.db.Invoice)9 PaymentMode (com.axelor.apps.account.db.PaymentMode)9 PriceList (com.axelor.apps.base.db.PriceList)9 Map (java.util.Map)9 SaleOrder (com.axelor.apps.sale.db.SaleOrder)8 LocalDate (java.time.LocalDate)8 BankDetails (com.axelor.apps.base.db.BankDetails)7 Wizard (com.axelor.apps.base.db.Wizard)7 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)7 Product (com.axelor.apps.base.db.Product)6 Transactional (com.google.inject.persist.Transactional)6 PaymentCondition (com.axelor.apps.account.db.PaymentCondition)4 BankOrder (com.axelor.apps.bankpayment.db.BankOrder)4