public function actionCreateAjax($modelName, $modelID) { // Esta funcion sirve tanto para dar de alta un mensaje como para darlo de baja, // las dos acciones se hacen por el submit del formulario, la diferencia es que cuando // se hace un alta, el campo estado (que está hidden) viene vacío, cuando viene con el valor 1 significa // que ya existia un mensaje y con el submit lo tiene que dar de baja (lógica) // Esta función solo retorna 1 registro (que tiene que estar activo) $model = Mensajes::getMensajesByModelId($modelName, $modelID); // si no tiene registro activo, se inicializa $model para permitir su alta if (empty($model)) { $model = new Mensajes(); } // toma los valores que vienen por submit if ($model->load(Yii::$app->request->post())) { $model->model = $modelName; $model->model_id = $modelID; // Si estado es 1 significa que ya existia el mensaje y hay que darle baja lógica if ($model->estado == 1) { $model->estado = 0; } if ($model->save()) { Yii::$app->response->format = 'json'; return ['modelP' => $model]; } } return $this->renderAjax('createajax', ['model' => $model, 'modelNameOrigen' => $modelName, 'modelIDOrigen' => $modelID]); }
public function refreshListas() { $response = ['ingpersonas' => '', 'ingvehiculos' => '', 'autorizantes' => '', 'egrpersonas' => '', 'egrvehiculos' => '']; foreach ($response as $grupo => $valor) { // Se recupera de la sesion $sess = \Yii::$app->session->get($grupo); if (!empty($sess)) { // Se crea el array vacio para el dataprovider $dp = []; // La session solo contiene los IDs, se recorre el array y se completa $dp con el objeto que corresponda foreach ($sess as $p) { switch ($grupo) { case 'ingpersonas': $dp[] = Personas::findOne($p); break; case 'ingvehiculos': $dp[] = Vehiculos::findOne($p); break; case 'autorizantes': $dp[] = Autorizantes::findOne($p); break; case 'egrpersonas': $dp[] = Personas::findOne($p); break; case 'egrvehiculos': $dp[] = Vehiculos::findOne($p); break; } } $dataProvider = new ArrayDataProvider(['allModels' => $dp]); } else { // dataProvider vacio //return ''; $response[$grupo] = ''; continue; } // if !empty $sess switch ($grupo) { case 'ingpersonas': $columns = [['header' => '<span class="glyphicon glyphicon-trash"></span>', 'attribute' => 'Acción', 'format' => 'raw', 'value' => function ($model, $index, $widget) { $url = Yii::$app->urlManager->createUrl(['accesos/drop-lista', 'grupo' => 'ingpersonas', 'id' => isset($model->id) ? $model->id : '']); return Html::a('<span class="glyphicon glyphicon-remove"></span>', $url, ['title' => 'Eliminar', 'onclick' => '$.ajax({ type : "POST", cache : false, url : $(this).attr("href"), success : function(r) { $("#divlistapersonas").html(r["ingpersonas"]); } });return false;']); }], ['header' => '<span class="glyphicon glyphicon-envelope"></span>', 'attribute' => 'Mensajes', 'format' => 'raw', 'value' => function ($model, $index, $widget) { $c = Mensajes::getMensajesByModelId($model->className(), $model->id); if (!empty($c)) { $text = '<span class="glyphicon glyphicon-alert" style="color:#FF8000"></span>'; $titl = 'Ver mensaje'; } else { $text = '<span class="glyphicon glyphicon-envelope"></span>'; $titl = 'Ingresar nuevo mensaje'; } $url = Yii::$app->urlManager->createUrl(['mensajes/create-ajax', 'modelName' => $model->className(), 'modelID' => $model->id]); return Html::a($text, $url, ['title' => $titl, 'onclick' => '$.ajax({ type :"POST", cache : false, url : $(this).attr("href"), success : function(response) { $("#divmensaje").html(response); $("#modalmensaje").modal("show"); } });return false;']); }], ['header' => ' ', 'attribute' => 'venc_vto_seguro', 'visible' => \Yii::$app->session->get('req_seguro'), 'format' => 'raw', 'value' => function ($model, $index, $widget) { if (empty($model->vto_seguro)) { $ic = ' '; } else { // se debe controlar si no está vencido el seguro if ($this->fecVencida($model->vto_seguro)) { $ic = '<span class="glyphicon glyphicon-hourglass" title="Seguro VENCIDO" style="color:#FF8000"></span>'; } else { // no está vencido, controla si esta por vencer en 2 dias (ver el valor en params.php) if ($this->fecPorVencer($model->vto_seguro, \Yii::$app->params['fecSeguroDias'])) { $ic = '<span class="glyphicon glyphicon-hourglass" title="Seguro por vencer" ></span>'; } else { $ic = ' '; } } } return $ic; }], ['attribute' => 'vto_seguro', 'visible' => \Yii::$app->session->get('req_seguro'), 'format' => 'raw', 'value' => function ($model, $index, $widget) { // intendencia pidio que se pueda modificar siempre $pide = true; /* if (empty($model->vto_seguro)) { $pide=true; } else { // se debe controlar si no está vencido el seguro if ($this->fecVencida($model->vto_seguro)) { $pide=true; } else { // no está vencido, por lo tanto no se pide, solo se muestra $pide=false; } } */ if (!$pide) { return Yii::$app->formatter->format($model->vto_seguro, 'date'); } else { $url = Yii::$app->urlManager->createUrl(['accesos/pide-seguro', 'idPersona' => $model->id]); return Html::a(empty($model->vto_seguro) ? 'Sin seguro' : Yii::$app->formatter->format($model->vto_seguro, 'date'), $url, ['title' => 'Modificar fecha de vencimiento', 'onclick' => '$.ajax({ type :"POST", cache : false, url : $(this).attr("href"), success : function(response) { console.log(response); $("#divupdseguro").html(response); $("#modalupdseguro").modal("show"); } });return false;']); } }], 'id', 'apellido', 'nombre', 'nombre2', 'nro_doc']; $heading = '<i class="glyphicon glyphicon-user"></i> Personas (Ingreso)'; //$heading='Personas'; break; case 'egrpersonas': $columns = [['header' => '<span class="glyphicon glyphicon-trash"></span>', 'attribute' => 'Acción', 'format' => 'raw', 'value' => function ($model, $index, $widget) { $url = Yii::$app->urlManager->createUrl(['accesos/drop-lista', 'grupo' => 'egrpersonas', 'id' => isset($model->id) ? $model->id : '']); return Html::a('<span class="glyphicon glyphicon-remove"></span>', $url, ['title' => 'Eliminar', 'onclick' => '$.ajax({ type : "POST", cache : false, url : $(this).attr("href"), success : function(r) { $("#divlistapersonas").html(r["egrpersonas"]); } });return false;']); }], ['header' => '<span class="glyphicon glyphicon-envelope"></span>', 'attribute' => 'Mensajes', 'format' => 'raw', 'value' => function ($model, $index, $widget) { $c = Mensajes::getMensajesByModelId($model->className(), $model->id); if (!empty($c)) { $text = '<span class="glyphicon glyphicon-alert" style="color:#FF8000"></span>'; $titl = 'Ver mensaje'; } else { $text = '<span class="glyphicon glyphicon-envelope"></span>'; $titl = 'Ingresar nuevo mensaje'; } $url = Yii::$app->urlManager->createUrl(['mensajes/create-ajax', 'modelName' => $model->className(), 'modelID' => $model->id]); return Html::a($text, $url, ['title' => $titl, 'onclick' => '$.ajax({ type :"POST", cache : false, url : $(this).attr("href"), success : function(response) { $("#divmensaje").html(response); $("#modalmensaje").modal("show"); } });return false;']); }], ['header' => '', 'attribute' => 'Sin ingreso', 'format' => 'raw', 'value' => function ($model, $index, $widget) { $a = Accesos::find()->where(['id_persona' => $model->id, 'egr_fecha' => null])->orderBy(['id' => SORT_DESC])->one(); if (empty($a)) { return '<span class="glyphicon glyphicon-bell" title="Sin ingreso" style="color:#FF8000"> </span>'; } else { return ''; } }], 'id', 'apellido', 'nombre', 'nombre2', 'nro_doc']; $heading = '<i class="glyphicon glyphicon-user"></i> Personas (Egreso)'; //$heading='Personas'; break; case 'ingvehiculos': $columns = [['header' => '<span class="glyphicon glyphicon-trash"></span>', 'attribute' => 'Acción', 'format' => 'raw', 'value' => function ($model, $index, $widget) { $url = Yii::$app->urlManager->createUrl(['accesos/drop-lista', 'grupo' => 'ingvehiculos', 'id' => isset($model->id) ? $model->id : '']); return Html::a('<span class="glyphicon glyphicon-remove"></span>', $url, ['title' => 'Eliminar', 'onclick' => '$.ajax({ type : "POST", cache : false, url : $(this).attr("href"), success : function(r) { $("#divlistavehiculos").html(r["ingvehiculos"]); } });return false;']); }], ['header' => '<span class="glyphicon glyphicon-envelope"></span>', 'attribute' => 'Mensajes', 'format' => 'raw', 'value' => function ($model, $index, $widget) { $c = Mensajes::getMensajesByModelId($model->className(), $model->id); if (!empty($c)) { $text = '<span class="glyphicon glyphicon-alert" style="color:#FF8000"></span>'; $titl = 'Ver mensaje'; } else { $text = '<span class="glyphicon glyphicon-envelope"></span>'; $titl = 'Ingresar nuevo mensaje'; } $url = Yii::$app->urlManager->createUrl(['mensajes/create-ajax', 'modelName' => $model->className(), 'modelID' => $model->id]); return Html::a($text, $url, ['title' => $titl, 'onclick' => '$.ajax({ type :"POST", cache : false, url : $(this).attr("href"), success : function(response) { $("#divmensaje").html(response); $("#modalmensaje").modal("show"); } });return false;']); }], 'id', 'patente', 'marca', 'modelo', 'color']; $heading = '<i class="fa fa-car"></i> Vehiculos (Ingreso)'; //$heading='Vehiculos'; break; case 'egrvehiculos': $columns = [['header' => '<span class="glyphicon glyphicon-trash"></span>', 'attribute' => 'Acción', 'format' => 'raw', 'value' => function ($model, $index, $widget) { $url = Yii::$app->urlManager->createUrl(['accesos/drop-lista', 'grupo' => 'egrvehiculos', 'id' => isset($model->id) ? $model->id : '']); return Html::a('<span class="glyphicon glyphicon-remove"></span>', $url, ['title' => 'Eliminar', 'onclick' => '$.ajax({ type : "POST", cache : false, url : $(this).attr("href"), success : function(r) { $("#divlistavehiculos").html(r["egrvehiculos"]); } });return false;']); }], ['header' => '<span class="glyphicon glyphicon-envelope"></span>', 'attribute' => 'Mensajes', 'format' => 'raw', 'value' => function ($model, $index, $widget) { $c = Mensajes::getMensajesByModelId($model->className(), $model->id); if (!empty($c)) { $text = '<span class="glyphicon glyphicon-alert" style="color:#FF8000"></span>'; $titl = 'Ver mensaje'; } else { $text = '<span class="glyphicon glyphicon-envelope"></span>'; $titl = 'Ingresar nuevo mensaje'; } $url = Yii::$app->urlManager->createUrl(['mensajes/create-ajax', 'modelName' => $model->className(), 'modelID' => $model->id]); return Html::a($text, $url, ['title' => $titl, 'onclick' => '$.ajax({ type :"POST", cache : false, url : $(this).attr("href"), success : function(response) { $("#divmensaje").html(response); $("#modalmensaje").modal("show"); } });return false;']); }], 'id', 'patente', 'marca', 'modelo', 'color']; $heading = '<i class="fa fa-car"></i> Vehiculos (Egreso)'; //$heading='Vehiculos'; break; case 'autorizantes': $columns = [['header' => '<span class="glyphicon glyphicon-trash"></span>', 'attribute' => 'Acción', 'format' => 'raw', 'value' => function ($model, $index, $widget) { $url = Yii::$app->urlManager->createUrl(['accesos/drop-lista', 'grupo' => 'autorizantes', 'id' => isset($model->id) ? $model->id : '']); return Html::a('<span class="glyphicon glyphicon-remove"></span>', $url, ['title' => 'Eliminar', 'onclick' => '$.ajax({ type : "POST", cache : false, url : $(this).attr("href"), success : function(r) { $("#divlistaautorizantes").html(r["autorizantes"]); } });return false;']); }], 'persona.apellido', 'persona.nombre', 'persona.nombre2', 'persona.nro_doc', 'id_uf']; $heading = '<i class="fa fa-key"></i> Autorizantes (Ingreso)'; break; } if ($grupo == 'egrpersonas' || $grupo == 'egrvehiculos') { $gvType = GridView::TYPE_DANGER; } else { $gvType = GridView::TYPE_INFO; } $response[$grupo] = GridView::widget(['dataProvider' => $dataProvider, 'layout' => '{items}', 'columns' => $columns, 'panel' => ['type' => $gvType, 'heading' => $heading, 'footer' => false, 'before' => false, 'after' => false], 'panelHeadingTemplate' => '{heading}', 'resizableColumns' => false, 'bordered' => false, 'striped' => true, 'condensed' => true, 'responsive' => true, 'hover' => false, 'toolbar' => false, 'export' => false]); } //foreach $response return $response; }
$titl = 'Ver mensaje sobre la persona'; } else { $text = '<span class="glyphicon glyphicon-user"></span>'; $titl = 'Ingresar nuevo mensaje sobre la persona'; } return Html::a($text, $url, ['title' => $titl, 'onclick' => '$.ajax({ type :"POST", cache : false, url : $(this).attr("href"), success : function(response) { $("#divmensaje").html(response); $("#modalmensaje").modal("show"); } });return false;']); }, 'mensajeV' => function ($url, $model) { $c = Mensajes::getMensajesByModelId('frontend\\models\\Vehiculos', $model->ing_id_vehiculo); if (!empty($c)) { $text = '<i class="fa fa-car" style="color:#FF8000"></i>'; $titl = 'Ver mensaje sobre el vehiculo'; } else { $text = '<i class="fa fa-car"></i>'; $titl = 'Ingresar nuevo mensaje sobre el vehiculo'; } return Html::a($text, $url, ['title' => $titl, 'onclick' => '$.ajax({ type :"POST", cache : false, url : $(this).attr("href"), success : function(response) { $("#divmensaje").html(response); $("#modalmensaje").modal("show"); }
} else { $text .= '></span>'; $titl = 'Ingresar nuevo comentario'; } return Html::a($text, $url, ['title' => $titl, 'onclick' => '$.ajax({ type :"POST", cache : false, url : $(this).attr("href"), success : function(response) { $("#divcomentarionuevo").html(response); $("#modalcomentarionuevo").modal("show"); } });return false;']); }, 'mensajeP' => function ($url, $model) { $c = Mensajes::getMensajesByModelId('frontend\\models\\Personas', $model->id_persona); if (!empty($c)) { $text = '<span class="glyphicon glyphicon-envelope" style="color:#FF8000"></span>'; $titl = 'Ver mensaje sobre la persona'; } else { $text = '<span class="glyphicon glyphicon-envelope"></span>'; $titl = 'Ingresar nuevo mensaje sobre la persona'; } return Html::a($text, $url, ['title' => $titl, 'onclick' => '$.ajax({ type :"POST", cache : false, url : $(this).attr("href"), success : function(response) { $("#divmensaje").html(response); $("#modalmensaje").modal("show"); }
} else { $text .= '></span>'; $titl = 'Ingresar nuevo comentario'; } return Html::a($text, $url, ['title' => $titl, 'onclick' => '$.ajax({ type :"POST", cache : false, url : $(this).attr("href"), success : function(response) { $("#divcomentarionuevo").html(response); $("#modalcomentarionuevo").modal("show"); } });return false;']); }, 'mensajeP' => function ($url, $model) { $c = Mensajes::getMensajesByModelId($model->className(), $model->id); if (!empty($c)) { $text = '<span class="glyphicon glyphicon-envelope" style="color:#FF8000"></span>'; $titl = 'Ver mensaje sobre el vehiculo'; } else { $text = '<span class="glyphicon glyphicon-envelope"></span>'; $titl = 'Ingresar nuevo mensaje sobre el vehiculo'; } return Html::a($text, $url, ['title' => $titl, 'onclick' => '$.ajax({ type :"POST", cache : false, url : $(this).attr("href"), success : function(response) { $("#divmensaje").html(response); $("#modalmensaje").modal("show"); }