Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Copy this code tomorrow
- //Daganzo controller
- public function actionIndex()
- {
- $searchModel = new DaganzoBusqueda();
- $searchModelo = $searchModel->buscarAnio(Yii::$app->request->queryParams);
- $dataProvider = $searchModel->busca(Yii::$app->request->queryParams);
- $miObjeto = $searchModel->buscarTodoAgrupado($dataProvider);
- return $this->render('index', [
- 'searchModel' => $searchModel,
- 'searchModelo' => $searchModelo,
- 'dataProvider' => $miObjeto,
- ]);
- }
- //Daganzo Busqueda
- public function busca($params)
- {
- $query = Daganzo::findBySql("select * from daganzo");
- $dataProvider = new ActiveDataProvider([
- 'query' => $query,
- ]);
- $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_cuenta' => $this->id_cuenta,
- 'ano' => $this->ano,
- 'mes' => $this->mes,
- 'id_funcional' => $this->id_funcional,
- 'id_economica' => $this->id_economica,
- 'pre_inicial' => $this->pre_inicial,
- 'pre_modificacion' => $this->pre_modificacion,
- 'pre_final' => $this->pre_final,
- 'gas_comprometidos' => $this->gas_comprometidos,
- 'gas_reconocidos' => $this->gas_reconocidos,
- 'pag_realizados' => $this->pag_realizados,
- 'pag_pendientes' => $this->pag_pendientes,
- 'sal_remanente' => $this->sal_remanente,
- ]);
- $query->andFilterWhere(['like', 'trimestre', $this->trimestre])
- ->andFilterWhere(['like', 'des_funcional', $this->des_funcional])
- ->andFilterWhere(['like', 'des_economica', $this->des_economica]);
- return $dataProvider;
- }
- public function buscarAnio($params)
- {
- $query = Daganzo::findBySql('select distinct ano
- from daganzo group by ano');
- $dataProvider = new ActiveDataProvider([
- 'query' => $query,
- ]);
- $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_cuenta' => $this->id_cuenta,
- 'ano' => $this->ano,
- 'mes' => $this->mes,
- 'id_funcional' => $this->id_funcional,
- 'id_economica' => $this->id_economica,
- 'pre_inicial' => $this->pre_inicial,
- 'pre_modificacion' => $this->pre_modificacion,
- 'pre_final' => $this->pre_final,
- 'gas_comprometidos' => $this->gas_comprometidos,
- 'gas_reconocidos' => $this->gas_reconocidos,
- 'pag_realizados' => $this->pag_realizados,
- 'pag_pendientes' => $this->pag_pendientes,
- 'sal_remanente' => $this->sal_remanente,
- ]);
- $query->andFilterWhere(['like', 'trimestre', $this->trimestre])
- ->andFilterWhere(['like', 'des_funcional', $this->des_funcional])
- ->andFilterWhere(['like', 'des_economica', $this->des_economica]);
- return $dataProvider;
- }
- /**
- * Crea un dataProvider con los distintos registros del a;o 2013 agrupados por id_funcional
- * @param array $params
- * @return ActiveDataProvider
- */
- public function buscarTodoAgrupado($dataProvider)
- {
- $datos=$dataProvider->getModels();
- foreach($datos as $row){
- $id_funcional = $row['id_funcional'];
- $ano = $row['ano'];
- $id = $row['id_cuenta'];
- }
- $query = Daganzo::findBySql("select id_funcional, ano, id_cuenta, des_funcional, trimestre, sum(pre_final) as pre_final,
- sum(gas_comprometidos) as gas_comprometidos, sum(pag_realizados) as pag_realizados
- from daganzo where ano = $ano group by id_funcional");
- $dataProvider = new ActiveDataProvider([
- 'query' => $query,
- 'pagination' => array('pageSize' => 20),
- ]);
- $this->load($id);
- 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_cuenta' => $this->id_cuenta,
- 'ano' => $this->ano,
- 'mes' => $this->mes,
- 'id_funcional' => $this->id_funcional,
- 'id_economica' => $this->id_economica,
- 'pre_inicial' => $this->pre_inicial,
- 'pre_modificacion' => $this->pre_modificacion,
- 'pre_final' => $this->pre_final,
- 'gas_comprometidos' => $this->gas_comprometidos,
- 'gas_reconocidos' => $this->gas_reconocidos,
- 'pag_realizados' => $this->pag_realizados,
- 'pag_pendientes' => $this->pag_pendientes,
- 'sal_remanente' => $this->sal_remanente,
- ]);
- $query->andFilterWhere(['like', 'trimestre', $this->trimestre])
- ->andFilterWhere(['like', 'des_funcional', $this->des_funcional])
- ->andFilterWhere(['like', 'des_economica', $this->des_economica]);
- return $dataProvider;
- }
- /**
- * Metodo que recibe un id_cuenta y nos devuelve un dataProvider con el id_funcional que queremos encontrar
- * @param string $id
- * @return ActiveDataProvider
- */
- public function buscarIdFuncional($id)
- {
- $idCuenta = intval($id);
- $query = Daganzo::findBySql("select id_funcional, ano from daganzo where id_cuenta = $idCuenta");
- $dataProvider = new ActiveDataProvider([
- 'query' => $query,
- ]);
- $this->load($id);
- 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_cuenta' => $this->id_cuenta,
- 'ano' => $this->ano,
- 'mes' => $this->mes,
- 'id_funcional' => $this->id_funcional,
- 'id_economica' => $this->id_economica,
- 'pre_inicial' => $this->pre_inicial,
- 'pre_modificacion' => $this->pre_modificacion,
- 'pre_final' => $this->pre_final,
- 'gas_comprometidos' => $this->gas_comprometidos,
- 'gas_reconocidos' => $this->gas_reconocidos,
- 'pag_realizados' => $this->pag_realizados,
- 'pag_pendientes' => $this->pag_pendientes,
- 'sal_remanente' => $this->sal_remanente,
- ]);
- $query->andFilterWhere(['like', 'trimestre', $this->trimestre])
- ->andFilterWhere(['like', 'des_funcional', $this->des_funcional])
- ->andFilterWhere(['like', 'des_economica', $this->des_economica]);
- return $dataProvider;
- }
- /**
- * Metodo que recibe un ActiveDataProvider y un string que devuelve los registros cuyo id_funcional
- * es el que hemos seleccionado en el metodo buscarIdFuncional
- * @param ActiveDataProvider $dataProvider
- * @param string $id
- * @return ActiveDataProvider
- */
- public function devuelveFilasIdFuncional($dataProvider, $id){
- $datos=$dataProvider->getModels();
- foreach($datos as $row){
- $id_funcional = $row['id_funcional'];
- $ano = $row['ano'];
- }
- $query = Daganzo::findBySql("select id_funcional, id_cuenta, des_funcional, trimestre, pre_final,
- gas_comprometidos, pag_realizados, ano from daganzo where ano = $ano AND id_funcional = $id_funcional");
- $dataProvider = new ActiveDataProvider([
- 'query' => $query,
- //Eliminamos la paginacion existente para mejorar la salida de los datos
- 'pagination' => array('pageSize' => 0),
- ]);
- $this->load($id);
- 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_cuenta' => $this->id_cuenta,
- 'ano' => $this->ano,
- 'mes' => $this->mes,
- 'id_funcional' => $this->id_funcional,
- 'id_economica' => $this->id_economica,
- 'pre_inicial' => $this->pre_inicial,
- 'pre_modificacion' => $this->pre_modificacion,
- 'pre_final' => $this->pre_final,
- 'gas_comprometidos' => $this->gas_comprometidos,
- 'gas_reconocidos' => $this->gas_reconocidos,
- 'pag_realizados' => $this->pag_realizados,
- 'pag_pendientes' => $this->pag_pendientes,
- 'sal_remanente' => $this->sal_remanente,
- ]);
- $query->andFilterWhere(['like', 'trimestre', $this->trimestre])
- ->andFilterWhere(['like', 'des_funcional', $this->des_funcional])
- ->andFilterWhere(['like', 'des_economica', $this->des_economica]);
- return $dataProvider;
- }
- //Index of Daganzo
- <?php
- //namespace kartik\grid;
- //use yii\grid\GridView;
- use yii\helpers\Html;
- use app\models\Daganzo;
- use app\models\DaganzoBusqueda;
- use kartik\grid\GridView;
- use kartik\grid\DataColumn;
- use yii\bootstrap\Collapse;
- use kartik\widgets\Select2;
- use yii\helpers\ArrayHelper;
- use yii\data\ActiveDataProvider;
- /* @var $this yii\web\View */
- /* @var $searchModel app\models\DaganzoBusqueda */
- /* @var $dataProvider yii\data\ActiveDataProvider */
- $this->title = 'Daganzos Index';
- $this->params['breadcrumbs'][] = $this->title;
- ?>
- <div class="daganzo-index">
- <h1><?= Html::encode($this->title) ?></h1>
- <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
- <?php
- $data = ArrayHelper::map(Daganzo::find()->groupBy('ano')->asArray()->all(),'ano','ano');
- $miObjeto = $searchModel->buscarTodoAgrupado($dataProvider);
- $datos=$miObjeto->getModels();
- foreach($datos as $row){
- $id_funcional = $row['id_funcional'];
- $ano = $row['ano'];
- $id = $row['id_cuenta'];
- }
- //var_dump($ano);
- if(isset($_GET['ano'])){
- $a =htmlspecialchars($_GET["ano"]);
- if($a == '2012'){
- $ano = $a;
- }
- else{
- if($a == '2013'){
- $ano ='2013';
- }
- else{if($a=='2011'){
- $ano = '2011';
- }}
- }
- }
- $query = Daganzo::findBySql("select id_funcional, ano, id_cuenta, des_funcional, trimestre, sum(pre_final) as pre_final,
- sum(gas_comprometidos) as gas_comprometidos, sum(pag_realizados) as pag_realizados
- from daganzo where ano = $ano group by id_funcional");
- $dataProvider = new ActiveDataProvider([
- 'query' => $query,
- ]);
- $select =Select2::widget([
- 'name' => 'ano',
- 'model' => $searchModelo,
- 'attribute' => 'ano',
- 'data' => $data,
- 'options' => ['placeholder' => 'Selleccione año ...', 'id' =>'id_ano'],
- 'pluginOptions' => [
- 'allowClear' => true
- ],
- ]);
- echo GridView::widget([
- 'dataProvider'=> $dataProvider,
- 'filterModel' => $searchModelo,
- 'columns' => [
- ['class' => 'yii\grid\SerialColumn'],
- [
- 'class' => 'kartik\grid\ExpandRowColumn',
- 'value' => function($model, $key, $index, $column){
- return GridView::ROW_COLLAPSED;
- },
- 'detail' => function($model, $key, $index, $column){
- /**
- * Pasos para avanzar en una sql hasta poder llegar a pasarle el dataProvider
- * y el id_funcional necesarios para que la consulta devuelva:
- * Los campos por id funcional y que sean del año 2013
- */
- $searchModel = new DaganzoBusqueda();
- //$dataProvider = $searchModel->buscarTodoAgrupado(Yii::$app->request->queryParams);
- $dataProvider = $searchModel->buscarIdFuncional($key);
- $dataProvider = $searchModel->devuelveFilasIdFuncional($dataProvider, $key);
- #Accedemos al metodo devuelve totales
- #$miObjeto = $searchModel->devuelveTotales($dataProvider, $key);
- /**
- * return que devuelve una vista que no es necesario que este definida en DaganzoController
- * le pasamos el dataProvider y el searchModel
- */
- return Yii::$app->controller->renderPartial('vista',
- ['searchModel' => $searchModel,
- 'dataProvider' => $dataProvider,
- ]);
- }
- ],
- //'id_funcional',
- 'des_funcional',
- // 'id_economica',
- // 'des_economica',
- [
- 'attribute' => 'ano',
- 'value' => 'ano',
- 'format' => 'raw',
- 'filter' => $select
- ],
- #descomentamos las filas a mostrar
- //'pre_inicial',
- //'pre_modificacion',
- 'pre_final',
- 'gas_comprometidos',
- //'gas_reconocidos',
- //'pag_realizados',
- //'pag_pendientes',
- //'sal_remanente',
- ],
- //Atributos del GridView
- 'bordered' => true,
- 'striped' => true,
- 'condensed' => true,
- 'responsive' => true,
- 'hover' => true,
- 'showPageSummary' => false,
- //Panel que hace referencia al "titulo" del gridview y a su footer
- 'panel' => [
- 'heading'=>'<h1 class="panel-title"><i class="glyphicon glyphicon-globe"></i> Daganzo Index</h1>',
- 'type'=>'info',
- 'before'=>Html::a('<i class="glyphicon glyphicon-plus"></i> Crear Nuevo registro',
- ['create'], ['class' => 'btn btn-success']),
- 'after'=>Html::a('<i class="glyphicon glyphicon-repeat"></i> Reiniciar Tabla',
- ['index'], ['class' => 'btn btn-info']),
- 'footer'=>false
- ],
- 'persistResize' => false,
- 'exportConfig' => true,
- ]);
- ?>
- </div>
- <?php
- $script = <<< JS
- $('#id_ano').change(function(){
- var idano = $(this).val();
- });
- JS;
- $this->registerJs($script);
- ?>
- //All here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement