Example #1
0
        /// <summary>
        /// Get Organizations Of Client
        /// </summary>
        /// <param name="po">persistent object</param>
        /// <returns>array of orgs</returns>
        public static MOrg[] GetOfClient(PO po)
        {
            List <MOrg> list = new List <MOrg>();
            String      sql  = "SELECT * FROM AD_Org WHERE AD_Client_ID=" + po.GetAD_Client_ID() + " ORDER BY Value";

            try
            {
                DataSet ds = DataBase.DB.ExecuteDataset(sql, null, null);
                if (ds.Tables.Count > 0)
                {
                    DataRow dr       = null;
                    int     totCount = ds.Tables[0].Rows.Count;
                    for (int i = 0; i < totCount; i++)
                    {
                        dr = ds.Tables[0].Rows[i];
                        list.Add(new MOrg(po.GetCtx(), dr, null));
                    }
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql, e);
            }

            MOrg[] retValue = new MOrg[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }
Example #2
0
        /// <summary>
        /// Fire Model Change.
        ///	Call modelChange method of added validators
        /// </summary>
        /// <param name="po">persistent objects</param>
        /// <param name="changeType">ModalValidatorVariables.CHANGETYPE_*</param>
        /// <returns>error message or NULL for no veto</returns>
        public String FireModelChange(PO po, int changeType)
        {
            if (po == null || _modelChangeListeners.Count == 0)
            {
                return(null);
            }
            //
            String propertyName        = po.Get_TableName() + po.GetAD_Client_ID();
            List <ModelValidator> list = null;

            if (_modelChangeListeners.ContainsKey(propertyName))
            {
                list = new List <ModelValidator>();
                list = _modelChangeListeners[propertyName];
            }
            if (list == null || list.Count == 0)
            {
                return(null);
            }

            //
            for (int i = 0; i < list.Count; i++)
            {
                try
                {
                    ModelValidator validator = (ModelValidator)list[i];
                    if (validator.GetAD_Client_ID() == po.GetAD_Client_ID())
                    {
                        String error = validator.ModelChange(po, changeType);
                        if (error != null && error.Length > 0)
                        {
                            return(error);
                        }
                    }
                }
                catch (Exception e)
                {
                    String error = e.Message;
                    if (error == null)
                    {
                        error = e.ToString();
                    }
                    return(error);
                }
            }
            return(null);
        }
Example #3
0
        /// <summary>
        /// Parse text
        /// </summary>
        /// <param name="text">text</param>
        /// <param name="po">po object</param>
        /// <returns>parsed text</returns>
        public static string Parse(String text, PO po)
        {
            if (po == null || text.IndexOf("@") == -1)
            {
                return(text);
            }

            String        inStr = text;
            String        token;
            StringBuilder outStr = new StringBuilder();

            int i = inStr.IndexOf("@");

            while (i != -1)
            {
                outStr.Append(inStr.Substring(0, i)); // up to @
                inStr = inStr.Substring(i + 1);       ///from first @

                int j = inStr.IndexOf("@");           // next @
                if (j < 0)                            // no second tag
                {
                    inStr = "@" + inStr;
                    break;
                }

                token = inStr.Substring(0, j);
                if (token == "Tenant")
                {
                    int id = po.GetAD_Client_ID();
                    outStr.Append(DB.ExecuteScalar("Select Name FROM AD_Client WHERE AD_Client_ID=" + id));
                }
                else if (token == "Org")
                {
                    int id = po.GetAD_Org_ID();
                    outStr.Append(DB.ExecuteScalar("Select Name FROM AD_ORG WHERE AD_ORG_ID=" + id));
                }
                else if (token == "BPName")
                {
                    if (po.Get_TableName() == "C_BPartner")
                    {
                        outStr.Append(ParseVariable("Name", po));
                    }
                    else
                    {
                        outStr.Append("@" + token + "@");
                    }
                }
                else
                {
                    outStr.Append(ParseVariable(token, po));            // replace context
                }
                inStr = inStr.Substring(j + 1);
                // from second @
                i = inStr.IndexOf("@");
            }

            outStr.Append(inStr);                                               //	add remainder
            return(outStr.ToString());
        }
Example #4
0
        }       //	updateInfoColumns

        /// <summary>
        /// Fire Document Validation.
        /// Call docValidate method of added validators
        /// </summary>
        /// <param name="po">persistent objects</param>
        /// <param name="docTiming">see ModalValidatorVariables.DOCTIMING_ constants</param>
        /// <returns>error message or null</returns>
        public String FireDocValidate(PO po, int docTiming)
        {
            if (po == null || _docValidateListeners.Count == 0)
            {
                return(null);
            }
            //
            String propertyName        = po.Get_TableName() + po.GetAD_Client_ID();
            List <ModelValidator> list = null;

            if (_docValidateListeners.ContainsKey(propertyName))
            {
                list = new List <ModelValidator>();
                list = _docValidateListeners[propertyName];
            }
            if (list == null || list.Count == 0)
            {
                return(null);
            }

            //
            for (int i = 0; i < list.Count; i++)
            {
                ModelValidator validator = null;
                try
                {
                    validator = (ModelValidator)list[i];
                    if (validator.GetAD_Client_ID() == po.GetAD_Client_ID())
                    {
                        String error = validator.DocValidate(po, docTiming);
                        if (error != null && error.Length > 0)
                        {
                            return(error);
                        }
                    }
                }
                catch (Exception e)
                {
                    s_log.Log(Level.SEVERE, validator.ToString(), e);
                }
            }
            return(null);
        }
