use of com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator in project axelor-open-suite by axelor.
the class SaleOrderInvoiceServiceImpl method createInvoiceLine.
@Override
public List<InvoiceLine> createInvoiceLine(Invoice invoice, SaleOrderLine saleOrderLine, BigDecimal qtyToInvoice) throws AxelorException {
Product product = saleOrderLine.getProduct();
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGeneratorSupplyChain(invoice, product, saleOrderLine.getProductName(), saleOrderLine.getDescription(), qtyToInvoice, saleOrderLine.getUnit(), saleOrderLine.getSequence(), false, saleOrderLine, null, null) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
List<InvoiceLine> invoiceLines = new ArrayList<>();
invoiceLines.add(invoiceLine);
return invoiceLines;
}
};
return invoiceLineGenerator.creates();
}
use of com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator 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.account.service.invoice.generator.InvoiceLineGenerator 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.service.invoice.generator.InvoiceLineGenerator in project axelor-open-suite by axelor.
the class StockMoveInvoiceServiceImpl method createInvoiceLine.
@Override
public InvoiceLine createInvoiceLine(Invoice invoice, StockMoveLine stockMoveLine, BigDecimal qty) throws AxelorException {
Product product = stockMoveLine.getProduct();
boolean isTitleLine = false;
int sequence = InvoiceLineGenerator.DEFAULT_SEQUENCE;
SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
PurchaseOrderLine purchaseOrderLine = stockMoveLine.getPurchaseOrderLine();
if (saleOrderLine != null) {
sequence = saleOrderLine.getSequence();
} else if (purchaseOrderLine != null) {
if (purchaseOrderLine.getIsTitleLine()) {
isTitleLine = true;
}
sequence = purchaseOrderLine.getSequence();
}
// do not create lines with no qties
if ((qty == null || qty.signum() == 0 || stockMoveLine.getRealQty().signum() == 0) && !isTitleLine) {
return null;
}
if (product == null && !isTitleLine) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.STOCK_MOVE_INVOICE_1), stockMoveLine.getStockMove().getStockMoveSeq());
}
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGeneratorSupplyChain(invoice, product, stockMoveLine.getProductName(), stockMoveLine.getDescription(), qty, stockMoveLine.getUnit(), sequence, false, stockMoveLine.getSaleOrderLine(), stockMoveLine.getPurchaseOrderLine(), stockMoveLine) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
List<InvoiceLine> invoiceLines = new ArrayList<>();
invoiceLines.add(invoiceLine);
return invoiceLines;
}
};
List<InvoiceLine> invoiceLines = invoiceLineGenerator.creates();
InvoiceLine invoiceLine = null;
if (invoiceLines != null && !invoiceLines.isEmpty()) {
invoiceLine = invoiceLines.get(0);
if (!stockMoveLine.getIsMergedStockMoveLine()) {
// not a consolidated line so we can set the reference.
invoiceLine.setStockMoveLine(stockMoveLine);
} else {
// set the reference to a correct stock move line by following either the sale order line or
// purchase order line. We cannot have a consolidated line without purchase order line or
// sale order line reference
StockMoveLine nonConsolidatedStockMoveLine = null;
StockMove stockMove = stockMoveLine.getStockMove();
if (saleOrderLine != null) {
nonConsolidatedStockMoveLine = stockMoveLineRepository.all().filter("self.saleOrderLine.id = :saleOrderLineId " + "AND self.stockMove.id = :stockMoveId " + "AND self.id != :stockMoveLineId").bind("saleOrderLineId", saleOrderLine.getId()).bind("stockMoveId", stockMove.getId()).bind("stockMoveLineId", stockMoveLine.getId()).order("id").fetchOne();
} else if (purchaseOrderLine != null) {
nonConsolidatedStockMoveLine = stockMoveLineRepository.all().filter("self.purchaseOrderLine.id = :purchaseOrderLineId " + "AND self.stockMove.id = :stockMoveId " + "AND self.id != :stockMoveLineId").bind("purchaseOrderLineId", purchaseOrderLine.getId()).bind("stockMoveId", stockMove.getId()).bind("stockMoveLineId", stockMoveLine.getId()).order("id").fetchOne();
}
invoiceLine.setStockMoveLine(nonConsolidatedStockMoveLine);
deleteConsolidatedStockMoveLine(stockMoveLine);
}
}
return invoiceLine;
}
use of com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator in project axelor-open-suite by axelor.
the class InvoicingProjectService method createInvoiceLine.
public List<InvoiceLine> createInvoiceLine(Invoice invoice, SaleOrderLine saleOrderLine, int priority) throws AxelorException {
Product product = saleOrderLine.getProduct();
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGeneratorSupplyChain(invoice, product, saleOrderLine.getProductName(), saleOrderLine.getDescription(), saleOrderLine.getQty(), saleOrderLine.getUnit(), priority, false, saleOrderLine, null, null) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
invoiceLine.setProject(saleOrderLine.getProject());
List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
invoiceLines.add(invoiceLine);
return invoiceLines;
}
};
return invoiceLineGenerator.creates();
}
Aggregations