Exemplo n.º 1
0
 /**
  * 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";
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 public function validateUniqueTaskNumber()
 {
     $tasks = Tasks::find()->where(['TASK_NUMBER' => $this->task_number])->one();
     if ($tasks) {
         $this->addError('task_number', 'Исходящий номер уже зарегистрирован в системе. Укажите другой.');
     }
 }
Exemplo n.º 4
0
 private function findTask()
 {
     $task = Tasks::find()->where(['status' => Tasks::STATUS_CREATE])->orderBy('created_at ASC')->one();
     if (!$task) {
         throw new Exception('Task not found');
     } else {
         return $task;
     }
 }
Exemplo n.º 5
0
 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");
 }
Exemplo n.º 6
0
 /**
  * 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;
 }
Exemplo n.º 7
0
 public function invoice($id, $requestData)
 {
     $contatGuid = $requestData->invoiceContact;
     $taskname = Tasks::find($id);
     $timemanger = TaskTime::where('fk_task_id', $id)->get();
     $sendMail = $requestData->sendMail;
     $productlines = [];
     foreach ($timemanger as $time) {
         $productlines[] = array('Description' => $time->title, 'Comments' => $time->comment, 'BaseAmountValue' => $time->value, 'Quantity' => $time->time, 'AccountNumber' => 1000, 'Unit' => 'hours');
     }
     $api = Integration::getApi('billing');
     $results = $api->createInvoice(['Currency' => 'DKK', 'Description' => $taskname->title, 'contactId' => $contatGuid, 'ProductLines' => $productlines]);
     if ($sendMail == true) {
         $bookGuid = $booked->Guid;
         $bookTime = $booked->TimeStamp;
         $api->sendInvoice($bookGuid, $bookTime);
     }
 }
Exemplo n.º 8
0
 /**
  * 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;
 }
Exemplo n.º 9
0
                    $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;
        ?>
Exemplo n.º 10
0
 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;
 }
Exemplo n.º 11
0
 public function actionGetpersons()
 {
     if (Yii::$app->request->isAjax) {
         //проверка на асинхронный запрос
         $post_data = $_POST['selected_podr'];
         \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         // устанавливаем ответ сервера в виде JSON объекта
         $persons_list = '<ul>';
         foreach (json_decode($post_data) as $kodzifr => $value) {
             // обходим список полученных подразделений
             $query = new \yii\db\Query();
             $query->select('NAIMPODR AS name, VIDPODR as vid, KODPODR AS id, KODRODIT as parent, KODZIFR as code')->from('STIGIT.V_F_PODR')->where('KODZIFR = \'' . $kodzifr . '\'');
             $command = $query->createCommand();
             $data = $command->queryOne();
             //формирование списка
             $persons_list .= "<li class=\"expanded\"><span style=\"font-weight: normal; font-size: 12px;\">" . $data['vid'] . " " . $data['code'] . ". " . $data['name'] . "</span>";
             $query = new \yii\db\Query();
             $query->select('*')->from('STIGIT.V_F_PERS')->where('KODZIFR = \'' . $kodzifr . '\'');
             $command = $query->createCommand();
             $data = $command->queryAll();
             $persons_list .= '<ul>';
             foreach ($data as $key => $value) {
                 // обходим список сотрудников каждого подразделения
                 //получаем кол-во заданий для каждого исполнителя
                 $pers_tasks = \app\models\PersTasks::find()->where(['TN' => $value['TN'], 'DEL_TRACT_ID' => 0])->all();
                 if ($pers_tasks) {
                     $tasks_array = [];
                     foreach ($pers_tasks as $task) {
                         $tasks_array[] = $task->TASK_ID;
                     }
                     $tasks = \app\models\Tasks::find()->where(['in', 'ID', $tasks_array])->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);
                     $counter = count($list);
                     $counter = ' <span class="label label-info"><a target="_blank" href="' . \yii\helpers\Url::to(['/site/index', 'for_person' => $value['TN']]) . '">Заданий в работе: ' . $counter . '</a></span>';
                 } else {
                     $counter = '';
                 }
                 $persons_list .= "<li><input id=\"checkbox_" . $value['TN'] . "\" type='checkbox' name=\"persons_check[]\" data-title=\"" . $value['FIO'] . "\" value=\"" . $value['TN'] . "\" /> <span style=\"font-size: 11px;\">" . $value['FAM'] . " " . $value['IMJ'] . " " . $value['OTCH'] . " " . $counter . "</span></li>";
             }
             $persons_list .= '</ul>';
         }
         $persons_list .= '</ul>';
         return $persons_list;
     }
 }
Exemplo n.º 12
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('У Вас нет прав на редактирование "Формирование отчета"');
     }
 }