}       //	setDateAcct

        /// <summary>
        /// Set Period
        /// </summary>
        /// <param name="C_Period_ID">period</param>
        public new void SetC_Period_ID(int C_Period_ID)
        {
            base.SetC_Period_ID(C_Period_ID);
            if (C_Period_ID == 0)
            {
                return;
            }
            DateTime?dateAcct = GetDateAcct();
            //
            MPeriod period = GetPeriod();

            if (period != null && period.IsStandardPeriod())
            {
                if (!period.IsInPeriod(dateAcct))
                {
                    base.SetDateAcct(period.GetEndDate());
                }
            }
        }       //	setC_Period_ID
예제 #2
0
        /// <summary>
        /// Find standard Period of DateAcct based on Client Calendar
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="C_Calendar_ID">calendar</param>
        /// <param name="DateAcct">DateAcct date</param>
        /// <returns> active Period or null</returns>
        /// <date>07-March-2011</date>
        /// <writer>raghu</writer>
        public static MPeriod GetOfCalendar(Ctx ctx, int C_Calendar_ID, DateTime?DateAcct)
        {
            if (DateAcct == null)
            {
                _log.Warning("No DateAcct");
                return(null);
            }
            if (C_Calendar_ID == 0)
            {
                _log.Warning("No Calendar");
                return(null);
            }
            //	Search in Cache first
            IEnumerator <MPeriod> it = cache.Values.GetEnumerator();

            while (it.MoveNext())
            {
                MPeriod period = it.Current;
                if (period.GetC_Calendar_ID() == C_Calendar_ID &&
                    period.IsStandardPeriod() &&
                    period.IsInPeriod(DateAcct))
                {
                    return(period);
                }
            }

            //	Get it from DB
            MPeriod retValue = null;
            // mohit 28-9-2015
            //String sql = "SELECT * FROM C_Period "
            //    + "WHERE C_Year_ID IN "
            //    + "(SELECT C_Year_ID FROM C_Year WHERE C_Calendar_ID=" + C_Calendar_ID + ")"
            //    + " AND '" + TimeUtil.GetDay(DateAcct) + "' BETWEEN TRUNC(StartDate,'DD') AND TRUNC(EndDate,'DD')"
            //    + " AND IsActive='Y' AND PeriodType='S'";
            String sql = "SELECT * FROM C_Period "
                         + "WHERE C_Year_ID IN "
                         + "(SELECT C_Year_ID FROM C_Year WHERE C_Calendar_ID=" + C_Calendar_ID + ")"
                         + " AND " + GlobalVariable.TO_DATE(DateAcct, true) + " BETWEEN TRUNC(StartDate,'DD') AND TRUNC(EndDate,'DD')"
                         + " AND IsActive='Y' AND PeriodType='S'";
            IDataReader idr = null;

            try
            {
                idr = DB.ExecuteReader(sql, null);
                DataTable dt = new DataTable();
                dt.Load(idr);
                idr.Close();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    MPeriod period = new MPeriod(ctx, dt.Rows[i], null);
                    int     key    = Util.GetValueOfInt(period.GetC_Period_ID());

                    cache[key] = period;

                    if (period.IsStandardPeriod())
                    {
                        retValue = period;
                    }
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, "DateAcct=" + DateAcct, e);
            }
            finally
            {
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
            }
            if (retValue == null)
            {
                _log.Warning("No Standard Period for " + DateAcct
                             + " (C_Calendar_ID=" + C_Calendar_ID + ")");
            }
            return(retValue);
        }
예제 #3
0
        /// <summary>
        /// Find standard Period of DateAcct based on Client Calendar
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="dateAcct">date</param>
        /// <returns>active Period or null</returns>
        public static MPeriod Get(Ctx ctx, DateTime?dateAcct)
        {
            if (dateAcct == null)
            {
                return(null);
            }
            //	Search in Cache first
            IEnumerator <MPeriod> it = cache.Values.GetEnumerator();

            it.Reset();
            while (it.MoveNext())
            {
                MPeriod period = it.Current;
                if (period.GetAD_Client_ID() == ctx.GetAD_Client_ID() && period.IsStandardPeriod() && period.IsInPeriod((DateTime?)dateAcct))
                {
                    return(period);
                }
            }

            //	Get it from DB
            MPeriod retValue     = null;
            int     AD_Client_ID = ctx.GetAD_Client_ID();
            String  sql          = "SELECT * "
                                   + "FROM C_Period "
                                   + "WHERE C_Year_ID IN "
                                   + "(SELECT C_Year_ID FROM C_Year WHERE C_Calendar_ID= "
                                   + "(SELECT C_Calendar_ID FROM AD_ClientInfo WHERE AD_Client_ID=@clientid))"
                                   + " AND @dateAcc BETWEEN TRUNC(StartDate,'DD') AND TRUNC(EndDate,'DD')"
                                   + " AND IsActive='Y' AND PeriodType='S'";

            try
            {
                //DateTime? dt = ((DateTime?)dateAcct).Date;
                DateTime?dt = ((DateTime?)dateAcct).Value.Date;

                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@clientid", AD_Client_ID);
                param[1] = new SqlParameter("@dateAcc", TimeUtil.GetDay((DateTime?)dateAcct));

                DataSet ds = DataBase.DB.ExecuteDataset(sql, param, null);
                if (ds.Tables.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        MPeriod period = new MPeriod(ctx, dr, null);
                        int     key    = period.GetC_Period_ID();
                        cache.Add(key, period);
                        if (period.IsStandardPeriod())
                        {
                            retValue = period;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, "dateAcct=" + dateAcct, e);
            }
            if (retValue == null)
            {
                _log.Warning("No Standard Period for " + dateAcct + " (AD_Client_ID=" + AD_Client_ID + ")");
            }
            return(retValue);
        }