use of com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method createInvoiceLine.
@Override
public List<InvoiceLine> createInvoiceLine(Invoice invoice, Product product, User user, String date, BigDecimal hoursDuration, int priority, PriceList priceList) throws AxelorException {
int discountMethodTypeSelect = PriceListLineRepository.TYPE_DISCOUNT;
int discountTypeSelect = PriceListLineRepository.AMOUNT_TYPE_NONE;
if (product == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TIMESHEET_PRODUCT));
}
BigDecimal price = (BigDecimal) productCompanyService.get(product, "salePrice", invoice.getCompany());
BigDecimal discountAmount = BigDecimal.ZERO;
BigDecimal priceDiscounted = price;
BigDecimal qtyConverted = Beans.get(UnitConversionService.class).convert(appHumanResourceService.getAppBase().getUnitHours(), (Unit) productCompanyService.get(product, "unit", invoice.getCompany()), hoursDuration, AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, product);
if (priceList != null) {
PriceListLine priceListLine = priceListService.getPriceListLine(product, qtyConverted, priceList, price);
if (priceListLine != null) {
discountMethodTypeSelect = priceListLine.getTypeSelect();
}
Map<String, Object> discounts = priceListService.getDiscounts(priceList, priceListLine, price);
if (discounts != null) {
discountAmount = (BigDecimal) discounts.get("discountAmount");
discountTypeSelect = (int) discounts.get("discountTypeSelect");
priceDiscounted = priceListService.computeDiscount(price, discountTypeSelect, discountAmount);
}
if ((appHumanResourceService.getAppBase().getComputeMethodDiscountSelect() == AppBaseRepository.INCLUDE_DISCOUNT_REPLACE_ONLY && discountMethodTypeSelect == PriceListLineRepository.TYPE_REPLACE) || appHumanResourceService.getAppBase().getComputeMethodDiscountSelect() == AppBaseRepository.INCLUDE_DISCOUNT) {
discountTypeSelect = PriceListLineRepository.AMOUNT_TYPE_NONE;
price = priceDiscounted;
}
}
String description = user.getFullName();
String productName = (String) productCompanyService.get(product, "name", invoice.getCompany());
if (date != null) {
productName += " " + "(" + date + ")";
}
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGenerator(invoice, product, productName, price, price, priceDiscounted, description, qtyConverted, (Unit) productCompanyService.get(product, "unit", invoice.getCompany()), null, priority, discountAmount, discountTypeSelect, price.multiply(qtyConverted), null, false) {
@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 ExpenseServiceImpl method createInvoiceLine.
@Override
public List<InvoiceLine> createInvoiceLine(Invoice invoice, ExpenseLine expenseLine, int priority) throws AxelorException {
Product product = expenseLine.getExpenseProduct();
InvoiceLineGenerator invoiceLineGenerator = null;
Integer atiChoice = invoice.getCompany().getAccountConfig().getInvoiceInAtiSelect();
if (atiChoice == AccountConfigRepository.INVOICE_WT_ALWAYS || atiChoice == AccountConfigRepository.INVOICE_WT_DEFAULT) {
invoiceLineGenerator = new InvoiceLineGenerator(invoice, product, product.getName(), expenseLine.getUntaxedAmount(), expenseLine.getTotalAmount(), expenseLine.getUntaxedAmount(), expenseLine.getComments(), BigDecimal.ONE, product.getUnit(), null, priority, BigDecimal.ZERO, PriceListLineRepository.AMOUNT_TYPE_NONE, expenseLine.getUntaxedAmount(), expenseLine.getTotalAmount(), false) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
List<InvoiceLine> invoiceLines = new ArrayList<>();
invoiceLines.add(invoiceLine);
return invoiceLines;
}
};
} else {
invoiceLineGenerator = new InvoiceLineGenerator(invoice, product, product.getName(), expenseLine.getUntaxedAmount(), expenseLine.getTotalAmount(), expenseLine.getTotalAmount(), expenseLine.getComments(), BigDecimal.ONE, product.getUnit(), null, priority, BigDecimal.ZERO, PriceListLineRepository.AMOUNT_TYPE_NONE, expenseLine.getUntaxedAmount(), expenseLine.getTotalAmount(), false) {
@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 ProjectTaskBusinessProjectServiceImpl method createInvoiceLine.
@Override
public List<InvoiceLine> createInvoiceLine(Invoice invoice, ProjectTask projectTask, int priority) throws AxelorException {
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGenerator(invoice, projectTask.getProduct(), projectTask.getName(), projectTask.getUnitPrice(), BigDecimal.ZERO, projectTask.getPriceDiscounted(), projectTask.getDescription(), projectTask.getQuantity(), projectTask.getUnit(), null, priority, projectTask.getDiscountAmount(), projectTask.getDiscountTypeSelect(), projectTask.getExTaxTotal(), BigDecimal.ZERO, false) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
invoiceLine.setProject(projectTask.getProject());
invoiceLine.setSaleOrderLine(projectTask.getSaleOrderLine());
projectTask.setInvoiceLine(invoiceLine);
List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
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 createInvoiceLinesFromSO.
protected List<InvoiceLine> createInvoiceLinesFromSO(Invoice invoice, SaleOrder saleOrder, Product invoicingProduct, BigDecimal percentToInvoice) throws AxelorException {
List<InvoiceLine> invoiceLineList = new ArrayList<>();
BigDecimal lineAmountToInvoice = percentToInvoice.multiply(saleOrder.getInTaxTotal()).divide(new BigDecimal("100"), 4, BigDecimal.ROUND_HALF_UP);
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGenerator(invoice, invoicingProduct, invoicingProduct.getName(), lineAmountToInvoice, lineAmountToInvoice, lineAmountToInvoice, invoicingProduct.getDescription(), BigDecimal.ONE, invoicingProduct.getUnit(), null, 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();
invoiceLineList.addAll(invoiceOneLineList);
return invoiceLineList;
}
use of com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator in project axelor-open-suite by axelor.
the class PurchaseOrderInvoiceServiceImpl method createInvoiceLine.
public List<InvoiceLine> createInvoiceLine(Invoice invoice, PurchaseOrderLine purchaseOrderLine, BigDecimal qtyToInvoice) throws AxelorException {
Product product = purchaseOrderLine.getProduct();
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGeneratorSupplyChain(invoice, product, purchaseOrderLine.getProductName(), purchaseOrderLine.getDescription(), qtyToInvoice, purchaseOrderLine.getUnit(), purchaseOrderLine.getSequence(), false, null, purchaseOrderLine, 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();
}
Aggregations