</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;
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 . ' <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; } } }
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]; } }
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; }
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'; } }