Search in sources :

Example 21 with Currency

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

the class AccountingCutOffServiceImpl method generateCutOffMove.

public Move generateCutOffMove(StockMove stockMove, List<StockMoveLine> sortedStockMoveLine, LocalDate moveDate, LocalDate originDate, boolean isPurchase, boolean recoveredTax, boolean ati, String moveDescription, boolean includeNotStockManagedProduct, boolean isReverse) throws AxelorException {
    if (moveDate == null || stockMove.getOriginTypeSelect() == null || stockMove.getOriginId() == null) {
        return null;
    }
    Company company = stockMove.getCompany();
    AccountConfig accountConfig = accountConfigSupplychainService.getAccountConfig(company);
    Partner partner = stockMove.getPartner();
    Account partnerAccount = null;
    Currency currency = null;
    if (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect()) && stockMove.getOriginId() != null) {
        SaleOrder saleOrder = saleOrderRepository.find(stockMove.getOriginId());
        currency = saleOrder.getCurrency();
        if (partner == null) {
            partner = saleOrder.getClientPartner();
        }
        partnerAccount = accountConfigSupplychainService.getForecastedInvCustAccount(accountConfig);
    }
    if (StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect()) && stockMove.getOriginId() != null) {
        PurchaseOrder purchaseOrder = purchaseOrderRepository.find(stockMove.getOriginId());
        currency = purchaseOrder.getCurrency();
        if (partner == null) {
            partner = purchaseOrder.getSupplierPartner();
        }
        partnerAccount = accountConfigSupplychainService.getForecastedInvSuppAccount(accountConfig);
    }
    String origin = stockMove.getStockMoveSeq();
    Move move = moveCreateService.createMove(accountConfigSupplychainService.getAutoMiscOpeJournal(accountConfig), company, currency, partner, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_CUT_OFF);
    counter = 0;
    this.generateMoveLines(move, stockMove.getStockMoveLineList(), origin, isPurchase, recoveredTax, ati, moveDescription, isReverse, originDate, includeNotStockManagedProduct);
    this.generatePartnerMoveLine(move, origin, partnerAccount, moveDescription, originDate);
    if (move.getMoveLineList() != null && !move.getMoveLineList().isEmpty()) {
        move.setStockMove(stockMove);
        moveValidateService.validate(move);
    } else {
        moveRepository.remove(move);
        return null;
    }
    return move;
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) StockMove(com.axelor.apps.stock.db.StockMove) Currency(com.axelor.apps.base.db.Currency) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Partner(com.axelor.apps.base.db.Partner) AccountConfig(com.axelor.apps.account.db.AccountConfig)

Example 22 with Currency

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

the class MoveLineController method computeCurrentRate.

public void computeCurrentRate(ActionRequest request, ActionResponse response) {
    try {
        Context parentContext = request.getContext().getParent();
        BigDecimal currencyRate = BigDecimal.ONE;
        if (parentContext != null && Move.class.equals(parentContext.getContextClass())) {
            Move move = parentContext.asType(Move.class);
            Currency currency = move.getCurrency();
            Currency companyCurrency = move.getCompanyCurrency();
            if (currency != null && companyCurrency != null && !currency.equals(companyCurrency)) {
                currencyRate = Beans.get(CurrencyService.class).getCurrencyConversionRate(currency, companyCurrency);
            }
        }
        response.setValue("currencyRate", currencyRate);
    } catch (AxelorException e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) AxelorException(com.axelor.exception.AxelorException) Move(com.axelor.apps.account.db.Move) Currency(com.axelor.apps.base.db.Currency) BigDecimal(java.math.BigDecimal)

Example 23 with Currency

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

the class BankOrderCreateServiceHr method createBankOrder.

/**
 * Method to create a bank order for an expense
 *
 * @param expense An expense
 * @throws AxelorException
 */
public BankOrder createBankOrder(Expense expense, BankDetails bankDetails) throws AxelorException {
    Company company = expense.getCompany();
    Partner partner = expense.getUser().getPartner();
    PaymentMode paymentMode = expense.getPaymentMode();
    BigDecimal amount = expense.getInTaxTotal().subtract(expense.getAdvanceAmount()).subtract(expense.getWithdrawnCash()).subtract(expense.getPersonalExpenseAmount());
    Currency currency = company.getCurrency();
    LocalDate paymentDate = Beans.get(AppBaseService.class).getTodayDate(company);
    BankOrder bankOrder = super.createBankOrder(paymentMode, BankOrderRepository.PARTNER_TYPE_EMPLOYEE, paymentDate, company, bankDetails, currency, expense.getFullName(), expense.getFullName(), BankOrderRepository.TECHNICAL_ORIGIN_AUTOMATIC);
    bankOrder.addBankOrderLineListItem(bankOrderLineService.createBankOrderLine(paymentMode.getBankOrderFileFormat(), partner, amount, currency, paymentDate, expense.getExpenseSeq(), expense.getFullName(), expense));
    bankOrder = bankOrderRepo.save(bankOrder);
    return bankOrder;
}
Also used : Company(com.axelor.apps.base.db.Company) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) 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 24 with Currency

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

