Search in sources :

Example 61 with InvoiceLine

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

the class StockMoveMultiInvoiceServiceImpl method transformToRefund.

/**
 * Change the operation type and invert all prices in the invoice.
 *
 * @param invoice an invoice
 * @return the refund invoice
 */
protected Invoice transformToRefund(Invoice invoice) throws AxelorException {
    Invoice refund = new RefundInvoice(invoice).generate();
    if (refund.getInvoiceLineList() != null) {
        for (InvoiceLine invoiceLine : refund.getInvoiceLineList()) {
            invoiceLine.setPrice(invoiceLine.getPrice().negate());
            invoiceLine.setPriceDiscounted(invoiceLine.getPriceDiscounted().negate());
            invoiceLine.setInTaxPrice(invoiceLine.getInTaxPrice().negate());
            invoiceLine.setExTaxTotal(invoiceLine.getExTaxTotal().negate());
            invoiceLine.setInTaxTotal(invoiceLine.getInTaxTotal().negate());
            invoiceLine.setCompanyExTaxTotal(invoiceLine.getCompanyExTaxTotal().negate());
            invoiceLine.setCompanyInTaxTotal(invoiceLine.getCompanyInTaxTotal().negate());
        }
    }
    if (refund.getInvoiceLineTaxList() != null) {
        for (InvoiceLineTax invoiceLineTax : refund.getInvoiceLineTaxList()) {
            invoiceLineTax.setExTaxBase(invoiceLineTax.getExTaxBase().negate());
            invoiceLineTax.setTaxTotal(invoiceLineTax.getTaxTotal().negate());
            invoiceLineTax.setCompanyExTaxBase(invoiceLineTax.getCompanyExTaxBase().negate());
            invoiceLineTax.setInTaxTotal(invoiceLineTax.getInTaxTotal().negate());
            invoiceLineTax.setCompanyInTaxTotal(invoiceLineTax.getCompanyInTaxTotal().negate());
        }
    }
    refund.setExTaxTotal(refund.getExTaxTotal().negate());
    refund.setInTaxTotal(refund.getInTaxTotal().negate());
    refund.setCompanyExTaxTotal(refund.getCompanyExTaxTotal().negate());
    refund.setCompanyInTaxTotal(refund.getCompanyInTaxTotal().negate());
    refund.setTaxTotal(refund.getTaxTotal().negate());
    refund.setAmountRemaining(refund.getAmountRemaining().negate());
    refund.setCompanyTaxTotal(refund.getCompanyTaxTotal().negate());
    refund.setPaymentMode(InvoiceToolService.getPaymentMode(refund));
    return invoiceRepository.save(refund);
}
Also used : RefundInvoice(com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice) Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceLineTax(com.axelor.apps.account.db.InvoiceLineTax) RefundInvoice(com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice)

Example 62 with InvoiceLine

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

the class StockMoveInvoiceServiceImpl method computeNonCanceledInvoiceQty.

@Override
public BigDecimal computeNonCanceledInvoiceQty(StockMoveLine stockMoveLine) throws AxelorException {
    List<InvoiceLine> nonCanceledInvoiceLineList = invoiceLineRepository.all().filter("self.invoice.statusSelect != :invoiceCanceled " + "AND self.stockMoveLine.id = :stockMoveLineId").bind("invoiceCanceled", InvoiceRepository.STATUS_CANCELED).bind("stockMoveLineId", stockMoveLine.getId()).fetch();
    BigDecimal nonCanceledInvoiceQty = BigDecimal.ZERO;
    for (InvoiceLine invoiceLine : nonCanceledInvoiceLineList) {
        if (isInvoiceRefundingStockMove(stockMoveLine.getStockMove(), invoiceLine.getInvoice())) {
            nonCanceledInvoiceQty = nonCanceledInvoiceQty.subtract(invoiceLine.getQty());
        } else {
            nonCanceledInvoiceQty = nonCanceledInvoiceQty.add(invoiceLine.getQty());
        }
    }
    return nonCanceledInvoiceQty;
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) BigDecimal(java.math.BigDecimal)

Example 63 with InvoiceLine

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

the class StockMoveInvoiceServiceImpl method createInvoiceLines.

@Override
public List<InvoiceLine> createInvoiceLines(Invoice invoice, StockMove stockMove, List<StockMoveLine> stockMoveLineList, Map<Long, BigDecimal> qtyToInvoiceMap) throws AxelorException {
    List<InvoiceLine> invoiceLineList = new ArrayList<>();
    List<StockMoveLine> stockMoveLineToInvoiceList;
    if ((StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect()) && supplyChainConfigService.getSupplyChainConfig(invoice.getCompany()).getActivateIncStockMovePartialInvoicing()) || (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect()) && supplyChainConfigService.getSupplyChainConfig(invoice.getCompany()).getActivateOutStockMovePartialInvoicing())) {
        // we do not consolidate because the invoicing is partial
        stockMoveLineToInvoiceList = stockMoveLineList;
    } else {
        stockMoveLineToInvoiceList = getConsolidatedStockMoveLineList(stockMoveLineList);
    }
    for (StockMoveLine stockMoveLine : stockMoveLineToInvoiceList) {
        InvoiceLine invoiceLineCreated;
        Long id = stockMoveLine.getId();
        if (qtyToInvoiceMap != null) {
            invoiceLineCreated = this.createInvoiceLine(invoice, stockMoveLine, qtyToInvoiceMap.get(id));
        } else {
            invoiceLineCreated = this.createInvoiceLine(invoice, stockMoveLine, stockMoveLine.getRealQty().subtract(computeNonCanceledInvoiceQty(stockMoveLine)));
        }
        if (invoiceLineCreated != null) {
            invoiceLineList.add(invoiceLineCreated);
        }
    }
    return invoiceLineList;
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) ArrayList(java.util.ArrayList) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine)

Example 64 with InvoiceLine

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

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

the class WorkflowCancelServiceSupplychainImpl method purchaseOrderProcess.

public void purchaseOrderProcess(Invoice invoice) throws AxelorException {
    PurchaseOrder invoicePurchaseOrder = invoice.getPurchaseOrder();
    if (invoicePurchaseOrder != null) {
        log.debug("Update the invoiced amount of the purchase order : {}", invoicePurchaseOrder.getPurchaseOrderSeq());
        invoicePurchaseOrder.setAmountInvoiced(purchaseOrderInvoiceService.getInvoicedAmount(invoicePurchaseOrder, invoice.getId(), true));
    } else {
        // Get all different purchaseOrders from invoice
        List<PurchaseOrder> purchaseOrderList = Lists.newArrayList();
        ;
        for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
            PurchaseOrder purchaseOrder = this.purchaseOrderLineProcess(invoice, invoiceLine);
            if (purchaseOrder != null && !purchaseOrderList.contains(purchaseOrder)) {
                purchaseOrderList.add(purchaseOrder);
            }
        }
        for (PurchaseOrder purchaseOrder : purchaseOrderList) {
            log.debug("Update the invoiced amount of the purchase order : {}", purchaseOrder.getPurchaseOrderSeq());
            purchaseOrder.setAmountInvoiced(purchaseOrderInvoiceService.getInvoicedAmount(purchaseOrder, invoice.getId(), true));
            purchaseOrderRepository.save(purchaseOrder);
        }
    }
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

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