Search in sources :

Example 1 with InvoiceLineGenerator

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();
}
Also used : AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) PriceListLine(com.axelor.apps.base.db.PriceListLine) ArrayList(java.util.ArrayList) InvoiceLineGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator) BigDecimal(java.math.BigDecimal)

Example 2 with InvoiceLineGenerator

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();
}
Also used : AxelorException(com.axelor.exception.AxelorException) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) Product(com.axelor.apps.base.db.Product) List(java.util.List) ArrayList(java.util.ArrayList) InvoiceLineGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator)

Example 3 with InvoiceLineGenerator

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();
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) ArrayList(java.util.ArrayList) InvoiceLineGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator)

Example 4 with InvoiceLineGenerator

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;
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) ArrayList(java.util.ArrayList) InvoiceLineGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator) BigDecimal(java.math.BigDecimal)

Example 5 with InvoiceLineGenerator

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();
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceLineGeneratorSupplyChain(com.axelor.apps.supplychain.service.invoice.generator.InvoiceLineGeneratorSupplyChain) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) InvoiceLineGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator)

Aggregations

InvoiceLine (com.axelor.apps.account.db.InvoiceLine)11 InvoiceLineGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator)11 ArrayList (java.util.ArrayList)11 Product (com.axelor.apps.base.db.Product)6 InvoiceLineGeneratorSupplyChain (com.axelor.apps.supplychain.service.invoice.generator.InvoiceLineGeneratorSupplyChain)5 BigDecimal (java.math.BigDecimal)5 AxelorException (com.axelor.exception.AxelorException)4 TaxLine (com.axelor.apps.account.db.TaxLine)2 PriceListLine (com.axelor.apps.base.db.PriceListLine)2 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)2 List (java.util.List)2 Account (com.axelor.apps.account.db.Account)1 FiscalPosition (com.axelor.apps.account.db.FiscalPosition)1 InvoiceLineRepository (com.axelor.apps.account.db.repo.InvoiceLineRepository)1 FiscalPositionAccountService (com.axelor.apps.account.service.FiscalPositionAccountService)1 Company (com.axelor.apps.base.db.Company)1 PriceList (com.axelor.apps.base.db.PriceList)1 PartnerPriceListService (com.axelor.apps.base.service.PartnerPriceListService)1 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)1 AccountManagementService (com.axelor.apps.base.service.tax.AccountManagementService)1