Search in sources :

Example 31 with InvoiceLine

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

the class InvoiceLineController method updateQty.

public List<InvoiceLine> updateQty(List<InvoiceLine> invoiceLines, BigDecimal oldKitQty, BigDecimal newKitQty, Invoice invoice) throws AxelorException {
    BigDecimal qty = BigDecimal.ZERO;
    BigDecimal exTaxTotal = BigDecimal.ZERO;
    BigDecimal companyExTaxTotal = BigDecimal.ZERO;
    BigDecimal inTaxTotal = BigDecimal.ZERO;
    BigDecimal companyInTaxTotal = BigDecimal.ZERO;
    BigDecimal priceDiscounted = BigDecimal.ZERO;
    BigDecimal taxRate = BigDecimal.ZERO;
    AppBaseService appBaseService = Beans.get(AppBaseService.class);
    InvoiceLineService invoiceLineService = Beans.get(InvoiceLineService.class);
    int scale = appBaseService.getNbDecimalDigitForQty();
    if (invoiceLines != null) {
        if (newKitQty.compareTo(BigDecimal.ZERO) != 0) {
            for (InvoiceLine line : invoiceLines) {
                qty = (line.getQty().divide(oldKitQty, scale, RoundingMode.HALF_UP)).multiply(newKitQty).setScale(scale, RoundingMode.HALF_UP);
                priceDiscounted = invoiceLineService.computeDiscount(line, invoice.getInAti());
                if (line.getTaxLine() != null) {
                    taxRate = line.getTaxLine().getValue();
                }
                if (!invoice.getInAti()) {
                    exTaxTotal = InvoiceLineManagement.computeAmount(qty, priceDiscounted);
                    inTaxTotal = exTaxTotal.add(exTaxTotal.multiply(taxRate));
                } else {
                    inTaxTotal = InvoiceLineManagement.computeAmount(qty, priceDiscounted);
                    exTaxTotal = inTaxTotal.divide(taxRate.add(BigDecimal.ONE), 2, BigDecimal.ROUND_HALF_UP);
                }
                companyExTaxTotal = invoiceLineService.getCompanyExTaxTotal(exTaxTotal, invoice);
                companyInTaxTotal = invoiceLineService.getCompanyExTaxTotal(inTaxTotal, invoice);
                line.setQty(qty);
                line.setExTaxTotal(exTaxTotal);
                line.setCompanyExTaxTotal(companyExTaxTotal);
                line.setInTaxTotal(inTaxTotal);
                line.setCompanyInTaxTotal(companyInTaxTotal);
                line.setPriceDiscounted(priceDiscounted);
                line.setTaxRate(taxRate);
            }
        } else {
            for (InvoiceLine line : invoiceLines) {
                line.setQty(qty);
            }
        }
    }
    return invoiceLines;
}
Also used : AppBaseService(com.axelor.apps.base.service.app.AppBaseService) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceLineService(com.axelor.apps.account.service.invoice.InvoiceLineService) BigDecimal(java.math.BigDecimal)

Example 32 with InvoiceLine

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

the class WorkflowCancelServiceSupplychainImpl method saleOrderProcess.

public void saleOrderProcess(Invoice invoice) throws AxelorException {
    SaleOrder invoiceSaleOrder = invoice.getSaleOrder();
    if (invoiceSaleOrder != null) {
        log.debug("Update the invoiced amount of the sale order : {}", invoiceSaleOrder.getSaleOrderSeq());
        invoiceSaleOrder.setAmountInvoiced(saleOrderInvoiceService.getInvoicedAmount(invoiceSaleOrder, invoice.getId(), true));
    } else {
        // Get all different saleOrders from invoice
        List<SaleOrder> saleOrderList = Lists.newArrayList();
        for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
            SaleOrder saleOrder = this.saleOrderLineProcess(invoice, invoiceLine);
            if (saleOrder != null && !saleOrderList.contains(saleOrder)) {
                saleOrderList.add(saleOrder);
            }
        }
        for (SaleOrder saleOrder : saleOrderList) {
            log.debug("Update the invoiced amount of the sale order : {}", saleOrder.getSaleOrderSeq());
            saleOrder.setAmountInvoiced(saleOrderInvoiceService.getInvoicedAmount(saleOrder, invoice.getId(), true));
            saleOrderRepository.save(saleOrder);
        }
    }
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder)

Example 33 with InvoiceLine

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

the class WorkflowVentilationServiceSupplychainImpl method purchaseOrderProcess.

