public function actionIndex() { $model = $this->findModel(Yii::$app->user->id); $laborTally = []; $laborTally['Hourly'] = Labor::find()->hourly()->tech($model->contact_id)->total(); $laborTally['Proactive'] = Labor::find()->hourly(false)->tech($model->contact_id)->total(); $openTickets = new ActiveDataProvider(['query' => Ticket::find()->active()->joinWith('invoice.location.client', false), 'pagination' => ['pageSize' => 10], 'sort' => ['defaultOrder' => ['status_id' => SORT_ASC, 'id' => SORT_ASC]]]); $openTickets->sort->attributes['location_id'] = ['asc' => [Client::tableName() . '.name' => SORT_ASC, Location::tableName() . '.name' => SORT_ASC], 'desc' => [Client::tableName() . '.name' => SORT_DESC, Location::tableName() . '.name' => SORT_DESC]]; Url::remember(); return $this->render('index', ['model' => $model, 'laborTally' => $laborTally, 'openTickets' => $openTickets]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Invoice::find()->andWhere(['not', ['status_id' => Invoice::STATUS_CURRENT]])->with('location.client'); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false, 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]); $dataProvider->sort->attributes['location_id'] = ['asc' => [Client::tableName() . '.name' => SORT_ASC, Location::tableName() . '.name' => SORT_ASC], 'desc' => [Client::tableName() . '.name' => SORT_DESC, Location::tableName() . '.name' => SORT_DESC]]; $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([Invoice::tableName() . '.location_id' => $this->location_id, Invoice::tableName() . '.status_id' => $this->status_id]); $query->andFilterWhere(['like', Invoice::tableName() . '.id', (int) $this->id]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Ticket::find()->current()->joinWith(['invoice.location', 'invoice.location.client']); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50], 'sort' => ['defaultOrder' => ['status_id' => SORT_ASC]]]); $dataProvider->sort->attributes['location_id'] = ['asc' => [Client::tableName() . '.name' => SORT_ASC, Location::tableName() . '.name' => SORT_ASC], 'desc' => [Client::tableName() . '.name' => SORT_DESC, Location::tableName() . '.name' => SORT_DESC]]; $dataProvider->sort->attributes['status_id'] = ['asc' => [Ticket::tableName() . '.status_id' => SORT_DESC], 'desc' => [Ticket::tableName() . '.status_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([Location::tableName() . '.id' => $this->location_id, Ticket::tableName() . '.status_id' => $this->status_id, Ticket::tableName() . '.priority_id' => $this->priority_id, Ticket::tableName() . '.bill_type_id' => $this->bill_type_id]); $query->andFilterWhere(['like', Ticket::tableName() . '.id', $this->id]); return $dataProvider; }
/** * @param integer $client_id * @return $this */ public function client($client_id) { $this->joinWith(['invoice.location'])->andWhere([Location::tableName() . '.client_id' => $client_id]); return $this; }
public function getLocations() { return $this->hasMany(Location::className(), ['entity_id' => 'id'])->andOnCondition([Location::tableName() . '.entity' => self::THIS_ENTITY]); }