use of com.axelor.apps.account.db.TaxEquiv in project axelor-open-suite by axelor.
the class PurchaseOrderLineTaxService method createsPurchaseOrderLineTax.
/**
* Créer les lignes de TVA de la commande. La création des lignes de TVA se basent sur les lignes
* de commande.
*
* @param purchaseOrder La commande.
* @param purchaseOrderLineList Les lignes de commandes.
* @return La liste des lignes de TVA de la commande.
*/
public List<PurchaseOrderLineTax> createsPurchaseOrderLineTax(PurchaseOrder purchaseOrder, List<PurchaseOrderLine> purchaseOrderLineList) {
List<PurchaseOrderLineTax> purchaseOrderLineTaxList = new ArrayList<PurchaseOrderLineTax>();
Map<TaxLine, PurchaseOrderLineTax> map = new HashMap<TaxLine, PurchaseOrderLineTax>();
if (purchaseOrderLineList != null && !purchaseOrderLineList.isEmpty()) {
LOG.debug("Création des lignes de tva pour les lignes de commande.");
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
TaxLine taxLine = purchaseOrderLine.getTaxLine();
TaxEquiv taxEquiv = purchaseOrderLine.getTaxEquiv();
TaxLine taxLineRC = (taxEquiv != null && taxEquiv.getReverseCharge() && taxEquiv.getReverseChargeTax() != null) ? taxEquiv.getReverseChargeTax().getActiveTaxLine() : null;
if (taxLine != null) {
LOG.debug("TVA {}", taxLine);
if (map.containsKey(taxLine)) {
PurchaseOrderLineTax purchaseOrderLineVat = map.get(taxLine);
purchaseOrderLineVat.setExTaxBase(purchaseOrderLineVat.getExTaxBase().add(purchaseOrderLine.getExTaxTotal()));
purchaseOrderLineVat.setReverseCharged(false);
} else {
PurchaseOrderLineTax purchaseOrderLineTax = new PurchaseOrderLineTax();
purchaseOrderLineTax.setPurchaseOrder(purchaseOrder);
purchaseOrderLineTax.setExTaxBase(purchaseOrderLine.getExTaxTotal());
purchaseOrderLineTax.setReverseCharged(false);
purchaseOrderLineTax.setTaxLine(taxLine);
map.put(taxLine, purchaseOrderLineTax);
}
}
if (taxLineRC != null) {
LOG.debug("TVA {}", taxLineRC);
if (map.containsKey(taxLineRC)) {
PurchaseOrderLineTax purchaseOrderLineRC = map.get(taxEquiv.getReverseChargeTax().getActiveTaxLine());
purchaseOrderLineRC.setExTaxBase(purchaseOrderLineRC.getExTaxBase().add(purchaseOrderLine.getExTaxTotal()));
purchaseOrderLineRC.setReverseCharged(true);
} else {
PurchaseOrderLineTax purchaseOrderLineTaxRC = new PurchaseOrderLineTax();
purchaseOrderLineTaxRC.setPurchaseOrder(purchaseOrder);
purchaseOrderLineTaxRC.setExTaxBase(purchaseOrderLine.getExTaxTotal());
purchaseOrderLineTaxRC.setReverseCharged(true);
purchaseOrderLineTaxRC.setTaxLine(taxLineRC);
map.put(taxLineRC, purchaseOrderLineTaxRC);
}
}
}
}
for (PurchaseOrderLineTax purchaseOrderLineTax : map.values()) {
// Dans la devise de la commande
BigDecimal exTaxBase = (purchaseOrderLineTax.getReverseCharged()) ? purchaseOrderLineTax.getExTaxBase().negate() : purchaseOrderLineTax.getExTaxBase();
BigDecimal taxTotal = BigDecimal.ZERO;
if (purchaseOrderLineTax.getTaxLine() != null)
taxTotal = purchaseOrderToolService.computeAmount(exTaxBase, purchaseOrderLineTax.getTaxLine().getValue());
purchaseOrderLineTax.setTaxTotal(taxTotal);
purchaseOrderLineTax.setInTaxTotal(purchaseOrderLineTax.getExTaxBase().add(taxTotal));
purchaseOrderLineTaxList.add(purchaseOrderLineTax);
LOG.debug("Ligne de TVA : Total TVA => {}, Total HT => {}", new Object[] { purchaseOrderLineTax.getTaxTotal(), purchaseOrderLineTax.getInTaxTotal() });
}
return purchaseOrderLineTaxList;
}
use of com.axelor.apps.account.db.TaxEquiv 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;
}
use of com.axelor.apps.account.db.TaxEquiv in project axelor-open-suite by axelor.
the class InvoiceLineGenerator method createInvoiceLine.
/**
* @return
* @throws AxelorException
*/
protected InvoiceLine createInvoiceLine() throws AxelorException {
InvoiceLine invoiceLine = new InvoiceLine();
boolean isPurchase = InvoiceToolService.isPurchase(invoice);
Partner partner = invoice.getPartner();
Company company = invoice.getCompany();
invoiceLine.setInvoice(invoice);
invoiceLine.setProduct(product);
invoiceLine.setProductName(productName);
if (product != null) {
invoiceLine.setProductCode((String) productCompanyService.get(product, "code", company));
Account account = accountManagementService.getProductAccount(product, company, partner.getFiscalPosition(), isPurchase, invoiceLine.getFixedAssets());
invoiceLine.setAccount(account);
}
invoiceLine.setDescription(description);
invoiceLine.setPrice(price);
invoiceLine.setInTaxPrice(inTaxPrice);
invoiceLine.setPriceDiscounted(priceDiscounted);
invoiceLine.setQty(qty);
invoiceLine.setUnit(unit);
invoiceLine.setTypeSelect(typeSelect);
if (taxLine == null) {
this.determineTaxLine();
}
if (product != null) {
TaxEquiv taxEquiv = Beans.get(AccountManagementService.class).getProductTaxEquiv(product, company, partner.getFiscalPosition(), isPurchase);
invoiceLine.setTaxEquiv(taxEquiv);
}
invoiceLine.setTaxLine(taxLine);
if (taxLine != null) {
invoiceLine.setTaxRate(taxLine.getValue());
invoiceLine.setTaxCode(taxLine.getTax().getCode());
}
if ((exTaxTotal == null || inTaxTotal == null)) {
this.computeTotal();
}
invoiceLine.setExTaxTotal(exTaxTotal);
invoiceLine.setInTaxTotal(inTaxTotal);
this.computeCompanyTotal(invoiceLine);
invoiceLine.setSequence(sequence);
invoiceLine.setDiscountTypeSelect(discountTypeSelect);
invoiceLine.setDiscountAmount(discountAmount);
return invoiceLine;
}
Aggregations