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);
}
I liked your blog.Thanks for your interest in sharing your ideas.keep doing more.
ReplyDeleteMS Dynamics Online Training