Search in sources :

Example 26 with TaxLine

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

the class SaleOrderStockServiceImpl method createStockMoveLine.

@Override
public StockMoveLine createStockMoveLine(StockMove stockMove, SaleOrderLine saleOrderLine, BigDecimal qty) throws AxelorException {
    if (this.isStockMoveProduct(saleOrderLine)) {
        Unit unit = saleOrderLine.getProduct().getUnit();
        BigDecimal priceDiscounted = saleOrderLine.getPriceDiscounted();
        BigDecimal requestedReservedQty = saleOrderLine.getRequestedReservedQty().subtract(saleOrderLine.getDeliveredQty());
        BigDecimal companyUnitPriceUntaxed = (BigDecimal) productCompanyService.get(saleOrderLine.getProduct(), "costPrice", saleOrderLine.getSaleOrder() != null ? saleOrderLine.getSaleOrder().getCompany() : null);
        if (unit != null && !unit.equals(saleOrderLine.getUnit())) {
            qty = unitConversionService.convert(saleOrderLine.getUnit(), unit, qty, qty.scale(), saleOrderLine.getProduct());
            priceDiscounted = unitConversionService.convert(unit, saleOrderLine.getUnit(), priceDiscounted, appBaseService.getNbDecimalDigitForUnitPrice(), saleOrderLine.getProduct());
            requestedReservedQty = unitConversionService.convert(saleOrderLine.getUnit(), unit, requestedReservedQty, requestedReservedQty.scale(), saleOrderLine.getProduct());
        }
        BigDecimal taxRate = BigDecimal.ZERO;
        TaxLine taxLine = saleOrderLine.getTaxLine();
        if (taxLine != null) {
            taxRate = taxLine.getValue();
        }
        if (saleOrderLine.getQty().signum() != 0) {
            companyUnitPriceUntaxed = saleOrderLine.getCompanyExTaxTotal().divide(saleOrderLine.getQty(), Beans.get(AppBaseService.class).getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
        }
        StockMoveLine stockMoveLine = stockMoveLineSupplychainService.createStockMoveLine(saleOrderLine.getProduct(), saleOrderLine.getProductName(), saleOrderLine.getDescription(), qty, requestedReservedQty, priceDiscounted, companyUnitPriceUntaxed, null, unit, stockMove, StockMoveLineService.TYPE_SALES, saleOrderLine.getSaleOrder().getInAti(), taxRate, saleOrderLine, null);
        if (saleOrderLine.getDeliveryState() == 0) {
            saleOrderLine.setDeliveryState(SaleOrderLineRepository.DELIVERY_STATE_NOT_DELIVERED);
        }
        return stockMoveLine;
    }
    return null;
}
Also used : AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 27 with TaxLine

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

the class InvoiceLineServiceImpl method fillPriceAndAccount.

@Override
public Map<String, Object> fillPriceAndAccount(Invoice invoice, InvoiceLine invoiceLine, boolean isPurchase) throws AxelorException {
    Map<String, Object> productInformation = resetProductInformation(invoice);
    Product product = invoiceLine.getProduct();
    TaxLine taxLine = null;
    Company company = invoice.getCompany();
    FiscalPosition fiscalPosition = invoice.getPartner().getFiscalPosition();
    try {
        taxLine = this.getTaxLine(invoice, invoiceLine, isPurchase);
        invoiceLine.setTaxLine(taxLine);
        productInformation.put("taxLine", taxLine);
        productInformation.put("taxRate", taxLine.getValue());
        productInformation.put("taxCode", taxLine.getTax().getCode());
        TaxEquiv taxEquiv = accountManagementAccountService.getProductTaxEquiv(product, company, fiscalPosition, isPurchase);
        productInformation.put("taxEquiv", taxEquiv);
        Account account = accountManagementAccountService.getProductAccount(product, company, fiscalPosition, isPurchase, invoiceLine.getFixedAssets());
        productInformation.put("account", account);
    } catch (AxelorException e) {
        productInformation.put("error", e.getMessage());
    }
    BigDecimal price = this.getExTaxUnitPrice(invoice, invoiceLine, taxLine, isPurchase);
    BigDecimal inTaxPrice = this.getInTaxUnitPrice(invoice, invoiceLine, taxLine, isPurchase);
    productInformation.put("price", price);
    productInformation.put("inTaxPrice", inTaxPrice);
    productInformation.putAll(this.getDiscount(invoice, invoiceLine, product.getInAti() ? inTaxPrice : price));
    productInformation.put("productName", invoiceLine.getProduct().getName());
    return productInformation;
}
Also used : Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) FiscalPosition(com.axelor.apps.account.db.FiscalPosition) Product(com.axelor.apps.base.db.Product) TaxEquiv(com.axelor.apps.account.db.TaxEquiv) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 28 with TaxLine

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

