Example #1
0
        /// <summary>
        /// Is Period Open for Doc Base Type in selected Organization
        /// </summary>
        /// <param name="DocBaseType">document base type</param>
        /// <param name="dateAcct">accounting date</param>
        /// <returns>error message or null</returns>
        /// <date>07-March-2011</date>
        /// <writer>raghu</writer>
        public String IsOpen(String DocBaseType, DateTime?dateAcct, int AD_Org_ID)
        {
            if (!IsActive())
            {
                _log.Warning("Period not active: " + GetName());
                return("@C_Period_ID@ <> @IsActive@");
            }

            MAcctSchema as1 = null;

            if (AD_Org_ID > 0)
            {
                as1 = MOrg.Get(GetCtx(), AD_Org_ID).GetAcctSchema();
            }
            else
            {
                as1 = MClient.Get(GetCtx(), GetAD_Client_ID()).GetAcctSchema();
            }
            if (as1 != null && as1.IsAutoPeriodControl())
            {
                if (!as1.IsAutoPeriodControlOpen(dateAcct))
                {
                    return("@PeriodClosed@ - @AutoPeriodControl@");
                }
                //	We are OK
                DateTime today = DateTime.Now.Date;
                if (IsInPeriod(today) && as1.GetC_Period_ID() != GetC_Period_ID())
                {
                    as1.SetC_Period_ID(GetC_Period_ID());
                    as1.Save();
                }
                return(null);
            }

            //	Standard Period Control
            if (DocBaseType == null)
            {
                log.Warning(GetName() + " - No DocBaseType");
                return("@NotFound@ @DocBaseType@");
            }
            MPeriodControl pc = GetPeriodControl(DocBaseType, AD_Org_ID);

            if (pc == null)
            {
                log.Warning(GetName() + " - Period Control not found for " + DocBaseType);
                return("@NotFound@ @C_PeriodControl_ID@: " + DocBaseType);
            }
            log.Fine(GetName() + ": " + DocBaseType);
            if (pc.IsOpen())
            {
                return(null);
            }
            return("@PeriodClosed@ - @C_PeriodControl_ID@ ("
                   + DocBaseType + ", " + dateAcct + ")");
        }
Example #2
0
        /// <summary>
        /// Is Period Open for Doc Base Type
        /// </summary>
        /// <param name="docBaseType">document base type</param>
        /// <returns>true if open</returns>
        public bool IsOpen(String docBaseType)
        {
            if (!IsActive())
            {
                _log.Warning("Period not active: " + GetName());
                return(false);
            }

            MAcctSchema mas = MClient.Get(GetCtx(), GetAD_Client_ID()).GetAcctSchema();

            if (mas != null && mas.IsAutoPeriodControl())
            {
                //	if (as.getC_Period_ID() == getC_Period_ID())
                //		return true;
                DateTime today = DateTime.Now;// new DateTime(CommonFunctions.CurrentTimeMillis());
                DateTime first = TimeUtil.AddDays(today, -mas.GetPeriod_OpenHistory());
                DateTime last  = TimeUtil.AddDays(today, mas.GetPeriod_OpenFuture());
                //if (today.before(first))
                if (today < first)
                {
                    log.Warning("Today before first day - " + first);
                    return(false);
                }
                //if (today.after(last))
                if (today > last)
                {
                    log.Warning("Today after last day - " + first);
                    return(false);
                }
                //	We are OK
                if (IsInPeriod(today))
                {
                    mas.SetC_Period_ID(GetC_Period_ID());
                    mas.Save();
                }
                return(true);
            }

            //	Standard Period Control
            if (docBaseType == null)
            {
                log.Warning(GetName() + " - No DocBaseType");
                return(false);
            }
            MPeriodControl pc = GetPeriodControl(docBaseType);

            if (pc == null)
            {
                log.Warning(GetName() + " - Period Control not found for " + docBaseType);
                return(false);
            }
            log.Fine(GetName() + ": " + docBaseType);
            return(pc.IsOpen());
        }