<?php

namespace App\Http\Controllers\ReferenciasAntiguas;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
use App\User;


class c_referencias_2019 extends Controller
{

    /////////////////////////////// MANZANILLO //////////////////////////////////////////////
     
    public function buscadorRefMZ2019(Request $request){
        $referenciasMZ2019 = DB::connection('bitacora2019Mysql')->select("select * from referencias_mz WHERE pedimento = '".$request['referencia']."'");
        $list = '<tr>';
        
        foreach($referenciasMZ2019 as $var){
            $list .= '<td>'.$var->folio.'</td>';
            $list .= '<td>'.$var->cliente.'</td>';
        }
        $list .= '</tr>';

        return $list;
    }

    public function ageRefAnt2019(Request $request){
        $ageMZ2019 = DB::connection('bitacora2019Mysql')->select("select * from referencias_mz");

        $list = '<select class="form-control" style="border:#a3a3a3 solid 0.5px; border-bottom:2px #a3a3a3 solid;" id="listReferenciasMZ"><option>Selecciona la referencia</option>';
        foreach($ageMZ2019 as $var){
            $list .= '<option value="'.$var->pedimento.'">'.$var->pedimento.'</option>';
        }
        $list .= '</select><script>tail.select("#listReferenciasMZ", {locale: "es",height: 250,classNames: "null",
            animate: true,search: true,searchFocus: true,searchMarked: true,});</script>';

            $list .= '<script>$(document).ready(function(){$("#listReferenciasMZ").change(function(){var referencia = $("#listReferenciasMZ").val();
                    $.ajax({type: "GET",url: "buscRef2019MZ",data: {"referencia": referencia,},success:function(result){
                    $("#TBMZBuscador").html(result);},error:function (xhr, ajaxOptions, thrownError){if(xhr.status==404) {alert(thrownError);
                    }}});});});</script>';
        return $list;
    }

    /////////////////////////////// VERACRUZ //////////////////////////////////////////////
     
    public function buscadorRefVZ2019(Request $request){
        $referenciasVZ2019 = DB::connection('bitacora2019Mysql')->select("select * from referencias_vz WHERE pedimento = '".$request['referencia']."'");
        $list = '<tr>';
        
        foreach($referenciasVZ2019 as $var){
            $list .= '<td>'.$var->folio.'</td>';
            $list .= '<td>'.$var->cliente.'</td>';
        }
        $list .= '</tr>';

        return $list;
    }

    public function ageRefAntVZ2019(Request $request){
        $ageVZ2019 = DB::connection('bitacora2019Mysql')->select("select * from referencias_vz");

        $list = '<select class="form-control" style="border:#a3a3a3 solid 0.5px; border-bottom:2px #a3a3a3 solid;" id="listReferenciasVZ"><option>Selecciona la referencia</option>';
        foreach($ageVZ2019 as $var){
            $list .= '<option value="'.$var->pedimento.'">'.$var->pedimento.'</option>';
        }
        $list .= '</select><script>tail.select("#listReferenciasVZ", {locale: "es",height: 250,classNames: "null",
            animate: true,search: true,searchFocus: true,searchMarked: true,});</script>';

            $list .= '<script>$(document).ready(function(){$("#listReferenciasVZ").change(function(){var referencia = $("#listReferenciasVZ").val();
                    $.ajax({type: "GET",url: "buscadorRefVZ2019",data: {"referencia": referencia,},success:function(result){
                    $("#TBVZBuscador").html(result);},error:function (xhr, ajaxOptions, thrownError){if(xhr.status==404) {alert(thrownError);
                    }}});});});</script>';
        return $list;
    }

    /////////////////////////////// LÁZARO CÁRDENAS //////////////////////////////////////////////
     
    public function buscadorRefLZ2019(Request $request){
        $referenciasLZ2019 = DB::connection('bitacora2019Mysql')->select("select * from referencias_lz WHERE pedimento = '".$request['referencia']."'");
        $list = '<tr>';
        
        foreach($referenciasLZ2019 as $var){
            $list .= '<td>'.$var->folio.'</td>';
            $list .= '<td>'.$var->cliente.'</td>';
        }
        $list .= '</tr>';

        return $list;
    }

    public function ageRefAntLZ2019(Request $request){
        $ageVZ2019 = DB::connection('bitacora2019Mysql')->select("select * from referencias_lz");

        $list = '<select class="form-control" style="border:#a3a3a3 solid 0.5px; border-bottom:2px #a3a3a3 solid;" id="listReferenciasLZ"><option>Selecciona la referencia</option>';
        foreach($ageVZ2019 as $var){
            $list .= '<option value="'.$var->pedimento.'">'.$var->pedimento.'</option>';
        }
        $list .= '</select><script>tail.select("#listReferenciasLZ", {locale: "es",height: 250,classNames: "null",
            animate: true,search: true,searchFocus: true,searchMarked: true,});</script>';

            $list .= '<script>$(document).ready(function(){$("#listReferenciasLZ").change(function(){var referencia = $("#listReferenciasLZ").val();
                    $.ajax({type: "GET",url: "buscadorRefLZ2019",data: {"referencia": referencia,},success:function(result){
                    $("#TBLZBuscador").html(result);},error:function (xhr, ajaxOptions, thrownError){if(xhr.status==404) {alert(thrownError);
                    }}});});});</script>';
        return $list;
    }

    /////////////////////////////// MÉXICO //////////////////////////////////////////////
     
    public function buscadorRefMX2019(Request $request){
        $referenciasMX2019 = DB::connection('bitacora2019Mysql')->select("select * from referencias_mx WHERE pedimento = '".$request['referencia']."'");
        $list = '<tr>';
        
        foreach($referenciasMX2019 as $var){
            $list .= '<td>'.$var->folio.'</td>';
            $list .= '<td>'.$var->cliente.'</td>';
        }
        $list .= '</tr>';

        return $list;
    }

    public function ageRefAntMX2019(Request $request){
        $ageVZ2019 = DB::connection('bitacora2019Mysql')->select("select * from referencias_mx");

        $list = '<select class="form-control" style="border:#a3a3a3 solid 0.5px; border-bottom:2px #a3a3a3 solid;" id="listReferenciasMX"><option>Selecciona la referencia</option>';
        foreach($ageVZ2019 as $var){
            $list .= '<option value="'.$var->pedimento.'">'.$var->pedimento.'</option>';
        }
        $list .= '</select><script>tail.select("#listReferenciasMX", {locale: "es",height: 250,classNames: "null",
            animate: true,search: true,searchFocus: true,searchMarked: true,});</script>';

            $list .= '<script>$(document).ready(function(){$("#listReferenciasMX").change(function(){var referencia = $("#listReferenciasMX").val();
                    $.ajax({type: "GET",url: "buscadorRefMX2019",data: {"referencia": referencia,},success:function(result){
                    $("#TBMXBuscador").html(result);},error:function (xhr, ajaxOptions, thrownError){if(xhr.status==404) {alert(thrownError);
                    }}});});});</script>';
        return $list;
    }
}
