Esempio n. 1
0
        bool FindBucket(DateTime dt, out IBAFiscalYear pVal)
        {
            int  i;
            long value;
            long min;

            dt = dt.Date;

            for (i = 0; i < BUCKETCOUNT; i++)
            {
                if (m_yearBuckets[i].GetObject(dt, out pVal))
                {
                    return(true);
                }
            }

            min = 99999999L;
            for (i = 0; i < BUCKETCOUNT; i++)
            {
                value = m_yearBuckets[i].get_Count();
                if (value < min)
                {
                    m_nextBucket = (short)i;
                    min          = value;
                }
            }
            pVal = null;
            return(false);
        }
Esempio n. 2
0
        public bool BuildFiscalYear(IBACycleObject objCalCycle, short YearNumber, out IBAFiscalYear objIFY)
        {
            IBAFiscalYear obj = new BAFASFiscalYear();

            obj.InitializeWithCycleObject(objCalCycle, YearNumber);
            objIFY = obj;

            return(true);
        }
 public bool GetObject(DateTime dt, out IBAFiscalYear pVal) // returns E_FAIL if not valid.
 {
     dt = dt.Date;
     if (dt > DateTime.MinValue && dt >= m_startDate && dt <= m_endDate)
     {
         m_count++;
         pVal = m_object;
         return(true);
     }
     pVal = null;
     return(false);
 }
Esempio n. 4
0
        public bool GetFiscalYearNum(DateTime dtDate, out short pVal)
        {
            IBAFiscalYear objIFY = null;

            dtDate = dtDate.Date;
            pVal   = 0;
            if (!GetFiscalYear(dtDate, out objIFY))
            {
                return(false);
            }
            pVal = objIFY.FYNum;
            return(true);
        }
Esempio n. 5
0
        public bool GetFiscalYearByNum(short iYearNum, out IBAFiscalYear objIFY)
        {
            short          iNumYears;
            short          iYearNumOffset;
            IBACycleObject objCalCycle;
            int            posi;
            bool           hr = false;
            DateTime       dtEndDate;
            IBAFiscalYear  objFY;

            objIFY = null;
            if (m_FYList == null)
            {
                new Exception("Cycle list is uninitialized.");
            }

            for (posi = 0; posi < m_FYList.Count; posi++)
            {
                objCalCycle = m_FYList[posi];

                if (objCalCycle != null)
                {
                    iNumYears      = objCalCycle.NumberOfYears;
                    iYearNumOffset = objCalCycle.YearNumberOffset;
                    dtEndDate      = objCalCycle.EndDate;

                    if (iYearNumOffset < iYearNum && (dtEndDate <= DateTime.MinValue || iYearNum <= iYearNumOffset + iNumYears))
                    {
                        if ((FindBucket(DetermineDateForFY(objCalCycle, (short)(iYearNum - iYearNumOffset)), out objIFY)))
                        {
                            return(true);
                        }

                        if (!(hr = BuildFiscalYear(objCalCycle, (short)(iYearNum - iYearNumOffset), out objFY)))
                        {
                            return(hr);
                        }
                        //
                        // Save this year object in the cache.
                        //
                        m_yearBuckets[m_nextBucket].HoldMe(objFY);
                        objIFY = objFY;
                        return(true);
                    }
                }
                objCalCycle = null;
                //throw new Exception("Invalid year number specified.");
            }
            return(false);
        }
 public bool HoldMe(IBAFiscalYear newVal)
 {
     m_object    = null;
     m_object    = newVal;
     m_startDate = DateTime.MinValue;
     m_endDate   = DateTime.MinValue;
     m_count     = 0;
     if (m_object != null)
     {
         m_startDate = m_object.YRStartDate;
         m_endDate   = m_object.YREndDate;
     }
     m_count = 1;
     return(true);
 }
Esempio n. 7
0
        public bool ShortYearList(out List <IBAFiscalYear> pVal)
        {
            int            posi, count;
            IBACycleObject objCalCycle;
            IBAFiscalYear  objIFY = null;
            bool           b;
            DateTime       dtDate;
            bool           hr;

            pVal = null;

            if (m_FYList == null)
            {
                throw new Exception("Cycle list is uninitialized.");
            }

            count = m_FYList.Count;

            for (posi = 0; posi < count; posi++)
            {
                objCalCycle = m_FYList[posi];
                dtDate      = objCalCycle.EffectiveDate;

                objCalCycle = null;
                objIFY      = null;

                if (!(hr = GetFiscalYear(dtDate, out objIFY)))
                {
                    return(hr);
                }

                b = objIFY.IsShortYear;

                if (b)   // it's a short year
                {
                    if (pVal == null)
                    {
                        // create the list if this is the first short year
                        pVal = new List <IBAFiscalYear>();
                    }
                    // add the fy to the list
                    pVal.Add(objIFY);
                }
            }

            return(true);
        }
