Advertisement
dlwjdc

Financial dimensions

Feb 11th, 2020
2,753
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XPP 5.38 KB | None | 0 0
  1. public class RKVCreateDailyJournalWithFinancialDimensions
  2. {        
  3.     /// <summary>
  4.     /// Runs the class with the specified arguments.
  5.     /// </summary>
  6.     /// <param name = "_args">The specified arguments.</param>
  7.     public static void main(Args _args)
  8.     {        
  9.         LedgerJournalEngine ledgerJournalEngine = LedgerJournalEngine::construct(LedgerJournalType::Daily);
  10.         LedgerJournalTable ledgerJournalTable;
  11.         LedgerJournalTableData ledgerJournalTableData = JournalTableData::newTable(ledgerJournalTable);
  12.         LedgerJournalTrans ledgerJournalTrans;
  13.         Voucher mySavedVoucher;
  14.        
  15.         ttsbegin;
  16.  
  17.         // Create the ledger journal table
  18.         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
  19.         ledgerJournalTable.JournalType = LedgerJournalType::Daily;
  20.         ledgerJournalTable.JournalName = RKVIFParameters::find().LedgerJournalName;
  21.        
  22.         ledgerJournalTableData.initFromJournalName(ledgerJournalTableData.journalStatic().findJournalName(ledgerJournalTable.JournalName));
  23.  
  24.         if(!ledgerJournalTable.validateWrite())
  25.             throw Exception::Error;
  26.  
  27.         ledgerJournalTable.insert();
  28.  
  29.         // create the first line - don't do this in real code, do this in a loop
  30.         ledgerJournalEngine.newJournalActive(ledgerJournalTable);
  31.         ledgerJournalTrans.initValue();
  32.         ledgerJournalEngine.initValue(ledgerJournalTrans);
  33.         ledgerJournalTrans.TransDate = today();
  34.         ledgerJournalTrans.AmountCurDebit = 50;
  35.         ledgerJournalTrans.AccountType = LedgerJournalACType::Ledger;
  36.         // don't do it in real code with a private static ofcourse! Use the class variables and generate it in a seperate method
  37.         ledgerJournalTrans.LedgerDimension = RKVCreateDailyJournalWithFinancialDimensions::generateLedgerDimension("6011070000","0520000");
  38.         ledgerJournalTrans.Txt = "some text";
  39.        
  40.         if(!ledgerJournalTrans.validateWrite())
  41.             throw Exception::Error;
  42.  
  43.         ledgerJournalTrans.insert();
  44.         // 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
  45.         mySavedVoucher = ledgerJournalTrans.Voucher;
  46.        
  47.         // create the second line, again, don't do it like this in real code
  48.         ledgerJournalTrans.clear();
  49.         ledgerJournalTrans.initValue();
  50.         ledgerJournalEngine.initValue(ledgerJournalTrans);
  51.         ledgerJournalTrans.TransDate = today();
  52.         ledgerJournalTrans.AmountCurCredit = 50;
  53.         ledgerJournalTrans.AccountType = LedgerJournalACType::Ledger;
  54.         ledgerJournalTrans.LedgerDimension = RKVCreateDailyJournalWithFinancialDimensions::generateLedgerDimension("4390900000", ""); // no costcenter here
  55.         ledgerJournalTrans.Txt = "some text";
  56.         ledgerJournalTrans.Voucher = mySavedVoucher; // add the same voucher as the first line
  57.        
  58.         if(!ledgerJournalTrans.validateWrite())
  59.             throw Exception::Error;
  60.  
  61.         ledgerJournalTrans.insert();
  62.  
  63.         ttscommit;
  64.     }
  65.  
  66.     private static DimensionDynamicAccount generateLedgerDimension(MainAccountNum _mainAccountId, DimensionValue _costCenter)
  67.     {
  68.         DimensionAttribute dimensionAttribute;
  69.         DimensionAttributeValue dimensionAttributeValue;
  70.         DimensionStorage dimensionStorage;
  71.         LedgerAccountContract ledgerAccountContract = new LedgerAccountContract();
  72.         DimensionAttributeValueContract valueContract;
  73.         List valueContracts = new List(Types::Class);
  74.         DimensionAttributeValueCombination dimensionAttributeValueCombination; // this is the ledger dimension record
  75.  
  76.         // create a value contract for the cost center financial dimension, only if there is one
  77.         if(_costCenter)
  78.         {
  79.             // use a beter name for this to identify the cost center financial dimension here, 'LedgerJournalDimensionName' is too generic
  80.             // Get the financial dimension and value
  81.             dimensionAttribute = DimensionAttribute::findByName(RKVIFParameters::find().LedgerJournalDimensionName);
  82.             dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, _costCenter, false, true);
  83.            
  84.             // create e new value contract with the name and value of the financial dimension, if you have more, add them to the list
  85.             valueContract = new DimensionAttributeValueContract();
  86.             valueContract.parmName(dimensionAttribute.Name);
  87.             valueContract.parmValue(dimensionAttributeValue.CachedDisplayValue);
  88.  
  89.             // add the value contracts to the value contracts list
  90.             valueContracts.addEnd(valueContract);
  91.         }
  92.        
  93.         ledgerAccountContract.parmMainAccount(_mainAccountId);
  94.         ledgerAccountContract.parmValues(valueContracts);
  95.  
  96.         // use the standard class to generate a new ledger dimension and return it
  97.         dimensionStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(ledgerAccountContract);
  98.         dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimensionStorage.save());
  99.        
  100.         return dimensionAttributeValueCombination.RecId;
  101.     }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement