/// <summary> /// Load Invoice Line /// </summary> /// <param name="order">order</param> /// <returns>DocLine Array</returns> private DocLine[] LoadLines(MOrder order) { List <DocLine> list = new List <DocLine>(); MOrderLine[] lines = order.GetLines(); for (int i = 0; i < lines.Length; i++) { MOrderLine line = lines[i]; DocLine docLine = new DocLine(line, this); Decimal Qty = line.GetQtyOrdered(); docLine.SetQty(Qty, order.IsSOTrx()); // // Decimal PriceActual = line.getPriceActual(); Decimal?PriceCost = null; if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_PURCHASEORDER)) // PO { PriceCost = line.GetPriceCost(); } Decimal?LineNetAmt = null; if (PriceCost != null && Env.Signum(PriceCost.Value) != 0) { LineNetAmt = Decimal.Multiply(Qty, PriceCost.Value); } else { LineNetAmt = line.GetLineNetAmt(); } docLine.SetAmount(LineNetAmt); // DR Decimal PriceList = line.GetPriceList(); int C_Tax_ID = docLine.GetC_Tax_ID(); // Correct included Tax if (IsTaxIncluded() && C_Tax_ID != 0) { MTax tax = MTax.Get(GetCtx(), C_Tax_ID); if (!tax.IsZeroTax()) { Decimal LineNetAmtTax = tax.CalculateTax(LineNetAmt.Value, true, GetStdPrecision()); log.Fine("LineNetAmt=" + LineNetAmt + " - Tax=" + LineNetAmtTax); LineNetAmt = Decimal.Subtract(LineNetAmt.Value, LineNetAmtTax); for (int t = 0; t < _taxes.Length; t++) { if (_taxes[t].GetC_Tax_ID() == C_Tax_ID) { _taxes[t].AddIncludedTax(LineNetAmtTax); break; } } Decimal PriceListTax = tax.CalculateTax(PriceList, true, GetStdPrecision()); PriceList = Decimal.Subtract(PriceList, PriceListTax); } } // correct included Tax docLine.SetAmount(LineNetAmt, PriceList, Qty); list.Add(docLine); } // Return Array DocLine[] dl = new DocLine[list.Count]; dl = list.ToArray(); return(dl); }
/// <summary> /// Load Invoice Line /// </summary> /// <param name="invoice">invoice</param> /// <returns>DocLine Array</returns> private DocLine[] LoadLines(MInvoice invoice) { List <DocLine> list = new List <DocLine>(); // MInvoiceLine[] lines = invoice.GetLines(false); for (int i = 0; i < lines.Length; i++) { MInvoiceLine line = lines[i]; if (line.IsDescription()) { continue; } DocLine docLine = new DocLine(line, this); // Qty Decimal Qty = line.GetQtyInvoiced(); bool cm = GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_ARCREDITMEMO) || GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_APCREDITMEMO); docLine.SetQty(cm ? Decimal.Negate(Qty) : Qty, invoice.IsSOTrx()); // Decimal LineNetAmt = line.GetLineNetAmt(); Decimal PriceList = line.GetPriceList(); int C_Tax_ID = docLine.GetC_Tax_ID(); // Correct included Tax if (IsTaxIncluded() && C_Tax_ID != 0) { MTax tax = MTax.Get(GetCtx(), C_Tax_ID); if (!tax.IsZeroTax()) { Decimal LineNetAmtTax = tax.CalculateTax(LineNetAmt, true, GetStdPercision()); log.Fine("LineNetAmt=" + LineNetAmt + " - Tax=" + LineNetAmtTax); LineNetAmt = Decimal.Subtract(LineNetAmt, LineNetAmtTax); for (int t = 0; t < _taxes.Length; t++) { if (_taxes[t].GetC_Tax_ID() == C_Tax_ID) { _taxes[t].AddIncludedTax(LineNetAmtTax); break; } } Decimal PriceListTax = tax.CalculateTax(PriceList, true, GetStdPercision()); PriceList = Decimal.Subtract(PriceList, PriceListTax); } } // correct included Tax docLine.SetAmount(LineNetAmt, PriceList, Qty); // qty for discount calc if (docLine.IsItem()) { _allLinesService = false; } else { _allLinesItem = false; } // log.Fine(docLine.ToString()); list.Add(docLine); } // Convert to Array DocLine[] dls = new DocLine[list.Count]; dls = list.ToArray(); // Included Tax - make sure that no difference if (IsTaxIncluded()) { for (int i = 0; i < _taxes.Length; i++) { if (_taxes[i].IsIncludedTaxDifference()) { Decimal diff = _taxes[i].GetIncludedTaxDifference(); for (int j = 0; j < dls.Length; j++) { if (dls[j].GetC_Tax_ID() == _taxes[i].GetC_Tax_ID()) { dls[j].SetLineNetAmtDifference(diff); break; } } // for all lines } // tax difference } // for all taxes } // Included Tax difference // Return Array return(dls); }
/// <summary> /// Get Commitments /// </summary> /// <param name="doc">document</param> /// <param name="maxQty">Qty invoiced/matched</param> /// <param name="C_InvoiceLine_ID">invoice line</param> /// <returns>commitments (order lines)</returns> protected static DocLine[] GetCommitments(Doc doc, Decimal maxQty, int C_InvoiceLine_ID) { int precision = -1; // List <DocLine> list = new List <DocLine>(); String sql = "SELECT * FROM C_OrderLine ol " + "WHERE EXISTS " + "(SELECT * FROM C_InvoiceLine il " + "WHERE il.C_OrderLine_ID=ol.C_OrderLine_ID" + " AND il.C_InvoiceLine_ID=" + C_InvoiceLine_ID + ")" + " OR EXISTS " + "(SELECT * FROM M_MatchPO po " + "WHERE po.C_OrderLine_ID=ol.C_OrderLine_ID" + " AND po.C_InvoiceLine_ID=" + C_InvoiceLine_ID + ")"; IDataReader idr = null; try { idr = DataBase.DB.ExecuteReader(sql, null, null); while (idr.Read()) { if (Env.Signum(maxQty) == 0) { continue; } MOrderLine line = new MOrderLine(doc.GetCtx(), idr, null); DocLine docLine = new DocLine(line, doc); // Currency if (precision == -1) { doc.SetC_Currency_ID(docLine.GetC_Currency_ID()); precision = MCurrency.GetStdPrecision(doc.GetCtx(), docLine.GetC_Currency_ID()); } // Qty Decimal Qty = Math.Max(line.GetQtyOrdered(), maxQty); docLine.SetQty(Qty, false); // Decimal PriceActual = line.GetPriceActual(); Decimal PriceCost = line.GetPriceCost(); Decimal?LineNetAmt = null; if (Env.Signum(PriceCost) != 0) { LineNetAmt = Decimal.Multiply(Qty, PriceCost); } else if (Qty.Equals(maxQty)) { LineNetAmt = line.GetLineNetAmt(); } else { LineNetAmt = Decimal.Multiply(Qty, PriceActual); } maxQty = Decimal.Subtract(maxQty, Qty); docLine.SetAmount(LineNetAmt); // DR Decimal PriceList = line.GetPriceList(); int C_Tax_ID = docLine.GetC_Tax_ID(); // Correct included Tax if (C_Tax_ID != 0 && line.GetParent().IsTaxIncluded()) { MTax tax = MTax.Get(doc.GetCtx(), C_Tax_ID); if (!tax.IsZeroTax()) { Decimal LineNetAmtTax = tax.CalculateTax(LineNetAmt.Value, true, precision); _log.Fine("LineNetAmt=" + LineNetAmt + " - Tax=" + LineNetAmtTax); LineNetAmt = Decimal.Subtract(LineNetAmt.Value, LineNetAmtTax); Decimal PriceListTax = tax.CalculateTax(PriceList, true, precision); PriceList = Decimal.Subtract(PriceList, PriceListTax); } } // correct included Tax docLine.SetAmount(LineNetAmt, PriceList, Qty); list.Add(docLine); } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); idr = null; } _log.Log(Level.SEVERE, sql, e); } // Return Array DocLine[] dl = new DocLine[list.Count]; dl = list.ToArray(); return(dl); }