public void clicked()
{
LedgerJournalTable ledgerJournalTableloc;
LedgerJournalTrans ledgerJournalTransloc,ledgerJournalTrans1;
NumberSequenceTable numberSequenceTable;
NumberSeq numberSeq;
FormRun formrun;
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
LedgerJournalACType ljcType;
FileName filename;
real value;
RefRecId ledgerdim,ledgerdim1;
container con;
int row = 1;
// date testdate , validfromdate ,validtodate ;
str invoicenum,Currency1 , Currency2;
Dialog dialog;
DialogField selectfile;
JournalFormTable journalFormTable;
super();
//formrun = element.args().caller();
// formrun = journalFormTable.formRun();
ledgerJournalTableloc = element.args().record() ;
info(ledgerJournalTableloc.JournalNum);
// validfromdate = FromDate.dateValue();
// validtodate = ToDate.dateValue();
dialog = new Dialog("Please select the file to load");
dialog.addText("Select file:");
selectfile = dialog.addField(ExtendedTypeStr("FilenameOpen"));
dialog.run();
if (dialog.closedOK())
{
application = SysExcelApplication::construct();
workbooks = application.workbooks();
filename =selectfile.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
{
row++;
// testdate = cells.item(row, 1).value().date();
// Currency1 = cells.item(row, 2).value().bStr();
// Currency2 = cells.item(row, 3).value().bStr();
// value = any2real(cells.item(row,4).value().bStr());
//if ( ledgerJournalTableloc)
// {
ledgerJournalTransloc.JournalNum = ledgerJournalTableloc.JournalNum;
ledgerJournalTransloc.TransDate = cells.item(row, 1).value().date();
ledgerJournalTransloc.Company = curext();//range.get_Item(i, 3).value;
ledgerJournalTransloc.AccountType = LedgerJournalACType::Cust;
ledgerdim1 = DimensionStorage::getDynamicAccount(cells.item(row, 3).value().bStr(), LedgerJournalACType::Cust);
// ledgerdim1 = ledgerJournalTrans1.parmLedgerDimension(DimensionStorage::accountNum2LedgerDimension(
//cells.item(row, 3).value().bStr(),
//LedgerJournalACType::Cust)
//,curext());
ledgerJournalTransloc.LedgerDimension = ledgerdim1;
//ledgerJournalTransloc.LedgerDimension = DimensionStorage::getDynamicAccount(
// cells.item(row, 3).value().bStr(),
// LedgerJournalACType::Cust);
ledgerJournalTransloc.Txt = cells.item(row, 4).value().bStr();
ledgerJournalTransloc.AmountCurDebit = any2Real(cells.item(row, 5).value().bStr());
ledgerJournalTransloc.AmountCurCredit = any2real(cells.item(row, 6).value().bStr());
ledgerJournalTransloc.CurrencyCode = cells.item(row, 7).value().bStr();
ledgerJournalTransloc.OffsetAccountType = str2Enum(ljcType,cells.item(row, 9).value().bStr());
if (ledgerJournalTransloc.OffsetAccountType == LedgerJournalACType::Ledger)
{
con = [cells.item(row, 10).value().bStr() ,cells.item(row, 10).value().bStr(),
2,"businessunit", cells.item(row, 15).value().bStr(),"department",cells.item(row, 16).value().bStr()];
ledgerdim = AxdDimensionUtil::getLedgerAccountId(con);
ledgerJournalTransloc.OffsetLedgerDimension = ledgerdim;
}
ledgerJournalTransloc.DocumentNum = cells.item(row, 12).value().bStr();
ledgerJournalTransloc.DocumentDate = cells.item(row, 13).value().date();
ledgerJournalTransloc.Due =any2date( cells.item(row, 14).value().date());
ttsBegin;
numberSeq = NumberSeq::newGetVoucherFromId(ledgerJournalTableloc.NumberSequenceTable, false);
ledgerJournalTransloc.Voucher = numberSeq.voucher();
ttsCommit;
// numberSequenceTable = NumberSequenceTable::find(LedgerJournalName::find (ledgerJournalTableloc.JournalName).NumberSequenceTable);
// ledgerJournalTransloc.Voucher = NumberSeq::newGetVoucherFromCode(numberSequenceTable.NumberSequence).voucher();
invoicenum = ledgerJournalTransloc.daxInvoicenum(ledgerJournalTableloc.JournalNum);
ledgerJournalTransloc.DaxInvoiceNum = invoicenum ;
ledgerJournalTransloc.initValue();
ledgerJournalTransloc.insert();
//}
type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
application.quit();
}
}
But In D365 fo above SysExcelApplication classes are removed. To Knw the proces in D365 fo follow my Next blog
No comments:
Post a Comment