Example #5
0
        }       //	getAll

        /// <summary>
        /// Execute Auto Assignment
        /// </summary>
        /// <param name="po">PO to be modified</param>
        /// <param name="newRecord">new</param>
        /// <returns>true if modified</returns>
        static public bool Execute(PO po, bool newRecord)
        {
            if (s_assignments == null)
            {
                s_assignments = GetAll(po.GetCtx());
            }
            bool modified = false;

            for (int i = 0; i < s_assignments.Length; i++)
            {
                MAssignSet set = s_assignments[i];
                if (!set.IsActive())
                {
                    continue;
                }
                //	Check IDs
                if (po.Get_Table_ID() == set.GetAD_Table_ID() &&
                    (po.GetAD_Client_ID() == set.GetAD_Client_ID() ||
                     set.GetAD_Client_ID() == 0))
                {
                    //	Check Timing
                    String rule = set.GetAutoAssignRule();
                    if (!newRecord && rule.Equals(AUTOASSIGNRULE_CreateOnly))
                    {
                        continue;
                    }
                    if (newRecord &&
                        (rule.Equals(AUTOASSIGNRULE_UpdateOnly) ||
                         rule.Equals(AUTOASSIGNRULE_UpdateIfNotProcessed)))
                    {
                        continue;
                    }
                    //	Eliminate Processed
                    if (rule.Equals(AUTOASSIGNRULE_CreateAndUpdateIfNotProcessed) ||
                        rule.Equals(AUTOASSIGNRULE_UpdateIfNotProcessed))
                    {
                        int indexProcessed = po.Get_ColumnIndex("Processed");
                        if (indexProcessed != -1 &&
                            "Y".Equals(po.Get_Value(indexProcessed)))
                        {
                            continue;
                        }
                    }
                    //
                    if (set.ExecuteIt(po))
                    {
                        modified = true;
                    }
                }
            }
            return(modified);
        }       //	execute
Example #6
0
        /**
         *  Get active Material Cost Element for client
         *	@param po parent
         *	@return cost element array
         */
        public static MCostElement[] GetCostingMethods(PO po)
        {
            List <MCostElement> list = new List <MCostElement>();
            String sql = "SELECT * FROM M_CostElement "
                         + "WHERE AD_Client_ID=@Client_ID"
                         + " AND IsActive='Y' AND CostElementType='M' AND CostingMethod IS NOT NULL";
            DataTable dt = null;

            //IDataReader idr = null;
            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@Client_ID", po.GetAD_Client_ID());
                //idr = DataBase.DB.ExecuteReader(sql, param, po.Get_TrxName());
                DataSet ds = DataBase.DB.ExecuteDataset(sql, param, po.Get_TrxName());
                dt = new DataTable();
                dt = ds.Tables[0];
                //idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    list.Add(new MCostElement(po.GetCtx(), dr, po.Get_TrxName()));
                }
            }
            catch (Exception e)
            {
                //if (idr != null)
                // {
                //     idr.Close();
                //}
                _log.Log(Level.SEVERE, sql, e);
            }
            finally
            {
                dt = null;
            }

            MCostElement[] retValue = new MCostElement[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }
