Example #1
0
        /// <summary>
        /// Get all active Tables with input sql
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="sql">query to get tables</param>
        /// <returns>array of tables</returns>

        public static List <MTable> GetTablesByQuery(Ctx ctx, String sql)
        {
            IDataReader   idr  = null;
            List <MTable> list = new List <MTable>();

            try
            {
                idr = DataBase.DB.ExecuteReader(sql);
                while (idr.Read())
                {
                    MTable table = new MTable(ctx, idr, null);

                    /**
                     * String s = table.getSQLCreate();
                     * HashMap hmt = table.get_HashMap();
                     * MColumn[] columns = table.getColumns(false);
                     * HashMap hmc = columns[0].get_HashMap();
                     **/
                    list.Add(table);
                }
                idr.Close();
            }
            catch (Exception e)
            {
                idr.Close();
                s_log.Log(Level.SEVERE, sql, e);
            }
            return(list);
        }
        /// <summary>
        /// After save logic for asset
        /// </summary>
        /// <param name="newRecord"></param>
        /// <param name="success"></param>
        /// <returns></returns>
        protected override bool AfterSave(bool newRecord, bool success)
        {
            //Cost Code Commented - As not required on Asset Save
            //if (newRecord)
            //{
            //    UpdateAssetCost();
            //}

            // create default Account
            StringBuilder _sql = new StringBuilder("");

            // check table exist or not
            _sql.Append("SELECT count(*) FROM all_objects WHERE object_type IN ('TABLE') AND (object_name)  = UPPER('FRPT_Asset_Group_Acct')  AND OWNER LIKE '" + DB.GetSchema() + "'");
            int count = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString()));

            if (count > 0)
            {
                PO  obj          = null;
                int assetId      = GetA_Asset_ID();
                int assetGroupId = GetA_Asset_Group_ID();
                // get related to value agaisnt asset = 75
                string sql = "SELECT L.VALUE FROM AD_REF_LIST L inner join AD_Reference r on R.AD_REFERENCE_ID=L.AD_REFERENCE_ID where   r.name='FRPT_RelatedTo' and l.name='Asset'";
                string _RelatedToProduct = Convert.ToString(DB.ExecuteScalar(sql));

                _sql.Clear();
                _sql.Append("Select Count(*) From FRPT_Asset_Acct   where A_Asset_ID=" + assetId + " AND IsActive = 'Y' AND AD_Client_ID = " + GetAD_Client_ID());
                int value = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString()));
                if (value < 1)
                {
                    _sql.Clear();
                    _sql.Append(@"Select  PCA.c_acctschema_id, PCA.c_validcombination_id, PCA.frpt_acctdefault_id " +
                                " From FRPT_Asset_Group_Acct PCA " +
                                " inner join frpt_acctdefault ACC ON acc.frpt_acctdefault_id= PCA.frpt_acctdefault_id " +
                                " where PCA.A_Asset_Group_ID=" + assetGroupId +
                                " and acc.frpt_relatedto=" + _RelatedToProduct +
                                " AND PCA.IsActive = 'Y' AND PCA.AD_Client_ID = " + GetAD_Client_ID());

                    DataSet ds = DB.ExecuteDataset(_sql.ToString());
                    if (ds.Tables != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            obj = MTable.GetPO(GetCtx(), "FRPT_Asset_Acct", 0, null);
                            obj.Set_ValueNoCheck("AD_Org_ID", 0);
                            obj.Set_ValueNoCheck("A_Asset_ID", assetId);
                            obj.Set_ValueNoCheck("C_AcctSchema_ID", Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_AcctSchema_ID"]));
                            obj.Set_ValueNoCheck("C_ValidCombination_ID", Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_ValidCombination_ID"]));
                            obj.Set_ValueNoCheck("FRPT_AcctDefault_ID", Util.GetValueOfInt(ds.Tables[0].Rows[i]["FRPT_AcctDefault_ID"]));
                            if (!obj.Save())
                            {
                                ValueNamePair pp = VLogger.RetrieveError();
                                _log.Log(Level.SEVERE, "Could Not create FRPT_Asset_Acct. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName());
                            }
                        }
                    }
                }
            }

            return(true);
        }
Example #3
0
        /// <summary>
        ///Add Translation Columns
        /// </summary>
        private void InitColumns()
        {
            //MTable table = null;
            //MTable table = MTable.get(Env.getCtx(), m_trlTableName);
            MTable table = MTable.Get(Utility.Env.GetContext(), _trlTableName);

            if (table == null)
            {
                throw new ArgumentException("Table Not found=" + _trlTableName);
            }
            MColumn[] columns = table.GetColumns(false);
            for (int i = 0; i < columns.Length; i++)
            {
                MColumn column = columns[i];
                if (column.IsStandardColumn())
                {
                    continue;
                }
                String columnName = column.GetColumnName();
                if (columnName.EndsWith("_ID") ||
                    columnName.StartsWith("AD_Language") ||
                    columnName.Equals("IsTranslated"))
                {
                    continue;
                }
                //
                _columns.Add(columnName);
            }
            if (_columns.Count == 0)
            {
                throw new ArgumentException("No Columns found=" + _trlTableName);
            }
        }
Example #4
0
        }       //	isOrgLevelOnly

        /// <summary>
        /// Get Table model
        /// </summary>
        /// <returns>talble</returns>
        public MTable GetTable()
        {
            if (_table == null)
            {
                _table = MTable.Get(GetCtx(), GetAD_Table_ID());
            }
            return(_table);
        }       //	getTable
Example #5
0
 /// <summary>
 /// Get Table Name
 /// </summary>
 /// <returns>table name</returns>
 protected String GetTableName()
 {
     if (_tableName == null)
     {
         MTable table = MTable.Get(GetCtx(), GetAD_Table_ID());
         _tableName = table.Get_TableName();
     }
     return(_tableName);
 }
        /// <summary>
        /// function to check if user try to either delete or remove
        /// last column which is marked as Maintain Version to false
        /// then return false, if there is data in respective Version Table
        /// </summary>
        /// <param name="delete"></param>
        /// <returns>bool (true/false)</returns>
        public bool CheckVersions(bool delete)
        {
            bool          check = true;
            StringBuilder sb    = new StringBuilder("SELECT COUNT(AD_Column_ID) FROM AD_Column WHERE AD_Table_ID = " + GetAD_Table_ID() + " AND IsMaintainVersions = 'Y' AND AD_Column_ID != " + GetAD_Column_ID());

            if (!delete)
            {
                if (!(Is_ValueChanged("IsMaintainVersions") && (Util.GetValueOfBool(Get_ValueOld("IsMaintainVersions")) && !Util.GetValueOfBool(Get_Value("IsMaintainVersions")))))
                {
                    check = false;
                }
            }
            else
            {
                if (!(Util.GetValueOfBool(Get_ValueOld("IsMaintainVersions"))))
                {
                    check = false;
                }
            }
            if (check)
            {
                int countVerCols = Util.GetValueOfInt(DB.ExecuteScalar(sb.ToString(), null, Get_Trx()));
                if (countVerCols == 0)
                {
                    sb.Clear();
                    sb.Append("SELECT TableName FROM AD_Table WHERE AD_Table_ID = " + GetAD_Table_ID());
                    string tableName = Util.GetValueOfString(DB.ExecuteScalar(sb.ToString(), null, Get_Trx()));
                    sb.Clear();

                    DatabaseMetaData md = new DatabaseMetaData();

                    //get columns of a table
                    DataSet dt = md.GetColumns("", DataBase.DB.GetSchema(), tableName + "_Ver");
                    md.Dispose();

                    // check whether version table exists in database
                    if (dt != null && dt.Tables[0] != null && dt.Tables[0].Rows.Count > 0)
                    {
                        MTable tblVer = MTable.Get(GetCtx(), tableName + "_Ver");
                        if (tblVer.HasVersionData(tableName + "_Ver"))
                        {
                            // if Maintain Version is marked on Table Level then allow to remove Maintain Version from Column
                            if (Util.GetValueOfString(DB.ExecuteScalar("SELECT IsMaintainVersions FROM AD_Table WHERE AD_Table_ID = " + GetAD_Table_ID(), null, Get_Trx())) == "Y")
                            {
                                return(true);
                            }
                            else
                            {
                                log.SaveError("VersionDataExists", Utility.Msg.GetElement(GetCtx(), "VersionDataExists"));
                                return(false);
                            }
                        }
                    }
                }
            }
            return(true);
        }
