static void Test_NumberSeqTableRef(Args _args)
{
NumberSequenceTable _nst;
NumberSequenceReference _nsr;
NumberSequenceDataType _nsd;
;
while select _nst
order by _nst.NumberSequence
join _nsr
where _nst.RecId == _nsr.NumberSequenceId
join _nsd
where _nsd.RecId == _nsr.NumberSequenceDatatype
&& _nst.Txt like 'AAA *'
{
info(strFmt('%1 ; %2 ; %3 ; %4 ; %5 ; %6',_nst.NumberSequence,_nst.Txt,_nst.Format,_nst.Highest,
_nsd.referenceLabelForDisplay(), _nsd.referenceModuleLabel() ));
}
}
Friday, April 22, 2016
Thursday, April 21, 2016
Class to Create Item Group include Main Account in AX 2012 R3
CreateInventGroup::Create(itemGroupx,itemGroupNamex,inventoryAccx,expenseAccx,revenueAccx,interUnitAccx);
==============
class CreateInventGroup
{
}
public static void Create(
ItemGroupId _itemGroupId,
Name _itemGroupName,
MainAccountNum _inventoryAcc,
MainAccountNum _expenseyAcc,
MainAccountNum _revenueAcc,
MainAccountNum _interUnitAcc,
MainAccountNum _wipAcc=''
)
{
InventPosting _inventPosting;
InventItemGroup _itemGroup0,_itemGroup;
InventItemGroupForm _itemGroupForm;
InventAccountType inventAcctTypeEnum;
InventPostingItemCode inventItemCodeEnum;
container conCOAInventory,conCOAExpense,conCOARevenue,conCOAInterunit,conCOAWIP;
ItemGroupId itemGroupx;
Name itemGroupNamex,invttypex;
MainAccountNum inventoryAccx,expenseAccx,revenueAccx,interUnitAccx,wipAccx;
int i,counterx;
;
itemGroupx = _itemGroupId;
itemGroupNamex = _itemGroupName;
inventoryAccx = _inventoryAcc;
expenseAccx = _expenseyAcc;
revenueAccx = _revenueAcc;
interUnitAccx = _interUnitAcc;
wipAccx = _wipAcc;
conCOAInventory = ['Inventory, issue',
'Inventory, receipt',
'Product receipt',
'Production, issue',
'Production, picking list',
'Production, receipt',
'Production, report as finished',
'Purchase, inventory receipt',
'Sales order, issue',
'Order, packing slip'];
conCOAExpense = ['Inventory, loss',
'Inventory, profit',
'Purchase expenditure for expense',
'Purchase expenditure for product',
'Sales order, consumption',
'Sales, packing slip offset'];
conCOARevenue = ['Sales order, revenue'];
conCOAInterunit = ['Inventory inter-unit payable','Inventory inter-unit receivable'];
conCOAWIP = [ 'Production, issue offset',
'Production, picking list offset',
'Production, receipt offset',
'Production, report as finished offset'];
_itemGroup0 = InventItemGroup::find(itemGroupx);
if(!_itemGroup0)
{
ttsBegin;
_itemGroup.clear();
_itemGroup.ItemGroupId = itemGroupx;
_itemGroup.Name = itemGroupNamex;
_itemGroup.validateWrite();
_itemGroup.insert();
ttsCommit;
if(inventoryAccx)
{
for (i=1; i <= conLen(conCOAInventory); i++)
{
invttypex = conPeek(conCOAInventory, i);
ttsBegin;
_inventPosting.clear();
_inventPosting.initValue();
_inventPosting.InventAccountType = str2enum(inventAcctTypeEnum,invttypex);
_inventPosting.ItemCode = str2enum(inventItemCodeEnum,'Group');
_inventPosting.ItemRelation = itemGroupx;
_inventPosting.CustVendCode = TableGroupAll::All;
_inventPosting.LedgerDimension = DimensionStorage::getDefaultAccountForMainAccountNum(inventoryAccx);
_inventPosting.validateWrite();
_inventPosting.insert();
ttsCommit;
DIP_CreateInventGroup::CreateUpdateGroupForm(itemGroupx,_inventPosting.LedgerDimension,invttypex);
}//for
}// if(inventoryAccx)
if(expenseAccx)
{
for (i=1; i <= conLen(conCOAExpense); i++)
{
invttypex = conPeek(conCOAExpense, i);
ttsBegin;
_inventPosting.clear();
_inventPosting.initValue();
_inventPosting.InventAccountType = str2enum(inventAcctTypeEnum,invttypex);
_inventPosting.ItemCode = str2enum(inventItemCodeEnum,'Group');
_inventPosting.ItemRelation = itemGroupx;
_inventPosting.CustVendCode = TableGroupAll::All;
_inventPosting.LedgerDimension = DimensionStorage::getDefaultAccountForMainAccountNum(expenseAccx);
_inventPosting.validateWrite();
_inventPosting.insert();
ttsCommit;
DIP_CreateInventGroup::CreateUpdateGroupForm(itemGroupx,_inventPosting.LedgerDimension,invttypex);
}//for
}// if(expenseAccx)
if(revenueAccx)
{
for (i=1; i <= conLen(conCOARevenue); i++)
{
invttypex = conPeek(conCOARevenue, i);
ttsBegin;
_inventPosting.clear();
_inventPosting.initValue();
_inventPosting.InventAccountType = str2enum(inventAcctTypeEnum,invttypex);
_inventPosting.ItemCode = str2enum(inventItemCodeEnum,'Group');
_inventPosting.ItemRelation = itemGroupx;
_inventPosting.CustVendCode = TableGroupAll::All;
_inventPosting.LedgerDimension = DimensionStorage::getDefaultAccountForMainAccountNum(revenueAccx);
_inventPosting.validateWrite();
_inventPosting.insert();
ttsCommit;
DIP_CreateInventGroup::CreateUpdateGroupForm(itemGroupx,_inventPosting.LedgerDimension,invttypex);
}//for
}// if(revenueAccx)
if(interUnitAccx)
{
for (i=1; i <= conLen(conCOAInterunit); i++)
{
invttypex = conPeek(conCOAInterunit, i);
ttsBegin;
_inventPosting.clear();
_inventPosting.initValue();
_inventPosting.InventAccountType = str2enum(inventAcctTypeEnum,invttypex);
_inventPosting.ItemCode = str2enum(inventItemCodeEnum,'Group');
_inventPosting.ItemRelation = itemGroupx;
_inventPosting.CustVendCode = TableGroupAll::All;
_inventPosting.LedgerDimension = DimensionStorage::getDefaultAccountForMainAccountNum(interUnitAccx);
_inventPosting.validateWrite();
_inventPosting.insert();
ttsCommit;
DIP_CreateInventGroup::CreateUpdateGroupForm(itemGroupx,_inventPosting.LedgerDimension,invttypex);
}//for
}// if(interUnitAccx)
if(wipAccx)
{
for (i=1; i <= conLen(conCOAWIP); i++)
{
invttypex = conPeek(conCOAWIP, i);
ttsBegin;
_inventPosting.clear();
_inventPosting.initValue();
_inventPosting.InventAccountType = str2enum(inventAcctTypeEnum,invttypex);
_inventPosting.ItemCode = str2enum(inventItemCodeEnum,'Group');
_inventPosting.ItemRelation = itemGroupx;
_inventPosting.CustVendCode = TableGroupAll::All;
_inventPosting.LedgerDimension = DimensionStorage::getDefaultAccountForMainAccountNum(wipAccx);
_inventPosting.validateWrite();
_inventPosting.insert();
ttsCommit;
DIP_CreateInventGroup::CreateUpdateGroupForm(itemGroupx,_inventPosting.LedgerDimension,invttypex);
}//for
}// if(interUnitAccx)
} //if(!_itemGroup0)
}
public static void CreateUpdateGroupForm(
ItemGroupId _itemGroupIdx,
LedgerDimensionDefaultAccount _ledgerDimDefaultx,
Name _inventAcctTypex
)
{
InventItemGroupForm _itemGroupForm,_itemGroupForm1;
InventAccountType inventAcctTypeEnum;
ItemGroupLedgerDimensionGroup itemGroupDimGroup;
;
select * from _itemGroupForm
where _itemGroupForm.ItemGroupId == _itemGroupIdx
&& _itemGroupForm.InventAccountType == str2enum(inventAcctTypeEnum,_inventAcctTypex);
switch(_inventAcctTypex)
{
Case 'Inventory, issue',
'Inventory, receipt',
'Inventory, loss',
'Inventory, profit',
'Inventory inter-unit payable',
'Inventory inter-unit receivable':
itemGroupDimGroup = ItemGroupLedgerDimensionGroup::Inventory;
break;
Case 'Production, issue',
'Production, picking list',
'Production, receipt',
'Production, report as finished',
'Production, issue offset',
'Production, picking list offset',
'Production, receipt offset',
'Production, report as finished offset':
itemGroupDimGroup = ItemGroupLedgerDimensionGroup::Production;
break;
Case 'Sales order, issue',
'Order, packing slip',
'Sales order, consumption',
'Sales, packing slip offset',
'Sales order, revenue':
itemGroupDimGroup = ItemGroupLedgerDimensionGroup::Sales;
break;
Case 'Purchase, inventory receipt',
'Product receipt',
'Purchase expenditure for expense',
'Purchase expenditure for product':
itemGroupDimGroup = ItemGroupLedgerDimensionGroup::Purchase;
break;
}//switch
if(!_itemGroupForm)
{
ttsBegin;
_itemGroupForm.clear();
_itemGroupForm.initValue();
_itemGroupForm.InventAccountType = str2enum(inventAcctTypeEnum,_inventAcctTypex);
_itemGroupForm.ItemGroupId = _itemGroupIdx;
_itemGroupForm.LedgerDimension = _ledgerDimDefaultx;
_itemGroupForm.LedgerDimensionGroup = itemGroupDimGroup;
_itemGroupForm.validateWrite();
_itemGroupForm.insert();
ttsCommit;
}
else
{
while select forupdate _itemGroupForm1
where _itemGroupForm1.ItemGroupId == _itemGroupIdx
&& _itemGroupForm1.InventAccountType == str2enum(inventAcctTypeEnum,_inventAcctTypex)
{
ttsBegin;
_itemGroupForm1.LedgerDimension = _ledgerDimDefaultx;
_itemGroupForm1.LedgerDimensionGroup = itemGroupDimGroup;
_itemGroupForm1.validateWrite();
_itemGroupForm1.update();
ttsCommit;
}
}
}
==============
class CreateInventGroup
{
}
public static void Create(
ItemGroupId _itemGroupId,
Name _itemGroupName,
MainAccountNum _inventoryAcc,
MainAccountNum _expenseyAcc,
MainAccountNum _revenueAcc,
MainAccountNum _interUnitAcc,
MainAccountNum _wipAcc=''
)
{
InventPosting _inventPosting;
InventItemGroup _itemGroup0,_itemGroup;
InventItemGroupForm _itemGroupForm;
InventAccountType inventAcctTypeEnum;
InventPostingItemCode inventItemCodeEnum;
container conCOAInventory,conCOAExpense,conCOARevenue,conCOAInterunit,conCOAWIP;
ItemGroupId itemGroupx;
Name itemGroupNamex,invttypex;
MainAccountNum inventoryAccx,expenseAccx,revenueAccx,interUnitAccx,wipAccx;
int i,counterx;
;
itemGroupx = _itemGroupId;
itemGroupNamex = _itemGroupName;
inventoryAccx = _inventoryAcc;
expenseAccx = _expenseyAcc;
revenueAccx = _revenueAcc;
interUnitAccx = _interUnitAcc;
wipAccx = _wipAcc;
conCOAInventory = ['Inventory, issue',
'Inventory, receipt',
'Product receipt',
'Production, issue',
'Production, picking list',
'Production, receipt',
'Production, report as finished',
'Purchase, inventory receipt',
'Sales order, issue',
'Order, packing slip'];
conCOAExpense = ['Inventory, loss',
'Inventory, profit',
'Purchase expenditure for expense',
'Purchase expenditure for product',
'Sales order, consumption',
'Sales, packing slip offset'];
conCOARevenue = ['Sales order, revenue'];
conCOAInterunit = ['Inventory inter-unit payable','Inventory inter-unit receivable'];
conCOAWIP = [ 'Production, issue offset',
'Production, picking list offset',
'Production, receipt offset',
'Production, report as finished offset'];
_itemGroup0 = InventItemGroup::find(itemGroupx);
if(!_itemGroup0)
{
ttsBegin;
_itemGroup.clear();
_itemGroup.ItemGroupId = itemGroupx;
_itemGroup.Name = itemGroupNamex;
_itemGroup.validateWrite();
_itemGroup.insert();
ttsCommit;
if(inventoryAccx)
{
for (i=1; i <= conLen(conCOAInventory); i++)
{
invttypex = conPeek(conCOAInventory, i);
ttsBegin;
_inventPosting.clear();
_inventPosting.initValue();
_inventPosting.InventAccountType = str2enum(inventAcctTypeEnum,invttypex);
_inventPosting.ItemCode = str2enum(inventItemCodeEnum,'Group');
_inventPosting.ItemRelation = itemGroupx;
_inventPosting.CustVendCode = TableGroupAll::All;
_inventPosting.LedgerDimension = DimensionStorage::getDefaultAccountForMainAccountNum(inventoryAccx);
_inventPosting.validateWrite();
_inventPosting.insert();
ttsCommit;
DIP_CreateInventGroup::CreateUpdateGroupForm(itemGroupx,_inventPosting.LedgerDimension,invttypex);
}//for
}// if(inventoryAccx)
if(expenseAccx)
{
for (i=1; i <= conLen(conCOAExpense); i++)
{
invttypex = conPeek(conCOAExpense, i);
ttsBegin;
_inventPosting.clear();
_inventPosting.initValue();
_inventPosting.InventAccountType = str2enum(inventAcctTypeEnum,invttypex);
_inventPosting.ItemCode = str2enum(inventItemCodeEnum,'Group');
_inventPosting.ItemRelation = itemGroupx;
_inventPosting.CustVendCode = TableGroupAll::All;
_inventPosting.LedgerDimension = DimensionStorage::getDefaultAccountForMainAccountNum(expenseAccx);
_inventPosting.validateWrite();
_inventPosting.insert();
ttsCommit;
DIP_CreateInventGroup::CreateUpdateGroupForm(itemGroupx,_inventPosting.LedgerDimension,invttypex);
}//for
}// if(expenseAccx)
if(revenueAccx)
{
for (i=1; i <= conLen(conCOARevenue); i++)
{
invttypex = conPeek(conCOARevenue, i);
ttsBegin;
_inventPosting.clear();
_inventPosting.initValue();
_inventPosting.InventAccountType = str2enum(inventAcctTypeEnum,invttypex);
_inventPosting.ItemCode = str2enum(inventItemCodeEnum,'Group');
_inventPosting.ItemRelation = itemGroupx;
_inventPosting.CustVendCode = TableGroupAll::All;
_inventPosting.LedgerDimension = DimensionStorage::getDefaultAccountForMainAccountNum(revenueAccx);
_inventPosting.validateWrite();
_inventPosting.insert();
ttsCommit;
DIP_CreateInventGroup::CreateUpdateGroupForm(itemGroupx,_inventPosting.LedgerDimension,invttypex);
}//for
}// if(revenueAccx)
if(interUnitAccx)
{
for (i=1; i <= conLen(conCOAInterunit); i++)
{
invttypex = conPeek(conCOAInterunit, i);
ttsBegin;
_inventPosting.clear();
_inventPosting.initValue();
_inventPosting.InventAccountType = str2enum(inventAcctTypeEnum,invttypex);
_inventPosting.ItemCode = str2enum(inventItemCodeEnum,'Group');
_inventPosting.ItemRelation = itemGroupx;
_inventPosting.CustVendCode = TableGroupAll::All;
_inventPosting.LedgerDimension = DimensionStorage::getDefaultAccountForMainAccountNum(interUnitAccx);
_inventPosting.validateWrite();
_inventPosting.insert();
ttsCommit;
DIP_CreateInventGroup::CreateUpdateGroupForm(itemGroupx,_inventPosting.LedgerDimension,invttypex);
}//for
}// if(interUnitAccx)
if(wipAccx)
{
for (i=1; i <= conLen(conCOAWIP); i++)
{
invttypex = conPeek(conCOAWIP, i);
ttsBegin;
_inventPosting.clear();
_inventPosting.initValue();
_inventPosting.InventAccountType = str2enum(inventAcctTypeEnum,invttypex);
_inventPosting.ItemCode = str2enum(inventItemCodeEnum,'Group');
_inventPosting.ItemRelation = itemGroupx;
_inventPosting.CustVendCode = TableGroupAll::All;
_inventPosting.LedgerDimension = DimensionStorage::getDefaultAccountForMainAccountNum(wipAccx);
_inventPosting.validateWrite();
_inventPosting.insert();
ttsCommit;
DIP_CreateInventGroup::CreateUpdateGroupForm(itemGroupx,_inventPosting.LedgerDimension,invttypex);
}//for
}// if(interUnitAccx)
} //if(!_itemGroup0)
}
public static void CreateUpdateGroupForm(
ItemGroupId _itemGroupIdx,
LedgerDimensionDefaultAccount _ledgerDimDefaultx,
Name _inventAcctTypex
)
{
InventItemGroupForm _itemGroupForm,_itemGroupForm1;
InventAccountType inventAcctTypeEnum;
ItemGroupLedgerDimensionGroup itemGroupDimGroup;
;
select * from _itemGroupForm
where _itemGroupForm.ItemGroupId == _itemGroupIdx
&& _itemGroupForm.InventAccountType == str2enum(inventAcctTypeEnum,_inventAcctTypex);
switch(_inventAcctTypex)
{
Case 'Inventory, issue',
'Inventory, receipt',
'Inventory, loss',
'Inventory, profit',
'Inventory inter-unit payable',
'Inventory inter-unit receivable':
itemGroupDimGroup = ItemGroupLedgerDimensionGroup::Inventory;
break;
Case 'Production, issue',
'Production, picking list',
'Production, receipt',
'Production, report as finished',
'Production, issue offset',
'Production, picking list offset',
'Production, receipt offset',
'Production, report as finished offset':
itemGroupDimGroup = ItemGroupLedgerDimensionGroup::Production;
break;
Case 'Sales order, issue',
'Order, packing slip',
'Sales order, consumption',
'Sales, packing slip offset',
'Sales order, revenue':
itemGroupDimGroup = ItemGroupLedgerDimensionGroup::Sales;
break;
Case 'Purchase, inventory receipt',
'Product receipt',
'Purchase expenditure for expense',
'Purchase expenditure for product':
itemGroupDimGroup = ItemGroupLedgerDimensionGroup::Purchase;
break;
}//switch
if(!_itemGroupForm)
{
ttsBegin;
_itemGroupForm.clear();
_itemGroupForm.initValue();
_itemGroupForm.InventAccountType = str2enum(inventAcctTypeEnum,_inventAcctTypex);
_itemGroupForm.ItemGroupId = _itemGroupIdx;
_itemGroupForm.LedgerDimension = _ledgerDimDefaultx;
_itemGroupForm.LedgerDimensionGroup = itemGroupDimGroup;
_itemGroupForm.validateWrite();
_itemGroupForm.insert();
ttsCommit;
}
else
{
while select forupdate _itemGroupForm1
where _itemGroupForm1.ItemGroupId == _itemGroupIdx
&& _itemGroupForm1.InventAccountType == str2enum(inventAcctTypeEnum,_inventAcctTypex)
{
ttsBegin;
_itemGroupForm1.LedgerDimension = _ledgerDimDefaultx;
_itemGroupForm1.LedgerDimensionGroup = itemGroupDimGroup;
_itemGroupForm1.validateWrite();
_itemGroupForm1.update();
ttsCommit;
}
}
}
Wednesday, January 6, 2016
Can not rename InventTable in AX 2012 R3
"You cannot rename the record because the table (InventTable) has a distribution type Same as parent distribution and not No distribution."
Solution:
Step-1
Menu: Retail > Setup > Parameters > Retail scheduler parameters