Example #7
0
        /// <summary>
        /// Insert data in Version table against multikey Master table
        /// </summary>
        /// <param name="baseTbl"></param>
        /// <param name="keyCols"></param>
        /// <param name="tblVer"></param>
        /// <returns></returns>
        private string InsertMKVersionData(MTable baseTbl, string[] keyCols, MTable tblVer)
        {
            string retMsg = "";
            // Get data from Master table
            DataSet dsRecs = DB.ExecuteDataset("SELECT * FROM " + baseTbl.GetTableName(), null, _trx);

            // check if there are any records in master table
            if (dsRecs != null && dsRecs.Tables[0].Rows.Count > 0)
            {
                // loop through all records and insert in Version table
                for (int i = 0; i < dsRecs.Tables[0].Rows.Count; i++)
                {
                    // get where Clause for Master table against multiple key columns
                    GetMKWhereClause(dsRecs.Tables[0].Rows[i], keyCols);
                    if (MKWhereClause.Length > 0)
                    {
                        int count = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(" + tblVer.GetTableName() + "_ID) FROM " + tblVer.GetTableName() + " WHERE " + MKWhereClause.ToString(), null, _trx));
                        if (count > 0)
                        {
                            continue;
                        }
                    }

                    // create PO object of source table (Master table)
                    PO sPO = baseTbl.GetPO(GetCtx(), dsRecs.Tables[0].Rows[i], _trx);
                    // create PO object of destination table (Version table)
                    PO dPO = tblVer.GetPO(GetCtx(), 0, _trx);
                    sPO.CopyTo(dPO);
                    dPO.SetAD_Client_ID(sPO.GetAD_Client_ID());
                    dPO.SetAD_Org_ID(sPO.GetAD_Org_ID());
                    dPO.Set_Value("RecordVersion", "1");
                    dPO.Set_ValueNoCheck("VersionValidFrom", sPO.Get_Value("Created"));
                    dPO.Set_ValueNoCheck("IsVersionApproved", true);
                    dPO.Set_ValueNoCheck("Processed", true);
                    dPO.Set_ValueNoCheck("ProcessedVersion", true);
                    for (int j = 0; j < keyCols.Length; j++)
                    {
                        dPO.Set_ValueNoCheck(keyCols[j], sPO.Get_Value(keyCols[j]));
                    }
                    dPO.Set_Value("Export_ID", null);
                    if (!dPO.Save())
                    {
                        ValueNamePair vnp   = VLogger.RetrieveError();
                        string        error = "";
                        if (vnp != null)
                        {
                            error = vnp.GetName();
                            if (error == "" && vnp.GetValue() != null)
                            {
                                error = vnp.GetValue();
                            }
                        }
                        if (error == "")
                        {
                            error = "Error in saving data in Version table";
                        }
                        return(retMsg);
                    }
                }
            }

            return(retMsg);
        }
