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