Ejemplo n.º 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 + ")");
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Is standard Period Open for specified orgs for the client. For best
        /// performance, ensure that the list of orgs does not contain duplicates.
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="AD_Client_ID"></param>
        /// <param name="orgs"></param>
        /// <param name="DateAcct">accounting date</param>
        /// <param name="DocBaseType">document base type</param>
        /// <returns>error message or null</returns>
        /// <date>07-March-2011</date>
        /// <writer>raghu</writer>
        public static String IsOpen(Ctx ctx, int AD_Client_ID, List <int> orgs, DateTime?DateAcct,
                                    String DocBaseType)
        {
            if (DateAcct == null)
            {
                return("@NotFound@ @DateAcct@");
            }
            if (DocBaseType == null)
            {
                return("@NotFound@ @DocBaseType@");
            }

            MAcctSchema as1 = MClient.Get(ctx, AD_Client_ID).GetAcctSchema();

            if (as1 == null)
            {
                return("@NotFound@ @C_AcctSchema_ID@ for AD_Client_ID=" + AD_Client_ID);
            }
            if (as1.IsAutoPeriodControl())
            {
                if (as1.IsAutoPeriodControlOpen(DateAcct))
                {
                    return(null);
                }
                else
                {
                    return("@PeriodClosed@ - @AutoPeriodControl@");
                }
            }

            //	Get all Calendars in line with Organizations
            MClientInfo clientInfo   = MClientInfo.Get(ctx, AD_Client_ID, null);
            List <int>  orgCalendars = new List <int>();
            List <int>  calendars    = new List <int>();

            foreach (int org in orgs)
            {
                MOrgInfo orgInfo = MOrgInfo.Get(ctx, org, null);

                int C_Calendar_ID = orgInfo.GetC_Calendar_ID();
                if (C_Calendar_ID == 0)
                {
                    C_Calendar_ID = clientInfo.GetC_Calendar_ID();
                }
                orgCalendars.Add(C_Calendar_ID);
                if (!calendars.Contains(C_Calendar_ID))
                {
                    calendars.Add(C_Calendar_ID);
                }
            }
            //	Should not happen
            if (calendars.Count == 0)
            {
                return("@NotFound@ @C_Calendar_ID@");
            }

            //	For all Calendars get Periods
            for (int i = 0; i < calendars.Count; i++)
            {
                int     C_Calendar_ID = calendars[i];
                MPeriod period        = MPeriod.GetOfCalendar(ctx, C_Calendar_ID, DateAcct);
                //	First Org for Calendar
                int AD_Org_ID = 0;
                for (int j = 0; j < orgCalendars.Count; j++)
                {
                    if (orgCalendars[j] == C_Calendar_ID)
                    {
                        AD_Org_ID = orgs[j];
                        break;
                    }
                }
                if (period == null)
                {
                    MCalendar cal  = MCalendar.Get(ctx, C_Calendar_ID);
                    String    date = DisplayType.GetDateFormat(DisplayType.Date).Format(DateAcct);
                    if (cal != null)
                    {
                        return("@NotFound@ @C_Period_ID@: " + date
                               + " - " + MOrg.Get(ctx, AD_Org_ID).GetName()
                               + " -> " + cal.GetName());
                    }
                    else
                    {
                        return("@NotFound@ @C_Period_ID@: " + date
                               + " - " + MOrg.Get(ctx, AD_Org_ID).GetName()
                               + " -> C_Calendar_ID=" + C_Calendar_ID);
                    }
                }
                String error = period.IsOpen(DocBaseType, DateAcct);
                if (error != null)
                {
                    return(error
                           + " - " + MOrg.Get(ctx, AD_Org_ID).GetName()
                           + " -> " + MCalendar.Get(ctx, C_Calendar_ID).GetName());
                }
            }
            return(null);        //	open
        }