/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = DetalleProyecto::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, 'id_departamento' => $this->id_departamento, 'id_municipio' => $this->id_municipio, 'latitud' => $this->latitud, 'longitud' => $this->longitud, 'total' => $this->total, 'aporte_fondo' => $this->aporte_fondo, 'cofinanciacion' => $this->cofinanciacion, 'usuarios_nuevos' => $this->usuarios_nuevos, 'usuarios_existentes' => $this->usuarios_existentes, 'numero' => $this->numero]);
     $query->andFilterWhere(['like', 'descripcion_veredas', $this->descripcion_veredas]);
     return $dataProvider;
 }
 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;
                 $n_faer = $data[$c++];
                 if (!Faer::find()->where(['faer_no' => $n_faer])->exists()) {
                     $model = new Faer();
                     $model->faer_no = $n_faer;
                     $model->radicado = intval($data[$c++]);
                     $model->proyecto = $data[$c++];
                     $model->nit_presento = $data[$c++];
                     $model->nit_ejecuto = $data[$c++];
                     $model->fecha_radicacion = $data[$c++];
                     $model->fecha_aprobacion = $data[$c++];
                     $model->oep = doubleval($data[$c++]);
                     $model->categoria = 3;
                     $model->subcategoria = 8;
                     $model->convocatoria = 1;
                     $numero = 0;
                     //var_dump($model);die();
                     if ($model->save()) {
                         if (Faer::find()->where(['faer_no' => $n_faer])->exists()) {
                             $tmp = Faer::findOne(['faer_no' => $n_faer]);
                             $numero = $tmp->numero;
                         }
                     } else {
                         var_dump($model->getErrors());
                     }
                 } else {
                     $c = 8;
                     $tmp = Faer::findOne(['faer_no' => $n_faer]);
                     $numero = $tmp->numero;
                 }
                 if ($numero != 0) {
                     $model_detalle = new DetalleProyecto();
                     $model_detalle->numero = $numero;
                     $model_detalle->id_departamento = intval($data[$c++]);
                     $model_detalle->id_municipio = intval($data[$c++]);
                     $model_detalle->descripcion_veredas = $data[$c++];
                     $model_detalle->latitud = doubleval($data[$c++]);
                     $model_detalle->longitud = doubleval($data[$c++]);
                     $model_detalle->total = doubleval($data[$c++]);
                     $model_detalle->cofinanciacion = doubleval($data[$c++]);
                     $model_detalle->aporte_fondo = doubleval($data[$c++]);
                     $model_detalle->usuarios_existentes = intval($data[$c++]);
                     $model_detalle->usuarios_nuevos = intval($data[$c]);
                     if (!$model_detalle->save()) {
                         var_dump($model_detalle->getErrors());
                     }
                 }
                 $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);
 }
Exemple #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDetalleProyectos()
 {
     return $this->hasMany(DetalleProyecto::className(), ['numero' => 'numero']);
 }
 /**
  * Finds the DetalleProyecto model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return DetalleProyecto the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = DetalleProyecto::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }