[ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['post'], ], ], ]; } /** * Lists all tercero models. * @return mixed */ public function actionIndex() { $searchModel = new TerceroSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } public function actionCalendario(){ return $this->render('calendario'); } /** * Displays a single tercero model. * @param integer $id * @return mixed */ public function actionView($id) { $model = $this->findModel($id); $providerAcademico = new \yii\data\ArrayDataProvider([ 'allModels' => $model->academicos, ]); $providerAsistencia = new \yii\data\ArrayDataProvider([ 'allModels' => $model->asistencias, ]); $providerCalificacion = new \yii\data\ArrayDataProvider([ 'allModels' => $model->calificaciones, ]); $providerGrupo = new \yii\data\ArrayDataProvider([ 'allModels' => $model->grupos, ]); return $this->render('view', [ 'model' => $this->findModel($id), 'providerAcademico' => $providerAcademico, 'providerAsistencia' => $providerAsistencia, 'providerCalificacion' => $providerCalificacion, 'providerGrupo' => $providerGrupo, ]); } /** * Creates a new tercero model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Tercero(); if ($model->loadAll(Yii::$app->request->post())){ if($model->foto != '') { $foto = UploadedFile::getInstance($model,'foto'); $file = rand(10,100).'-'.str_replace(' ','-',$foto); $foto->saveAs( 'uploads/'.$file); //Image::thumbnail('uploads/'.$foto->name, 120, 120)->save('uploads/'.$foto->name, ['quality' => 80]); Image::getImagine()->open('uploads/'.$file)->thumbnail(new Box(120, 120))->save('uploads/thumbnail/sm-'.$file , ['quality' => 80]); Image::getImagine()->open('uploads/'.$file)->thumbnail(new Box(360, 360))->save('uploads/thumbnail/lg-'.$file , ['quality' => 80]); //save the path in DB.. $model->foto = 'uploads/thumbnail/sm-'.$file; unlink('uploads/'.$file); } $model->departamento_nacimiento = ($model->departamento_nacimiento == '') ? NULL : $model->departamento_nacimiento; if ($model->saveAll()) { \Yii::$app->session->addFlash('mensaje', [ 'tipo' => 'success', 'titulo' => 'Creación de Tercero', 'icono' => 'fa fa-user', 'mensaje' => 'El tercero '.$model->nombre.' se creó éxitosamente.', ]); return $this->redirect(['view', 'id' => $model->id]); } } else { return $this->render('create', [ 'model' => $model, ]); } } public function actionUpdate($id) { $model = $this->findModel($id); if ($model->loadAll(Yii::$app->request->post())) { $model->departamento_nacimiento = ($model->departamento_nacimiento == '') ? NULL : $model->departamento_nacimiento; $model->saveAll(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', [ 'model' => $model, ]); } } /** * Deletes an existing tercero model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { //$this->findModel($id)->deleteWithRelated(); //return $this->redirect(['index']); $tercero = static::findModel($id); $tercero->estado = '3'; $tercero->update(); return $this->redirect(['index']); } /** * * for export pdf at actionView * * @param type $id * @return type */ public function actionPdf($id) { $model = $this->findModel($id); $providerAcademico = new \yii\data\ArrayDataProvider([ 'allModels' => $model->academicos, ]); $providerAsistencia = new \yii\data\ArrayDataProvider([ 'allModels' => $model->asistencias, ]); $providerCalificacion = new \yii\data\ArrayDataProvider([ 'allModels' => $model->calificacions, ]); $providerGrupo = new \yii\data\ArrayDataProvider([ 'allModels' => $model->grupos, ]); $content = $this->renderAjax('_pdf', [ 'model' => $model, 'providerAcademico' => $providerAcademico, 'providerAsistencia' => $providerAsistencia, 'providerCalificacion' => $providerCalificacion, 'providerGrupo' => $providerGrupo, ]); $pdf = new \kartik\mpdf\Pdf([ 'mode' => \kartik\mpdf\Pdf::MODE_CORE, 'format' => \kartik\mpdf\Pdf::FORMAT_A4, 'orientation' => \kartik\mpdf\Pdf::ORIENT_PORTRAIT, 'destination' => \kartik\mpdf\Pdf::DEST_BROWSER, 'content' => $content, 'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css', 'cssInline' => '.kv-heading-1{font-size:18px}', 'options' => ['title' => \Yii::$app->name], 'methods' => [ 'SetHeader' => [\Yii::$app->name], 'SetFooter' => ['{PAGENO}'], ] ]); return $pdf->render(); } /** * Finds the tercero model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return tercero the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = tercero::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } /* public function actionFindmunicipios() { $out = []; if (isset($_POST['depdrop_parents'])) { $parents = $_POST['depdrop_parents']; if ($parents != null) { $dep_id = $parents[0]; $out=Municipio::getMunicipiosbyDepartamento($dep_id); echo json_encode(['output'=>$out, 'selected'=>'']); return; } } echo json_encode(['output'=>'', 'selected'=>'']); } */ public function actionFindmunicipios() { $out = []; if (isset($_POST['depdrop_parents'])) { $id = end($_POST['depdrop_parents']); $list = Municipio::find()->andWhere(['departamento'=>$id])->asArray()->all(); $selected = null; if ($id != null && count($list) > 0) { $selected = ''; foreach ($list as $i => $data) { $out[] = ['id' => $data['id'], 'name' => $data['nombre']]; if ($i == 0) { $selected = $data['id']; } } // Shows how you can preselect a value echo Json_encode(['output' => $out, 'selected'=>$selected]); return; } } echo Json_encode(['output' => '', 'selected'=>'']); } public function actionFindestados() { $out = []; if (isset($_POST['depdrop_parents'])) { $id = end($_POST['depdrop_parents']); $list = Terceroestado::find()->andWhere(['tipo_tercero'=>$id])->asArray()->all(); $selected = null; if ($id != null && count($list) > 0) { $selected = ''; foreach ($list as $i => $data) { $out[] = ['id' => $data['id'], 'name' => $data['estado']]; if ($i == 0) { $selected = $data['id']; } } // Shows how you can preselect a value echo Json_encode(['output' => $out, 'selected'=>$selected]); return; } } echo Json_encode(['output' => '', 'selected'=>'']); } public function actionAddTercero() { if (Yii::$app->request->isAjax) { $row = Yii::$app->request->post('Tercero'); if((Yii::$app->request->post('isNewRecord') && Yii::$app->request->post('action') == 'load' && empty($row)) || Yii::$app->request->post('action') == 'add') $row[] = []; return $this->renderAjax('_formTercero', ['row' => $row]); } else { throw new NotFoundHttpException('The requested page does not exist.'); } } public function actionAddAcademico() { if (Yii::$app->request->isAjax) { $row = Yii::$app->request->post('Academico'); if((Yii::$app->request->post('isNewRecord') && Yii::$app->request->post('action') == 'load' && empty($row)) || Yii::$app->request->post('action') == 'add') $row[] = []; return $this->renderAjax('_formAcademico', ['row' => $row]); } else { throw new NotFoundHttpException('The requested page does not exist.'); } } /** * Action to load a tabular form grid * for Asistencia * @author Yohanes Candrajaya * @author Jiwantoro Ndaru * * @return mixed */ public function actionAddAsistencia() { if (Yii::$app->request->isAjax) { $row = Yii::$app->request->post('Asistencia'); if((Yii::$app->request->post('isNewRecord') && Yii::$app->request->post('action') == 'load' && empty($row)) || Yii::$app->request->post('action') == 'add') $row[] = []; return $this->renderAjax('_formAsistencia', ['row' => $row]); } else { throw new NotFoundHttpException('The requested page does not exist.'); } } /** * Action to load a tabular form grid * for Calificacion * @author Yohanes Candrajaya * @author Jiwantoro Ndaru * * @return mixed */ public function actionAddCalificacion() { if (Yii::$app->request->isAjax) { $row = Yii::$app->request->post('Calificacion'); if((Yii::$app->request->post('isNewRecord') && Yii::$app->request->post('action') == 'load' && empty($row)) || Yii::$app->request->post('action') == 'add') $row[] = []; return $this->renderAjax('_formCalificacion', ['row' => $row]); } else { throw new NotFoundHttpException('The requested page does not exist.'); } } /** * Action to load a tabular form grid * for Grupo * @author Yohanes Candrajaya * @author Jiwantoro Ndaru * * @return mixed */ public function actionAddGrupo() { if (Yii::$app->request->isAjax) { $row = Yii::$app->request->post('Grupo'); if((Yii::$app->request->post('isNewRecord') && Yii::$app->request->post('action') == 'load' && empty($row)) || Yii::$app->request->post('action') == 'add') $row[] = []; return $this->renderAjax('_formGrupo', ['row' => $row]); } else { throw new NotFoundHttpException('The requested page does not exist.'); } } }