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