Пример #1
0
 /**
  * @param \yii\web\Request $request
  * @return integer|null
  */
 private function getNoteAuthorId($request)
 {
     $noteId = $request->get('id');
     /** @var $note Note|null */
     $note = Note::findOne($noteId);
     return isset($note) ? $note->author_id : null;
 }
Пример #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Note::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, 'user_id' => $this->user_id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'color', $this->color]);
     return $dataProvider;
 }
Пример #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Note::find()->complete()->joinWith('attachment')->with(['author', 'ticket']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_ASC]]]);
     $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(['ticket_id' => $this->ticket_id, 'public' => $this->public]);
     $query->andFilterWhere(['like', 'body', $this->body]);
     if ($this->attachment !== '') {
         $attachment = [Attachment::tableName() . '.file_name' => null];
         if ($this->attachment) {
             $attachment = ['not', $attachment];
         }
         $query->andWhere($attachment);
     }
     return $dataProvider;
 }
Пример #4
0
 public function actionLogWork($remote = false)
 {
     $model = new Schedule(['scenario' => Schedule::SCENARIO_REMOTE]);
     $model->loadDefaultValues();
     $model->duration = null;
     $model->tech_id = Yii::$app->user->id;
     $note = new Note(['scenario' => Note::SCENARIO_REMOTE]);
     $ticket = new Ticket(['scenario' => Ticket::SCENARIO_REMOTE]);
     if ($model->load(Yii::$app->request->post()) && $model->validate() && $note->load(Yii::$app->request->post()) && $note->validate()) {
         if (empty($note->ticket_id)) {
             // new ticket
             if (!($ticket->load(Yii::$app->request->post()) && !empty(trim($ticket->title)) && $ticket->validate())) {
                 $ticket->addError('title', 'Select a ticket or enter a title to create a new one');
             } else {
                 $ticket->invoice_id = $model->invoice_id;
                 $ticket->status_id = $ticket::STATUS_IN_PROGRESS;
                 if ($ticket->save(false) && $model->save(false)) {
                     $note->link('ticket', $ticket);
                     $note->link('schedule', $model, ['hours' => $model->duration / 60]);
                     return $this->redirect(['ticket/view', 'id' => $note->ticket_id]);
                 }
             }
         } elseif ($model->save(false) && $note->save(false)) {
             $note->link('schedule', $model, ['hours' => $model->duration / 60]);
             if ($note->ticket->status_id == $ticket::STATUS_SUBMITTED) {
                 $note->ticket->status_id = $ticket::STATUS_IN_PROGRESS;
                 $note->ticket->save(false);
             }
             return $this->redirect(['ticket/view', 'id' => $note->ticket_id]);
         }
     } elseif (!Yii::$app->request->isPost) {
         $model->load(Yii::$app->request->get());
         $note->load(Yii::$app->request->get());
         $ticket->load(Yii::$app->request->get());
     }
     if (empty($model->start_time)) {
         $minutes = time() / 60;
         $minutes = $minutes - $minutes % 5;
         // round down to 5 min increment
         $model->start_time = date('Y-m-d H:i:00', $minutes * 60);
     }
     if (Yii::$app->request->isAjax) {
         return $this->renderAjax('log-work', ['model' => $model, 'note' => $note, 'ticket' => $ticket, 'remote' => $remote]);
     }
     return $this->render('log-work', ['model' => $model, 'note' => $note, 'ticket' => $ticket, 'remote' => $remote]);
 }
Пример #5
0
 /**
  * @return NoteQuery
  */
 public function getNotes()
 {
     return $this->hasMany(Note::className(), ['author_id' => 'id'])->inverseOf('author');
 }
Пример #6
0
 /**
  * Finds the Note model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Note the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Note::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #7
0
 /**
  * @return NoteQuery
  */
 public function getNote()
 {
     return $this->hasOne(Note::className(), ['id' => 'note_id'])->inverseOf('labor');
 }
Пример #8
0
 public function actionDuplicate($id)
 {
     $model = $this->findModel($id);
     $model->status_id = $model::STATUS_DUPLICATE;
     $model->scenario = $model::SCENARIO_DUPLICATE;
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $noteAppend = "\r\n\r\n---Moved from duplicate " . $model->fullName . ' ( ' . Url::base(true) . Url::to(['/ticket/view', 'id' => $model->id]) . ' )';
         foreach ($model->notes as $note) {
             //duplicate the original note and attach to original ticket
             $oldNote = new Note($note->attributes);
             $oldNote->id = null;
             $oldNote->save(false);
             //move the original note to the new ticket
             $note->scenario = $note::SCENARIO_DUPLICATE;
             $note->ticket_id = $model->dup_id;
             if (!empty($note->body)) {
                 $note->body .= $noteAppend;
             }
             $note->save(false);
         }
         $newNote = new Note();
         $newNote->ticket_id = $model->id;
         $newNote->body = '---Marked as duplicate of TT#' . $model->dup_id . ' ( ' . Url::base(true) . Url::to(['/ticket/view', 'id' => $model->dup_id]) . ' )';
         $newNote->save(false);
         if ($model->save(false)) {
             return $this->redirect(['/ticket/view', 'id' => $model->dup_id]);
         }
     }
     if (Yii::$app->request->isAjax) {
         return $this->renderAjax('duplicate', ['model' => $model]);
     }
     return $this->render('duplicate', ['model' => $model]);
 }
Пример #9
0
 /**
  * @return $this
  */
 public function totals()
 {
     $this->joinWith(['labors', 'purchasedItems'], false)->groupBy('id')->addSelect([Ticket::tableName() . '.*', 'COALESCE(SUM(' . Labor::tableName() . '.[[hours]]), 0) * COUNT(DISTINCT ' . Note::tableName() . '.[[id]]) / COUNT(*) AS [[totalHours]]', 'COALESCE(SUM(' . PurchasedItem::tableName() . '.[[cost]] * ' . PurchasedItem::tableName() . '.[[quantity]]), 0) * COUNT(DISTINCT ' . PurchasedItem::tableName() . '.[[id]]) / COUNT(*) AS [[totalPurchases]]']);
     return $this;
 }
Пример #10
0
 /**
  * @return NoteQuery
  */
 public function getNotes()
 {
     return $this->hasMany(Note::className(), ['ticket_id' => 'id'])->inverseOf('ticket');
 }
Пример #11
0
 /**
  * @return NoteQuery
  */
 public function getNotes()
 {
     return $this->hasMany(Note::className(), ['id' => 'note_id'])->via('labors')->inverseOf('schedule');
 }
Пример #12
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getNote()
 {
     return $this->hasOne(Note::className(), ['id' => 'note_id']);
 }