the class SaleOrderController method createSaleOrder.

@SuppressWarnings("unchecked")
public void createSaleOrder(ActionRequest request, ActionResponse response) throws AxelorException {
    SaleOrder origin = Beans.get(SaleOrderRepository.class).find(Long.parseLong(request.getContext().get("_idCopy").toString()));
    if (origin != null) {
        LinkedHashMap<String, Object> wizardCurrencyContext = (LinkedHashMap<String, Object>) request.getContext().get("_wizardCurrency");
        Integer wizardCurrencyId = (Integer) wizardCurrencyContext.get("id");
        Currency wizardCurrency = Beans.get(CurrencyRepository.class).find(Long.valueOf(wizardCurrencyId));
        PriceList wizardPriceList = null;
        if (request.getContext().get("_wizardPriceList") != null) {
            LinkedHashMap<String, Object> wizardPriceListContext = (LinkedHashMap<String, Object>) request.getContext().get("_wizardPriceList");
            Integer wizardPriceListId = (Integer) wizardPriceListContext.get("id");
            wizardPriceList = Beans.get(PriceListRepository.class).find(Long.valueOf(wizardPriceListId));
        }
        SaleOrder copy = Beans.get(SaleOrderCreateService.class).createSaleOrder(origin, wizardCurrency, wizardPriceList);
        response.setValues(Mapper.toMap(copy));
    }
}
Also used : SaleOrderCreateService(com.axelor.apps.sale.service.saleorder.SaleOrderCreateService) Currency(com.axelor.apps.base.db.Currency) CurrencyRepository(com.axelor.apps.base.db.repo.CurrencyRepository) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) SaleOrder(com.axelor.apps.sale.db.SaleOrder) PriceList(com.axelor.apps.base.db.PriceList) LinkedHashMap(java.util.LinkedHashMap)

Example 25 with Currency

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

the class SaleOrderLineServiceImpl method getUnitPrice.

/**
 * A function used to get the unit price of a sale order line, either in ati or wt
 *
 * @param saleOrder the sale order containing the sale order line
 * @param saleOrderLine
 * @param taxLine the tax applied to the unit price
 * @param resultInAti whether you want the result in ati or not
 * @return the unit price of the sale order line
 * @throws AxelorException
 */
private BigDecimal getUnitPrice(SaleOrder saleOrder, SaleOrderLine saleOrderLine, TaxLine taxLine, boolean resultInAti) throws AxelorException {
    Product product = saleOrderLine.getProduct();
    Boolean productInAti = (Boolean) productCompanyService.get(product, "inAti", saleOrder.getCompany());
    BigDecimal productSalePrice = (BigDecimal) productCompanyService.get(product, "salePrice", saleOrder.getCompany());
    BigDecimal price = (productInAti == resultInAti) ? productSalePrice : this.convertUnitPrice(productInAti, taxLine, productSalePrice);
    return currencyService.getAmountCurrencyConvertedAtDate((Currency) productCompanyService.get(product, "saleCurrency", saleOrder.getCompany()), saleOrder.getCurrency(), price, saleOrder.getCreationDate()).setScale(appSaleService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
}
Also used : Currency(com.axelor.apps.base.db.Currency) Product(com.axelor.apps.base.db.Product) ComplementaryProduct(com.axelor.apps.sale.db.ComplementaryProduct) BigDecimal(java.math.BigDecimal)

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