Пример #1
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());
        }