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