public function endTasksInWork() { $session = SessionRegistry::instance(); $user = $session->getCurrentUser(); $tasksModel = new Tasks(); $userTasks = $tasksModel->getMyTasks($user); foreach ($userTasks as $task) { $this->endWork($task['id']); } }
/** * Execute the job. * * @return void */ public function handle() { echo "Run task: #" . $this->job_id, "\n"; $task = Tasks::find($this->job_id); $task->status = Tasks::RUN; $task->save(); $client = new \Hoa\Websocket\Client(new \Hoa\Socket\Client('tcp://127.0.0.1:8889')); $client->setHost('127.0.0.1'); $client->connect(); $client->send(json_encode(["command" => webSocket::BROADCASTIF, "jobid" => $this->job_id, "msg" => json_encode(["jid" => $this->job_id, "status" => Tasks::RUN])])); $builder = new ProcessBuilder(); $builder->setPrefix('ansible-playbook'); $builder->setArguments(["-i", "inv" . $this->job_id, "yml" . $this->job_id]); $builder->setWorkingDirectory(storage_path("roles")); $process = $builder->getProcess(); $process->run(); //echo $process->getOutput() . "\n"; $client->send(json_encode(["command" => webSocket::BROADCASTIF, "jobid" => $this->job_id, "msg" => json_encode(["jid" => $this->job_id, "status" => Tasks::FINISH])])); $client->close(); $task->status = Tasks::FINISH; $task->content = file_get_contents(storage_path("tmp/log" . $this->job_id . ".txt")); $task->save(); unlink(storage_path("roles/yml" . $this->job_id)); unlink(storage_path("roles/inv" . $this->job_id)); unlink(storage_path("tmp/log" . $this->job_id . ".txt")); echo "End task: #" . $this->job_id, "\n"; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Tasks::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => false]); $this->load($params); if (!$this->validate()) { //default show tasks of user $query->andFilterWhere(['user_id' => Yii::$app->user->id]); // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } //if user not admin if (!Yii::$app->user->identity->isAdmin()) { $query->andFilterWhere(['user_id' => Yii::$app->user->id]); } //фильтр по дате поста, т.к. дата у нас в формате "time" в БД, а в форме лишь день-месяц-год, начинаем финтовать if (!empty($this->created_at) && $this->created_at !== 0) { $beginOfDay = strtotime("midnight", $this->created_at); $endOfDay = strtotime("tomorrow", $beginOfDay) - 1; $query->andWhere(['<', 'created_at', $endOfDay]); $query->andWhere(['>', 'created_at', $beginOfDay]); } //filter by complete_time - complete_at if (!empty($this->complete_at) && $this->complete_at !== 0) { $beginOfDay = strtotime("midnight", $this->complete_at); $endOfDay = strtotime("tomorrow", $beginOfDay) - 1; $query->andWhere(['<', 'complete_at', $endOfDay]); $query->andWhere(['>', 'complete_at', $beginOfDay]); } $query->andFilterWhere(['status' => $this->status]); $query->andFilterWhere(['like', 'desc', $this->desc]); return $dataProvider; }
public function validateUniqueTaskNumber() { $tasks = Tasks::find()->where(['TASK_NUMBER' => $this->task_number])->one(); if ($tasks) { $this->addError('task_number', 'Исходящий номер уже зарегистрирован в системе. Укажите другой.'); } }
public function run($id) { $task = Tasks::findOrFail($id); if ($task->status == Tasks::RUN) { $task->content = file_get_contents(storage_path("tmp/log" . $id . ".txt")); } return view("jobs.run", compact("id", "task")); }
/** * Deletes an existing Clients model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param string $id * @return mixed */ public function actionDelete($id) { if ($this->findModel($id)->delete()) { Tasks::deleteAll('client = :client', [':client' => $id]); Contacts::deleteAll('client = :client', [':client' => $id]); } return $this->redirect(['index']); }
public static function createJob($request) { $inv = Inventories::find($request->iid); $job = new Tasks(); $job->iid = $request->iid; $job->tid = $request->tid; $job->vars = $request->vars; $job->sudo = $request->sudo; $job->hosts = $request->hosts; $job->save(); $pid = $job->id; $vars = json_decode($job->vars); file_put_contents(storage_path("roles/inv{$pid}"), $inv->content); file_put_contents(storage_path("roles/yml{$pid}"), View::make("jobs.yml", compact("job", "pid", "vars"))->render()); file_put_contents(storage_path("tmp/log" . $pid . ".txt"), ""); dispatch(new runAnsible($job->id)); return $job->id; }
public function destroy() { $tasks = Tasks::find(Input::get("id")); if (!$tasks) { Session::flash('error', trans("tasks.notifications.no_exists")); return Redirect::to("/tasks"); } $tasks->delete(); Session::flash('success', trans("tasks.notifications.delete_successful")); return Redirect::to("/tasks"); }
public function closedTaskData($id) { $tasks = Tasks::select(['id', 'title', 'created_at', 'deadline', 'fk_user_id_assign'])->where('fk_user_id_assign', $id)->where('status', 2); return Datatables::of($tasks)->addColumn('titlelink', function ($tasks) { return '<a href="' . route('tasks.show', $tasks->id) . '">' . $tasks->title . '</a>'; })->editColumn('created_at', function ($tasks) { return $tasks->created_at ? with(new Carbon($tasks->created_at))->format('d/m/Y') : ''; })->editColumn('deadline', function ($tasks) { return $tasks->created_at ? with(new Carbon($tasks->created_at))->format('d/m/Y') : ''; })->make(true); }
/** * @return bool */ public function handle() { $configurationRepository = new ConfigurationRepository(); $enableQueueProcess = $configurationRepository->getValue('enable_queue_process'); $task = Tasks::findOrNew($this->idTask); if (!$enableQueueProcess || !$task->id || $task->status != Tasks::STATUS_PENDING) { return true; } $processor = new TaskProcessor(); $processor->processOneTask($task); return true; }
public function getUserFilesById($id, \App\models\User $user) { $this->setWhere(array('id' => $id)); $data = $this->select(); if (empty($data)) { throw new \Exception('Файл не найден!'); } if ($user->roles_id != 1) { $tasksModel = new Tasks(); if ($data[0]['tasks_id'] > 0) { $tasksModel->getOneMyTask($user, $data[0]['tasks_id']); } elseif ($data[0]['projects_id'] > 0) { $projectsModel = new Projects(); $project = $projectsModel->getProjectsDataById($data[0]['projects_id']); if ($project['initiator_id'] != $user->id) { throw new \Exception('Доступ запрещен!'); } } else { throw new \Exception('Доступ запрещен!'); } } return $data[0]; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $task = Tasks::findOrFail($request->id); $settings = Settings::all(); $isAdmin = Auth()->user()->hasRole('administrator'); $settingscomplete = $settings[0]['task_assign_allowed']; if ($isAdmin) { return $next($request); } if ($settingscomplete == 1 && Auth()->user()->id != $task->fk_user_id_assign) { Session()->flash('flash_message_warning', 'Only assigned user are allowed to do this'); return redirect()->back(); } return $next($request); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Tasks::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'active' => $this->active, 'client' => $this->client, 'created' => $this->created, 'updated' => $this->updated, 'user_created' => $this->user_created, 'user_ispol' => $this->user_ispol, 'fakt_date' => $this->fakt_date]); $query->andFilterWhere(['like', 'plan', $this->plan])->andFilterWhere(['like', 'task', $this->task])->andFilterWhere(['like', 'priority', $this->priority])->andFilterWhere(['like', 'results', $this->results])->andFilterWhere(['like', 'report', $this->report]); $query->andFilterWhere(['between', 'plan_date', $this->fromDate, $this->toDate]); $query->orderBy(['plan_date' => SORT_DESC]); return $dataProvider; }
public function actionIndex() { if (User::isUserAdmin(Yii::$app->user->identity->username) or User::isUserModer(Yii::$app->user->identity->username)) { $tasks = Tasks::findAll(['active' => Tasks::STATUS_ACTIVE]); } else { $tasks = Tasks::findAll(['active' => Tasks::STATUS_ACTIVE, 'user_ispol' => Yii::$app->user->identity->id]); } $events = array(); foreach ($tasks as $task) { $Event = new \yii2fullcalendar\models\Event(); $Event->id = $task->id; $Event->title = $task->clientName->name; $Event->start = $task->plan_date; $events[] = $Event; } return $this->render('index', ['events' => $events]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Tasks::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]], 'pagination' => ['pageSize' => 100]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'created' => $this->created, 'updated' => $this->updated, 'closed' => $this->closed, 'user_id' => $this->user_id, 'status_id' => $this->status_id, 'typeperson_id' => $this->typeperson_id, 'typesolicitation_id' => $this->typesolicitation_id, 'location_id' => $this->location_id]); $query->andFilterWhere(['like', 'cpf_cnpj', $this->cpf_cnpj]); // $query->andFilterWhere(['like', 'cpf_cnpj', $this->cpf_cnpj]) // ->andFilterWhere(['like', 'notes', $this->notes]) // ->andFilterWhere(['like', 'note_analyst', $this->note_analyst]) // ->andFilterWhere(['like', 'file_cpf', $this->file_cpf]) // ->andFilterWhere(['like', 'file_cartao_assinatura', $this->file_cartao_assinatura]) // ->andFilterWhere(['like', 'file_comprovante_residencia', $this->file_comprovante_residencia]) // ->andFilterWhere(['like', 'file_outro_endereco', $this->file_outro_endereco]) // ->andFilterWhere(['like', 'file_imposto_renda', $this->file_imposto_renda]) // ->andFilterWhere(['like', 'file_comp_estado_civil', $this->file_comp_estado_civil]); return $dataProvider; }
/** * Finds the Tasks model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Tasks the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Tasks::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function TaskError() { //запишим ошибку $this->log('error'); //укажим, что задание на обработку выполнилось с ошибкой $query = \Yii::$app->db->createCommand('UPDATE ' . Tasks::tableName() . ' SET status=:status, complete_at=:complete_at WHERE id=:id'); $query->bindValues([':status' => Tasks::STATUS_ERROR, ':id' => $this->task->id, ':complete_at' => time()]); $query->execute(); //осовбодим очередь для след. задания \Yii::$app->get('mutex')->release($this->tasks_mutex_name); }
public function completedTasksToday() { return Tasks::whereRaw('date(updated_at) = ?', [Carbon::now()->format('Y-m-d')])->where('status', 2)->count(); }
public function remove($id) { $this->setWhere(array('id' => $id)); $this->delete(); $filesModel = new Files(); $filesModel->removeFilesByProject($id); $executorsModel = new Executors(); $executorsModel->setWhere(array('projects_id' => $id)); $executorsModel->delete(); $tasksModel = new Tasks(); $tasksModel->removeTasksByProjectId($id); }
/** * @param Tasks $task * @param $link * @return bool */ private function updateTask(Tasks $task, $link) { if (!$link) { $task->status = Tasks::STATUS_ERROR; $task->error_message = 'Cant save form'; $task->save(); Log::error("Link not found to task [{$task->id}]"); return true; } $task->status = Tasks::STATUS_PROCESSED; $task->sent_at = Carbon::now()->format('Y-m-d H:i:s'); $task->link = $link; $task->save(); return true; }
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 removeAction(Request $request, $id) { $task = $this->repository->findById($id); if (!$task) { $request->session()->flash('message', "Task [{$id}] not found"); return redirect('tasks'); } $taskDescription = $task->task; Tasks::destroy($id); $request->session()->flash('message', "Successfully removed task [{$taskDescription}]"); $request->session()->flash('success', true); return redirect('tasks'); }
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]; } }
//echo $form->field($model, 'user_ispol')->textInput(['maxlength' => true]); } ?> <?php //= $form->field($model, 'fakt_date')->textInput() ?> </td> </tr> </table> <?php if (!$model->isNewRecord) { echo $form->field($model, 'results')->dropDownList(Tasks::getResultsArray(), array('prompt' => ' ')); //echo $form->field($model, 'results')->textInput(['maxlength' => true]); echo $form->field($model, 'report')->textarea(array('rows' => 3)); //echo $form->field($model, 'report')->textInput(['maxlength' => true]); } ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Создать' : 'Обновить', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?>
public function managetimeAction() { if (is_null($this->request->getProperty('id'))) { throw new \Exception('Страница не найдена!'); } $id = (int) $this->request->getProperty('id'); $tasksModel = new Tasks(); $this->view->task = $tasksModel->getTasksDataById($id); $timelineModel = new Timeline(); $timelineModel->setWhere(array('tasks_id' => $id)); $timeline = $timelineModel->select(); $timelineToOut = array(); // TODO: учесть распределение времени на границе дня. foreach ($timeline as $item) { $dateTime1 = new \DateTime($item['works_begin']); if ($item['works_end'] == '0000-00-00 00:00:00') { $dateTime2 = new \DateTime(date('Y-m-d H:i:s')); } else { $dateTime2 = new \DateTime($item['works_end']); } $interval = $dateTime2->getTimestamp() - $dateTime1->getTimestamp(); $index = $dateTime1->format('z') . '-' . $dateTime1->format('Y'); if (!isset($timelineToOut[$index])) { $item['day_time_sum'] = gmdate('H часов i минут', $interval); $item['interval'] = $interval; $timelineToOut[$index] = $item; } else { $timelineToOut[$index]['interval'] = $timelineToOut[$index]['interval'] + $interval; $timelineToOut[$index]['day_time_sum'] = gmdate('H часов i минут', $timelineToOut[$index]['interval']); } } $this->view->timeline = $timelineToOut; $seconds = $timelineModel->getTimeSumByTask($id); $hours = floor($seconds / 3600); $mins = floor(($seconds - $hours * 3600) / 60); $this->view->timesum = $hours . ' часов ' . $mins . ' минут'; }
public function invoice($id, Request $request) { $task = Tasks::findOrFail($id); $clientId = $task->clientAssignee()->first()->id; $timeTaskId = $task->allTime()->get(); $integrationCheck = Integration::first(); if ($integrationCheck) { $this->tasks->invoice($id, $request); } $this->invoices->create($clientId, $timeTaskId, $request->all()); Session()->flash('flash_message', 'Invoice created'); return redirect()->back(); }
public static function boot() { parent::boot(); Tasks::observe(new TaskObserver()); }
public function getPending() { return Tasks::where('status', '<>', Tasks::STATUS_PROCESSED)->get(); }
$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 = \app\models\Tasks::find(); $dateFormat = 'YYYY-MM-DD hh24:mi:ss'; $query->andFilterWhere(['TASKS.ID' => $list]); $now = date("Y-m-d"); $query->andFilterWhere(['<', 'TASKS.DEADLINE', new \yii\db\Expression("to_date('" . $now . "','{$dateFormat}')")]); $query->joinWith('perstasks'); $query->andFilterWhere(['PERS_TASKS.TN' => \Yii::$app->user->id]); $counter_overdue = $query->count(); if ($counter_overdue > 0) { ?> <li class="submenu-li"><a style="color: #ff0000;" href="<?php echo Url::to(['/site/index', 'overdue' => 1]); ?> ">Просроченные задания (<?php echo $counter_overdue; ?>
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('У Вас нет прав на редактирование "Формирование отчета"'); } }