Example #7
0
        /// <summary>
        /// Get SQL Modify command
        /// </summary>
        /// <param param name="table">MTable object</param>
        /// <param name="setNullOption"></param>
        /// Created By : Kiran Sangwan
        /// <returns>string modified sqlCommand</returns>
        public string GetSQLModify(MTable table, bool setNullOption)
        {
            StringBuilder sql     = new StringBuilder();
            StringBuilder sqlBase = new StringBuilder("ALTER TABLE ")
                                    .Append(table.GetTableName())
                                    .Append(" MODIFY ").Append(GetColumnName());

            //	Default
            StringBuilder sqlDefault = new StringBuilder(sqlBase.ToString())
                                       .Append(" ").Append(getSQLDataType())
                                       .Append(" DEFAULT ");
            string defaultValue = GetSQLDefaultValue();

            if (defaultValue.Length > 0)
            {
                sqlDefault.Append(defaultValue);
            }
            else
            {
                sqlDefault.Append(" NULL ");
                defaultValue = null;
            }
            sql.Append(sqlDefault);

            //	Constraint

            //	Null Values
            if (IsMandatory() && defaultValue != null && defaultValue.Length > 0)
            {
                StringBuilder sqlSet = new StringBuilder("UPDATE ")
                                       .Append(table.GetTableName())
                                       .Append(" SET ").Append(GetColumnName())
                                       .Append("=").Append(defaultValue)
                                       .Append(" WHERE ").Append(GetColumnName()).Append(" IS NULL");
                sql.Append("; ").Append(sqlSet);
            }

            //	Null
            if (setNullOption)
            {
                StringBuilder sqlNull = new StringBuilder(sqlBase.ToString());
                if (IsMandatory())
                {
                    sqlNull.Append(" NOT NULL");
                }
                else
                {
                    sqlNull.Append(" NULL");
                }
                sql.Append("; ").Append(sqlNull);
            }
            //
            return(sql.ToString());
        }
        /// <summary>
        /// Get the Parent Table
        /// </summary>
        /// <param name="tab"></param>
        /// <returns></returns>
        public MTable GetParentTable(MWindow win, MTab currentTab)
        {
            MTab[] tabs = win.GetTabs(false, null);
            MTab   tab  = tabs[currentTab.GetTabLevel()];

            if (currentTab.GetTabLevel() == 0)
            {
                return(null);
            }
            return(MTable.Get(GetCtx(), tab.GetAD_Table_ID()));
        }
Example #9
0
        /// <summary>
        /// Load Meta Data
        /// </summary>
        /// <param name="ctx"></param>
        /// <returns></returns>
        protected override POInfo InitPO(Ctx ctx)
        {
            PropertiesWrapper wrapper = (PropertiesWrapper)ctx;

            p_ctx     = wrapper.source;
            tableName = wrapper.tableName;
            tableID   = MTable.Get_Table_ID(tableName);
            // log.info("Table_ID: "+Table_ID);
            POInfo poi = POInfo.GetPOInfo(ctx, tableID);

            return(poi);
        }
Example #10
0
        /// <summary>
        /// Get SQL Add command
        /// </summary>
        /// Created By : Kiran Sangwan
        /// <returns>string sql add command</returns>
        public string GetSQLAdd(MTable table)
        {
            if (IsVirtualColumn())
            {
                return(null);
            }
            StringBuilder sql = new StringBuilder("ALTER TABLE ")
                                .Append(table.GetTableName())
                                .Append(" ADD ").Append(GetSQLDDL());

            return(sql.ToString());
        }
Example #11
0
        /// <summary>
        /// Get Table from Cache
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="tableName">case insensitive table name</param>
        /// <returns>able or null</returns>
        /// <author>Raghunandan</author>
        public static MTable Get(Ctx ctx, string tableName)
        {
            //Uesd in translationTable Class
            if (tableName == null)
            {
                return(null);
            }
            //	Check cache
            //iterator<MTable> it = s_cache.Values().iterator();
            IEnumerator <MTable> it = s_cache.Values.GetEnumerator();

            it.Reset();
            while (it.MoveNext())
            //foreach(MTable mtable in it)
            {
                //MTable retValue = (MTable)it.next();
                MTable retValue1 = (MTable)it.Current;
                //if (tableName.equalsIgnoreCase(retValue.getTableName()))
                if (tableName.ToLower().Equals(retValue1.GetTableName().ToLower()))
                {
                    return(retValue1);
                }
            }
            //	Get direct
            MTable  retValue = null;
            String  sql      = "SELECT * FROM AD_Table WHERE UPPER(TableName)=UPPER('" + tableName + "')";
            DataSet ds       = null;

            try
            {
                ds = DataBase.DB.ExecuteDataset(sql, null, null);
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow rs = ds.Tables[0].Rows[i];
                    retValue = new MTable(ctx, rs, null);
                }
            }
            catch (Exception e)
            {
                //
                s_log.Log(Level.SEVERE, sql, e);
            }
            ds = null;
            if (retValue != null)
            {
                int key = retValue.GetAD_Table_ID();
                s_cache.Add(key, retValue);
            }
            return(retValue);
        }
Example #12
0
        /// <summary>
        /// Get Po Object of table
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="tableName"></param>
        /// <param name="Record_ID"></param>
        /// <param name="trxName"></param>
        /// <returns></returns>
        public static PO GetPO(Ctx ctx, string tableName, int Record_ID, Trx trxName)
        {
            var    tableId   = MTable.Get_Table_ID(tableName);
            MTable tbl       = new MTable(ctx, tableId, trxName);
            String TableName = tbl.GetTableName();

            if (TableName == null)
            {
                return(null);
            }
            var locpo = tbl.GetPO(ctx, Record_ID, trxName);

            return(locpo);
        }
