/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Empresas::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]); $query->andFilterWhere(['like', 'razao_social', $this->razao_social])->andFilterWhere(['like', 'nome_fantasia', $this->nome_fantasia])->andFilterWhere(['like', 'cnpj', $this->cnpj])->andFilterWhere(['like', 'insc_estadual', $this->insc_estadual])->andFilterWhere(['like', 'endereco', $this->endereco])->andFilterWhere(['like', 'numero', $this->numero])->andFilterWhere(['like', 'bairro', $this->bairro])->andFilterWhere(['like', 'estado', $this->estado])->andFilterWhere(['like', 'cidade', $this->cidade])->andFilterWhere(['like', 'cep', $this->cep])->andFilterWhere(['like', 'telefone', $this->telefone])->andFilterWhere(['like', 'telefone1', $this->telefone1])->andFilterWhere(['like', 'telefone2', $this->telefone2])->andFilterWhere(['like', 'email', $this->email]); return $dataProvider; }
public function actionIndex($filtro = 'todos') { $modelEmpresa = \app\models\Empresas::findOne(Yii::$app->session->get('empresa')); $today = date("Y-m-d H:i:s"); $yearSg = ['start' => date('Y-m-d H:i:s', mktime(0, 0, 0, 1, 1, date('Y'))), 'end' => date('Y-m-d H:i:s', mktime(23, 59, 59, 12, 31, date('Y')))]; $pendentes = (new Query())->select(['count(*) as total'])->from(['eventos o'])->leftJoin('atividades a', 'o.atividade_id = a.id')->where(['>=', 'd_ini', $yearSg['start']])->andWhere(['<=', 'd_ter', $yearSg['end']])->andWhere(['status' => 0])->andWhere(['a.empresa_id' => Yii::$app->session->get('empresa')])->scalar(); $avencer = (new Query())->select(['count(*) as total'])->from(['eventos o'])->leftJoin('atividades a', 'o.atividade_id = a.id')->where(['>=', 'd_ter', $today])->andWhere(['<=', 'd_ter', $yearSg['end']])->andWhere(['status' => 0])->andWhere(['a.empresa_id' => Yii::$app->session->get('empresa')])->scalar(); $vencidas = (new Query())->select(['count(*) as total'])->from(['eventos o'])->leftJoin('atividades a', 'o.atividade_id = a.id')->andWhere(['a.empresa_id' => Yii::$app->session->get('empresa')])->andWhere(['<', 'd_ter', $today])->andWhere(['status' => 0])->scalar(); $canceladas = (new Query())->select(['count(*) as total'])->from(['eventos o'])->leftJoin('atividades a', 'o.atividade_id = a.id')->andWhere(['a.empresa_id' => Yii::$app->session->get('empresa')])->andWhere(['status' => 3])->scalar(); $concluidas = (new Query())->select(['count(*) as total'])->from(['eventos o'])->leftJoin('atividades a', 'o.atividade_id = a.id')->andWhere(['a.empresa_id' => Yii::$app->session->get('empresa')])->andWhere(['status' => 1])->scalar(); $concluidas_atraso = (new Query())->select(['count(*) as total'])->from(['eventos o'])->leftJoin('atividades a', 'o.atividade_id = a.id')->andWhere(['a.empresa_id' => Yii::$app->session->get('empresa')])->andWhere(['status' => 2])->scalar(); switch ($filtro) { case "": Eventos::find()->joinWith('atividade')->where(['MONTH(d_ini)' => date('m')])->andWhere(['atividades.empresa_id' => Yii::$app->session->get('empresa')]); break; default: $query = Eventos::find()->joinWith('atividade')->where(['MONTH(d_ini)' => date('m')])->andWhere(['atividades.empresa_id' => Yii::$app->session->get('empresa')]); break; } $modelOcorrencia = new \yii\data\ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 8]]); return $this->render('index', ['modelEmpresa' => $modelEmpresa, 'modelOcorrencia' => $modelOcorrencia, 'pendentes' => $pendentes, 'avencer' => $avencer, 'vencidas' => $vencidas, 'canceladas' => $canceladas, 'concluidas' => $concluidas, 'concluidas_atraso' => $concluidas_atraso]); }
/** * Finds the Empresas model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Empresas the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Empresas::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function getEmpresas() { return $this->hasOne(Empresas::className(), ['id' => 'empresa_did']); }