Quintiq file version 2.0 
 | 
#parent: #root 
 | 
StaticMethod SynchronizeWithTemplate ( 
 | 
  MacroPlan owner, 
 | 
  Accounts accounttemplates 
 | 
) 
 | 
{ 
 | 
  Description: 'Synchronize with accounts in scenario manager' 
 | 
  TextBody: 
 | 
  [* 
 | 
    // Reset all account's IsInTemplate flag 
 | 
    traverse( owner, Account_MP, a ) 
 | 
    { 
 | 
      a.IsInTemplate( false ); 
 | 
    } 
 | 
     
 | 
    // Traverse all passed in accounts and use them as templates to update/create accounts 
 | 
    traverse( accounttemplates, Elements, template ) 
 | 
    { 
 | 
      // Look for the account with the same name as template 
 | 
      account := select( owner, Account_MP, acct, acct.Name() = template.Name() ); 
 | 
     
 | 
      // Create account if it is not found 
 | 
      if( isnull( account ) ) 
 | 
      { 
 | 
        account := Account_MP::Create( owner, template ); 
 | 
      } 
 | 
      // Else, update the matching account 
 | 
      else 
 | 
      { 
 | 
        account.Update( template.AccountTypeName(), 
 | 
                        template.ParentName(), 
 | 
                        template.ReportType(), 
 | 
                        template.DefaultCost(), 
 | 
                        template.DefaultCostDriver(), 
 | 
                        template.DefaultLengthOfTime(), 
 | 
                        template.DefaultTimeUnit(), 
 | 
                        template.DisplayIndex(), 
 | 
                        template.IsMaximize(), 
 | 
                        template.IsUsedByOptimizer() ); 
 | 
      } 
 | 
      // Set account's IsInTemplate flag to true 
 | 
      account.IsInTemplate( true ); 
 | 
    } 
 | 
     
 | 
    // Delete all accounts that is not is template 
 | 
    traverse( owner, Account_MP, a, not a.IsInTemplate() ) 
 | 
    { 
 | 
      a.Delete(); 
 | 
    } 
 | 
     
 | 
    // Sort Account_MP according to it's display index 
 | 
    owner.SortAccount( attribute( Account_MP, DisplayIndexForTemplate ), true ); 
 | 
  *] 
 | 
} 
 |