Esempio n. 1
0
        /// <summary>
        /// Create Facts (the accounting logic) for
        ///  MMM.
        ///  <pre>
        ///  Movement
        ///      Inventory       DR      CR
        ///      InventoryTo     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 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);

                //  ** Inventory       DR      CR
                dr = fact.CreateLine(line,
                                     line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1),
                                     as1.GetC_Currency_ID(), Decimal.Negate(costs)); //	from (-) CR
                if (dr == null)
                {
                    continue;
                }
                dr.SetM_Locator_ID(line.GetM_Locator_ID());
                dr.SetQty(Decimal.Negate(line.GetQty().Value)); //	outgoing

                //  ** InventoryTo     DR      CR
                cr = fact.CreateLine(line,
                                     line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1),
                                     as1.GetC_Currency_ID(), costs);    //	to (+) DR
                if (cr == null)
                {
                    continue;
                }
                cr.SetM_Locator_ID(line.GetM_LocatorTo_ID());
                cr.SetQty(line.GetQty());

                //	Only for between-org movements
                if (dr.GetAD_Org_ID() != cr.GetAD_Org_ID())
                {
                    String costingLevel      = as1.GetCostingLevel();
                    MProductCategoryAcct pca = MProductCategoryAcct.Get(GetCtx(),
                                                                        line.GetProduct().GetM_Product_Category_ID(),
                                                                        as1.GetC_AcctSchema_ID(), GetTrx());
                    if (pca.GetCostingLevel() != null)
                    {
                        costingLevel = pca.GetCostingLevel();
                    }
                    if (!MAcctSchema.COSTINGLEVEL_Organization.Equals(costingLevel))
                    {
                        continue;
                    }
                    //
                    String description = line.GetDescription();
                    if (description == null)
                    {
                        description = "";
                    }
                    if (!IsPosted())
                    {
                        //	Cost Detail From
                        MCostDetail.CreateMovement(as1, dr.GetAD_Org_ID(),      //	locator org
                                                   line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(),
                                                   line.Get_ID(), 0,
                                                   Decimal.Negate(costs), Decimal.Negate(line.GetQty().Value), true,
                                                   description + "(|->)", GetTrx(), GetRectifyingProcess());


                        //	Cost Detail To
                        MCostDetail.CreateMovement(as1, cr.GetAD_Org_ID(),      //	locator org
                                                   line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(),
                                                   line.Get_ID(), 0,
                                                   costs, line.GetQty().Value, false,
                                                   description + "(|<-)", GetTrx(), GetRectifyingProcess());
                    }
                }
            }

            //
            List <Fact> facts = new List <Fact>();

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