use of com.axelor.apps.sale.db.SaleOrderLineTax in project axelor-open-suite by axelor.
the class SaleOrderInvoiceServiceImpl method generateAdvancePayment.
@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice generateAdvancePayment(SaleOrder saleOrder, BigDecimal amountToInvoice, boolean isPercent) throws AxelorException {
List<SaleOrderLineTax> taxLineList = saleOrder.getSaleOrderLineTaxList();
AccountConfigService accountConfigService = Beans.get(AccountConfigService.class);
BigDecimal percentToInvoice = computeAmountToInvoicePercent(saleOrder, amountToInvoice, isPercent);
Product invoicingProduct = accountConfigService.getAccountConfig(saleOrder.getCompany()).getAdvancePaymentProduct();
Account advancePaymentAccount = accountConfigService.getAccountConfig(saleOrder.getCompany()).getAdvancePaymentAccount();
if (invoicingProduct == null) {
throw new AxelorException(saleOrder, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.SO_INVOICE_MISSING_ADVANCE_PAYMENT_PRODUCT));
}
if (advancePaymentAccount == null) {
throw new AxelorException(saleOrder, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.SO_INVOICE_MISSING_ADVANCE_PAYMENT_ACCOUNT), saleOrder.getCompany().getName());
}
Invoice invoice = createInvoiceAndLines(saleOrder, taxLineList, invoicingProduct, percentToInvoice, InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE, advancePaymentAccount);
// no need for link to sale order lines for an advance payment
if (invoice.getInvoiceLineList() != null) {
invoice.getInvoiceLineList().forEach(invoiceLine -> invoiceLine.setSaleOrderLine(null));
}
return invoiceRepo.save(invoice);
}
use of com.axelor.apps.sale.db.SaleOrderLineTax in project axelor-open-suite by axelor.
the class SaleOrderComputeServiceImpl method _computeSaleOrder.
/**
* Compute the sale order total amounts
*
* @param saleOrder
* @throws AxelorException
*/
@Override
public void _computeSaleOrder(SaleOrder saleOrder) throws AxelorException {
saleOrder.setExTaxTotal(BigDecimal.ZERO);
saleOrder.setCompanyExTaxTotal(BigDecimal.ZERO);
saleOrder.setTaxTotal(BigDecimal.ZERO);
saleOrder.setInTaxTotal(BigDecimal.ZERO);
for (SaleOrderLine saleOrderLine : saleOrder.getSaleOrderLineList()) {
// skip title lines in computing total amounts
if (saleOrderLine.getTypeSelect() != SaleOrderLineRepository.TYPE_NORMAL) {
continue;
}
saleOrder.setExTaxTotal(saleOrder.getExTaxTotal().add(saleOrderLine.getExTaxTotal()));
// In the company accounting currency
saleOrder.setCompanyExTaxTotal(saleOrder.getCompanyExTaxTotal().add(saleOrderLine.getCompanyExTaxTotal()));
}
for (SaleOrderLineTax saleOrderLineVat : saleOrder.getSaleOrderLineTaxList()) {
// In the sale order currency
saleOrder.setTaxTotal(saleOrder.getTaxTotal().add(saleOrderLineVat.getTaxTotal()));
}
saleOrder.setInTaxTotal(saleOrder.getExTaxTotal().add(saleOrder.getTaxTotal()));
saleOrder.setAdvanceTotal(computeTotalAdvancePayment(saleOrder));
logger.debug("Montant de la facture: HTT = {}, HT = {}, Taxe = {}, TTC = {}", new Object[] { saleOrder.getExTaxTotal(), saleOrder.getTaxTotal(), saleOrder.getInTaxTotal() });
}
use of com.axelor.apps.sale.db.SaleOrderLineTax 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;
}
use of com.axelor.apps.sale.db.SaleOrderLineTax 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