MINI MINI MANI MO
<?php
namespace App\Http\Controllers;
use App\Models\Comisiones;
use App\Models\DatosUsers;
use App\Models\asistenciaVotos;
use App\Models\ComisionUsuario;
use App\Models\Commission;
use App\Models\EventoVotos;
use App\Models\mensajesVotos;
use App\Models\temasVotos;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use phpDocumentor\Reflection\DocBlock\Tags\Author;
use PhpParser\Node\Stmt\DeclareDeclare;
class OpinionController extends Controller
{
private $request;
public function __construct(Request $request) {
$this->request=$request;
// $this->middleware('auth');
}
public function index()
{
// if (auth()->user()->DatosUsers->tipo_usuario == 1) {
$UsuarioRegistro = auth()->user();
// dd($UsuarioRegistro);
// $parlamentarioComision = ComisionUsuario::where('id_users',$UsuarioRegistro)->get();
if ($UsuarioRegistro->permisoAcceso == 1) {
$eventoActivo = EventoVotos::where('estatus', 1)->get();
if (count($eventoActivo)) {
$temaVotos = temasVotos::where('status', 1)->get();
$votacion = mensajesVotos::where('status', 1)->get();
$favor = 0;
$contra = 0;
$abstencion = 0;
$totalVotos = 0;
$totalAsistencias = 0;
foreach ($votacion as $voto) {
if ($voto->mensaje == 'FAVOR') {
$favor = $favor + 1;
} elseif ($voto->mensaje == 'CONTRA') {
$contra = $contra + 1;
} elseif ($voto->mensaje == 'ABSTENCION') {
$abstencion = $abstencion + 1;
}
$totalVotos = $favor + $contra + $abstencion;
}
$asistencias = asistenciaVotos::where('status', 1)->where('randomEvento', $eventoActivo[0]->random)->orderBy('id_diputado', 'ASC')->get();
foreach ($asistencias as $asiste) {
if ($asiste->mensaje == 'ASISTENCIA') {
$totalAsistencias = $totalAsistencias + 1;
}
}
// $turnos = Turnos::where('status',1)->where('randomEvento',$eventoActivo[0]->random)->orderBy('created_at', 'ASC')->get();
return view("sistemaVotos.sistema", compact('eventoActivo', 'votacion', 'favor', 'contra', 'abstencion', 'totalVotos', 'asistencias', 'totalAsistencias', 'temaVotos'));
} else {
return view('sistemaVotos.aviso');
}
} else {
return redirect()->route('logout');
}
// }else{
// return redirect('cerrar');
// }
}
public function validaEventosActivos(){
$eventoActivo = EventoVotos::where('estatus', 1)->get();
if(count($eventoActivo)=='0'){
$inactivo='inactivo';
$response[] = array(
"sinactivo"=> $inactivo,
);
return json_encode($response);
}
$votacion = mensajesVotos::where('status',1)->get();
$asistencias = asistenciaVotos::where('status',1)->where('randomEvento',$eventoActivo[0]->random)->get();
$pertenece='si';
$asistencias = count($asistencias);
$votacion = count($votacion);
$response[] = array(
"asistencias"=>$asistencias,
"votacion"=>$votacion,
"pertenece" => $pertenece,
);
return json_encode($response);
}
public function validaEventosActivos2(){
$eventoActivo = EventoVotos::where('estatus', 1)->get();
$votacion = mensajesVotos::where('status',1)->get();
$asistencias = asistenciaVotos::where('status',1)->where('randomEvento',$eventoActivo[0]->random)->get();
$asistencias = count($asistencias);
$votacion = count($votacion);
$response[] = array(
"asistencias"=>$asistencias,
"votacion"=>$votacion,
);
return json_encode($response);
}
public function validaEventos(){
$eventoActivo1 = EventoVotos::where('estatus', 1)->get();
$asistencias1 = asistenciaVotos::where('status',1)->where('randomEvento',$eventoActivo1[0]->random)->get();
$votosActivos = mensajesVotos::where('status', 1)->get();
$eventoActivo2 = count($eventoActivo1);
$asistencias2 = count($asistencias1);
$votosActivos1 = count($votosActivos);
$response[] = array(
"evento"=>$eventoActivo2,
"asistencia"=>$asistencias2,
"voto"=>$votosActivos1,
);
return json_encode($response);
}
public function actualizaTotalesVotos(){
$votacion= mensajesVotos::where('status',1)->get();
$votacionFavor = 0;
$votacionContra = 0;
$votacionAbsten = 0;
foreach ($votacion as $v){
if($v->mensaje == 'FAVOR'){
$votacionFavor = $votacionFavor +1;
}
if($v->mensaje == 'CONTRA'){
$votacionContra = $votacionContra +1;
}
if($v->mensaje == 'ABSTENCION'){
$votacionAbsten = $votacionAbsten +1;
}
}
$totalVotos = $votacionFavor + $votacionContra + $votacionAbsten;
$response[] = array(
"votacionFavor"=>$votacionFavor,
"votacionContra"=>$votacionContra,
"votacionAbsten"=>$votacionAbsten,
"totalVotos"=>$totalVotos,
"tiempo"=>$votacion[0]->temaVoto->tiempoVotacion,
);
return json_encode($response);
}
public function actualizaListaVotacion(){
$votacion = DB::select("SELECT m.id_diputado, d.nombre, d.ap_pat, d.ap_mat, m.mensaje FROM mensajes_votos AS m, datos_users AS d WHERE m.id_diputado=d.id AND m.status=1 order by ap_pat,ap_mat ASC");
foreach($votacion as $e){
$response[] = array(
"id"=>$e->id_diputado,
"name"=>$e->nombre,
"ap_pat"=>$e->ap_pat,
"ap_mat"=>$e->ap_mat,
"mensaje"=>$e->mensaje,
);
}
return json_encode($response);
}
public function actualizaAsistencias(){
// $votacion = DB::select("SELECT * FROM asistencia_votos
// INNER JOIN datos_users ON asistencia_votos.id_diputado = datos_users.id WHERE asistencia_votos.status = '1'");
$votacion = DB::select("SELECT m.id_diputado, d.nombre, d.ap_pat, d.ap_mat, m.mensaje FROM asistencia_votos AS m, datos_users AS d WHERE m.id_diputado=d.id AND m.status=1 order by d.ap_pat, d.ap_mat ASC");
foreach($votacion as $e){
$response[] = array(
"id"=>$e->id_diputado,
"name"=>$e->nombre,
"ap_pat"=>$e->ap_pat,
"ap_mat"=>$e->ap_mat,
"mensaje"=>$e->mensaje,
);
}
// dd(json_encode($response));
return json_encode($response);
}
public function actasistot(){
$asistenciast = asistenciaVotos::where('status',1)->where('mensaje','ASISTENCIA')->get();
$asistenciast= count($asistenciast);
$response[] = array(
"asistenciast"=>$asistenciast,
);
return json_encode($response);
}
public function proyecta()
{
$eventoActivo = EventoVotos::where('estatus', 1)->get();
if (count($eventoActivo)) {
$comision = Comisiones::where('random', $eventoActivo[0]->tipoEventoIntegrantes)->get();
// dd($comision);
if ($comision[0]->random != 'jo7uWqChe') {
$parlamentarioComision = ComisionUsuario::where('id_commission', $comision[0]->id)->get();
// dd($parlamentarioComision);
foreach ($parlamentarioComision as $comisionUs) {
$comisiones[] = Commission::find($comisionUs->id_commission);
}
$temaVotos = temasVotos::where('status', 1)->get();
$votacion = mensajesVotos::where('status', 1)->get();
$favor = 0;
$contra = 0;
$abstencion = 0;
$totalVotos = 0;
$totalAsistencias = 0;
foreach ($votacion as $voto) {
if ($voto->mensaje == 'FAVOR') {
$favor = $favor + 1;
} elseif ($voto->mensaje == 'CONTRA') {
$contra = $contra + 1;
} elseif ($voto->mensaje == 'ABSTENCION') {
$abstencion = $abstencion + 1;
}
$totalVotos = $favor + $contra + $abstencion;
}
$asistencias = asistenciaVotos::where('status', 1)->where('randomEvento', $eventoActivo[0]->random)->get();
foreach ($asistencias as $asiste) {
if ($asiste->mensaje == 'ASISTENCIA') {
$totalAsistencias = $totalAsistencias + 1;
}
}
$turnos = Turnos::where('status', 1)->where('randomEvento', $eventoActivo[0]->random)->orderBy('created_at', 'ASC')->get();
foreach ($comisiones as $comision) {
if ($comision->random == $eventoActivo[0]->tipoEvento) {
dd('if');
return view("sistemaVotos.proyeccion", compact('eventoActivo', 'votacion', 'favor', 'contra', 'abstencion', 'totalVotos', 'asistencias', 'totalAsistencias', 'temaVotos', 'turnos'));
} else {
// dd('else');
// dd("no hay sesion activa");
return view("sistemaVotos.index");
}
}
}else{
$parlamentarioComision = DatosUsers::where('status',1)->get();
// dd($parlamentarioComision);
$temaVotos = temasVotos::where('status', 1)->get();
$votacion = mensajesVotos::where('status', 1)->get();
$favor = 0;
$contra = 0;
$abstencion = 0;
$totalVotos = 0;
$totalAsistencias = 0;
$asistencias = asistenciaVotos::where('status', 1)->where('randomEvento', $eventoActivo[0]->random)->get();
// $turnos = Turnos::where('status', 1)->where('randomEvento', $eventoActivo[0]->random)->orderBy('created_at', 'ASC')->get();
foreach ($votacion as $voto) {
if ($voto->mensaje == 'FAVOR') {
$favor = $favor + 1;
} elseif ($voto->mensaje == 'CONTRA') {
$contra = $contra + 1;
} elseif ($voto->mensaje == 'ABSTENCION') {
$abstencion = $abstencion + 1;
}
$totalVotos = $favor + $contra + $abstencion;
}
return view("sistemaVotos.proyeccion", compact('eventoActivo', 'votacion', 'favor', 'contra', 'abstencion', 'totalVotos', 'asistencias', 'totalAsistencias', 'temaVotos'));
dd('ghjkis' );
}
}else{
// dd('else22');
return view("sistemaVotos.index");
}
}
public function proyectaN()
{
$eventoActivo = EventoVotos::where('estatus', 1)->get();
if (count($eventoActivo)) {
$comision = Comisiones::where('random', $eventoActivo[0]->tipoEventoIntegrantes)->get();
// dd($comision);
if ($comision[0]->random != 'jo7uWqChe') {
$parlamentarioComision = ComisionUsuario::where('id_commission', $comision[0]->id)->get();
// dd($parlamentarioComision);
foreach ($parlamentarioComision as $comisionUs) {
$comisiones[] = Commission::find($comisionUs->id_commission);
}
$temaVotos = temasVotos::where('status', 1)->get();
$votacion = mensajesVotos::where('status', 1)->get();
$favor = 0;
$contra = 0;
$abstencion = 0;
$totalVotos = 0;
$totalAsistencias = 0;
foreach ($votacion as $voto) {
if ($voto->mensaje == 'FAVOR') {
$favor = $favor + 1;
} elseif ($voto->mensaje == 'CONTRA') {
$contra = $contra + 1;
} elseif ($voto->mensaje == 'ABSTENCION') {
$abstencion = $abstencion + 1;
}
$totalVotos = $favor + $contra + $abstencion;
}
$asistencias = asistenciaVotos::where('status', 1)->where('randomEvento', $eventoActivo[0]->random)->get();
foreach ($asistencias as $asiste) {
if ($asiste->mensaje == 'ASISTENCIA') {
$totalAsistencias = $totalAsistencias + 1;
}
}
$turnos = Turnos::where('status', 1)->where('randomEvento', $eventoActivo[0]->random)->orderBy('created_at', 'ASC')->get();
foreach ($comisiones as $comision) {
if ($comision->random == $eventoActivo[0]->tipoEvento) {
dd('if');
return view("sistemaVotos.proyeccionNV", compact('eventoActivo', 'votacion', 'favor', 'contra', 'abstencion', 'totalVotos', 'asistencias', 'totalAsistencias', 'temaVotos', 'turnos'));
} else {
// dd('else');
// dd("no hay sesion activa");
return view("sistemaVotos.index");
}
}
}else{
$parlamentarioComision = DatosUsers::where('status',1)->get();
// dd($parlamentarioComision);
$temaVotos = temasVotos::where('status', 1)->get();
$votacion = mensajesVotos::where('status', 1)->get();
$favor = 0;
$contra = 0;
$abstencion = 0;
$totalVotos = 0;
$totalAsistencias = 0;
$asistencias = asistenciaVotos::where('status', 1)->where('randomEvento', $eventoActivo[0]->random)->get();
// $turnos = Turnos::where('status', 1)->where('randomEvento', $eventoActivo[0]->random)->orderBy('created_at', 'ASC')->get();
foreach ($votacion as $voto) {
if ($voto->mensaje == 'FAVOR') {
$favor = $favor + 1;
} elseif ($voto->mensaje == 'CONTRA') {
$contra = $contra + 1;
} elseif ($voto->mensaje == 'ABSTENCION') {
$abstencion = $abstencion + 1;
}
$totalVotos = $favor + $contra + $abstencion;
}
//dd('ghjkis' );
return view("sistemaVotos.proyeccionNV", compact('eventoActivo', 'votacion', 'favor', 'contra', 'abstencion', 'totalVotos', 'asistencias', 'totalAsistencias', 'temaVotos'));
dd('ghjkis' );
}
}else{
// dd('else22');
return view("sistemaVotos.index");
}
}
public function proyectaC()
{
$eventoActivo = EventoVotos::where('estatus', 1)->get();
if (count($eventoActivo)) {
$comision = Comisiones::where('random', $eventoActivo[0]->tipoEventoIntegrantes)->get();
// dd($comision);
if ($comision[0]->random != 'jo7uWqChe') {
$parlamentarioComision = ComisionUsuario::where('id_commission', $comision[0]->id)->get();
// dd($parlamentarioComision);
foreach ($parlamentarioComision as $comisionUs) {
$comisiones[] = Commission::find($comisionUs->id_commission);
}
$temaVotos = temasVotos::where('status', 1)->get();
$votacion = mensajesVotos::where('status', 1)->get();
$favor = 0;
$contra = 0;
$abstencion = 0;
$totalVotos = 0;
$totalAsistencias = 0;
foreach ($votacion as $voto) {
if ($voto->mensaje == 'FAVOR') {
$favor = $favor + 1;
} elseif ($voto->mensaje == 'CONTRA') {
$contra = $contra + 1;
} elseif ($voto->mensaje == 'ABSTENCION') {
$abstencion = $abstencion + 1;
}
$totalVotos = $favor + $contra + $abstencion;
}
$asistencias = asistenciaVotos::where('status', 1)->where('randomEvento', $eventoActivo[0]->random)->get();
foreach ($asistencias as $asiste) {
if ($asiste->mensaje == 'ASISTENCIA') {
$totalAsistencias = $totalAsistencias + 1;
}
}
$turnos = Turnos::where('status', 1)->where('randomEvento', $eventoActivo[0]->random)->orderBy('created_at', 'ASC')->get();
foreach ($comisiones as $comision) {
if ($comision->random == $eventoActivo[0]->tipoEvento) {
return view("sistemaVotos.proyeccionC", compact('eventoActivo', 'votacion', 'favor', 'contra', 'abstencion', 'totalVotos', 'asistencias', 'totalAsistencias', 'temaVotos', 'turnos'));
} else {
// dd('else');
// dd("no hay sesion activa");
return view("sistemaVotos.index");
}
}
}else{
$parlamentarioComision = DatosUsers::where('status',1)->get();
// dd($parlamentarioComision);
$temaVotos = temasVotos::where('status', 1)->get();
$votacion = mensajesVotos::where('status', 1)->get();
$favor = 0;
$contra = 0;
$abstencion = 0;
$totalVotos = 0;
$totalAsistencias = 0;
$asistencias = asistenciaVotos::where('status', 1)->where('randomEvento', $eventoActivo[0]->random)->get();
// $turnos = Turnos::where('status', 1)->where('randomEvento', $eventoActivo[0]->random)->orderBy('created_at', 'ASC')->get();
foreach ($votacion as $voto) {
if ($voto->mensaje == 'FAVOR') {
$favor = $favor + 1;
} elseif ($voto->mensaje == 'CONTRA') {
$contra = $contra + 1;
} elseif ($voto->mensaje == 'ABSTENCION') {
$abstencion = $abstencion + 1;
}
$totalVotos = $favor + $contra + $abstencion;
}
return view("sistemaVotos.proyeccionC", compact('eventoActivo', 'votacion', 'favor', 'contra', 'abstencion', 'totalVotos', 'asistencias', 'totalAsistencias', 'temaVotos'));
// dd('ghjkis' );
}
}else{
// dd('else22');
return view("sistemaVotos.index");
}
}
public function consensoU(Request $request)
{
$temaVoto = temasVotos::where('status', 1)->first();
$UsuarioRegistro = auth()->user();
if($UsuarioRegistro->permisoAcceso == 1){
$votos = mensajesVotos::where('id_diputado',$UsuarioRegistro->DatosUsers->id)->where('id_votacion', $temaVoto['id'])->first();
$favor = mensajesVotos::find($votos['id']);
$voto["mensaje"] = 'FAVOR';
$voto["usuario_registra"] = $UsuarioRegistro->id;
$favor->update($voto);
}
}
public function disensoU(Request $request)
{
$UsuarioRegistro = auth()->user();
if($UsuarioRegistro->permisoAcceso == 1) {
$votos = mensajesVotos::where('id_diputado', $UsuarioRegistro->DatosUsers->id)->where('status', 1)->get();
$contra = mensajesVotos::find($votos[0]->id);
$voto["mensaje"] = 'CONTRA';
$voto["usuario_registra"] = $UsuarioRegistro->id;
$contra->update($voto);
}
}
public function abstencionU(Request $request)
{
// dd("llego");
$UsuarioRegistro = auth()->user();
if($UsuarioRegistro->permisoAcceso == 1) {
$votos = mensajesVotos::where('id_diputado', $UsuarioRegistro->DatosUsers->id)->where('status', 1)->get();
$abs = mensajesVotos::find($votos[0]->id);
$voto["mensaje"] = 'ABSTENCION';
$voto["usuario_registra"] = $UsuarioRegistro->id;
$abs->update($voto);
}
}
public function sinRegistroU(Request $request)
{
// dd("llego");
$UsuarioRegistro = auth()->user();
if($UsuarioRegistro->permisoAcceso == 1) {
$votos = mensajesVotos::where('id_diputado', $UsuarioRegistro->DatosUsers->id)->where('status', 1)->get();
$sin = mensajesVotos::find($votos[0]->id);
$voto["mensaje"] = 'SIN REGISTRO';
$voto["usuario_registra"] = $UsuarioRegistro->id;
$sin->update($voto);
}
}
public function asistenciaU(Request $request)
{
$UsuarioRegistro = auth()->user();
$activo = User::where('id',$UsuarioRegistro->id)->first();
if($activo->permisoAcceso == 1){
$asisten = asistenciaVotos::where('id_diputado',$UsuarioRegistro->DatosUsers->id)->where('status',1)->first();
$asistencia = asistenciaVotos::find($asisten->id);
$asiste["mensaje"] = 'ASISTENCIA';
$voto["usuario_registra"] = $UsuarioRegistro;
$asistencia->update($asiste);
}
}
public function actualizaTemaVotos(){
$temaActivo = temasVotos::where('status', 1)->first();
$response[] = array(
"temaV"=>$temaActivo->votacion,
);
return json_encode($response);
}
}
OHA YOOOO