use of com.axelor.apps.account.db.TaxLine in project axelor-open-suite by axelor.
the class PurchaseOrderLineController method updatePrice.
/**
* Update the ex. tax unit price of an invoice line from its in. tax unit price.
*
* @param request
* @param response
*/
public void updatePrice(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
try {
BigDecimal inTaxPrice = purchaseOrderLine.getInTaxPrice();
TaxLine taxLine = purchaseOrderLine.getTaxLine();
response.setValue("price", Beans.get(PurchaseOrderLineService.class).convertUnitPrice(true, taxLine, inTaxPrice));
} catch (Exception e) {
response.setFlash(e.getMessage());
}
}
use of com.axelor.apps.account.db.TaxLine 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;
}
}
use of com.axelor.apps.account.db.TaxLine in project axelor-open-suite by axelor.
the class PurchaseOrderLineServiceImpl method fill.
public PurchaseOrderLine fill(PurchaseOrderLine line, PurchaseOrder purchaseOrder) throws AxelorException {
Preconditions.checkNotNull(line, I18n.get("The line cannot be null."));
Preconditions.checkNotNull(purchaseOrder, I18n.get("You need a purchase order associated to line."));
Partner supplierPartner = purchaseOrder.getSupplierPartner();
Product product = line.getProduct();
String[] productSupplierInfos = getProductSupplierInfos(purchaseOrder, line);
if (!line.getEnableFreezeFields()) {
line.setProductName(productSupplierInfos[0]);
line.setQty(getQty(purchaseOrder, line));
}
line.setProductCode(productSupplierInfos[1]);
line.setUnit(getPurchaseUnit(line));
if (appPurchaseService.getAppPurchase().getIsEnabledProductDescriptionCopy()) {
line.setDescription(product.getDescription());
}
TaxLine taxLine = getTaxLine(purchaseOrder, line);
line.setTaxLine(taxLine);
BigDecimal price = getExTaxUnitPrice(purchaseOrder, line, taxLine);
BigDecimal inTaxPrice = getInTaxUnitPrice(purchaseOrder, line, taxLine);
if (price == null || inTaxPrice == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.PURCHASE_ORDER_LINE_NO_SUPPLIER_CATALOG));
}
TaxEquiv taxEquiv = accountManagementService.getProductTaxEquiv(product, purchaseOrder.getCompany(), supplierPartner.getFiscalPosition(), true);
line.setTaxEquiv(taxEquiv);
Map<String, Object> discounts = getDiscountsFromPriceLists(purchaseOrder, line, purchaseOrder.getInAti() ? inTaxPrice : price);
if (discounts != null) {
if (discounts.get("price") != null) {
BigDecimal discountPrice = (BigDecimal) discounts.get("price");
if (product.getInAti()) {
inTaxPrice = discountPrice;
price = this.convertUnitPrice(true, line.getTaxLine(), discountPrice);
} else {
price = discountPrice;
inTaxPrice = this.convertUnitPrice(false, line.getTaxLine(), discountPrice);
}
}
if (product.getInAti() != purchaseOrder.getInAti() && (Integer) discounts.get("discountTypeSelect") != PriceListLineRepository.AMOUNT_TYPE_PERCENT) {
line.setDiscountAmount(this.convertUnitPrice(product.getInAti(), line.getTaxLine(), (BigDecimal) discounts.get("discountAmount")));
} else {
line.setDiscountAmount((BigDecimal) discounts.get("discountAmount"));
}
line.setDiscountTypeSelect((Integer) discounts.get("discountTypeSelect"));
}
if (!line.getEnableFreezeFields()) {
line.setPrice(price);
}
line.setInTaxPrice(inTaxPrice);
line.setMaxPurchasePrice(getPurchaseMaxPrice(purchaseOrder, line));
return line;
}
use of com.axelor.apps.account.db.TaxLine in project axelor-open-suite by axelor.
the class AccountingCutOffServiceImpl method generateTaxMoveLine.
protected void generateTaxMoveLine(Move move, MoveLine productMoveLine, String origin, boolean isPurchase, boolean isFixedAssets, String moveDescription) throws AxelorException {
TaxLine taxLine = productMoveLine.getTaxLine();
Tax tax = taxLine.getTax();
Account taxAccount = taxAccountService.getAccount(tax, move.getCompany(), isPurchase, isFixedAssets);
BigDecimal currencyTaxAmount = InvoiceLineManagement.computeAmount(productMoveLine.getCurrencyAmount(), taxLine.getValue());
MoveLine taxMoveLine = moveLineService.createMoveLine(move, move.getPartner(), taxAccount, currencyTaxAmount, productMoveLine.getDebit().compareTo(BigDecimal.ZERO) == 1, productMoveLine.getOriginDate(), ++counter, origin, moveDescription);
taxMoveLine.setDate(move.getDate());
taxMoveLine.setDueDate(move.getDate());
move.addMoveLineListItem(taxMoveLine);
}
use of com.axelor.apps.account.db.TaxLine in project axelor-open-suite by axelor.
the class SaleOrderInvoiceServiceImpl method createInvoiceLinesFromTax.
@Override
public List<InvoiceLine> createInvoiceLinesFromTax(Invoice invoice, List<SaleOrderLineTax> taxLineList, Product invoicingProduct, BigDecimal percentToInvoice) throws AxelorException {
List<InvoiceLine> createdInvoiceLineList = new ArrayList<>();
if (taxLineList != null) {
for (SaleOrderLineTax saleOrderLineTax : taxLineList) {
BigDecimal lineAmountToInvoice = percentToInvoice.multiply(saleOrderLineTax.getExTaxBase()).divide(new BigDecimal("100"), 4, BigDecimal.ROUND_HALF_UP);
TaxLine taxLine = saleOrderLineTax.getTaxLine();
BigDecimal lineAmountToInvoiceInclTax = (taxLine != null) ? lineAmountToInvoice.add(lineAmountToInvoice.multiply(taxLine.getValue())) : lineAmountToInvoice;
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGenerator(invoice, invoicingProduct, invoicingProduct.getName(), lineAmountToInvoice, lineAmountToInvoiceInclTax, invoice.getInAti() ? lineAmountToInvoiceInclTax : lineAmountToInvoice, invoicingProduct.getDescription(), BigDecimal.ONE, invoicingProduct.getUnit(), taxLine, InvoiceLineGenerator.DEFAULT_SEQUENCE, BigDecimal.ZERO, PriceListLineRepository.AMOUNT_TYPE_NONE, lineAmountToInvoice, null, false) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
List<InvoiceLine> invoiceLines = new ArrayList<>();
invoiceLines.add(invoiceLine);
return invoiceLines;
}
};
List<InvoiceLine> invoiceOneLineList = invoiceLineGenerator.creates();
// link to the created invoice line the first line of the sale order.
for (InvoiceLine invoiceLine : invoiceOneLineList) {
SaleOrderLine saleOrderLine = saleOrderLineTax.getSaleOrder().getSaleOrderLineList().get(0);
invoiceLine.setSaleOrderLine(saleOrderLine);
}
createdInvoiceLineList.addAll(invoiceOneLineList);
}
}
return createdInvoiceLineList;
}
Aggregations