/// <summary> /// Create Facts (the accounting logic) for /// MMP. /// <pre> /// Production /// Inventory DR CR /// </pre> /// </summary> /// <param name="as1"></param> /// <returns>fact</returns> public override List <Fact> CreateFacts(MAcctSchema as1) { // create Fact Header Fact fact = new Fact(this, as1, Fact.POST_Actual); SetC_Currency_ID(as1.GetC_Currency_ID()); // Line pointer FactLine fl = null; for (int i = 0; i < _lines.Length; i++) { DocLine line = _lines[i]; // Calculate Costs Decimal?costs = null; if (line.IsProductionBOM()) { // Get BOM Cost - Sum of individual lines Decimal bomCost = Env.ZERO; for (int ii = 0; ii < _lines.Length; ii++) { DocLine line0 = _lines[ii]; if (line0.GetM_ProductionPlan_ID() != line.GetM_ProductionPlan_ID()) { continue; } if (!line0.IsProductionBOM()) { bomCost = Decimal.Add(bomCost, line0.GetProductCosts(as1, line.GetAD_Org_ID(), false)); } } costs = Decimal.Negate(bomCost); } else { costs = line.GetProductCosts(as1, line.GetAD_Org_ID(), false); } // Inventory DR CR fl = fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1), as1.GetC_Currency_ID(), costs); if (fl == null) { _error = "No Costs for Line " + line.GetLine() + " - " + line; return(null); } fl.SetM_Locator_ID(line.GetM_Locator_ID()); fl.SetQty(line.GetQty()); // Cost Detail String description = line.GetDescription(); if (description == null) { description = ""; } if (line.IsProductionBOM()) { description += "(*)"; } if (!IsPosted()) { MCostDetail.CreateProduction(as1, line.GetAD_Org_ID(), line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), line.Get_ID(), 0, Utility.Util.GetValueOfInt(costs), line.GetQty().Value, description, GetTrx(), GetRectifyingProcess()); } } // List <Fact> facts = new List <Fact>(); facts.Add(fact); return(facts); }
/// <summary> /// Set Document Info /// </summary> /// <param name="doc">document</param> /// <param name="docLine">doc line</param> public void SetDocumentInfo(Doc doc, DocLine docLine) { _doc = doc; _docLine = docLine; // reset SetAD_Org_ID(0); SetC_SalesRegion_ID(0); // Client if (GetAD_Client_ID() == 0) { SetAD_Client_ID(_doc.GetAD_Client_ID()); } // Date Trx SetDateTrx(_doc.GetDateDoc()); if (_docLine != null && _docLine.GetDateDoc() != null) { SetDateTrx(_docLine.GetDateDoc()); } // Date Acct SetDateAcct(_doc.GetDateAcct()); if (_docLine != null && _docLine.GetDateAcct() != null) { SetDateAcct(_docLine.GetDateAcct()); } // Period, Tax if (_docLine != null && _docLine.GetC_Period_ID() != 0) { SetC_Period_ID(_docLine.GetC_Period_ID()); } else { SetC_Period_ID(_doc.GetC_Period_ID()); } if (_docLine != null) { SetC_Tax_ID(_docLine.GetC_Tax_ID()); } // Description StringBuilder description = new StringBuilder(_doc.GetDocumentNo()); if (_docLine != null) { description.Append(" #").Append(_docLine.GetLine()); if (_docLine.GetDescription() != null) { description.Append(" (").Append(_docLine.GetDescription()).Append(")"); } else if (_doc.GetDescription() != null && _doc.GetDescription().Length > 0) { description.Append(" (").Append(_doc.GetDescription()).Append(")"); } } else if (_doc.GetDescription() != null && _doc.GetDescription().Length > 0) { description.Append(" (").Append(_doc.GetDescription()).Append(")"); } SetDescription(description.ToString()); // Journal Info SetGL_Budget_ID(_doc.GetGL_Budget_ID()); SetGL_Category_ID(_doc.GetGL_Category_ID()); // Product if (_docLine != null) { SetM_Product_ID(_docLine.GetM_Product_ID()); } if (GetM_Product_ID() == 0) { SetM_Product_ID(_doc.GetM_Product_ID()); } // UOM if (_docLine != null) { SetC_UOM_ID(_docLine.GetC_UOM_ID()); } // Qty if (Get_Value("Qty") == null) // not previously set { SetQty(_doc.GetQty()); // neg = outgoing if (_docLine != null) { SetQty(_docLine.GetQty()); } } // Loc From (maybe set earlier) if (GetC_LocFrom_ID() == 0 && _docLine != null) { SetC_LocFrom_ID(_docLine.GetC_LocFrom_ID()); } if (GetC_LocFrom_ID() == 0) { SetC_LocFrom_ID(_doc.GetC_LocFrom_ID()); } // Loc To (maybe set earlier) if (GetC_LocTo_ID() == 0 && _docLine != null) { SetC_LocTo_ID(_docLine.GetC_LocTo_ID()); } if (GetC_LocTo_ID() == 0) { SetC_LocTo_ID(_doc.GetC_LocTo_ID()); } // BPartner if (_docLine != null) { SetC_BPartner_ID(_docLine.GetC_BPartner_ID()); } if (GetC_BPartner_ID() == 0) { SetC_BPartner_ID(_doc.GetC_BPartner_ID()); } // Sales Region from BPLocation/Sales Rep // Trx Org if (_docLine != null) { SetAD_OrgTrx_ID(_docLine.GetAD_OrgTrx_ID()); } if (GetAD_OrgTrx_ID() == 0) { SetAD_OrgTrx_ID(_doc.GetAD_OrgTrx_ID()); } // Project if (_docLine != null) { SetC_Project_ID(_docLine.GetC_Project_ID()); } if (GetC_Project_ID() == 0) { SetC_Project_ID(_doc.GetC_Project_ID()); } // Campaign if (_docLine != null) { SetC_Campaign_ID(_docLine.GetC_Campaign_ID()); } if (GetC_Campaign_ID() == 0) { SetC_Campaign_ID(_doc.GetC_Campaign_ID()); } // Activity if (_docLine != null) { SetC_Activity_ID(_docLine.GetC_Activity_ID()); } if (GetC_Activity_ID() == 0) { SetC_Activity_ID(_doc.GetC_Activity_ID()); } // User List 1 if (_docLine != null) { SetUser1_ID(_docLine.GetUser1_ID()); } if (GetUser1_ID() == 0) { SetUser1_ID(_doc.GetUser1_ID()); } // User List 2 if (_docLine != null) { SetUser2_ID(_docLine.GetUser2_ID()); } if (GetUser2_ID() == 0) { SetUser2_ID(_doc.GetUser2_ID()); } // References in setAccount }