Example #13
0
        }       //	checkStandardColumns

        /// <summary>
        /// Create Column in AD and DB
        /// </summary>
        /// <param name="col">Column Object</param>
        /// <param name="table">Table Object</param>
        /// <param name="alsoInDB">Also in DB</param>
        /// <returns></returns>
        private static bool CreateColumn(MColumn col, MTable table, bool alsoInDB)
        {
            //	Element
            M_Element element = M_Element.Get(col.GetCtx(), col.GetColumnName(), col.Get_TrxName());

            if (element == null)
            {
                element = new M_Element(col.GetCtx(), col.GetColumnName(), col.GetEntityType(), null);
                if (!element.Save())
                {
                    return(false);
                }
                log.Info("Created Element: " + element.GetColumnName());
            }
            //	Column Sync
            col.SetColumnName(element.GetColumnName());
            col.SetName(element.GetName());
            col.SetDescription(element.GetDescription());
            col.SetHelp(element.GetHelp());
            col.SetAD_Element_ID(element.GetAD_Element_ID());
            //

            if (!col.Save())
            {
                return(false);
            }

            //	DB
            if (!alsoInDB)
            {
                return(true);
            }
            //
            String sql     = col.GetSQLAdd(table);
            bool   success = DataBase.DB.ExecuteUpdateMultiple(sql, false, table.Get_TrxName()) >= 0;

            if (success)
            {
                log.Info("Created: " + table.GetTableName()
                         + "." + col.GetColumnName());
            }
            else
            {
                log.Warning("NOT Created: " + table.GetTableName()
                            + "." + col.GetColumnName());
            }
            return(success);
        }       //	createColumn
Example #14
0
        public string UpdateDefaultValue(MTable table)
        {
            string defaultValue = GetDefaultValue();

            //	Null Values
            if (IsMandatory() && defaultValue != null && defaultValue.Length > 0)
            {
                StringBuilder sqlSet = new StringBuilder("UPDATE ")
                                       .Append(table.GetTableName())
                                       .Append(" SET ").Append(GetColumnName())
                                       .Append("=").Append(defaultValue)
                                       .Append(" WHERE ").Append(GetColumnName()).Append(" IS NULL");
                return(sqlSet.ToString());
            }
            return("");
        }
Example #15
0
        }  // getColumns()

        // getColumns()


        /**
         *  Get Table from Cache
         *	@param ctx context
         *	@param AD_Table_ID id
         *	@return MTable
         */
        public static MTable Get(Ctx ctx, int AD_Table_ID)
        {
            int    key      = AD_Table_ID;
            MTable retValue = null;

            s_cache.TryGetValue(key, out retValue);
            if (retValue != null)
            {
                return(retValue);
            }
            retValue = new MTable(ctx, AD_Table_ID, null);
            if (retValue.Get_ID() != 0)
            {
                s_cache.Add(key, retValue);
            }
            return(retValue);
        }
        /// <summary>
        /// After Save
        /// </summary>
        /// <param name="newRecord">new Record</param>
        /// <param name="success">save success</param>
        /// <returns>success</returns>
        protected override bool AfterSave(bool newRecord, bool success)
        {
            if (!success)
            {
                return(success);
            }
            if (newRecord)
            {
                //	Info
                info = new MOrgInfo(this);
                info.Save();
                //	Access
                MRoleOrgAccess.CreateForOrg(this);
                MRole.GetDefault(GetCtx(), true);       //	reload
            }
            //	Value/Name change
            if (!newRecord && (Is_ValueChanged("Value") || Is_ValueChanged("Name")))
            {
                MAccount.UpdateValueDescription(GetCtx(), "AD_Org_ID=" + GetAD_Org_ID(), Get_Trx());
                if ("Y".Equals(GetCtx().GetContext("$Element_OT")))
                {
                    MAccount.UpdateValueDescription(GetCtx(), "AD_OrgTrx_ID=" + GetAD_Org_ID(), Get_Trx());
                }
            }

            if (!newRecord)
            {
                if (!IsSummary())
                {
                    int orgTableID = MTable.Get_Table_ID("AD_Org");

                    string sql = "SELECT AD_Tree_ID FROM AD_Tree "
                                 + "WHERE AD_Client_ID=" + GetCtx().GetAD_Client_ID() + " AND AD_Table_ID=" + orgTableID + " AND IsActive='Y' AND IsAllNodes='Y' "
                                 + "ORDER BY IsDefault DESC, AD_Tree_ID";

                    object AD_Tree_ID = DB.ExecuteScalar(sql, null, null);

                    DB.ExecuteQuery("Update AD_TreeNode Set Parent_ID = 0 where Parent_ID=" + GetAD_Org_ID() + " AND AD_Tree_ID=" + Util.GetValueOfInt(AD_Tree_ID));
                }
            }

            return(true);
        }
Example #17
0
        }       //	getSql

        public String GetTableName()
        {
            int AD_Table_ID = GetAD_Table_ID();

            if (AD_Table_ID != 0)
            {
                MTable table     = MTable.Get(GetCtx(), AD_Table_ID);
                String tableName = table.GetTableName();
                if (!VAdvantage.Utility.Util.IsEmpty(tableName))
                {
                    return(tableName);
                }
            }
            //	FROM clause
            String          from   = GetFromClause().Trim();
            StringTokenizer st     = new StringTokenizer(from, " ,\t\n\r\f", false);
            int             tokens = st.CountTokens();

            if (tokens == 0)
            {
                return(null);
            }
            if (tokens == 1)
            {
                return(st.NextToken());
            }
            String mainTable = st.NextToken();

            if (st.HasMoreTokens())
            {
                String next = st.NextToken();
                if (next.Equals("RIGHT", StringComparison.OrdinalIgnoreCase) ||
                    next.Equals("LEFT", StringComparison.OrdinalIgnoreCase) ||
                    next.Equals("INNER", StringComparison.OrdinalIgnoreCase) ||
                    next.Equals("FULL", StringComparison.OrdinalIgnoreCase))
                {
                    return(mainTable);
                }
                return(next);
            }
            return(mainTable);
        }       //	getTableName
Example #18
0
        public string SetDefaultValue(MTable table, string columnName)
        {
            StringBuilder sqlDefault = new StringBuilder("");

            if (DatabaseType.IsOracle)
            {
                sqlDefault.Append(" DEFAULT ");
                string defaultValue = GetSQLDefaultValue();
                if (defaultValue.Length > 0)
                {
                    sqlDefault.Append(defaultValue);
                }
                else
                {
                    sqlDefault.Append(" NULL ");
                    defaultValue = null;
                }
            }
            else if (DatabaseType.IsPostgre)
            {
                //ALTER TABLE Test ALTER COLUMN  Description SET DEFAULT  NULL
                sqlDefault.Append("; ALTER TABLE " + table.GetTableName())
                .Append(" ALTER COLUMN " + columnName + " SET DEFAULT ");
                string defaultValue = GetSQLDefaultValue();
                if (defaultValue.Length > 0)
                {
                    sqlDefault.Append(defaultValue);
                }
                else
                {
                    sqlDefault.Append(" NULL ");
                    defaultValue = null;
                }
            }
            return(sqlDefault.ToString());
        }
Example #19
0
        public string GetSQLModifyPerColumn(MTable table, string columnName, bool setNullOption)
        {
            //StringBuilder sql = new StringBuilder();
            //sql.Append(" " + columnName + " ");

            StringBuilder sqlBase = new StringBuilder(" " + columnName + " ");

            if (DatabaseType.IsPostgre)
            {
                sqlBase.Append(" TYPE ");
            }

            //	Default
            StringBuilder sqlDefault = new StringBuilder(sqlBase.ToString())
                                       .Append(" ").Append(getSQLDataType());


            //    .Append(" DEFAULT ");
            //string defaultValue = GetSQLDefaultValue();
            //if (defaultValue.Length > 0)
            //    sqlDefault.Append(defaultValue);
            //else
            //{
            //    sqlDefault.Append(" NULL ");
            //    defaultValue = null;
            //}

            //sql.Append(sqlDefault);


            //SetNullOption(setNullOption, table, columnName);


            //	Constraint
            return(sqlDefault.ToString());
        }
