static void UploadVendorAddress(Args _args)
{
CommaTextIO csvFile;
int row = 1;
int i = 0;
container readCon;
counter icount,inserted;
Dialog dialog;
DialogField dfFileName;
DirPartyRecId partyRecId,contactPartyRecid;
VendTable vendtable;
str contactperson;
DirPartyPostalAddressView addressView;
DirPartyContactInfoView contactView;
ContactPerson contactpersonTable;
LogisticsElectronicAddressMethodType enumType;
DirContactPersonsService dirContactPersonsService;
DirContactPersons dirContactPersons;
DirContactPersons_ContactPerson dirContactPersons_ContactPerson;
DirContactPersons_Person dirContactPersons_Person;
DirContactPersons_PersonName dirContactPersons_PersonName;
AifEntityKeyList aifEntityKeyList, aifEntityKeyList_DirContactPerson;
str fName, mName, lName;
VendAccount vendorAccount;
DirParty dirParty;
LogisticsPostalAddress address;
LogisticsElectronicAddress logisticsElectronicAddress;
BinData binData;
str stringImage;
LogisticsAddressStateID stateId;
str accountnum,accountName,vendgroup,currency,dlvmode,paymtermid,countryid,street,city,mobile,fax,email,zipcode,pobox,phone;
Filename filename;
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
;
#File
dialog = new Dialog("Select Excel to Import");
dfFileName = dialog.addField(extendedTypeStr("FilenameOpen"));
dialog.filenameLookupFilter(["All files", #AllFiles]);
if (dialog.run())
{
filename = dfFileName.value();
application = SysExcelApplication::construct();
workbooks = application.workbooks();
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
do
{
row++;
accountnum = cells.item(row,1).value().bStr();
street = cells.item(row,2).value().bStr();
countryid = cells.item(row,3).value().bStr();
fax =cells.item(row,5).value().bStr();
phone = cells.item(row,6).value().bStr();
mobile = cells.item(row,7).value().bStr();
vendtable = vendtable::find(accountnum);
address.clear();
address.CountryRegionId = strLRTrim(Countryid);
address.Street = strLRTrim(Street);
addressView.clear();
addressView.IsPrimary = NoYes::Yes;
addressView.Party = vendtable.Party;
addressview.initFromPostalAddress(address);
DirParty = DirParty::constructFromPartyRecId(addressView.Party );
DirParty.createOrUpdatePostalAddress(addressView);
if(mobile)
{
contactView.clear();
contactView.LocationName = "Mobile";
contactView.Locator = strLRTrim(mobile);
contactView.Type = LogisticsElectronicAddressMethodType::Phone;
contactView.Party = vendtable.Party;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
}
if(Phone)
{
contactView.clear();
contactView.LocationName = "Phone";
contactView.Locator = strLRTrim(Phone);
contactView.Type = LogisticsElectronicAddressMethodType::Phone;
contactView.Party = vendtable.Party;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
}
if(fax)
{
contactView.clear();
contactView.LocationName = "Fax";
contactView.Locator = strLRTrim(Fax);
contactView.Type = LogisticsElectronicAddressMethodType::Fax;
contactView.Party = vendtable.Party;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
}
i++;
type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
application.quit();
info(strFmt(" No of Records updated is %1",i));
}
}
static void Job1(Args _args)
{
//CommaTextIO csvFile;
container readCon;
counter icount,inserted;
Dialog dialog;
DialogField dfFileName;
DirPartyRecId partyRecId,contactPartyRecid;
Name name,contactName;
VendTable vendtable;
str contactperson;
DirPartyPostalAddressView addressView;
DirPartyContactInfoView contactView;
ContactPerson contactpersonTable;
LogisticsElectronicAddressMethodType enumType;
DirContactPersonsService dirContactPersonsService;
DirContactPersons dirContactPersons;
DirContactPersons_ContactPerson dirContactPersons_ContactPerson;
DirContactPersons_Person dirContactPersons_Person;
DirContactPersons_PersonName dirContactPersons_PersonName;
AifEntityKeyList aifEntityKeyList, aifEntityKeyList_DirContactPerson;
str fName, mName, lName;
VendAccount vendorAccount;
DirParty dirParty;
LogisticsPostalAddress address;
LogisticsElectronicAddress logisticsElectronicAddress;
BinData binData;
str stringImage;
LogisticsAddressStateID stateId;
str accountnum,accountName,vendgroup,currency,dlvmode,paymtermid,countryid,street,city,mobile,fax,email,zipcode,pobox,phone;
;
csvFile = new CommaIO(filename, 'r');
try
{
if (csvFile)
{
ttsbegin;
readCon = csvFile.read();
while (csvFile.status() == IO_Status::OK)
{
readCon = csvFile.read();
if(readCon)
{
icount++;
accountnum = conPeek(readCon,1);
accountName = conPeek(readCon,2);
phone = conPeek(readCon,3);
fax = conPeek(readCon,4);
vendgroup = conPeek(readCon,5);
currency = conPeek(readCon,6);
dlvmode = conPeek(readCon,7);
paymtermid = conPeek(readCon,8);
email = conPeek(readCon,9);
mobile = conPeek(readCon,10);
contactperson = conPeek(readCon,11);
pobox = conPeek(readCon,12);
countryid = conPeek(readCon,13);
zipcode = conPeek(readCon,14);
stateId = conPeek(readCon,15);
city = conPeek(readCon,16);
street = conPeek(readCon,17);
ttsBegin;
name = conPeek(readCon,2);
if(!name)
break;
partyRecId = DirPartyTable::createNew( DirPartyType::Organization, name).RecId;
vendtable.clear();
vendtable.initValue();
vendtable.Party = partyRecId;
vendtable.AccountNum = accountnum;
vendtable.VendGroup = vendgroup;
vendtable.Currency = currency;
//vendtable.Blocked =
vendtable.DlvMode = dlvmode;
vendtable.PaymTermId = paymtermid;
if(contactperson != '')
{
contactname = ContactPerson;
ContactPerson::findOrCreateNameParty(partyRecId,contactname);
}
vendtable.insert();
ttsCommit;
stateId = subStr(stateId,1,25);
address.PostBox = strLRTrim(PoBox);
address.CountryRegionId = strLRTrim(Countryid);
address.State = stateId;
address.ZipCode = strLRTrim(ZipCode);
address.Street = strLRTrim(Street);
//address.county = strLRTrim(conPeek(readCon,17));
address.City = strLRTrim(City);
addressView.LocationName = name;
addressView.IsPrimary = NoYes::Yes;
addressView.Party = partyRecId;
addressview.initFromPostalAddress(address);
DirParty = DirParty::constructFromPartyRecId(addressView.Party );
DirParty.createOrUpdatePostalAddress(addressView);
contactView.LocationName = "Email";
contactView.Locator = strLRTrim(email);
contactView.Type = LogisticsElectronicAddressMethodType::Email;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
contactView.LocationName = "Mobile";
contactView.Locator = strLRTrim(mobile);
contactView.Type = LogisticsElectronicAddressMethodType::Phone;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
contactView.LocationName = "Phone";
contactView.Locator = strLRTrim(Phone);
contactView.Type = LogisticsElectronicAddressMethodType::Phone;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
contactView.LocationName = "Fax";
contactView.Locator = strLRTrim(Fax);
contactView.Type = LogisticsElectronicAddressMethodType::Fax;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
inserted++;
}
}
ttsCommit;
}
icount--;//Remove header recount from total record count
}
catch(Exception::Error)
{
info(strFmt("%1 %2",Exception::Error,icount));
}
}
{
CommaTextIO csvFile;
int row = 1;
int i = 0;
container readCon;
counter icount,inserted;
Dialog dialog;
DialogField dfFileName;
DirPartyRecId partyRecId,contactPartyRecid;
VendTable vendtable;
str contactperson;
DirPartyPostalAddressView addressView;
DirPartyContactInfoView contactView;
ContactPerson contactpersonTable;
LogisticsElectronicAddressMethodType enumType;
DirContactPersonsService dirContactPersonsService;
DirContactPersons dirContactPersons;
DirContactPersons_ContactPerson dirContactPersons_ContactPerson;
DirContactPersons_Person dirContactPersons_Person;
DirContactPersons_PersonName dirContactPersons_PersonName;
AifEntityKeyList aifEntityKeyList, aifEntityKeyList_DirContactPerson;
str fName, mName, lName;
VendAccount vendorAccount;
DirParty dirParty;
LogisticsPostalAddress address;
LogisticsElectronicAddress logisticsElectronicAddress;
BinData binData;
str stringImage;
LogisticsAddressStateID stateId;
str accountnum,accountName,vendgroup,currency,dlvmode,paymtermid,countryid,street,city,mobile,fax,email,zipcode,pobox,phone;
Filename filename;
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
;
#File
dialog = new Dialog("Select Excel to Import");
dfFileName = dialog.addField(extendedTypeStr("FilenameOpen"));
dialog.filenameLookupFilter(["All files", #AllFiles]);
if (dialog.run())
{
filename = dfFileName.value();
application = SysExcelApplication::construct();
workbooks = application.workbooks();
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
do
{
row++;
accountnum = cells.item(row,1).value().bStr();
street = cells.item(row,2).value().bStr();
countryid = cells.item(row,3).value().bStr();
fax =cells.item(row,5).value().bStr();
phone = cells.item(row,6).value().bStr();
mobile = cells.item(row,7).value().bStr();
vendtable = vendtable::find(accountnum);
address.clear();
address.CountryRegionId = strLRTrim(Countryid);
address.Street = strLRTrim(Street);
addressView.clear();
addressView.IsPrimary = NoYes::Yes;
addressView.Party = vendtable.Party;
addressview.initFromPostalAddress(address);
DirParty = DirParty::constructFromPartyRecId(addressView.Party );
DirParty.createOrUpdatePostalAddress(addressView);
if(mobile)
{
contactView.clear();
contactView.LocationName = "Mobile";
contactView.Locator = strLRTrim(mobile);
contactView.Type = LogisticsElectronicAddressMethodType::Phone;
contactView.Party = vendtable.Party;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
}
if(Phone)
{
contactView.clear();
contactView.LocationName = "Phone";
contactView.Locator = strLRTrim(Phone);
contactView.Type = LogisticsElectronicAddressMethodType::Phone;
contactView.Party = vendtable.Party;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
}
if(fax)
{
contactView.clear();
contactView.LocationName = "Fax";
contactView.Locator = strLRTrim(Fax);
contactView.Type = LogisticsElectronicAddressMethodType::Fax;
contactView.Party = vendtable.Party;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
}
i++;
type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
application.quit();
info(strFmt(" No of Records updated is %1",i));
}
}
static void Job1(Args _args)
{
//CommaTextIO csvFile;
container readCon;
counter icount,inserted;
Dialog dialog;
DialogField dfFileName;
DirPartyRecId partyRecId,contactPartyRecid;
Name name,contactName;
VendTable vendtable;
str contactperson;
DirPartyPostalAddressView addressView;
DirPartyContactInfoView contactView;
ContactPerson contactpersonTable;
LogisticsElectronicAddressMethodType enumType;
DirContactPersonsService dirContactPersonsService;
DirContactPersons dirContactPersons;
DirContactPersons_ContactPerson dirContactPersons_ContactPerson;
DirContactPersons_Person dirContactPersons_Person;
DirContactPersons_PersonName dirContactPersons_PersonName;
AifEntityKeyList aifEntityKeyList, aifEntityKeyList_DirContactPerson;
str fName, mName, lName;
VendAccount vendorAccount;
DirParty dirParty;
LogisticsPostalAddress address;
LogisticsElectronicAddress logisticsElectronicAddress;
BinData binData;
str stringImage;
LogisticsAddressStateID stateId;
str accountnum,accountName,vendgroup,currency,dlvmode,paymtermid,countryid,street,city,mobile,fax,email,zipcode,pobox,phone;
;
csvFile = new CommaIO(filename, 'r');
try
{
if (csvFile)
{
ttsbegin;
readCon = csvFile.read();
while (csvFile.status() == IO_Status::OK)
{
readCon = csvFile.read();
if(readCon)
{
icount++;
accountnum = conPeek(readCon,1);
accountName = conPeek(readCon,2);
phone = conPeek(readCon,3);
fax = conPeek(readCon,4);
vendgroup = conPeek(readCon,5);
currency = conPeek(readCon,6);
dlvmode = conPeek(readCon,7);
paymtermid = conPeek(readCon,8);
email = conPeek(readCon,9);
mobile = conPeek(readCon,10);
contactperson = conPeek(readCon,11);
pobox = conPeek(readCon,12);
countryid = conPeek(readCon,13);
zipcode = conPeek(readCon,14);
stateId = conPeek(readCon,15);
city = conPeek(readCon,16);
street = conPeek(readCon,17);
ttsBegin;
name = conPeek(readCon,2);
if(!name)
break;
partyRecId = DirPartyTable::createNew( DirPartyType::Organization, name).RecId;
vendtable.clear();
vendtable.initValue();
vendtable.Party = partyRecId;
vendtable.AccountNum = accountnum;
vendtable.VendGroup = vendgroup;
vendtable.Currency = currency;
//vendtable.Blocked =
vendtable.DlvMode = dlvmode;
vendtable.PaymTermId = paymtermid;
if(contactperson != '')
{
contactname = ContactPerson;
ContactPerson::findOrCreateNameParty(partyRecId,contactname);
}
vendtable.insert();
ttsCommit;
stateId = subStr(stateId,1,25);
address.PostBox = strLRTrim(PoBox);
address.CountryRegionId = strLRTrim(Countryid);
address.State = stateId;
address.ZipCode = strLRTrim(ZipCode);
address.Street = strLRTrim(Street);
//address.county = strLRTrim(conPeek(readCon,17));
address.City = strLRTrim(City);
addressView.LocationName = name;
addressView.IsPrimary = NoYes::Yes;
addressView.Party = partyRecId;
addressview.initFromPostalAddress(address);
DirParty = DirParty::constructFromPartyRecId(addressView.Party );
DirParty.createOrUpdatePostalAddress(addressView);
contactView.LocationName = "Email";
contactView.Locator = strLRTrim(email);
contactView.Type = LogisticsElectronicAddressMethodType::Email;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
contactView.LocationName = "Mobile";
contactView.Locator = strLRTrim(mobile);
contactView.Type = LogisticsElectronicAddressMethodType::Phone;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
contactView.LocationName = "Phone";
contactView.Locator = strLRTrim(Phone);
contactView.Type = LogisticsElectronicAddressMethodType::Phone;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
contactView.LocationName = "Fax";
contactView.Locator = strLRTrim(Fax);
contactView.Type = LogisticsElectronicAddressMethodType::Fax;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
inserted++;
}
}
ttsCommit;
}
icount--;//Remove header recount from total record count
}
catch(Exception::Error)
{
info(strFmt("%1 %2",Exception::Error,icount));
}
}
No comments:
Post a Comment