Search in sources :

Example 11 with Currency

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

the class BankReconciliationCreateService method createAllFromBankStatement.

@Transactional(rollbackOn = { Exception.class })
public List<BankReconciliation> createAllFromBankStatement(BankStatement bankStatement) throws IOException {
    List<BankReconciliation> bankReconciliationList = new ArrayList<>();
    List<BankDetails> bankDetailsList = getDistinctBankDetails(bankStatement);
    if (bankDetailsList == null) {
        return bankReconciliationList;
    }
    LocalDate fromDate = bankStatement.getFromDate();
    LocalDate toDate = bankStatement.getToDate();
    for (BankDetails bankDetails : bankDetailsList) {
        Company company = companyRepository.all().filter("?1 member of self.bankDetailsList", bankDetails).fetchOne();
        Currency currency = bankDetails.getCurrency();
        if (currency == null) {
            currency = company.getCurrency();
        }
        BankReconciliation bankReconciliation = createBankReconciliation(company, fromDate, toDate, currency, bankDetails, bankStatement);
        bankReconciliationRepository.save(bankReconciliation);
        bankReconciliationList.add(bankReconciliation);
    }
    return bankReconciliationList;
}
Also used : Company(com.axelor.apps.base.db.Company) BankDetails(com.axelor.apps.base.db.BankDetails) Currency(com.axelor.apps.base.db.Currency) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate) BankReconciliation(com.axelor.apps.bankpayment.db.BankReconciliation) Transactional(com.google.inject.persist.Transactional)

Example 12 with Currency

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

the class BankStatementFileAFB120Service method createBankStatementLine.

@Transactional
public BankStatementLineAFB120 createBankStatementLine(Map<String, Object> structuredContentLine, int sequence) {
    String description = (String) structuredContentLine.get("description");
    if (structuredContentLine.containsKey("additionalInformation") && structuredContentLine.get("additionalInformation") != null) {
        description += "\n" + (String) structuredContentLine.get("additionalInformation");
    }
    BankDetails bankDetails = null;
    if (structuredContentLine.containsKey("bankDetails") && structuredContentLine.get("bankDetails") != null) {
        bankDetails = bankDetailsRepository.find(((BankDetails) structuredContentLine.get("bankDetails")).getId());
    }
    Currency currency = null;
    if (structuredContentLine.containsKey("currency") && structuredContentLine.get("currency") != null) {
        currency = currencyRepository.find(((Currency) structuredContentLine.get("currency")).getId());
    }
    InterbankCodeLine operationInterbankCodeLine = null;
    if (structuredContentLine.containsKey("operationInterbankCodeLine") && structuredContentLine.get("operationInterbankCodeLine") != null) {
        operationInterbankCodeLine = interbankCodeLineRepository.find(((InterbankCodeLine) structuredContentLine.get("operationInterbankCodeLine")).getId());
    }
    InterbankCodeLine rejectInterbankCodeLine = null;
    if (structuredContentLine.containsKey("rejectInterbankCodeLine") && structuredContentLine.get("rejectInterbankCodeLine") != null) {
        rejectInterbankCodeLine = interbankCodeLineRepository.find(((InterbankCodeLine) structuredContentLine.get("rejectInterbankCodeLine")).getId());
    }
    BankStatementLineAFB120 bankStatementLineAFB120 = bankStatementLineAFB120Service.createBankStatementLine(findBankStatement(), sequence, bankDetails, (BigDecimal) structuredContentLine.get("debit"), (BigDecimal) structuredContentLine.get("credit"), currency, description, (LocalDate) structuredContentLine.get("operationDate"), (LocalDate) structuredContentLine.get("valueDate"), operationInterbankCodeLine, rejectInterbankCodeLine, (String) structuredContentLine.get("origin"), (String) structuredContentLine.get("reference"), (int) structuredContentLine.get("lineType"), (String) structuredContentLine.get("unavailabilityIndexSelect"), (String) structuredContentLine.get("commissionExemptionIndexSelect"));
    return bankStatementLineAFB120Repository.save(bankStatementLineAFB120);
}
Also used : BankDetails(com.axelor.apps.base.db.BankDetails) InterbankCodeLine(com.axelor.apps.account.db.InterbankCodeLine) Currency(com.axelor.apps.base.db.Currency) BankStatementLineAFB120(com.axelor.apps.bankpayment.db.BankStatementLineAFB120) Transactional(com.google.inject.persist.Transactional)

