Exemple #1
0
    public static function getPersonasPorVehiculo($id_vehiculo, $ultimasPersonas)
    {
        // se hace para verificar que exista el parametro pasado a esta funcion
        $p = Vehiculos::findOne($id_vehiculo);
        if (!$ultimasPersonas) {
            // trae todas las personas que usaron alguna vez el vehiculo, ordenadas por ultimo uso
            $command = \Yii::$app->db->createCommand('SELECT id_persona AS id_persona,MAX(ing_hora) AS ult 
													FROM accesos LEFT JOIN personas ON id_persona=personas.id
													WHERE ing_id_vehiculo=:vehiculo
													AND personas.estado=1
													GROUP BY id_persona
													ORDER BY ult DESC');
        } else {
            // trae las personas que usaron el vehiculo por ultima vez
            $command = \Yii::$app->db->createCommand('SELECT id_persona AS id_persona 
													FROM accesos LEFT JOIN personas ON id_persona=personas.id
													WHERE ing_id_vehiculo=:vehiculo 
													AND personas.estado=1													
													AND ing_hora IN (SELECT MAX(ing_hora) 
																		FROM accesos WHERE ing_id_vehiculo=:vehiculo)');
        }
        $command->bindParam(':vehiculo', $id_vehiculo);
        $personas = $command->queryAll();
        /*	
        foreach ($vehiculos as $vehiculo){
        	echo $vehiculo['id_vehiculo'];
        }
        */
        return $personas;
    }
    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' => '&nbsp;', '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;
    }
 /**
  * Finds the Vehiculos model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Vehiculos the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Vehiculos::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Vehiculo inexistente');
     }
 }
 public function actionListaVehiculos($id_persona)
 {
     // recupera los vehiculos utilizados por la persona en ingresos/egresos
     $vehiculos = Accesos::getVehiculosPorPersona($id_persona, true, true);
     // Si la persona es nueva o nunca tuvo accesos devuelve una bandera para que no se muestre el modal
     if (count($vehiculos) == 0) {
         return 'notFound';
     }
     $dp = [];
     foreach ($vehiculos as $veh) {
         foreach ($veh as $k => $v) {
             //Yii::trace($vehiculos);die;
             $dp[] = Vehiculos::findOne($v);
         }
     }
     $dataProvider = new ArrayDataProvider(['allModels' => $dp]);
     return $this->renderAjax('vehiculoslist', ['dataProvider' => $dataProvider]);
 }
Exemple #5
0
 public static function formateaVehiculoSelect2($id)
 {
     $p = Vehiculos::findOne($id);
     $r = $p->patente . ' ' . $p->marca . ' ' . $p->modelo . ' ' . $p->color . ' (' . $id . ')';
     return $r;
 }