Beispiel #1
0
        /// <summary>
        /// Create Facts (the accounting logic) for
        ///  MMI.
        ///  <pre>
        ///  Inventory
        ///      Inventory       DR      CR
        ///      InventoryDiff   DR      CR   (or Charge)
        ///  </pre>
        /// </summary>
        /// <param name="?"></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 pointers
            FactLine dr = null;
            FactLine cr = null;

            for (int i = 0; i < _lines.Length; i++)
            {
                DocLine line  = _lines[i];
                Decimal costs = line.GetProductCosts(as1, line.GetAD_Org_ID(), false);
                if (Env.Signum(costs) == 0)
                {
                    _error = "No Costs for " + line.GetProduct().GetName();
                    return(null);
                }
                //  Inventory       DR      CR
                dr = fact.CreateLine(line,
                                     line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1),
                                     as1.GetC_Currency_ID(), costs);
                //  may be zero difference - no line created.
                if (dr == null)
                {
                    continue;
                }
                dr.SetM_Locator_ID(line.GetM_Locator_ID());

                //  InventoryDiff   DR      CR
                //	or Charge
                MAccount invDiff = line.GetChargeAccount(as1, Decimal.Negate(costs));
                if (invDiff == null)
                {
                    invDiff = GetAccount(Doc.ACCTTYPE_InvDifferences, as1);
                }
                cr = fact.CreateLine(line, invDiff,
                                     as1.GetC_Currency_ID(), Decimal.Negate(costs));
                if (cr == null)
                {
                    continue;
                }
                cr.SetM_Locator_ID(line.GetM_Locator_ID());
                cr.SetQty(Decimal.Negate(line.GetQty().Value));
                if (line.GetC_Charge_ID() != 0) //	explicit overwrite for charge
                {
                    cr.SetAD_Org_ID(line.GetAD_Org_ID());
                }
                if (!IsPosted())
                {
                    //	Cost Detail
                    MCostDetail.CreateInventory(as1, line.GetAD_Org_ID(),
                                                line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(),
                                                line.Get_ID(), 0,
                                                costs, line.GetQty().Value,
                                                line.GetDescription(), GetTrx(), GetRectifyingProcess());
                }
            }
            //
            List <Fact> facts = new List <Fact>();

            facts.Add(fact);
            return(facts);
        }