https://www.youtube.com/watch?v=axTuEooZa9A&list=PL-YLHPDNPOL4SZuoDfC0JvRI8ETYiyzvS&index=9
MICROSOFT DYNAMICS AX
Sunday, 20 May 2018
Tuesday, 21 March 2017
Transfer PDF, Text file from one server to another server through code
We have a new requirement where we need to move the PDF file generated in one server and move it to another server
Create a new folder call Export in c drive and create text file to transfer in another server
After this try to execute this code, it will create sendTXTFile.bat file and execute it which will transfer in another server.
Static void UploadTxtFile(Args _args)
{
TextIo textIoFile;
Set permissionSet;
FileName filePath, filename;
FileName sharedLocation, batchFileName;
InteropPermission interopPerm;
System.Diagnostics.Process process;
System.Diagnostics.ProcessStartInfo processStartInfo;
System.Exception netException;
#File
filePath = 'c:\\Export'; //Create a Folder Export
sharedLocation = 'Location';
fileName = filePath + '\\Abdulmajeed.txt';//used Txt file to transfer
batchFileName = filePath + '\\sendTxtFile.bat';
try
{
if (System.IO.File::Exists(fileName))
{
permissionSet = new Set(Types::Class);
permissionSet.add(new FileIoPermission(batchFileName, #io_write));
CodeAccessPermission::assertMultiple(permissionSet);
textIoFile = new TextIo(batchFileName , #io_write, 0);
CodeAccessPermission::revertAssert();
textIoFile.write(strFmt("net use %1 PWDxxxxxx /user:UserName", sharedLocation));
textIoFile.write(strFmt("copy %1 %2", fileName ,sharedLocation));
textIoFile.write(strFmt("net use %1 /delete", sharedLocation));
textIoFile = null;
new InteropPermission(InteropKind::ClrInterop).assert();
process = new System.Diagnostics.Process();
processStartInfo = new System.Diagnostics.ProcessStartInfo();
processStartInfo.set_FileName(batchFileName);
processStartInfo.set_WorkingDirectory(filePath);
process.set_StartInfo(processStartInfo);
process.Start();
process.WaitForExit();
process.get_ExitCode();
CodeAccessPermission::revertAssert();
interopPerm = new InteropPermission(InteropKind::ClrInterop);
interopPerm.assert();
if (System.IO.File::Exists(batchFileName))
{
System.IO.File::Delete(batchFileName);
}
if (System.IO.File::Exists(fileName))
{
System.IO.File::Delete(fileName);
}
CodeAccessPermission::revertAssert();
}
else
{
throw error("File does not exist");
}
}
catch (Exception::CLRError)
{
netException = CLRInterop::getLastException();
throw error(netException.ToString());
}
}
SSRS Report Deployment Issue:
When we try to deploy any report some time this kind of issue will occur. Even we have proper Privilege on URL ( Site setting and folder setting in Report url )
In order to resolve this issue if you configuration is correct.
You can login as run as admin and deploy the report but user how have this property set to 1 will not be able to deploy the report.
To resolve this
Go to SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System and set EnableLUA values as 0 and restart the server and then go to DAT/System administration/Setup/Business intelligence/Reporting Services and open report server, Click on validate it will validate successfully and you can deploy the report with user
You can find complete detail about this key here: https://msdn.microsoft.com/en-us/library/cc232765.aspx
User roles and permission is very nicely explained here: http://bhushan.extreme-advice.com/user-roles-and-permissions-in-ssrs/
Walk through for defining permission on URL: https://www.mssqltips.com/sqlservertip/2793/sql-server-reporting-services-2012-permissions/
Sunday, 7 June 2015
Currency Conversion in Ax through X++ Code
static void CurrencyConversion(Args _args)
{
CurrencyExchHelper currencyExchangeHelper;
AmountMst amountMST;
CurrencyCode transCurrency;
AmountCur amountCur;
;
amountCur = 5000.00;
currencyExchangeHelper = CurrencyExchHelper::newExchDate(“KSI”,”USD”,systemDateGet());
amountMST = currencyExchangeHelper.calculateAmountCurToMst(amountCur ,true);
info(strFmt(“%1″,amountMST));
}
In Ms Dynamics Ax 2012
static void SR_CEHConversion(Args _args)
{
CurrencyExchangeHelper currencyExchangeHelper;
CurrencyCode transCurrency = ‘EUR’;
AmountCur amountCur = 500.00;
AmountMst amountMST;
currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), systemDateGet());
amountMST = currencyExchangeHelper.calculateTransactionToAccounting(transCurrency, amountCur ,true);
info(strFmt(‘%1′,amountMST));
}
{
CurrencyExchHelper currencyExchangeHelper;
AmountMst amountMST;
CurrencyCode transCurrency;
AmountCur amountCur;
;
amountCur = 5000.00;
currencyExchangeHelper = CurrencyExchHelper::newExchDate(“KSI”,”USD”,systemDateGet());
amountMST = currencyExchangeHelper.calculateAmountCurToMst(amountCur ,true);
info(strFmt(“%1″,amountMST));
}
In Ms Dynamics Ax 2012
static void SR_CEHConversion(Args _args)
{
CurrencyExchangeHelper currencyExchangeHelper;
CurrencyCode transCurrency = ‘EUR’;
AmountCur amountCur = 500.00;
AmountMst amountMST;
currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), systemDateGet());
amountMST = currencyExchangeHelper.calculateTransactionToAccounting(transCurrency, amountCur ,true);
info(strFmt(‘%1′,amountMST));
}
Sunday, 31 May 2015
Creation of Default Dimension
static void CreateDefaultDimension(Args _args)
{
DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
DimensionDefault result;
int i;
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;
// Note that "Item" is not one of the default dimension,
// but DimensionAttributeValueSetStorage will handle it gracefully
container conAttr = ["Department", "ExpensePurpose", "Item"];
container conValue = ["00000028", "Training", "1000"];
str dimValue;
for (i = 1; i <= conLen(conAttr); i++)
{
dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));
if (dimensionAttribute.RecId == 0)
{
continue;
}
dimValue = conPeek(conValue,i);
if (dimValue != "")
{
// The last parameter is "true". A dimensionAttributeValue record will be created if not found.
dimensionAttributeValue =
dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);
// Add the dimensionAttibuteValue to the default dimension
valueSetStorage.addItem(dimensionAttributeValue);
}
}
result = valueSetStorage.save();
info(strFmt("%1",result));
}
{
DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
DimensionDefault result;
int i;
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;
// Note that "Item" is not one of the default dimension,
// but DimensionAttributeValueSetStorage will handle it gracefully
container conAttr = ["Department", "ExpensePurpose", "Item"];
container conValue = ["00000028", "Training", "1000"];
str dimValue;
for (i = 1; i <= conLen(conAttr); i++)
{
dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));
if (dimensionAttribute.RecId == 0)
{
continue;
}
dimValue = conPeek(conValue,i);
if (dimValue != "")
{
// The last parameter is "true". A dimensionAttributeValue record will be created if not found.
dimensionAttributeValue =
dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);
// Add the dimensionAttibuteValue to the default dimension
valueSetStorage.addItem(dimensionAttributeValue);
}
}
result = valueSetStorage.save();
info(strFmt("%1",result));
}
Sunday, 17 May 2015
Custom Lookup in Ax
public void lookup(FormControl _formControl, str _filterStr)
{
sysTableLookup sysTableLookup;
Query query = New Query();
QueryBuildDataSource qbdsJour, qbdsTrans,qdbsVend;
QueryBuildRange qbr;
;
sysTableLookup = SysTableLookup::newParameters(tableNum(VendPackingSlipJour), _formControl);
qbdsJour = query.addDataSource(tableNum(VendPackingSlipJour));
qbdsTrans = qbdsJour.addDataSource(tableNum(VendPackingSlipTrans));
qbdsJour.relations(true);
qbr = qbdsTrans.addRange(fieldNum(VendPackingSlipTrans, ItemId));
qbr.value(<ItemId>);
qbdsTrans.relations(true);
sysTableLookup.addLookupfield(fieldNum(VendPackingSlipJour, GRNNumber_IN));
sysTableLookup.addLookupfield(fieldNum(VendPackingSlipJour, PurchId));
sysTableLookup.addLookupfield(fieldNum(VendPackingSlipJour, OrderAccount));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
{
sysTableLookup sysTableLookup;
Query query = New Query();
QueryBuildDataSource qbdsJour, qbdsTrans,qdbsVend;
QueryBuildRange qbr;
;
sysTableLookup = SysTableLookup::newParameters(tableNum(VendPackingSlipJour), _formControl);
qbdsJour = query.addDataSource(tableNum(VendPackingSlipJour));
qbdsTrans = qbdsJour.addDataSource(tableNum(VendPackingSlipTrans));
qbdsJour.relations(true);
qbr = qbdsTrans.addRange(fieldNum(VendPackingSlipTrans, ItemId));
qbr.value(<ItemId>);
qbdsTrans.relations(true);
sysTableLookup.addLookupfield(fieldNum(VendPackingSlipJour, GRNNumber_IN));
sysTableLookup.addLookupfield(fieldNum(VendPackingSlipJour, PurchId));
sysTableLookup.addLookupfield(fieldNum(VendPackingSlipJour, OrderAccount));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
Sunday, 26 April 2015
Importing Fixed Asset Opening Balance through CSV File
class CustFinancialDimension
{
}
static RecId createDimension(str custaccount)
{
dimensionAttribute dimensionAttribute;
dimensionAttributevalue dimensionAttributevalue;
DimensionAttributeValueSetStorage dimstorage;
RecId ret;
;
dimStorage = new DimensionAttributeValueSetStorage();
dimensionAttribute = AxdDimensionUtil::validateFinancialDimension("SystemGeneratedAttributeFixedAsset");
dimensionAttributeValue = AxdDimensionUtil::validateFinancialDimensionValue(dimensionAttribute, custAccount);
dimStorage.addItem(dimensionAttributeValue);
ret = dimStorage.save();
return Ret;
}
//------------------------------------------------------
public class FixedAssestsOpeningBalanceUpload extends RunBaseBatch
{
LedgerJournalId journalNum;
DialogField dialogFilename,dialogcheckbox,dialogFromDate,dialogledger;
Filename filename;
TransDate TransactionDate,Fromdate,TransDate,StartDate,enddate,reversedate;
NoYesID NoYes;
Ledgerjournalnameid Ledgerjournalnameid1,LedgerJournalNameId;
CommaIo csvFile;
currencycode currencycode;
args args;
container readCon;
container ledgerDimensions, offsetDimensions;
counter icount,inserted;
LedgerJournalTable ledgerJournalTable;
Map voucherMap;
#define.CurrentVersion(2)
#localmacro.CurrentList
filename,
insertIncorrectRecords,
#endmacro
#localmacro.ListVersion1
filename,
insertIncorrectRecords
#endmacro
#File
}
public Object dialog()
{
DialogRunbase dialog = super();
;
dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
dialogFilename.value(filename);
dialog.filenameLookupFilter(["All files", #AllFiles]);
dialogFromDate = dialog.addFieldValue(extendedtypestr(TransDate), TransactionDate,"TransactionDate");
dialogledger = dialog.addFieldvalue(extendedtypestr(LedgerJournalNameid),"JournalName","JournalName");
//dialogcheckbox = dialog.addFieldValue(enumstr(NoYes),"","Reversing","");
return dialog;
}
public boolean getFromDialog()
{
filename = dialogFilename.value();
FromDate = dialogFromDate.value();
//NoYes = dialogcheckbox.value();
Ledgerjournalnameid1 = dialogledger.Value();
return true;
}
public LedgerDimensionAccount getLedgerDimension(AccountNum _accountNum)
{
MainAccount mainAccount;
RefRecId accountStructureId;
List dimensionList = new List(Types::Class);
DimensionDefaultingEngine dimensionDefaultingEngine;
;
mainAccount = MainAccount::findByMainAccountId(_accountNum);
accountStructureId = DimensionHierarchy::getAccountStructure(mainAccount.RecId);
if(mainAccount)
{
dimensionDefaultingEngine = DimensionDefaultingEngine::constructForMainAccountId(mainAccount.RecId, accountStructureId);
dimensionDefaultingEngine.applyDimensionSources(dimensionList);
return dimensionDefaultingEngine.getLedgerDimension();
}
else
return 0;
}
public LedgerJournalId parmJournalNum(LedgerJournalId _journalNum = journalNum)
{
journalNum = _journalNum;
return journalNum;
}
static void main(Args args)
{
FixedAssestsOpeningBalanceUpload FixedAssestsOpeningBalanceUpload;
ledgerJournalTrans ledgerJournalTrans;
;
FixedAssestsOpeningBalanceUpload = new FixedAssestsOpeningBalanceUpload();
if(FixedAssestsOpeningBalanceUpload.prompt())
{
FixedAssestsOpeningBalanceUpload.run();
}
}
void run()
{
boolean first = true;
MainAccount mainAccount;
DimensionAttributeValueCombination dimensionAttributeValueCombination;
MainAccountNum mainAccountNum;
NumberSequenceTable numberSequenceTable;
LedgerJournalEngine_Daily ledgerJournalEngine_Daily;
Voucher voucher;
DimensionLedgerAccountType ledgerAccountType;
str accountType;
Amount amountCurDebit,amountCurCredit,amtcrdt,amtdebt;
container conSplitValue,dimm,offdim;
projTable projTable;
DimensionAttributeValueCombination ledgerDimension,dimensionAttributeValueCombinationrecid;
ProjId projid;
JournalTableData JournalTableData;
AxLedgerJournalTrans trans = new AxLedgerJournalTrans();
AxLedgerJournalTable header = new AxLedgerJournalTable();
str dimensn,offdimensn;
str 64 custAccount,ledgerAccount;
CustTable custtable;
dimensionAttribute dimensionAttribute;
dimensionAttributevalue dimensionAttributevalue;
DimensionAttributeValueSetStorage dimstorage;
int64 reccid;
Struct struct = new Struct();
container conledgerDimension;
DimensionDefault DimensionDefault;
str costcenter,department,revenueDimension,description;
//CISBillingInterfaceTable cisBillingInterfaceTable;
LedgerJournalACTypE acctype,offacctype;
DimensionStorage DimensionStorage;
LedgerJournalTrans ledgerJournalTrans;
LedgerJournalTrans_Asset ledgerJournalTransAssets;
AssetTable assetTable ;
LedgerDimensionDefaultAccount defaultAccount;
LedgerJournalEngine ledgerJournalEngine;
AssetBook assetBook;
str 64 assetid;
AssetTransTypeJournal transtype;
LedgerJournalName ledgerJournalName;
;
LedgerJournalNameId = Ledgerjournalnameid1;
TransDate= Fromdate;
csvFile = new CommaIO(filename, 'r');
try
{
if (csvFile)
{
ttsbegin;
if(first) //Create Journal Header
{
Select ledgerjournalname where ledgerjournalname.JournalName == LedgerJournalNameId;
if(!ledgerJournalName.RecId)
{
throw error ("ledgerJournalName doesn't exgist");
}
ledgerJournalTable.clear();
ledgerJournalTable.initValue();
ledgerJournalTable.JournalNum = JournalTableData::newTable(ledgerJournalTable).nextJournalId();
ledgerJournalTable.journalType = LedgerJournalType::Daily;
ledgerJournalTable.JournalName = ledgerJournalName.JournalName;
ledgerJournalTable.Name = ledgerJournalName.Name;
ledgerJournalTable.initFromLedgerJournalName(ledgerJournalName.JournalName);
ledgerJournalTable.insert();
first = false;
}
numberSequenceTable = NumberSequenceTable::find(LedgerJournalName::find(LedgerJournalNameId).NumberSequenceTable);
voucher = NumberSeq::newGetVoucherFromCode(numberSequenceTable.NumberSequence).voucher();
while (csvFile.status() == IO_Status::OK)
{
readCon = csvFile.read();
icount++;
amountCurDebit = 0;
amountCurCredit = 0;
if (readCon && icount )//dont insert first record of file : header
{
description = conPeek(readcon,1);
currencycode = conPeek(readCon,2);
acctype = conPeek(readCon,4);
amountCurDebit = conPeek(readCon,5);
amountCurCredit = conPeek(readCon,6);
ledgerAccount = conPeek(readCon,7);
assetid = conPeek(readCon,8);
transtype = conPeek(readCon,9);
ledgerJournalTrans.JournalNum = ledgerJournalTable.JournalNum;
assetTable=assetTable::find(assetid);
select assetBook where assetBook.AssetId == assetid;
ledgerJournalTrans.CurrencyCode = currencyCode;
ledgerJournalTrans.initValue();
ledgerJournalTrans.LedgerDimension = DimensionStorage::getDynamicAccount(assetid,acctype);
ledgerJournalTrans.parmAccount(AssetId, LedgerJournalACType::FixedAssets);
ledgerJournalTrans.TransDate = transDate;
ledgerJournalTrans.Txt = description;
ledgerJournalTrans.AccountType = acctype;
ledgerJournalTrans.Voucher = voucher;
ledgerJournalTrans.PostingProfile =AssetParameters::find().PostingProfile;
ledgerJournalTrans.Company = curext();
ledgerJournalTrans.OffsetCompany = curext();
ledgerJournalTrans.OffsetDefaultDimension = 0;
dimm = [ledgeraccount,ledgeraccount,"",""];
ledgerJournalTrans.OffsetAccountType = LedgerJournalACType::Ledger;
ledgerJournalTrans.AmountCurCredit = amountCurCredit;
ledgerJournalTrans.AmountCurDebit = amountCurDebit;
ledgerJournalTrans.DefaultDimension = CustFinancialDimension::CreateDimension(AssetId);
ledgerJournalTrans.OffsetAccountType = ledgerJournalTable.OffsetAccountType;
ledgerJournalTrans.OffsetLedgerDimension = DimensionDefaultingService::serviceCreateLedgerDimension(ledgerJournalTable.OffsetLedgerDimension, ledgerJournalTrans.DefaultDimension);
defaultAccount = AssetTable::find(assetTable.AssetId).assetOffsetLedgerDimension(ledgerJournalTrans.PostingProfile,
AssetPost::assetTransTypeJournal2AssetTransType(AssetTransTypeJournal::Acquisition),
AssetBook.BookId);
ledgerJournalTrans.OffsetLedgerDimension = this.getLedgerDimension(ledgerAccount);
ledgerJournalTrans.calcAmountMST();
ledgerJournalTrans.insert();
ledgerJournalTransAssets.BookId = assetBook.BookId;
ledgerJournalTransAssets.TransType = AssetTransTypeJournal::Depreciation;
ledgerJournalTransAssets.AssetId = ledgerJournalTrans.parmAccount();
ledgerJournalTransAssets.Company = ledgerJournalTrans.Company;
ledgerJournalEngine = new LedgerJournalEngine();
ledgerJournalEngine.initDefaultDimension(ledgerJournalTrans, ledgerJournalTransAssets);
ledgerJournalTransAssets.RefRecId = ledgerJournalTrans.RecId;
ledgerJournalTransAssets.insert();
inserted++;
} // if ends
} // while ends
ttsCommit;
} // if ends
icount--;
} // try ends
catch(Exception::Error)
{
info(strFmt("%1 %2",Exception::Error,icount));
}
args = new Args();
args.record(LedgerJournalTable::find(ledgerjournaltable.JournalNum ));
new MenuFunction(MenuItemDisplayStr(LedgerJournalTable),MenuItemType::Display).run(args);
}
{
}
static RecId createDimension(str custaccount)
{
dimensionAttribute dimensionAttribute;
dimensionAttributevalue dimensionAttributevalue;
DimensionAttributeValueSetStorage dimstorage;
RecId ret;
;
dimStorage = new DimensionAttributeValueSetStorage();
dimensionAttribute = AxdDimensionUtil::validateFinancialDimension("SystemGeneratedAttributeFixedAsset");
dimensionAttributeValue = AxdDimensionUtil::validateFinancialDimensionValue(dimensionAttribute, custAccount);
dimStorage.addItem(dimensionAttributeValue);
ret = dimStorage.save();
return Ret;
}
//------------------------------------------------------
public class FixedAssestsOpeningBalanceUpload extends RunBaseBatch
{
LedgerJournalId journalNum;
DialogField dialogFilename,dialogcheckbox,dialogFromDate,dialogledger;
Filename filename;
TransDate TransactionDate,Fromdate,TransDate,StartDate,enddate,reversedate;
NoYesID NoYes;
Ledgerjournalnameid Ledgerjournalnameid1,LedgerJournalNameId;
CommaIo csvFile;
currencycode currencycode;
args args;
container readCon;
container ledgerDimensions, offsetDimensions;
counter icount,inserted;
LedgerJournalTable ledgerJournalTable;
Map voucherMap;
#define.CurrentVersion(2)
#localmacro.CurrentList
filename,
insertIncorrectRecords,
#endmacro
#localmacro.ListVersion1
filename,
insertIncorrectRecords
#endmacro
#File
}
public Object dialog()
{
DialogRunbase dialog = super();
;
dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
dialogFilename.value(filename);
dialog.filenameLookupFilter(["All files", #AllFiles]);
dialogFromDate = dialog.addFieldValue(extendedtypestr(TransDate), TransactionDate,"TransactionDate");
dialogledger = dialog.addFieldvalue(extendedtypestr(LedgerJournalNameid),"JournalName","JournalName");
//dialogcheckbox = dialog.addFieldValue(enumstr(NoYes),"","Reversing","");
return dialog;
}
public boolean getFromDialog()
{
filename = dialogFilename.value();
FromDate = dialogFromDate.value();
//NoYes = dialogcheckbox.value();
Ledgerjournalnameid1 = dialogledger.Value();
return true;
}
public LedgerDimensionAccount getLedgerDimension(AccountNum _accountNum)
{
MainAccount mainAccount;
RefRecId accountStructureId;
List dimensionList = new List(Types::Class);
DimensionDefaultingEngine dimensionDefaultingEngine;
;
mainAccount = MainAccount::findByMainAccountId(_accountNum);
accountStructureId = DimensionHierarchy::getAccountStructure(mainAccount.RecId);
if(mainAccount)
{
dimensionDefaultingEngine = DimensionDefaultingEngine::constructForMainAccountId(mainAccount.RecId, accountStructureId);
dimensionDefaultingEngine.applyDimensionSources(dimensionList);
return dimensionDefaultingEngine.getLedgerDimension();
}
else
return 0;
}
public LedgerJournalId parmJournalNum(LedgerJournalId _journalNum = journalNum)
{
journalNum = _journalNum;
return journalNum;
}
static void main(Args args)
{
FixedAssestsOpeningBalanceUpload FixedAssestsOpeningBalanceUpload;
ledgerJournalTrans ledgerJournalTrans;
;
FixedAssestsOpeningBalanceUpload = new FixedAssestsOpeningBalanceUpload();
if(FixedAssestsOpeningBalanceUpload.prompt())
{
FixedAssestsOpeningBalanceUpload.run();
}
}
void run()
{
boolean first = true;
MainAccount mainAccount;
DimensionAttributeValueCombination dimensionAttributeValueCombination;
MainAccountNum mainAccountNum;
NumberSequenceTable numberSequenceTable;
LedgerJournalEngine_Daily ledgerJournalEngine_Daily;
Voucher voucher;
DimensionLedgerAccountType ledgerAccountType;
str accountType;
Amount amountCurDebit,amountCurCredit,amtcrdt,amtdebt;
container conSplitValue,dimm,offdim;
projTable projTable;
DimensionAttributeValueCombination ledgerDimension,dimensionAttributeValueCombinationrecid;
ProjId projid;
JournalTableData JournalTableData;
AxLedgerJournalTrans trans = new AxLedgerJournalTrans();
AxLedgerJournalTable header = new AxLedgerJournalTable();
str dimensn,offdimensn;
str 64 custAccount,ledgerAccount;
CustTable custtable;
dimensionAttribute dimensionAttribute;
dimensionAttributevalue dimensionAttributevalue;
DimensionAttributeValueSetStorage dimstorage;
int64 reccid;
Struct struct = new Struct();
container conledgerDimension;
DimensionDefault DimensionDefault;
str costcenter,department,revenueDimension,description;
//CISBillingInterfaceTable cisBillingInterfaceTable;
LedgerJournalACTypE acctype,offacctype;
DimensionStorage DimensionStorage;
LedgerJournalTrans ledgerJournalTrans;
LedgerJournalTrans_Asset ledgerJournalTransAssets;
AssetTable assetTable ;
LedgerDimensionDefaultAccount defaultAccount;
LedgerJournalEngine ledgerJournalEngine;
AssetBook assetBook;
str 64 assetid;
AssetTransTypeJournal transtype;
LedgerJournalName ledgerJournalName;
;
LedgerJournalNameId = Ledgerjournalnameid1;
TransDate= Fromdate;
csvFile = new CommaIO(filename, 'r');
try
{
if (csvFile)
{
ttsbegin;
if(first) //Create Journal Header
{
Select ledgerjournalname where ledgerjournalname.JournalName == LedgerJournalNameId;
if(!ledgerJournalName.RecId)
{
throw error ("ledgerJournalName doesn't exgist");
}
ledgerJournalTable.clear();
ledgerJournalTable.initValue();
ledgerJournalTable.JournalNum = JournalTableData::newTable(ledgerJournalTable).nextJournalId();
ledgerJournalTable.journalType = LedgerJournalType::Daily;
ledgerJournalTable.JournalName = ledgerJournalName.JournalName;
ledgerJournalTable.Name = ledgerJournalName.Name;
ledgerJournalTable.initFromLedgerJournalName(ledgerJournalName.JournalName);
ledgerJournalTable.insert();
first = false;
}
numberSequenceTable = NumberSequenceTable::find(LedgerJournalName::find(LedgerJournalNameId).NumberSequenceTable);
voucher = NumberSeq::newGetVoucherFromCode(numberSequenceTable.NumberSequence).voucher();
while (csvFile.status() == IO_Status::OK)
{
readCon = csvFile.read();
icount++;
amountCurDebit = 0;
amountCurCredit = 0;
if (readCon && icount )//dont insert first record of file : header
{
description = conPeek(readcon,1);
currencycode = conPeek(readCon,2);
acctype = conPeek(readCon,4);
amountCurDebit = conPeek(readCon,5);
amountCurCredit = conPeek(readCon,6);
ledgerAccount = conPeek(readCon,7);
assetid = conPeek(readCon,8);
transtype = conPeek(readCon,9);
ledgerJournalTrans.JournalNum = ledgerJournalTable.JournalNum;
assetTable=assetTable::find(assetid);
select assetBook where assetBook.AssetId == assetid;
ledgerJournalTrans.CurrencyCode = currencyCode;
ledgerJournalTrans.initValue();
ledgerJournalTrans.LedgerDimension = DimensionStorage::getDynamicAccount(assetid,acctype);
ledgerJournalTrans.parmAccount(AssetId, LedgerJournalACType::FixedAssets);
ledgerJournalTrans.TransDate = transDate;
ledgerJournalTrans.Txt = description;
ledgerJournalTrans.AccountType = acctype;
ledgerJournalTrans.Voucher = voucher;
ledgerJournalTrans.PostingProfile =AssetParameters::find().PostingProfile;
ledgerJournalTrans.Company = curext();
ledgerJournalTrans.OffsetCompany = curext();
ledgerJournalTrans.OffsetDefaultDimension = 0;
dimm = [ledgeraccount,ledgeraccount,"",""];
ledgerJournalTrans.OffsetAccountType = LedgerJournalACType::Ledger;
ledgerJournalTrans.AmountCurCredit = amountCurCredit;
ledgerJournalTrans.AmountCurDebit = amountCurDebit;
ledgerJournalTrans.DefaultDimension = CustFinancialDimension::CreateDimension(AssetId);
ledgerJournalTrans.OffsetAccountType = ledgerJournalTable.OffsetAccountType;
ledgerJournalTrans.OffsetLedgerDimension = DimensionDefaultingService::serviceCreateLedgerDimension(ledgerJournalTable.OffsetLedgerDimension, ledgerJournalTrans.DefaultDimension);
defaultAccount = AssetTable::find(assetTable.AssetId).assetOffsetLedgerDimension(ledgerJournalTrans.PostingProfile,
AssetPost::assetTransTypeJournal2AssetTransType(AssetTransTypeJournal::Acquisition),
AssetBook.BookId);
ledgerJournalTrans.OffsetLedgerDimension = this.getLedgerDimension(ledgerAccount);
ledgerJournalTrans.calcAmountMST();
ledgerJournalTrans.insert();
ledgerJournalTransAssets.BookId = assetBook.BookId;
ledgerJournalTransAssets.TransType = AssetTransTypeJournal::Depreciation;
ledgerJournalTransAssets.AssetId = ledgerJournalTrans.parmAccount();
ledgerJournalTransAssets.Company = ledgerJournalTrans.Company;
ledgerJournalEngine = new LedgerJournalEngine();
ledgerJournalEngine.initDefaultDimension(ledgerJournalTrans, ledgerJournalTransAssets);
ledgerJournalTransAssets.RefRecId = ledgerJournalTrans.RecId;
ledgerJournalTransAssets.insert();
inserted++;
} // if ends
} // while ends
ttsCommit;
} // if ends
icount--;
} // try ends
catch(Exception::Error)
{
info(strFmt("%1 %2",Exception::Error,icount));
}
args = new Args();
args.record(LedgerJournalTable::find(ledgerjournaltable.JournalNum ));
new MenuFunction(MenuItemDisplayStr(LedgerJournalTable),MenuItemType::Display).run(args);
}
Subscribe to:
Posts (Atom)