Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RKVCreateDailyJournalWithFinancialDimensions
- {
- /// <summary>
- /// Runs the class with the specified arguments.
- /// </summary>
- /// <param name = "_args">The specified arguments.</param>
- public static void main(Args _args)
- {
- LedgerJournalEngine ledgerJournalEngine = LedgerJournalEngine::construct(LedgerJournalType::Daily);
- LedgerJournalTable ledgerJournalTable;
- LedgerJournalTableData ledgerJournalTableData = JournalTableData::newTable(ledgerJournalTable);
- LedgerJournalTrans ledgerJournalTrans;
- Voucher mySavedVoucher;
- ttsbegin;
- // Create the ledger journal table
- ledgerJournalTable.JournalNum = "DVB-001003"; // Note: fill in journal number manually in this job because the functional setup is not completed yet on this dev box, just increment by one each time. Do it properly in real code
- ledgerJournalTable.JournalType = LedgerJournalType::Daily;
- ledgerJournalTable.JournalName = RKVIFParameters::find().LedgerJournalName;
- ledgerJournalTableData.initFromJournalName(ledgerJournalTableData.journalStatic().findJournalName(ledgerJournalTable.JournalName));
- if(!ledgerJournalTable.validateWrite())
- throw Exception::Error;
- ledgerJournalTable.insert();
- // create the first line - don't do this in real code, do this in a loop
- ledgerJournalEngine.newJournalActive(ledgerJournalTable);
- ledgerJournalTrans.initValue();
- ledgerJournalEngine.initValue(ledgerJournalTrans);
- ledgerJournalTrans.TransDate = today();
- ledgerJournalTrans.AmountCurDebit = 50;
- ledgerJournalTrans.AccountType = LedgerJournalACType::Ledger;
- // don't do it in real code with a private static ofcourse! Use the class variables and generate it in a seperate method
- ledgerJournalTrans.LedgerDimension = RKVCreateDailyJournalWithFinancialDimensions::generateLedgerDimension("6011070000","0520000");
- ledgerJournalTrans.Txt = "some text";
- if(!ledgerJournalTrans.validateWrite())
- throw Exception::Error;
- ledgerJournalTrans.insert();
- // save the voucher of the first line so the journal can be posted without balance issues - don't do it like this in real code
- mySavedVoucher = ledgerJournalTrans.Voucher;
- // create the second line, again, don't do it like this in real code
- ledgerJournalTrans.clear();
- ledgerJournalTrans.initValue();
- ledgerJournalEngine.initValue(ledgerJournalTrans);
- ledgerJournalTrans.TransDate = today();
- ledgerJournalTrans.AmountCurCredit = 50;
- ledgerJournalTrans.AccountType = LedgerJournalACType::Ledger;
- ledgerJournalTrans.LedgerDimension = RKVCreateDailyJournalWithFinancialDimensions::generateLedgerDimension("4390900000", ""); // no costcenter here
- ledgerJournalTrans.Txt = "some text";
- ledgerJournalTrans.Voucher = mySavedVoucher; // add the same voucher as the first line
- if(!ledgerJournalTrans.validateWrite())
- throw Exception::Error;
- ledgerJournalTrans.insert();
- ttscommit;
- }
- private static DimensionDynamicAccount generateLedgerDimension(MainAccountNum _mainAccountId, DimensionValue _costCenter)
- {
- DimensionAttribute dimensionAttribute;
- DimensionAttributeValue dimensionAttributeValue;
- DimensionStorage dimensionStorage;
- LedgerAccountContract ledgerAccountContract = new LedgerAccountContract();
- DimensionAttributeValueContract valueContract;
- List valueContracts = new List(Types::Class);
- DimensionAttributeValueCombination dimensionAttributeValueCombination; // this is the ledger dimension record
- // create a value contract for the cost center financial dimension, only if there is one
- if(_costCenter)
- {
- // use a beter name for this to identify the cost center financial dimension here, 'LedgerJournalDimensionName' is too generic
- // Get the financial dimension and value
- dimensionAttribute = DimensionAttribute::findByName(RKVIFParameters::find().LedgerJournalDimensionName);
- dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, _costCenter, false, true);
- // create e new value contract with the name and value of the financial dimension, if you have more, add them to the list
- valueContract = new DimensionAttributeValueContract();
- valueContract.parmName(dimensionAttribute.Name);
- valueContract.parmValue(dimensionAttributeValue.CachedDisplayValue);
- // add the value contracts to the value contracts list
- valueContracts.addEnd(valueContract);
- }
- ledgerAccountContract.parmMainAccount(_mainAccountId);
- ledgerAccountContract.parmValues(valueContracts);
- // use the standard class to generate a new ledger dimension and return it
- dimensionStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(ledgerAccountContract);
- dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimensionStorage.save());
- return dimensionAttributeValueCombination.RecId;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement