<?php

namespace App\Http\Controllers\RectificacionesActuales;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
use App\rec_manzanillo;
use App\rec_lazaro;
use App\rec_mexico;
use App\rec_veracruz;

use App\User;

class c_Rectificaciones extends Controller
{
    public function index(Request $request)
    {
        if(Auth::check()){
            if($request->user()->hasRole('Administrador') || $request->user()->hasRole('Estandar')){

                $id = auth()->user()->id;
                $datos = DB::connection('usuariosMysql')->select("select * from vw_list_user WHERE id = '".$id."'");
                $MZ = rec_manzanillo::paginate(100);
                $MX = rec_mexico::paginate(30);
                $VZ = rec_veracruz::paginate(30);
                $LZ = rec_lazaro::paginate(30);
                // $MX = DB::select('SELECT * FROM rectificaciones_mx');
                // $VZ = DB::select('SELECT * FROM rectificaciones_vz');
                // $LZ = DB::select('SELECT * FROM rectificaciones_lz');
                $Clnts = DB::connection('clientesMysql')->select('SELECT * FROM clientes_MZ');
                return view('rectificaciones.v_listaRectificaciones',compact('datos', 'Clnts', 'MZ','VZ','MX','LZ'));

            }else {
                return redirect()->route('login');
            }
        }else {
            return redirect()->route('login');
        }
        
    }

    public function generarREC(Request $request)
    {
        if(Auth::check()){
            if($request->user()->hasRole('Administrador') || $request->user()->hasRole('Estandar')){

                $id = auth()->user()->id;
                $datos = DB::connection('usuariosMysql')->select("select * from vw_list_user WHERE id = '".$id."'");
                $referenciasMZ2019 = DB::connection('bitacora2019Mysql')->select("select * from referencias_mz");
                return view('rectificaciones.v_generarRec', compact('datos', 'referenciasMZ2019'));

            }else {
                return redirect()->route('login');
            }
        }else {
            return redirect()->route('login');
        }
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////////////

    
}
