static void Import_GL_LedgerJournal_CSV(Args _args)///and also it will import the data from the Excel
{
LedgerJournalName ledgerJournalName;
LedgerJournalTable ledgerjournalTable;
Axledgerjournaltrans axledgerjournaltrans;
LedgerJournalTrans ledgerJournalTrans;
LedgerJournalTrans_Asset ledgerJournalTrans_asset;
LedgerJournalACType ledgerJournalACType;
Numberseq _NumberSeq;
Voucher numbervoucher;
Dialog dialog;
DialogField dialogField,dialogField2,dialogdate;
Filename filename;
CommaIO io;
Container con;
Container filterCriteria;
str val, qtyStr, priceStr, tgl, tgl_due;
str acctype,offacctype,_bookId,prepay;
COMVariant cOMVariant;
int i,j,k;
SysOperationProgress simpleProgress;
#avifiles
;
Dialog = new 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;
ledgerJournalTable.JournalName = "GL-BEGIN";
ledgerJournalTable.Name = " Saldo Awal ";
ledgerJournalTable.initFromLedgerJournalName();
ledgerJournalTable.insert();
ttscommit;
_NumberSeq = NumberSeq::newGetVoucherFromCode(ledgerJournalName::find(ledgerJournalTable.JournalName).VoucherSeries);
numbervoucher = _NumberSeq.voucher();
simpleProgress = SysOperationProgress::newGeneral(#aviUpdate,'Importing Transactions',100);///SysProgressOperation
while((io.status()==IO_Status::Ok))
{
con = io.read();
if (conlen(con) == 26)
{
j++;
simpleProgress.incCount();
simpleprogress.setText(strfmt("Transaction Imported: %1",i));
sleep(10);
tgl = conPeek(con, 22);
tgl_due = conPeek(con, 22);
_BookId = conPeek(con, 19);
acctype = conPeek(con, 3);
offacctype = conPeek(con, 2);
prepay = conPeek(con, 26);
axledgerjournaltrans = new Axledgerjournaltrans();
axledgerjournaltrans.parmJournalNum(ledgerJournalTable.JournalNum);
// mm-dd-yy --> 213, dd-mm-yy --> 123
axledgerjournaltrans.parmTransDate(str2date(tgl,213));
//info(tgl + ' - ' + date2str(str2date(tgl,213),123,2,2,2,2,4));
axledgerjournaltrans.parmVoucher(conPeek(con, 17));
switch(acctype) //accounttype
{
case "Ledger":
axledgerjournaltrans.parmAccountType(ledgerJournalACType::Ledger);
break;
case "Customer":
axledgerjournaltrans.parmAccountType(ledgerJournalACType::Cust);
break;
case "Vendor":
axledgerjournaltrans.parmAccountType(ledgerJournalACType::Vend);
break;
case "Fixed assets":
axledgerjournaltrans.parmAccountType(ledgerJournalACType::FixedAssets);
break;
case "Bank":
axledgerjournaltrans.parmAccountType(ledgerJournalACType::Bank);
break;
}
axledgerjournaltrans.parmAccountNum(conPeek(con, 4));
axledgerjournaltrans.parmTxt(conPeek(con, 6));
axledgerjournaltrans.parmPostingProfile(conPeek(con, 8));
if (prepay == "Y" )
{
axledgerjournaltrans.parmPrepayment(Noyes::Yes);
}
else
{
axledgerjournaltrans.parmPrepayment(Noyes::No);
}
axledgerjournaltrans.parmAmountCurDebit(conPeek(con, 11));
axledgerjournaltrans.parmAmountCurCredit(conPeek(con, 10));
switch(offacctype) //offset accounttype
{
case "Ledger":
axledgerjournaltrans.parmOffsetAccountType(ledgerJournalACType::Ledger);
break;
case "Customer":
axledgerjournaltrans.parmOffsetAccountType(ledgerJournalACType::Cust);
break;
case "Vendor":
axledgerjournaltrans.parmOffsetAccountType(ledgerJournalACType::Vend);
break;
case "Fixed assets":
axledgerjournaltrans.parmOffsetAccountType(ledgerJournalACType::FixedAssets);
break;
case "Bank":
axledgerjournaltrans.parmOffsetAccountType(ledgerJournalACType::Bank);
break;
}
axledgerjournaltrans.parmOffsetAccount(conPeek(con, 5));
axledgerjournaltrans.parmDue(str2date(tgl_due,123));
axledgerjournaltrans.parmDocumentDate(str2date(tgl,123));
axledgerjournaltrans.save();
/*
if(acctype == "Fixed assets")
{
if(axledgerjournaltrans.ledgerJournalTrans().RecId)
{
ttsbegin;
ledgerJournalTrans_asset.RefRecId = axledgerjournaltrans.ledgerJournalTrans().RecId;
ledgerJournalTrans_asset.AssetId = axledgerjournaltrans.ledgerJournalTrans().getAssetId();
ledgerJournalTrans_Asset.Company = axledgerjournaltrans.ledgerJournalTrans().getAssetCompany();
ledgerJournalTrans_asset.BookId = _BookId;
ledgerJournalTrans_asset.TransType = AssetTransTypeJournal::Acquisition;
ledgerJournalTrans_asset.TransType = AssetTransTypeJournal::Depreciation;
if(assetype == "A")
ledgerJournalTrans_asset.TransType = AssetTransTypeJournal::Acquisition;
else
ledgerJournalTrans_asset.TransType = AssetTransTypeJournal::Depreciation;
ledgerJournalTrans_asset.insert();
ttscommit;
}
}
*/
i++;
} //if
}//while
}//if filename
}
No comments:
Post a Comment