Example #8
0
        /**
         *  Get Material Cost Element or create it
         *	@param po parent
         *	@param CostingMethod method
         *	@return cost element
         */
        public static MCostElement GetMaterialCostElement(PO po, String CostingMethod)
        {
            if (CostingMethod == null || CostingMethod.Length == 0)
            {
                _log.Severe("No CostingMethod");
                return(null);
            }
            //
            MCostElement retValue = null;
            String       sql      = "SELECT * FROM M_CostElement WHERE AD_Client_ID=" + po.GetAD_Client_ID() + " AND CostingMethod=@costingMethod ORDER BY AD_Org_ID";
            DataTable    dt       = null;
            IDataReader  idr      = null;

            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@costingMethod", CostingMethod);

                idr = DataBase.DB.ExecuteReader(sql, param, po.Get_TrxName());
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();

                //bool n = dr.next(); //jz to fix DB2 resultSet closed problem
                //if (n)
                foreach (DataRow dr in dt.Rows)
                {
                    retValue = new MCostElement(po.GetCtx(), dr, po.Get_TrxName());
                }
                //if (n && dr.next())
                //    s_log.warning("More then one Material Cost Element for CostingMethod=" + CostingMethod);
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            finally
            {
                dt = null;
            }

            if (retValue != null)
            {
                return(retValue);
            }

            //	Create New
            retValue = new MCostElement(po.GetCtx(), 0, po.Get_TrxName());
            retValue.SetClientOrg(po.GetAD_Client_ID(), 0);
            String name = MRefList.GetListName(po.GetCtx(), COSTINGMETHOD_AD_Reference_ID, CostingMethod);

            if (name == null || name.Length == 0)
            {
                name = CostingMethod;
            }
            retValue.SetName(name);
            retValue.SetCostElementType(COSTELEMENTTYPE_Material);
            retValue.SetCostingMethod(CostingMethod);
            retValue.Save();
            return(retValue);
        }
        /// <summary>
        /// Process Document Value Workflow
        /// </summary>
        /// <param name="document">document</param>
        /// <param name="AD_Table_ID">table</param>
        /// <returns>true if WF started</returns>
        public bool Process(PO document, int AD_Table_ID)
        {
            _noCalled++;
            MWorkflow[] wfs = MWorkflow.GetDocValue(document.GetCtx(),
                                                    document.GetAD_Client_ID(), AD_Table_ID);
            if (wfs == null || wfs.Length == 0)
            {
                return(false);
            }

            bool started = false;

            for (int i = 0; i < wfs.Length; i++)
            {
                MWorkflow wf = wfs[i];
                //	We have a Document Workflow
                String logic = wf.GetDocValueLogic();
                if (logic == null || logic.Length == 0)
                {
                    log.Severe("Workflow has no Logic - " + wf.GetName());
                    continue;
                }

                //	Re-check: Document must be same Client as workflow
                if (wf.GetAD_Client_ID() != document.GetAD_Client_ID())
                {
                    continue;
                }

                //	Check Logic
                bool sql = logic.StartsWith("SQL=");
                if (sql && !TestStart(wf, document))
                {
                    log.Fine("SQL Logic evaluated to false (" + logic + ")");
                    continue;
                }
                if (!sql && !Evaluator.EvaluateLogic(document, logic))
                {
                    log.Fine("Logic evaluated to false (" + logic + ")");
                    continue;
                }

                if (document.Get_Trx() != null)
                {
                    ManageSkippedWF.Add(document.Get_Trx().SetUniqueTrxName(Trx.CreateTrxName("WFDV")), document);
                    log.Severe("Not started: " + wf);
                    continue;
                }
                //	Start Workflow
                log.Fine(logic);
                int         AD_Process_ID = 305;        //	HARDCODED
                ProcessInfo pi            = new ProcessInfo(wf.GetName(), AD_Process_ID, AD_Table_ID, document.Get_ID());
                pi.SetAD_User_ID(document.GetCtx().GetAD_User_ID());
                pi.SetAD_Client_ID(document.GetAD_Client_ID());

                // vinay bhatt for window id
                pi.SetAD_Window_ID(document.GetAD_Window_ID());
                //

                wf.GetCtx().SetContext("#AD_Client_ID", pi.GetAD_Client_ID().ToString());
                if (wf.Start(pi) != null)
                {
                    log.Config(wf.GetName());
                    _noStarted++;
                    started = true;
                }
            }
            return(started);
        }
