static void KTI_fixedAsset2(Args _args)
{
Dialog dialog;
Dialogfield dialogfield;
SysExcelApplication application;
SysExcelWorkbooks workBooks;
SysExcelWorkbook workBook;
SysExcelWorksheets workSheets;
SysExcelWorksheet workSheet;
SysExcelCells cells;
AssetTable assettable;
AssetBook assetbook;
AssetType assettype;
AssetPropertyType assetPropertyType;
NoYes noYes;
AssetDepreciationConvention assetDepreciationConvention;
Filename fileName;
Container filterCriteria;
COMVariantType type;
int row = 1 ;
int recordcnt ;
str 70 assetId,bookid;
str assetGroup,Name, Namealias,model,modelyear,serialnum, location, postingprofile,despreciation,techinfo1,lifetime;
real quantity,unitcost,acquistionprice,lifetimerest;
date deprectionstartdate,lasttdepreciationdate,acquistindate,usedfromdate;
anytype propertytype,servicelife;
str COMVariant2Str(COMVariant _cv, int _decimals = 0,int _characters = 0,int _separator1 = 0,int _separator2 = 0)
{
switch(_cv.variantType())
{
case (COMVariantType::VT_BSTR):
return _cv.bStr();
case (COMVariantType::VT_R4):
return num2str(_cv.float(),_characters,_decimals, _separator1,_separator2);
case (COMVariantType::VT_R8):
return num2str(_cv.double(),_characters,_decimals,_separator1,_separator2);
case (COMVariantType::VT_DECIMAL):
return num2str(_cv.decimal(),_characters,_decimals, _separator1, _separator2);
case (COMVariantType::VT_DATE):
return date2str(_cv.date(),123,2,1,2, 1,4);
case (COMVariantType::VT_EMPTY):
return "";
default:
throw error(strfmt("@SYS26908",_cv.variantType()));
}
return "";
}
application = SysExcelApplication::construct();
workBooks = application.workbooks();
dialog = new Dialog("FileOpen");
dialogfield = dialog.addField(extendedTypeStr(Filenameopen), "File Name");
filterCriteria = ['*.xlsx'];
filterCriteria = dialog.filenameLookupFilter(filterCriteria);
dialog.run();
if (dialog.run())
{
filename = (dialogfield.value());
}
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
{
try
{
row++;
assetid = COMVariant2Str(cells.item(row, 1).value());
assetGroup = cells.item(row, 2).value().bStr();
Name = cells.item(row, 3).value().bStr();
Namealias = cells.item(row, 4).value().bStr();
assettype = str2enum(AssetType,cells.item(row, 5).value().bStr());
propertytype = COMVariant2str(cells.item(row,6).value());
quantity = cells.item(row, 7).value().double();
unitcost = cells.item(row, 8).value().double();
model = cells.item(row, 9).value().bstr();
modelyear = cells.item(row, 10).value().bstr();
serialnum = COMVariant2str(cells.item(row,11).value());
location = cells.item(row, 12).value().bStr();
postingprofile = cells.item(row, 15).value().bStr();
bookid = cells.item(row, 16).value().bStr();
acquistindate = cells.item(row, 17).value().date();
usedfromdate = cells.item(row, 18).value().date();
acquistionprice = cells.item(row, 19).value().double();
deprectionstartdate = cells.item(row, 20).value().date();
lasttdepreciationdate = cells.item(row, 21).value().date();
servicelife = COMVariant2str(cells.item(row,22).value());
lifetime = COMVariant2str(cells.item(row,23).value());
lifetimerest = cells.item(row, 24).value().double();
noYes = str2enum(NoYes,cells.item(row, 25).value().bStr());
techinfo1 = cells.item(row, 26).value().bstr();
assetDepreciationConvention = str2enum(AssetDepreciationConvention,cells.item(row, 27).value().bStr());
breakpoint;
ttsBegin;
if(assettable.AssetId == assetId)
{
select forUpdate assettable where assettable.AssetId == assetid;
// && assettable.dataAreaId == "RURT";
ttsBegin;
assetTable.initValue();
assettable.AssetId= assetid;
assettable.AssetGroup=assetGroup;
assettable.Name=Name;
assettable.NameAlias=Namealias;
assettable.AssetType=assettype;
assettable.propertytype= assetPropertyType;
assettable.quantity= quantity;
assettable.UnitCost= unitcost;
assettable.model= model;
assettable.modelyear= modelyear;
assettable.serialnum= serialnum;
assettable.location= location;
assettable.Techinfo1= techinfo1;
assettable.update();
ttsCommit;
}
else
{
assetTable.clear();
select * from assettable
where assettable.AssetId != assetId;
assetTable.initValue();
assettable.AssetId= assetid;
assettable.AssetGroup=assetGroup;
assettable.Name=Name;
assettable.NameAlias=Namealias;
assettable.AssetType=assettype;
assettable.propertytype= assetPropertyType;
assettable.quantity= quantity;
assettable.unitcost= unitcost;
assettable.model= model;
assettable.modelyear= modelyear;
assettable.serialnum= serialnum;
assettable.location= location;
assettable.Techinfo1= techinfo1;
assetTable.insert();
}
select forUpdate assetbook
where assetbook.AssetId != assettable.AssetId
&& assetbook.AssetId != assetId
&& assetbook.BookId != bookid;
if(!assetbook)
{
ttsBegin;
assetbook.BookId = bookid;
assetBook.selectForUpdate(true);
assetbook.AcquisitionDate = acquistindate;
assetbook.AcquisitionPrice = acquistionprice;
assetbook.usedfromdate= usedfromdate;
assetbook.Depreciationstartdate =deprectionstartdate;
assetbook.lastdepreciationdate= lasttdepreciationdate;
assetbook.ServiceLife =( servicelife);
assetbook.PostingProfile = postingprofile;
assetbook.lifetime = str2int(lifetime);
assetbook.lifetimerest= lifetimerest;
assetbook.DepreciationConvention= assetDepreciationConvention;
assetbook.Depreciation = noYes;
assetBook.AssetId = assetTable.AssetId;
assetBook.update();
ttsCommit;
}
else
{
assetBook.clear();
assetBook.initValue();
assetbook.selectForUpdate(true);
assetbook.BookId = bookid;
assetbook.AcquisitionDate = acquistindate;
assetbook.AcquisitionPrice = acquistionprice;
assetbook.usedfromdate= usedfromdate;
assetbook.Depreciationstartdate =deprectionstartdate;
assetbook.lastdepreciationdate= lasttdepreciationdate;
assetbook.ServiceLife = (servicelife);
assetbook.PostingProfile = postingprofile;
assetbook.lifetime=str2int( lifetime);
assetbook.lifetimerest= lifetimerest;
assetbook.DepreciationConvention= assetDepreciationConvention;
assetbook.Depreciation = noYes;
assetBook.AssetId = assetTable.AssetId;
assetBook.insert();
}
ttsCommit;
}
catch(Exception::Error)
{
throw error("The missing asset id %1 :",assettable.AssetId );
}
//type = cells.item(row+1, 1).value().variantType();
info(strFmt("Records %1-%2 inserted",assetTable.AssetId,assetTable.Location));
}
while (type != COMVariantType::VT_EMPTY);
application.quit();
workbooks.close();
info("Done");
}
Since dont know the language that you have attached to the excel.I am giving you the code.
Please try and let me know.