コード例 #1
0
        /// <summary>
        ///     Move stock to location
        /// </summary>
        /// <param name="target">storage</param>
        /// <returns>no of movements</returns>
        private int Move(MStorage target)
        {
            log.Info(target.ToString());
            Decimal qty = Decimal.Negate(target.GetQtyOnHand());//.negate();

            //	Create Movement
            MMovement mh = new MMovement(GetCtx(), 0, Get_Trx());

            mh.SetC_DocType_ID(_C_DocType_ID);
            mh.SetDescription(GetName());
            if (!mh.Save())
            {
                return(0);
            }

            int lines = 0;

            MStorage[] sources = GetSources(target.GetM_Product_ID(), target.GetM_Locator_ID());
            for (int i = 0; i < sources.Length; i++)
            {
                MStorage source = sources[i];

                //	Movement Line
                MMovementLine ml = new MMovementLine(mh);
                ml.SetM_Product_ID(target.GetM_Product_ID());
                ml.SetM_LocatorTo_ID(target.GetM_Locator_ID());
                ml.SetM_AttributeSetInstanceTo_ID(target.GetM_AttributeSetInstance_ID());
                //	From
                ml.SetM_Locator_ID(source.GetM_Locator_ID());
                ml.SetM_AttributeSetInstance_ID(source.GetM_AttributeSetInstance_ID());

                Decimal qtyMove = qty;
                if (qtyMove.CompareTo(source.GetQtyOnHand()) > 0)
                {
                    qtyMove = source.GetQtyOnHand();
                }
                ml.SetMovementQty(qtyMove);
                //
                lines++;
                ml.SetLine(lines * 10);
                if (!ml.Save())
                {
                    return(0);
                }

                qty = Decimal.Subtract(qty, qtyMove);
                if (Env.Signum(qty) <= 0)
                {
                    break;
                }
            }   //	for all movements

            //	Process
            //mh.ProcessIt(MMovement.ACTION_Complete);
            mh.ProcessIt(DocActionVariables.ACTION_COMPLETE);
            mh.Save();

            AddLog(0, null, new Decimal(lines), "@M_Movement_ID@ " + mh.GetDocumentNo() + " ("
                   + MRefList.Get(GetCtx(), MMovement.DOCSTATUS_AD_Reference_ID,
                                  mh.GetDocStatus(), Get_Trx()) + ")");

            EliminateReservation(target);
            return(lines);
        }