Generate Proj Hours Journal Lines
public class ALE_GenerareJournalLines extends RunBase
{
TransDate fromDate,toDate;
ProjId projId;
Name peroid;
JournalId journalId;
ProjCategoryId projCategoryId;
HcmPersonnelNumberId worker;
DialogField dlgPeriod;
DialogField dlgProjId;
DialogField dlgWorker;
DialogField dlgProjCategoryId;
#define.CurrentVersion(1)
#localmacro.CurrentList
peroid,
projId,
worker,
projCategoryId
#endmacro
}
.................................................................................
protected Object dialog()
{
Dialog dialog;
FormStringControl control,controlPeriodName;
dialog = super();
dialog.caption('Generate Journal lines');
dlgPeriod = dialog.addFieldValue(extendedTypeStr(Name),peroid);
dlgProjId = dialog.addFieldValue(extendedTypeStr(ProjId),projId);
dlgWorker = dialog.addFieldValue(extendedTypeStr(HcmPersonnelNumberId),worker);
dlgProjCategoryId = dialog.addFieldValue(extendedTypeStr(ProjCategoryId),projCategoryId);
control = dlgWorker.control();
controlPeriodName = dlgPeriod.control();
control.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(ALE_GenerareJournalLines,lookupCategoryId), this);
controlPeriodName.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(ALE_GenerareJournalLines,lookupPeriodName), this);
return dialog;
}
......................................................................................
public boolean getFromDialog()
{
boolean ret;
ret = super();
peroid = dlgPeriod.value();
projId = dlgProjId.value();
worker = dlgWorker.value();
projCategoryId = dlgProjCategoryId.value();
return ret;
}
.................................................................................................
public container pack()
{
return [#CurrentVersion,#CurrentList];
}
.......................................................................................................
public boolean unpack(container packedClass)
{
Integer version = conPeek(packedClass,1);
switch (version)
{
case #CurrentVersion :
[version,#CurrentList] = packedClass;
break;
default :
return false;
}
return true;
}
.....................................................................................................
public static void main(Args args)
{
JournalId journalId;
ProjJournalTable projJournalTable;
ALE_GenerareJournalLines generareJournalLines = new ALE_GenerareJournalLines();
projJournalTable = args.record();
journalId = projJournalTable.JournalId;
generareJournalLines.getJournalId(journalId);
if(generareJournalLines.prompt())
{
generareJournalLines.run();
}
}
...................................................................................
public void lookupCategoryId(FormStringControl _control)
{
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(HcmWorker),
_control);
sysTableLookup.addLookupField(fieldNum(HcmWorker, PersonnelNumber));
sysTableLookup.addLookupField(fieldNum(HcmWorker, Person));
// Setup query
queryBuildDataSource = query.addDataSource(tableNum(HcmWorker));
sysTableLookup.parmQuery(query);
// Perform lookup
sysTableLookup.performFormLookup();
}
.........................................................................................
public void lookupPeriodName(FormStringControl _control)
{
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(Ale_PeriodMaster),_control);
sysTableLookup.addLookupField(fieldNum(Ale_PeriodMaster, Name));
queryBuildDataSource = query.addDataSource(tableNum(Ale_PeriodMaster));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
............................................................................................
public void getJournalId(JournalId journalIdB)
{
journalId = journalIdB;
}
.......................................................................................................
public void run()
{
int linescount;
Hours totalHours;
JournalId journalIdLoc;
ALE_STG_AttendanceData attendanceData,attendanceDataLoc,attendanceDataLoc1;
Ale_PeriodMaster periodMaster;
ProjJournalTrans projJournalTrans;
ProjJournalTable projJournalTableLoc,projJournalTableLoc1;
ProjJournalTableData projJournalTableData;
ProjJournalTransData projJournalTransData;
TransDate periodFromDate,periodToDate;
select StartDate,Enddate from periodMaster where periodMaster.Name == peroid;
periodFromDate = periodMaster.StartDate;
periodToDate = periodMaster.Enddate;
journalIdLoc = journalId;
ttsBegin;
projJournalTableLoc = ProjJournalTable::find(journalIdLoc);
if(projId && peroid && projCategoryId == "" && worker == "" )
{
projJournalTableData = JournalTableData::newTable(projJournalTableLoc);
projJournalTransData = projJournalTableData.journalStatic().newJournalTransData(projJournalTrans,projJournalTableData);
while select attendanceData group by EmployeeID,ProjectId where attendanceData.ProjectId == projId
&& attendanceData.AttendanceDate >= periodFromDate
&& attendanceData.AttendanceDate <= periodToDate
{
select sum(Hours) from attendanceDataLoc where attendanceDataLoc.ProjectId == attendanceData.ProjectId
&& attendanceDataLoc.EmployeeID == attendanceData.EmployeeID
&& attendanceDataLoc.AttendanceDate >= periodFromDate
&& attendanceDataLoc.AttendanceDate <= periodToDate;//&& attendanceDataLoc.CategoryId == attendanceData.CategoryId
select EmployeeID,CategoryId from attendanceDataLoc1 where attendanceDataLoc1.ProjectId == attendanceData.ProjectId
&& attendanceDataLoc1.EmployeeID == attendanceData.EmployeeID
&& attendanceDataLoc1.AttendanceDate >= periodFromDate
&& attendanceDataLoc1.AttendanceDate <= periodToDate;
projJournalTrans.JournalId = journalIdLoc;
projJournalTrans.initValue();
projJournalTrans.ProjId = projId;
projJournalTrans.initFromProjTable( ProjTable::find(projId));
projJournalTrans.TransDate = systemDateGet();
projJournalTrans.LinePropertyId = 'CHRG';
projJournalTrans.ProjTransDate = projJournalTrans.TransDate;
projJournalTrans.CategoryId = attendanceDataLoc1.CategoryId;
projJournalTrans.TaxItemGroupId = ProjCategory::find(projCategoryId).TaxItemGroupId;
projJournalTrans.Worker = HcmWorker::findByPersonnelNumber(attendanceDataLoc1.EmployeeID).RecId;//HcmWorker::findByPersonnelNumber(worker).RecId;
projJournalTrans.Txt = 'Create hours journal';
projJournalTrans.Qty = attendanceDataLoc.Hours;
projJournalTrans.setHourCostPrice();
projJournalTrans.setHourSalesPrice();
linescount++;
totalHours += attendanceDataLoc.Hours;
projJournalTransData.create();
//projJournalTrans.insert();
}
}
select forUpdate projJournalTableLoc1 where projJournalTableLoc1.JournalId == journalIdLoc;
projJournalTableLoc1.ProjQty = projJournalTableLoc.ProjQty ;
projJournalTableLoc1.NumOfLines = projJournalTableLoc.NumOfLines ;
projJournalTableLoc1.update();
ttsCommit;
info(strFmt('%1 Journal lines has been created',linescount));
}
public class ALE_GenerareJournalLines extends RunBase
{
TransDate fromDate,toDate;
ProjId projId;
Name peroid;
JournalId journalId;
ProjCategoryId projCategoryId;
HcmPersonnelNumberId worker;
DialogField dlgPeriod;
DialogField dlgProjId;
DialogField dlgWorker;
DialogField dlgProjCategoryId;
#define.CurrentVersion(1)
#localmacro.CurrentList
peroid,
projId,
worker,
projCategoryId
#endmacro
}
.................................................................................
protected Object dialog()
{
Dialog dialog;
FormStringControl control,controlPeriodName;
dialog = super();
dialog.caption('Generate Journal lines');
dlgPeriod = dialog.addFieldValue(extendedTypeStr(Name),peroid);
dlgProjId = dialog.addFieldValue(extendedTypeStr(ProjId),projId);
dlgWorker = dialog.addFieldValue(extendedTypeStr(HcmPersonnelNumberId),worker);
dlgProjCategoryId = dialog.addFieldValue(extendedTypeStr(ProjCategoryId),projCategoryId);
control = dlgWorker.control();
controlPeriodName = dlgPeriod.control();
control.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(ALE_GenerareJournalLines,lookupCategoryId), this);
controlPeriodName.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(ALE_GenerareJournalLines,lookupPeriodName), this);
return dialog;
}
......................................................................................
public boolean getFromDialog()
{
boolean ret;
ret = super();
peroid = dlgPeriod.value();
projId = dlgProjId.value();
worker = dlgWorker.value();
projCategoryId = dlgProjCategoryId.value();
return ret;
}
.................................................................................................
public container pack()
{
return [#CurrentVersion,#CurrentList];
}
.......................................................................................................
public boolean unpack(container packedClass)
{
Integer version = conPeek(packedClass,1);
switch (version)
{
case #CurrentVersion :
[version,#CurrentList] = packedClass;
break;
default :
return false;
}
return true;
}
.....................................................................................................
public static void main(Args args)
{
JournalId journalId;
ProjJournalTable projJournalTable;
ALE_GenerareJournalLines generareJournalLines = new ALE_GenerareJournalLines();
projJournalTable = args.record();
journalId = projJournalTable.JournalId;
generareJournalLines.getJournalId(journalId);
if(generareJournalLines.prompt())
{
generareJournalLines.run();
}
}
...................................................................................
public void lookupCategoryId(FormStringControl _control)
{
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(HcmWorker),
_control);
sysTableLookup.addLookupField(fieldNum(HcmWorker, PersonnelNumber));
sysTableLookup.addLookupField(fieldNum(HcmWorker, Person));
// Setup query
queryBuildDataSource = query.addDataSource(tableNum(HcmWorker));
sysTableLookup.parmQuery(query);
// Perform lookup
sysTableLookup.performFormLookup();
}
.........................................................................................
public void lookupPeriodName(FormStringControl _control)
{
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(Ale_PeriodMaster),_control);
sysTableLookup.addLookupField(fieldNum(Ale_PeriodMaster, Name));
queryBuildDataSource = query.addDataSource(tableNum(Ale_PeriodMaster));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
............................................................................................
public void getJournalId(JournalId journalIdB)
{
journalId = journalIdB;
}
.......................................................................................................
public void run()
{
int linescount;
Hours totalHours;
JournalId journalIdLoc;
ALE_STG_AttendanceData attendanceData,attendanceDataLoc,attendanceDataLoc1;
Ale_PeriodMaster periodMaster;
ProjJournalTrans projJournalTrans;
ProjJournalTable projJournalTableLoc,projJournalTableLoc1;
ProjJournalTableData projJournalTableData;
ProjJournalTransData projJournalTransData;
TransDate periodFromDate,periodToDate;
select StartDate,Enddate from periodMaster where periodMaster.Name == peroid;
periodFromDate = periodMaster.StartDate;
periodToDate = periodMaster.Enddate;
journalIdLoc = journalId;
ttsBegin;
projJournalTableLoc = ProjJournalTable::find(journalIdLoc);
if(projId && peroid && projCategoryId == "" && worker == "" )
{
projJournalTableData = JournalTableData::newTable(projJournalTableLoc);
projJournalTransData = projJournalTableData.journalStatic().newJournalTransData(projJournalTrans,projJournalTableData);
while select attendanceData group by EmployeeID,ProjectId where attendanceData.ProjectId == projId
&& attendanceData.AttendanceDate >= periodFromDate
&& attendanceData.AttendanceDate <= periodToDate
{
select sum(Hours) from attendanceDataLoc where attendanceDataLoc.ProjectId == attendanceData.ProjectId
&& attendanceDataLoc.EmployeeID == attendanceData.EmployeeID
&& attendanceDataLoc.AttendanceDate >= periodFromDate
&& attendanceDataLoc.AttendanceDate <= periodToDate;//&& attendanceDataLoc.CategoryId == attendanceData.CategoryId
select EmployeeID,CategoryId from attendanceDataLoc1 where attendanceDataLoc1.ProjectId == attendanceData.ProjectId
&& attendanceDataLoc1.EmployeeID == attendanceData.EmployeeID
&& attendanceDataLoc1.AttendanceDate >= periodFromDate
&& attendanceDataLoc1.AttendanceDate <= periodToDate;
projJournalTrans.JournalId = journalIdLoc;
projJournalTrans.initValue();
projJournalTrans.ProjId = projId;
projJournalTrans.initFromProjTable( ProjTable::find(projId));
projJournalTrans.TransDate = systemDateGet();
projJournalTrans.LinePropertyId = 'CHRG';
projJournalTrans.ProjTransDate = projJournalTrans.TransDate;
projJournalTrans.CategoryId = attendanceDataLoc1.CategoryId;
projJournalTrans.TaxItemGroupId = ProjCategory::find(projCategoryId).TaxItemGroupId;
projJournalTrans.Worker = HcmWorker::findByPersonnelNumber(attendanceDataLoc1.EmployeeID).RecId;//HcmWorker::findByPersonnelNumber(worker).RecId;
projJournalTrans.Txt = 'Create hours journal';
projJournalTrans.Qty = attendanceDataLoc.Hours;
projJournalTrans.setHourCostPrice();
projJournalTrans.setHourSalesPrice();
linescount++;
totalHours += attendanceDataLoc.Hours;
projJournalTransData.create();
//projJournalTrans.insert();
}
}
select forUpdate projJournalTableLoc1 where projJournalTableLoc1.JournalId == journalIdLoc;
projJournalTableLoc1.ProjQty = projJournalTableLoc.ProjQty ;
projJournalTableLoc1.NumOfLines = projJournalTableLoc.NumOfLines ;
projJournalTableLoc1.update();
ttsCommit;
info(strFmt('%1 Journal lines has been created',linescount));
}