Example #10
0
        }       //	GetSourceColumn

        /**
         *  Is Criteria Met
         *	@param po po
         *	@return true if criteria is met
         */
        public bool IsMet(PO po)
        {
            MColumn column     = GetSourceColumn();
            String  columnName = column.GetColumnName();
            int     index      = po.Get_ColumnIndex(columnName);

            if (index == -1)
            {
                throw new Exception(ToString() + ": AD_Column_ID not found");
            }
            //	Get Value
            Object value = po.Get_Value(index);
            String op    = GetOperation();
            //	Compare Value
            String compareString = GetValueString();

            if (op.Equals(OPERATION_Sql))
            {
                compareString = GetSQLValue();
                op            = OPERATION_Eq;
            }
            //	NULL handling
            if (value == null)
            {
                if (compareString == null ||
                    compareString.Length == 0 ||
                    compareString.Equals("NULL", StringComparison.OrdinalIgnoreCase))
                {
                    if (op.Equals(OPERATION_Eq))
                    {
                        return(true);
                    }
                }
                else
                {
                    if (!op.Equals(OPERATION_Eq))
                    {
                        return(true);
                    }
                }
                return(false);
            }
            if (GetRecord_ID() == 0 &&          //	no value to compare to
                (compareString == null || compareString.Length == 0))
            {
                return(false);
            }

            //	Like - String
            if (op.Equals(OPERATION_Like))
            {
                String s   = value.ToString();
                String cmp = compareString;
                if (cmp.IndexOf('%') != -1)             //	SQL Like
                {
                    log.Warning(ToString() + ": SQL LIKE not supported yet");
                    //TODO: SQL Like
                }
                return(s.ToUpper()
                       .IndexOf(cmp.ToUpper()) != 0);   //	substring
            }

            try
            {
                if (value is int)
                {
                    int ii  = (int)value;
                    int?cmp = null;
                    if (GetRecord_ID() > 0)
                    {
                        cmp = GetRecord_ID();
                    }
                    else
                    {
                        cmp = (int)int.Parse(compareString);
                    }
                    //	Tree Handling
                    bool?treeOp = (bool?)TreeOperation(columnName, cmp, op, ii, po.GetAD_Client_ID());
                    if (treeOp != null)
                    {
                        return(treeOp.Value);
                    }
                    //
                    if (op.Equals(OPERATION_Eq))
                    {
                        return(ii.Equals(cmp));
                    }
                    else if (op.Equals(OPERATION_NotEq))
                    {
                        return(!ii.Equals(cmp));
                    }
                    else if (op.Equals(OPERATION_Gt))
                    {
                        return(ii.CompareTo(cmp) > 0);
                    }
                    else if (op.Equals(OPERATION_GtEq))
                    {
                        return(ii.CompareTo(cmp) >= 0);
                    }
                    else if (op.Equals(OPERATION_Le))
                    {
                        return(ii.CompareTo(cmp) < 0);
                    }
                    else if (op.Equals(OPERATION_LeEq))
                    {
                        return(ii.CompareTo(cmp) <= 0);
                    }
                }
                else if (value is Decimal)
                {
                    Decimal bd  = (Decimal)value;
                    Decimal cmp = decimal.Parse(compareString);
                    if (op.Equals(OPERATION_Eq))
                    {
                        return(bd.Equals(cmp));
                    }
                    else if (op.Equals(OPERATION_NotEq))
                    {
                        return(!bd.Equals(cmp));
                    }
                    else if (op.Equals(OPERATION_Gt))
                    {
                        return(bd.CompareTo(cmp) > 0);
                    }
                    else if (op.Equals(OPERATION_GtEq))
                    {
                        return(bd.CompareTo(cmp) >= 0);
                    }
                    else if (op.Equals(OPERATION_Le))
                    {
                        return(bd.CompareTo(cmp) < 0);
                    }
                    else if (op.Equals(OPERATION_LeEq))
                    {
                        return(bd.CompareTo(cmp) <= 0);
                    }
                }
                else if (value is DateTime)
                {
                    DateTime?ts  = (DateTime?)value;
                    DateTime cmp = DateTime.Parse(compareString);
                    if (op.Equals(OPERATION_Eq))
                    {
                        return(ts.Equals(cmp));
                    }
                    else if (op.Equals(OPERATION_NotEq))
                    {
                        return(!ts.Equals(cmp));
                    }
                    else if (op.Equals(OPERATION_Gt))
                    {
                        return(ts.Value.CompareTo(cmp) > 0);
                    }
                    else if (op.Equals(OPERATION_GtEq))
                    {
                        return(ts.Value.CompareTo(cmp) >= 0);
                    }
                    else if (op.Equals(OPERATION_Le))
                    {
                        return(ts.Value.CompareTo(cmp) < 0);
                    }
                    else if (op.Equals(OPERATION_LeEq))
                    {
                        return(ts.Value.CompareTo(cmp) <= 0);
                    }
                }
                else
                // String
                {
                    String s   = value.ToString();
                    String cmp = compareString;
                    if (op.Equals(OPERATION_Eq))
                    {
                        return(s.Equals(cmp));
                    }
                    else if (op.Equals(OPERATION_NotEq))
                    {
                        return(!s.Equals(cmp));
                    }
                    else if (op.Equals(OPERATION_Gt))
                    {
                        return(s.CompareTo(cmp) > 0);
                    }
                    else if (op.Equals(OPERATION_GtEq))
                    {
                        return(s.CompareTo(cmp) >= 0);
                    }
                    else if (op.Equals(OPERATION_Le))
                    {
                        return(s.CompareTo(cmp) < 0);
                    }
                    else if (op.Equals(OPERATION_LeEq))
                    {
                        return(s.CompareTo(cmp) <= 0);
                    }
                }
            }
            catch (Exception e)
            {
                log.Warning(ToString() + ": " + e);
            }
            return(false);
        }       //	isMet
        /// <summary>
        /// Function to update data in Master Table based on the versions saved
        /// </summary>
        /// <param name="dsRec">All Records which need to be updated</param>
        /// <param name="TableName">Version Table Name</param>
        /// <param name="VerTableID">Version Table ID</param>
        /// <returns>True/False based on the Updation of data in parent table</returns>
        private bool UpdateRecords(DataSet dsRec, string TableName, int VerTableID)
        {
            // Get Master table name from Version table
            string BaseTblName = TableName;

            if (TableName.EndsWith("_Ver"))
            {
                BaseTblName = BaseTblName.Substring(0, TableName.Length - 4);
            }
            // Master Table ID from Table name
            int BaseTableID = Util.GetValueOfInt(DB.ExecuteScalar("SELECT AD_Table_ID FROM AD_Table WHERE TableName = '" + BaseTblName + "'"));

            // Get Column information of Master Table
            DataSet dsDBColNames = DB.ExecuteDataset("SELECT ColumnName, AD_Reference_ID, IsUpdateable, IsAlwaysUpdateable FROM AD_Column WHERE AD_Table_ID = " + BaseTableID);

            if (dsDBColNames != null && dsDBColNames.Tables[0].Rows.Count > 0)
            {
                log.Info("Processing for " + TableName + " :: ");

                StringBuilder sqlSB           = new StringBuilder("");
                bool          recordProcessed = false;
                // create object of Master Table
                MTable tbl = new MTable(GetCtx(), BaseTableID, null);
                // create object of Version table
                MTable tblVer = new MTable(GetCtx(), VerTableID, null);

                // check whether master table has Single key
                bool isSingleKey = tbl.IsSingleKey();

                // List of records which were not processed by process in case of any error
                List <string> keys  = new List <string>();
                StringBuilder sbKey = new StringBuilder("");
                // Loop through the records which need to be updated on Master Table
                for (int i = 0; i < dsRec.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = dsRec.Tables[0].Rows[i];
                    sbKey.Clear();
                    PO poDest   = null;
                    PO poSource = tblVer.GetPO(GetCtx(), dr, null);
                    // if table has single key
                    if (isSingleKey)
                    {
                        // Create object of PO Class from TableName and Record ID
                        poDest = MTable.GetPO(GetCtx(), BaseTblName, Util.GetValueOfInt(dr[BaseTblName + "_ID"]), null);
                        sbKey.Append(Util.GetValueOfInt(dr[BaseTblName + "_ID"]));
                    }
                    else
                    {
                        // Create object of PO Class from combination of key columns
                        string[]      keyCols   = tbl.GetKeyColumns();
                        StringBuilder whereCond = new StringBuilder("");
                        for (int w = 0; w < keyCols.Length; w++)
                        {
                            if (w == 0)
                            {
                                if (keyCols[w] != null)
                                {
                                    whereCond.Append(keyCols[w] + " = " + poSource.Get_Value(keyCols[w]));
                                }
                                else
                                {
                                    whereCond.Append(" NVL(" + keyCols[w] + ",0) = 0");
                                }
                            }
                            else
                            {
                                if (keyCols[w] != null)
                                {
                                    whereCond.Append(" AND " + keyCols[w] + " = " + poSource.Get_Value(keyCols[w]));
                                }
                                else
                                {
                                    whereCond.Append(" AND NVL(" + keyCols[w] + ",0) = 0");
                                }
                            }
                        }
                        poDest = tbl.GetPO(GetCtx(), whereCond.ToString(), null);
                        sbKey.Append(whereCond);
                    }

                    // check if there is any error in processing record, then continue and do not process next versions
                    if (keys.Contains(sbKey.ToString()))
                    {
                        continue;
                    }

                    // Check whether Master Table contains "Processing" Column
                    if (poDest.Get_ColumnIndex("Processing") >= 0)
                    {
                        // if "Processing" column found then return, do not update in Master Table,
                        // because transaction might be in approval process
                        if (Util.GetValueOfString(poSource.Get_Value("Processing")) == "Y")
                        {
                            keys.Add(sbKey.ToString());
                            continue;
                        }
                    }

                    // Check whether Master Table contains "Processed" Column
                    if (poDest.Get_ColumnIndex("Processed") >= 0)
                    {
                        if (Util.GetValueOfString(poSource.Get_Value("Processed")) == "Y")
                        {
                            recordProcessed = true;
                        }
                    }

                    // set client and Organization ID from Version table to Master
                    // as copy PO set these ID's as 0
                    poDest.SetAD_Client_ID(poSource.GetAD_Client_ID());
                    poDest.SetAD_Org_ID(poSource.GetAD_Org_ID());

                    StringBuilder sbColName = new StringBuilder("");
                    // Loop through all the columns in Master Table
                    for (int j = 0; j < dsDBColNames.Tables[0].Rows.Count; j++)
                    {
                        sbColName.Clear();
                        // Get Name of Column
                        sbColName.Append(dsDBColNames.Tables[0].Rows[j]["ColumnName"]);

                        // check if column exist in Default columns list, in that case do not update and continue to next column
                        if (defcolNames.Contains(sbColName.ToString()))
                        {
                            continue;
                        }
                        // No need to update Primary key column, continue to next column
                        if (sbColName.ToString().Equals(BaseTblName + "_ID"))
                        {
                            continue;
                        }
                        // if column is of "Yes-No" type i.e. Reference ID is 20 (Fixed) then set True/False
                        if (Util.GetValueOfInt(dsDBColNames.Tables[0].Rows[j]["AD_Reference_ID"]) == 20)
                        {
                            Object val = false;
                            if (poSource.Get_Value(sbColName.ToString()) != null)
                            {
                                val = poSource.Get_Value(sbColName.ToString());
                            }
                            poDest.Set_Value(sbColName.ToString(), val);
                        }
                        else
                        {
                            poDest.Set_ValueNoCheck(sbColName.ToString(), poSource.Get_Value(sbColName.ToString()));
                        }

                        // Check if Master record is Processed and Always Updatable is false then check whether any value updated in such column
                        // if value updated then return false, can't change data in Processed record if it's not Always Updatable
                        if (recordProcessed && Util.GetValueOfString(dsDBColNames.Tables[0].Rows[j]["IsAlwaysUpdateable"]) == "N")
                        {
                            bool upd = poDest.Is_ValueChanged(sbColName.ToString());
                            if (upd)
                            {
                                msg.Append("Can't update  " + sbColName.ToString() + " in " + TableName);
                                log.SaveError("ERROR", "Can not update processed record for column ==>> " + sbColName.ToString());
                                // Add record to the list of unprocessed records
                                keys.Add(sbKey.ToString());
                                continue;
                            }
                        }
                    }

                    // Save Master Record
                    if (!poDest.Save())
                    {
                        // Add record to the list of unprocessed records
                        keys.Add(sbKey.ToString());
                        // Check for Errors
                        ValueNamePair vnp   = VLogger.RetrieveError();
                        string        error = "";
                        if (vnp != null)
                        {
                            error = vnp.GetName();
                            if (error == "" && vnp.GetValue() != null)
                            {
                                error = vnp.GetValue();
                            }
                        }
                        if (error == "")
                        {
                            error = "Error in updating Version";
                        }

                        msg.Append("Save error in " + TableName + " ==>> " + error);
                        log.SaveError("ERROR", error);

                        sqlSB.Clear();

                        sqlSB.Append("UPDATE " + TableName + " SET VersionLog = '" + error + "' WHERE " + TableName + "_ID = " + dr[TableName + "_ID"]);
                        int count = DB.ExecuteQuery(sqlSB.ToString(), null, null);

                        continue;
                    }
                    else
                    {
                        // Update Version table, Set "ProcessedVersion" to "Y", so that it don't consider when process runs next time
                        sqlSB.Clear();
                        // Update against record id in case of Single key, and update Key column in version table as well in case of new record
                        if (isSingleKey)
                        {
                            sqlSB.Append("UPDATE " + TableName + " SET ProcessedVersion = 'Y', " + BaseTblName + "_ID  = " + poDest.Get_ID() + " WHERE " + TableName + "_ID = " + dr[TableName + "_ID"]);
                        }
                        // else
                        else
                        {
                            sqlSB.Append("UPDATE " + TableName + " SET ProcessedVersion = 'Y' WHERE " + TableName + "_ID = " + dr[TableName + "_ID"]);
                        }

                        int count = DB.ExecuteQuery(sqlSB.ToString(), null, null);
                        if (count <= 0)
                        {
                            log.Info(TableName + " not updated ==>> " + sqlSB.ToString());
                        }
                    }
                }
            }
            return(true);
        }