Search in sources :

Example 46 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine 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)

Example 47 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.

the class SaleOrderInvoiceServiceImpl method createInvoiceLines.

// TODO ajouter tri sur les séquences
@Override
public List<InvoiceLine> createInvoiceLines(Invoice invoice, List<SaleOrderLine> saleOrderLineList, Map<Long, BigDecimal> qtyToInvoiceMap) throws AxelorException {
    List<InvoiceLine> invoiceLineList = new ArrayList<>();
    for (SaleOrderLine saleOrderLine : saleOrderLineList) {
        if (qtyToInvoiceMap.containsKey(saleOrderLine.getId())) {
            List<InvoiceLine> invoiceLines = createInvoiceLine(invoice, saleOrderLine, qtyToInvoiceMap.get(saleOrderLine.getId()));
            invoiceLineList.addAll(invoiceLines);
            saleOrderLine.setInvoiced(true);
        }
    }
    return invoiceLineList;
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) ArrayList(java.util.ArrayList) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 48 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine 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 49 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.

the class SaleOrderInvoiceServiceImpl method mergeInvoice.

@Override
@Transactional
public Invoice mergeInvoice(List<Invoice> invoiceList, Company company, Currency currency, Partner partner, Partner contactPartner, PriceList priceList, PaymentMode paymentMode, PaymentCondition paymentCondition, SaleOrder saleOrder) throws AxelorException {
    log.debug("service supplychain 1 (saleOrder) {}", saleOrder);
    if (saleOrder != null) {
        String numSeq = "";
        String externalRef = "";
        for (Invoice invoiceLocal : invoiceList) {
            if (!numSeq.isEmpty()) {
                numSeq += "-";
            }
            if (invoiceLocal.getInternalReference() != null) {
                numSeq += invoiceLocal.getInternalReference();
            }
            if (!externalRef.isEmpty()) {
                externalRef += "|";
            }
            if (invoiceLocal.getExternalReference() != null) {
                externalRef += invoiceLocal.getExternalReference();
            }
        }
        InvoiceGenerator invoiceGenerator = this.createInvoiceGenerator(saleOrder);
        Invoice invoiceMerged = invoiceGenerator.generate();
        invoiceMerged.setExternalReference(externalRef);
        invoiceMerged.setInternalReference(numSeq);
        if (paymentMode != null)
            invoiceMerged.setPaymentMode(paymentMode);
        if (paymentCondition != null)
            invoiceMerged.setPaymentCondition(paymentCondition);
        List<InvoiceLine> invoiceLines = invoiceService.getInvoiceLinesFromInvoiceList(invoiceList);
        invoiceGenerator.populate(invoiceMerged, invoiceLines);
        invoiceService.setInvoiceForInvoiceLines(invoiceLines, invoiceMerged);
        invoiceMerged.setSaleOrder(null);
        invoiceRepo.save(invoiceMerged);
        swapStockMoveInvoices(invoiceList, invoiceMerged);
        invoiceService.deleteOldInvoices(invoiceList);
        return invoiceMerged;
    } else {
        Invoice invoiceMerged = invoiceService.mergeInvoice(invoiceList, company, currency, partner, contactPartner, priceList, paymentMode, paymentCondition);
        swapStockMoveInvoices(invoiceList, invoiceMerged);
        invoiceService.deleteOldInvoices(invoiceList);
        return invoiceMerged;
    }
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceGenerator) StringTool.getIdListString(com.axelor.apps.tool.StringTool.getIdListString) Transactional(com.google.inject.persist.Transactional)

Example 50 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine 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)

Aggregations

InvoiceLine (com.axelor.apps.account.db.InvoiceLine)80 ArrayList (java.util.ArrayList)36 Invoice (com.axelor.apps.account.db.Invoice)27 BigDecimal (java.math.BigDecimal)22 AxelorException (com.axelor.exception.AxelorException)20 Product (com.axelor.apps.base.db.Product)13 InvoiceLineGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator)12 Transactional (com.google.inject.persist.Transactional)12 Context (com.axelor.rpc.Context)11 Account (com.axelor.apps.account.db.Account)8 InvoiceGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceGenerator)8 TaxLine (com.axelor.apps.account.db.TaxLine)7 InvoiceLineService (com.axelor.apps.account.service.invoice.InvoiceLineService)7 RefundInvoice (com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice)6 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)6 InvoiceLineGeneratorSupplyChain (com.axelor.apps.supplychain.service.invoice.generator.InvoiceLineGeneratorSupplyChain)6 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)5 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)5 HashSet (java.util.HashSet)5 List (java.util.List)5