use of com.axelor.apps.account.db.TaxEquiv in project axelor-open-suite by axelor.
the class TaxInvoiceLine method createInvoiceLineTaxes.
protected void createInvoiceLineTaxes(InvoiceLine invoiceLine, Map<TaxLine, InvoiceLineTax> map) {
TaxLine taxLine = invoiceLine.getTaxLine();
TaxEquiv taxEquiv = invoiceLine.getTaxEquiv();
TaxLine taxLineRC = (taxEquiv != null && taxEquiv.getReverseCharge() && taxEquiv.getReverseChargeTax() != null) ? taxEquiv.getReverseChargeTax().getActiveTaxLine() : null;
if (taxLine != null) {
createOrUpdateInvoiceLineTax(invoiceLine, taxLine, map);
}
if (taxLineRC != null) {
createOrUpdateInvoiceLineTaxRc(invoiceLine, taxLineRC, taxEquiv, map);
}
}
use of com.axelor.apps.account.db.TaxEquiv in project axelor-open-suite by axelor.
the class IntercoServiceImpl method createIntercoInvoiceLine.
protected InvoiceLine createIntercoInvoiceLine(InvoiceLine invoiceLine, boolean isPurchase) throws AxelorException {
AccountManagementAccountService accountManagementAccountService = Beans.get(AccountManagementAccountService.class);
InvoiceLineService invoiceLineService = Beans.get(InvoiceLineService.class);
Invoice intercoInvoice = invoiceLine.getInvoice();
Partner partner = intercoInvoice.getPartner();
if (intercoInvoice.getCompany() != null) {
Account account = accountManagementAccountService.getProductAccount(invoiceLine.getProduct(), intercoInvoice.getCompany(), partner.getFiscalPosition(), isPurchase, false);
invoiceLine.setAccount(account);
TaxLine taxLine = invoiceLineService.getTaxLine(intercoInvoice, invoiceLine, isPurchase);
invoiceLine.setTaxLine(taxLine);
invoiceLine.setTaxRate(taxLine.getValue());
invoiceLine.setTaxCode(taxLine.getTax().getCode());
TaxEquiv taxEquiv = accountManagementAccountService.getProductTaxEquiv(invoiceLine.getProduct(), intercoInvoice.getCompany(), intercoInvoice.getPartner().getFiscalPosition(), isPurchase);
invoiceLine.setTaxEquiv(taxEquiv);
invoiceLine.setCompanyExTaxTotal(invoiceLineService.getCompanyExTaxTotal(invoiceLine.getExTaxTotal(), intercoInvoice));
invoiceLine.setCompanyInTaxTotal(invoiceLineService.getCompanyExTaxTotal(invoiceLine.getInTaxTotal(), intercoInvoice));
if (invoiceLine.getAnalyticDistributionTemplate() != null) {
invoiceLine.setAnalyticDistributionTemplate(accountManagementAccountService.getAnalyticDistributionTemplate(invoiceLine.getProduct(), intercoInvoice.getCompany()));
List<AnalyticMoveLine> analyticMoveLineList = invoiceLineService.createAnalyticDistributionWithTemplate(invoiceLine);
analyticMoveLineList.forEach(analyticMoveLine -> analyticMoveLine.setInvoiceLine(invoiceLine));
invoiceLine.setAnalyticMoveLineList(analyticMoveLineList);
}
}
return invoiceLine;
}
use of com.axelor.apps.account.db.TaxEquiv 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.TaxEquiv in project axelor-open-suite by axelor.
the class SaleOrderLineServiceImpl method fillTaxInformation.
protected void fillTaxInformation(SaleOrderLine saleOrderLine, SaleOrder saleOrder) throws AxelorException {
if (saleOrder.getClientPartner() != null) {
TaxLine taxLine = this.getTaxLine(saleOrder, saleOrderLine);
saleOrderLine.setTaxLine(taxLine);
FiscalPosition fiscalPosition = saleOrder.getClientPartner().getFiscalPosition();
TaxEquiv taxEquiv = accountManagementService.getProductTaxEquiv(saleOrderLine.getProduct(), saleOrder.getCompany(), fiscalPosition, false);
saleOrderLine.setTaxEquiv(taxEquiv);
} else {
saleOrderLine.setTaxLine(null);
saleOrderLine.setTaxEquiv(null);
}
}
use of com.axelor.apps.account.db.TaxEquiv in project axelor-open-suite by axelor.
the class SaleOrderLineTaxService method createsSaleOrderLineTax.
/**
* Créer les lignes de TVA du devis. La création des lignes de TVA se basent sur les lignes de
* devis ainsi que les sous-lignes de devis de celles-ci. Si une ligne de devis comporte des
* sous-lignes de devis, alors on se base uniquement sur celles-ci.
*
* @param invoice La facture.
* @param invoiceLines Les lignes de facture.
* @param invoiceLineTaxes Les lignes des taxes de la facture.
* @return La liste des lignes de taxe de la facture.
*/
public List<SaleOrderLineTax> createsSaleOrderLineTax(SaleOrder saleOrder, List<SaleOrderLine> saleOrderLineList) {
List<SaleOrderLineTax> saleOrderLineTaxList = new ArrayList<SaleOrderLineTax>();
Map<TaxLine, SaleOrderLineTax> map = new HashMap<TaxLine, SaleOrderLineTax>();
Set<String> specificNotes = new HashSet<String>();
boolean customerSpecificNote = false;
if (saleOrder.getClientPartner().getFiscalPosition() != null) {
customerSpecificNote = saleOrder.getClientPartner().getFiscalPosition().getCustomerSpecificNote();
}
if (saleOrderLineList != null && !saleOrderLineList.isEmpty()) {
LOG.debug("Création des lignes de tva pour les lignes de factures.");
for (SaleOrderLine saleOrderLine : saleOrderLineList) {
TaxLine taxLine = saleOrderLine.getTaxLine();
if (taxLine != null) {
LOG.debug("Tax {}", taxLine);
if (map.containsKey(taxLine)) {
SaleOrderLineTax saleOrderLineTax = map.get(taxLine);
saleOrderLineTax.setExTaxBase(saleOrderLineTax.getExTaxBase().add(saleOrderLine.getExTaxTotal()));
} else {
SaleOrderLineTax saleOrderLineTax = new SaleOrderLineTax();
saleOrderLineTax.setSaleOrder(saleOrder);
saleOrderLineTax.setExTaxBase(saleOrderLine.getExTaxTotal());
saleOrderLineTax.setTaxLine(taxLine);
map.put(taxLine, saleOrderLineTax);
}
}
if (!customerSpecificNote) {
TaxEquiv taxEquiv = saleOrderLine.getTaxEquiv();
if (taxEquiv != null && taxEquiv.getSpecificNote() != null) {
specificNotes.add(taxEquiv.getSpecificNote());
}
}
}
}
for (SaleOrderLineTax saleOrderLineTax : map.values()) {
// Dans la devise de la facture
BigDecimal exTaxBase = saleOrderLineTax.getExTaxBase();
BigDecimal taxTotal = BigDecimal.ZERO;
if (saleOrderLineTax.getTaxLine() != null) {
taxTotal = saleOrderToolService.computeAmount(exTaxBase, saleOrderLineTax.getTaxLine().getValue());
saleOrderLineTax.setTaxTotal(taxTotal);
}
saleOrderLineTax.setInTaxTotal(exTaxBase.add(taxTotal));
saleOrderLineTaxList.add(saleOrderLineTax);
LOG.debug("Ligne de TVA : Total TVA => {}, Total HT => {}", new Object[] { saleOrderLineTax.getTaxTotal(), saleOrderLineTax.getInTaxTotal() });
}
if (!customerSpecificNote) {
saleOrder.setSpecificNotes(Joiner.on('\n').join(specificNotes));
} else {
saleOrder.setSpecificNotes(saleOrder.getClientPartner().getSpecificTaxNote());
}
return saleOrderLineTaxList;
}
Aggregations