use of com.axelor.apps.account.db.TaxLine in project axelor-open-suite by axelor.
the class SaleOrderLineController 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();
SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
try {
BigDecimal inTaxPrice = saleOrderLine.getInTaxPrice();
TaxLine taxLine = saleOrderLine.getTaxLine();
response.setValue("price", Beans.get(SaleOrderLineService.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 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.TaxLine 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;
}
use of com.axelor.apps.account.db.TaxLine in project axelor-open-suite by axelor.
the class ContractServiceImpl method generate.
public InvoiceLine generate(Invoice invoice, ContractLine line) throws AxelorException {
BigDecimal inTaxPriceComputed = invoiceLineService.convertUnitPrice(false, line.getTaxLine(), line.getPrice());
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGenerator(invoice, line.getProduct(), line.getProductName(), line.getPrice(), inTaxPriceComputed, invoice.getInAti() ? inTaxPriceComputed : line.getPrice(), line.getDescription(), line.getQty(), line.getUnit(), line.getTaxLine(), line.getSequence(), BigDecimal.ZERO, PriceListLineRepository.AMOUNT_TYPE_NONE, line.getExTaxTotal(), line.getInTaxTotal(), false) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
List<InvoiceLine> invoiceLines = new ArrayList<>();
invoiceLines.add(invoiceLine);
return invoiceLines;
}
};
InvoiceLine invoiceLine = invoiceLineGenerator.creates().get(0);
FiscalPositionAccountService fiscalPositionAccountService = Beans.get(FiscalPositionAccountService.class);
FiscalPosition fiscalPosition = line.getFiscalPosition();
Account currentAccount = invoiceLine.getAccount();
Account replacedAccount = fiscalPositionAccountService.getAccount(fiscalPosition, currentAccount);
boolean isPurchase = Beans.get(InvoiceService.class).getPurchaseTypeOrSaleType(invoice) == PriceListRepository.TYPE_PURCHASE;
TaxLine taxLine = Beans.get(AccountManagementService.class).getTaxLine(appBaseService.getTodayDate(invoice.getCompany()), invoiceLine.getProduct(), invoice.getCompany(), fiscalPosition, isPurchase);
invoiceLine.setTaxLine(taxLine);
invoiceLine.setAccount(replacedAccount);
if (line.getAnalyticDistributionTemplate() != null) {
invoiceLine.setAnalyticDistributionTemplate(line.getAnalyticDistributionTemplate());
this.copyAnalyticMoveLines(line.getAnalyticMoveLineList(), invoiceLine);
}
invoice.addInvoiceLineListItem(invoiceLine);
return Beans.get(InvoiceLineRepository.class).save(invoiceLine);
}
use of com.axelor.apps.account.db.TaxLine 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;
}
Aggregations