Announcements
I'm having a hard time in assigning the Fixed Asset transaction type programmatically
I've created an uploader which upload excel file to generate general journal....
How do I assign fixed asset transaction type.
I have tried this but it won't work
LedgerJournalTrans_AssetTransType = AssetTransTypeJournal::Depreciation;
Below is my code
public void uploadFromExcel()
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType variantType;
int row = 1, failedCtr = 0, lineNum = 1;
LedgerJournalTable jourTable;
LedgerJournalTrans jourTrans;
//new table PX
LedgerJournalTrans_Asset jourTransAsset;
//Classes
LedgerJournalTableData jourTableData;
LedgerJournalTransData jourTransData;
LedgerJournalStatic jourStatic;
DimensionDynamicAccount ledgerDim, offsetLedgerDim,
acctTypeDim, offsetAcctTypeDim;
DimensionDynamicAccount defaultDim, offsetDefaultDim;
LedgerJournalACType accountType;
#AviFiles
SysOperationProgress progressBar = new SysOperationProgress();
str sisTypeStr;
SISType curSIStype;
str grouping;
str voucher = "x";
str previousVoucher;
;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
try
{
workbooks.open(fileName);
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromName(worksheetName);
cells = worksheet.cells();
}
catch
{
application.quit();
throw error('File cannot be opened.');
}
if(!LedgerJournalName::exist(journalNameId))
{
error(strFmt("Journal Name %1 does not exist.", journalNameId));
return;
}
//Progress Bar and HourGlass Pointer
startLengthyOperation();
progressBar.setCaption(#Caption);
progressBar.setAnimation(#AviUpdate);
progressBar.setTotal(this.getLastRow(cells));
ttsBegin;
jourTableData = JournalTableData::newTable(jourTable);
jourTable.JournalNum = jourTableData.nextJournalId();
jourTable.JournalType = LedgerJournalType::Daily;
jourTable.JournalName = journalNameId;
jourTableData.initFromJournalName(LedgerJournalName::find(jourTable.JournalName));
jourStatic = jourTableData.journalStatic();
jourTransData = jourStatic.newJournalTransData(jourTrans, jourTableData);
do
{
try
{
row++;
/*
if(this.validateLines(cells, row))
{
failedCtr++;
break;
}
*/
progressBar.setText(#TextLine);
//account
accountType = this.ledgerAccountType(UploadingHelper::getCellStrValue(cells,column5,row));
if(UploadingHelper::getCellStrValue(cells, column6, row)!= "")
{
account = UploadingHelper::getCellStrValue(cells,column6,row);
finDim1 = UploadingHelper::getCellStrValue(cells,column10,row);
finDim2 = UploadingHelper::getCellStrValue(cells,column11,row);
finDim3 = UploadingHelper::getCellStrValue(cells,column12,row);
finDim4 = UploadingHelper::getCellStrValue(cells,column13,row);
finDim5 = UploadingHelper::getCellStrValue(cells,column14,row);
finDim6 = UploadingHelper::getCellStrValue(cells,column15,row);
finDim7 = UploadingHelper::getCellStrValue(cells,column16,row);
ledgerDim = this.ledgerDimension(
UploadingHelper::getCellStrValue(cells,column5,row),account,
finDim1,finDim2,finDim3,
finDim4,finDim5,finDim6,finDim7);
defaultDim = this.getDefaultDimension(finDim1,finDim2,finDim3,
finDim4,finDim5,finDim6,finDim7);
}
//offset
strOffsetAccount = UploadingHelper::getCellStrValue(cells, column18, row);
if(UploadingHelper::getCellStrValue(cells, column18, row)!= "")
{
strOffsetDimension1 = UploadingHelper::getCellStrValue(cells, column19, row);
strOffsetDimension2 = UploadingHelper::getCellStrValue(cells, column20, row);
strOffsetDimension3 = UploadingHelper::getCellStrValue(cells, column21, row);
strOffsetDimension4 = UploadingHelper::getCellStrValue(cells, column22, row);
strOffsetDimension5 = UploadingHelper::getCellStrValue(cells, column23, row);
strOffsetDimension6 = UploadingHelper::getCellStrValue(cells, column24, row);
strOffsetDimension7 = UploadingHelper::getCellStrValue(cells, column25, row);
offsetLedgerDim = this.ledgerDimension(UploadingHelper::getCellStrValue(cells,column17,row),
strOffsetAccount,strOffsetDimension1,strOffsetDimension2,strOffsetDimension3,
strOffsetDimension4,strOffsetDimension5,strOffsetDimension6,strOffsetDimension7);
offsetDefaultDim = this.getDefaultDimension(strOffsetDimension1,strOffsetDimension2,strOffsetDimension3,
strOffsetDimension4,strOffsetDimension5,strOffsetDimension6,strOffsetDimension7);
}
jourTrans.clear();
jourTransData.initFromJournalTable();
jourTrans.CurrencyCode = strLRTrim(cells.item(row, column26).value().bStr());
jourTrans.initValue();
jourTrans.TransDate = UploadingHelper::getCellDateValue(cells, column1, row);
if(account != "")
{
jourTrans.LedgerDimension = ledgerDim;
jourTrans.DefaultDimension = defaultDim;
}
if(strOffsetAccount != "")
{
jourTrans.OffsetLedgerDimension = offsetLedgerDim;
jourTrans.OffsetDefaultDimension= offsetDefaultDim;
}
jourTrans.Invoice = UploadingHelper::getCellStrValue(cells, column4, row);
jourTrans.Txt = UploadingHelper::getCellStrValue(cells, column7, row);
jourTrans.AmountCurDebit = UploadingHelper::getCellDoubleValue(cells, column8, row);
jourTrans.AmountCurCredit = UploadingHelper::getCellDoubleValue(cells, column9, row);
jourTrans.AccountType = this.ledgerAccountType(UploadingHelper::getCellStrValue(cells,column5,row));
jourTrans.OffsetAccountType = this.ledgerAccountType(UploadingHelper::getCellStrValue(cells, column17, row));
jourTrans.DocumentDate = UploadingHelper::getCellDateValue(cells, column2, row);
//jourTrans.PostingProfile = "test";
// jourTrans.
// jourTransAsset.TransType = AssetAccountType::AcquisitionAdj;
//jourTransAsset.TransType = AssetAccountType::AcquisitionAdj;
//can be compiled
//jourTransAsset.TransType = AssetTransTypeJournal::AcquisitionAdj;
jourTransAsset.TransType = AssetTransTypeJournal::Depreciation;
//jourTransAsset =
//From Setup
if(accountType == LedgerJournalACType::Cust)
{
jourTrans.PostingProfile = this.getPostingProfile(UploadingHelper::getCellStrValue(cells, column33, row));
}
else if(accountType == LedgerJournalACType::Vend)
{
jourTrans.PostingProfile = "GENERAL"; //double check client setup
}
else if(accountType == LedgerJournalACType::Ledger)
{
jourTrans.PostingProfile = "";
}
jourTrans.Payment = UploadingHelper::getCellStrValue(cells, column30, row);
if (strLRTrim(cells.item(row, column26).value().bStr()) != 'PHP')
{
jourTrans.ExchRate = cells.item(row, column27).value().double() * 100;
}
jourTrans.DocumentNum = UploadingHelper::getCellStrValue(cells, column28, row);
jourTrans.BankTransType = UploadingHelper::getCellStrValue(cells, column31, row);
jourTrans.PaymReference = UploadingHelper::getCellStrValue(cells, column32, row);
/* //JSG-20160303 - removed
sisTypeStr = UploadingHelper::getCellStrValue(cells, column33, row);
curSIStype = str2enum(curSIStype,sisTypeStr);
jourTrans.SISType = curSIStype;
*/
/// voucher
grouping = UploadingHelper::getCellStrValue(cells, column34, row);
if(grouping != voucher)
{
jourTrans.Voucher = new JournalVoucherNum(jourTableData).getNew(false);
previousVoucher = jourTrans.Voucher;
}
else
jourTrans.Voucher = previousVoucher;
voucher = grouping;
progressBar.setText(strFmt('Line %1', row));
progressBar.incCount();
jourTransData.insert();
//PX New
jourTransAsset.insert();
//info(strFmt("'%1' has been created", jourTable.JournalNum));
//clear value
}
catch
{
failedCtr++;
continue;
}
variantType = cells.item(row+1, column1).value().variantType();
}while (variantType != COMVariantType::VT_EMPTY);
if(failedCtr)
{
workbooks.close();
application.quit();
ttsAbort;
}
else
{
jourTable.insert();
ttsCommit;
workbooks.close();
application.quit();
info(#InfoPass);
}
}
Hope you'd help thanks!
Thank you very much sir :)
Hi Spamm, I'm not a developer but have done something similar with a colleague before. We used an event handler to get this fixed. Maybe take a look there dynamicsax-fico.com/.../excel-add-in-enhancements-2 to get some additional impression how this might work in your case. Hope this helps, Ludwig
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,186 Super User 2024 Season 2
Martin Dráb 227,996 Super User 2024 Season 2
nmaenpaa 101,148