Example #20
0
        }       //	generate

        /// <summary>
        /// Generate Delta and History Table
        /// </summary>
        /// <returns></returns>
        private bool GenerateTable()
        {
            //	Table
            m_derivedTable = MTable.Get(m_ctx, m_dTableName);
            if (m_derivedTable == null)
            {
                m_derivedTable = new MTable(m_ctx, 0, null);
            }

            PO.CopyValues(m_baseTable, m_derivedTable);
            m_derivedTable.SetTableName(m_dTableName);
            m_derivedTable.SetName(m_derivedTable.GetName() + " SubTable");
            m_derivedTable.SetSubTableType(m_derivedTableType);
            m_derivedTable.SetBase_Table_ID(m_baseTable.GetAD_Table_ID());
            if (!m_derivedTable.Save())
            {
                throw new Exception("Cannot save " + m_dTableName);
            }

            MColumn[] dCols = SyncMColumns(true);

            //	Sync Columns in Database
            List <MColumn> list = new List <MColumn>(dCols.Length);

            foreach (MColumn element in dCols)
            {
                list.Add(element);
            }
            Trx trx = Trx.Get("getDatabaseMetaData");
            //

            String catalog   = "";
            String schema    = DataBase.DB.GetSchema();
            String tableName = m_dTableName;

            tableName = tableName.ToUpper();
            int noColumns = 0;
            //
            DataSet rs = null;

            using (DatabaseMetaData md = new DatabaseMetaData())
            {
                rs = md.GetColumns(catalog, schema, tableName);
            }
            for (int rscount = 0; rscount <= rs.Tables[0].Rows.Count - 1; rscount++)
            {
                noColumns++;
                String columnName = rs.Tables[0].Rows[rscount]["COLUMN_NAME"].ToString();
                bool   found      = false;
                for (int i = 0; i < list.Count; i++)
                {
                    MColumn dCol = list[i];
                    if (columnName.Equals(dCol.GetColumnName(), StringComparison.OrdinalIgnoreCase))
                    {
                        String sql = dCol.GetSQLModify(m_derivedTable, false);
                        DataBase.DB.ExecuteUpdateMultiple(sql, false, null);
                        found = true;
                        list.Remove(list[i]);
                        break;
                    }
                }
                if (!found)
                {
                    String sql = "ALTER TABLE " + m_dTableName + " DROP COLUMN " + columnName;
                    DataBase.DB.ExecuteQuery(sql, null);
                }
            }
            //rs.close();
            trx.Close();

            //	No Columns
            if (noColumns == 0)
            {
                String sql = m_derivedTable.GetSQLCreate();
                return(DataBase.DB.ExecuteUpdateMultiple(sql, false, null) >= 0);
            }
            //	New Columns
            for (int i = 0; i < list.Count(); i++)
            {
                MColumn dCol = list[i];
                if (dCol.IsVirtualColumn())
                {
                    continue;
                }
                String sql = dCol.GetSQLAdd(m_derivedTable);
                DataBase.DB.ExecuteUpdateMultiple(sql, false, null);
            }
            return(true);
        }       //	generateTable
Example #21
0
        /// <summary>
        /// Get SQL Modify command
        /// </summary>
        /// <param param name="table">MTable object</param>
        /// <param name="setNullOption"></param>
        /// Created By : Kiran Sangwan
        /// <returns>string modified sqlCommand</returns>
        public string GetSQLModify(MTable table, bool setNullOption)
        {
            StringBuilder sql     = new StringBuilder();
            StringBuilder sqlBase = new StringBuilder("ALTER TABLE ")
                                    .Append(table.GetTableName());

            if (DatabaseType.IsOracle)
            {
                sqlBase.Append(" MODIFY ");
            }
            else if (DatabaseType.IsPostgre)
            {
                sqlBase.Append(" ALTER COLUMN ");
            }


            ////	Default
            //StringBuilder sqlDefault = new StringBuilder(sqlBase.ToString())
            //    .Append(" ").Append(getSQLDataType())
            //    .Append(" DEFAULT ");
            //string defaultValue = GetSQLDefaultValue();
            //if (defaultValue.Length > 0)
            //    sqlDefault.Append(defaultValue);
            //else
            //{
            //    sqlDefault.Append(" NULL ");
            //    defaultValue = null;
            //}
            //sql.Append(sqlDefault);

            ////	Constraint

            ////	Null Values
            //if (IsMandatory() && defaultValue != null && defaultValue.Length > 0)
            //{
            //    StringBuilder sqlSet = new StringBuilder("UPDATE ")
            //        .Append(table.GetTableName())
            //        .Append(" SET ").Append(GetColumnName())
            //        .Append("=").Append(defaultValue)
            //        .Append(" WHERE ").Append(GetColumnName()).Append(" IS NULL");
            //    sql.Append("; ").Append(sqlSet);
            //}

            ////	Null
            //if (setNullOption)
            //{
            //    StringBuilder sqlNull = new StringBuilder(sqlBase.ToString());
            //    if (IsMandatory())
            //        sqlNull.Append(" NOT NULL");
            //    else
            //        sqlNull.Append(" NULL");
            //    sql.Append("; ").Append(sqlNull);
            //}
            //
            sql.Append(sqlBase.ToString()).Append(GetSQLModifyPerColumn(table, GetColumnName(), setNullOption));

            string defaultVal = SetDefaultValue(table, GetColumnName());

            if (!string.IsNullOrEmpty(defaultVal))
            {
                sql.Append(defaultVal);
            }



            string setNull = SetNullOption(setNullOption, table, GetColumnName());

            if (setNull.Length > 0)
            {
                sql.Append(";").Append(setNull);
            }

            string updateQL = UpdateDefaultValue(table);

            if (updateQL.Length > 0)
            {
                sql.Append(";").Append(updateQL);
            }

            return(sql.ToString());
        }
Example #22
0
 /// <summary>
 /// Get Table Name
 /// </summary>
 /// <param name="ctx">context</param>
 /// <param name="AD_Table_ID">table id</param>
 /// <returns>table name</returns>
 public static String GetTableName(Ctx ctx, int AD_Table_ID)
 {
     return(MTable.Get(ctx, AD_Table_ID).GetTableName());
 }
Example #23
0
 /// <summary>
 /// Parent Constructor
 /// </summary>
 /// <param name="parent">parent</param>
 public MViewComponent(MTable parent) : this(parent.GetCtx(), 0, parent.Get_TrxName())
 {
     SetClientOrg(parent);
     SetAD_Table_ID(parent.GetAD_Table_ID());
 }       //	MViewComponent
