/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Divipola::find(); // add conditions that should always apply here $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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'dpto', $this->dpto])->andFilterWhere(['like', 'mpio', $this->mpio]); return $dataProvider; }
<?php $form = ActiveForm::begin(); ?> <div class="panel panel-primary"> <div class="panel-heading"> <h3 class="panel-title">Registrar</h3> </div> <div class="panel-body"> <div class="row"> <div class="col-md-3"> <?php echo $form->field($model, 'id_departamento')->widget(Select2::classname(), ['data' => ArrayHelper::map(\app\models\Divipola::find()->all(), 'id_dpto', 'dpto'), 'options' => ['placeholder' => 'Seleccione una opción'], 'pluginOptions' => ['allowClear' => true]]); ?> </div> <div class="col-md-3"> <?php echo $form->field($model, 'id_municipio')->widget(DepDrop::classname(), ['type' => DepDrop::TYPE_SELECT2, 'pluginOptions' => ['depends' => ['detalleproyecto-id_departamento'], 'loadingText' => 'Cargando...', 'placeholder' => 'Seleccione ciudad', 'url' => Url::to(['divipola/ciudades'])]]); ?> </div> <div class="col-md-3"> <?php echo $form->field($model, 'latitud')->textInput(); ?> </div> <div class="col-md-3"> <?php
public function actionFileUpload() { if (empty($_FILES['attachment'])) { echo json_encode(['error' => 'No seleccionó ningun archivo']); return; } // a flag to see if everything is ok $success = null; $file = $_FILES['attachment']; $target = '/var/www/html/cobertura/web/files/'; $filename = $file['name']; if (file_exists($target . $filename)) { unlink($target . $filename); } $success = move_uploaded_file($_FILES['attachment']['tmp_name'], $target . $filename) ? true : false; // check and process based on successful status if ($success === true) { $row = 1; if (($handle = fopen($target . $filename, "r")) !== FALSE) { while (($data = fgetcsv($handle, 0, ",")) !== FALSE) { $c = 0; $num_dpto = $data[$c++]; $nombre_dpto = $data[$c++]; $num_mpio = $data[$c++]; $nombre_mpio = $data[$c++]; if (!Divipola::find()->where(['id_dpto' => $num_dpto, 'id' => $num_dpto])->exists()) { $model = new Divipola(); $model->id = $num_mpio; $model->id_dpto = $num_dpto; $model->dpto = $nombre_dpto; $model->mpio = $nombre_mpio; $model->save(); } else { $row++; } } fclose($handle); } //$this->redirect(['index']); $output = ['success' => 'Carga exitosa']; } elseif ($success === false) { $output = ['error' => 'Error subiendo archivo']; // delete any uploaded files //unlink($file); } else { $output = ['error' => 'No se procesó el archivo']; } // return a json encoded response for plugin to process successfully echo json_encode($output); }
<?php echo $this->render('_search3', ['model' => $searchModel]); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'responsive' => true, 'resizableColumns' => true, 'panel' => ['before' => ''], 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'faer_no', ['attribute' => 'nit_ejecuto', 'value' => function ($data) { return $data->nitEjecuto->razon_social; }, 'filter' => \kartik\select2\Select2::widget(['name' => 'nit_ejecuto', 'data' => ArrayHelper::map(\app\models\OperadorRed::find()->all(), 'nit', 'razon_social'), 'options' => ['placeholder' => ''], 'pluginOptions' => ['allowClear' => true]])], ['attribute' => 'fecha_radicacion', 'value' => function ($data) { return $data->fecha_radicacion; }, 'filter' => DateRangePicker::widget(['model' => $searchModel, 'attribute' => 'fecha_radicacion', 'convertFormat' => true, 'pluginOptions' => ['timePicker' => false, 'format' => 'Y-m-d']])], 'proyecto', ['attribute' => 'Dpto', 'value' => function ($data) { if (count($data->detalleProyectos) > 0) { return app\models\Divipola::findOne(['id_dpto' => $data->detalleProyectos[0]->id_departamento])->dpto; } else { return ""; } }, 'filter' => \kartik\select2\Select2::widget(['name' => 'dpto', 'data' => ArrayHelper::map(\app\models\Divipola::find()->all(), 'id_dpto', 'dpto'), 'options' => ['placeholder' => ''], 'pluginOptions' => ['allowClear' => true]])], ['attribute' => 'Total Beneficiarios', 'contentOptions' => ['style' => 'text-align: right;'], 'value' => function ($data, $acum) use(&$global_acum_beneficiarios) { if (count($data->detalleProyectos) > 0) { foreach ($data->detalleProyectos as $d) { $acum += $d->usuarios_nuevos; } $global_acum_beneficiarios += $acum; return $global_acum_beneficiarios; } else { return $global_acum_beneficiarios; } }], ['attribute' => 'Total Proyecto', 'format' => 'Currency', 'contentOptions' => ['style' => 'text-align: right;'], 'value' => function ($data, $acum) { if (count($data->detalleProyectos) > 0) { foreach ($data->detalleProyectos as $d) { $acum += $d->total; } return $acum;