static void ProjectItemJournalCreate(Args _args)
{
InventJournalTableData JournalTableData;
InventJournalTransData journalTransData;
InventJournalTable journalTable;
InventJournalTrans journalTrans;
InventTable InventTable;
CommaTextIO csvFile;
container readCon;
counter icount,inserted;
Dialog dialog;
DialogField dfFileName;
FileName fileName;
ProjTable projTable;
inventDim inventDim;
inserted =0;
#File
dialog = new Dialog("Pick the file");
dfFileName = dialog.addField(extendedTypeStr("FilenameOpen"));
dialog.filenameLookupFilter(["All files", #AllFiles]);
if (dialog.run())
{
csvFile = new CommaTextIo(dfFileName.value(), 'r');
csvFile.inFieldDelimiter(',');
readCon = csvFile.read();
ttsBegin;
journalTableData = JournalTableData::newTable(journalTable);
journalTransData = journalTableData.journalStatic().newJournalTransData(journalTrans,journalTableData);
// Init JournalTable
journalTable.clear();
journalTable.JournalId = journalTableData.nextJournalId();
journalTable.JournalType = InventJournalType::project;
journalTable.JournalNameId = "ProjItem";
while(csvFile.status() == IO_Status::OK)
{
readCon = csvFile.read();
if(readCon)
{
icount++;
// Init JournalTrans
journalTableData.initFromJournalName(journalTableData.journalStatic().findJournalName(journalTable.JournalNameId));
journalTrans.clear();
journalTransData.initFromJournalTable();
projTable = ProjTable::find(conPeek(readCon,1));
journalTrans.TransDate = systemDateGet();
journalTrans.ProjId = conPeek(readCon,1);
inventDim.InventSiteId = "2";
inventDim.InventLocationId = "21";
inventDim = InventDim::findOrCreate(inventDim);
journalTrans.InventDimId = inventDim.inventDimId;
journalTrans.Qty = str2num(conPeek(readCon,2));
journalTrans.costPrice = str2num(conPeek(readCon,3));
journalTrans.ItemId = conPeek(readCon,4);
journalTrans.ProjUnitID = conPeek(readCon,5);
journalTrans.ProjLinePropertyId = "charge";//projTable.psaRetainageBillingDesc();
journalTrans.ProjCategoryId = "car audio";
journalTrans.ProjSalesCurrencyId = "usd";//ProjInvoiceTable::find(projTable.ProjInvoiceProjId).CurrencyId;
journalTrans.Worker = HcmWorker::userId2Worker(curUserId());
journalTrans.ProjSalesPrice = 10;
//journalTrans.Voucher = NumberSeq::newGetVoucherFromCode(JournalTable.getNumberSequenceTable().NumberSequence).voucher();
journalTransData.create();
}
}
journalTable.insert();
ttsCommit;
}
}
{
InventJournalTableData JournalTableData;
InventJournalTransData journalTransData;
InventJournalTable journalTable;
InventJournalTrans journalTrans;
InventTable InventTable;
CommaTextIO csvFile;
container readCon;
counter icount,inserted;
Dialog dialog;
DialogField dfFileName;
FileName fileName;
ProjTable projTable;
inventDim inventDim;
inserted =0;
#File
dialog = new Dialog("Pick the file");
dfFileName = dialog.addField(extendedTypeStr("FilenameOpen"));
dialog.filenameLookupFilter(["All files", #AllFiles]);
if (dialog.run())
{
csvFile = new CommaTextIo(dfFileName.value(), 'r');
csvFile.inFieldDelimiter(',');
readCon = csvFile.read();
ttsBegin;
journalTableData = JournalTableData::newTable(journalTable);
journalTransData = journalTableData.journalStatic().newJournalTransData(journalTrans,journalTableData);
// Init JournalTable
journalTable.clear();
journalTable.JournalId = journalTableData.nextJournalId();
journalTable.JournalType = InventJournalType::project;
journalTable.JournalNameId = "ProjItem";
while(csvFile.status() == IO_Status::OK)
{
readCon = csvFile.read();
if(readCon)
{
icount++;
// Init JournalTrans
journalTableData.initFromJournalName(journalTableData.journalStatic().findJournalName(journalTable.JournalNameId));
journalTrans.clear();
journalTransData.initFromJournalTable();
projTable = ProjTable::find(conPeek(readCon,1));
journalTrans.TransDate = systemDateGet();
journalTrans.ProjId = conPeek(readCon,1);
inventDim.InventSiteId = "2";
inventDim.InventLocationId = "21";
inventDim = InventDim::findOrCreate(inventDim);
journalTrans.InventDimId = inventDim.inventDimId;
journalTrans.Qty = str2num(conPeek(readCon,2));
journalTrans.costPrice = str2num(conPeek(readCon,3));
journalTrans.ItemId = conPeek(readCon,4);
journalTrans.ProjUnitID = conPeek(readCon,5);
journalTrans.ProjLinePropertyId = "charge";//projTable.psaRetainageBillingDesc();
journalTrans.ProjCategoryId = "car audio";
journalTrans.ProjSalesCurrencyId = "usd";//ProjInvoiceTable::find(projTable.ProjInvoiceProjId).CurrencyId;
journalTrans.Worker = HcmWorker::userId2Worker(curUserId());
journalTrans.ProjSalesPrice = 10;
//journalTrans.Voucher = NumberSeq::newGetVoucherFromCode(JournalTable.getNumberSequenceTable().NumberSequence).voucher();
journalTransData.create();
}
}
journalTable.insert();
ttsCommit;
}
}
No comments:
Post a Comment