Search in sources :

Example 6 with InvoiceLineGenerator

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();
}
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)

Example 7 with InvoiceLineGenerator

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

Example 8 with InvoiceLineGenerator

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);
}
Also used : FiscalPositionAccountService(com.axelor.apps.account.service.FiscalPositionAccountService) Account(com.axelor.apps.account.db.Account) AccountManagementService(com.axelor.apps.base.service.tax.AccountManagementService) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) FiscalPosition(com.axelor.apps.account.db.FiscalPosition) ArrayList(java.util.ArrayList) InvoiceLineGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator) BigDecimal(java.math.BigDecimal) InvoiceLineRepository(com.axelor.apps.account.db.repo.InvoiceLineRepository) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 9 with InvoiceLineGenerator

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;
}
Also used : AxelorException(com.axelor.exception.AxelorException) StockMove(com.axelor.apps.stock.db.StockMove) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) InvoiceLineGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) InvoiceLineGeneratorSupplyChain(com.axelor.apps.supplychain.service.invoice.generator.InvoiceLineGeneratorSupplyChain) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine)

Example 10 with InvoiceLineGenerator

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();
}
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