/**
  * Finds the Importconfig model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Importconfig the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Importconfig::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Сеттер для максимального количества отчетов импорта из 1С, настройка из базы данных.
  * @return bool True, если присвоение успешно.
  */
 private function setMaxReportsFiles()
 {
     $config = Importconfig::findOne(1);
     if (empty($config)) {
         return false;
     }
     $this->_maxReportsFiles = $config->logreport_reportcount;
     return true;
 }
 public function actionIndex()
 {
     $searchModel = new LogreportSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     $Importconfig = Importconfig::findOne(1);
     if ($Importconfig->load(Yii::$app->request->post()) && $Importconfig->save()) {
         return $this->redirect(Proc::GetPreviousURLBreadcrumbsFromSession());
     } else {
         return $this->render('index', ['Importconfig' => $Importconfig, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
     }
 }
 public function actionUpdateProfiles()
 {
     $Importconfig = Importconfig::findOne(1);
     $filename = 'imp/' . $Importconfig['emp_filename'] . '.txt';
     if (file_exists($filename)) {
         ini_set('max_execution_time', $Importconfig['max_execution_time']);
         // 1000 seconds
         ini_set('memory_limit', $Importconfig['memory_limit']);
         // 1Gbyte Max Memory
         $i = 0;
         $j = 0;
         $handle = @fopen($filename, "r");
         if ($handle) {
             $UTF8deleteBOM = true;
             while (($subject = fgets($handle, 4096)) !== false) {
                 if ($UTF8deleteBOM) {
                     $subject = str_replace("", '', $subject);
                     $UTF8deleteBOM = false;
                 }
                 $pattern = '/^(.*?)\\|(Поликлиника №\\s?[1,2,3] )?(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|/ui';
                 preg_match($pattern, $subject, $matches);
                 $employee_fio = $matches[1];
                 $AuthuserCount = Authuser::find()->where(['like', 'auth_user_fullname', $employee_fio, false])->count();
                 $Authuser = $AuthuserCount == 1 ? Authuser::find()->where(['like', 'auth_user_fullname', $employee_fio, false])->one() : false;
                 if (!empty($Authuser)) {
                     $Profile = Profile::findOne($Authuser->primaryKey);
                     $Profile = empty($Profile) ? new Profile() : $Profile;
                     $Profile->profile_id = $Authuser->primaryKey;
                     $Profile->profile_dr = $matches[16];
                     $Profile->profile_pol = $matches[15];
                     $Profile->profile_inn = $matches[11];
                     $Profile->profile_snils = $matches[12];
                     $Profile->profile_address = $matches[10];
                     $Profile->save();
                     if ($Profile->getErrors()) {
                         var_dump($Profile->getErrors());
                     } else {
                         $i++;
                     }
                 }
                 $j++;
             }
             fclose($handle);
             echo 'Профилей создано ' . $i . ' из ' . $j;
         }
     } else {
         echo 'Файл не существует ' . $filename;
     }
 }
Exemple #5
0
 private static function DeleteOldReports()
 {
     $countreports = Importconfig::findOne(1);
     if (!empty($countreports)) {
         $files = glob('importreports/*.xlsx');
         if (count($files) > $countreports->logreport_reportcount) {
             $ToDelete = Logreport::find()->select(['logreport_id'])->orderBy(['logreport_id' => SORT_ASC])->limit(count($files) - $countreports->logreport_reportcount)->asArray()->all();
         }
         if (!empty($ToDelete)) {
             foreach ($ToDelete as $row) {
                 Traflog::deleteAll(['id_logreport' => $row['logreport_id']]);
                 Matlog::deleteAll(['id_logreport' => $row['logreport_id']]);
                 Employeelog::deleteAll(['id_logreport' => $row['logreport_id']]);
                 Logreport::findOne($row['logreport_id'])->delete();
                 $fileroot = 'importreports/Отчет импорта в систему Фрегат N' . $row['logreport_id'] . '.xlsx';
                 if (DIRECTORY_SEPARATOR !== '/') {
                     $fileroot = mb_convert_encoding($fileroot, 'Windows-1251', 'UTF-8');
                 }
                 unlink($fileroot);
             }
         }
     }
 }