Example #24
0
        /// <summary>
        /// Check Existence of Std columns and create them in AD and DB
        /// </summary>
        /// <param name="table">name of the table</param>
        /// <param name="EntityType">Entity Type</param>
        public static void CheckStandardColumns(MTable table, String EntityType)
        {
            if (table == null)
            {
                return;
            }
            if (Utility.Util.IsEmpty(EntityType))
            {
                EntityType = table.GetEntityType();
            }
            table.GetColumns(true);             //	get new columns
            //	Key Column
            String colName = table.GetTableName() + "_ID";

            if (table.GetColumn(colName) == null)
            {
                MColumn col = new MColumn(table);
                col.SetColumnName(colName);
                col.SetAD_Reference_ID(DisplayType.ID);
                col.SetIsKey(true);
                col.SetIsUpdateable(false);
                col.SetIsMandatory(true);
                col.SetEntityType(EntityType);
                CreateColumn(col, table, true);
            }
            colName = "AD_Client_ID";
            if (table.GetColumn(colName) == null)
            {
                MColumn col = new MColumn(table);
                col.SetColumnName(colName);
                col.SetAD_Reference_ID(DisplayType.TableDir);
                col.SetIsUpdateable(false);
                col.SetIsMandatory(true);
                col.SetAD_Val_Rule_ID(116);     //	Client Login
                col.SetDefaultValue("@#AD_Client_ID@");
                col.SetConstraintType(X_AD_Column.CONSTRAINTTYPE_Restrict);
                col.SetEntityType(EntityType);
                CreateColumn(col, table, true);
            }
            colName = "AD_Org_ID";
            if (table.GetColumn(colName) == null)
            {
                MColumn col = new MColumn(table);
                col.SetColumnName(colName);
                col.SetAD_Reference_ID(DisplayType.TableDir);
                col.SetIsUpdateable(false);
                col.SetIsMandatory(true);
                col.SetAD_Val_Rule_ID(104);     //	Org Security
                col.SetDefaultValue("@#AD_Org_ID@");
                col.SetConstraintType(X_AD_Column.CONSTRAINTTYPE_Restrict);
                col.SetEntityType(EntityType);
                CreateColumn(col, table, true);
            }
            colName = "Created";
            if (table.GetColumn(colName) == null)
            {
                MColumn col = new MColumn(table);
                col.SetColumnName(colName);
                col.SetAD_Reference_ID(DisplayType.DateTime);
                col.SetIsUpdateable(false);
                col.SetIsMandatory(true);
                col.SetEntityType(EntityType);
                CreateColumn(col, table, true);
            }
            colName = "Updated";
            if (table.GetColumn(colName) == null)
            {
                MColumn col = new MColumn(table);
                col.SetColumnName(colName);
                col.SetAD_Reference_ID(DisplayType.DateTime);
                col.SetIsUpdateable(false);
                col.SetIsMandatory(true);
                col.SetEntityType(EntityType);
                CreateColumn(col, table, true);
            }
            colName = "CreatedBy";
            if (table.GetColumn(colName) == null)
            {
                MColumn col = new MColumn(table);
                col.SetColumnName(colName);
                col.SetAD_Reference_ID(DisplayType.Table);
                col.SetAD_Reference_Value_ID(110);
                col.SetConstraintType(X_AD_Column.CONSTRAINTTYPE_DoNOTCreate);
                col.SetIsUpdateable(false);
                col.SetIsMandatory(true);
                col.SetEntityType(EntityType);
                CreateColumn(col, table, true);
            }
            colName = "UpdatedBy";
            if (table.GetColumn(colName) == null)
            {
                MColumn col = new MColumn(table);
                col.SetColumnName(colName);
                col.SetAD_Reference_ID(DisplayType.Table);
                col.SetAD_Reference_Value_ID(110);
                col.SetConstraintType(X_AD_Column.CONSTRAINTTYPE_DoNOTCreate);
                col.SetIsUpdateable(false);
                col.SetIsMandatory(true);
                col.SetEntityType(EntityType);
                CreateColumn(col, table, true);
            }
            colName = "IsActive";
            if (table.GetColumn(colName) == null)
            {
                MColumn col = new MColumn(table);
                col.SetColumnName(colName);
                col.SetAD_Reference_ID(DisplayType.YesNo);
                col.SetDefaultValue("Y");
                col.SetIsUpdateable(true);
                col.SetIsMandatory(true);
                col.SetEntityType(EntityType);
                CreateColumn(col, table, true);
            }
            colName = "Export_ID";
            if (table.GetColumn(colName) == null)
            {
                MColumn col = new MColumn(table);
                col.SetColumnName(colName);
                col.SetAD_Reference_ID(DisplayType.String);
                col.SetIsUpdateable(true);
                col.SetIsMandatory(false);
                col.SetEntityType(EntityType);
                col.SetFieldLength(50);
                CreateColumn(col, table, true);
            }
        }       //	checkStandardColumns
Example #25
0
        }       //	SyncMColumns

        /// <summary>
        /// Check Existence of Std columns and create them in AD and DB
        /// </summary>
        /// <param name="Context">context</param>
        /// <param name="tableName">name of the  table</param>
        static void CheckStandardColumns(Context Context, String tableName)
        {
            MTable table = MTable.Get(Context, tableName);

            CheckStandardColumns(table, null);
        }
