public function actionRemoveImport($id)
 {
     if (Yii::$app->request->isAjax) {
         $transaction = Yii::$app->db->beginTransaction();
         try {
             echo 'Traflog deleted ' . Traflog::deleteAll(['id_logreport' => $id]) . ' rows.<br>';
             echo 'Matlog deleted ' . Matlog::deleteAll(['id_logreport' => $id]) . ' rows.<br>';
             echo 'Employeelog deleted ' . Employeelog::deleteAll(['id_logreport' => $id]) . ' rows.<br>';
             echo 'Logreport deleted ' . Logreport::deleteAll(['logreport_id' => $id]) . ' rows.<br>';
             $transaction->commit();
         } catch (Exception $e) {
             $transaction->rollBack();
             throw new Exception($e->getMessage());
         }
     }
 }
 /**
  * Выполняем удаление отчетов, если превышен лимит количества хранящихся отчетов.
  * @throws Exception
  */
 public function Execute()
 {
     foreach ($this->getNeedDeleteReports() as $Row) {
         $Transaction = Yii::$app->db->beginTransaction();
         try {
             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);
             $Transaction->commit();
         } catch (Exception $e) {
             $Transaction->rollBack();
             throw new Exception($e->getMessage() . ' logreport_id = ' . $Row['logreport_id']);
         }
     }
 }
Exemple #3
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);
             }
         }
     }
 }
Exemple #4
0
 /**
  * @return bool
  */
 private function inactiveLog()
 {
     $Forlog = Employee::find()->joinWith(['idperson', 'idpodraz', 'iddolzh', 'idbuild'])->andWhere(' DATE(employee_dateinactive) = CURDATE()')->andWhere(['employee_forinactive' => 2])->all();
     if (empty($Forlog)) {
         return false;
     } else {
         foreach ($Forlog as $i => $ar) {
             $Employeelog = new Employeelog();
             $Employeelog->id_logreport = $this->getLogReport()->primaryKey;
             $Employeelog->employeelog_type = 2;
             $Employeelog->employeelog_filename = $this->getFileName();
             $Employeelog->employeelog_filelastdate = $this->getFileLastDate();
             $Employeelog->employeelog_rownum = 0;
             $Employeelog->employeelog_message = 'Запись изменена. Специальность сотрудника неактивна с "' . Yii::$app->formatter->asDate($ar->employee_dateinactive) . '"';
             $Employeelog->employee_fio = $ar->idperson->auth_user_fullname;
             $Employeelog->dolzh_name = $ar->iddolzh->dolzh_name;
             $Employeelog->podraz_name = $ar->idpodraz->podraz_name;
             $Employeelog->build_name = $ar->isRelationPopulated('idbuild') ? $ar->idbuild['build_name'] : '';
             $Employeelog->save(false);
         }
     }
     return true;
 }
Exemple #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdemployeelog()
 {
     return $this->hasOne(Employeelog::className(), ['employeelog_id' => 'id_employeelog'])->from(['idemployeelog' => Employeelog::tableName()]);
 }
Exemple #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getEmployeelogs()
 {
     return $this->hasMany(Employeelog::className(), ['id_logreport' => 'logreport_id'])->from(['employeelogs' => Employeelog::tableName()]);
 }