<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;

class nomspermcontroller extends Controller
{
    //
    public function getFracc()
    {
        //$infoFD=FraccionesDerogadas::All();
        $infoFD=DB::select('select * from fracc_noms');
        
        return view('intern.fracciones.index',[
            'Fracc'=>$infoFD,
        ]);
        //return $infoFD;
    }

    public function getNomsPerm($idFracc)
    {
        $InfoNoms=DB::select("select * from noms_perm where frac=? and cond=1",[$idFracc]);        
        return $InfoNoms;
    }

    public function postCRUD(Request $InfoIDF)    
    {
        switch($InfoIDF['oper'])
        {
            case 'C':
                DB::insert('insert into noms_perm (frac, id1, c1, c2, c3) values (?, ?, ?, ?, ?)', [$InfoIDF['idBD'], "".Str::upper($InfoIDF['idNomPerm'])."","".Str::upper($InfoIDF['idC1'])."","".Str::upper($InfoIDF['idC2'])."","".Str::upper($InfoIDF['idC3']).""]);
                break;
            case 'U':
                $idDeLaFrac=DB::select("select * from noms_perm where idnp=?",[$InfoIDF['idBD']]);
                DB::update('update noms_perm set frac='.$idDeLaFrac[0]->frac.',id1="'.Str::upper($InfoIDF['idNomPerm']).'",c1="'.Str::upper($InfoIDF['idC1']).'",c2="'.Str::upper($InfoIDF['idC2']).'",c3="'.$InfoIDF['idC3'].'" where idnp=?',[$InfoIDF['idBD']]);
                break;
            default;
                break;
        }

        return redirect('/int/fracciones_noms');
    }

    public function eliminar_reg($idDato)
    {
        $Datos=DB::select("select * from noms_perm where idnp=?",[$idDato]);
        DB::update('update noms_perm set cond=0 where idnp=?',[$idDato]);
        return "Se eliminó el registro\rID: ".$Datos[0]->idnp." CASO1: ".$Datos[0]->c1." CASO2: ".$Datos[0]->c2." CASO3: ".$Datos[0]->c3;
    }

    public function getNomsP($Fracc)
    {        
        $idFracc=DB::select("select * from fracc_noms where numfra=?",[$Fracc]);
        $InfoNoms=DB::select("select * from noms_perm where frac=? and cond=1",[$idFracc[0]->idfrn]);
        return $InfoNoms;
    }

}
