static void ImportWorkerthruExcel(Args _args)
{
SysExcelApplication xlsApplication;
SysExcelWorkBooks xlsWorkBookCollection;
SysExcelWorkBook xlsWorkBook;
SysExcelWorksheets xlsWorkSheetCollection;
SysExcelWorksheet xlsWorkSheet;
SysExcelRange xlsRange;
SysExcelCells Cells;
SysExcelCell RCell;
CommaIO inFile;
int nRow,i;
DialogField dialogPath;
Dialog dialog;
Filename filename;
Name firstName, LastName;
LegalEntity LegalEntity;
HcmPersonnelNumberId PersonnelNo;
HcmEmploymentType WorkerType;
HcmWorker hcmWorker;
DirPerson dirPerson;
DirPartyTable DirPartyTable;
HcmEmployment HcmEmployment;
DirPersonName DirPersonName;
HcmPersonPrivateDetails HcmPersonPrivateDetails;
HcmPersonIdentificationNumber HcmPersonIdentificationNumber;
// importworker importworker;
NameAlias SearchName;
BirthDate birthdate;
str CountryCode;
str IdentificationNumber;
ExpirationDate ExpireDate;
DirAddressBookPartyAllView DirAddressBookPartyAllView;
HcmPositionDuration HcmPositionDuration;
;
dialog = new Dialog("Import");
dialogPath = dialog.addField(extendedTypeStr(Filenameopen), "File Name");
dialog.run();
if (dialog.run())
{
filename = (dialogPath.value());
}
inFile = new CommaIO (filename, 'R');
if (!inFile || infile.status() != IO_Status::Ok )
{
throw error (strfmt("@SYS19312",filename));
}
try
{
xlsApplication = SysExcelApplication::construct();
xlsWorkBookCollection = xlsApplication.workbooks();
xlsWorkBookCollection.open(filename);
xlsWorkSheetCollection = xlsApplication.worksheets();
xlsWorkSheet = xlsWorkSheetCollection.itemFromNum(1);
Cells = xlsWorkSheet.Cells();
nRow = 2;
RCell = Cells.Item(nRow, 1);
while (RCell.value().bstr() != "")
{
//Name = RCell.value().bStr();
RCell = Cells.item(nRow,2);
SearchName = RCell.value().bStr();
//RCell = Cells.item(nRow,2);
//PersonnelNo = RCell.value().bStr();
RCell = Cells.item(nRow,3);
FirstName = RCell.value().bStr();
RCell = Cells.item(nRow,4);
LastName = RCell.value().bStr();
RCell = Cells.item(nRow,13);
birthdate = str2DateDMY(RCell.value().bStr());
RCell = Cells.item(nRow,5);
CountryCode = RCell.value().bStr();
DirPerson.Name = firstname+" "+LastName;
dirpersonname.FirstName = firstname;
dirpersonname.LastName = LastName;
dirperson.NameAlias = SearchName;
// LogisticsElectronicAddress.Locator = Telephone;
//hcmWorker.Person=dirPerson.RecId;
//exportImportRecords.income = income;
//importworker.insert();
//dirPerson.RecId=DirPartyTable.RecId;
DirPerson.insert();
DirPartyTable.RecId=dirPerson.RecId;
DirPartyTable.insert();
DirPersonName.Person=dirPerson.RecId;
dirpersonname.insert();
hcmWorker.Person=DirAddressBookPartyAllView.Party;
hcmWorker.Person=dirPerson.RecId;
hcmWorker.insert();
// Hcm Employement Table Data
HcmEmployment.EmploymentType = HcmEmploymentType::Employee;
HcmEmployment.LegalEntity = CompanyInfo::find().RecId;
HcmEmployment.ValidFrom = DateTimeUtil::newDateTime(today(), str2time('00:00:00'));
HcmEmployment.ValidTo = DateTimeUtil::maxValue();
HcmEmployment.Worker=hcmWorker.RecId;
HcmEmployment.insert();
// Worker Private Details (HCMPersonPrivateDetails)
HcmPersonPrivateDetails.BirthDate = birthdate;
HcmPersonPrivateDetails.CitizenshipCountryRegion = CountryCode;
HcmPersonPrivateDetails.Person = dirPerson.RecId;
HcmPersonPrivateDetails.insert();
// Worker Identification Numbers
RCell = Cells.item(nRow,11);
if(RCell.value().bStr() != "")
{
HcmPersonIdentificationNumber.IdentificationNumber = RCell.value().bStr();
RCell = Cells.item(nRow,12);
HcmPersonIdentificationNumber.ExpirationDate = str2DateDMY(RCell.value().bStr());
HcmPersonIdentificationNumber.Description = "Ikama Number";
HcmPersonIdentificationNumber.Person = dirPerson.RecId;
HcmPersonIdentificationNumber.IdentificationType = 5637145329;
HcmPersonIdentificationNumber.insert();
}
RCell = Cells.item(nRow,14);
if(RCell.value().bStr() != "")
{
HcmPersonIdentificationNumber.IdentificationNumber = RCell.value().bStr();
RCell = Cells.item(nRow,15);
HcmPersonIdentificationNumber.ExpirationDate = str2DateDMY(RCell.value().bStr());
HcmPersonIdentificationNumber.Description = "Passport Number";
HcmPersonIdentificationNumber.Person = dirPerson.RecId;
HcmPersonIdentificationNumber.IdentificationType = 5637145328;
HcmPersonIdentificationNumber.insert();
}
nRow++;
RCell = Cells.Item(nRow, 1);
}
xlsApplication.quit ();
xlsApplication.finalize ();
info("Import completed");
}
catch( Exception::Error)
{
xlsApplication.quit ();
xlsApplication.finalize ();
ttsabort;
info("Unable to process the excel import ");
}
}
{
SysExcelApplication xlsApplication;
SysExcelWorkBooks xlsWorkBookCollection;
SysExcelWorkBook xlsWorkBook;
SysExcelWorksheets xlsWorkSheetCollection;
SysExcelWorksheet xlsWorkSheet;
SysExcelRange xlsRange;
SysExcelCells Cells;
SysExcelCell RCell;
CommaIO inFile;
int nRow,i;
DialogField dialogPath;
Dialog dialog;
Filename filename;
Name firstName, LastName;
LegalEntity LegalEntity;
HcmPersonnelNumberId PersonnelNo;
HcmEmploymentType WorkerType;
HcmWorker hcmWorker;
DirPerson dirPerson;
DirPartyTable DirPartyTable;
HcmEmployment HcmEmployment;
DirPersonName DirPersonName;
HcmPersonPrivateDetails HcmPersonPrivateDetails;
HcmPersonIdentificationNumber HcmPersonIdentificationNumber;
// importworker importworker;
NameAlias SearchName;
BirthDate birthdate;
str CountryCode;
str IdentificationNumber;
ExpirationDate ExpireDate;
DirAddressBookPartyAllView DirAddressBookPartyAllView;
HcmPositionDuration HcmPositionDuration;
;
dialog = new Dialog("Import");
dialogPath = dialog.addField(extendedTypeStr(Filenameopen), "File Name");
dialog.run();
if (dialog.run())
{
filename = (dialogPath.value());
}
inFile = new CommaIO (filename, 'R');
if (!inFile || infile.status() != IO_Status::Ok )
{
throw error (strfmt("@SYS19312",filename));
}
try
{
xlsApplication = SysExcelApplication::construct();
xlsWorkBookCollection = xlsApplication.workbooks();
xlsWorkBookCollection.open(filename);
xlsWorkSheetCollection = xlsApplication.worksheets();
xlsWorkSheet = xlsWorkSheetCollection.itemFromNum(1);
Cells = xlsWorkSheet.Cells();
nRow = 2;
RCell = Cells.Item(nRow, 1);
while (RCell.value().bstr() != "")
{
//Name = RCell.value().bStr();
RCell = Cells.item(nRow,2);
SearchName = RCell.value().bStr();
//RCell = Cells.item(nRow,2);
//PersonnelNo = RCell.value().bStr();
RCell = Cells.item(nRow,3);
FirstName = RCell.value().bStr();
RCell = Cells.item(nRow,4);
LastName = RCell.value().bStr();
RCell = Cells.item(nRow,13);
birthdate = str2DateDMY(RCell.value().bStr());
RCell = Cells.item(nRow,5);
CountryCode = RCell.value().bStr();
DirPerson.Name = firstname+" "+LastName;
dirpersonname.FirstName = firstname;
dirpersonname.LastName = LastName;
dirperson.NameAlias = SearchName;
// LogisticsElectronicAddress.Locator = Telephone;
//hcmWorker.Person=dirPerson.RecId;
//exportImportRecords.income = income;
//importworker.insert();
//dirPerson.RecId=DirPartyTable.RecId;
DirPerson.insert();
DirPartyTable.RecId=dirPerson.RecId;
DirPartyTable.insert();
DirPersonName.Person=dirPerson.RecId;
dirpersonname.insert();
hcmWorker.Person=DirAddressBookPartyAllView.Party;
hcmWorker.Person=dirPerson.RecId;
hcmWorker.insert();
// Hcm Employement Table Data
HcmEmployment.EmploymentType = HcmEmploymentType::Employee;
HcmEmployment.LegalEntity = CompanyInfo::find().RecId;
HcmEmployment.ValidFrom = DateTimeUtil::newDateTime(today(), str2time('00:00:00'));
HcmEmployment.ValidTo = DateTimeUtil::maxValue();
HcmEmployment.Worker=hcmWorker.RecId;
HcmEmployment.insert();
// Worker Private Details (HCMPersonPrivateDetails)
HcmPersonPrivateDetails.BirthDate = birthdate;
HcmPersonPrivateDetails.CitizenshipCountryRegion = CountryCode;
HcmPersonPrivateDetails.Person = dirPerson.RecId;
HcmPersonPrivateDetails.insert();
// Worker Identification Numbers
RCell = Cells.item(nRow,11);
if(RCell.value().bStr() != "")
{
HcmPersonIdentificationNumber.IdentificationNumber = RCell.value().bStr();
RCell = Cells.item(nRow,12);
HcmPersonIdentificationNumber.ExpirationDate = str2DateDMY(RCell.value().bStr());
HcmPersonIdentificationNumber.Description = "Ikama Number";
HcmPersonIdentificationNumber.Person = dirPerson.RecId;
HcmPersonIdentificationNumber.IdentificationType = 5637145329;
HcmPersonIdentificationNumber.insert();
}
RCell = Cells.item(nRow,14);
if(RCell.value().bStr() != "")
{
HcmPersonIdentificationNumber.IdentificationNumber = RCell.value().bStr();
RCell = Cells.item(nRow,15);
HcmPersonIdentificationNumber.ExpirationDate = str2DateDMY(RCell.value().bStr());
HcmPersonIdentificationNumber.Description = "Passport Number";
HcmPersonIdentificationNumber.Person = dirPerson.RecId;
HcmPersonIdentificationNumber.IdentificationType = 5637145328;
HcmPersonIdentificationNumber.insert();
}
nRow++;
RCell = Cells.Item(nRow, 1);
}
xlsApplication.quit ();
xlsApplication.finalize ();
info("Import completed");
}
catch( Exception::Error)
{
xlsApplication.quit ();
xlsApplication.finalize ();
ttsabort;
info("Unable to process the excel import ");
}
}
No comments:
Post a Comment