Example 13 with Currency

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

the class PurchaseOrderLineServiceImpl method getPurchaseMaxPrice.

@Override
public BigDecimal getPurchaseMaxPrice(PurchaseOrder purchaseOrder, PurchaseOrderLine purchaseOrderLine) throws AxelorException {
    try {
        Product product = purchaseOrderLine.getProduct();
        if (product == null || !((Boolean) productCompanyService.get(product, "sellable", purchaseOrder.getCompany()))) {
            return BigDecimal.ZERO;
        }
        TaxLine saleTaxLine = accountManagementService.getTaxLine(purchaseOrder.getOrderDate(), purchaseOrderLine.getProduct(), purchaseOrder.getCompany(), purchaseOrder.getSupplierPartner().getFiscalPosition(), false);
        BigDecimal price;
        if (purchaseOrder.getInAti() != (Boolean) productCompanyService.get(product, "inAti", purchaseOrder.getCompany())) {
            price = this.convertUnitPrice((Boolean) productCompanyService.get(product, "inAti", purchaseOrder.getCompany()), saleTaxLine, ((BigDecimal) productCompanyService.get(product, "salePrice", purchaseOrder.getCompany())).divide(product.getManagPriceCoef().signum() == 0 ? BigDecimal.ONE : product.getManagPriceCoef(), appBaseService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP));
        } else {
            price = ((BigDecimal) productCompanyService.get(product, "salePrice", purchaseOrder.getCompany())).divide(product.getManagPriceCoef().signum() == 0 ? BigDecimal.ONE : product.getManagPriceCoef(), appBaseService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
        }
        return currencyService.getAmountCurrencyConvertedAtDate((Currency) productCompanyService.get(product, "saleCurrency", purchaseOrder.getCompany()), purchaseOrder.getCurrency(), price, purchaseOrder.getOrderDate()).setScale(appBaseService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
    } catch (Exception e) {
        return BigDecimal.ZERO;
    }
}
Also used : Currency(com.axelor.apps.base.db.Currency) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 14 with Currency

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

the class BankOrderLineService method computeCompanyCurrencyAmount.

public BigDecimal computeCompanyCurrencyAmount(BankOrder bankOrder, BankOrderLine bankOrderLine) throws AxelorException {
    LocalDate bankOrderDate = bankOrder.getBankOrderDate();
    if (bankOrder.getIsMultiDate()) {
        bankOrderDate = bankOrderLine.getBankOrderDate();
    }
    Currency bankOrderCurrency = bankOrder.getBankOrderCurrency();
    if (bankOrder.getIsMultiCurrency()) {
        bankOrderCurrency = bankOrderLine.getBankOrderCurrency();
    }
    return currencyService.getAmountCurrencyConvertedAtDate(bankOrderCurrency, bankOrder.getCompanyCurrency(), bankOrderLine.getBankOrderAmount(), bankOrderDate).setScale(2, // TODO Manage the number of decimal for currency
    RoundingMode.HALF_UP);
}
Also used : Currency(com.axelor.apps.base.db.Currency) LocalDate(java.time.LocalDate)

Example 15 with Currency

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

the class InvoiceController method mergeInvoice.

// Generate single invoice from several
@SuppressWarnings({ "rawtypes", "unchecked" })
public void mergeInvoice(ActionRequest request, ActionResponse response) {
    List<Invoice> invoiceList = new ArrayList<Invoice>();
    List<Long> invoiceIdList = new ArrayList<Long>();
    boolean fromPopup = false;
    if (request.getContext().get("invoiceToMerge") != null) {
        if (request.getContext().get("invoiceToMerge") instanceof List) {
            // No confirmation popup, invoices are content in a parameter list
            List<Map> invoiceMap = (List<Map>) request.getContext().get("invoiceToMerge");
            for (Map map : invoiceMap) {
                invoiceIdList.add(new Long((Integer) map.get("id")));
            }
        } else {
            // After confirmation popup, invoice's id are in a string separated by ","
            String invoiceIdListStr = (String) request.getContext().get("invoiceToMerge");
            for (String invoiceId : invoiceIdListStr.split(",")) {
                invoiceIdList.add(new Long(invoiceId));
            }
            fromPopup = true;
        }
    }
    // Check if company, currency and partner are the same for all selected invoices
    Company commonCompany = null;
    Currency commonCurrency = null;
    Partner commonPartner = null;
    PaymentCondition commonPaymentCondition = null;
    // Useful to determine if a difference exists between payment conditions of all invoices
    boolean existPaymentConditionDiff = false;
    Partner commonContactPartner = null;
    // Useful to determine if a difference exists between contact partners of all purchase orders
    boolean existContactPartnerDiff = false;
    PriceList commonPriceList = null;
    // Useful to determine if a difference exists between price lists of all purchase orders
    boolean existPriceListDiff = false;
    PaymentMode commonPaymentMode = null;
    // Useful to determine if a difference exists between stock locations of all purchase orders
    boolean existPaymentModeDiff = false;
    SaleOrder commonSaleOrder = null;
    // Useful to check if all sale orders are null (since this field is not required)
    boolean saleOrderIsNull = false;
    Invoice invoiceTemp;
    int count = 1;
    for (Long invoiceId : invoiceIdList) {
        invoiceTemp = JPA.em().find(Invoice.class, invoiceId);
        invoiceList.add(invoiceTemp);
        if (count == 1) {
            commonCompany = invoiceTemp.getCompany();
            commonCurrency = invoiceTemp.getCurrency();
            commonPartner = invoiceTemp.getPartner();
            commonPaymentCondition = invoiceTemp.getPaymentCondition();
            commonContactPartner = invoiceTemp.getContactPartner();
            commonPriceList = invoiceTemp.getPriceList();
            commonPaymentMode = invoiceTemp.getPaymentMode();
            commonSaleOrder = invoiceTemp.getSaleOrder();
            if (commonSaleOrder == null) {
                saleOrderIsNull = true;
            }
        } else {
            if (commonCompany != null && !commonCompany.equals(invoiceTemp.getCompany())) {
                commonCompany = null;
            }
            if (commonCurrency != null && !commonCurrency.equals(invoiceTemp.getCurrency())) {
                commonCurrency = null;
            }
            if (commonPartner != null && !commonPartner.equals(invoiceTemp.getPartner())) {
                commonPartner = null;
            }
            if (commonPaymentCondition != null && !commonPaymentCondition.equals(invoiceTemp.getPaymentCondition())) {
                commonPaymentCondition = null;
                existPaymentConditionDiff = true;
            }
            if (commonContactPartner != null && !commonContactPartner.equals(invoiceTemp.getContactPartner())) {
                commonContactPartner = null;
                existContactPartnerDiff = true;
            }
            if (commonPriceList != null && !commonPriceList.equals(invoiceTemp.getPriceList())) {
                commonPriceList = null;
                existPriceListDiff = true;
            }
            if (commonPaymentMode != null && !commonPaymentMode.equals(invoiceTemp.getPaymentMode())) {
                commonPaymentMode = null;
                existPaymentModeDiff = true;
            }
            if (commonSaleOrder != null && !commonSaleOrder.equals(invoiceTemp.getSaleOrder())) {
                commonSaleOrder = null;
            }
            if (invoiceTemp.getSaleOrder() != null) {
                saleOrderIsNull = false;
            }
        }
        count++;
    }
    StringBuilder fieldErrors = new StringBuilder();
    if (commonCurrency == null) {
        fieldErrors.append(I18n.get(IExceptionMessage.INVOICE_MERGE_ERROR_CURRENCY));
    }
    if (commonCompany == null) {
        if (fieldErrors.length() > 0) {
            fieldErrors.append("<br/>");
        }
        fieldErrors.append(I18n.get(IExceptionMessage.INVOICE_MERGE_ERROR_COMPANY));
    }
    if (commonPartner == null) {
        if (fieldErrors.length() > 0) {
            fieldErrors.append("<br/>");
        }
        fieldErrors.append(I18n.get(IExceptionMessage.INVOICE_MERGE_ERROR_PARTNER));
    }
    if (commonSaleOrder == null && saleOrderIsNull == false) {
        if (fieldErrors.length() > 0) {
            fieldErrors.append("<br/>");
        }
        fieldErrors.append(I18n.get(IExceptionMessage.INVOICE_MERGE_ERROR_SALEORDER));
    }
    if (fieldErrors.length() > 0) {
        response.setFlash(fieldErrors.toString());
        return;
    }
    // content in parameters
    if (request.getContext().get("contactPartner") != null) {
        commonContactPartner = JPA.em().find(Partner.class, new Long((Integer) ((Map) request.getContext().get("contactPartner")).get("id")));
    }
    if (request.getContext().get("priceList") != null) {
        commonPriceList = JPA.em().find(PriceList.class, new Long((Integer) ((Map) request.getContext().get("priceList")).get("id")));
    }
    if (request.getContext().get("paymentMode") != null) {
        commonPaymentMode = JPA.em().find(PaymentMode.class, new Long((Integer) ((Map) request.getContext().get("paymentMode")).get("id")));
    }
    if (request.getContext().get("paymentCondition") != null) {
        commonPaymentCondition = JPA.em().find(PaymentCondition.class, new Long((Integer) ((Map) request.getContext().get("paymentCondition")).get("id")));
    }
    if (!fromPopup && (existPaymentConditionDiff || existContactPartnerDiff || existPriceListDiff || existPaymentModeDiff)) {
        // Need to display intermediate screen to select some values
        ActionViewBuilder confirmView = ActionView.define("Confirm merge invoice").model(Wizard.class.getName()).add("form", "customer-invoices-merge-confirm-form").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true");
        if (existContactPartnerDiff) {
            confirmView.context("contextContactPartnerToCheck", "true");
            confirmView.context("contextPartnerId", commonPartner.getId().toString());
        }
        if (existPriceListDiff) {
            confirmView.context("contextPriceListToCheck", "true");
        }
        if (existPaymentModeDiff) {
            confirmView.context("contextPaymentModeToCheck", "true");
        }
        if (existPaymentConditionDiff) {
            confirmView.context("contextPaymentConditionToCheck", "true");
        }
        confirmView.context("invoiceToMerge", Joiner.on(",").join(invoiceIdList));
        response.setView(confirmView.map());
        return;
    }
    try {
        Invoice invoice = Beans.get(SaleOrderInvoiceService.class).mergeInvoice(invoiceList, commonCompany, commonCurrency, commonPartner, commonContactPartner, commonPriceList, commonPaymentMode, commonPaymentCondition, commonSaleOrder);
        if (invoice != null) {
            // Open the generated invoice in a new tab
            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(invoice.getId())).map());
            response.setCanClose(true);
        }
    } catch (Exception e) {
        response.setFlash(e.getLocalizedMessage());
    }
}
Also used : PaymentCondition(com.axelor.apps.account.db.PaymentCondition) Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) SaleOrderInvoiceService(com.axelor.apps.supplychain.service.SaleOrderInvoiceService) ArrayList(java.util.ArrayList) SaleOrder(com.axelor.apps.sale.db.SaleOrder) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) AxelorException(com.axelor.exception.AxelorException) Currency(com.axelor.apps.base.db.Currency) ArrayList(java.util.ArrayList) List(java.util.List) PriceList(com.axelor.apps.base.db.PriceList) Map(java.util.Map) Partner(com.axelor.apps.base.db.Partner) PriceList(com.axelor.apps.base.db.PriceList) Wizard(com.axelor.apps.base.db.Wizard) PaymentMode(com.axelor.apps.account.db.PaymentMode)

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