[Form]
public class AK_ForwardLookingAllocation extends FormRun
{
#TimeConstants
#ISOCountryRegionCodes
int WeekCount = 38;
int firstDayIndex = 1;
LabelString dayLabels[62];
NoYes requireStartStopTime;
public Array setDatesInArray()
{
TSDate d;
TSDate cwstartDate;
Array dates = new Array(Types::Date);
d = DateTimeUtil::date(systemDateget());
TSDate temp_date;
cwstartDate = Global::dateStartWk(d) 1;
for(int i=-6; i<=31;i )
{
temp_date = (cwstartDate 7*i);
dates.value(i 7, temp_date);
}
return dates;
}
void setLineGridDays(
TransDate _periodFrom,
TransDate _periodTo)
{
Array gridDays = this.setDatesInArray();
str dayControlNames = strReplace(formcontrolstr(AK_ForwardLookingAllocation, INCK_ResourceRequitionLine_RealBaseCopy_1),'1','%1');
for(int i=1;i<=gridDays.lastIndex();i )
{
info(strFmt("Dates : %1",gridDays.value(i)));
}
for (int dayNum = 1; dayNum <= WeekCount; dayNum )
{
FormRealControl hoursField = element.design().controlName(strfmt(dayControlNames,dayNum));
if (any2date(gridDays.value(dayNum)) != dateNull())
{
dayLabels[dayNum] = this.getDateCaption(any2date(gridDays.value(dayNum)));
hoursField.visible(true);
//hoursField.label(gridDays.value(dayNum));
hoursField.label(dayLabels[dayNum]);
hoursField.allowEdit(!requireStartStopTime);
}
else
{
hoursField.visible(false);
hoursField.label('');
}
}
}
public str getDateCaption(TransDate _date)
{
//TSWeekDayAbbrev dayAbbr = dayOfWk( _date);
//str dateStr = TSPeriods::date2StrUsrMMDD(_date);
str dateStr = this.date2StrUsrMMDDYYYY(_date);
return strFmt("%1", dateStr);
}
public TempStr date2StrUsrMMDDYYYY(date _transDate)
{
return date2str(_transDate, -1, DateDay::Digits2, -1, DateMonth::Digits2, -1, DateYear::Digits4, DateFlags::FormatAll);
}
public void init()
{
super();
this.setLineGridDays(systemDateGet() (-7*6),systemDateGet() (7*31));
INCK_ResourceRequitionLine_ds.executeQuery();
// element.refreshTimesheetGrid();
}
[DataSource]
class INCK_ResourceRequitionLine
{
///
///
///
public void executeQuery()
{
QueryBuildDataSource queryBuildDataSource;
queryBuildDataSource = this.query().dataSourceTable(tablenum(INCK_ResourceRequitionLine));
queryBuildDataSource.clearRanges();
queryBuildDataSource.addRange(fieldnum(INCK_ResourceRequitionLine, LineAllocationStatus)).value(enum2Str(INCK_LineAllocationStatus::Allocated));
queryBuildDataSource.addRange(fieldnum(INCK_ResourceRequitionLine, LineAllocationStatus)).value(enum2Str(INCK_LineAllocationStatus::ExternalHiring));
queryBuildDataSource.addRange(fieldnum(INCK_ResourceRequitionLine, LineAllocationStatus)).value(enum2Str(INCK_LineAllocationStatus::Hold));
queryBuildDataSource.addRange(fieldnum(INCK_ResourceRequitionLine, LineAllocationStatus)).value(enum2Str(INCK_LineAllocationStatus::Offered));
queryBuildDataSource.addRange(fieldnum(INCK_ResourceRequitionLine, LineAllocationStatus)).value(enum2Str(INCK_LineAllocationStatus::Pending));
super();
}
[DataField]
class AllocationPercentage
{
///
///
///
public void modified()
{
//Array dates = element.setDatesInArray();
str dayControlNames = strReplace(formcontrolstr(AK_ForwardLookingAllocation, INCK_ResourceRequitionLine_RealBaseCopy_1),'1','%1');
super();
for (int i=1; i<=38; i )
{
FormRealControl hoursField = element.design().controlName(strfmt(dayControlNames, i));
// if( dates.value(i) >= INCK_ResourceRequitionLine.AllocationStartDate)
Info(strFmt("%1", INCK_ResourceRequitionLine.AllocationStartDate));
Info(strFmt("%1", hoursField.labelText()));
if( str2Date(hoursField.labelText(),213) >= INCK_ResourceRequitionLine.AllocationStartDate)
{
INCK_ResourceRequitionLine.RealBaseCopy[i-1] = ((6-dayOfWk(INCK_ResourceRequitionLine.AllocationStartDate))*(INCK_ResourceRequitionLine.AllocationPercentage/5));
break;
}
}
for (int i=1; i<=38; i )
{
FormRealControl hoursField = element.design().controlName(strfmt(dayControlNames, i));
//if (dates.value(i) <= INCK_ResourceRequitionLine.AllocationEndDate && dates.value(i) >= INCK_ResourceRequitionLine.AllocationStartDate)
Info(strFmt("%1", INCK_ResourceRequitionLine.AllocationStartDate));
Info(strFmt("%1", hoursField.labelText()));
if (str2Date(hoursField.labelText(),213) <= INCK_ResourceRequitionLine.AllocationEndDate && str2Date(hoursField.labelText(),213) >= INCK_ResourceRequitionLine.AllocationStartDate)
{
INCK_ResourceRequitionLine.RealBaseCopy[i] = INCK_ResourceRequitionLine.AllocationPercentage;
}
}
for (int i=38; i>=1; i--)
{
FormRealControl hoursField = element.design().controlName(strfmt(dayControlNames, i));
// if( dates.value(i) <= INCK_ResourceRequitionLine.AllocationEndDate)
Info(strFmt("%1", INCK_ResourceRequitionLine.AllocationStartDate));
Info(strFmt("%1", hoursField.labelText()));
if( str2Date(hoursField.labelText(),213) <= INCK_ResourceRequitionLine.AllocationEndDate)
{
INCK_ResourceRequitionLine.RealBaseCopy[i] = ((dayOfWk(INCK_ResourceRequitionLine.AllocationEndDate))*(INCK_ResourceRequitionLine.AllocationPercentage/5));
break;
}
}
}
}
[DataField]
class EmployeeId
{
///
///
///
public void modified()
{
ResourceView resourceView;
super();
select * from resourceView where resourceView.ResourceId == INCK_ResourceRequitionLine.EmployeeId;
INCK_ResourceRequitionLine.INCK_Worker = resourceView.Worker;
}
}
}
}
Hi Manoj and Girish, Thanks for your response.
I have a table in which I have a field named RealBaseCopy which is a base enum containing 38 elements. Each element of enum is meant to store a real value based on some conditions. I also a a real field named percentageAllocation. Based on the value of percentageAllocation, the values are inserted in to the elements of the base enum RealBaseCopy.
I have modified the labels of the base enum elements dynamically to display dates of upcoming weeks. The data is inserted into the base enum elements after comparison of the labels of the base enum elements with the allocationstartdate and allocationenddate fields of the table. Refer to the attached code.
The issue is that if I create an entry this week into the table, the data is entered correctly but when I view that entry next week, the existing data is moved to the next base enum element (because the current week date is moved to the previous label but the data in table remains at the same index thus showing it below the next week label in form) thus resulting in wrong display of data.
How do I resolve it? Please help.
Thanks and Regards.