the class MoveLineServiceImpl method generateTaxPaymentMoveLineList.

@Override
@Transactional(rollbackOn = { Exception.class })
public MoveLine generateTaxPaymentMoveLineList(MoveLine customerMoveLine, Invoice invoice, Reconcile reconcile) throws AxelorException {
    BigDecimal paymentAmount = reconcile.getAmount();
    BigDecimal invoiceTotalAmount = invoice.getCompanyInTaxTotal();
    for (InvoiceLineTax invoiceLineTax : invoice.getInvoiceLineTaxList()) {
        TaxLine taxLine = invoiceLineTax.getTaxLine();
        BigDecimal vatRate = taxLine.getValue();
        BigDecimal baseAmount = invoiceLineTax.getCompanyExTaxBase();
        BigDecimal detailPaymentAmount = baseAmount.multiply(paymentAmount).divide(invoiceTotalAmount, 6, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP);
        TaxPaymentMoveLine taxPaymentMoveLine = new TaxPaymentMoveLine(customerMoveLine, taxLine, reconcile, vatRate, detailPaymentAmount, Beans.get(AppBaseService.class).getTodayDate(reconcile.getCompany()));
        taxPaymentMoveLine = taxPaymentMoveLineService.computeTaxAmount(taxPaymentMoveLine);
        customerMoveLine.addTaxPaymentMoveLineListItem(taxPaymentMoveLine);
    }
    this.computeTaxAmount(customerMoveLine);
    return Beans.get(MoveLineRepository.class).save(customerMoveLine);
}
Also used : TaxPaymentMoveLine(com.axelor.apps.account.db.TaxPaymentMoveLine) AnalyticMoveLineRepository(com.axelor.apps.account.db.repo.AnalyticMoveLineRepository) MoveLineRepository(com.axelor.apps.account.db.repo.MoveLineRepository) InvoiceLineTax(com.axelor.apps.account.db.InvoiceLineTax) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine) Transactional(com.google.inject.persist.Transactional)

Aggregations

TaxLine (com.axelor.apps.account.db.TaxLine)28 BigDecimal (java.math.BigDecimal)25 AxelorException (com.axelor.exception.AxelorException)9 Account (com.axelor.apps.account.db.Account)8 MoveLine (com.axelor.apps.account.db.MoveLine)7 TaxEquiv (com.axelor.apps.account.db.TaxEquiv)7 ArrayList (java.util.ArrayList)7 Context (com.axelor.rpc.Context)6 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)5 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)5 Partner (com.axelor.apps.base.db.Partner)5 Product (com.axelor.apps.base.db.Product)5 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)5 Tax (com.axelor.apps.account.db.Tax)4 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)4 Transactional (com.google.inject.persist.Transactional)4 HashMap (java.util.HashMap)4 FiscalPosition (com.axelor.apps.account.db.FiscalPosition)3 TaxPaymentMoveLine (com.axelor.apps.account.db.TaxPaymentMoveLine)3 Company (com.axelor.apps.base.db.Company)3