static void Na_Hcm(Args _args)
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType comtype;
HcmWorker hcmWorker;
HcmEmployment hcmEmployment;
DirPerson dirPerson;
DirPersonName dirPersonName;
CompanyInfo companyInfo;
HcmPersonnelNumberId personnelNumber;
utcDateTime validFrom;
HcmEmploymentType employmentType;
Name firstName, companny;
int insertcount=0;
int row = 1;
Dialog dialog;
DialogField fileName;
dialog = new Dialog();
dialog.caption("Select File");
fileName = dialog.addField(extendedTypeStr(FilenameOpen));
dialog.run();
application = SysExcelApplication::construct();
workbooks = application.workbooks();
try
{
workbooks.open(fileName.value());
}
catch
{
throw error("File cannot be opened");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
do
{
row++;
firstName = cells.item(row, 1).value().bStr();
personnelNumber = cells.item(row, 2).value().bStr();
employmentType = str2enum(employmentType, cells.item(row, 3).value().bStr());
validFrom = DateTimeUtil::newDateTime(cells.item(row, 4).value().date(), 0);
companny = cells.item(row, 5).value().bStr();
try
{
changeCompany(companny)
{
ttsbegin;
select hcmworker where hcmWorker.PersonnelNumber == personnelNumber;
if(!hcmworker)
{
dirPerson.clear();
dirPerson.Name = firstName;
dirPerson.insert();
dirPersonName.clear();
dirPersonName.FirstName = firstName;
dirPersonName.ValidFrom = validFrom;
dirPersonName.ValidTo = DateTimeUtil::maxValue();
dirPersonName.Person = dirPerson.RecId;
dirpersonName.insert();
hcmWorker.clear();
hcmWorker.Person = dirPerson.RecId;
hcmWorker.PersonnelNumber = personnelNumber;
hcmWorker.insert();
hcmEmployment.clear();
hcmEmployment.Worker = hcmWorker.RecId;
hcmEmployment.EmploymentType = employmentType;
hcmEmployment.ValidFrom = validFrom;
hcmEmployment.ValidTo = DateTimeUtil::maxValue();
hcmEmployment.LegalEntity = CompanyInfo::findDataArea(companny).RecId;
hcmEmployment.insert();
info(strFmt('Employee %1 created', hcmWorker.PersonnelNumber));
insertcount++;
}
comtype = cells.item(row+1, 1).value().variantType();
ttsCommit;
}
}
catch(Exception::Error)
{
info(strFmt("Error in row %1", row));
}
}
while(comtype != COMVariantType::VT_EMPTY);
info(strFmt("%1 Record(s) inserted", insertcount));
application.quit();
}
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType comtype;
HcmWorker hcmWorker;
HcmEmployment hcmEmployment;
DirPerson dirPerson;
DirPersonName dirPersonName;
CompanyInfo companyInfo;
HcmPersonnelNumberId personnelNumber;
utcDateTime validFrom;
HcmEmploymentType employmentType;
Name firstName, companny;
int insertcount=0;
int row = 1;
Dialog dialog;
DialogField fileName;
dialog = new Dialog();
dialog.caption("Select File");
fileName = dialog.addField(extendedTypeStr(FilenameOpen));
dialog.run();
application = SysExcelApplication::construct();
workbooks = application.workbooks();
try
{
workbooks.open(fileName.value());
}
catch
{
throw error("File cannot be opened");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
do
{
row++;
firstName = cells.item(row, 1).value().bStr();
personnelNumber = cells.item(row, 2).value().bStr();
employmentType = str2enum(employmentType, cells.item(row, 3).value().bStr());
validFrom = DateTimeUtil::newDateTime(cells.item(row, 4).value().date(), 0);
companny = cells.item(row, 5).value().bStr();
try
{
changeCompany(companny)
{
ttsbegin;
select hcmworker where hcmWorker.PersonnelNumber == personnelNumber;
if(!hcmworker)
{
dirPerson.clear();
dirPerson.Name = firstName;
dirPerson.insert();
dirPersonName.clear();
dirPersonName.FirstName = firstName;
dirPersonName.ValidFrom = validFrom;
dirPersonName.ValidTo = DateTimeUtil::maxValue();
dirPersonName.Person = dirPerson.RecId;
dirpersonName.insert();
hcmWorker.clear();
hcmWorker.Person = dirPerson.RecId;
hcmWorker.PersonnelNumber = personnelNumber;
hcmWorker.insert();
hcmEmployment.clear();
hcmEmployment.Worker = hcmWorker.RecId;
hcmEmployment.EmploymentType = employmentType;
hcmEmployment.ValidFrom = validFrom;
hcmEmployment.ValidTo = DateTimeUtil::maxValue();
hcmEmployment.LegalEntity = CompanyInfo::findDataArea(companny).RecId;
hcmEmployment.insert();
info(strFmt('Employee %1 created', hcmWorker.PersonnelNumber));
insertcount++;
}
comtype = cells.item(row+1, 1).value().variantType();
ttsCommit;
}
}
catch(Exception::Error)
{
info(strFmt("Error in row %1", row));
}
}
while(comtype != COMVariantType::VT_EMPTY);
info(strFmt("%1 Record(s) inserted", insertcount));
application.quit();
}
No comments:
Post a Comment