Esempio n. 1
0
        /// <summary>
        /// Create Confirmation or return existing one
        /// </summary>
        /// <param name="move">movement</param>
        /// <param name="checkExisting">if false, new confirmation is created</param>
        /// <returns>Confirmation</returns>
        public static MMovementConfirm Create(MMovement move, Boolean checkExisting)
        {
            if (checkExisting)
            {
                MMovementConfirm[] confirmations = move.GetConfirmations(false);
                for (int i = 0; i < confirmations.Length; i++)
                {
                    MMovementConfirm confirm1 = confirmations[i];
                    if (confirm1 != null)
                    {
                        return(confirm1);
                    }
                }
            }

            MMovementConfirm confirm = new MMovementConfirm(move);

            confirm.Save(move.Get_TrxName());
            MMovementLine[] moveLines = move.GetLines(false);
            for (int i = 0; i < moveLines.Length; i++)
            {
                MMovementLine        mLine = moveLines[i];
                MMovementLineConfirm cLine = new MMovementLineConfirm(confirm);
                cLine.SetMovementLine(mLine);
                cLine.Save(move.Get_TrxName());
            }
            return(confirm);
        }
Esempio n. 2
0
 /// <summary>
 /// Get Parent
 /// </summary>
 ///
 /// <returns>Parent Movement</returns>
 public MMovement GetParent()
 {
     if (_parent == null)
     {
         _parent = new MMovement(GetCtx(), GetM_Movement_ID(), Get_TrxName());
     }
     return(_parent);
 }
Esempio n. 3
0
        /// <summary>
        /// Load Document Details
        /// </summary>
        /// <returns>error message or null</returns>
        public override String LoadDocumentDetails()
        {
            SetC_Currency_ID(NO_CURRENCY);
            MMovement move = (MMovement)GetPO();

            SetDateDoc(move.GetMovementDate());
            SetDateAcct(move.GetMovementDate());
            //	Contained Objects
            _lines = LoadLines(move);
            log.Fine("Lines=" + _lines.Length);
            return(null);
        }
Esempio n. 4
0
        /// <summary>
        /// Load Invoice Line
        /// </summary>
        /// <param name="move"></param>
        /// <returns>document lines (DocLine_Material)</returns>
        private DocLine[] LoadLines(MMovement move)
        {
            List <DocLine> list = new List <DocLine>();

            MMovementLine[] lines = move.GetLines(false);
            for (int i = 0; i < lines.Length; i++)
            {
                MMovementLine line    = lines[i];
                DocLine       docLine = new DocLine(line, this);
                docLine.SetQty(line.GetMovementQty(), false);
                //
                log.Fine(docLine.ToString());
                list.Add(docLine);
            }

            //	Return Array
            DocLine[] dls = new DocLine[list.Count];
            dls = list.ToArray();
            return(dls);
        }
Esempio n. 5
0
        /// <summary>
        /// Create Confirmation or return existing one
        /// </summary>
        /// <param name="move">movement</param>
        /// <param name="checkExisting">if false, new confirmation is created</param>
        /// <returns>Confirmation</returns>
        public static MMovementConfirm Create(MMovement move, Boolean checkExisting)
        {
            if (checkExisting)
            {
                MMovementConfirm[] confirmations = move.GetConfirmations(false);
                for (int i = 0; i < confirmations.Length; i++)
                {
                    MMovementConfirm confirm1 = confirmations[i];
                    if (confirm1 != null)
                    {
                        return(confirm1);
                    }
                }
            }

            MMovementConfirm confirm = new MMovementConfirm(move);

            confirm.Save(move.Get_TrxName());
            MMovementLine[] moveLines = move.GetLines(false);
            for (int i = 0; i < moveLines.Length; i++)
            {
                MMovementLine        mLine = moveLines[i];
                MMovementLineConfirm cLine = new MMovementLineConfirm(confirm);
                cLine.SetMovementLine(mLine);
                // setting QtyEntered in Target Qty on Confirmation Line
                cLine.SetTargetQty(mLine.GetQtyEntered());
                cLine.SetConfirmedQty(mLine.GetQtyEntered());
                cLine.Save(move.Get_TrxName());
            }
            // Change By Arpit Rai on 24th August,2017 To Check if VA Material Quality Control Module exists or not
            if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(*) FROM AD_ModuleInfo WHERE Prefix='VA010_'", null, null)) > 0)
            {
                CreateConfirmParameters(move, confirm.GetM_MovementConfirm_ID(), confirm.GetCtx());
            }
            return(confirm);
        }
 public bool SetProductQty1(int recordID, string keyColName, List <string> product, List <string> attribute, List <string> qty, List <string> oline_ID, List <string> locID, int LocToID, List <string> AssetID, int lineID, VAdvantage.Utility.Ctx ctx)
 {
     if (keyColName.ToUpper().Trim() == "M_MOVEMENT_ID")
     {
         MMovement inv = new MMovement(ctx, recordID, null);
         for (int i = 0; i < product.Count; i++)
         {
             MMovementLine invline = new MMovementLine(ctx, lineID, null);
             invline.SetAD_Client_ID(inv.GetAD_Client_ID());
             invline.SetAD_Org_ID(inv.GetAD_Org_ID());
             invline.SetM_Locator_ID(Util.GetValueOfInt(locID[i]));
             invline.SetM_LocatorTo_ID(LocToID);
             invline.SetM_Product_ID(Util.GetValueOfInt(product[i]));
             invline.SetMovementQty(Util.GetValueOfDecimal(qty[i]));
             invline.SetM_Movement_ID(recordID);
             if (Util.GetValueOfInt(AssetID[i]) > 0)
             {
                 invline.SetA_Asset_ID(Util.GetValueOfInt(AssetID[i]));
             }
             if (Util.GetValueOfInt(oline_ID[i]) > 0)
             {
                 invline.SetM_RequisitionLine_ID(Util.GetValueOfInt(oline_ID[i]));
             }
             if (Util.GetValueOfInt(attribute[i]) != 0)
             {
                 invline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i]));
             }
             if (!invline.Save())
             {
             }
         }
     }
     else if (keyColName.ToUpper().Trim() == "M_INVENTORY_ID")
     {
         MInventory inv = new MInventory(ctx, recordID, null);
         for (int i = 0; i < product.Count; i++)
         {
             MInventoryLine invline = new MInventoryLine(ctx, lineID, null);
             invline.SetAD_Client_ID(inv.GetAD_Client_ID());
             invline.SetAD_Org_ID(inv.GetAD_Org_ID());
             invline.SetM_Product_ID(Util.GetValueOfInt(product[i]));
             invline.SetQtyInternalUse(Util.GetValueOfDecimal(qty[i]));
             invline.SetC_Charge_ID(Util.GetValueOfInt(AssetID[i]));
             invline.SetM_Inventory_ID(recordID);
             invline.SetIsInternalUse(true);
             invline.SetM_RequisitionLine_ID(Util.GetValueOfInt(oline_ID[i]));
             if (Util.GetValueOfInt(attribute[i]) != 0)
             {
                 invline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i]));
             }
             else
             {
                 invline.SetM_AttributeSetInstance_ID(0);
             }
             if (!invline.Save())
             {
             }
         }
     }
     return(true);
 }
        /// <summary>
        /// Before Save
        /// </summary>
        /// <param name="newRecord">new</param>
        /// <returns>true</returns>
        protected override Boolean BeforeSave(Boolean newRecord)
        {
            Decimal  VA024_ProvisionPrice = 0;
            MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID());

            // chck pallet Functionality applicable or not
            bool isContainrApplicable = MTransaction.ProductContainerApplicable(GetCtx());

            // Get Old Value of AttributeSetInstance_ID
            _mvlOldAttId = Util.GetValueOfInt(Get_ValueOld("M_AttributeSetInstance_ID"));

            //	Set Line No
            if (GetLine() == 0)
            {
                String sql = "SELECT COALESCE(MAX(Line),0)+10 AS DefaultValue FROM M_MovementLine WHERE M_Movement_ID=" + GetM_Movement_ID();
                int    ii  = DataBase.DB.GetSQLValue(Get_TrxName(), sql);
                SetLine(ii);
            }

            // JID_0775: System is not checking on move line that the attribute set instance is mandatory.
            if (GetM_AttributeSetInstance_ID() == 0)
            {
                if (product != null && product.GetM_AttributeSet_ID() != 0)
                {
                    MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID());
                    if (mas.IsMandatory() || mas.IsMandatoryAlways())
                    {
                        log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstance_ID"));
                        return(false);
                    }
                }
            }

            // Check Locator For Header Warehouse
            MMovement mov = new MMovement(GetCtx(), GetM_Movement_ID(), Get_TrxName());
            MLocator  loc = new MLocator(GetCtx(), GetM_Locator_ID(), Get_TrxName());
            Tuple <string, string, string> aInfo = null;

            if (Env.HasModulePrefix("DTD001_", out aInfo))
            {
                if (mov.GetDTD001_MWarehouseSource_ID() == loc.GetM_Warehouse_ID())
                {
                }
                else
                {
                    String sql = "SELECT M_Locator_ID FROM M_Locator WHERE M_Warehouse_ID=" + mov.GetDTD001_MWarehouseSource_ID() + " AND IsDefault = 'Y'";
                    int    ii  = DataBase.DB.GetSQLValue(Get_TrxName(), sql);
                    SetM_Locator_ID(ii);
                }
            }

            // when we try to move product from container to container which are in same locator then no need to check this case
            if (GetM_Locator_ID() == GetM_LocatorTo_ID() &&
                (Get_ColumnIndex("M_ProductContainer_ID") > 0 && Get_ColumnIndex("Ref_M_ProductContainerTo_ID") > 0 &&
                 !(GetM_ProductContainer_ID() > 0 || GetRef_M_ProductContainerTo_ID() > 0)))
            {
                log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "'From @M_Locator_ID@' and '@M_LocatorTo_ID@' cannot be same."));//change message according to requirement
                return(false);
            }

            if (Env.Signum(GetMovementQty()) == 0 && Util.GetValueOfInt(GetTargetQty()) == 0)
            {
                log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "MovementQty"));
                return(false);
            }

            Tuple <String, String, String> mInfo = null;

            if (Env.HasModulePrefix("DTD001_", out mInfo))
            {
                if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Product_ID")) != GetM_Product_ID())
                {
                    log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ProdNotChanged"));
                    return(false);
                }
                if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Locator_ID")) != GetM_Locator_ID())
                {
                    log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_LocatorNotChanged"));
                    return(false);
                }
                if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_RequisitionLine_ID")) != GetM_RequisitionLine_ID())
                {
                    log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ReqNotChanged"));
                    return(false);
                }
            }
            //if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA203_'", null, null)) > 0)
            if (Env.IsModuleInstalled("VA203_"))
            {
                if (GetM_RequisitionLine_ID() > 0)
                {
                    MRequisitionLine reqline = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), Get_Trx());        // Trx used to handle query stuck problem
                    if (GetM_AttributeSetInstance_ID() != reqline.GetM_AttributeSetInstance_ID())
                    {
                        log.SaveError("Message", Msg.GetMsg(GetCtx(), "VA203_AttributeInstanceMustBeSame"));
                        return(false);
                    }
                }
            }
            // IF Doc Status = InProgress then No record Save
            MMovement move = new MMovement(GetCtx(), GetM_Movement_ID(), Get_Trx());        // Trx used to handle query stuck problem

            if (newRecord && move.GetDocStatus() == "IP")
            {
                log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_CannotCreate"));
                return(false);
            }

            //	Qty Precision
            if (newRecord || Is_ValueChanged("QtyEntered"))
            {
                SetQtyEntered(GetQtyEntered());
            }

            // change to set Converted Quantity in Movement quantity if there is differnce in UOM of Base Product and UOM Selected on line
            if (newRecord || Is_ValueChanged("QtyEntered") || Is_ValueChanged("C_UOM_ID"))
            {
                Decimal?qty = Util.GetValueOfDecimal(Get_Value("QtyEntered"));
                if (product.GetC_UOM_ID() != Util.GetValueOfInt(Get_Value("C_UOM_ID")))
                {
                    SetMovementQty(MUOMConversion.ConvertProductFrom(GetCtx(), GetM_Product_ID(), Util.GetValueOfInt(Get_Value("C_UOM_ID")), Util.GetValueOfDecimal(Get_Value("QtyEntered"))));
                }
            }

            //	Qty Precision
            if (newRecord || Is_ValueChanged("QtyEntered"))
            {
                SetMovementQty(GetMovementQty());
            }

            string qry;

            if (!mov.IsProcessing() || newRecord)
            {
                MWarehouse wh = null; MWarehouse whTo = null;
                wh   = MWarehouse.Get(GetCtx(), mov.GetDTD001_MWarehouseSource_ID());
                whTo = MWarehouse.Get(GetCtx(), MLocator.Get(GetCtx(), GetM_LocatorTo_ID()).GetM_Warehouse_ID());

                qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)),0) AS QtyOnHand FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID();
                if (GetDTD001_AttributeNumber() == null || GetM_AttributeSetInstance_ID() > 0)
                {
                    qry += " AND NVL(M_AttributeSetInstance_ID , 0) =" + GetM_AttributeSetInstance_ID();
                }
                OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry));

                qry         = "SELECT NVL(SUM(NVL(QtyOnHand,0)),0) AS QtyOnHand FROM M_Storage where m_locator_id=" + GetM_LocatorTo_ID() + " and m_product_id=" + GetM_Product_ID();
                qry        += " AND NVL(M_AttributeSetInstance_ID, 0) =" + GetM_AttributeSetInstance_ID();
                OnHandQtyTo = Convert.ToDecimal(DB.ExecuteScalar(qry));

                // SI_0635 : System is giving error of insufficient qty if disallow is true in TO warehouse and false in From warehouse
                // when record is in completed & closed stage - then no need to check qty availablity in warehouse
                if ((wh.IsDisallowNegativeInv() || whTo.IsDisallowNegativeInv()) &&
                    (!(move.GetDocStatus() == "CO" || move.GetDocStatus() == "CL" || move.GetDocStatus() == "RE" || move.GetDocStatus() == "VO")))
                {
                    // pick container current qty from transaction based on locator / product / ASI / Container / Movement Date
                    if (isContainrApplicable && Get_ColumnIndex("M_ProductContainer_ID") >= 0)
                    {
                        //                    qry = @"SELECT SUM(t.ContainerCurrentQty) keep (dense_rank last ORDER BY t.MovementDate, t.M_Transaction_ID) AS CurrentQty FROM m_transaction t
                        //                            INNER JOIN M_Locator l ON t.M_Locator_ID = l.M_Locator_ID WHERE t.MovementDate <= " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) +
                        //                                " AND t.AD_Client_ID = " + GetAD_Client_ID() +
                        //                                @" AND t.M_Locator_ID = " + (move.IsReversal() && GetMovementQty() < 0 ? GetM_LocatorTo_ID() : GetM_Locator_ID()) +
                        //                                " AND t.M_Product_ID = " + GetM_Product_ID() + " AND NVL(t.M_AttributeSetInstance_ID,0) = " + GetM_AttributeSetInstance_ID() +
                        //                                " AND NVL(t.M_ProductContainer_ID, 0) = " + (move.IsReversal() && !IsMoveFullContainer() && GetMovementQty() < 0 ? GetRef_M_ProductContainerTo_ID() : GetM_ProductContainer_ID());
                        //                    containerQty = Util.GetValueOfDecimal(DB.ExecuteScalar(qry.ToString(), null, null));  // dont use Transaction here - otherwise impact goes wrong on completion

                        //                    qry = @"SELECT SUM(t.ContainerCurrentQty) keep (dense_rank last ORDER BY t.MovementDate, t.M_Transaction_ID) AS CurrentQty FROM m_transaction t
                        //                            INNER JOIN M_Locator l ON t.M_Locator_ID = l.M_Locator_ID WHERE t.MovementDate <= " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) +
                        //                               " AND t.AD_Client_ID = " + GetAD_Client_ID() +
                        //                               @" AND t.M_Locator_ID = " + (move.IsReversal() && GetMovementQty() < 0 ? GetM_Locator_ID() : GetM_LocatorTo_ID()) +
                        //                               " AND t.M_Product_ID = " + GetM_Product_ID() + " AND NVL(t.M_AttributeSetInstance_ID,0) = " + GetM_AttributeSetInstance_ID() +
                        //                               " AND NVL(t.M_ProductContainer_ID, 0) = " + (move.IsReversal() && !IsMoveFullContainer() && GetMovementQty() < 0 ? GetM_ProductContainer_ID() : GetRef_M_ProductContainerTo_ID());
                        //                    containerQtyTo = Util.GetValueOfDecimal(DB.ExecuteScalar(qry.ToString(), null, null));  // dont use Transaction here - otherwise impact goes wrong on completion

                        qry = @"SELECT DISTINCT First_VALUE(t.ContainerCurrentQty) OVER (PARTITION BY t.M_Product_ID, t.M_AttributeSetInstance_ID ORDER BY t.MovementDate DESC, t.M_Transaction_ID DESC) AS CurrentQty FROM m_transaction t 
                                                INNER JOIN M_Locator l ON t.M_Locator_ID = l.M_Locator_ID WHERE t.MovementDate <= " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) +
                              " AND t.AD_Client_ID = " + GetAD_Client_ID() +
                              @" AND t.M_Locator_ID = " + GetM_Locator_ID() +
                              " AND t.M_Product_ID = " + GetM_Product_ID() + " AND NVL(t.M_ProductContainer_ID, 0) = " + GetM_ProductContainer_ID();

                        // In Case of Attribute Number do not check qty with attribute from storage
                        if (GetDTD001_AttributeNumber() == null || GetM_AttributeSetInstance_ID() > 0)
                        {
                            qry += " AND NVL(M_AttributeSetInstance_ID , 0) =" + GetM_AttributeSetInstance_ID();
                        }

                        containerQty = Util.GetValueOfDecimal(DB.ExecuteScalar(qry.ToString(), null, null));  // dont use Transaction here - otherwise impact goes wrong on completion

                        qry = @"SELECT DISTINCT First_VALUE(t.ContainerCurrentQty) OVER (PARTITION BY t.M_Product_ID, t.M_AttributeSetInstance_ID ORDER BY t.MovementDate DESC, t.M_Transaction_ID DESC)  AS CurrentQty FROM m_transaction t 
                                                INNER JOIN M_Locator l ON t.M_Locator_ID = l.M_Locator_ID WHERE t.MovementDate <= " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) +
                              " AND t.AD_Client_ID = " + GetAD_Client_ID() +
                              @" AND t.M_Locator_ID = " + GetM_LocatorTo_ID() +
                              " AND t.M_Product_ID = " + GetM_Product_ID() + " AND NVL(t.M_AttributeSetInstance_ID,0) = " + GetM_AttributeSetInstance_ID() +
                              " AND NVL(t.M_ProductContainer_ID, 0) = " + GetRef_M_ProductContainerTo_ID();
                        containerQtyTo = Util.GetValueOfDecimal(DB.ExecuteScalar(qry.ToString(), null, null));  // dont use Transaction here - otherwise impact goes wrong on completion
                    }

                    if (wh.IsDisallowNegativeInv() && (OnHandQty - GetMovementQty()) < 0)
                    {
                        // check for From Locator
                        log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty);
                        return(false);
                    }
                    else if (isContainrApplicable && wh.IsDisallowNegativeInv() && Get_ColumnIndex("M_ProductContainer_ID") >= 0 && (containerQty - GetMovementQty()) < 0)
                    {
                        // check container qty -  for From Locator
                        log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQtyContainer") + containerQty);
                        return(false);
                    }
                    else if (whTo.IsDisallowNegativeInv() && (OnHandQtyTo + GetMovementQty()) < 0)
                    {
                        // check for To Locator
                        log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQtyTo);
                        return(false);
                    }
                    else if (isContainrApplicable && whTo.IsDisallowNegativeInv() && Get_ColumnIndex("M_ProductContainer_ID") >= 0 && (containerQtyTo + GetMovementQty()) < 0)
                    {
                        // check for To Locator
                        log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQtyContainerTo") + containerQtyTo);
                        return(false);
                    }
                }
            }

            if (Env.IsModuleInstalled("DTD001_"))
            {
                // not used this variable, that why commented
                //qry = "SELECT   NVL(SUM(NVL(QtyOnHand,0)- qtyreserved),0) AS QtyAvailable  FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID();
                //if (GetM_AttributeSetInstance_ID() != 0)
                //{
                //    qry += " AND NVL(M_AttributeSetInstance_ID , 0) = " + GetM_AttributeSetInstance_ID();
                //}
                //qtyAvailable = Convert.ToDecimal(DB.ExecuteScalar(qry));
                qtyReserved = Util.GetValueOfDecimal(Get_ValueOld("MovementQty"));
                //if (wh.IsDisallowNegativeInv() == true)
                //{
                //    if ((qtyAvailable < (GetMovementQty() - qtyReserved)))
                //    {
                //        log.SaveError("Message", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "DTD001_QtyNotAvailable"));
                //        return false;
                //    }
                //}
            }

            //By Amit - 17-April-2017
            if (Env.IsModuleInstalled("VA024_"))
            {
                // checking are we moving product from one warehouse to other warehouse
                if (Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT CASE WHEN ((SELECT CASE WHEN o.IsLegalEntity = 'Y' THEN w.AD_Org_ID
                 ELSE (SELECT AD_Org_ID FROM AD_Org WHERE Ad_Org_id = o.LegalEntityOrg ) END
                 FROM m_warehouse w INNER JOIN ad_org o ON o.AD_Org_ID = w.AD_Org_ID WHERE w.m_warehouse_id = m.DTD001_MWarehouseSource_ID)) =
                 (SELECT  CASE WHEN o2.IsLegalEntity = 'Y' THEN w2.AD_Org_ID 
                 ELSE (SELECT AD_Org_ID FROM AD_Org WHERE Ad_Org_id = o2.LegalEntityOrg) END
                 FROM m_warehouse w2 INNER JOIN ad_org o2 ON o2.AD_Org_ID = w2.AD_Org_ID WHERE M_Warehouse_ID = m.M_Warehouse_ID )
                 THEN 0 ELSE (SELECT ad_org_id FROM m_warehouse WHERE M_Warehouse_ID = m.M_Warehouse_ID ) END AS result FROM m_movement m WHERE m_movement_id = " + GetM_Movement_ID(), null, Get_Trx())) > 0)
                {
                    string qry1 = @"SELECT  SUM(o.VA024_UnitPrice)   FROM VA024_t_ObsoleteInventory o 
                                  WHERE o.IsActive = 'Y' AND  o.M_Product_ID = " + GetM_Product_ID() + @" and 
                                  ( o.M_AttributeSetInstance_ID = " + GetM_AttributeSetInstance_ID() + @" OR o.M_AttributeSetInstance_ID IS NULL )" +
                                  " AND o.AD_Org_ID = " + GetAD_Org_ID();
                    VA024_ProvisionPrice = Util.GetValueOfDecimal(DB.ExecuteScalar(qry1, null, Get_Trx()));
                    SetVA024_UnitPrice(Util.GetValueOfDecimal(VA024_ProvisionPrice * GetMovementQty()));

                    // is used to get cost of binded cost method / costing level of primary accounting schema
                    Decimal cost = MCost.GetproductCosts(move.GetAD_Client_ID(), move.GetAD_Org_ID(), GetM_Product_ID(),
                                                         GetM_AttributeSetInstance_ID(), Get_Trx(), move.GetDTD001_MWarehouseSource_ID());
                    SetVA024_CostPrice((cost - VA024_ProvisionPrice) * GetMovementQty());
                }
            }

            //	Mandatory Instance
            if (GetM_AttributeSetInstanceTo_ID() == 0)
            {
                if (GetM_AttributeSetInstance_ID() != 0)        //	Set to from
                {
                    SetM_AttributeSetInstanceTo_ID(GetM_AttributeSetInstance_ID());
                }
                else
                {
                    if (Env.HasModulePrefix("DTD001_", out mInfo))
                    {
                        //MProduct product = GetProduct();
                        if (product != null &&
                            product.GetM_AttributeSet_ID() != 0)
                        {
                            //MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID());
                            //if (mas.IsInstanceAttribute()
                            //    && (mas.IsMandatory() || mas.IsMandatoryAlways()))
                            //{
                            //    log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID"));
                            //    return false;
                            //}

                            // Code Addeded by Bharat as Discussed with Mukesh Sir
                            if (String.IsNullOrEmpty(GetDTD001_AttributeNumber()))
                            {
                                return(true);
                            }
                            else
                            {
                                if (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null)
                                {
                                    log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber"));

                                    return(false);
                                }
                            }

                            //JID_1422: Check No Of Attributes Are Equal To Quantity Or Less Than

                            int Count = CountAttributes(GetDTD001_AttributeNumber());
                            if (Count != GetQtyEntered())
                            {
                                if (Count > GetQtyEntered())
                                {
                                    log.SaveError("DTD001_MovementAttrbtGreater", "");
                                    return(false);
                                }
                                else
                                {
                                    log.SaveError("DTD001_MovementAttrbtLess", "");
                                    return(false);
                                }
                            }
                        }
                        else
                        {
                            if (product != null)
                            {
                                if (product.GetM_AttributeSet_ID() == 0 && (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null))
                                {
                                    return(true);
                                }
                                else
                                {
                                    //log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber"));
                                    //ShowMessage.Info("a", true, "Product is not of Attribute Type", null);
                                    log.SaveError("Product is not of Attribute Type", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber"));
                                    return(false);
                                }

                                //Check No Of Attributes Are Equal To Quantity Or Less Than

                                //int Count = CountAttributes(GetDTD001_AttributeNumber());
                                //if (Count != GetMovementQty())
                                //{
                                //    if (Count > GetMovementQty())
                                //    {
                                //        log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtGreater"));
                                //        return false;
                                //    }
                                //    else
                                //    {
                                //        log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtLess"));
                                //        return false;
                                //    }
                                //}
                            }
                        }
                    }
                    else
                    {
                        //MProduct product = GetProduct();
                        if (product != null &&
                            product.GetM_AttributeSet_ID() != 0)
                        {
                            MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID());
                            if (mas.IsInstanceAttribute() &&
                                (mas.IsMandatory() || mas.IsMandatoryAlways()))
                            {
                                log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID"));
                                return(false);
                            }
                        }
                    }
                }
            }    //	ASI
            return(true);
        }
Esempio n. 8
0
        /// <summary>
        /// Process
        /// </summary>
        /// <returns>info</returns>
        protected override String DoIt()
        {
            log.Info("M_Movement_ID=" + _m_Movement_ID
                     + ", M_Locator_ID=" + _m_Locator_ID + ", M_LocatorTo_ID=" + _m_LocatorTo_ID
                     + ", M_Product_ID=" + _m_product_ID
                     + ", M_Product_Category_ID=" + _m_Product_Category_ID
                     + ", QtyRange=" + _qtyRange + ", DeleteOld=" + _deleteOld);
            _movement = new MMovement(GetCtx(), _m_Movement_ID, Get_Trx());
            if (_movement.Get_ID() == 0)
            {
                throw new SystemException("Not found: M_Movement_ID=" + _m_Movement_ID);
            }
            if (_movement.IsProcessed())
            {
                throw new SystemException("@M_Movement_ID@ @Processed@");
            }
            //
            String sqlQry = "";

            if (_deleteOld)
            {
                sqlQry = "DELETE FROM M_MovementLine WHERE Processed='N' "
                         + "AND M_Movement_ID=" + _m_Movement_ID;
                int no = DB.ExecuteQuery(sqlQry, null, Get_Trx());
                log.Fine("doIt - Deleted #" + no);
            }

            //	Create Null Storage records
            if (_qtyRange != null && _qtyRange.Equals("="))
            {
                sqlQry = "INSERT INTO M_Storage "
                         + "(AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,"
                         + " M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID,"
                         + " qtyOnHand, QtyReserved, QtyOrdered, DateLastInventory) "
                         + "SELECT l.AD_CLIENT_ID, l.AD_ORG_ID, 'Y', SysDate, 0,SysDate, 0,"
                         + " l.M_Locator_ID, p.M_Product_ID, 0,"
                         + " 0,0,0,null "
                         + "FROM M_Locator l"
                         + " INNER JOIN M_Product p ON (l.AD_Client_ID=p.AD_Client_ID) "
                         + "WHERE l.M_Warehouse_ID=" + _movement.GetM_Warehouse_ID();
                if (_m_Locator_ID != 0)
                {
                    sqlQry += " AND l.M_Locator_ID=" + _m_Locator_ID;
                }
                sqlQry += " AND l.IsDefault='Y'"
                          + " AND p.IsActive='Y' AND p.IsStocked='Y' and p.ProductType='I'"
                          + " AND NOT EXISTS (SELECT * FROM M_Storage s"
                          + " INNER JOIN M_Locator sl ON (s.M_Locator_ID=sl.M_Locator_ID) "
                          + "WHERE sl.M_Warehouse_ID=l.M_Warehouse_ID"
                          + " AND s.M_Product_ID=p.M_Product_ID)";
                int no = DB.ExecuteQuery(sqlQry, null, Get_Trx());
                log.Fine("'0' Inserted #" + no);
            }

            StringBuilder sql = new StringBuilder(
                "SELECT s.M_Product_ID, s.M_Locator_ID, s.M_AttributeSetInstance_ID,"
                + " s.qtyOnHand, p.M_AttributeSet_ID "
                + "FROM M_Product p"
                + " INNER JOIN M_Storage s ON (s.M_Product_ID=p.M_Product_ID)"
                + " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID) "
                + "WHERE l.M_Warehouse_ID=" + _movement.GetDTD001_MWarehouseSource_ID()
                + " AND p.IsActive='Y' AND p.IsStocked='Y' and p.ProductType='I'");

            //
            if (_m_Locator_ID != 0)
            {
                sql.Append(" AND s.M_Locator_ID=" + _m_Locator_ID);
            }

            //
            if (_m_product_ID != null && !string.IsNullOrEmpty(_m_product_ID))
            {
                sql.Append(" AND  p.M_Product_ID IN ( " + _m_product_ID + ") ");
            }
            //
            if (_m_Product_Category_ID != 0)
            {
                sql.Append(" AND p.M_Product_Category_ID=" + _m_Product_Category_ID);
            }

            //	Do not overwrite existing records
            if (!_deleteOld)
            {
                sql.Append(" AND NOT EXISTS (SELECT * FROM M_MovementLine il "
                           + "WHERE il.M_Movement_ID=" + _m_Movement_ID
                           + " AND il.M_Product_ID=s.M_Product_ID"
                           + " AND il.M_Locator_ID=s.M_Locator_ID"
                           + " AND COALESCE(il.M_AttributeSetInstance_ID,0)=COALESCE(s.M_AttributeSetInstance_ID,0))");
            }
            //	+ " AND il.M_AttributeSetInstance_ID=s.M_AttributeSetInstance_ID)");
            //
            sql.Append(" ORDER BY l.Value, p.Value, s.qtyOnHand DESC"); //	Locator/Product
            //
            int         count = 0;
            IDataReader idr   = null;

            try
            {
                idr = DB.ExecuteReader(sql.ToString(), null, Get_Trx());
                while (idr.Read())
                {
                    int     M_Product_ID = Util.GetValueOfInt(idr[0]);
                    int     M_Locator_ID = Util.GetValueOfInt(idr[1]);
                    int     M_AttributeSetInstance_ID = Util.GetValueOfInt(idr[2]);
                    Decimal qtyOnHand = Util.GetValueOfDecimal(idr[3]);
                    if (qtyOnHand == null)
                    {
                        qtyOnHand = Env.ZERO;
                    }
                    int M_AttributeSet_ID = Util.GetValueOfInt(idr[4]);
                    //
                    int compare = qtyOnHand.CompareTo(Env.ZERO);
                    if (_qtyRange == null ||
                        (_qtyRange.Equals(">") && compare > 0) ||
                        (_qtyRange.Equals("<") && compare < 0) ||
                        (_qtyRange.Equals("=") && compare == 0) ||
                        (_qtyRange.Equals("N") && compare != 0))
                    {
                        //Save data on Movement Line
                        _line = new MMovementLine(GetCtx(), 0, Get_Trx());
                        _line.SetAD_Client_ID(_movement.GetAD_Client_ID());
                        _line.SetAD_Org_ID(_movement.GetAD_Org_ID());
                        _line.SetM_Movement_ID(_m_Movement_ID);
                        _line.SetM_Locator_ID(_m_Locator_ID);
                        _line.SetM_LocatorTo_ID(_m_LocatorTo_ID);
                        _line.SetMovementQty(qtyOnHand);
                        _line.SetProcessed(false);
                        _line.SetM_AttributeSetInstance_ID(M_AttributeSetInstance_ID);
                        _line.SetM_Product_ID(M_Product_ID);
                        if (!_line.Save())
                        {
                            log.Info("Movement Line Not Created for M_Product_ID = " + M_Product_ID + " M_AttributeSetInstance =  " + M_AttributeSetInstance_ID);
                        }
                        else
                        {
                            count = count + 1;
                        }
                    }
                }
                idr.Close();
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                log.Log(Level.SEVERE, sql.ToString(), e);
            }

            //
            return("@M_MovementLine_ID@ - #" + count);
        }
Esempio n. 9
0
        /// <summary>
        /// Before Save
        /// </summary>
        /// <param name="newRecord">new</param>
        /// <returns>true</returns>
        protected override Boolean BeforeSave(Boolean newRecord)
        {
            Decimal  VA024_ProvisionPrice = 0;
            MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID());

            // By vikas
            // Get Old Value of AttributeSetInstance_ID
            _mvlOldAttId = Util.GetValueOfInt(Get_ValueOld("M_AttributeSetInstance_ID"));

            //	Set Line No
            if (GetLine() == 0)
            {
                String sql = "SELECT COALESCE(MAX(Line),0)+10 AS DefaultValue FROM M_MovementLine WHERE M_Movement_ID=" + GetM_Movement_ID();
                int    ii  = DataBase.DB.GetSQLValue(Get_TrxName(), sql);
                SetLine(ii);
            }

            // Check Locator For Header Warehouse
            MMovement mov = new MMovement(GetCtx(), GetM_Movement_ID(), Get_TrxName());
            MLocator  loc = new MLocator(GetCtx(), GetM_Locator_ID(), Get_TrxName());
            Tuple <string, string, string> aInfo = null;

            if (Env.HasModulePrefix("DTD001_", out aInfo))
            {
                if (mov.GetDTD001_MWarehouseSource_ID() == loc.GetM_Warehouse_ID())
                {
                }
                else
                {
                    String sql = "SELECT M_Locator_ID FROM M_Locator WHERE M_Warehouse_ID=" + mov.GetDTD001_MWarehouseSource_ID() + " AND IsDefault = 'Y'";
                    int    ii  = DataBase.DB.GetSQLValue(Get_TrxName(), sql);
                    SetM_Locator_ID(ii);
                }
            }

            if (GetM_Locator_ID() == GetM_LocatorTo_ID())
            {
                log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "'From @M_Locator_ID@' and '@M_LocatorTo_ID@' cannot be same."));//change message according to requirement
                return(false);
            }

            if (Env.Signum(GetMovementQty()) == 0 && Util.GetValueOfInt(GetTargetQty()) == 0)
            {
                log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "MovementQty"));
                return(false);
            }
            //Amit
            Tuple <String, String, String> mInfo = null;

            if (Env.HasModulePrefix("DTD001_", out mInfo))
            {
                if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Product_ID")) != GetM_Product_ID())
                {
                    log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ProdNotChanged"));
                    return(false);
                }
                if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Locator_ID")) != GetM_Locator_ID())
                {
                    log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_LocatorNotChanged"));
                    return(false);
                }
                if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_RequisitionLine_ID")) != GetM_RequisitionLine_ID())
                {
                    log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ReqNotChanged"));
                    return(false);
                }
            }
            //if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA203_'", null, null)) > 0)
            if (Env.IsModuleInstalled("VA203_"))
            {
                if (GetM_RequisitionLine_ID() > 0)
                {
                    MRequisitionLine reqline = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), Get_Trx());        // Trx used to handle query stuck problem
                    if (GetM_AttributeSetInstance_ID() != reqline.GetM_AttributeSetInstance_ID())
                    {
                        log.SaveError("Message", Msg.GetMsg(GetCtx(), "VA203_AttributeInstanceMustBeSame"));
                        return(false);
                    }
                }
            }
            // IF Doc Status = InProgress then No record Save
            MMovement move = new MMovement(GetCtx(), GetM_Movement_ID(), Get_Trx());        // Trx used to handle query stuck problem

            if (newRecord && move.GetDocStatus() == "IP")
            {
                log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_CannotCreate"));
                return(false);
            }

            // change to set Converted Quantity in Movement quantity if there is differnce in UOM of Base Product and UOM Selected on line
            if (newRecord || Is_ValueChanged("QtyEntered") || Is_ValueChanged("C_UOM_ID"))
            {
                Decimal?qty = Util.GetValueOfDecimal(Get_Value("QtyEntered"));
                if (product.GetC_UOM_ID() != Util.GetValueOfInt(Get_Value("C_UOM_ID")))
                {
                    SetMovementQty(MUOMConversion.ConvertProductFrom(GetCtx(), GetM_Product_ID(), Util.GetValueOfInt(Get_Value("C_UOM_ID")), Util.GetValueOfDecimal(Get_Value("QtyEntered"))));
                }
            }

            //	Qty Precision
            if (newRecord || Is_ValueChanged("QtyEntered"))
            {
                SetMovementQty(GetMovementQty());
            }
            MWarehouse wh = null; MWarehouse whTo = null;

            //string qry = "select m_warehouse_id from m_locator where m_locator_id=" + GetM_Locator_ID();
            //M_Warehouse_ID = Util.GetValueOfInt(DB.ExecuteScalar(qry));

            wh   = MWarehouse.Get(GetCtx(), mov.GetDTD001_MWarehouseSource_ID());
            whTo = MWarehouse.Get(GetCtx(), mov.GetM_Warehouse_ID());

            string qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)),0) AS QtyOnHand FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID();

            if (GetM_AttributeSetInstance_ID() != 0)
            {
                qry += " AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID();
            }
            OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry));

            qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)),0) AS QtyOnHand FROM M_Storage where m_locator_id=" + GetM_LocatorTo_ID() + " and m_product_id=" + GetM_Product_ID();
            if (GetM_AttributeSetInstance_ID() != 0)
            {
                qry += " AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID();
            }
            OnHandQtyTo = Convert.ToDecimal(DB.ExecuteScalar(qry));

            // SI_0635 : System is giving error of insufficient qty if disallow is true in TO warehouse and false in From warehouse
            // when record is in completed & closed stage - then no need to check qty availablity in warehouse
            if ((wh.IsDisallowNegativeInv() || whTo.IsDisallowNegativeInv()) &&
                (!(move.GetDocStatus() == "CO" || move.GetDocStatus() == "CL" || move.GetDocStatus() == "RE" || move.GetDocStatus() == "VO")))
            {
                if (wh.IsDisallowNegativeInv() && (OnHandQty - GetMovementQty()) < 0)
                {
                    // check for From Locator
                    log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty);
                    return(false);
                }
                else if (whTo.IsDisallowNegativeInv() && (OnHandQtyTo + GetMovementQty()) < 0)
                {
                    // check for To Locator
                    log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQtyTo);
                    return(false);
                }
            }
            if (Env.HasModulePrefix("DTD001_", out mInfo))
            {
                qry = "SELECT   NVL(SUM(NVL(QtyOnHand,0)- qtyreserved),0) AS QtyAvailable  FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID();
                if (GetM_AttributeSetInstance_ID() != 0)
                {
                    qry += " AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID();
                }
                qtyAvailable = Convert.ToDecimal(DB.ExecuteScalar(qry));
                qtyReserved  = Util.GetValueOfDecimal(Get_ValueOld("MovementQty"));
                //if (wh.IsDisallowNegativeInv() == true)
                //{
                //    if ((qtyAvailable < (GetMovementQty() - qtyReserved)))
                //    {
                //        log.SaveError("Message", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "DTD001_QtyNotAvailable"));
                //        return false;
                //    }
                //}
            }

            //By Amit - 17-April-2017
            if (Env.IsModuleInstalled("VA024_"))
            {
                // checking are we moving product from one warehouse to other warehouse
                if (Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT CASE WHEN ((SELECT CASE WHEN o.IsLegalEntity = 'Y' THEN w.AD_Org_ID
                 ELSE (SELECT AD_Org_ID FROM AD_Org WHERE Ad_Org_id = o.LegalEntityOrg ) END
                 FROM m_warehouse w INNER JOIN ad_org o ON o.AD_Org_ID = w.AD_Org_ID WHERE w.m_warehouse_id = m.DTD001_MWarehouseSource_ID)) =
                 (SELECT  CASE WHEN o2.IsLegalEntity = 'Y' THEN w2.AD_Org_ID 
                 ELSE (SELECT AD_Org_ID FROM AD_Org WHERE Ad_Org_id = o2.LegalEntityOrg) END
                 FROM m_warehouse w2 INNER JOIN ad_org o2 ON o2.AD_Org_ID = w2.AD_Org_ID WHERE M_Warehouse_ID = m.M_Warehouse_ID )
                 THEN 0 ELSE (SELECT ad_org_id FROM m_warehouse WHERE M_Warehouse_ID = m.M_Warehouse_ID ) END AS result FROM m_movement m WHERE m_movement_id = " + GetM_Movement_ID(), null, Get_Trx())) > 0)
                {
                    MMovement inventory = new MMovement(GetCtx(), GetM_Movement_ID(), Get_Trx());
                    try
                    {
                        string qry1 = @"SELECT  SUM(o.VA024_UnitPrice)   FROM VA024_t_ObsoleteInventory o 
                                  WHERE o.IsActive = 'Y' AND  o.M_Product_ID = " + GetM_Product_ID() + @" and 
                                  ( o.M_AttributeSetInstance_ID = " + GetM_AttributeSetInstance_ID() + @" OR o.M_AttributeSetInstance_ID IS NULL )" +
                                      " AND o.AD_Org_ID = " + GetAD_Org_ID();
                        VA024_ProvisionPrice = Util.GetValueOfDecimal(DB.ExecuteScalar(qry1, null, Get_Trx()));
                        SetVA024_UnitPrice(Util.GetValueOfDecimal(VA024_ProvisionPrice * GetMovementQty()));

                        qry1  = @"SELECT (ct.currentcostprice - " + VA024_ProvisionPrice + ") * " + GetMovementQty();
                        qry1 += @" FROM m_product p  INNER JOIN va024_t_obsoleteinventory oi ON p.m_product_id = oi.M_product_ID
                                 INNER JOIN m_product_category pc ON pc.m_product_category_ID = p.m_product_category_ID
                                 INNER JOIN AD_client c ON c.AD_Client_ID = p.Ad_Client_ID   INNER JOIN AD_ClientInfo ci  ON c.AD_Client_ID = ci.Ad_Client_ID
                                 INNER JOIN m_cost ct ON ( p.M_Product_ID     = ct.M_Product_ID  AND ci.C_AcctSchema1_ID = ct.C_AcctSchema_ID )
                                 INNER JOIN c_acctschema asch  ON (asch.C_AcctSchema_ID = ci.C_AcctSchema1_ID)
                                 INNER JOIN va024_obsoleteinvline oil ON oil.va024_obsoleteinvline_ID = oi.va024_obsoleteinvline_ID ";
                        qry1 += @"    WHERE ct.AD_Org_ID =  
                          CASE WHEN ( pc.costinglevel IS NOT NULL AND pc.costinglevel = 'O') THEN " + GetAD_Org_ID() + @" 
                               WHEN ( pc.costinglevel IS NOT NULL AND (pc.costinglevel  = 'C' OR pc.costinglevel = 'B')) THEN 0 
                               WHEN (pc.costinglevel IS NULL AND asch.costinglevel  = 'O') THEN " + GetAD_Org_ID() + @" 
                               WHEN ( pc.costinglevel IS NULL AND (asch.costinglevel  = 'C' OR asch.costinglevel   = 'B')) THEN 0  END
                          AND ct.m_costelement_id =  
                          CASE WHEN ( pc.costingmethod IS NOT NULL AND pc.costingmethod  != 'C') THEN  (SELECT MIN(m_costelement_id)  FROM m_costelement  
                                     WHERE m_costelement.costingmethod =pc.costingmethod  AND m_costelement.Ad_Client_ID  = oi.ad_client_id  ) 
                                WHEN ( pc.costingmethod IS NOT NULL AND pc.costingmethod = 'C' ) THEN  pc.m_costelement_id 
                                WHEN ( pc.costingmethod IS NULL AND asch.costingmethod  != 'C') THEN  (SELECT MIN(m_costelement_id)  FROM m_costelement 
                                     WHERE m_costelement.costingmethod = asch.costingmethod  AND m_costelement.Ad_Client_ID  = oi.ad_client_id  )
                                WHEN ( pc.costingmethod IS NULL AND asch.costingmethod  = 'C') THEN asch.m_costelement_id  END 
                         AND NVL(ct.M_Attributesetinstance_ID , 0) =  
                         CASE WHEN ( pc.costinglevel IS NOT NULL AND pc.costinglevel = 'B') THEN " + GetM_AttributeSetInstance_ID() + @" 
                              WHEN ( pc.costinglevel IS NOT NULL AND (pc.costinglevel  = 'C' OR pc.costinglevel = 'O')) THEN 0 
                              WHEN ( pc.costinglevel IS NULL AND asch.costinglevel  = 'B') THEN " + GetM_AttributeSetInstance_ID() + @"
                              WHEN ( pc.costinglevel IS NULL AND (asch.costinglevel  = 'C' OR asch.costinglevel   = 'O')) THEN 0  END 
                         AND p.M_Product_ID = " + GetM_Product_ID();
                        SetVA024_CostPrice(Util.GetValueOfDecimal(DB.ExecuteScalar(qry1, null, Get_Trx())));
                    }
                    catch { }
                }
            }

            //	Mandatory Instance
            if (GetM_AttributeSetInstanceTo_ID() == 0)
            {
                if (GetM_AttributeSetInstance_ID() != 0)        //	Set to from
                {
                    SetM_AttributeSetInstanceTo_ID(GetM_AttributeSetInstance_ID());
                }
                else
                {
                    if (Env.HasModulePrefix("DTD001_", out mInfo))
                    {
                        //MProduct product = GetProduct();
                        if (product != null &&
                            product.GetM_AttributeSet_ID() != 0)
                        {
                            //MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID());
                            //if (mas.IsInstanceAttribute()
                            //    && (mas.IsMandatory() || mas.IsMandatoryAlways()))
                            //{
                            //    log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID"));
                            //    return false;
                            //}

                            // Code Addeded by Bharat as Discussed with Mukesh Sir
                            if (String.IsNullOrEmpty(GetDTD001_AttributeNumber()))
                            {
                                return(true);
                            }
                            else
                            {
                                if (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null)
                                {
                                    log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber"));

                                    return(false);
                                }
                            }
                        }
                        else
                        {
                            if (product != null)
                            {
                                if (product.GetM_AttributeSet_ID() == 0 && (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null))
                                {
                                    return(true);
                                }
                                else
                                {
                                    //log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber"));
                                    //ShowMessage.Info("a", true, "Product is not of Attribute Type", null);
                                    log.SaveError("Product is not of Attribute Type", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber"));
                                    return(false);
                                }

                                //Check No Of Attributes Are Equal To Quantity Or Less Than

                                int Count = CountAttributes(GetDTD001_AttributeNumber());
                                if (Count != GetMovementQty())
                                {
                                    if (Count > GetMovementQty())
                                    {
                                        log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtGreater"));
                                        return(false);
                                    }
                                    else
                                    {
                                        log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtLess"));
                                        return(false);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        //MProduct product = GetProduct();
                        if (product != null &&
                            product.GetM_AttributeSet_ID() != 0)
                        {
                            MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID());
                            if (mas.IsInstanceAttribute() &&
                                (mas.IsMandatory() || mas.IsMandatoryAlways()))
                            {
                                log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID"));
                                return(false);
                            }
                        }
                    }
                }
            }   //	ASI
            return(true);
        }
Esempio n. 10
0
        /// <summary>
        /// is used to save data in case of Full move container / full qty move
        /// </summary>
        /// <param name="movementId">movement header refernce</param>
        /// <param name="fromLocatorId">From Locator - from where we have to move product</param>
        /// <param name="fromContainerId">From Container - from which container, we have to move product</param>
        /// <param name="toLocatorId">To Locator - where we are moving product</param>
        /// <param name="toContainerId">To container - in which container we are moving product</param>
        /// <param name="lineNo"></param>
        /// <param name="isMoveFullContainerQty">Is Container also move with Product</param>
        /// <param name="trx">Self created Trx</param>
        /// <returns>Message : lines inserted or not</returns>
        public String SaveMoveLinewithFullContainer(int movementId, int fromLocatorId, int fromContainerId, int toLocatorId, int toContainerId, int lineNo, bool isMoveFullContainerQty, Trx trx)
        {
            MMovement     movement         = new MMovement(_ctx, movementId, trx);
            string        childContainerId = null;
            StringBuilder error            = new StringBuilder();

            // Get Path upto selected container
            string sql           = @"SELECT sys_connect_by_path(m_productcontainer_id,'->') tree
                            FROM m_productcontainer 
                           WHERE m_productcontainer_id = " + fromContainerId + @"
                            START WITH ref_m_container_id IS NULL CONNECT BY prior m_productcontainer_id = ref_m_container_id
                           ORDER BY tree ";
            string pathContainer = Util.GetValueOfString(DB.ExecuteScalar(sql, null, trx));

            // child records with Parent Id
            if (!isMoveFullContainerQty)
            {
                sql = @"SELECT tree, m_productcontainer_id FROM
                            (SELECT sys_connect_by_path(m_productcontainer_id,'->') tree , m_productcontainer_id
                             FROM m_productcontainer
                             START WITH ref_m_container_id IS NULL
                             CONNECT BY prior m_productcontainer_id = ref_m_container_id
                             ORDER BY tree  
                             )
                           WHERE tree LIKE ('" + pathContainer + "%') ";
                DataSet ds = DB.ExecuteDataset(sql, null, trx);
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        if (String.IsNullOrEmpty(childContainerId))
                        {
                            childContainerId = Util.GetValueOfString(ds.Tables[0].Rows[i]["m_productcontainer_id"]);
                        }
                        else
                        {
                            childContainerId += "," + Util.GetValueOfString(ds.Tables[0].Rows[i]["m_productcontainer_id"]);
                        }
                    }
                }
                ds.Dispose();
            }
            else
            {
                childContainerId = fromContainerId.ToString();
            }

            // check is same container already moved to another container
            // Ex :: p1 -> c1 and p1 -> c2
            // OR also check -- is any other container is moving into exist target container
            // Ex :: p1 -> c1 and p2 -> p1
            if (!isMoveFullContainerQty)
            {
                if (!IsContainerMoved(movementId, pathContainer, childContainerId, toContainerId, trx))
                {
                    return(Msg.GetMsg(_ctx, "VIS_AlreadyMoved"));
                }
            }

            // not to move Parent container to its child container
            if (toContainerId > 0 && childContainerId.Contains(toContainerId.ToString()))
            {
                //Parent cant be Move to its own child
                return(Msg.GetMsg(_ctx, "VIS_cantMoveParentTochild"));
            }

            // Get All records of Parent Container and child container
            sql = @"SELECT * FROM (
                            SELECT p.M_PRODUCT_ID, p.NAME, p.C_UOM_ID, u.Name AS UomName,  t.M_ATTRIBUTESETINSTANCE_ID, t.M_ProductContainer_ID,
                            SUM(t.ContainerCurrentQty) keep (dense_rank last ORDER BY t.MovementDate, t.M_Transaction_ID) AS ContainerCurrentQty
                            FROM M_Transaction t
                            INNER JOIN M_Product p ON p.M_Product_ID = t.M_Product_ID
                            INNER JOIN C_UOM u ON u.C_UOM_ID = p.C_UOM_ID
                            WHERE t.IsActive = 'Y' AND NVL(t.M_ProductContainer_ID, 0) IN ( " + childContainerId +
                  @" ) AND t.MovementDate <=" + GlobalVariable.TO_DATE(movement.GetMovementDate(), true) + @" 
                               AND t.M_Locator_ID  = " + fromLocatorId + @"
                               AND t.AD_Client_ID  = " + movement.GetAD_Client_ID() + @"
                            GROUP BY p.M_PRODUCT_ID, p.NAME, p.C_UOM_ID, u.Name, t.M_ATTRIBUTESETINSTANCE_ID, t.M_ProductContainer_ID 
                          ) t WHERE ContainerCurrentQty <> 0 ";
            DataSet dsRecords = DB.ExecuteDataset(sql, null, trx);

            if (dsRecords != null && dsRecords.Tables.Count > 0 && dsRecords.Tables[0].Rows.Count > 0)
            {
                int           movementlineId = 0;
                MMovementLine moveline       = null;
                MProduct      product        = null;
                for (int i = 0; i < dsRecords.Tables[0].Rows.Count; i++)
                {
                    movementlineId = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT NVL(M_MovementLine_ID, 0) AS M_Movement_ID FROM M_MovementLine WHERE 
                             M_Movement_ID = " + Util.GetValueOfInt(movementId) +
                                                                         @" AND M_Product_ID = " + Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_Product_ID"]) +
                                                                         @" AND NVL(M_AttributeSetInstance_ID, 0) = " + Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_AttributeSetInstance_ID"]) +
                                                                         @" AND M_Locator_ID = " + Util.GetValueOfInt(fromLocatorId) +
                                                                         @" AND NVL(M_ProductContainer_ID, 0) = " + Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_ProductContainer_ID"]) +
                                                                         @" AND M_LocatorTo_ID = " + Util.GetValueOfInt(toLocatorId) +
                                                                         @" AND NVL(Ref_M_ProductContainerTo_ID, 0) = " + toContainerId +
                                                                         @" AND AD_Org_ID = " + movement.GetAD_Org_ID()));

                    if (movementlineId > 0)
                    {
                        moveline = new MMovementLine(_ctx, movementlineId, trx);
                    }
                    else
                    {
                        moveline = new MMovementLine(_ctx, 0, trx);
                    }
                    if (movementlineId == 0)
                    {
                        #region Create new record of movement line
                        lineNo += 10;
                        moveline.SetAD_Client_ID(movement.GetAD_Client_ID());
                        moveline.SetAD_Org_ID(movement.GetAD_Org_ID());
                        moveline.SetM_Movement_ID(movement.GetM_Movement_ID());
                        moveline.SetLine(lineNo);
                        moveline.SetM_Product_ID(Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_Product_ID"]));
                        moveline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_AttributeSetInstance_ID"]));
                        moveline.SetC_UOM_ID(Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["C_UOM_ID"]));
                        moveline.SetM_Locator_ID(fromLocatorId);
                        moveline.SetM_LocatorTo_ID(toLocatorId);
                        moveline.SetM_ProductContainer_ID(Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_ProductContainer_ID"]));
                        moveline.SetRef_M_ProductContainerTo_ID(toContainerId);
                        moveline.SetQtyEntered(Util.GetValueOfDecimal(dsRecords.Tables[0].Rows[i]["ContainerCurrentQty"]));
                        moveline.SetMovementQty(Util.GetValueOfDecimal(dsRecords.Tables[0].Rows[i]["ContainerCurrentQty"]));
                        moveline.SetMoveFullContainer(isMoveFullContainerQty ? false : true);
                        // when move full container, then only need to update IsParentMove and Target container (which represent - to which container we are moving)
                        // and set true value on those line which container are moving, not on its child container
                        if (!isMoveFullContainerQty)
                        {
                            moveline.SetIsParentMove(Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_ProductContainer_ID"]) == fromContainerId ? true : false);
                            moveline.SetTargetContainer_ID(fromContainerId);
                        }
                        #endregion
                    }
                    else
                    {
                        #region Update record of movement line
                        moveline.SetQtyEntered(Decimal.Add(moveline.GetQtyEntered(), Util.GetValueOfDecimal(dsRecords.Tables[0].Rows[i]["ContainerCurrentQty"])));
                        moveline.SetMovementQty(Decimal.Add(moveline.GetMovementQty(), Util.GetValueOfDecimal(dsRecords.Tables[0].Rows[i]["ContainerCurrentQty"])));
                        moveline.SetMoveFullContainer(true);
                        #endregion
                    }
                    if (!moveline.Save(trx))
                    {
                        #region Save error catch and rollback
                        product = MProduct.Get(_ctx, Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_Product_ID"]));
                        ValueNamePair pp = VLogger.RetrieveError();
                        if (pp != null)
                        {
                            _log.SaveError("Movement line not inserted through Move Container Form : ", pp.GetName());
                            if (String.IsNullOrEmpty(error.ToString()))
                            {
                                error.Append(Msg.GetMsg(_ctx, "VIS_MoveLineNotSaveFor") + product.GetName() + Msg.GetMsg(_ctx, "VIS_DueTo") + pp.GetName());
                            }
                            else
                            {
                                error.Append(" , " + Msg.GetMsg(_ctx, "VIS_MoveLineNotSaveFor") + product.GetName() + Msg.GetMsg(_ctx, "VIS_DueTo") + pp.GetName());
                            }
                        }
                        trx.Rollback();
                        #endregion
                    }
                    else
                    {
                        trx.Commit();
                    }
                }
            }
            else
            {
                return(Msg.GetMsg(_ctx, "VIS_ContainerhaveNoRecord"));
            }

            return(String.IsNullOrEmpty(error.ToString()) ? "VIS_SuccessFullyInserted" : error.ToString());
        }
Esempio n. 11
0
        }       //	createRequisition

        /// <summary>
        /// Create Inventory Movements
        /// </summary>
        private void CreateMovements()
        {
            int    noMoves = 0;
            String info    = "";
            //
            MClient    client               = null;
            MMovement  move                 = null;
            int        M_Warehouse_ID       = 0;
            int        M_WarehouseSource_ID = 0;
            MWarehouse whSource             = null;
            MWarehouse whTarget             = null;

            string param = "";

            if (_M_WareSource != null)
            {
                param = _M_WareSource;
            }
            else
            {
                param = "M_WarehouseSource_ID IS NOT NULL";
            }
            X_T_Replenish[] replenishs = GetReplenish(param);;
            for (int i = 0; i < replenishs.Length; i++)
            {
                X_T_Replenish replenish = replenishs[i];
                if (whSource == null || whSource.GetM_WarehouseSource_ID() != replenish.GetM_WarehouseSource_ID())
                {
                    whSource = MWarehouse.Get(GetCtx(), replenish.GetM_WarehouseSource_ID());
                }
                if (whTarget == null || whTarget.GetM_Warehouse_ID() != replenish.GetM_Warehouse_ID())
                {
                    whTarget = MWarehouse.Get(GetCtx(), replenish.GetM_Warehouse_ID());
                }
                if (client == null || client.GetAD_Client_ID() != whSource.GetAD_Client_ID())
                {
                    client = MClient.Get(GetCtx(), whSource.GetAD_Client_ID());
                }
                //
                if (move == null ||
                    M_WarehouseSource_ID != replenish.GetM_WarehouseSource_ID() ||
                    M_Warehouse_ID != replenish.GetM_Warehouse_ID())
                {
                    M_WarehouseSource_ID = replenish.GetM_WarehouseSource_ID();
                    M_Warehouse_ID       = replenish.GetM_Warehouse_ID();

                    move = new MMovement(GetCtx(), 0, Get_TrxName());
                    move.SetC_DocType_ID(_C_DocType_ID);
                    move.SetDescription(Msg.GetMsg(GetCtx(), "Replenishment")
                                        + ": " + whSource.GetName() + "->" + whTarget.GetName());
                    //	Set Org
                    move.SetAD_Org_ID(whSource.GetAD_Org_ID());
                    if (!move.Save())
                    {
                        return;
                    }
                    log.Fine(move.ToString());
                    noMoves++;
                    info += " - " + move.GetDocumentNo();
                }
                MProduct product = MProduct.Get(GetCtx(), replenish.GetM_Product_ID());
                //	To
                int M_LocatorTo_ID = GetLocator_ID(product, whTarget);

                //	From: Look-up Storage
                MProductCategory pc       = MProductCategory.Get(GetCtx(), product.GetM_Product_Category_ID());
                String           MMPolicy = pc.GetMMPolicy();
                if (MMPolicy == null || MMPolicy.Length == 0)
                {
                    MMPolicy = client.GetMMPolicy();
                }
                //
                MStorage[] storages = MStorage.GetWarehouse(GetCtx(),
                                                            whSource.GetM_Warehouse_ID(), replenish.GetM_Product_ID(), 0, 0,
                                                            true, null,
                                                            MClient.MMPOLICY_FiFo.Equals(MMPolicy), Get_TrxName());
                if (storages == null || storages.Length == 0)
                {
                    AddLog("No Inventory in " + whSource.GetName()
                           + " for " + product.GetName());
                    continue;
                }
                //
                Decimal target = replenish.GetQtyToOrder();
                for (int j = 0; j < storages.Length; j++)
                {
                    MStorage storage = storages[j];
                    //if (storage.GetQtyOnHand().signum() <= 0)
                    if (Env.Signum(storage.GetQtyOnHand()) <= 0)
                    {
                        continue;
                    }
                    Decimal moveQty = target;
                    if (storage.GetQtyOnHand().CompareTo(moveQty) < 0)
                    {
                        moveQty = storage.GetQtyOnHand();
                    }
                    //
                    MMovementLine line = new MMovementLine(move);
                    line.SetM_Product_ID(replenish.GetM_Product_ID());
                    line.SetMovementQty(moveQty);
                    if (replenish.GetQtyToOrder().CompareTo(moveQty) != 0)
                    {
                        line.SetDescription("Total: " + replenish.GetQtyToOrder());
                    }
                    line.SetM_Locator_ID(storage.GetM_Locator_ID());            //	from
                    line.SetM_AttributeSetInstance_ID(storage.GetM_AttributeSetInstance_ID());
                    line.SetM_LocatorTo_ID(M_LocatorTo_ID);                     //	to
                    line.SetM_AttributeSetInstanceTo_ID(storage.GetM_AttributeSetInstance_ID());
                    line.Save();
                    //
                    //target = target.subtract(moveQty);
                    target = Decimal.Subtract(target, moveQty);
                    //if (target.signum() == 0)
                    if (Env.Signum(target) == 0)
                    {
                        break;
                    }
                }
                if (Env.Signum(target) != 0)
                {
                    AddLog("Insufficient Inventory in " + whSource.GetName()
                           + " for " + product.GetName() + " Qty=" + target);
                }
            }
            if (replenishs.Length == 0)
            {
                _info = "No Source Warehouse";
                log.Warning(_info);
            }
            else
            {
                _info = "#" + noMoves + info;
                log.Info(_info);
            }
        }       //	createRequisition
Esempio n. 12
0
        /// <summary>
        /// Before Save
        /// </summary>
        /// <param name="newRecord">new</param>
        /// <returns>true</returns>
        protected override Boolean BeforeSave(Boolean newRecord)
        {
            // By vikas
            // Get Old Value of AttributeSetInstance_ID
            _mvlOldAttId = Util.GetValueOfInt(Get_ValueOld("M_AttributeSetInstance_ID"));

            //	Set Line No
            if (GetLine() == 0)
            {
                String sql = "SELECT COALESCE(MAX(Line),0)+10 AS DefaultValue FROM M_MovementLine WHERE M_Movement_ID=" + GetM_Movement_ID();
                int    ii  = DB.GetSQLValue(Get_TrxName(), sql);
                SetLine(ii);
            }

            // Check Locator For Header Warehouse
            MMovement mov = new MMovement(GetCtx(), GetM_Movement_ID(), Get_TrxName());

            VAdvantage.Model.MLocator      loc   = new VAdvantage.Model.MLocator(GetCtx(), GetM_Locator_ID(), Get_TrxName());
            Tuple <string, string, string> aInfo = null;

            if (Env.HasModulePrefix("DTD001_", out aInfo))
            {
                if (mov.GetDTD001_MWarehouseSource_ID() == loc.GetM_Warehouse_ID())
                {
                }
                else
                {
                    String sql = "SELECT M_Locator_ID FROM M_Locator WHERE M_Warehouse_ID=" + mov.GetDTD001_MWarehouseSource_ID() + " AND IsDefault = 'Y'";
                    int    ii  = DB.GetSQLValue(Get_TrxName(), sql);
                    SetM_Locator_ID(ii);
                }
            }

            if (GetM_Locator_ID() == GetM_LocatorTo_ID())
            {
                log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "'From @M_Locator_ID@' and '@M_LocatorTo_ID@' cannot be same."));//change message according to requirement
                return(false);
            }

            if (Env.Signum(GetMovementQty()) == 0 && Util.GetValueOfInt(GetTargetQty()) == 0)
            {
                log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "MovementQty"));
                return(false);
            }
            //Amit
            Tuple <String, String, String> mInfo = null;

            if (Env.HasModulePrefix("DTD001_", out mInfo))
            {
                if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Product_ID")) != GetM_Product_ID())
                {
                    log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ProdNotChanged"));
                    return(false);
                }
                if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Locator_ID")) != GetM_Locator_ID())
                {
                    log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_LocatorNotChanged"));
                    return(false);
                }
                if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_RequisitionLine_ID")) != GetM_RequisitionLine_ID())
                {
                    log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ReqNotChanged"));
                    return(false);
                }
            }
            if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA203_'", null, null)) > 0)
            {
                if (GetM_RequisitionLine_ID() > 0)
                {
                    VAdvantage.Model.MRequisitionLine reqline = new VAdvantage.Model.MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), null);
                    if (GetM_AttributeSetInstance_ID() != reqline.GetM_AttributeSetInstance_ID())
                    {
                        log.SaveError("Message", Msg.GetMsg(GetCtx(), "VA203_AttributeInstanceMustBeSame"));
                        return(false);
                    }
                }
            }
            // IF Doc Status = InProgress then No record Save
            MMovement move = new MMovement(GetCtx(), GetM_Movement_ID(), null);

            if (newRecord && move.GetDocStatus() == "IP")
            {
                log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_CannotCreate"));
                return(false);
            }

            //	Qty Precision
            if (newRecord || Is_ValueChanged("QtyEntered"))
            {
                SetMovementQty(GetMovementQty());
            }
            int    M_Warehouse_ID = 0; VAdvantage.Model.MWarehouse wh = null;
            string qry = "select m_warehouse_id from m_locator where m_locator_id=" + GetM_Locator_ID();

            M_Warehouse_ID = Util.GetValueOfInt(DB.ExecuteScalar(qry));

            wh  = VAdvantage.Model.MWarehouse.Get(GetCtx(), M_Warehouse_ID);
            qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)),0) AS QtyOnHand FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID();
            if (GetM_AttributeSetInstance_ID() != 0)
            {
                qry += " AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID();
            }
            OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry));
            // when record is in completed & closed & Reversed stage - then no need to check qty availablity in warehouse
            if (wh.IsDisallowNegativeInv() == true && (!(move.GetDocStatus() == "CO" || move.GetDocStatus() == "CL" || move.GetDocStatus() == "RE")))
            {
                if (GetDescription() != "RC")
                {
                    if (GetMovementQty() < 0)
                    {
                        log.SaveError("Error", Msg.GetMsg(GetCtx(), "Qty Available " + OnHandQty));
                        //ShowMessage.Info("Qty Available " + OnHandQty, true, null, null);
                        return(false);
                    }
                    else if ((OnHandQty - GetMovementQty()) < 0)
                    {
                        log.SaveError("Error", Msg.GetMsg(GetCtx(), "Qty Available " + OnHandQty));
                        //ShowMessage.Info("Qty Available " + OnHandQty, true, null, null);
                        return(false);
                    }
                }
            }
            if (Env.HasModulePrefix("DTD001_", out mInfo))
            {
                qry = "SELECT   NVL(SUM(NVL(QtyOnHand,0)- qtyreserved),0) AS QtyAvailable  FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID();
                if (GetM_AttributeSetInstance_ID() != 0)
                {
                    qry += " AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID();
                }
                qtyAvailable = Convert.ToDecimal(DB.ExecuteScalar(qry));
                qtyReserved  = Util.GetValueOfDecimal(Get_ValueOld("MovementQty"));
                if (wh.IsDisallowNegativeInv() == true)
                {
                    if ((qtyAvailable < (GetMovementQty() - qtyReserved)))
                    {
                        log.SaveError("Message", Msg.GetElement(GetCtx(), "DTD001_QtyNotAvailable"));
                        return(false);
                    }
                }
            }
            //	Mandatory Instance
            if (GetM_AttributeSetInstanceTo_ID() == 0)
            {
                if (GetM_AttributeSetInstance_ID() != 0)        //	Set to from
                {
                    SetM_AttributeSetInstanceTo_ID(GetM_AttributeSetInstance_ID());
                }
                else
                {
                    if (Env.HasModulePrefix("DTD001_", out mInfo))
                    {
                        VAdvantage.Model.MProduct product = GetProduct();
                        if (product != null &&
                            product.GetM_AttributeSet_ID() != 0)
                        {
                            //MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID());
                            //if (mas.IsInstanceAttribute()
                            //    && (mas.IsMandatory() || mas.IsMandatoryAlways()))
                            //{
                            //    log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID"));
                            //    return false;
                            //}

                            // Code Addeded by Bharat as Discussed with Mukesh Sir
                            if (String.IsNullOrEmpty(GetDTD001_AttributeNumber()))
                            {
                                return(true);
                            }
                            else
                            {
                                if (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null)
                                {
                                    log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber"));

                                    return(false);
                                }
                            }
                        }
                        else
                        {
                            if (product != null)
                            {
                                if (product.GetM_AttributeSet_ID() == 0 && (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null))
                                {
                                    return(true);
                                }
                                else
                                {
                                    //log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber"));
                                    //ShowMessage.Info("a", true, "Product is not of Attribute Type", null);
                                    log.SaveError("Product is not of Attribute Type", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber"));
                                    return(false);
                                }

                                //Check No Of Attributes Are Equal To Quantity Or Less Than

                                int Count = CountAttributes(GetDTD001_AttributeNumber());
                                if (Count != GetMovementQty())
                                {
                                    if (Count > GetMovementQty())
                                    {
                                        log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtGreater"));
                                        return(false);
                                    }
                                    else
                                    {
                                        log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtLess"));
                                        return(false);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        VAdvantage.Model.MProduct product = GetProduct();
                        if (product != null &&
                            product.GetM_AttributeSet_ID() != 0)
                        {
                            VAdvantage.Model.MAttributeSet mas = VAdvantage.Model.MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID());
                            if (mas.IsInstanceAttribute() &&
                                (mas.IsMandatory() || mas.IsMandatoryAlways()))
                            {
                                log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID"));
                                return(false);
                            }
                        }
                    }
                }
            }   //	ASI

            return(true);
        }
Esempio n. 13
0
        /// <summary>
        /// Create Difference Document.
        ///	Creates one or two inventory lines
        /// </summary>
        /// <param name="move">movement</param>
        /// <param name="confirm">confirm line</param>
        /// <returns>true if created</returns>
        private Boolean CreateDifferenceDoc(MMovement move, MMovementLineConfirm confirm)
        {
            string        query      = "";
            int           result     = 0;
            decimal       currentQty = 0;
            MMovementLine mLine      = confirm.GetLine();

            //	Difference - Create Inventory Difference for Source Location
            if (Env.ZERO.CompareTo(confirm.GetDifferenceQty()) != 0)
            {
                //	Get Warehouse for Source
                VAdvantage.Model.MLocator loc = VAdvantage.Model.MLocator.Get(GetCtx(), mLine.GetM_Locator_ID());
                if (_inventoryFrom != null &&
                    _inventoryFrom.GetM_Warehouse_ID() != loc.GetM_Warehouse_ID())
                {
                    _inventoryFrom = null;
                }

                if (_inventoryFrom == null)
                {
                    VAdvantage.Model.MWarehouse wh = VAdvantage.Model.MWarehouse.Get(GetCtx(), loc.GetM_Warehouse_ID());
                    _inventoryFrom = new VAdvantage.Model.MInventory(wh);
                    _inventoryFrom.SetDescription(Msg.Translate(GetCtx(), "M_MovementConfirm_ID") + " " + GetDocumentNo());
                    if (!_inventoryFrom.Save(Get_TrxName()))
                    {
                        _processMsg += "Inventory not created";
                        return(false);
                    }
                    //	First Inventory
                    if (GetM_Inventory_ID() == 0)
                    {
                        SetM_Inventory_ID(_inventoryFrom.GetM_Inventory_ID());
                        _inventoryInfo = _inventoryFrom.GetDocumentNo();
                    }
                    else
                    {
                        _inventoryInfo += "," + _inventoryFrom.GetDocumentNo();
                    }
                }

                log.Info("createDifferenceDoc - Difference=" + confirm.GetDifferenceQty());
                VAdvantage.Model.MInventoryLine line = new VAdvantage.Model.MInventoryLine(_inventoryFrom,
                                                                                           mLine.GetM_Locator_ID(), mLine.GetM_Product_ID(), mLine.GetM_AttributeSetInstance_ID(),
                                                                                           confirm.GetDifferenceQty(), Env.ZERO);
                //Added By amit 11-jun-2015
                //Opening Stock , Qunatity Book => CurrentQty From Transaction of MovementDate
                //As On Date Count = Opening Stock - Diff Qty
                //Qty Count = Qty Book - Diff Qty
                query  = "SELECT COUNT(*) FROM M_Transaction WHERE movementdate = " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + @" 
                           AND  M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID();
                result = Util.GetValueOfInt(DB.ExecuteScalar(query));
                if (result > 0)
                {
                    query      = @"SELECT currentqty FROM M_Transaction WHERE M_Transaction_ID =
                            (SELECT MAX(M_Transaction_ID)   FROM M_Transaction
                            WHERE movementdate =     (SELECT MAX(movementdate) FROM M_Transaction WHERE movementdate <= " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + @" 
                            AND  M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID() + @")
                            AND  M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID() + @")
                            AND  M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID();
                    currentQty = Util.GetValueOfDecimal(DB.ExecuteScalar(query));
                }
                else
                {
                    query  = "SELECT COUNT(*) FROM M_Transaction WHERE movementdate < " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + @" 
                            AND  M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID();
                    result = Util.GetValueOfInt(DB.ExecuteScalar(query));
                    if (result > 0)
                    {
                        query      = @"SELECT currentqty FROM M_Transaction WHERE M_Transaction_ID =
                            (SELECT MAX(M_Transaction_ID)   FROM M_Transaction
                            WHERE movementdate =     (SELECT MAX(movementdate) FROM M_Transaction WHERE movementdate < " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + @" 
                            AND  M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID() + @")
                            AND  M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID() + @")
                            AND  M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID();
                        currentQty = Util.GetValueOfDecimal(DB.ExecuteScalar(query));
                    }
                }
                //End
                line.SetAdjustmentType("D");
                line.SetDifferenceQty(Util.GetValueOfDecimal(confirm.GetDifferenceQty()));
                line.SetQtyBook(currentQty);
                line.SetOpeningStock(currentQty);
                line.SetAsOnDateCount(Decimal.Subtract(Util.GetValueOfDecimal(line.GetOpeningStock()), Util.GetValueOfDecimal(confirm.GetDifferenceQty())));
                line.SetQtyCount(Decimal.Subtract(Util.GetValueOfDecimal(line.GetQtyBook()), Util.GetValueOfDecimal(confirm.GetDifferenceQty())));
                line.SetDescription(Msg.Translate(GetCtx(), "DifferenceQty"));
                if (!line.Save(Get_TrxName()))
                {
                    _processMsg += "Inventory Line not created";
                    return(false);
                }
                confirm.SetM_InventoryLine_ID(line.GetM_InventoryLine_ID());
            }   //	Difference

            //	Scrapped - Create Inventory Difference for TarGet Location
            if (Env.ZERO.CompareTo(confirm.GetScrappedQty()) != 0)
            {
                //	Get Warehouse for TarGet
                VAdvantage.Model.MLocator loc = VAdvantage.Model.MLocator.Get(GetCtx(), mLine.GetM_LocatorTo_ID());
                if (_inventoryTo != null &&
                    _inventoryTo.GetM_Warehouse_ID() != loc.GetM_Warehouse_ID())
                {
                    _inventoryTo = null;
                }

                if (_inventoryTo == null)
                {
                    VAdvantage.Model.MWarehouse wh = VAdvantage.Model.MWarehouse.Get(GetCtx(), loc.GetM_Warehouse_ID());
                    _inventoryTo = new VAdvantage.Model.MInventory(wh);
                    _inventoryTo.SetDescription(Msg.Translate(GetCtx(), "M_MovementConfirm_ID") + " " + GetDocumentNo());
                    if (!_inventoryTo.Save(Get_TrxName()))
                    {
                        _processMsg += "Inventory not created";
                        return(false);
                    }
                    //	First Inventory
                    if (GetM_Inventory_ID() == 0)
                    {
                        SetM_Inventory_ID(_inventoryTo.GetM_Inventory_ID());
                        _inventoryInfo = _inventoryTo.GetDocumentNo();
                    }
                    else
                    {
                        _inventoryInfo += "," + _inventoryTo.GetDocumentNo();
                    }
                }

                log.Info("CreateDifferenceDoc - Scrapped=" + confirm.GetScrappedQty());
                VAdvantage.Model.MInventoryLine line = new VAdvantage.Model.MInventoryLine(_inventoryTo,
                                                                                           mLine.GetM_LocatorTo_ID(), mLine.GetM_Product_ID(), mLine.GetM_AttributeSetInstance_ID(),
                                                                                           confirm.GetScrappedQty(), Env.ZERO);
                line.SetDescription(Msg.Translate(GetCtx(), "ScrappedQty"));
                if (!line.Save(Get_TrxName()))
                {
                    _processMsg += "Inventory Line not created";
                    return(false);
                }
                confirm.SetM_InventoryLine_ID(line.GetM_InventoryLine_ID());
            }   //	Scrapped

            return(true);
        }
Esempio n. 14
0
        /// <summary>
        /// Complete Document
        /// </summary>
        /// <returns>new status (Complete, In Progress, Invalid, Waiting ..)</returns>
        public String CompleteIt()
        {
            //	Re-Check
            if (!_justPrepared)
            {
                String status = PrepareIt();
                if (!DocActionVariables.STATUS_INPROGRESS.Equals(status))
                {
                    return(status);
                }
            }
            //	Implicit Approval
            if (!IsApproved())
            {
                ApproveIt();
            }
            log.Info("CompleteIt - " + ToString());
            //
            MMovement move = new MMovement(GetCtx(), GetM_Movement_ID(), Get_TrxName());

            MMovementLineConfirm[] lines = GetLines(false);
            for (int i = 0; i < lines.Length; i++)
            {
                MMovementLineConfirm confirm = lines[i];
                confirm.Set_TrxName(Get_TrxName());
                if (!confirm.ProcessLine())
                {
                    _processMsg = "ShipLine not saved - " + confirm;
                    return(DocActionVariables.STATUS_INVALID);
                }
                if (confirm.IsFullyConfirmed())
                {
                    confirm.SetProcessed(true);
                    confirm.Save(Get_TrxName());
                }
                else
                {
                    if (CreateDifferenceDoc(move, confirm))
                    {
                        confirm.SetProcessed(true);
                        confirm.Save(Get_TrxName());
                    }
                    else
                    {
                        log.Log(Level.SEVERE, "completeIt - Scrapped=" + confirm.GetScrappedQty()
                                + " - Difference=" + confirm.GetDifferenceQty());

                        _processMsg = "Differnce Doc not created";
                        return(DocActionVariables.STATUS_INVALID);
                    }
                }
            }   //	for all lines

            if (_inventoryInfo != null)
            {
                _processMsg = " @M_Inventory_ID@: " + _inventoryInfo;
                AddDescription(Msg.Translate(GetCtx(), "M_Inventory_ID")
                               + ": " + _inventoryInfo);
            }
            //Amit 21-nov-2014 (Reduce reserved quantity from requisition and warehouse distribution center)
            Tuple <String, String, String> mInfo = null;

            if (Env.HasModulePrefix("DTD001_", out mInfo))
            {
                MMovementLine movementLine = null;
                VAdvantage.Model.MRequisitionLine requisitionLine = null;
                VAdvantage.Model.MStorage         storage         = null;
                for (int i = 0; i < lines.Length; i++)
                {
                    MMovementLineConfirm confirm = lines[i];
                    if (confirm.GetDifferenceQty() > 0)
                    {
                        movementLine = new MMovementLine(GetCtx(), confirm.GetM_MovementLine_ID(), Get_Trx());
                        if (movementLine.GetM_RequisitionLine_ID() > 0)
                        {
                            requisitionLine = new VAdvantage.Model.MRequisitionLine(GetCtx(), movementLine.GetM_RequisitionLine_ID(), Get_Trx());
                            requisitionLine.SetDTD001_ReservedQty(decimal.Subtract(requisitionLine.GetDTD001_ReservedQty(), confirm.GetDifferenceQty()));
                            if (!requisitionLine.Save(Get_Trx()))
                            {
                                _processMsg = Msg.GetMsg(GetCtx(), "DTD001_ReqNotUpdate");
                                // _processMsg = "Requisitionline not updated";
                                return(DocActionVariables.STATUS_INVALID);
                            }
                            storage = VAdvantage.Model.MStorage.Get(GetCtx(), movementLine.GetM_Locator_ID(), movementLine.GetM_Product_ID(), movementLine.GetM_AttributeSetInstance_ID(), Get_Trx());
                            if (storage == null)
                            {
                                storage = VAdvantage.Model.MStorage.Get(GetCtx(), movementLine.GetM_Locator_ID(), movementLine.GetM_Product_ID(), 0, Get_Trx());
                            }
                            storage.SetQtyReserved(decimal.Subtract(storage.GetQtyReserved(), confirm.GetDifferenceQty()));
                            if (!storage.Save(Get_Trx()))
                            {
                                _processMsg = Msg.GetMsg(GetCtx(), "DTD001_StorageNotUpdate");
                                //_processMsg = "Storage From not updated (MA)";
                                return(DocActionVariables.STATUS_INVALID);
                            }
                        }
                    }
                }
            }
            //Amit
            SetProcessed(true);
            SetDocAction(DOCACTION_Close);
            return(DocActionVariables.STATUS_COMPLETED);
        }
Esempio n. 15
0
        /// <summary>
        /// Complete Document
        /// </summary>
        /// <returns>new status (Complete, In Progress, Invalid, Waiting ..)</returns>
        public String CompleteIt()
        {
            //	Re-Check
            if (!_justPrepared)
            {
                String status = PrepareIt();
                if (!DocActionVariables.STATUS_INPROGRESS.Equals(status))
                {
                    return(status);
                }
            }
            //	Implicit Approval
            if (!IsApproved())
            {
                ApproveIt();
            }
            log.Info("CompleteIt - " + ToString());
            //
            MMovement move = new MMovement(GetCtx(), GetM_Movement_ID(), Get_TrxName());

            MMovementLineConfirm[] lines = GetLines(false);



            #region [Change By Sukhwinder on 11th October,2017 To Check if VA Material Quality Control Module exists or not, and then check if actual value at Quality Control tab exists or not]
            if (Env.IsModuleInstalled("VA010_"))
            {
                try
                {
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < lines.Length; i++)
                    {
                        sb.Append(lines[i].Get_ID() + ",");
                    }

                    string mMovementLinesConfirm = sb.ToString().Trim(',');

                    if (!string.IsNullOrEmpty(mMovementLinesConfirm))
                    {
                        string qry = DBFunctionCollection.MoveConfirmNoActualValue(mMovementLinesConfirm);
                        string productsNoActualValue = Util.GetValueOfString(DB.ExecuteScalar(qry));
                        if (!string.IsNullOrEmpty(productsNoActualValue))
                        {
                            //_processMsg = productsNoActualValue + " is/are not verified with all the Quality Parameters." +
                            //              " Please fill actual value for the missing Quality Parameters in Quality Control. ";
                            _processMsg = productsNoActualValue + " " + Msg.GetMsg(GetCtx(), "VIS_NoActualValueInQC");
                            return(DocActionVariables.STATUS_INVALID);
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Severe("Exception When Checking actual value at Quality Control Tab - " + ex.Message);
                }
            }
            #endregion



            for (int i = 0; i < lines.Length; i++)
            {
                MMovementLineConfirm confirm = lines[i];
                confirm.Set_TrxName(Get_TrxName());
                //Added By Arpit
                if (GetDescription() != null && GetDescription().Contains("{->"))
                {
                    //if (!confirm.ProcessLineReverse())
                    //{
                    //    _processMsg = "ShipLine not saved - " + confirm;
                    //    return DocActionVariables.STATUS_INVALID;
                    //}
                }
                else if (!confirm.ProcessLine())
                {
                    _processMsg = "ShipLine not saved - " + confirm;
                    return(DocActionVariables.STATUS_INVALID);
                }
                if (confirm.IsFullyConfirmed())
                {
                    confirm.SetProcessed(true);
                    confirm.Save(Get_TrxName());
                }
                else
                {
                    if (CreateDifferenceDoc(move, confirm))
                    {
                        confirm.SetProcessed(true);
                        confirm.Save(Get_TrxName());
                    }
                    else
                    {
                        log.Log(Level.SEVERE, "completeIt - Scrapped=" + confirm.GetScrappedQty()
                                + " - Difference=" + confirm.GetDifferenceQty());

                        _processMsg = "Differnce Doc not created";
                        return(DocActionVariables.STATUS_INVALID);
                    }
                }
            }   //	for all lines

            if (_inventoryInfo != null)
            {
                _processMsg = " @M_Inventory_ID@: " + _inventoryInfo;
                AddDescription(Msg.Translate(GetCtx(), "M_Inventory_ID")
                               + ": " + _inventoryInfo);
            }
            //Amit 21-nov-2014 (Reduce reserved quantity from requisition and warehouse distribution center)
            Tuple <String, String, String> mInfo = null;
            if (Env.HasModulePrefix("DTD001_", out mInfo))
            {
                MMovementLine    movementLine    = null;
                MRequisitionLine requisitionLine = null;
                MStorage         storage         = null;
                for (int i = 0; i < lines.Length; i++)
                {
                    MMovementLineConfirm confirm = lines[i];
                    if (confirm.GetDifferenceQty() > 0)
                    {
                        movementLine = new MMovementLine(GetCtx(), confirm.GetM_MovementLine_ID(), Get_Trx());
                        if (movementLine.GetM_RequisitionLine_ID() > 0)
                        {
                            requisitionLine = new MRequisitionLine(GetCtx(), movementLine.GetM_RequisitionLine_ID(), Get_Trx());
                            requisitionLine.SetDTD001_ReservedQty(decimal.Subtract(requisitionLine.GetDTD001_ReservedQty(), confirm.GetDifferenceQty()));
                            if (!requisitionLine.Save(Get_Trx()))
                            {
                                _processMsg = Msg.GetMsg(GetCtx(), "DTD001_ReqNotUpdate");
                                // _processMsg = "Requisitionline not updated";
                                return(DocActionVariables.STATUS_INVALID);
                            }
                            storage = MStorage.Get(GetCtx(), movementLine.GetM_Locator_ID(), movementLine.GetM_Product_ID(), movementLine.GetM_AttributeSetInstance_ID(), Get_Trx());
                            if (storage == null)
                            {
                                storage = MStorage.Get(GetCtx(), movementLine.GetM_Locator_ID(), movementLine.GetM_Product_ID(), 0, Get_Trx());
                            }
                            storage.SetQtyReserved(decimal.Subtract(storage.GetQtyReserved(), confirm.GetDifferenceQty()));
                            if (!storage.Save(Get_Trx()))
                            {
                                Get_Trx().Rollback();
                                _processMsg = Msg.GetMsg(GetCtx(), "DTD001_StorageNotUpdate");
                                //_processMsg = "Storage From not updated (MA)";
                                return(DocActionVariables.STATUS_INVALID);
                            }
                        }
                    }
                }
            }
            //Amit
            SetProcessed(true);
            SetDocAction(DOCACTION_Close);
            Save(Get_Trx());
            //Adde by Arpit To complete The Inventory Move if Move Confirmation is completed ,16th Dec,2016
            MMovement Mov = new MMovement(GetCtx(), GetM_Movement_ID(), Get_Trx());
            if (move.GetDocStatus() != DOCSTATUS_Completed)
            {
                string Status = Mov.CompleteIt();
                if (Status == "CO")
                {
                    move.SetDocStatus(DOCSTATUS_Completed);
                    move.SetDocAction("CL");
                    move.SetProcessed(true);
                    move.Save(Get_Trx());
                }
                else
                {
                    Get_Trx().Rollback();
                    _processMsg = Mov.GetProcessMsg();
                    return(DocActionVariables.STATUS_INVALID);
                }
            }
            //End Here

            return(DocActionVariables.STATUS_COMPLETED);
        }
Esempio n. 16
0
        // Change By Arpit to Create Parameters on Ship/Reciept Confirm Quality Control Tab 24th Aug,2017
        public static void CreateConfirmParameters(MMovement move, int M_MoveConfirm_ID, Ctx ctx)
        {
            String _Sql = @" SELECT movln.M_MovementLine_ID,  mlnconf.M_MovementLineConfirm_ID,  movln.M_Product_ID , 
                           pr.VA010_QualityPlan_ID ,  movln.MovementQty  FROM M_MovementLine movln INNER JOIN M_Product pr  
                             ON (movln.M_Product_ID =pr.M_Product_ID) INNER JOIN m_movementlineconfirm mlnconf   
                             ON (movln.m_movementline_id=mlnconf.m_movementline_id) 
                             inner join m_movementconfirm mconf  on (mlnconf.m_movementconfirm_ID= mconf.m_movementconfirm_id)
                             WHERE movln.M_Movement_ID =" + move.GetM_Movement_ID() + " ORDER BY  Line";
            //" ORDER BY movln.M_Product_ID, pr.VA010_QualityPlan_ID ASC, movln.MovementQty,  Line";
            DataSet ds = new DataSet();
            //int _currentPlanQlty_ID = 0, CurrentLoopQty = 0, currProduct_ID = 0;
            int        _currentPlanQlty_ID = 0, CurrentLoopQty = 0;
            List <int> CurrentLoopProduct = new List <int>();
            List <int> ProductQty         = new List <int>();
            List <int> MoveConfirmLine_ID = new List <int>();

            try
            {
                ds = DB.ExecuteDataset(_Sql, null, move.Get_TrxName());
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        //if (_currentPlanQlty_ID == 0)
                        //{
                        _currentPlanQlty_ID = Util.GetValueOfInt(ds.Tables[0].Rows[i]["VA010_QualityPlan_ID"]);
                        //}
                        //currProduct_ID = Util.GetValueOfInt(ds.Tables[0].Rows[i]["M_Product_ID"]);
                        CurrentLoopProduct.Add(Util.GetValueOfInt(ds.Tables[0].Rows[i]["M_Product_ID"]));
                        ProductQty.Add(Util.GetValueOfInt(ds.Tables[0].Rows[i]["MovementQty"]));
                        CurrentLoopQty = Util.GetValueOfInt(ds.Tables[0].Rows[i]["MovementQty"]);
                        MoveConfirmLine_ID.Add(Util.GetValueOfInt(ds.Tables[0].Rows[i]["M_MovementLineConfirm_ID"]));
                        //if (i < ds.Tables[0].Rows.Count - 1)
                        //{
                        //    if (_currentPlanQlty_ID == Util.GetValueOfInt(ds.Tables[0].Rows[i + 1]["VA010_QualityPlan_ID"])
                        //        && currProduct_ID == Util.GetValueOfInt(ds.Tables[0].Rows[i + 1]["M_Product_ID"]))
                        //    {
                        //        continue;
                        //    }
                        //    else
                        //    {
                        //        CreateParameters(CurrentLoopProduct, ProductQty, M_MoveConfirm_ID, _currentPlanQlty_ID, CurrentLoopQty, MoveConfirmLine_ID, ctx, move.Get_TrxName());
                        //        CurrentLoopProduct.Clear();
                        //        ProductQty.Clear();
                        //        _currentPlanQlty_ID = 0;
                        //        CurrentLoopQty = 0;
                        //        MoveConfirmLine_ID.Clear();
                        //    }
                        //}
                        //else
                        //{
                        CreateParameters(CurrentLoopProduct, ProductQty, M_MoveConfirm_ID, _currentPlanQlty_ID, CurrentLoopQty, MoveConfirmLine_ID, ctx, move.Get_TrxName());
                        CurrentLoopProduct.Clear();
                        ProductQty.Clear();
                        _currentPlanQlty_ID = 0;
                        CurrentLoopQty      = 0;
                        MoveConfirmLine_ID.Clear();
                        //}
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Log(Level.SEVERE, _Sql, ex);
            }
            finally
            {
                ds.Dispose();
                CurrentLoopProduct  = ProductQty = MoveConfirmLine_ID = null;
                _currentPlanQlty_ID = CurrentLoopQty = 0;
                _Sql = String.Empty;
            }
        }
        /// <summary>
        /// Process
        /// </summary>
        /// <returns>info</returns>
        protected override String DoIt()
        {
            log.Info("M_Movement_ID=" + _m_Movement_ID
                     + ", M_Locator_ID=" + _m_Locator_ID + ", M_LocatorTo_ID=" + _m_LocatorTo_ID
                     + ", M_Product_ID=" + _m_product_ID
                     + ", M_Product_Category_ID=" + _m_Product_Category_ID
                     + ", QtyRange=" + _qtyRange + ", DeleteOld=" + _deleteOld);
            _movement = new MMovement(GetCtx(), _m_Movement_ID, Get_Trx());
            if (_movement.Get_ID() == 0)
            {
                throw new SystemException("Not found: M_Movement_ID=" + _m_Movement_ID);
            }
            if (_movement.IsProcessed())
            {
                throw new SystemException("@M_Movement_ID@ @Processed@");
            }

            // is used to check Container applicable into system
            isContainerApplicable = MTransaction.ProductContainerApplicable(GetCtx());

            //
            String sqlQry = "";

            if (_deleteOld)
            {
                sqlQry = "DELETE FROM M_MovementLine WHERE Processed='N' "
                         + "AND M_Movement_ID=" + _m_Movement_ID;
                int no = DB.ExecuteQuery(sqlQry, null, Get_Trx());
                log.Fine("doIt - Deleted #" + no);
            }

            //	Create Null Storage records
            if (_qtyRange != null && _qtyRange.Equals("="))
            {
                sqlQry = "INSERT INTO M_Storage "
                         + "(AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,"
                         + " M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID,"
                         + " qtyOnHand, QtyReserved, QtyOrdered, DateLastInventory) "
                         + "SELECT l.AD_CLIENT_ID, l.AD_ORG_ID, 'Y', SysDate, 0,SysDate, 0,"
                         + " l.M_Locator_ID, p.M_Product_ID, 0,"
                         + " 0,0,0,null "
                         + "FROM M_Locator l"
                         + " INNER JOIN M_Product p ON (l.AD_Client_ID=p.AD_Client_ID) "
                         + "WHERE l.M_Warehouse_ID=" + _movement.GetM_Warehouse_ID();
                if (_m_Locator_ID != 0)
                {
                    sqlQry += " AND l.M_Locator_ID=" + _m_Locator_ID;
                }
                sqlQry += " AND l.IsDefault='Y'"
                          + " AND p.IsActive='Y' AND p.IsStocked='Y' and p.ProductType='I'"
                          + " AND NOT EXISTS (SELECT * FROM M_Storage s"
                          + " INNER JOIN M_Locator sl ON (s.M_Locator_ID=sl.M_Locator_ID) "
                          + "WHERE sl.M_Warehouse_ID=l.M_Warehouse_ID"
                          + " AND s.M_Product_ID=p.M_Product_ID)";
                int no = DB.ExecuteQuery(sqlQry, null, Get_Trx());
                log.Fine("'0' Inserted #" + no);
            }

            StringBuilder sql = null;

            if (!isContainerApplicable)
            {
                sql = new StringBuilder(
                    "SELECT s.M_Product_ID, s.M_Locator_ID, s.M_AttributeSetInstance_ID,"
                    + " s.qtyOnHand, p.M_AttributeSet_ID, 0 AS M_ProductContainer_ID "
                    + "FROM M_Product p"
                    + " INNER JOIN M_Storage s ON (s.M_Product_ID=p.M_Product_ID)"
                    + " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID) "
                    + "WHERE l.M_Warehouse_ID=" + _movement.GetDTD001_MWarehouseSource_ID()
                    + " AND p.IsActive='Y' AND p.IsStocked='Y' and p.ProductType='I'");
            }
            else
            {
                sql = new StringBuilder(
                    "SELECT s.M_Product_ID, s.M_Locator_ID, s.M_AttributeSetInstance_ID,"
                    + " NVL(SUM(s.Qty) , 0) AS qtyOnHand , p.M_AttributeSet_ID, s.M_ProductContainer_ID "
                    + "FROM M_Product p"
                    + " INNER JOIN M_ContainerStorage s ON (s.M_Product_ID=p.M_Product_ID)"
                    + " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID) "
                    + "WHERE l.M_Warehouse_ID=" + _movement.GetDTD001_MWarehouseSource_ID()
                    + " AND p.IsActive='Y' AND p.IsStocked='Y' and p.ProductType='I'");
            }
            //
            if (_m_Locator_ID != 0)
            {
                sql.Append(" AND s.M_Locator_ID=" + _m_Locator_ID);
            }

            //
            if (_m_product_ID != null && !string.IsNullOrEmpty(_m_product_ID))
            {
                sql.Append(" AND  p.M_Product_ID IN ( " + _m_product_ID + ") ");
            }
            //
            if (_m_Product_Category_ID != 0)
            {
                sql.Append(" AND p.M_Product_Category_ID=" + _m_Product_Category_ID);
            }

            //	Do not overwrite existing records
            if (!_deleteOld)
            {
                sql.Append(" AND NOT EXISTS (SELECT * FROM M_MovementLine il "
                           + "WHERE il.M_Movement_ID=" + _m_Movement_ID
                           + " AND il.M_Product_ID=s.M_Product_ID"
                           + " AND il.M_Locator_ID=s.M_Locator_ID"
                           + " AND COALESCE(il.M_AttributeSetInstance_ID,0)=COALESCE(s.M_AttributeSetInstance_ID,0)");
                if (!isContainerApplicable)
                {
                    sql.Append(@" )  ");
                }
                else
                {
                    sql.Append(@" AND COALESCE(il.M_ProductContainer_ID,0)=COALESCE(s.M_ProductContainer_ID,0) )  ");
                }
            }
            //
            if (!isContainerApplicable)
            {
                sql.Append(" ORDER BY l.Value, p.Value, s.qtyOnHand DESC");     //	Locator/Product
            }
            else
            {
                sql.Append(@" GROUP BY s.M_Product_ID, s.M_Locator_ID, s.M_AttributeSetInstance_ID, p.M_AttributeSet_ID, s.M_ProductContainer_ID, s.Qty
ORDER BY s.M_Locator_ID, s.M_Product_ID, s.Qty DESC, s.M_AttributeSetInstance_ID, p.M_AttributeSet_ID,s.M_ProductContainer_ID");        //	Locator/Product
            }
            //
            int         count   = 0;
            IDataReader idr     = null;
            DataTable   dt      = null;
            MProduct    product = null;

            try
            {
                idr = DB.ExecuteReader(sql.ToString(), null, Get_Trx());
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                // while (idr.Read())
                {
                    int M_Product_ID = Util.GetValueOfInt(dr[0]);
                    product = MProduct.Get(GetCtx(), M_Product_ID);
                    int     M_Locator_ID = Util.GetValueOfInt(dr[1]);
                    int     M_AttributeSetInstance_ID = Util.GetValueOfInt(dr[2]);
                    Decimal qtyOnHand = Util.GetValueOfDecimal(dr[3]);
                    //if (qtyOnHand == null) commented by manjot Because Decimal is Never equals to Null
                    //  qtyOnHand = Env.ZERO;
                    int M_AttributeSet_ID = Util.GetValueOfInt(dr[4]);
                    //container
                    int container_Id = Util.GetValueOfInt(dr[5]);
                    //
                    int compare = qtyOnHand.CompareTo(Env.ZERO);
                    if (_qtyRange == null ||
                        (_qtyRange.Equals(">") && compare > 0) ||
                        (_qtyRange.Equals("<") && compare < 0) ||
                        (_qtyRange.Equals("=") && compare == 0) ||
                        (_qtyRange.Equals("N") && compare != 0))
                    {
                        //Save data on Movement Line
                        _line = new MMovementLine(GetCtx(), 0, Get_Trx());
                        _line.SetAD_Client_ID(_movement.GetAD_Client_ID());
                        _line.SetAD_Org_ID(_movement.GetAD_Org_ID());
                        _line.SetM_Movement_ID(_m_Movement_ID);
                        _line.SetM_Locator_ID(_m_Locator_ID);
                        _line.SetM_LocatorTo_ID(_m_LocatorTo_ID);
                        _line.SetMovementQty(qtyOnHand);
                        _line.SetProcessed(false);
                        _line.SetM_AttributeSetInstance_ID(M_AttributeSetInstance_ID);
                        _line.SetM_Product_ID(M_Product_ID);
                        if (isContainerApplicable && _line.Get_ColumnIndex("M_ProductContainer_ID") > 0)
                        {
                            _line.SetM_ProductContainer_ID(container_Id);
                        }
                        if (_line.Get_ColumnIndex("C_UOM_ID") > 0 && product != null)
                        {
                            _line.SetC_UOM_ID(product.GetC_UOM_ID());
                        }
                        if (_line.Get_ColumnIndex("QtyEntered") > 0)
                        {
                            _line.SetQtyEntered(qtyOnHand);
                        }
                        if (!_line.Save())
                        {
                            return(GetRetrievedError(_line, "Movement Line Not Created for M_Product_ID = " + M_Product_ID + " M_AttributeSetInstance =  " + M_AttributeSetInstance_ID));
                            //log.Info("Movement Line Not Created for M_Product_ID = " + M_Product_ID + " M_AttributeSetInstance =  " + M_AttributeSetInstance_ID);
                        }
                        else
                        {
                            count = count + 1;
                        }
                    }
                }
                //idr.Close();
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                log.Log(Level.SEVERE, sql.ToString(), e);
            }

            //
            return("@M_MovementLine_ID@ - #" + count);
        }
Esempio n. 18
0
 public void ChangeNameMovement(string moveName,MMovement move)
 {
     if(dicMoves.ContainsKey(moveName))
     {
         dicMoves.Remove(moveName);
         dicMoves.Add(move.moveName,move);
     }
     else
     {
         Debug.LogWarning("Not Exist Movement. " + moveName);
         dicMoves.Add(move.moveName,move);
     }
 }
Esempio n. 19
0
 /// <summary>
 /// Parent constructor
 /// </summary>
 /// <param name="parent">parent</param>
 public MMovementConfirm(MMovement move)
     : this(move.GetCtx(), 0, move.Get_TrxName())
 {
     SetClientOrg(move);
     SetM_Movement_ID(move.GetM_Movement_ID());
 }
Esempio n. 20
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);
        }
Esempio n. 21
0
 /// <summary>
 /// Parent constructor
 /// </summary>
 /// <param name="parent">parent</param>
 public MMovementLine(MMovement parent)
     : this(parent.GetCtx(), 0, parent.Get_TrxName())
 {
     SetClientOrg(parent);
     SetM_Movement_ID(parent.GetM_Movement_ID());
 }
        protected override string DoIt()
        {
            try
            {
                sql.Clear();
                sql.Append("SELECT * FROM M_InOut WHERE IsActive = 'Y' AND DocStatus IN ('DR') ");
                if (C_DocType_ID > 0)
                {
                    sql.Append(" AND C_DocType_ID = " + C_DocType_ID);
                }
                sql.Append(" ORDER BY movementdate");
                dsInOut = DB.ExecuteDataset(sql.ToString(), null, Get_Trx());

                #region complete Order Record
                if (windowName == "OR")
                {
                    sql.Clear();
                    sql.Append("SELECT * FROM C_Order WHERE IsActive = 'Y' AND DocStatus IN ('DR') ");
                    if (C_DocType_ID > 0)
                    {
                        sql.Append(" AND C_DocType_ID = " + C_DocType_ID);
                    }
                    sql.Append(" ORDER BY dateacct");
                    dsRecord = DB.ExecuteDataset(sql.ToString(), null, Get_Trx());

                    dataRow = dsRecord.Tables[0].Select("DocStatus = 'DR' ", "dateacct");
                    if (dataRow != null && dataRow.Length > 0)
                    {
                        MOrder order = null;
                        for (int i = 0; i < dataRow.Length; i++)
                        {
                            try
                            {
                                order = new MOrder(GetCtx(), Util.GetValueOfInt(dataRow[i]["C_Order_ID"]), Get_Trx());
                                order.CompleteIt();
                                if (order.GetDocAction() == "CL")
                                {
                                    order.SetDocStatus("CO");
                                    order.SetDocAction("CL");
                                    if (!order.Save(Get_Trx()))
                                    {
                                        Rollback();
                                        ValueNamePair pp = VLogger.RetrieveError();
                                        _log.Info("Error found for saving C_Order Record ID = " + order.GetC_Order_ID() +
                                                  " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType());
                                    }
                                    else
                                    {
                                        Get_Trx().Commit();
                                    }
                                }
                                else
                                {
                                    _log.Info("Order not completed for this Record ID = " + order.GetC_Order_ID());
                                }
                            }
                            catch { }
                        }
                    }
                }
                #endregion

                #region complete Invoice Record
                if (windowName == "IN")
                {
                    sql.Clear();
                    sql.Append("SELECT * FROM C_Invoice WHERE IsActive = 'Y' AND DocStatus IN ('DR') ");
                    if (C_DocType_ID > 0)
                    {
                        sql.Append(" AND C_DocType_ID = " + C_DocType_ID);
                    }
                    sql.Append(" ORDER BY dateacct");
                    dsRecord = DB.ExecuteDataset(sql.ToString(), null, Get_Trx());
                    dataRow  = dsRecord.Tables[0].Select("DocStatus = 'DR' ", "dateacct");
                    if (dataRow != null && dataRow.Length > 0)
                    {
                        MInvoice invoice = null;
                        for (int i = 0; i < dataRow.Length; i++)
                        {
                            try
                            {
                                invoice = new MInvoice(GetCtx(), Util.GetValueOfInt(dataRow[i]["C_Invoice_ID"]), Get_Trx());
                                invoice.CompleteIt();
                                if (invoice.GetDocAction() == "CL")
                                {
                                    invoice.SetDocStatus("CO");
                                    invoice.SetDocAction("CL");
                                    if (!invoice.Save(Get_Trx()))
                                    {
                                        Rollback();
                                        ValueNamePair pp = VLogger.RetrieveError();
                                        _log.Info("Error found for saving C_Invoice Record ID = " + invoice.GetC_Invoice_ID() +
                                                  " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType());
                                    }
                                    else
                                    {
                                        Get_Trx().Commit();
                                    }
                                }
                                else
                                {
                                    _log.Info("Invoice not completed for this Record ID = " + invoice.GetC_Invoice_ID());
                                }
                            }
                            catch { }
                        }
                    }
                }
                #endregion

                #region complete material receipt
                if (windowName == "MR")
                {
                    dataRow = dsInOut.Tables[0].Select("IsSoTrx = 'N' AND IsReturnTrx = 'N' AND DocStatus = 'DR' ", "dateacct");
                    if (dataRow != null && dataRow.Length > 0)
                    {
                        for (int i = 0; i < dataRow.Length; i++)
                        {
                            try
                            {
                                inout = new MInOut(GetCtx(), Util.GetValueOfInt(dataRow[i]["M_InOut_ID"]), Get_Trx());
                                inout.CompleteIt();
                                if (inout.GetDocAction() == "CL")
                                {
                                    inout.SetDocStatus("CO");
                                    inout.SetDocAction("CL");
                                    if (!inout.Save(Get_Trx()))
                                    {
                                        Rollback();
                                        ValueNamePair pp = VLogger.RetrieveError();
                                        _log.Info("Error found for saving C_Order Record ID = " + inout.GetM_InOut_ID() +
                                                  " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType());
                                    }
                                    else
                                    {
                                        Get_Trx().Commit();
                                    }
                                }
                                else
                                {
                                    _log.Info("Material Receipt not completed for this Record ID = " + inout.GetM_InOut_ID());
                                }
                            }
                            catch { }
                        }
                    }
                }
                #endregion

                #region complete Movement Record
                if (windowName == "IM")
                {
                    sql.Clear();
                    sql.Append("SELECT * FROM M_Movement WHERE IsActive = 'Y' AND DocStatus IN ('DR') ");
                    if (C_DocType_ID > 0)
                    {
                        sql.Append(" AND C_DocType_ID = " + C_DocType_ID);
                    }
                    sql.Append(" ORDER BY movementdate");
                    dsRecord = DB.ExecuteDataset(sql.ToString(), null, Get_Trx());

                    dataRow = dsRecord.Tables[0].Select("DocStatus = 'DR' ", "movementdate");
                    if (dataRow != null && dataRow.Length > 0)
                    {
                        MMovement movement = null;
                        for (int i = 0; i < dataRow.Length; i++)
                        {
                            try
                            {
                                movement = new MMovement(GetCtx(), Util.GetValueOfInt(dataRow[i]["M_Movement_ID"]), Get_Trx());
                                movement.CompleteIt();
                                if (movement.GetDocAction() == "CL")
                                {
                                    movement.SetDocStatus("CO");
                                    movement.SetDocAction("CL");
                                    if (!movement.Save(Get_Trx()))
                                    {
                                        Rollback();
                                        ValueNamePair pp = VLogger.RetrieveError();
                                        _log.Info("Error found for saving C_Invoice Record ID = " + movement.GetM_Movement_ID() +
                                                  " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType());
                                    }
                                    else
                                    {
                                        Get_Trx().Commit();
                                    }
                                }
                                else
                                {
                                    _log.Info("Movement not completed for this Record ID = " + movement.GetM_Movement_ID());
                                }
                            }
                            catch { }
                        }
                    }
                }
                #endregion

                #region complete shipment
                if (windowName == "SH")
                {
                    dataRow = dsInOut.Tables[0].Select("IsSoTrx = 'Y' AND IsReturnTrx = 'N' AND DocStatus = 'DR' ", "dateacct");
                    if (dataRow != null && dataRow.Length > 0)
                    {
                        for (int i = 0; i < dataRow.Length; i++)
                        {
                            try
                            {
                                inout = new MInOut(GetCtx(), Util.GetValueOfInt(dataRow[i]["M_InOut_ID"]), Get_Trx());
                                inout.CompleteIt();
                                if (inout.GetDocAction() == "CL")
                                {
                                    inout.SetDocStatus("CO");
                                    inout.SetDocAction("CL");
                                    if (!inout.Save(Get_Trx()))
                                    {
                                        Rollback();
                                        ValueNamePair pp = VLogger.RetrieveError();
                                        _log.Info("Error found for saving C_Order Record ID = " + inout.GetM_InOut_ID() +
                                                  " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType());
                                    }
                                    else
                                    {
                                        Get_Trx().Commit();
                                    }
                                }
                                else
                                {
                                    _log.Info("Shipment not completed for this Record ID = " + inout.GetM_InOut_ID());
                                }
                            }
                            catch { }
                        }
                    }
                }
                #endregion

                #region complete Customer Return
                if (windowName == "CR")
                {
                    dataRow = dsInOut.Tables[0].Select("IsSoTrx = 'Y' AND IsReturnTrx = 'Y' AND DocStatus = 'DR' ", "dateacct");
                    if (dataRow != null && dataRow.Length > 0)
                    {
                        for (int i = 0; i < dataRow.Length; i++)
                        {
                            try
                            {
                                inout = new MInOut(GetCtx(), Util.GetValueOfInt(dataRow[i]["M_InOut_ID"]), Get_Trx());
                                inout.CompleteIt();
                                if (inout.GetDocAction() == "CL")
                                {
                                    inout.SetDocStatus("CO");
                                    inout.SetDocAction("CL");
                                    if (!inout.Save(Get_Trx()))
                                    {
                                        Rollback();
                                        ValueNamePair pp = VLogger.RetrieveError();
                                        _log.Info("Error found for saving C_Order Record ID = " + inout.GetM_InOut_ID() +
                                                  " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType());
                                    }
                                    else
                                    {
                                        Get_Trx().Commit();
                                    }
                                }
                                else
                                {
                                    _log.Info("Customer return not completed for this Record ID = " + inout.GetM_InOut_ID());
                                }
                            }
                            catch { }
                        }
                    }
                }
                #endregion

                #region complete Return to Vendor
                if (windowName == "VR")
                {
                    dataRow = dsInOut.Tables[0].Select("IsSoTrx = 'N' AND IsReturnTrx = 'Y' AND DocStatus = 'DR' ", "dateacct");
                    if (dataRow != null && dataRow.Length > 0)
                    {
                        for (int i = 0; i < dataRow.Length; i++)
                        {
                            try
                            {
                                inout = new MInOut(GetCtx(), Util.GetValueOfInt(dataRow[i]["M_InOut_ID"]), Get_Trx());
                                inout.CompleteIt();
                                if (inout.GetDocAction() == "CL")
                                {
                                    inout.SetDocStatus("CO");
                                    inout.SetDocAction("CL");
                                    if (!inout.Save(Get_Trx()))
                                    {
                                        Rollback();
                                        ValueNamePair pp = VLogger.RetrieveError();
                                        _log.Info("Error found for saving C_Order Record ID = " + inout.GetM_InOut_ID() +
                                                  " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType());
                                    }
                                    else
                                    {
                                        Get_Trx().Commit();
                                    }
                                }
                                else
                                {
                                    _log.Info("Return to Vendor not completed for this Record ID = " + inout.GetM_InOut_ID());
                                }
                            }
                            catch { }
                        }
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                _log.Info("Error Occured during completion of record by using  ImportedDataCompletion Process - " + ex.ToString());
                return(Msg.GetMsg(GetCtx(), "NotCompleted"));
            }
            return(Msg.GetMsg(GetCtx(), "SucessfullyCompleted"));
        }
Esempio n. 23
0
 public void AddMovement(MMovement move)
 {
     if(dicMoves.ContainsKey(move.moveName))
     {
         if(dicMoves[move.moveName] != null)
         {
             Debug.LogWarning("Already Exist Movement. " + move.moveName);
         }
         else
         {
             dicMoves[move.moveName] = move;
         }
     }
     else
     {
         dicMoves.Add(move.moveName,move);
     }
 }
Esempio n. 24
0
        /// <summary>
        /// Is used to save data on movememt line
        /// </summary>
        /// <param name="mData"></param>
        /// <returns></returns>
        public String SaveMovementLine(List <Dictionary <string, string> > mData)
        {
            StringBuilder error = new StringBuilder();
            bool          isMoveFullContainer    = false;
            bool          isMoveFullContainerQty = false;

            Trx trx = Trx.GetTrx("Movement");

            if (mData.Count > 0)
            {
                isMoveFullContainer = Util.GetValueOfBool(mData[0]["IsFullMoveContainer"]);

                //to delete all the movement lines where MoveFullContainer is False
                if (isMoveFullContainer)
                {
                    DB.ExecuteQuery("DELETE FROM M_MovementLine WHERE M_Movement_ID = " + Util.GetValueOfInt(mData[0]["M_Movement_ID"]) + " AND MoveFullContainer= 'N' ", null, null);
                }

                // Lines not inserted, as movement line already has a full move container line.
                if (!isMoveFullContainer)
                {
                    if (Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT COUNT(MoveFullContainer) FROM M_MovementLine WHERE MoveFullContainer= 'Y' AND M_Movement_ID = "
                                                            + Util.GetValueOfInt(mData[0]["M_Movement_ID"]), null, trx)) > 0)
                    {
                        trx.Close();
                        return(Msg.GetMsg(_ctx, "VIS_LinehaveFullContainer"));
                    }
                }

                // Get Line No
                int lineNo = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT NVL(MAX(Line),0) AS DefaultValue FROM M_MovementLine WHERE M_Movement_ID="
                                                                 + Util.GetValueOfInt(mData[0]["M_Movement_ID"]), null, trx));


                isMoveFullContainerQty = Util.GetValueOfBool(mData[0]["IsfullContainerQtyWise"]);

                if (!isMoveFullContainer && !isMoveFullContainerQty)
                {
                    goto moveFullContainer;
                }
                else if (isMoveFullContainer || isMoveFullContainerQty)
                {
                    error.Clear();
                    error.Append(SaveMoveLinewithFullContainer(Util.GetValueOfInt(mData[0]["M_Movement_ID"]),
                                                               Util.GetValueOfInt(mData[0]["FromLocator"]),
                                                               Util.GetValueOfInt(mData[0]["FromContainer"]),
                                                               Util.GetValueOfInt(mData[0]["ToLocator"]),
                                                               Util.GetValueOfInt(mData[0]["ToContainer"]),
                                                               lineNo, isMoveFullContainerQty,
                                                               trx));
                    trx.Close();
                    return(error.ToString());
                }

moveFullContainer:
                MMovementLine moveline = null;
                MProduct product = null;
                int      moveId  = 0;
                for (int i = 0; i < mData.Count; i++)
                {
                    #region Quantity Only
                    MMovement move = new MMovement(_ctx, Util.GetValueOfInt(mData[i]["M_Movement_ID"]), null);

                    moveId = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT NVL(M_MovementLine_ID, 0) AS M_Movement_ID FROM M_MovementLine WHERE 
                             M_Movement_ID = " + Util.GetValueOfInt(mData[i]["M_Movement_ID"]) +
                                                                 @" AND M_Product_ID = " + Util.GetValueOfInt(mData[i]["M_Product_ID"]) +
                                                                 @" AND NVL(M_AttributeSetInstance_ID, 0) = " + Util.GetValueOfInt(mData[i]["M_AttributeSetInstance_ID"]) +
                                                                 @" AND M_Locator_ID = " + Util.GetValueOfInt(mData[i]["FromLocator"]) +
                                                                 @" AND NVL(M_ProductContainer_ID, 0) = " + Util.GetValueOfInt(mData[i]["FromContainer"]) +
                                                                 @" AND M_LocatorTo_ID = " + Util.GetValueOfInt(mData[i]["ToLocator"]) +
                                                                 @" AND NVL(Ref_M_ProductContainerTo_ID, 0) = " + Util.GetValueOfInt(mData[i]["ToContainer"]) +
                                                                 @" AND AD_Org_ID = " + move.GetAD_Org_ID()));

                    if (moveId > 0)
                    {
                        moveline = new MMovementLine(_ctx, moveId, trx);
                    }
                    else
                    {
                        moveline = new MMovementLine(_ctx, 0, trx);
                    }
                    if (moveId == 0)
                    {
                        #region Create new record of movement line
                        lineNo += 10;
                        moveline.SetAD_Client_ID(move.GetAD_Client_ID());
                        moveline.SetAD_Org_ID(move.GetAD_Org_ID());
                        moveline.SetM_Movement_ID(move.GetM_Movement_ID());
                        moveline.SetLine(lineNo);
                        moveline.SetM_Product_ID(Util.GetValueOfInt(mData[i]["M_Product_ID"]));
                        moveline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(mData[i]["M_AttributeSetInstance_ID"]));
                        moveline.SetC_UOM_ID(Util.GetValueOfInt(mData[i]["C_UOM_ID"]));
                        moveline.SetM_Locator_ID(Util.GetValueOfInt(mData[i]["FromLocator"]));
                        moveline.SetM_LocatorTo_ID(Util.GetValueOfInt(mData[i]["ToLocator"]));
                        moveline.SetM_ProductContainer_ID(Util.GetValueOfInt(mData[i]["FromContainer"]));
                        moveline.SetRef_M_ProductContainerTo_ID(Util.GetValueOfInt(mData[i]["ToContainer"]));
                        moveline.SetQtyEntered(Util.GetValueOfDecimal(mData[i]["MoveQty"]));
                        moveline.SetMovementQty(Util.GetValueOfDecimal(mData[i]["MoveQty"]));
                        moveline.SetMoveFullContainer(Util.GetValueOfBool(mData[i]["IsFullMoveContainer"]));
                        #endregion
                    }
                    else
                    {
                        #region Update record of movement line
                        moveline.SetQtyEntered(Decimal.Add(moveline.GetQtyEntered(), Util.GetValueOfDecimal(mData[i]["MoveQty"])));
                        moveline.SetMovementQty(Decimal.Add(moveline.GetMovementQty(), Util.GetValueOfDecimal(mData[i]["MoveQty"])));
                        moveline.SetMoveFullContainer(Util.GetValueOfBool(mData[i]["IsFullMoveContainer"]));
                        #endregion
                    }
                    if (!moveline.Save(trx))
                    {
                        #region Save error catch and rollback
                        product = MProduct.Get(_ctx, Util.GetValueOfInt(mData[i]["M_Product_ID"]));
                        ValueNamePair pp = VLogger.RetrieveError();
                        if (pp != null)
                        {
                            _log.SaveError("Movement line not inserted through Move Container Form : ", pp.GetName());
                            if (String.IsNullOrEmpty(error.ToString()))
                            {
                                error.Append(Msg.GetMsg(_ctx, "VIS_MoveLineNotSaveFor") + product.GetName() + Msg.GetMsg(_ctx, "VIS_DueTo") + pp.GetName());
                            }
                            else
                            {
                                error.Append(" , " + Msg.GetMsg(_ctx, "VIS_MoveLineNotSaveFor") + product.GetName() + Msg.GetMsg(_ctx, "VIS_DueTo") + pp.GetName());
                            }
                        }
                        trx.Rollback();
                        #endregion
                    }
                    else
                    {
                        trx.Commit();
                    }

                    #endregion
                }
            }
            trx.Close();
            return(String.IsNullOrEmpty(error.ToString()) ? "VIS_SuccessFullyInserted" : error.ToString());
        }