MINI MINI MANI MO

Path : /var/www/html/sistemas/archivodigital/app/Http/Controllers/
File Upload :
Current File : /var/www/html/sistemas/archivodigital/app/Http/Controllers/IntegrantesController.php

<?php

namespace App\Http\Controllers;

use App\Models\PumpesGabinete;
use App\Models\Integrantes;
use App\Models\UsuariosCentralizada;
use App\Models\Diputado;
use GuzzleHttp\Client;
use Illuminate\Http\Request;
use Carbon\Carbon;
use DateTime;

class IntegrantesController extends Controller
{
    private $request;

    public function __construct(Request $request) {
        $this->request=$request;
        $this->middleware('auth');
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {

        $inte = Diputado::all();
        $rows = [];
        foreach ($inte as $item) {
            $rows[$item->id] = $item->nombres .' '.$item->apaterno.' '.$item->amaterno;
        }
        return view("diputados.ficha.show", compact('rows'));

    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Models\Integrantes  $integrantes
     * @return \Illuminate\Http\Response
     */
    public function show(Integrantes $integrantes)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Models\Integrantes  $integrantes
     * @return \Illuminate\Http\Response
     */
    public function edit(Integrantes $integrantes)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\Integrantes  $integrantes
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Integrantes $integrantes)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Models\Integrantes  $integrantes
     * @return \Illuminate\Http\Response
     */
    public function destroy(Integrantes $integrantes)
    {
        //
    }

    public function getInfo(Request $request,$id)
    {

        $data = Diputado::where('id', $id)->with(["integranteLegislatura" => function ($q) {
            $q->with('partido')->with(["distrito" => function ($q) {
                $q->with('municipio');
            }])->with(["comisiones" => function ($q) {
                $q->with('comision')->with('cargo');
            }]);
        }])->with('genero')->with('foto')->first();

        $nombre =   $data->apaterno . " " . $data->amaterno . " " . $data->nombres;
        $data1 = UsuariosCentralizada::where("Nombre", $nombre)->first();

        if($data1){
            $anio = substr($data1->N_Usuario, -6);
            $year = substr($anio, 0, 2);
            $month = substr($anio, 2, 2);
            $day = substr($anio, 4, 2);
            $fullYear = $year > 50 ? '19' . $year : '20' . $year;
            $fechna =  Carbon::createFromFormat('Y-m-d', "$fullYear-$month-$day");
            $formattedDate = $fechna->translatedFormat('j \d\e F ');
            $fechana = $fechna->translatedFormat('j \d\e F Y');
            $data->fechanac = $formattedDate;
            $data->fechanaci = $fechana;
        }
        return json_decode($data);
    }

    public function integrantesgabinete()
    {

        $inte = PumpesGabinete::all();
        $rows = [];
        foreach ($inte as $item) {
            $rows[$item->id] = $item->nombre ;
        }
        return view("diputados.ficha.show2", compact('rows'));

    }

    public function getgabinete(Request $request,$id)
    {
        $data = PumpesGabinete::where('id', $id)->first();
        $fechna = Carbon::createFromFormat('Y-m-d', "$data->fecha_nacimiento");
        $formattedDate = $fechna->translatedFormat('j \d\e F ');
        $fechana = $fechna->translatedFormat('j \d\e F Y');
        $data->fechanac = $formattedDate;
        $data->fechanaci = $fechana;
        return json_decode($data);
    }

    public function cumple()
    {
        $hoy = Carbon::now();
        $nombreMes = $hoy->translatedFormat('F');
        $data = PumpesGabinete::whereMonth('fecha_nacimiento', $hoy->month)
                ->whereDay('fecha_nacimiento', '>=', $hoy->day)
                ->orderByRaw('DAY(fecha_nacimiento) ASC')
                ->get();
        $mesSiguiente = $hoy->copy()->addMonth()->month;
        $data2 = PumpesGabinete::whereMonth('fecha_nacimiento', $mesSiguiente)
            ->orderByRaw('DAY(fecha_nacimiento) ASC')
            ->get();

        $cumpmes = [];
        $diputados = UsuariosCentralizada::where('Puesto', 'LEGISLADOR')
            ->where('Estado', 1)
            ->get();

        foreach ($diputados as $diputado) {
            $nUsuario = $diputado->N_Usuario;
            $anioRaw = substr($nUsuario, -6);

            $year = substr($anioRaw, 0, 2);
            $month = substr($anioRaw, 2, 2);
            $day = substr($anioRaw, 4, 2);

            $fullYear = $year > 50 ? '19' . $year : '20' . $year;

            try {
                $fechaNacimiento = Carbon::createFromFormat('Y-m-d', "$fullYear-$month-$day");
            } catch (\Exception $e) {
                continue;
            }

            if ($fechaNacimiento->month == $hoy->month && $fechaNacimiento->day >= $hoy->day) {
                $diputado['fecha_cumpe'] = $fechaNacimiento;
                $diputado['fecha_O'] = $fechaNacimiento->format('d/m/Y');
                $cumpmes[] = $diputado;
            }
        }
        usort($cumpmes, fn($a, $b) => $a['fecha_cumpe']->day <=> $b['fecha_cumpe']->day);


        $cumpmessiguiente = [];
        $hoy = now();
        $mesSiguiente = $hoy->copy()->addMonth()->month;
        $nombreMesSiguiente = $hoy->copy()->addMonth()->translatedFormat('F');
        foreach ($diputados as $diputado) {
            $nUsuario = $diputado->N_Usuario;
            $anioRaw = substr($nUsuario, -6);

            $year = substr($anioRaw, 0, 2);
            $month = substr($anioRaw, 2, 2);
            $day = substr($anioRaw, 4, 2);

            $fullYear = $year > 50 ? '19' . $year : '20' . $year;

            try {
                $fechaNacimiento = Carbon::createFromFormat('Y-m-d', "$fullYear-$month-$day");
            } catch (\Exception $e) {
                continue;
            }
            if ($fechaNacimiento->month == $mesSiguiente) {
                $diputado['fecha_cumpe'] = $fechaNacimiento;
                $diputado['fecha_O'] = $fechaNacimiento->format('d/m/Y');
                $cumpmessiguiente[] = $diputado;
            }
        }

        usort($cumpmessiguiente, fn($a, $b) => $a['fecha_cumpe']->day <=> $b['fecha_cumpe']->day);
//        dd($cumpmessiguiente);
        return view("diputados.ficha.index", compact('cumpmes', 'data', 'data2', 'cumpmessiguiente', 'nombreMesSiguiente','nombreMes'));
    }
}



OHA YOOOO