/// <summary> /// Parent Constructor /// </summary> /// <param name="period">parent</param> /// <param name="docBaseType">doc base type</param> public MPeriodControl(MPeriod period, String docBaseType) : this(period.GetCtx(), period.GetAD_Client_ID(), period.GetC_Period_ID(), docBaseType, period.Get_TrxName()) { }
/// <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); }