/**
  * @return array Errors  Import Template information
  */
 public static function importTemplates($root, $companyId, &$errors)
 {
     $nodeTemplates = $root->getElementsByTagName('template');
     foreach ($nodeTemplates as $nodeTemplate) {
         if ($root->getAttribute('version') > 1.0) {
             $errors[] = '*TemplateVersion*' . Yii::t('lazy8', 'There maybe problems because this is a file version greater then this programs version');
             $errors[] = Yii::t('lazy8', 'Select a file and try again');
         }
         $modelTemplate = new Template();
         $modelTemplate->companyId = $companyId;
         $modelTemplate->name = $nodeTemplate->getAttribute('name');
         $modelTemplate->desc = $nodeTemplate->getAttribute('desc');
         $modelTemplate->sortOrder = $nodeTemplate->getAttribute('sortorder');
         $modelTemplate->allowAccountingView = $nodeTemplate->getAttribute('allowaccountingview') == '1' ? 1 : 0;
         $modelTemplate->allowFreeTextField = $nodeTemplate->getAttribute('allowfreetextfield') == '1' ? 1 : 0;
         $modelTemplate->freeTextFieldDefault = $nodeTemplate->getAttribute('freetextfielddefault');
         $modelTemplate->allowFilingTextField = $nodeTemplate->getAttribute('allowfilingtextfield') == '1' ? 1 : 0;
         $modelTemplate->filingTextFieldDefault = $nodeTemplate->getAttribute('filingtextfielddefault');
         $modelTemplate->forceDateToday = $nodeTemplate->getAttribute('forcedatetoday');
         if (!$modelTemplate->save()) {
             $errors[] = Yii::t('lazy8', 'Could not create the modelTemplate, bad paramters') . ';name=' . $modelTemplate->name . ';' . serialize($modelTemplate->getErrors());
             return $errors;
         }
         $nodesTemplateRows = $nodeTemplate->getElementsByTagName('templaterow');
         foreach ($nodesTemplateRows as $nodesTemplateRow) {
             $modelTemplateRow = new TemplateRow();
             $modelTemplateRow->templateId = $modelTemplate->id;
             $modelTemplateRow->name = $nodesTemplateRow->getAttribute('name');
             $modelTemplateRow->desc = $nodesTemplateRow->getAttribute('desc');
             $modelTemplateRow->sortOrder = $nodesTemplateRow->getAttribute('sortorder');
             $modelTemplateRow->isDebit = $nodesTemplateRow->getAttribute('isdebit') == '1' ? 1 : 0;
             $modelTemplateRow->defaultAccountId = Template::FindAccountId($nodesTemplateRow->getAttribute('defaultaccount'), $modelTemplate->companyId);
             $modelTemplateRow->defaultValue = $nodesTemplateRow->getAttribute('defaultvalue');
             $modelTemplateRow->allowMinus = $nodesTemplateRow->getAttribute('allowminus') == '1' ? 1 : 0;
             $modelTemplateRow->phpFieldCalc = $nodesTemplateRow->getAttribute('phpfieldcalc');
             $modelTemplateRow->allowChangeValue = $nodesTemplateRow->getAttribute('allowchangevalue') == '1' ? 1 : 0;
             $modelTemplateRow->allowRepeatThisRow = $nodesTemplateRow->getAttribute('allowrepeatthisrow') == '1' ? 1 : 0;
             $modelTemplateRow->allowCustomer = $nodesTemplateRow->getAttribute('allowcustomer') == '1' ? 1 : 0;
             $modelTemplateRow->allowNotes = $nodesTemplateRow->getAttribute('allownotes') == '1' ? 1 : 0;
             $modelTemplateRow->isFinalBalance = $nodesTemplateRow->getAttribute('isfinalbalance') == '1' ? 1 : 0;
             if (!$modelTemplateRow->save()) {
                 $modelTemplate->delete();
                 $errors[] = Yii::t('lazy8', 'Could not create the TemplateRow, bad paramters') . ';' . serialize($modelTemplateRow->getErrors());
                 return;
             }
             $nodesTemplateRowAccounts = $nodesTemplateRow->getElementsByTagName('templaterowaccount');
             foreach ($nodesTemplateRowAccounts as $nodesTemplateRowAccount) {
                 $modelTemplateRowAccount = new TemplateRowAccount();
                 $modelTemplateRowAccount->templateRowId = $modelTemplateRow->id;
                 $modelTemplateRowAccount->accountId = Template::FindAccountId($nodesTemplateRowAccount->getAttribute('code'), $modelTemplate->companyId);
                 if ($modelTemplateRowAccount->accountId != 0) {
                     if (!$modelTemplateRowAccount->save()) {
                         $modelTemplate->delete();
                         $errors[] = Yii::t('lazy8', 'Could not create the TemplateRowAccount, bad paramters') . ';' . serialize($modelTemplateRowAccount->getErrors());
                         return;
                     }
                 } else {
                     $errors[] = Yii::t('lazy8', 'Could not create the Account, bad account number') . ';' . $nodesTemplateRowAccount->getAttribute('code');
                 }
             }
         }
     }
 }