예제 #1
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"));
        }
예제 #3
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());
 }
예제 #4
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;
            }
        }
예제 #5
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());
        }
예제 #6
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());
        }