Example #26
0
        }       //	MCharge

        /**
         *  After Save
         *	@param newRecord new
         *	@param success success
         *	@return success
         */
        //@Override
        protected override Boolean AfterSave(Boolean newRecord, Boolean success)
        {
            int           _client_ID = 0;
            StringBuilder _sql       = new StringBuilder();

            //_sql.Append("Select count(*) from  ad_table where tablename like 'FRPT_Charge_Acct'");
            _sql.Append("SELECT count(*) FROM all_objects WHERE object_type IN ('TABLE') AND (object_name)  = UPPER('FRPT_Charge_Acct')  AND OWNER LIKE '" + DB.GetSchema() + "'");
            int count = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString()));

            if (count > 0)
            {
                _sql.Clear();
                _sql.Append("Select L.Value From Ad_Ref_List L inner join AD_Reference r on R.AD_REFERENCE_ID=L.AD_REFERENCE_ID where r.name='FRPT_RelatedTo' and l.name='Charge'");
                var relatedtoChrge = Convert.ToString(DB.ExecuteScalar(_sql.ToString()));

                PO chrgact = null;
                _client_ID = GetAD_Client_ID();
                _sql.Clear();
                _sql.Append("select C_AcctSchema_ID from C_AcctSchema where AD_CLIENT_ID=" + _client_ID);
                DataSet ds3 = new DataSet();
                ds3 = DB.ExecuteDataset(_sql.ToString(), null);
                if (ds3 != null && ds3.Tables[0].Rows.Count > 0)
                {
                    for (int k = 0; k < ds3.Tables[0].Rows.Count; k++)
                    {
                        int _AcctSchema_ID = Util.GetValueOfInt(ds3.Tables[0].Rows[k]["C_AcctSchema_ID"]);
                        _sql.Clear();
                        _sql.Append("Select Frpt_Acctdefault_Id,C_Validcombination_Id,Frpt_Relatedto From Frpt_Acctschema_Default Where ISACTIVE='Y' AND AD_CLIENT_ID=" + _client_ID + "AND C_Acctschema_Id=" + _AcctSchema_ID);
                        DataSet ds = new DataSet();
                        ds = DB.ExecuteDataset(_sql.ToString(), null);
                        if (ds != null && ds.Tables[0].Rows.Count > 0)
                        {
                            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                            {
                                //DataSet ds2 = new DataSet();
                                string _relatedTo = ds.Tables[0].Rows[i]["Frpt_Relatedto"].ToString();
                                if (_relatedTo != "")
                                {
                                    if (_relatedTo == relatedtoChrge)
                                    {
                                        _sql.Clear();
                                        _sql.Append("Select COUNT(*) From C_Charge Bp Left Join Frpt_Charge_Acct ca On Bp.C_Charge_ID=ca.C_Charge_ID And ca.Frpt_Acctdefault_Id=" + ds.Tables[0].Rows[i]["FRPT_AcctDefault_ID"] + " WHERE Bp.IsActive='Y' AND Bp.AD_Client_ID=" + _client_ID + " AND ca.C_Validcombination_Id = " + Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_Validcombination_Id"]) + " AND Bp.C_Charge_ID = " + GetC_Charge_ID());
                                        int recordFound = Convert.ToInt32(DB.ExecuteScalar(_sql.ToString(), null, Get_Trx()));
                                        //ds2 = DB.ExecuteDataset(_sql.ToString(), null);
                                        //if (ds2 != null && ds2.Tables[0].Rows.Count > 0)
                                        //{
                                        //    for (int j = 0; j < ds2.Tables[0].Rows.Count; j++)
                                        //    {
                                        //        int value = Util.GetValueOfInt(ds2.Tables[0].Rows[j]["Frpt_Acctdefault_Id"]);
                                        //        if (value == 0)
                                        //        {
                                        //chrgact = new X_FRPT_Charge_Acct(GetCtx(), 0, null);
                                        if (recordFound == 0)
                                        {
                                            chrgact = MTable.GetPO(GetCtx(), "FRPT_Charge_Acct", 0, null);
                                            chrgact.Set_ValueNoCheck("C_Charge_ID", Util.GetValueOfInt(GetC_Charge_ID()));
                                            chrgact.Set_ValueNoCheck("AD_Org_ID", 0);
                                            chrgact.Set_ValueNoCheck("FRPT_AcctDefault_ID", Util.GetValueOfInt(ds.Tables[0].Rows[i]["FRPT_AcctDefault_ID"]));
                                            chrgact.Set_ValueNoCheck("C_ValidCombination_ID", Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_Validcombination_Id"]));
                                            chrgact.Set_ValueNoCheck("C_AcctSchema_ID", _AcctSchema_ID);
                                            if (!chrgact.Save())
                                            {
                                            }
                                        }
                                        //        }
                                        //    }
                                        //}
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (newRecord & success && (String.IsNullOrEmpty(GetCtx().GetContext("#DEFAULT_ACCOUNTING_APPLICABLE")) || Util.GetValueOfString(GetCtx().GetContext("#DEFAULT_ACCOUNTING_APPLICABLE")) == "Y"))
                {
                    success = Insert_Accounting("C_Charge_Acct", "C_AcctSchema_Default", null);

                    //Karan. work done to show message if data not saved in accounting tab. but will save data in current tab.
                    // Before this, data was being saved but giving message "record not saved".
                    if (!success)
                    {
                        log.SaveWarning("AcctNotSaved", "");
                        return(true);
                    }
                }
            }
            return(success);
        }
        /**
         *  After Save
         *	@param newRecord new
         *	@param success success
         *	@return success
         */
        protected override bool AfterSave(bool newRecord, bool success)
        {
            PO            project    = null;
            int           _client_ID = 0;
            StringBuilder _sql       = new StringBuilder();

            //_sql.Append("Select count(*) from  ad_table where tablename like 'FRPT_Project_Acct'");
            //_sql.Append("SELECT count(*) FROM all_objects WHERE object_type IN ('TABLE') AND (object_name)  = UPPER('FRPT_Project_Acct')  AND OWNER LIKE '" + DB.GetSchema() + "'");
            _sql.Append(DBFunctionCollection.CheckTableExistence(DB.GetSchema(), "FRPT_Project_Acct"));
            int count = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString()));

            if (count > 0)
            {
                _sql.Clear();
                _sql.Append("Select L.Value From Ad_Ref_List L inner join AD_Reference r on R.AD_REFERENCE_ID=L.AD_REFERENCE_ID where r.name='FRPT_RelatedTo' and l.name='Project'");
                var relatedtoProject = Convert.ToString(DB.ExecuteScalar(_sql.ToString()));
                _client_ID = GetAD_Client_ID();
                _sql.Clear();
                _sql.Append("select C_AcctSchema_ID from C_AcctSchema where AD_CLIENT_ID=" + _client_ID);
                DataSet ds3 = new DataSet();
                ds3 = DB.ExecuteDataset(_sql.ToString(), null);
                if (ds3 != null && ds3.Tables[0].Rows.Count > 0)
                {
                    for (int k = 0; k < ds3.Tables[0].Rows.Count; k++)
                    {
                        int _AcctSchema_ID = Util.GetValueOfInt(ds3.Tables[0].Rows[k]["C_AcctSchema_ID"]);
                        _sql.Clear();
                        _sql.Append("Select Frpt_Acctdefault_Id,C_Validcombination_Id,Frpt_Relatedto From Frpt_Acctschema_Default Where ISACTIVE='Y' AND AD_CLIENT_ID=" + _client_ID + "AND C_Acctschema_Id=" + _AcctSchema_ID);
                        DataSet ds = DB.ExecuteDataset(_sql.ToString(), null);
                        if (ds != null && ds.Tables[0].Rows.Count > 0)
                        {
                            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                            {
                                string _relatedTo = ds.Tables[0].Rows[i]["Frpt_Relatedto"].ToString();
                                if (_relatedTo != "" && (_relatedTo == relatedtoProject))
                                {
                                    _sql.Clear();
                                    _sql.Append("Select COUNT(*) From C_Project Bp Left Join FRPT_Project_Acct ca On Bp.C_Project_ID=ca.C_Project_ID And ca.Frpt_Acctdefault_Id=" + ds.Tables[0].Rows[i]["FRPT_AcctDefault_ID"] + " WHERE Bp.IsActive='Y' AND Bp.AD_Client_ID=" + _client_ID + " AND ca.C_Validcombination_Id = " + Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_Validcombination_Id"]) + " AND Bp.C_Project_ID = " + GetC_Project_ID());
                                    int recordFound = Convert.ToInt32(DB.ExecuteScalar(_sql.ToString(), null, Get_Trx()));
                                    if (recordFound == 0)
                                    {
                                        project = MTable.GetPO(GetCtx(), "FRPT_Project_Acct", 0, null);
                                        project.Set_ValueNoCheck("AD_Org_ID", 0);
                                        project.Set_ValueNoCheck("C_Project_ID", Util.GetValueOfInt(GetC_Project_ID()));
                                        project.Set_ValueNoCheck("FRPT_AcctDefault_ID", Util.GetValueOfInt(ds.Tables[0].Rows[i]["FRPT_AcctDefault_ID"]));
                                        project.Set_ValueNoCheck("C_ValidCombination_ID", Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_Validcombination_Id"]));
                                        project.Set_ValueNoCheck("C_AcctSchema_ID", _AcctSchema_ID);
                                        if (!project.Save())
                                        {
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (newRecord & success && (String.IsNullOrEmpty(GetCtx().GetContext("#DEFAULT_ACCOUNTING_APPLICABLE")) || Util.GetValueOfString(GetCtx().GetContext("#DEFAULT_ACCOUNTING_APPLICABLE")) == "Y"))
            {
                bool sucs = Insert_Accounting("C_Project_Acct", "C_AcctSchema_Default", null);
                //Karan. work done to show message if data not saved in accounting tab. but will save data in current tab.
                // Before this, data was being saved but giving message "record not saved".
                if (!sucs)
                {
                    log.SaveWarning("AcctNotSaved", "");
                }
            }

            //	Value/Name change
            MProject prjph = null;

            if (success && !newRecord &&
                (Is_ValueChanged("Value") || Is_ValueChanged("Name")))
            {
                MAccount.UpdateValueDescription(GetCtx(), "C_Project_ID=" + GetC_Project_ID(), Get_TrxName());
            }
            if (GetC_Campaign_ID() != 0)
            {
                //Used transaction because total was not updating on header
                MCampaign cam    = new MCampaign(GetCtx(), GetC_Campaign_ID(), Get_TrxName());
                decimal   plnAmt = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT COALESCE(SUM(pl.PlannedAmt),0)  FROM C_Project pl WHERE pl.IsActive = 'Y' AND pl.C_Campaign_ID = " + GetC_Campaign_ID(), null, Get_TrxName()));
                cam.SetCosts(plnAmt);
                cam.Save();
            }
            else
            {
                //Used transaction because total was not updating on header
                prjph = new MProject(GetCtx(), GetC_Project_ID(), Get_TrxName());
                if (!prjph.IsOpportunity())
                {
                    //Used transaction because total was not updating on header
                    decimal plnAmt = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT COALESCE(SUM(PlannedAmt),0) FROM C_ProjectPhase WHERE IsActive= 'Y' AND C_Project_ID= " + GetC_Project_ID(), null, Get_TrxName()));
                    DB.ExecuteQuery("UPDATE C_Project SET PlannedAmt=" + plnAmt + " WHERE C_Project_ID=" + GetC_Project_ID(), null, Get_TrxName());
                }
            }
            return(success);
        }
        /// <summary>
        ///Get Table Name
        /// </summary>
        /// <returns>table name</returns>
        public String GetTableName()
        {
            int AD_Table_ID = GetAD_Table_ID();

            if (AD_Table_ID == 0)
            {
                return(null);
            }
            //
            if (AD_Table_ID == X_C_Order.Table_ID)
            {
                return(X_C_Order.Table_Name);
            }
            if (AD_Table_ID == X_M_InOut.Table_ID)
            {
                return(X_M_InOut.Table_Name);
            }
            if (AD_Table_ID == X_C_Invoice.Table_ID)
            {
                return(X_C_Invoice.Table_Name);
            }
            if (AD_Table_ID == X_C_Payment.Table_ID)
            {
                return(X_C_Payment.Table_Name);
            }
            if (AD_Table_ID == X_C_AllocationHdr.Table_ID)
            {
                return(X_C_AllocationHdr.Table_Name);
            }
            if (AD_Table_ID == X_C_Cash.Table_ID)
            {
                return(X_C_Cash.Table_Name);
            }
            if (AD_Table_ID == X_C_BankStatement.Table_ID)
            {
                return(X_C_BankStatement.Table_Name);
            }
            if (AD_Table_ID == X_M_Inventory.Table_ID)
            {
                return(X_M_Inventory.Table_Name);
            }
            if (AD_Table_ID == X_M_Movement.Table_ID)
            {
                return(X_M_Movement.Table_Name);
            }
            if (AD_Table_ID == X_GL_Journal.Table_ID)
            {
                return(X_GL_Journal.Table_Name);
            }
            if (AD_Table_ID == X_M_MatchInv.Table_ID)
            {
                return(X_M_MatchInv.Table_Name);
            }
            if (AD_Table_ID == X_M_MatchPO.Table_ID)
            {
                return(X_M_MatchPO.Table_Name);
            }
            if (AD_Table_ID == X_C_ProjectIssue.Table_ID)
            {
                return(X_C_ProjectIssue.Table_Name);
            }
            if (AD_Table_ID == X_M_Requisition.Table_ID)
            {
                return(X_M_Requisition.Table_Name);
            }

            /*********Manafacturing*************/
            if (AD_Table_ID == X_M_WarehouseTask.Table_ID)
            {
                return(X_M_WarehouseTask.Table_Name);
            }
            if (AD_Table_ID == X_M_WorkOrder.Table_ID)
            {
                return(X_M_WorkOrder.Table_Name);
            }
            if (AD_Table_ID == X_M_WorkOrderTransaction.Table_ID)
            {
                return(X_M_WorkOrderTransaction.Table_Name);
            }
            if (AD_Table_ID == X_M_CostUpdate.Table_ID)
            {
                return(X_M_CostUpdate.Table_Name);
            }
            /*********Manafacturing*************/
            //
            return(MTable.GetTableName(GetCtx(), AD_Table_ID));
        }
Example #29
0
        /**
         *  Before Save
         *	@param newRecord new
         *	@return true
         */
        protected override bool BeforeSave(bool newRecord)
        {
            if (Is_ValueChanged("DueAmt"))
            {
                log.Fine("beforeSave");
                SetIsValid(false);
            }
            oldDueAmt = Util.GetValueOfDecimal(Get_ValueOld("DueAmt"));

            if (Env.IsModuleInstalled("VA009_"))
            {
                // get invoice currency for rounding
                MCurrency currency = MCurrency.Get(GetCtx(), GetC_Currency_ID());
                SetDueAmt(Decimal.Round(GetDueAmt(), currency.GetStdPrecision()));
                SetVA009_PaidAmntInvce(Decimal.Round(GetVA009_PaidAmntInvce(), currency.GetStdPrecision()));

                // when invoice schedule have payment reference then need to check payment mode on payment window & update here
                if (GetC_Payment_ID() > 0)
                {
                    #region for payment
                    MPayment payment = new MPayment(GetCtx(), GetC_Payment_ID(), Get_Trx());
                    SetVA009_PaymentMethod_ID(payment.GetVA009_PaymentMethod_ID());

                    // get payment method detail -- update to here
                    DataSet dsPaymentMethod = DB.ExecuteDataset(@"SELECT VA009_PaymentMode, VA009_PaymentType, VA009_PaymentTrigger FROM VA009_PaymentMethod
                                          WHERE VA009_PaymentMethod_ID = " + payment.GetVA009_PaymentMethod_ID(), null, Get_Trx());
                    if (dsPaymentMethod != null && dsPaymentMethod.Tables.Count > 0 && dsPaymentMethod.Tables[0].Rows.Count > 0)
                    {
                        if (!String.IsNullOrEmpty(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentMode"])))
                        {
                            SetVA009_PaymentMode(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentMode"]));
                        }
                        if (!String.IsNullOrEmpty(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentType"])))
                        {
                            SetVA009_PaymentType(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentType"]));
                        }
                        SetVA009_PaymentTrigger(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentTrigger"]));
                    }
                    #endregion
                }
                else if (GetC_CashLine_ID() > 0)
                {
                    #region For Cash
                    // when invoice schedule have cashline reference then need to check
                    // payment mode of "Cash" type having currency is null on "Payment Method" window & update here
                    DataSet dsPaymentMethod = (DB.ExecuteDataset(@"SELECT VA009_PaymentMethod_ID, VA009_PaymentMode, VA009_PaymentType, VA009_PaymentTrigger 
                                       FROM VA009_PaymentMethod WHERE IsActive = 'Y' 
                                       AND AD_Client_ID = " + GetAD_Client_ID() + @" AND VA009_PaymentBaseType = 'B' AND NVL(C_Currency_ID , 0) = 0", null, Get_Trx()));
                    if (dsPaymentMethod != null && dsPaymentMethod.Tables.Count > 0 && dsPaymentMethod.Tables[0].Rows.Count > 0)
                    {
                        SetVA009_PaymentMethod_ID(Util.GetValueOfInt(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentMethod_ID"]));
                        if (!String.IsNullOrEmpty(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentMode"])))
                        {
                            SetVA009_PaymentMode(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentMode"]));
                        }
                        if (!String.IsNullOrEmpty(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentType"])))
                        {
                            SetVA009_PaymentType(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentType"]));
                        }
                        SetVA009_PaymentTrigger(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentTrigger"]));
                    }
                    else
                    {
                        #region when we not found record of "Cash" then we will create a new rcord on Payment Method for Cash
                        string sql     = @"SELECT AD_TABLE_ID  FROM AD_TABLE WHERE tablename LIKE 'VA009_PaymentMethod' AND IsActive = 'Y'";
                        int    tableId = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null));
                        MTable tbl     = new MTable(GetCtx(), tableId, Get_Trx());
                        PO     po      = tbl.GetPO(GetCtx(), 0, Get_Trx());
                        po.SetAD_Client_ID(GetAD_Client_ID());
                        po.SetAD_Org_ID(0); // Recod will be created in (*) Organization
                        po.Set_Value("Value", "By Cash");
                        po.Set_Value("VA009_Name", "By Cash");
                        po.Set_Value("IsActive", true);
                        po.Set_Value("VA009_PaymentBaseType", "B");
                        po.Set_Value("VA009_PaymentRule", "M");
                        po.Set_Value("VA009_PaymentMode", "C");
                        po.Set_Value("VA009_PaymentType", "S");
                        po.Set_Value("VA009_PaymentTrigger", "S");
                        po.Set_Value("C_Currency_ID", null);
                        po.Set_Value("VA009_InitiatePay", false);
                        if (!po.Save(Get_Trx()))
                        {
                            ValueNamePair pp = VLogger.RetrieveError();
                            log.Info("Error Occured when try to save record on Payment Method for Cash. Error Type : " + pp.GetValue());
                        }
                        else
                        {
                            SetVA009_PaymentMethod_ID(Util.GetValueOfInt(po.Get_Value("VA009_PaymentMethod_ID")));
                            SetVA009_PaymentMode("C");
                            SetVA009_PaymentType("S");
                            SetVA009_PaymentTrigger("S");
                        }
                        #endregion
                    }
                    #endregion
                }
            }
            // to set processing false because in case of new schedule processing is set to be false
            if (newRecord)
            {
                SetProcessing(false);

                // when schedile is not paid and invoice hedaer having "Hold Payment", then set "Hold payment" on schedule also
                if (Get_ColumnIndex("IsHoldPayment") > 0 && (GetC_Payment_ID() == 0 && GetC_CashLine_ID() == 0))
                {
                    String sql           = "SELECT IsHoldPayment FROM C_Invoice WHERE C_Invoice_ID = " + GetC_Invoice_ID();
                    String IsHoldPayment = Util.GetValueOfString(DB.ExecuteScalar(sql, null, Get_Trx()));
                    SetIsHoldPayment(IsHoldPayment.Equals("Y"));
                }
            }
            // if payment refrence not found on schedule the set withholdimh amount as ZERO
            if (GetC_Payment_ID() <= 0)
            {
                SetBackupWithholdingAmount(0);
                SetWithholdingAmt(0);
            }
            return(true);
        }
Example #30
0
        }       //	generateView

        /// <summary>
        /// Synchronize target table with base table in dictionary
        /// </summary>
        /// <param name="derived">is derived</param>
        /// <returns></returns>
        private MColumn[] SyncMColumns(bool derived)
        {
            MTable target = derived ? m_derivedTable : m_viewTable;
            MTable source = derived ? m_baseTable : m_derivedTable;

            MColumn[] sCols = source.GetColumns(false);
            MColumn[] tCols = target.GetColumns(false);
            //	Base Columns
            foreach (MColumn sCol in sCols)
            {
                MColumn tCol = null;
                foreach (MColumn column in tCols)
                {
                    if (sCol.GetColumnName().Equals(column.GetColumnName()))
                    {
                        tCol = column;
                        break;
                    }
                }
                if (tCol == null)
                {
                    tCol = new MColumn(target);
                }
                PO.CopyValues(sCol, tCol);
                tCol.SetAD_Table_ID(target.GetAD_Table_ID());   //	reset parent
                tCol.SetIsCallout(false);
                tCol.SetCallout(null);
                tCol.SetIsMandatory(false);
                tCol.SetIsMandatoryUI(false);
                tCol.SetIsTranslated(false);
                //	tCol.SetIsUpdateable(true);
                if (tCol.IsKey())
                {
                    tCol.SetIsKey(false);
                    tCol.SetAD_Reference_ID(DisplayType.TableDir);
                }
                if (tCol.Save())
                {
                    throw new Exception("Cannot save column " + sCol.GetColumnName());
                }
            }
            //
            tCols = target.GetColumns(true);
            List <String> addlColumns = new List <String>();

            if (derived && !m_history)  //	delta only
            {
                //	KeyColumn
                String  keyColumnName = target.GetTableName() + "_ID";
                MColumn key           = target.GetColumn(keyColumnName);
                if (key == null)
                {
                    key = new MColumn(target);
                    M_Element ele = M_Element.Get(m_ctx, keyColumnName, target.Get_TrxName());
                    if (ele == null)
                    {
                        ele = new M_Element(m_ctx, keyColumnName, target.GetEntityType(), null);
                        ele.Save();
                    }
                    key.SetAD_Element_ID(ele.GetAD_Element_ID());
                    key.SetAD_Reference_ID(DisplayType.ID);
                    key.Save();
                }
                addlColumns.Add(keyColumnName);
                //	Addl References
                if (m_userDef)
                {
                    String colName = "AD_Role_ID";
                    addlColumns.Add(colName);
                    if (target.GetColumn(colName) == null)
                    {
                        MColumn col = new MColumn(target);
                        col.SetColumnName(colName);
                        col.SetAD_Reference_ID(DisplayType.TableDir);
                        CreateColumn(col, target, false);
                        col.SetIsUpdateable(false);
                        col.SetIsMandatory(false);
                    }
                    colName = "AD_User_ID";
                    addlColumns.Add(colName);
                    if (target.GetColumn(colName) == null)
                    {
                        MColumn col = new MColumn(target);
                        col.SetColumnName(colName);
                        col.SetAD_Reference_ID(DisplayType.TableDir);
                        col.SetIsUpdateable(false);
                        col.SetIsMandatory(false);
                        CreateColumn(col, target, false);
                    }
                }
                else    //	System
                {
                    String colName = "IsSystemDefault";
                    addlColumns.Add(colName);
                    if (target.GetColumn(colName) == null)
                    {
                        MColumn col = new MColumn(target);
                        col.SetColumnName(colName);
                        col.SetAD_Reference_ID(DisplayType.YesNo);
                        col.SetDefaultValue("N");
                        col.SetIsUpdateable(false);
                        col.SetIsMandatory(true);
                        CreateColumn(col, target, false);
                    }
                }
            }


            //	Delete
            foreach (MColumn tCol in tCols)
            {
                MColumn sCol = null;
                foreach (MColumn column in sCols)
                {
                    if (tCol.GetColumnName().Equals(column.GetColumnName()))
                    {
                        sCol = column;
                        break;
                    }
                }
                if (sCol == null)
                {
                    if (!addlColumns.Contains(tCol.GetColumnName()))
                    {
                        if (!tCol.Delete(true))
                        {
                            throw new Exception("Cannot delete column "
                                                + tCol.GetColumnName());
                        }
                    }
                }
            }
            return(tCols);
        }       //	SyncMColumns