Format impor file CSV harus menggunakan header. Adapun contoh CSV adalah sbb:
NO;TGL;ITEM ;QTY;PRICE;SITE;WH;ACCT
MEI2011;4/30/2011;320000600;100;436.5;Utama;GI;999.999
MEI2011;4/30/2011;320000611;100;519.39;Utama;GI;999.999
MEI2011;4/30/2011;320000600;100;436.5;Utama;GI;999.999
MEI2011;4/30/2011;320000611;100;519.39;Utama;GI;999.999
Catatan: Lebih baik yang diinput adalah amount (qty*price), jangan unit price-nya. Jadi parmCostPrice nya bisa diganti dengan parmCostAmount.
==========
static void UploadInventBeginBalance_CSV(Args _args)///and also it will import the data from the Excel
{
InventJournalNameId inventJournalNameId = "MV-00";///Assign the journal Name
AxInventJournalTrans axInventJournalTrans;
InventJournalTable inventJournalTable;
Dialog dialog;
DialogField dialogField,dialogdate;
Filename filename;
CommaIO io;
Container con;
Container filterCriteria;
str val, qtyStr, priceStr;
COMVariant cOMVariant;
int i,j,k;
SysOperationProgress simpleProgress;
#avifiles
;
Dialog = new dialog();
//dialogField = dialog
dialogField = dialog.addField(typeId(FileNameOpen),'File Name');
filterCriteria = ['*.csv','*.csv'];//// To filter only CSV files
filterCriteria = dialog.filenameLookupFilter(filterCriteria);
dialog.run();
if(dialog.run())
fileName = dialogField.value();
info(filename);
io = new CommaIO(fileName, "r");
io.read();
io.inFieldDelimiter(";");
if(fileName)
{
ttsBegin;
inventJournalTable.JournalNameId = inventJournalNameId;
inventJournalTable.initFromInventJournalName(InventJournalName::find(inventJournalNameId));
inventJournalTable.insert();
simpleProgress = SysOperationProgress::newGeneral(#aviUpdate,'Importing Transactions',100);///SysProgressOperation
while((io.status()==IO_Status::Ok))
{
con = io.read();
if (conlen(con) == 8)
{
j++;
simpleProgress.incCount();
simpleprogress.setText(strfmt("Transaction Imported: %1",i));
sleep(10);
axInventJournalTrans = new AxInventJournalTrans();
axInventJournalTrans.parmJournalId(inventJournalTable.JournalId);
axInventJournalTrans.parmTransDate( mkDate(30, 04, 2011));
axInventJournalTrans.parmLineNum(j);
axInventJournalTrans.parmItemId(conPeek(con, 3));
axInventJournalTrans.axInventDim().parmInventSiteId(conPeek(con, 6));
axInventJournalTrans.axInventDim().parmInventLocationId(conPeek(con, 7));
axInventJournalTrans.parmQty(conPeek(con, 4));
axInventJournalTrans.parmCostPrice(conPeek(con, 5));
axInventJournalTrans.parmLedgerAccountIdOffset(conPeek(con, 8));
axInventJournalTrans.save();
i++;
} //if
}
ttsCommit;
}
}
{
InventJournalNameId inventJournalNameId = "MV-00";///Assign the journal Name
AxInventJournalTrans axInventJournalTrans;
InventJournalTable inventJournalTable;
Dialog dialog;
DialogField dialogField,dialogdate;
Filename filename;
CommaIO io;
Container con;
Container filterCriteria;
str val, qtyStr, priceStr;
COMVariant cOMVariant;
int i,j,k;
SysOperationProgress simpleProgress;
#avifiles
;
Dialog = new dialog();
//dialogField = dialog
dialogField = dialog.addField(typeId(FileNameOpen),'File Name');
filterCriteria = ['*.csv','*.csv'];//// To filter only CSV files
filterCriteria = dialog.filenameLookupFilter(filterCriteria);
dialog.run();
if(dialog.run())
fileName = dialogField.value();
info(filename);
io = new CommaIO(fileName, "r");
io.read();
io.inFieldDelimiter(";");
if(fileName)
{
ttsBegin;
inventJournalTable.JournalNameId = inventJournalNameId;
inventJournalTable.initFromInventJournalName(InventJournalName::find(inventJournalNameId));
inventJournalTable.insert();
simpleProgress = SysOperationProgress::newGeneral(#aviUpdate,'Importing Transactions',100);///SysProgressOperation
while((io.status()==IO_Status::Ok))
{
con = io.read();
if (conlen(con) == 8)
{
j++;
simpleProgress.incCount();
simpleprogress.setText(strfmt("Transaction Imported: %1",i));
sleep(10);
axInventJournalTrans = new AxInventJournalTrans();
axInventJournalTrans.parmJournalId(inventJournalTable.JournalId);
axInventJournalTrans.parmTransDate( mkDate(30, 04, 2011));
axInventJournalTrans.parmLineNum(j);
axInventJournalTrans.parmItemId(conPeek(con, 3));
axInventJournalTrans.axInventDim().parmInventSiteId(conPeek(con, 6));
axInventJournalTrans.axInventDim().parmInventLocationId(conPeek(con, 7));
axInventJournalTrans.parmQty(conPeek(con, 4));
axInventJournalTrans.parmCostPrice(conPeek(con, 5));
axInventJournalTrans.parmLedgerAccountIdOffset(conPeek(con, 8));
axInventJournalTrans.save();
i++;
} //if
}
ttsCommit;
}
}
No comments:
Post a Comment