Method:
void GenerateOneYearWeekPeriods()
{
date d1,d2,d3,d4,wkst,wkend,i,k;
integer lineNum = 0;
int findlastrecid()
{
select * from FAHWeeklyTimeSheetPeriods order by Recid Desc;
return FAHWeeklyTimeSheetPeriods.LineNum;
}
;
d1 = Stratdate.dateValue();
d2 = Enddate.dateValue();
lineNum = findlastrecid();
if(!FAHWeeklyTimeSheetPeriods::exist(d1))
{
for(i = d1 ; i <= d2 ; i++)
{
if(mthofyr(i) == 1)
{
if(dayofwk(i) == 6 || i == d1 )//sat && start of the month
{
wkst = i;
}
if(dayofwk(i) == 5 || i == endmth(i))//fri && end of the month
{
wkend = i;
lineNum++;
FAHWeeklyTimeSheetPeriods.LineNum = lineNum;
FAHWeeklyTimeSheetPeriods.Weekcode = NumberSeq::newGetNum(ProjParameters::numRefFAHWeekCode(),true).num();
FAHWeeklyTimeSheetPeriods.PeriodId = mthofyr(i);
FAHWeeklyTimeSheetPeriods.Month = global::dateStartMth(i);
FAHWeeklyTimeSheetPeriods.Year = year(FAHWeeklyTimeSheetPeriods.Month);
FAHWeeklyTimeSheetPeriods.StratDate = wkst;
FAHWeeklyTimeSheetPeriods.StratDay = dayName(dayofwk(wkst));
FAHWeeklyTimeSheetPeriods.EndDate = wkend;
FAHWeeklyTimeSheetPeriods.EndDay = dayName(dayofwk(wkend));
FAHWeeklyTimeSheetPeriods.Status = WeekPeriodStatus::open;
FAHWeeklyTimeSheetPeriods.insert();
}
}
if(mthofyr(k) != mthofyr(i))
{
d3 = i ; d4 = endmth(i);
for( k = d3 ; k <= d4; k++)
{
if(dayofwk(k) == 6 || k == d3 )//sat && start of the month
{
wkst = k;
}
if(dayofwk(k) == 5 || k == d4 )//fri && end of the month
{
wkend = k;
lineNum++;
FAHWeeklyTimeSheetPeriods.LineNum = lineNum;
FAHWeeklyTimeSheetPeriods.Weekcode = NumberSeq::newGetNum(ProjParameters::numRefFAHWeekCode(),true).num();
FAHWeeklyTimeSheetPeriods.PeriodId = mthofyr(i);
FAHWeeklyTimeSheetPeriods.Month = global::dateStartMth(i);
FAHWeeklyTimeSheetPeriods.Year = year(FAHWeeklyTimeSheetPeriods.Month);
FAHWeeklyTimeSheetPeriods.StratDate = wkst;
FAHWeeklyTimeSheetPeriods.StratDay = dayName(dayofwk(wkst));
FAHWeeklyTimeSheetPeriods.EndDate = wkend;
FAHWeeklyTimeSheetPeriods.EndDay = dayName(dayofwk(wkend));
FAHWeeklyTimeSheetPeriods.Status = WeekPeriodStatus::open;
FAHWeeklyTimeSheetPeriods.insert();
}
}
k = i ;
}
}
}
FAHWeeklyTimeSheetPeriods_ds.executeQuery();
}