コード例 #1
0
ファイル: main.php プロジェクト: alaevka/stigit.basalt
</li>
			<?php 
        }
    }
    ?>
			<?php 
    //check if isset overdue issues
    $tasks = \app\models\Tasks::find()->all();
    $list = [];
    foreach ($tasks as $task) {
        $id = $task->ID;
        $persons = \app\models\PersTasks::find()->where(['TASK_ID' => $id, 'DEL_TRACT_ID' => 0])->all();
        if ($persons) {
            $states_array = [];
            foreach ($persons as $person) {
                $pers_tasks = \app\models\PersTasks::find()->where(['TASK_ID' => $id, 'TN' => $person->TN, 'DEL_TRACT_ID' => 0])->one();
                $task_state = \app\models\TaskStates::find()->where(['IS_CURRENT' => 1, 'PERS_TASKS_ID' => $pers_tasks->ID, 'TASK_ID' => $id])->one();
                if ($task_state) {
                    $states_array[] = $task_state->STATE_ID;
                } else {
                    $list[] = $id;
                }
            }
            if (!empty($states_array)) {
                $min_state = min($states_array);
                $state = \app\models\States::findOne($min_state);
            }
        }
        if (isset($state)) {
            if ($state->ID != 7 || $state->ID != 9) {
                $list[] = $id;
コード例 #2
0
ファイル: Tasks.php プロジェクト: alaevka/stigit.basalt
 public function _getStatusPerson()
 {
     $persons = \app\models\PersTasks::find()->where(['TASK_ID' => $this->ID, 'DEL_TRACT_ID' => 0])->all();
     if ($persons) {
         $list = '';
         foreach ($persons as $person) {
             $query = new \yii\db\Query();
             $query->select('*')->from('STIGIT.V_F_PERS')->where('TN = \'' . $person->TN . '\'');
             $command = $query->createCommand();
             $data = $command->queryOne();
             //$list .= '<nobr><a href="'.Url::to(['user', 'id'=>$person->TN]).'">'.$data['FAM'].' '.mb_substr($data['IMJ'], 0, 1, 'UTF-8').'. '.mb_substr($data['OTCH'], 0, 1, 'UTF-8').'.</a></nobr><br>';
             //get current state
             $pers_tasks = \app\models\PersTasks::find()->where(['TASK_ID' => $this->ID, 'TN' => $person->TN, 'DEL_TRACT_ID' => 0])->one();
             $task_state = \app\models\TaskStates::find()->where(['IS_CURRENT' => 1, 'PERS_TASKS_ID' => $pers_tasks->ID, 'TASK_ID' => $this->ID])->one();
             if ($task_state) {
                 $state = $task_state->getState_name_state_colour_without_text();
                 $state_date = $task_state->getStateDate();
             } else {
                 $state = '';
                 $state_date = '';
             }
             $list .= '<nobr>' . $state . '&nbsp;<a href="' . Url::to(['user', 'id' => $person->TN]) . '">' . $data['FIO'] . '</a></nobr><br>';
         }
         return $list;
     } else {
         $podr = \app\models\PodrTasks::find()->where(['TASK_ID' => $this->ID])->all();
         if ($podr) {
             $list = '';
             foreach ($podr as $task) {
                 $query = new \yii\db\Query();
                 $query->select('*')->from('STIGIT.V_F_PODR')->where('KODZIFR = \'' . trim($task->KODZIFR) . '\'');
                 $command = $query->createCommand();
                 $data = $command->queryOne();
                 if (isset($data['NAIMPODR'])) {
                     $list .= $data['NAIMPODR'] . "<br>";
                 }
             }
             return $list;
         }
     }
 }
コード例 #3
0
ファイル: SearchTasks.php プロジェクト: alaevka/stigit.basalt
 public function search($params)
 {
     $query = Tasks::find();
     //формируем провайдер
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     //задание сортировки по умолчанию
     $dataProvider->sort->attributes = ['TASKS.ID' => ['asc' => ['TASKS.ID' => SORT_ASC], 'desc' => ['TASKS.ID' => SORT_DESC]]];
     $dataProvider->sort->defaultOrder = ['TASKS.ID' => SORT_DESC];
     //overdue issues filter
     if (isset($params['overdue']) && $params['overdue'] == 1) {
         $tasks = \app\models\Tasks::find()->all();
         $list = [];
         foreach ($tasks as $task) {
             $id = $task->ID;
             $persons = \app\models\PersTasks::find()->where(['TASK_ID' => $id, 'DEL_TRACT_ID' => 0])->all();
             if ($persons) {
                 $states_array = [];
                 foreach ($persons as $person) {
                     $pers_tasks = \app\models\PersTasks::find()->where(['TASK_ID' => $id, 'TN' => $person->TN, 'DEL_TRACT_ID' => 0])->one();
                     $task_state = \app\models\TaskStates::find()->where(['IS_CURRENT' => 1, 'PERS_TASKS_ID' => $pers_tasks->ID, 'TASK_ID' => $id])->one();
                     if ($task_state) {
                         $states_array[] = $task_state->STATE_ID;
                     } else {
                         $list[] = $id;
                     }
                 }
                 if (!empty($states_array)) {
                     $min_state = min($states_array);
                     $state = \app\models\States::findOne($min_state);
                 }
             }
             if (isset($state)) {
                 if ($state->ID != 7 || $state->ID != 9) {
                     $list[] = $id;
                 }
             }
         }
         $list = array_unique($list);
         $query->andFilterWhere(['TASKS.ID' => $list]);
         $now = date("Y-m-d");
         $query->andFilterWhere(['<', 'TASKS.DEADLINE', new \yii\db\Expression("to_date('" . $now . "','{$this->dateFormat}')")]);
         $query->joinWith('perstasks');
         $query->andFilterWhere(['PERS_TASKS.TN' => \Yii::$app->user->id]);
     }
     //own issues filter
     if (isset($params['own_issues']) && $params['own_issues'] == 1) {
         $query->joinWith('perstasks');
         $query->andFilterWhere(['PERS_TASKS.TN' => \Yii::$app->user->id]);
     }
     if (isset($params['for_person']) && $params['for_person'] != '') {
         $query->joinWith('perstasks');
         $query->andFilterWhere(['PERS_TASKS.TN' => $params['for_person']]);
     }
     if (isset($params['for_podr']) && $params['for_podr'] != '') {
         $query->joinWith('podrtasks');
         $query->andFilterWhere(['PODR_TASKS.KODZIFR' => $params['for_podr']]);
     }
     //podr issues filter
     if (isset($params['podr_issues']) && $params['podr_issues'] == 1) {
         //check permission
         $permissions_podr_tasks_my = \app\models\Permissions::find()->where('(SUBJECT_TYPE = :subject_type and SUBJECT_ID = :user_id and DEL_TRACT_ID = :del_tract and PERM_LEVEL != :perm_level and ACTION_ID = :action) or
             (SUBJECT_TYPE = :subject_type_dolg and SUBJECT_ID = :id_dolg and DEL_TRACT_ID = :del_tract and PERM_LEVEL != :perm_level and ACTION_ID = :action)', ['subject_type_dolg' => 1, 'id_dolg' => \Yii::$app->session->get('user.user_iddolg'), 'action' => 21, 'subject_type' => 2, 'user_id' => \Yii::$app->user->id, 'del_tract' => 0, 'perm_level' => 0])->one();
         if ($permissions_podr_tasks_my) {
             if ($permissions_podr_tasks_my->PERM_LEVEL == 1 || $permissions_podr_tasks_my->PERM_LEVEL == 2) {
                 //get podr id of this user
                 $query_dao = new \yii\db\Query();
                 $query_dao->select('*')->from('STIGIT.V_F_PERS')->where('TN = \'' . \Yii::$app->user->id . '\'');
                 $command = $query_dao->createCommand();
                 $data = $command->queryOne();
                 //вот тут решить что означает выданные моему подразделению
                 $query->joinWith('podrtasks');
                 $query->andFilterWhere(['PODR_TASKS.KODZIFR' => trim($data['KODZIFR'])]);
             } else {
                 throw new \yii\web\ForbiddenHttpException('У Вас нет прав на "Выданные любым задания"');
             }
         } else {
             throw new \yii\web\ForbiddenHttpException('У Вас нет прав на "Выданные любым задания"');
         }
     }
     //tasks my filter
     if (isset($params['tasks_my']) && $params['tasks_my'] == 1) {
         //check permission
         $permissions_podr_tasks_my = \app\models\Permissions::find()->where('(SUBJECT_TYPE = :subject_type and SUBJECT_ID = :user_id and DEL_TRACT_ID = :del_tract and PERM_LEVEL != :perm_level and ACTION_ID = :action) or
         (SUBJECT_TYPE = :subject_type_dolg and SUBJECT_ID = :id_dolg and DEL_TRACT_ID = :del_tract and PERM_LEVEL != :perm_level and ACTION_ID = :action)', ['subject_type_dolg' => 1, 'id_dolg' => \Yii::$app->session->get('user.user_iddolg'), 'action' => 23, 'subject_type' => 2, 'user_id' => \Yii::$app->user->id, 'del_tract' => 0, 'perm_level' => 0])->one();
         if ($permissions_podr_tasks_my) {
             if ($permissions_podr_tasks_my->PERM_LEVEL == 1 || $permissions_podr_tasks_my->PERM_LEVEL == 2) {
                 //get all current user transactions
                 $transactions = \app\models\Transactions::find()->where(['TN' => \Yii::$app->user->id])->all();
                 if ($transactions) {
                     $transactions_array = [];
                     foreach ($transactions as $transaction) {
                         $transactions_array[] = $transaction->ID;
                     }
                     $query->andFilterWhere(['TRACT_ID' => $transactions_array]);
                 }
             } else {
                 throw new \yii\web\ForbiddenHttpException('У Вас нет прав на "Выданные лично задания"');
             }
         } else {
             throw new \yii\web\ForbiddenHttpException('У Вас нет прав на "Выданные лично задания"');
         }
     }
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     //проверяем существует ли фильтр и добавляем его в запрос провайдера для каждого из полей фильтра
     if (!empty($this->states)) {
         $query->joinWith('taskstates');
         $query->andFilterWhere(['TASK_STATES.STATE_ID' => $this->states]);
     }
     if (!empty($this->podr_list)) {
         $podr_list = array_map('trim', explode(',', $this->podr_list));
         $query->joinWith('podrtasks');
         $query->andFilterWhere(['PODR_TASKS.KODZIFR' => $podr_list]);
     }
     if (!empty($this->agreed_podr_list)) {
         $agreed_podr_list = array_map('trim', explode(',', $this->agreed_podr_list));
         $query->joinWith('taskconfirms');
         $query->andFilterWhere(['TASK_CONFIRMS.KODZIFR' => $agreed_podr_list]);
     }
     if (!empty($this->persons_list)) {
         $persons_list = array_map('trim', explode(',', $this->persons_list));
         $query->joinWith('perstasks');
         $query->andFilterWhere(['PERS_TASKS.TN' => $persons_list]);
     }
     if (!empty($this->documentation)) {
         $query->joinWith('taskdocs');
         $query->andFilterWhere(['TASK_DOCS.DOC_CODE' => $this->documentation]);
     }
     if ($this->deadline_from != '' && $this->deadline_to != '') {
         $deadline_from = explode('-', $this->deadline_from);
         $deadline_from_formatted = $deadline_from[2] . '-' . $deadline_from[1] . '-' . $deadline_from[0];
         $deadline_to = explode('-', $this->deadline_to);
         $deadline_to_formatted = $deadline_to[2] . '-' . $deadline_to[1] . '-' . $deadline_to[0];
         $query->andFilterWhere(['>=', 'DEADLINE', new \yii\db\Expression("to_date('" . $deadline_from_formatted . "','{$this->dateFormat}')")])->andFilterWhere(['<=', 'DEADLINE', new \yii\db\Expression("to_date('" . $deadline_to_formatted . "','{$this->dateFormat}')")]);
     } else {
         if ($this->deadline_from != '' && $this->deadline_to == '') {
             $deadline_from = explode('-', $this->deadline_from);
             $deadline_from_formatted = $deadline_from[2] . '-' . $deadline_from[1] . '-' . $deadline_from[0];
             $query->andFilterWhere(['>=', 'DEADLINE', new \yii\db\Expression("to_date('" . $deadline_from_formatted . "','{$this->dateFormat}')")]);
         } else {
             if ($this->deadline_from == '' && $this->deadline_to != '') {
                 $deadline_to = explode('-', $this->deadline_to);
                 $deadline_to_formatted = $deadline_to[2] . '-' . $deadline_to[1] . '-' . $deadline_to[0];
                 $query->andFilterWhere(['<=', 'DEADLINE', new \yii\db\Expression("to_date('" . $deadline_to_formatted . "','{$this->dateFormat}')")]);
             }
         }
     }
     if ($this->task_type_date_3_from != '' && $this->task_type_date_3_to != '') {
         $query->joinWith('datetype3');
         $task_type_date_3_from = explode('-', $this->task_type_date_3_from);
         $task_type_date_3_from_formatted = $task_type_date_3_from[2] . '-' . $task_type_date_3_from[1] . '-' . $task_type_date_3_from[0];
         $task_type_date_3_to = explode('-', $this->task_type_date_3_to);
         $task_type_date_3_to_formatted = $task_type_date_3_to[2] . '-' . $task_type_date_3_to[1] . '-' . $task_type_date_3_to[0];
         $query->andFilterWhere(['>=', 'TASK_DATES.TASK_TYPE_DATE', new \yii\db\Expression("to_date('" . $task_type_date_3_from_formatted . "','{$this->dateFormat}')")])->andFilterWhere(['<=', 'TASK_DATES.TASK_TYPE_DATE', new \yii\db\Expression("to_date('" . $task_type_date_3_to_formatted . "','{$this->dateFormat}')")]);
     } else {
         if ($this->task_type_date_3_from != '' && $this->task_type_date_3_to == '') {
             $query->joinWith('datetype3');
             $task_type_date_3_from = explode('-', $this->task_type_date_3_from);
             $task_type_date_3_from_formatted = $task_type_date_3_from[2] . '-' . $task_type_date_3_from[1] . '-' . $task_type_date_3_from[0];
             $query->andFilterWhere(['>=', 'TASK_DATES.TASK_TYPE_DATE', new \yii\db\Expression("to_date('" . $task_type_date_3_from_formatted . "','{$this->dateFormat}')")]);
         } else {
             if ($this->task_type_date_3_from == '' && $this->task_type_date_3_to != '') {
                 $query->joinWith('datetype3');
                 $task_type_date_3_to = explode('-', $this->task_type_date_3_to);
                 $task_type_date_3_to_formatted = $task_type_date_3_to[2] . '-' . $task_type_date_3_to[1] . '-' . $task_type_date_3_to[0];
                 $query->andFilterWhere(['<=', 'TASK_DATES.TASK_TYPE_DATE', new \yii\db\Expression("to_date('" . $task_type_date_3_to_formatted . "','{$this->dateFormat}')")]);
             }
         }
     }
     if ($this->task_type_date_1_from != '' && $this->task_type_date_1_to != '') {
         $query->joinWith('datetype1');
         $task_type_date_1_from = explode('-', $this->task_type_date_1_from);
         $task_type_date_1_from_formatted = $task_type_date_1_from[2] . '-' . $task_type_date_1_from[1] . '-' . $task_type_date_1_from[0];
         $task_type_date_1_to = explode('-', $this->task_type_date_1_to);
         $task_type_date_1_to_formatted = $task_type_date_1_to[2] . '-' . $task_type_date_1_to[1] . '-' . $task_type_date_1_to[0];
         $query->andFilterWhere(['>=', 'TASK_DATES.TASK_TYPE_DATE', new \yii\db\Expression("to_date('" . $task_type_date_1_from_formatted . "','{$this->dateFormat}')")])->andFilterWhere(['<=', 'TASK_DATES.TASK_TYPE_DATE', new \yii\db\Expression("to_date('" . $task_type_date_1_to_formatted . "','{$this->dateFormat}')")]);
     } else {
         if ($this->task_type_date_1_from != '' && $this->task_type_date_1_to == '') {
             $query->joinWith('datetype1');
             $task_type_date_1_from = explode('-', $this->task_type_date_1_from);
             $task_type_date_1_from_formatted = $task_type_date_1_from[2] . '-' . $task_type_date_1_from[1] . '-' . $task_type_date_1_from[0];
             $query->andFilterWhere(['>=', 'TASK_DATES.TASK_TYPE_DATE', new \yii\db\Expression("to_date('" . $task_type_date_1_from_formatted . "','{$this->dateFormat}')")]);
         } else {
             if ($this->task_type_date_1_from == '' && $this->task_type_date_1_to != '') {
                 $query->joinWith('datetype1');
                 $task_type_date_1_to = explode('-', $this->task_type_date_1_to);
                 $task_type_date_1_to_formatted = $task_type_date_1_to[2] . '-' . $task_type_date_1_to[1] . '-' . $task_type_date_1_to[0];
                 $query->andFilterWhere(['<=', 'TASK_DATES.TASK_TYPE_DATE', new \yii\db\Expression("to_date('" . $task_type_date_1_to_formatted . "','{$this->dateFormat}')")]);
             }
         }
     }
     if ($this->task_type_date_4_from != '' && $this->task_type_date_4_to != '') {
         $query->joinWith('datetype4');
         $task_type_date_4_from = explode('-', $this->task_type_date_4_from);
         $task_type_date_4_from_formatted = $task_type_date_4_from[2] . '-' . $task_type_date_4_from[1] . '-' . $task_type_date_4_from[0];
         $task_type_date_4_to = explode('-', $this->task_type_date_4_to);
         $task_type_date_4_to_formatted = $task_type_date_4_to[2] . '-' . $task_type_date_4_to[1] . '-' . $task_type_date_4_to[0];
         $query->andFilterWhere(['>=', 'TASK_DATES.TASK_TYPE_DATE', new \yii\db\Expression("to_date('" . $task_type_date_4_from_formatted . "','{$this->dateFormat}')")])->andFilterWhere(['<=', 'TASK_DATES.TASK_TYPE_DATE', new \yii\db\Expression("to_date('" . $task_type_date_4_to_formatted . "','{$this->dateFormat}')")]);
     } else {
         if ($this->task_type_date_4_from != '' && $this->task_type_date_4_to == '') {
             $query->joinWith('datetype4');
             $task_type_date_4_from = explode('-', $this->task_type_date_4_from);
             $task_type_date_4_from_formatted = $task_type_date_4_from[2] . '-' . $task_type_date_4_from[1] . '-' . $task_type_date_4_from[0];
             $query->andFilterWhere(['>=', 'TASK_DATES.TASK_TYPE_DATE', new \yii\db\Expression("to_date('" . $task_type_date_4_from_formatted . "','{$this->dateFormat}')")]);
         } else {
             if ($this->task_type_date_4_from == '' && $this->task_type_date_4_to != '') {
                 $query->joinWith('datetype4');
                 $task_type_date_4_to = explode('-', $this->task_type_date_4_to);
                 $task_type_date_4_to_formatted = $task_type_date_4_to[2] . '-' . $task_type_date_4_to[1] . '-' . $task_type_date_4_to[0];
                 $query->andFilterWhere(['<=', 'TASK_DATES.TASK_TYPE_DATE', new \yii\db\Expression("to_date('" . $task_type_date_4_to_formatted . "','{$this->dateFormat}')")]);
             }
         }
     }
     if ($this->task_type_date_2_from != '' && $this->task_type_date_2_to != '') {
         $query->joinWith('datetype2');
         $task_type_date_2_from = explode('-', $this->task_type_date_2_from);
         $task_type_date_2_from_formatted = $task_type_date_2_from[2] . '-' . $task_type_date_2_from[1] . '-' . $task_type_date_2_from[0];
         $task_type_date_2_to = explode('-', $this->task_type_date_2_to);
         $task_type_date_2_to_formatted = $task_type_date_2_to[2] . '-' . $task_type_date_2_to[1] . '-' . $task_type_date_2_to[0];
         $query->andFilterWhere(['>=', 'TASK_DATES.TASK_TYPE_DATE', new \yii\db\Expression("to_date('" . $task_type_date_2_from_formatted . "','{$this->dateFormat}')")])->andFilterWhere(['<=', 'TASK_DATES.TASK_TYPE_DATE', new \yii\db\Expression("to_date('" . $task_type_date_2_to_formatted . "','{$this->dateFormat}')")]);
     } else {
         if ($this->task_type_date_2_from != '' && $this->task_type_date_2_to == '') {
             $query->joinWith('datetype2');
             $task_type_date_2_from = explode('-', $this->task_type_date_2_from);
             $task_type_date_2_from_formatted = $task_type_date_2_from[2] . '-' . $task_type_date_2_from[1] . '-' . $task_type_date_2_from[0];
             $query->andFilterWhere(['>=', 'TASK_DATES.TASK_TYPE_DATE', new \yii\db\Expression("to_date('" . $task_type_date_2_from_formatted . "','{$this->dateFormat}')")]);
         } else {
             if ($this->task_type_date_2_from == '' && $this->task_type_date_2_to != '') {
                 $query->joinWith('datetype2');
                 $task_type_date_2_to = explode('-', $this->task_type_date_2_to);
                 $task_type_date_2_to_formatted = $task_type_date_2_to[2] . '-' . $task_type_date_2_to[1] . '-' . $task_type_date_2_to[0];
                 $query->andFilterWhere(['<=', 'TASK_DATES.TASK_TYPE_DATE', new \yii\db\Expression("to_date('" . $task_type_date_2_to_formatted . "','{$this->dateFormat}')")]);
             }
         }
     }
     $query->andFilterWhere(['like', 'SOURCENUM', $this->SOURCENUM]);
     $query->andFilterWhere(['like', 'TASK_TEXT', $this->TASK_TEXT]);
     $query->andFilterWhere(['or like', 'PEOORDERNUM', $this->PEOORDERNUM]);
     $query->andFilterWhere(['or like', 'ORDERNUM', $this->ORDERNUM]);
     $query->andFilterWhere(['like', 'TASK_NUMBER', $this->TASK_NUMBER]);
     $query->andFilterWhere(['like', 'LOWER(DESIGNATION)', mb_strtolower($this->DESIGNATION, 'UTF-8')]);
     return $dataProvider;
 }
コード例 #4
0
 public function actionChangestatus()
 {
     if (Yii::$app->request->isAjax) {
         $status_id = $_POST['status'];
         $selected_issues = $_POST['selected_issues'];
         $user_cant_permissions_on = [];
         $user_have_permission_and_status_changed_on = [];
         foreach (json_decode($selected_issues) as $issue) {
             $pers_tasks_this = \app\models\PersTasks::find()->where(['TASK_ID' => $issue, 'TN' => \Yii::$app->user->id, 'DEL_TRACT_ID' => 0])->one();
             //проверяем имеет ли доступ пользователь к заданию и входит ли вообще в него
             if ($pers_tasks_this) {
                 $task_state = \app\models\TaskStates::find()->where(['PERS_TASKS_ID' => $pers_tasks_this->ID, 'IS_CURRENT' => 1])->one();
                 if ($task_state) {
                     // проверяем есть ли статус
                     $last_state = $task_state->STATE_ID;
                 } else {
                     // иначе устанавливаем значние даты null
                     $last_state = null;
                 }
                 if ($last_state != $status_id) {
                     $transactions = \app\models\Transactions::find()->where(['TN' => \Yii::$app->user->id])->orderBy('ID DESC')->one();
                     $new_state = new \app\models\TaskStates();
                     $new_state->TASK_ID = $issue;
                     $new_state->STATE_ID = $status_id;
                     $new_state->TRACT_ID = $transactions->ID;
                     $new_state->IS_CURRENT = 1;
                     $pers_tasks_this = \app\models\PersTasks::find()->where(['TASK_ID' => $issue, 'TN' => \Yii::$app->user->id, 'DEL_TRACT_ID' => 0])->one();
                     $new_state->PERS_TASKS_ID = $pers_tasks_this->ID;
                     $new_state->save();
                     $user_have_permission_and_status_changed_on[] = $issue;
                     //обновление поля IS_CURRENT для предыдущего состояния
                     if ($last_state != null) {
                         $task_state->IS_CURRENT = 0;
                         $task_state->save();
                     }
                 }
             } else {
                 $user_cant_permissions_on[] = $issue;
             }
         }
         $string_status_changed = '';
         if (!empty($user_have_permission_and_status_changed_on)) {
             foreach ($user_have_permission_and_status_changed_on as $issue) {
                 $task = \app\models\Tasks::findOne($issue);
                 $string_status_changed .= 'Задание №' . $task->TASK_NUMBER . ',';
             }
         }
         $string_status_not_changed = '';
         if (!empty($user_cant_permissions_on)) {
             foreach ($user_cant_permissions_on as $issue) {
                 $task = \app\models\Tasks::findOne($issue);
                 $string_status_not_changed .= 'Задание №' . $task->TASK_NUMBER . ',';
             }
         }
         Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         return ['string_status_changed' => $string_status_changed, 'string_status_not_changed' => $string_status_not_changed];
     }
 }
コード例 #5
0
 public function actionExcel()
 {
     /*
         Проверка на доступ пользователя к странице
     */
     $permissions_report_task_search = \app\models\Permissions::find()->where('(SUBJECT_TYPE = :subject_type and SUBJECT_ID = :user_id and DEL_TRACT_ID = :del_tract and PERM_LEVEL != :perm_level and ACTION_ID = :action) or
                                     (SUBJECT_TYPE = :subject_type_dolg and SUBJECT_ID = :dolg_id and DEL_TRACT_ID = :del_tract and PERM_LEVEL != :perm_level and ACTION_ID = :action)', ['subject_type_dolg' => 1, 'dolg_id' => \Yii::$app->session->get('user.user_iddolg'), 'action' => 82, 'subject_type' => 2, 'user_id' => \Yii::$app->user->id, 'del_tract' => 0, 'perm_level' => 0])->one();
     if ($permissions_report_task_search) {
         /*
             Проверяем получены ли идентификаторы заданий для формирования отчета
         */
         if (Yii::$app->request->get('ids')) {
             $issues_ids = Yii::$app->request->get('ids');
             $issues_ids = explode(',', $issues_ids);
             /*
                 Делаем выборку необходимых заданий
             */
             $model = \app\models\Tasks::find()->where(['ID' => $issues_ids])->all();
             if ($model) {
                 // Создаем объект класса PHPExcel
                 $xls = new \PHPExcel();
                 // Устанавливаем индекс активного листа
                 $xls->setActiveSheetIndex(0);
                 // Получаем активный лист
                 $sheet = $xls->getActiveSheet();
                 // Подписываем лист
                 $sheet->setTitle('Отчет по отобранным заданиям');
                 $sheet->getStyle('A1')->getFont()->setBold(true);
                 // Вставляем текст в ячейку A1
                 $sheet->setCellValue("A1", 'Отчет по отобранным заданиям');
                 $sheet->getStyle('A1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
                 $sheet->getStyle('A1')->getFill()->getStartColor()->setRGB('EEEEEE');
                 // Объединяем ячейки
                 $sheet->mergeCells('A1:I1');
                 // Выравнивание текста
                 $sheet->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                 // Формируем шапку
                 $sheet->setCellValue("A2", 'Заказ ПЭО');
                 $sheet->setCellValue("B2", 'Номер заказа');
                 $sheet->setCellValue("C2", 'Проект/Тема');
                 $sheet->setCellValue("D2", 'Обозначение');
                 $sheet->setCellValue("E2", 'Наименование');
                 $sheet->setCellValue("F2", 'Срок выполнения');
                 $sheet->setCellValue("G2", 'Статус');
                 $sheet->setCellValue("H2", 'Ф.И.О. и Дата');
                 $sheet->setCellValue("I2", 'Форматов А4');
                 /* устанавливаем ширину колонок и стили*/
                 $sheet->getStyle('A2:I2')->getFont()->setBold(true);
                 $sheet->getColumnDimension('A')->setAutoSize(true);
                 $sheet->getColumnDimension('B')->setAutoSize(true);
                 $sheet->getColumnDimension('C')->setAutoSize(true);
                 $sheet->getColumnDimension('D')->setAutoSize(true);
                 $sheet->getColumnDimension('E')->setAutoSize(true);
                 $sheet->getColumnDimension('F')->setAutoSize(true);
                 $sheet->getColumnDimension('G')->setWidth(20);
                 $sheet->getColumnDimension('H')->setAutoSize(true);
                 $sheet->getColumnDimension('I')->setAutoSize(true);
                 $row_number = 3;
                 foreach ($model as $task) {
                     $sheet->setCellValue("A" . $row_number, $task->PEOORDERNUM);
                     $sheet->setCellValue("B" . $row_number, $task->ORDERNUM);
                     $sheet->setCellValue("C" . $row_number, '');
                     $sheet->setCellValue("D" . $row_number, $task->TASK_NUMBER);
                     $sheet->setCellValue("E" . $row_number, 'Задание');
                     $sheet->setCellValue("F" . $row_number, \Yii::$app->formatter->asDate($task->DEADLINE, 'php:d-m-Y'));
                     //вставляем информацию по статусам
                     $task_states = \app\models\TaskStates::find()->where(['TASK_ID' => $task->ID])->orderBy('STATE_ID ASC')->all();
                     if ($task_states) {
                         foreach ($task_states as $state) {
                             $state_date = $state->getStateDate();
                             $logo = new \PHPExcel_Worksheet_Drawing();
                             $logo->setPath(Yii::getAlias('@webroot') . '/images/items_status/' . $state->getStateColour() . '.png');
                             $logo->setCoordinates("G" . $row_number);
                             $logo->setOffsetX(5);
                             $logo->setOffsetY(2);
                             $logo->setResizeProportional(true);
                             $logo->setWidth(16);
                             $logo->setWorksheet($sheet);
                             $sheet->setCellValue("G" . $row_number, '        ' . $state->getStateName());
                             $pers_tasks = \app\models\PersTasks::findOne($state->PERS_TASKS_ID);
                             $query = new \yii\db\Query();
                             $query->select('*')->from('STIGIT.V_F_PERS')->where('TN = \'' . $pers_tasks->TN . '\'');
                             $command = $query->createCommand();
                             $data = $command->queryOne();
                             $sheet->setCellValue("H" . $row_number, $data['FIO'] . ' ' . $state_date);
                             $task_docs = \app\models\TaskDocs::find()->where(['PERS_TASKS_ID' => $state->PERS_TASKS_ID])->one();
                             if ($task_docs) {
                                 $quantity = $task_docs->FORMAT_QUANTITY;
                             } else {
                                 $quantity = 0;
                             }
                             $sheet->setCellValue("I" . $row_number, $quantity);
                             $row_number++;
                         }
                     }
                     $row_number++;
                 }
                 //стили для рамки таблицы
                 $styleArray = array('borders' => array('allborders' => array('style' => \PHPExcel_Style_Border::BORDER_THIN)));
                 $total_rows = $row_number - 1;
                 $sheet->getStyle('A1:I' . $total_rows)->applyFromArray($styleArray);
                 //параметры страницы для печати - альбомная
                 $xls->getActiveSheet()->getPageSetup()->setOrientation(\PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
                 $xls->getActiveSheet()->getPageSetup()->setPaperSize(\PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
                 $xls->getActiveSheet()->getPageSetup()->setFitToPage(true);
                 $xls->getActiveSheet()->getPageSetup()->setFitToWidth(1);
                 $xls->getActiveSheet()->getPageSetup()->setFitToHeight(0);
                 // Выводим HTTP-заголовки
                 header("Expires: Mon, 1 Apr 1974 05:00:00 GMT");
                 header("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
                 header("Cache-Control: no-cache, must-revalidate");
                 header("Pragma: no-cache");
                 header("Content-type: application/vnd.ms-excel");
                 header("Content-Disposition: attachment; filename=report.xls");
                 //Выводим содержимое файла
                 $objWriter = new \PHPExcel_Writer_Excel5($xls);
                 $objWriter->save('php://output');
             } else {
                 /*
                     Вызываем эксепшн в случае, если были переданы не верные параметры заданий
                 */
                 throw new \yii\web\NotFoundHttpException('Что-то пошло не так. Пожалуйста, обратитесь к администратору системы.');
             }
         }
     } else {
         /*
             Вызываем эксепшн в случае, если доступ к формированию отчета запрещен
         */
         throw new \yii\web\ForbiddenHttpException('У Вас нет прав на редактирование "Формирование отчета"');
     }
 }
コード例 #6
0
 public function _getCurrentTaskStatusForCurrentUser($task_id)
 {
     //получаем список исполнителей данного задания
     $persons = \app\models\PersTasks::find()->where(['TASK_ID' => $task_id, 'DEL_TRACT_ID' => 0, 'TN' => \Yii::$app->user->id])->one();
     if ($persons) {
         //получаем статус для данного исполнителя
         $task_state = \app\models\TaskStates::find()->where(['IS_CURRENT' => 1, 'PERS_TASKS_ID' => $persons->ID, 'TASK_ID' => $task_id])->one();
         if ($task_state) {
             return $task_state->STATE_ID;
         } else {
             //нет ни одного статуса для данного пользователя
             return 'empty_status';
         }
     } else {
         //пользователь не стоит в списке исполнителей задания
         return 'user_not_in_persons_list';
     }
 }