private void purchaseOrderProcess(Invoice invoice) throws AxelorException {
    // Get all different purchaseOrders from invoice
    Set<PurchaseOrder> purchaseOrderSet = new HashSet<>();
    for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
        PurchaseOrder purchaseOrder = null;
        purchaseOrder = this.purchaseOrderLineProcess(invoice, invoiceLine);
        if (purchaseOrder != null) {
            purchaseOrderSet.add(purchaseOrder);
        }
    }
    for (PurchaseOrder purchaseOrder : purchaseOrderSet) {
        log.debug("Update the invoiced amount of the purchase order : {}", purchaseOrder.getPurchaseOrderSeq());
        purchaseOrder.setAmountInvoiced(purchaseOrderInvoiceService.getInvoicedAmount(purchaseOrder, invoice.getId(), false));
        purchaseOrderRepository.save(purchaseOrder);
    }
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) HashSet(java.util.HashSet)

Example 34 with InvoiceLine

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

the class WorkflowVentilationServiceSupplychainImpl method stockMoveProcess.

private void stockMoveProcess(Invoice invoice) throws AxelorException {
    // update qty invoiced in stock move line
    for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
        StockMoveLine stockMoveLine = invoiceLine.getStockMoveLine();
        if (stockMoveLine == null) {
            continue;
        }
        if (isStockMoveInvoicingPartiallyActivated(invoice, stockMoveLine)) {
            BigDecimal qty = stockMoveLine.getQtyInvoiced();
            StockMove stockMove = stockMoveLine.getStockMove();
            if (stockMoveInvoiceService.isInvoiceRefundingStockMove(stockMove, invoice)) {
                qty = qty.subtract(invoiceLine.getQty());
            } else {
                qty = qty.add(invoiceLine.getQty());
            }
            Unit movUnit = stockMoveLine.getUnit(), invUnit = invoiceLine.getUnit();
            try {
                qty = unitConversionService.convert(invUnit, movUnit, qty, appBaseService.getNbDecimalDigitForQty(), null);
            } catch (AxelorException e) {
                throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.STOCK_MOVE_INVOICE_QTY_INVONVERTIBLE_UNIT) + "\n" + e.getMessage());
            }
            if (stockMoveLine.getRealQty().compareTo(qty) >= 0) {
                stockMoveLine.setQtyInvoiced(qty);
            } else {
                throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.STOCK_MOVE_INVOICE_QTY_MAX));
            }
        } else {
            // set qty invoiced to the maximum (or emptying it if refund) for all stock move lines
            boolean invoiceIsRefund = stockMoveInvoiceService.isInvoiceRefundingStockMove(stockMoveLine.getStockMove(), invoice);
            stockMoveLine.setQtyInvoiced(invoiceIsRefund ? BigDecimal.ZERO : stockMoveLine.getRealQty());
            // search in sale/purchase order lines to set split stock move lines to invoiced.
            if (stockMoveLine.getSaleOrderLine() != null) {
                stockMoveLineRepository.all().filter("self.saleOrderLine.id = :saleOrderLineId AND self.stockMove.id = :stockMoveId").bind("saleOrderLineId", stockMoveLine.getSaleOrderLine().getId()).bind("stockMoveId", stockMoveLine.getStockMove().getId()).fetch().forEach(stockMvLine -> stockMvLine.setQtyInvoiced(invoiceIsRefund ? BigDecimal.ZERO : stockMvLine.getRealQty()));
            }
            if (stockMoveLine.getPurchaseOrderLine() != null) {
                stockMoveLineRepository.all().filter("self.purchaseOrderLine.id = :purchaseOrderLineId AND self.stockMove.id = :stockMoveId").bind("purchaseOrderLineId", stockMoveLine.getPurchaseOrderLine().getId()).bind("stockMoveId", stockMoveLine.getStockMove().getId()).fetch().forEach(stockMvLine -> stockMvLine.setQtyInvoiced(invoiceIsRefund ? BigDecimal.ZERO : stockMvLine.getRealQty()));
            }
        }
    }
    // update stock moves invoicing status
    for (StockMove stockMove : invoice.getStockMoveSet()) {
        stockMoveInvoiceService.computeStockMoveInvoicingStatus(stockMove);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) StockMove(com.axelor.apps.stock.db.StockMove) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Example 35 with InvoiceLine

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

the class InvoiceLineController method convertUnitPrice.

public void convertUnitPrice(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
    Invoice invoice = this.getInvoice(context);
    if (invoice == null || invoiceLine.getProduct() == null || invoiceLine.getPrice() == null || invoiceLine.getInTaxPrice() == null) {
        return;
    }
    try {
        BigDecimal price = invoiceLine.getPrice();
        BigDecimal inTaxPrice = price.add(price.multiply(invoiceLine.getTaxLine().getValue()));
        response.setValue("inTaxPrice", inTaxPrice);
    } catch (Exception e) {
        response.setFlash(e.getMessage());
    }
}
Also used : Context(com.axelor.rpc.Context) Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException)

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