Step-2
Menu: Retail > Setup > Retail scheduler > Scheduler subjob

Remove and Add it back.
Solution:
Step-1
Menu: Retail > Setup > Parameters > Retail scheduler parameters
Step-2
Menu: Retail > Setup > Retail scheduler > Scheduler subjob
Remove and Add it back.
Wednesday, December 23, 2015
Ms Excel macro to create txt file
Macro to create txt file (flat file). You could change separator as you need.
Txt creator
Here is the code:
Sub CreateTXT()
Dim rCell As Range
Dim rRow As Range
Dim sOutput As String
Dim sFname As String, lFnum As Long
'Open a text file to write
sFname = "C:\AX\" & ActiveSheet.Name & ".txt"
lFnum = FreeFile
Open sFname For Output As lFnum
'Loop through the rows'
For Each rRow In ActiveSheet.UsedRange.Rows
'Loop through the cells in the rows'
For Each rCell In rRow.Cells
sOutput = sOutput & rCell.Value & ";" 'SEPARATOR !!!
Next rCell
'remove the last comma'
sOutput = Left(sOutput, Len(sOutput) - 1)
'write to the file and reinitialize the variables'
Print #lFnum, sOutput
sOutput = ""
Next rRow
'Close the file'
Close lFnum
End Sub
Txt creator
Here is the code:
Sub CreateTXT()
Dim rCell As Range
Dim rRow As Range
Dim sOutput As String
Dim sFname As String, lFnum As Long
'Open a text file to write
sFname = "C:\AX\" & ActiveSheet.Name & ".txt"
lFnum = FreeFile
Open sFname For Output As lFnum
'Loop through the rows'
For Each rRow In ActiveSheet.UsedRange.Rows
'Loop through the cells in the rows'
For Each rCell In rRow.Cells
sOutput = sOutput & rCell.Value & ";" 'SEPARATOR !!!
Next rCell
'remove the last comma'
sOutput = Left(sOutput, Len(sOutput) - 1)
'write to the file and reinitialize the variables'
Print #lFnum, sOutput
sOutput = ""
Next rRow
'Close the file'
Close lFnum
End Sub
Job for Insert or Update Worker in AX 2012 R3
You should already have Payroll Position Master. And be carefull with date validation in most of HCM and Payroll tables related.
static void Import_Worker_InsertUpdate(Args _args)
{
RecId workerRecId,hcmEmploymentRecId;
HcmPersonnelNumberId personnumx;
date datehiringx,datebirthx;
str 20 namefirtsx,namemidx,namelastx,initialx,educationx,subeducationx;
str 20 bankx,bankaccx,npx,levelx,updatedatax;
str 1 genderx;
HcmPersonGender hcmgenderEnum;
Gender genderEnum;
Dialog dialog;
DialogField dialogField,dialogField2,dialogdate,dialogField3,dialogField4;
Filename filename,filenamex;
str 60 oldnumx,newnumx,cityx,namex,positionx;
str 100 addressx;
TextIO io;
Container con;
Container filterCriteria;
COMVariant cOMVariant;
int i,j,k;
SysOperationProgress simpleProgress;
Numberseq numberseq;
Filename filepathz;
Filename filenamez;
Filename fileTypez;
str fileNameString;
CommaTextIo file;
boolean ret = true;
CompanyInfo companyInfo;
HcmEmploymentRecId newEmploymentRecId;
ValidFromDateTime employmentStartDateTime;
ValidToDateTime employmentEndDateTime;
DirPerson _dirPerson;
DirPersonName _dirPersonName;
DirPartyTable _dirPartyTable;
DirPartyLocation _dirPartyLocation;
HcmEmploymentType hcmEmploymentType = HcmEmploymentType::Employee;
NumberSeq numberSeqPersonnelNum;
AxLogisticsPostalAddress axLogisticsPostalAddress = new AxLogisticsPostalAddress();
AxLogisticsLocation axLogisticsLocation;
LogisticsPostalAddress logisticsPostalAddress_Default,_logisticsPostalAddress;
HcmWorker newHcmWorker,_hcmWorker;
HcmPersonPrivateDetails _hcmPersonPrivateDetails0,_hcmPersonPrivateDetails;
HcmPersonEducation _hcmPersonEducation;
HcmWorkerBankAccount _hcmWorkerBankAccount;
HcmEmploymentEmployee _hcmEmploymentEmployee,_hcmEmploymentEmployee0;
HcmPositionDetail _hcmPositionDetail;
HcmEmployment _hcmEmployment,_hcmEmployment2;
HcmPositionWorkerAssignment _hcmPositionWorkerAssignment,_hcmPositionWorkerAssignment2;
HcmPersonLaborUnion _hcmPersonLaborUnion;
HcmPositionUnionAgreement _hcmPositionUnionAgreement;
#avifiles
;
Dialog = new Dialog("Import insert and update worker ("+curext()+")");
dialogField = dialog.addField(ExtendedTypeStr("FilenameOpen"));
filterCriteria = ['*.txt','*.txt'];// To filter only TXT files
filterCriteria = dialog.filenameLookupFilter(filterCriteria);
dialog.run();
if(dialog.run())
fileName = dialogField.value();
if(!fileName)
{
Error('File is not selected. Process cancelled!');
return;
}
filenamex = filename;
[filepathz, filenamez, fileTypez] = fileNameSplit(filenamex);
fileNameString= filenamez + fileTypez;
try //#1
{
if(dialog.run()) //#2
{
file = new CommaTextIo(dialogField.value(), 'r');
file.inFieldDelimiter(';');
j=0;
k=0;
while((file.status()==IO_Status::Ok)) //#3
{
con = file.read();
//info(int2str(conlen(con)));
if (conlen(con) == 19) //#4
{
//*** GetValue
personnumx = conPeek(con, 1);
datehiringx = str2Date(conPeek(con, 2),123);
namefirtsx = conPeek(con, 3);
namemidx = conPeek(con, 4);
namelastx = conPeek(con, 5);
datebirthx = str2Date(conPeek(con, 6),123);
genderx = conPeek(con, 7);
switch (genderx)
{
case 'F':
hcmgenderEnum = HcmPersonGender::Female;
genderEnum = Gender::Female;
break;
case 'M':
hcmgenderEnum = HcmPersonGender::Male;
genderEnum = Gender::Male;
break;
default:
hcmgenderEnum = HcmPersonGender::None;
genderEnum = Gender::Unknown;
}
initialx = conPeek(con, 8);
positionx = conPeek(con, 9);
addressx = conPeek(con, 10);
cityx = conPeek(con, 11);
companyInfo = CompanyInfo::findByCompany_IN(conPeek(con, 12));
educationx = conPeek(con, 13);
subeducationx = conPeek(con, 14);
bankx = conPeek(con, 15);
bankaccx = conPeek(con, 16);
npx = conPeek(con, 17);
levelx = conPeek(con, 18);
updatedatax = conPeek(con, 19);
employmentStartDateTime = DateTimeUtil::newDateTime(datehiringx,timeNow());
employmentEndDateTime = DateTimeUtil::maxValue();
if (!HcmWorker::findByPersonnelNumber(personnumx).RecId)
{
//{warning(strFmt('Employee exists! %1',personnumx)); }
/*** BEGIN INSERT DATA ***/
_dirPersonName.FirstName = namefirtsx;
_dirPersonName.MiddleName = namemidx;
_dirPersonName.LastName = namelastx;
namex = namefirtsx+' '+namemidx+' '+namelastx;
_dirPartyTable = DirPartyTable::createNew(DirPartyType::Person, namex);
_dirPerson = DirPerson::find(_dirPartyTable.RecId, true);
_dirPerson.Gender = genderEnum;
_dirPerson.Initials = initialx;
_dirPerson.ProfessionalTitle = positionx;
_dirPerson.LanguageId = 'en-us';
_dirPerson.NameSequence = DirNameSequence::find("FirstMiddleLast").RecId;
_dirPerson.write();
//HcmWorkerTransition::newCreateHcmWorker(_dirPersonName,personnumx,companyInfo.RecId,
// hcmEmploymentType,employmentStartDateTime,employmentEndDateTime);
_hcmWorker.PersonnelNumber = personnumx;
_hcmWorker.Person = _dirPerson.RecId;
_hcmWorker.insert();
newHcmWorker = HcmWorker::findByPersonnelNumber(personnumx);
//info(strFmt('0.personnumx %1',personnumx));
//info(strFmt('1.newHcmWorker.RecId %1',newHcmWorker.RecId));
if(newHcmWorker.RecId != 0)
{
select * from _hcmEmployment where _hcmEmployment.Worker == newHcmWorker.RecId;
// Replace any exisiting employment
//info(strFmt('2._hcmEmployment.Worker %1',_hcmEmployment.Worker));
if(!_hcmEmployment)
{
newEmploymentRecId = HcmWorkerTransition::newCreateHcmEmployment(newHcmWorker.RecId, companyInfo.RecId,
hcmEmploymentType, employmentStartDateTime, employmentEndDateTime);
}
else
{
delete_from _hcmEmployment2 where _hcmEmployment2.Worker == newHcmWorker.RecId;
newEmploymentRecId = HcmWorkerTransition::newCreateHcmEmployment(newHcmWorker.RecId, companyInfo.RecId,
hcmEmploymentType, employmentStartDateTime, employmentEndDateTime);
}
}
_hcmPersonPrivateDetails0 = HcmPersonPrivateDetails::findByPerson(newHcmWorker.Person);
//info(strFmt('4._hcmPersonPrivateDetails0.RecId %1',_hcmPersonPrivateDetails0.RecId));
if(!_hcmPersonPrivateDetails0)
{
//info('4._hcmPersonPrivateDetails0 - no exist');
_hcmPersonPrivateDetails.Person = newHcmWorker.Person;
_hcmPersonPrivateDetails.BirthDate = datebirthx;
_hcmPersonPrivateDetails.Education = educationx+' / '+levelx;
_hcmPersonPrivateDetails.Gender = hcmgenderEnum;
_hcmPersonPrivateDetails.insert();
}
else
{
//info('4._hcmPersonPrivateDetails0 - exist');
select forupdate _hcmPersonPrivateDetails0;
ttsBegin;
_hcmPersonPrivateDetails0.BirthDate = datebirthx;
_hcmPersonPrivateDetails0.Gender = hcmgenderEnum;
_hcmPersonPrivateDetails0.update();
ttsCommit;
}
//Create address
axLogisticsLocation = new AxLogisticsLocation();
axLogisticsLocation.validateInput(true);
axLogisticsLocation.parmIsPostalAddress(NoYes::Yes);
axLogisticsLocation.parmDescription(namefirtsx
+ (namemidx ? " " + namemidx : "")
+ (namelastx ? " " + namelastx : ""));
axLogisticsLocation.save();
axLogisticsPostalAddress = new AxLogisticsPostalAddress();
axLogisticsPostalAddress.parmLocation(axLogisticsLocation.parmRecId());
axLogisticsPostalAddress.validateInput(true);
logisticsPostalAddress_Default.initValue();
axLogisticsPostalAddress.parmCountryRegionId(logisticsPostalAddress_Default.CountryRegionId);
//axLogisticsPostalAddress.parmZipCode(conpeek(_c, #PostalCode));
//axLogisticsPostalAddress.parmZipCodeRecId(LogisticsAddressZipCode::find(conpeek(_c, #PostalCode)).RecId);
axLogisticsPostalAddress.parmStreet(addressx);
axLogisticsPostalAddress.parmCity(cityx);
axLogisticsPostalAddress.parmCityRecId(LogisticsAddresssCity::findCity(cityx,logisticsPostalAddress_Default.CountryRegionId).RecId);
axLogisticsPostalAddress.save();
DirParty::addLocation(newHcmWorker.Person, axLogisticsLocation.parmRecId(), true, true, true);
_hcmPersonEducation.Person = newHcmWorker.Person;
_hcmPersonEducation.EducationDiscipline = HcmEducationDiscipline::findByEducationDiscipline(educationx).recid;
_hcmPersonEducation.insert();
_hcmWorkerBankAccount.Worker = newHcmWorker.RecId;
_hcmWorkerBankAccount.AccountId = '001';
_hcmWorkerBankAccount.AccountNum = bankaccx;
_hcmWorkerBankAccount.Name = namefirtsx+' '+namemidx+' '+namelastx;
_hcmWorkerBankAccount.insert();
select * from _hcmPositionDetail where _hcmPositionDetail.Description == positionx;
if(!_hcmPositionDetail)
{ error(strFmt('Position name not found ! %1',positionx)); }
select * from _hcmPositionWorkerAssignment where _hcmPositionWorkerAssignment.Worker == newHcmWorker.RecId;
if(!_hcmPositionWorkerAssignment)
{
HcmPositionTransition::newCreateHcmPositionWorkerAssignment(_hcmPositionDetail.Position,newHcmWorker.RecId,
employmentStartDateTime,employmentEndDateTime);
}
else
{
delete_from _hcmPositionWorkerAssignment2 where _hcmPositionWorkerAssignment2.Worker == newHcmWorker.RecId;
HcmPositionTransition::newCreateHcmPositionWorkerAssignment(_hcmPositionDetail.Position,newHcmWorker.RecId,
employmentStartDateTime,employmentEndDateTime);
}
If(!HcmEmploymentEmployee::findByEmployment(newEmploymentRecId))
{
_hcmEmploymentEmployee.initValue();
_hcmEmploymentEmployee.Employment = newEmploymentRecId;
_hcmEmploymentEmployee.ValidFrom = employmentStartDateTime;
_hcmEmploymentEmployee.ValidTo = employmentEndDateTime;
_hcmEmploymentEmployee.IncomeTaxCode = HcmIncomeTaxCode::findByIncomeTaxCode(npx).RecId;
_hcmEmploymentEmployee.insert();
}
_hcmPersonLaborUnion.initValue();
_hcmPersonLaborUnion.Person = newHcmWorker.Person;
_hcmPersonLaborUnion.LaborUnion = HcmUnions::findByUnion('DEMOCO').RecId;
_hcmPersonLaborUnion.StartDate = datehiringx;
_hcmPersonLaborUnion.insert();
j++;
/*** END ***/
} // If NOT EXIST
else
{
if(updatedatax == 'UPDATE')
{
// If EXIST
newHcmWorker = HcmWorker::findByPersonnelNumber(personnumx);
delete_from _hcmEmployment2 where _hcmEmployment2.Worker == newHcmWorker.RecId;
newEmploymentRecId = HcmWorkerTransition::newCreateHcmEmployment(newHcmWorker.RecId, companyInfo.RecId,
hcmEmploymentType, employmentStartDateTime, employmentEndDateTime);
_hcmPersonPrivateDetails0 = HcmPersonPrivateDetails::findByPerson(newHcmWorker.Person);
if(!_hcmPersonPrivateDetails0)
{
//info('4._hcmPersonPrivateDetails0 - no exist');
_hcmPersonPrivateDetails.Person = newHcmWorker.Person;
_hcmPersonPrivateDetails.BirthDate = datebirthx;
_hcmPersonPrivateDetails.Education = educationx+' / '+levelx;
_hcmPersonPrivateDetails.Gender = hcmgenderEnum;
_hcmPersonPrivateDetails.insert();
}
else
{
//info('4._hcmPersonPrivateDetails0 - exist');
select forupdate _hcmPersonPrivateDetails0;
ttsBegin;
_hcmPersonPrivateDetails0.BirthDate = datebirthx;
_hcmPersonPrivateDetails0.Gender = hcmgenderEnum;
_hcmPersonPrivateDetails0.update();
ttsCommit;
}
select * from _dirPartyLocation where _dirPartyLocation.Party == newHcmWorker.Person;
select forUpdate _logisticsPostalAddress
where _logisticsPostalAddress.Location == _dirPartyLocation.Location;
if(_logisticsPostalAddress)
{
logisticsPostalAddress_Default.initValue();
ttsBegin;
_logisticsPostalAddress.Street = addressx;
_logisticsPostalAddress.City = cityx;
_logisticsPostalAddress.CityRecId = LogisticsAddresssCity::findCity(cityx,logisticsPostalAddress_Default.CountryRegionId).RecId;
_logisticsPostalAddress.Address = addressx+' '+cityx;
_logisticsPostalAddress.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
_logisticsPostalAddress.update();
ttsCommit;
}
select forUpdate _hcmPersonEducation where _hcmPersonEducation.Person == newHcmWorker.Person;
if(_hcmPersonEducation)
{
ttsBegin;
_hcmPersonEducation.EducationDiscipline = HcmEducationDiscipline::findByEducationDiscipline(educationx).recid;
_hcmPersonEducation.update();
ttsCommit;
}
select forUpdate _hcmWorkerBankAccount where _hcmWorkerBankAccount.Worker == newHcmWorker.RecId;
if(_hcmWorkerBankAccount)
{
ttsBegin;
_hcmWorkerBankAccount.AccountId = '001';
_hcmWorkerBankAccount.AccountNum = bankaccx;
_hcmWorkerBankAccount.Name = namefirtsx+' '+namemidx+' '+namelastx;
_hcmWorkerBankAccount.update();
ttsCommit;
}
select * from _hcmPositionDetail where _hcmPositionDetail.Description == positionx;
select * from _hcmPositionWorkerAssignment where _hcmPositionWorkerAssignment.Worker == newHcmWorker.RecId;
if(!_hcmPositionWorkerAssignment)
{
HcmPositionTransition::newCreateHcmPositionWorkerAssignment(_hcmPositionDetail.Position,newHcmWorker.RecId,
employmentStartDateTime,employmentEndDateTime);
}
else
{
delete_from _hcmPositionWorkerAssignment2 where _hcmPositionWorkerAssignment2.Worker == newHcmWorker.RecId;
HcmPositionTransition::newCreateHcmPositionWorkerAssignment(_hcmPositionDetail.Position,newHcmWorker.RecId,
employmentStartDateTime,employmentEndDateTime);
}
If(!HcmEmploymentEmployee::findByEmployment(newEmploymentRecId))
{
_hcmEmploymentEmployee.initValue();
_hcmEmploymentEmployee.Employment = newEmploymentRecId;
_hcmEmploymentEmployee.ValidFrom = employmentStartDateTime;
_hcmEmploymentEmployee.ValidTo = employmentEndDateTime;
_hcmEmploymentEmployee.IncomeTaxCode = HcmIncomeTaxCode::findByIncomeTaxCode(npx).RecId;
_hcmEmploymentEmployee.insert();
}
else
{ select forUpdate _hcmEmploymentEmployee where _hcmEmploymentEmployee.Employment == newEmploymentRecId;
ttsBegin;
_hcmEmploymentEmployee.Employment = newEmploymentRecId;
_hcmEmploymentEmployee.ValidFrom = employmentStartDateTime;
_hcmEmploymentEmployee.ValidTo = employmentEndDateTime;
_hcmEmploymentEmployee.IncomeTaxCode = HcmIncomeTaxCode::findByIncomeTaxCode(npx).RecId;
_hcmEmploymentEmployee.update();
ttsCommit;
}
k++;
} //if(updatedatax == 'UPDATE')
} // If EXIST
} // #4 if (conlen(con)
}// #3 while((file.status()
}// #2 if(dialog.run())
info(strfmt('Proces insert %1, update %2',j,k));
}// #1 try
catch
{
error (strFmt('Process Cancelled'));
}
}
static void Import_Worker_InsertUpdate(Args _args)
{
RecId workerRecId,hcmEmploymentRecId;
HcmPersonnelNumberId personnumx;
date datehiringx,datebirthx;
str 20 namefirtsx,namemidx,namelastx,initialx,educationx,subeducationx;
str 20 bankx,bankaccx,npx,levelx,updatedatax;
str 1 genderx;
HcmPersonGender hcmgenderEnum;
Gender genderEnum;
Dialog dialog;
DialogField dialogField,dialogField2,dialogdate,dialogField3,dialogField4;
Filename filename,filenamex;
str 60 oldnumx,newnumx,cityx,namex,positionx;
str 100 addressx;
TextIO io;
Container con;
Container filterCriteria;
COMVariant cOMVariant;
int i,j,k;
SysOperationProgress simpleProgress;
Numberseq numberseq;
Filename filepathz;
Filename filenamez;
Filename fileTypez;
str fileNameString;
CommaTextIo file;
boolean ret = true;
CompanyInfo companyInfo;
HcmEmploymentRecId newEmploymentRecId;
ValidFromDateTime employmentStartDateTime;
ValidToDateTime employmentEndDateTime;
DirPerson _dirPerson;
DirPersonName _dirPersonName;
DirPartyTable _dirPartyTable;
DirPartyLocation _dirPartyLocation;
HcmEmploymentType hcmEmploymentType = HcmEmploymentType::Employee;
NumberSeq numberSeqPersonnelNum;
AxLogisticsPostalAddress axLogisticsPostalAddress = new AxLogisticsPostalAddress();
AxLogisticsLocation axLogisticsLocation;
LogisticsPostalAddress logisticsPostalAddress_Default,_logisticsPostalAddress;
HcmWorker newHcmWorker,_hcmWorker;
HcmPersonPrivateDetails _hcmPersonPrivateDetails0,_hcmPersonPrivateDetails;
HcmPersonEducation _hcmPersonEducation;
HcmWorkerBankAccount _hcmWorkerBankAccount;
HcmEmploymentEmployee _hcmEmploymentEmployee,_hcmEmploymentEmployee0;
HcmPositionDetail _hcmPositionDetail;
HcmEmployment _hcmEmployment,_hcmEmployment2;
HcmPositionWorkerAssignment _hcmPositionWorkerAssignment,_hcmPositionWorkerAssignment2;
HcmPersonLaborUnion _hcmPersonLaborUnion;
HcmPositionUnionAgreement _hcmPositionUnionAgreement;
#avifiles
;
Dialog = new Dialog("Import insert and update worker ("+curext()+")");
dialogField = dialog.addField(ExtendedTypeStr("FilenameOpen"));
filterCriteria = ['*.txt','*.txt'];// To filter only TXT files
filterCriteria = dialog.filenameLookupFilter(filterCriteria);
dialog.run();
if(dialog.run())
fileName = dialogField.value();
if(!fileName)
{
Error('File is not selected. Process cancelled!');
return;
}
filenamex = filename;
[filepathz, filenamez, fileTypez] = fileNameSplit(filenamex);
fileNameString= filenamez + fileTypez;
try //#1
{
if(dialog.run()) //#2
{
file = new CommaTextIo(dialogField.value(), 'r');
file.inFieldDelimiter(';');
j=0;
k=0;
while((file.status()==IO_Status::Ok)) //#3
{
con = file.read();
//info(int2str(conlen(con)));
if (conlen(con) == 19) //#4
{
//*** GetValue
personnumx = conPeek(con, 1);
datehiringx = str2Date(conPeek(con, 2),123);
namefirtsx = conPeek(con, 3);
namemidx = conPeek(con, 4);
namelastx = conPeek(con, 5);
datebirthx = str2Date(conPeek(con, 6),123);
genderx = conPeek(con, 7);
switch (genderx)
{
case 'F':
hcmgenderEnum = HcmPersonGender::Female;
genderEnum = Gender::Female;
break;
case 'M':
hcmgenderEnum = HcmPersonGender::Male;
genderEnum = Gender::Male;
break;
default:
hcmgenderEnum = HcmPersonGender::None;
genderEnum = Gender::Unknown;
}
initialx = conPeek(con, 8);
positionx = conPeek(con, 9);
addressx = conPeek(con, 10);
cityx = conPeek(con, 11);
companyInfo = CompanyInfo::findByCompany_IN(conPeek(con, 12));
educationx = conPeek(con, 13);
subeducationx = conPeek(con, 14);
bankx = conPeek(con, 15);
bankaccx = conPeek(con, 16);
npx = conPeek(con, 17);
levelx = conPeek(con, 18);
updatedatax = conPeek(con, 19);
employmentStartDateTime = DateTimeUtil::newDateTime(datehiringx,timeNow());
employmentEndDateTime = DateTimeUtil::maxValue();
if (!HcmWorker::findByPersonnelNumber(personnumx).RecId)
{
//{warning(strFmt('Employee exists! %1',personnumx)); }
/*** BEGIN INSERT DATA ***/
_dirPersonName.FirstName = namefirtsx;
_dirPersonName.MiddleName = namemidx;
_dirPersonName.LastName = namelastx;
namex = namefirtsx+' '+namemidx+' '+namelastx;
_dirPartyTable = DirPartyTable::createNew(DirPartyType::Person, namex);
_dirPerson = DirPerson::find(_dirPartyTable.RecId, true);
_dirPerson.Gender = genderEnum;
_dirPerson.Initials = initialx;
_dirPerson.ProfessionalTitle = positionx;
_dirPerson.LanguageId = 'en-us';
_dirPerson.NameSequence = DirNameSequence::find("FirstMiddleLast").RecId;
_dirPerson.write();
//HcmWorkerTransition::newCreateHcmWorker(_dirPersonName,personnumx,companyInfo.RecId,
// hcmEmploymentType,employmentStartDateTime,employmentEndDateTime);
_hcmWorker.PersonnelNumber = personnumx;
_hcmWorker.Person = _dirPerson.RecId;
_hcmWorker.insert();
newHcmWorker = HcmWorker::findByPersonnelNumber(personnumx);
//info(strFmt('0.personnumx %1',personnumx));
//info(strFmt('1.newHcmWorker.RecId %1',newHcmWorker.RecId));
if(newHcmWorker.RecId != 0)
{
select * from _hcmEmployment where _hcmEmployment.Worker == newHcmWorker.RecId;
// Replace any exisiting employment
//info(strFmt('2._hcmEmployment.Worker %1',_hcmEmployment.Worker));
if(!_hcmEmployment)
{
newEmploymentRecId = HcmWorkerTransition::newCreateHcmEmployment(newHcmWorker.RecId, companyInfo.RecId,
hcmEmploymentType, employmentStartDateTime, employmentEndDateTime);
}
else
{
delete_from _hcmEmployment2 where _hcmEmployment2.Worker == newHcmWorker.RecId;
newEmploymentRecId = HcmWorkerTransition::newCreateHcmEmployment(newHcmWorker.RecId, companyInfo.RecId,
hcmEmploymentType, employmentStartDateTime, employmentEndDateTime);
}
}
_hcmPersonPrivateDetails0 = HcmPersonPrivateDetails::findByPerson(newHcmWorker.Person);
//info(strFmt('4._hcmPersonPrivateDetails0.RecId %1',_hcmPersonPrivateDetails0.RecId));
if(!_hcmPersonPrivateDetails0)
{
//info('4._hcmPersonPrivateDetails0 - no exist');
_hcmPersonPrivateDetails.Person = newHcmWorker.Person;
_hcmPersonPrivateDetails.BirthDate = datebirthx;
_hcmPersonPrivateDetails.Education = educationx+' / '+levelx;
_hcmPersonPrivateDetails.Gender = hcmgenderEnum;
_hcmPersonPrivateDetails.insert();
}
else
{
//info('4._hcmPersonPrivateDetails0 - exist');
select forupdate _hcmPersonPrivateDetails0;
ttsBegin;
_hcmPersonPrivateDetails0.BirthDate = datebirthx;
_hcmPersonPrivateDetails0.Gender = hcmgenderEnum;
_hcmPersonPrivateDetails0.update();
ttsCommit;
}
//Create address
axLogisticsLocation = new AxLogisticsLocation();
axLogisticsLocation.validateInput(true);
axLogisticsLocation.parmIsPostalAddress(NoYes::Yes);
axLogisticsLocation.parmDescription(namefirtsx
+ (namemidx ? " " + namemidx : "")
+ (namelastx ? " " + namelastx : ""));
axLogisticsLocation.save();
axLogisticsPostalAddress = new AxLogisticsPostalAddress();
axLogisticsPostalAddress.parmLocation(axLogisticsLocation.parmRecId());
axLogisticsPostalAddress.validateInput(true);
logisticsPostalAddress_Default.initValue();
axLogisticsPostalAddress.parmCountryRegionId(logisticsPostalAddress_Default.CountryRegionId);
//axLogisticsPostalAddress.parmZipCode(conpeek(_c, #PostalCode));
//axLogisticsPostalAddress.parmZipCodeRecId(LogisticsAddressZipCode::find(conpeek(_c, #PostalCode)).RecId);
axLogisticsPostalAddress.parmStreet(addressx);
axLogisticsPostalAddress.parmCity(cityx);
axLogisticsPostalAddress.parmCityRecId(LogisticsAddresssCity::findCity(cityx,logisticsPostalAddress_Default.CountryRegionId).RecId);
axLogisticsPostalAddress.save();
DirParty::addLocation(newHcmWorker.Person, axLogisticsLocation.parmRecId(), true, true, true);
_hcmPersonEducation.Person = newHcmWorker.Person;
_hcmPersonEducation.EducationDiscipline = HcmEducationDiscipline::findByEducationDiscipline(educationx).recid;
_hcmPersonEducation.insert();
_hcmWorkerBankAccount.Worker = newHcmWorker.RecId;
_hcmWorkerBankAccount.AccountId = '001';
_hcmWorkerBankAccount.AccountNum = bankaccx;
_hcmWorkerBankAccount.Name = namefirtsx+' '+namemidx+' '+namelastx;
_hcmWorkerBankAccount.insert();
select * from _hcmPositionDetail where _hcmPositionDetail.Description == positionx;
if(!_hcmPositionDetail)
{ error(strFmt('Position name not found ! %1',positionx)); }
select * from _hcmPositionWorkerAssignment where _hcmPositionWorkerAssignment.Worker == newHcmWorker.RecId;
if(!_hcmPositionWorkerAssignment)
{
HcmPositionTransition::newCreateHcmPositionWorkerAssignment(_hcmPositionDetail.Position,newHcmWorker.RecId,
employmentStartDateTime,employmentEndDateTime);
}
else
{
delete_from _hcmPositionWorkerAssignment2 where _hcmPositionWorkerAssignment2.Worker == newHcmWorker.RecId;
HcmPositionTransition::newCreateHcmPositionWorkerAssignment(_hcmPositionDetail.Position,newHcmWorker.RecId,
employmentStartDateTime,employmentEndDateTime);
}
If(!HcmEmploymentEmployee::findByEmployment(newEmploymentRecId))
{
_hcmEmploymentEmployee.initValue();
_hcmEmploymentEmployee.Employment = newEmploymentRecId;
_hcmEmploymentEmployee.ValidFrom = employmentStartDateTime;
_hcmEmploymentEmployee.ValidTo = employmentEndDateTime;
_hcmEmploymentEmployee.IncomeTaxCode = HcmIncomeTaxCode::findByIncomeTaxCode(npx).RecId;
_hcmEmploymentEmployee.insert();
}
_hcmPersonLaborUnion.initValue();
_hcmPersonLaborUnion.Person = newHcmWorker.Person;
_hcmPersonLaborUnion.LaborUnion = HcmUnions::findByUnion('DEMOCO').RecId;
_hcmPersonLaborUnion.StartDate = datehiringx;
_hcmPersonLaborUnion.insert();
j++;
/*** END ***/
} // If NOT EXIST
else
{
if(updatedatax == 'UPDATE')
{
// If EXIST
newHcmWorker = HcmWorker::findByPersonnelNumber(personnumx);
delete_from _hcmEmployment2 where _hcmEmployment2.Worker == newHcmWorker.RecId;
newEmploymentRecId = HcmWorkerTransition::newCreateHcmEmployment(newHcmWorker.RecId, companyInfo.RecId,
hcmEmploymentType, employmentStartDateTime, employmentEndDateTime);
_hcmPersonPrivateDetails0 = HcmPersonPrivateDetails::findByPerson(newHcmWorker.Person);
if(!_hcmPersonPrivateDetails0)
{
//info('4._hcmPersonPrivateDetails0 - no exist');
_hcmPersonPrivateDetails.Person = newHcmWorker.Person;
_hcmPersonPrivateDetails.BirthDate = datebirthx;
_hcmPersonPrivateDetails.Education = educationx+' / '+levelx;
_hcmPersonPrivateDetails.Gender = hcmgenderEnum;
_hcmPersonPrivateDetails.insert();
}
else
{
//info('4._hcmPersonPrivateDetails0 - exist');
select forupdate _hcmPersonPrivateDetails0;
ttsBegin;
_hcmPersonPrivateDetails0.BirthDate = datebirthx;
_hcmPersonPrivateDetails0.Gender = hcmgenderEnum;
_hcmPersonPrivateDetails0.update();
ttsCommit;
}
select * from _dirPartyLocation where _dirPartyLocation.Party == newHcmWorker.Person;
select forUpdate _logisticsPostalAddress
where _logisticsPostalAddress.Location == _dirPartyLocation.Location;
if(_logisticsPostalAddress)
{
logisticsPostalAddress_Default.initValue();
ttsBegin;
_logisticsPostalAddress.Street = addressx;
_logisticsPostalAddress.City = cityx;
_logisticsPostalAddress.CityRecId = LogisticsAddresssCity::findCity(cityx,logisticsPostalAddress_Default.CountryRegionId).RecId;
_logisticsPostalAddress.Address = addressx+' '+cityx;
_logisticsPostalAddress.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
_logisticsPostalAddress.update();
ttsCommit;
}
select forUpdate _hcmPersonEducation where _hcmPersonEducation.Person == newHcmWorker.Person;
if(_hcmPersonEducation)
{
ttsBegin;
_hcmPersonEducation.EducationDiscipline = HcmEducationDiscipline::findByEducationDiscipline(educationx).recid;
_hcmPersonEducation.update();
ttsCommit;
}
select forUpdate _hcmWorkerBankAccount where _hcmWorkerBankAccount.Worker == newHcmWorker.RecId;
if(_hcmWorkerBankAccount)
{
ttsBegin;
_hcmWorkerBankAccount.AccountId = '001';
_hcmWorkerBankAccount.AccountNum = bankaccx;
_hcmWorkerBankAccount.Name = namefirtsx+' '+namemidx+' '+namelastx;
_hcmWorkerBankAccount.update();
ttsCommit;
}
select * from _hcmPositionDetail where _hcmPositionDetail.Description == positionx;
select * from _hcmPositionWorkerAssignment where _hcmPositionWorkerAssignment.Worker == newHcmWorker.RecId;
if(!_hcmPositionWorkerAssignment)
{
HcmPositionTransition::newCreateHcmPositionWorkerAssignment(_hcmPositionDetail.Position,newHcmWorker.RecId,
employmentStartDateTime,employmentEndDateTime);
}
else
{
delete_from _hcmPositionWorkerAssignment2 where _hcmPositionWorkerAssignment2.Worker == newHcmWorker.RecId;
HcmPositionTransition::newCreateHcmPositionWorkerAssignment(_hcmPositionDetail.Position,newHcmWorker.RecId,
employmentStartDateTime,employmentEndDateTime);
}
If(!HcmEmploymentEmployee::findByEmployment(newEmploymentRecId))
{
_hcmEmploymentEmployee.initValue();
_hcmEmploymentEmployee.Employment = newEmploymentRecId;
_hcmEmploymentEmployee.ValidFrom = employmentStartDateTime;
_hcmEmploymentEmployee.ValidTo = employmentEndDateTime;
_hcmEmploymentEmployee.IncomeTaxCode = HcmIncomeTaxCode::findByIncomeTaxCode(npx).RecId;
_hcmEmploymentEmployee.insert();
}
else
{ select forUpdate _hcmEmploymentEmployee where _hcmEmploymentEmployee.Employment == newEmploymentRecId;
ttsBegin;
_hcmEmploymentEmployee.Employment = newEmploymentRecId;
_hcmEmploymentEmployee.ValidFrom = employmentStartDateTime;
_hcmEmploymentEmployee.ValidTo = employmentEndDateTime;
_hcmEmploymentEmployee.IncomeTaxCode = HcmIncomeTaxCode::findByIncomeTaxCode(npx).RecId;
_hcmEmploymentEmployee.update();
ttsCommit;
}
k++;
} //if(updatedatax == 'UPDATE')
} // If EXIST
} // #4 if (conlen(con)
}// #3 while((file.status()
}// #2 if(dialog.run())
info(strfmt('Proces insert %1, update %2',j,k));
}// #1 try
catch
{
error (strFmt('Process Cancelled'));
}
}
Subscribe to:
Posts (Atom)