/// <summary>
        /// This function is used to get data of MRevenueRecognitionRun
        /// </summary>
        /// <param name="revenueRecognition">Revenue Recognition reference</param>
        /// <param name="recognitionDate">Recognition Date</param>
        /// <param name="_orgId">Org ID</param>
        /// <param name="reverse">is reverse or not</param>
        /// <returns>array of MRevenueRecognitionRun</returns>
        public static MRevenueRecognitionRun[] GetRecognitionRuns(MRevenueRecognition revenueRecognition, DateTime?recognitionDate, int _orgId, bool reverse)
        {
            List <MRevenueRecognitionRun> list = new List <MRevenueRecognitionRun>();
            string sql = "Select  rn.* from C_RevenueRecognition_Run rn " +
                         " JOIN c_revenuerecognition_plan pl ON pl.c_revenuerecognition_plan_id = rn.c_revenuerecognition_plan_id " +
                         " WHERE pl.c_revenuerecognition_id =" + revenueRecognition.GetC_RevenueRecognition_ID();

            if (!reverse)
            {
                sql += " And RecognitionDate <=" + GlobalVariable.TO_DATE(recognitionDate, true);
            }
            if (_orgId > 0)
            {
                sql += " AND pl.AD_Org_ID=" + _orgId;
            }
            sql += " And NVL(GL_Journal_ID,0) <= 0 ORDER BY rn.RecognitionDate, pl.c_currency_id, pl.c_acctschema_id";

            DataTable   dt  = null;
            IDataReader idr = null;

            try
            {
                idr = DB.ExecuteReader(sql, null, revenueRecognition.Get_Trx());
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    list.Add(new MRevenueRecognitionRun(revenueRecognition.GetCtx(), dr, revenueRecognition.Get_Trx()));
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            finally
            {
                dt = null;
            }

            MRevenueRecognitionRun[] retValue = new MRevenueRecognitionRun[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }
        /// <summary>
        /// This Function is used to gete Plan data record based on respective parameters
        /// </summary>
        /// <param name="RevenueRecognition">Revenue Recognition Reference</param>
        /// <param name="InvoiceLine_ID">Invoice Line Reference</param>
        /// <param name="OrgId">Org ID</param>
        /// <returns>Array of MRevenueRecognitionPlan</returns>
        public static MRevenueRecognitionPlan[] GetRecognitionPlans(MRevenueRecognition RevenueRecognition, int InvoiceLine_ID, int OrgId)
        {
            List <MRevenueRecognitionPlan> list = new List <MRevenueRecognitionPlan>();
            string sql = "SELECT * FROM C_RevenueRecognition_Plan pl";

            if (InvoiceLine_ID > 0)
            {
                sql += @" INNER  JOIN c_invoiceline invl ON invl.c_invoiceline_id = pl.c_invoiceline_id 
                            WHERE pl.C_RevenueRecognition_ID=" + RevenueRecognition.GetC_RevenueRecognition_ID() +
                       " AND invl.c_invoiceLine_id=" + InvoiceLine_ID + " AND invl.ad_org_id=" + OrgId;
            }
            else
            {
                sql += " WHERE pl.C_RevenueRecognition_ID=" + RevenueRecognition.GetC_RevenueRecognition_ID() + " AND pl.ad_org_id=" + OrgId;
            }
            DataTable   dt  = null;
            IDataReader idr = null;

            try
            {
                idr = DB.ExecuteReader(sql, null, RevenueRecognition.Get_Trx());
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    list.Add(new MRevenueRecognitionPlan(RevenueRecognition.GetCtx(), dr, RevenueRecognition.Get_Trx()));
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            finally
            {
                dt = null;
            }

            MRevenueRecognitionPlan[] retValue = new MRevenueRecognitionPlan[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }