public static DateTime GetNearDayOfWeek(DateTime dtmDate, ECALENDARCYCLE_DATEOFWEEK ePdDayWeekEnum)
        {
            int      iDayDiff = ((short)(ePdDayWeekEnum) - DateTimeHelper.Weekday(dtmDate));
            DateTime retDate;

            if (Math.Abs(iDayDiff) < 4)
            {
                retDate = dtmDate.AddDays(+iDayDiff);
            }
            else if (iDayDiff > 0)
            {
                retDate = dtmDate.AddDays(-(7 - iDayDiff));
            }
            else
            {
                retDate = dtmDate.AddDays(+(7 + iDayDiff));
            }

            return(retDate);
        }
Exemple #2
0
        public bool AddCycleEntry(DateTime dtEffectiveDate, ECALENDARCYCLE_CYCLETYPE eCycleType, short eFYEndMonth, ECALENDARCYCLE_DATEOFWEEK ePeriodDayOfWeek, ECALENDARCYCLE_YEARENDELECTION eYearEndElection, ECALENDARCYCLE_PDCOUNTING ePDCounting)
        {
            IBACycleObject   objCalCycle;
            BAFASCycleObject objNewCalCycle;
            int      posi, count, origCount;
            bool     hr;
            DateTime dtFYStart, dtFYEnd, dtDate;
            ECALENDARCYCLE_DATEOFWEEK      eTmpDateOfWeek;
            ECALENDARCYCLE_CYCLETYPE       eTmpCycleType;
            ECALENDARCYCLE_YEARENDELECTION eTmpYearEndElection;
            IBACycleObject            objPrevCalCycle;
            short                     eNumberOfYears, eYearNumberOffset, eTmpFYEndMonth;
            ECALENDARCYCLE_PDCOUNTING eTmpPDCounting;

            dtEffectiveDate = dtEffectiveDate.Date;
            if (eCycleType == ECALENDARCYCLE_CYCLETYPE.CYCLETYPE_MONTHLY)
            {
                eYearEndElection = ECALENDARCYCLE_YEARENDELECTION.YEARENDELECTION_LASTWEEKDAY;
                ePDCounting      = ECALENDARCYCLE_PDCOUNTING.PDCOUNT_BACKWARD;
            }

            ClearBuckets();

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

            count = m_FYList.Count;

            origCount = count;

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


                    objCalCycle = null;

                    if (dtDate >= dtEffectiveDate.AddDays(-7))
                    {
                        --count;
                    }
                }

                if (count > 0)
                {
                    objCalCycle = m_FYList[count - 1];

                    if (objCalCycle == null)
                    {
                        throw new Exception("Invalid effective date.");
                    }

                    eTmpCycleType       = objCalCycle.CycleType;
                    eTmpFYEndMonth      = objCalCycle.FYEndMonth;
                    eTmpYearEndElection = objCalCycle.YearEndElect;
                    eTmpDateOfWeek      = objCalCycle.DateOfWeek;
                    eTmpPDCounting      = objCalCycle.PDCounting;

                    if (eTmpCycleType == eCycleType &&
                        eTmpDateOfWeek == ePeriodDayOfWeek &&
                        eTmpFYEndMonth == eFYEndMonth &&
                        eTmpYearEndElection == eYearEndElection &&
                        eTmpPDCounting == ePDCounting)
                    {
                        for (posi = origCount - 1; posi >= count; posi--)
                        {
                            m_FYList.RemoveAt(posi);
                        }
                        objCalCycle.EndDate = DateTime.MinValue;
                        return(true);
                    }

                    if (!(FiscalYearEndDate((dtEffectiveDate.AddDays(-1)).Year,
                                            eTmpCycleType,
                                            eTmpFYEndMonth,
                                            eTmpYearEndElection,
                                            eTmpDateOfWeek,
                                            out dtFYEnd)) ||
                        !(FiscalYearStartDate((dtEffectiveDate.AddDays(-1)).Year + 1,
                                              eCycleType,
                                              eTmpFYEndMonth,
                                              eYearEndElection,
                                              ePeriodDayOfWeek,
                                              out dtFYStart)))
                    {
                        return(false);
                    }

                    if (dtEffectiveDate != dtFYEnd && dtEffectiveDate != dtFYStart && dtEffectiveDate != dtFYEnd.AddDays(+1))
                    {
                        if ((dtEffectiveDate.Month) == 1 && (dtEffectiveDate.Day) < 7)
                        {
                            if (!(FiscalYearEndDate((dtEffectiveDate.AddDays(-7)).Year,
                                                    eTmpCycleType,
                                                    eTmpFYEndMonth,
                                                    eTmpYearEndElection,
                                                    eTmpDateOfWeek,
                                                    out dtFYEnd)) ||
                                !(FiscalYearStartDate((dtEffectiveDate.Year),
                                                      eCycleType,
                                                      eTmpFYEndMonth,
                                                      eYearEndElection,
                                                      ePeriodDayOfWeek,
                                                      out dtFYStart)))
                            {
                                return(false);
                            }
                        }
                        if (dtEffectiveDate != dtFYEnd && dtEffectiveDate != dtFYStart && dtEffectiveDate != dtFYEnd.AddDays(+1))
                        {
                            throw new Exception("Not a valid fiscal year end");
                        }
                    }
                }
                count = origCount;

                // remove use case 8.1b 4.2.a.1 calendar cycles
                for (posi = count - 1; posi >= 0; posi--)
                {
                    objCalCycle = null;
                    objCalCycle = m_FYList[posi];
                    dtDate      = objCalCycle.EffectiveDate;

                    objCalCycle = null;

                    if (dtDate >= dtEffectiveDate.AddDays(-7))
                    {
                        m_FYList.RemoveAt(posi);
                        --count;
                    }
                }
            }



            if (count <= 0)
            {
                if (dtEffectiveDate == DateTime.MinValue ||
                    eCycleType < ECALENDARCYCLE_CYCLETYPE.CYCLETYPE_MONTHLY ||
                    eCycleType > ECALENDARCYCLE_CYCLETYPE.CYCLETYPE_CUSTOM ||
                    eFYEndMonth < 0 ||
                    eFYEndMonth > 12 ||
                    ePeriodDayOfWeek < ECALENDARCYCLE_DATEOFWEEK.DATEOFWEEK_SUNDAY ||
                    ePeriodDayOfWeek > ECALENDARCYCLE_DATEOFWEEK.DATEOFWEEK_SATURDAY ||
                    eYearEndElection < ECALENDARCYCLE_YEARENDELECTION.YEARENDELECTION_LASTWEEKDAY ||
                    eYearEndElection > ECALENDARCYCLE_YEARENDELECTION.YEARENDELECTION_CLOSESTWEEKDAY)
                {
                    throw new Exception("Parameter out of range.");
                }

                objNewCalCycle = new BAFASCycleObject();
                objCalCycle    = objNewCalCycle;

                objCalCycle.EffectiveDate = (dtEffectiveDate);
                objCalCycle.CycleType     = (eCycleType);
                objCalCycle.DateOfWeek    = (ePeriodDayOfWeek);
                objCalCycle.FYEndMonth    = (eFYEndMonth);
                objCalCycle.YearEndElect  = (eYearEndElection);
                objCalCycle.PDCounting    = (ePDCounting);
            }
            else               // count > 0 (modify cycle)
            {
                // assign the CycleEndDate for the previous CBAFASCycleObject
                objCalCycle         = m_FYList[count - 1];
                objCalCycle.EndDate = dtEffectiveDate.AddDays(-1);

                objCalCycle = null;

                objNewCalCycle = new BAFASCycleObject();
                objCalCycle    = objNewCalCycle;

                objCalCycle.EffectiveDate = (dtEffectiveDate);
                objCalCycle.CycleType     = (eCycleType);
                objCalCycle.DateOfWeek    = (ePeriodDayOfWeek);
                objCalCycle.FYEndMonth    = (eFYEndMonth);
                objCalCycle.YearEndElect  = (eYearEndElection);
                objCalCycle.PDCounting    = (ePDCounting);


                objPrevCalCycle = m_FYList[count - 1];
                dtDate          = objPrevCalCycle.EffectiveDate;


                if (dtDate >= dtEffectiveDate)
                {
                    --count;
                    m_FYList.RemoveAt(count);
                }

                objPrevCalCycle = null;

                objPrevCalCycle = m_FYList[count - 1];

                eYearNumberOffset = objPrevCalCycle.YearNumberOffset;
                eNumberOfYears    = objPrevCalCycle.NumberOfYears;

                objPrevCalCycle = null;

                if (count >= 2)
                {
                    objCalCycle.YearNumberOffset = (short)(eYearNumberOffset + eNumberOfYears);
                }
                else if (count == 1)
                {
                    objCalCycle.YearNumberOffset = (eNumberOfYears);
                }
            }

            m_FYList.Add(objCalCycle);
            m_IsDirty = true;
            return(true);
        }
Exemple #3
0
        public bool FiscalYearStartDate(int lYear, ECALENDARCYCLE_CYCLETYPE eCycleTypeEnum, short eFYEndMonthEnum, ECALENDARCYCLE_YEARENDELECTION eYREndElectionEnum, ECALENDARCYCLE_DATEOFWEEK ePdDayWeekEnum, out DateTime pVal)
        {
            bool hr;

            hr = FiscalYearEndDate(lYear - 1,
                                   eCycleTypeEnum,
                                   eFYEndMonthEnum,
                                   eYREndElectionEnum,
                                   ePdDayWeekEnum,
                                   out pVal);
            pVal = pVal.AddDays(1);
            return(true);
        }
Exemple #4
0
        public bool FiscalYearEndDate(int lYear, ECALENDARCYCLE_CYCLETYPE eCycleTypeEnum, short eFYEndMonthEnum, ECALENDARCYCLE_YEARENDELECTION eYREndElectionEnum, ECALENDARCYCLE_DATEOFWEEK ePdDayWeekEnum, out DateTime pVal)
        {
            DateTime dtTmpDate;
            int      iDayOfWeek, iDayDiff;

            // make end of month
            dtTmpDate = DateTimeHelper.GetEndOfMonth(new DateTime(lYear, eFYEndMonthEnum, Constants.EndOfMonthSeed));

            // make the function default to YEARENDELECTION_LASTDAY
            pVal = dtTmpDate;

            if (eCycleTypeEnum != ECALENDARCYCLE_CYCLETYPE.CYCLETYPE_MONTHLY)
            {
                if (eYREndElectionEnum == ECALENDARCYCLE_YEARENDELECTION.YEARENDELECTION_CLOSESTWEEKDAY)
                {
                    pVal = DateTimeHelper.GetNearDayOfWeek(dtTmpDate, ePdDayWeekEnum);
                }
                else if (eYREndElectionEnum == ECALENDARCYCLE_YEARENDELECTION.YEARENDELECTION_LASTWEEKDAY)
                {
                    iDayOfWeek = DateTimeHelper.Weekday(dtTmpDate);
                    iDayDiff   = (short)(iDayOfWeek - ePdDayWeekEnum);
                    if (iDayDiff < 0)
                    {
                        iDayDiff = (short)(7 + iDayDiff);
                    }
                    pVal = new DateTime(dtTmpDate.Year, dtTmpDate.Month, dtTmpDate.Day).AddDays(-iDayDiff);
                }
            }

            return(true);
        }