Esempio n. 8
0
        public IEnumerable <IBAFiscalYear> GetFiscalYearList(DateTime dtStartDate, DateTime dtEndDate)
        {
            IBAFiscalYear        objFy    = null;
            List <IBAFiscalYear> pTmpList = new List <IBAFiscalYear>();

            dtStartDate = dtStartDate.Date;
            dtEndDate   = dtEndDate.Date;
            DateTime tmpDate = dtStartDate;

            do
            {
                GetFiscalYear(tmpDate, out objFy);
                pTmpList.Add(objFy);
                tmpDate = objFy.YREndDate.AddDays(1);
            } while (objFy.YREndDate < dtEndDate);
            return(pTmpList);
        }
Esempio n. 9
0
        public bool LastShortYear(out DateTime pVal)
        {
            int            posi, count;
            IBACycleObject objCalCycle;
            IBAFiscalYear  objIFY = null;
            bool           b;
            DateTime       dtDate;
            bool           hr;

            pVal = DateTime.MinValue;

            if (m_FYList == null)
            {
                throw new Exception("Cycle list is uninitialized.");
            }

            count = m_FYList.Count;

            for (posi = count - 1; posi >= 0; posi--)
            {
                objCalCycle = m_FYList[posi];
                dtDate      = objCalCycle.EffectiveDate;

                objCalCycle = null;
                objIFY      = null;

                if (!(hr = GetFiscalYear(dtDate, out objIFY)))
                {
                    return(hr);
                }

                b = objIFY.IsShortYear;

                if (b)
                {
                    pVal = dtDate;
                    break;
                }
            }

            return(true);
        }
Esempio n. 10
0
        public bool GetFiscalYear(DateTime dtDate, out IBAFiscalYear objIFY)
        {
            int            iYear;
            IBACycleObject objCalCycle;
            IBAFiscalYear  objFY;
            int            count;
            int            posi;
            DateTime       dtEffectiveDate;
            DateTime       dtEndDate;
            DateTime       dtYREndDate;
            DateTime       dtYRStartDate;

            dtDate = dtDate.Date;

            if (m_FYList == null)
            {
                throw new Exception("Cycle list is uninitialized.");
            }
            count = m_FYList.Count;

            if (dtDate < new DateTime(1920, 1, 1))
            {
                throw new Exception("Invalid date specified. [dtDate < new DateTime(1920, 1, 1)], dtDate= " + dtDate.ToString());
            }
            if (dtDate > new DateTime(3000, 1, 1)) //change to allow to date till 2999
            {
                throw new Exception("Invalid date specified.[dtDate > new DateTime(3000, 1, 1)], dtDate= " + dtDate.ToString());
            }

            if (FindBucket(dtDate, out objIFY))
            {
                return(true);
            }

            for (posi = 0; posi < count; posi++)
            {
                bool ThisOne;

                objCalCycle = m_FYList[posi];

                dtEffectiveDate = objCalCycle.EffectiveDate;
                dtEndDate       = objCalCycle.EndDate;

                if (dtDate >= dtEffectiveDate &&
                    (dtEndDate <= DateTime.MinValue || dtEndDate >= dtDate))
                {
                    ThisOne = true;
                }
                else if (posi == 0 && dtDate.Month == dtEffectiveDate.Month &&
                         dtDate.Year == dtEffectiveDate.Year)
                {
                    dtDate  = dtEffectiveDate;
                    ThisOne = true;
                }
                else
                {
                    ThisOne = false;
                }

                if (ThisOne)
                {
                    // Find the nearest iYearNum
                    iYear = ((dtDate.Year) - (dtEffectiveDate.Year) + 1);

                    // dtDate == dtEndDate means dtDate is a year end date
                    // if Month(dtDate) == 1 and Day(dtDate) <= 4
                    // it means this year end date is move to the next year for some reason
                    if (dtDate == dtEndDate && (dtDate.Month) == 1 && (dtDate.Day) <= 4)
                    {
                        iYear -= 1;
                    }

                    BuildFiscalYear(objCalCycle, (short)iYear, out objFY);
                    dtYRStartDate = objFY.YRStartDate;
                    dtYREndDate   = objFY.YREndDate;

                    if (dtYREndDate < dtDate)
                    {
                        objFY = null;
                        BuildFiscalYear(objCalCycle, (short)(iYear + 1), out objFY);
                    }
                    else if (dtYRStartDate > dtDate)
                    {
                        while (dtYRStartDate > dtDate)
                        {
                            objFY = null;
                            iYear = iYear - 1;
                            BuildFiscalYear(objCalCycle, (short)iYear, out objFY);
                            dtYRStartDate = objFY.YRStartDate;
                            dtYREndDate   = objFY.YREndDate;
                        }
                    }
                    //
                    // Save this year object in the cache.
                    //
                    m_yearBuckets[m_nextBucket].HoldMe(objFY);
                    objIFY = objFY;

                    return(true);
                }


                objCalCycle = null;
            }
            throw new Exception("Invalid date specified.[None of the conditions met.], dtDate = " + dtDate.ToString() + ", count = " + count.ToString());
        }