<?php

namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
use Illuminate\Pagination\Paginator;
use Illuminate\Pagination\LengthAwarePaginator;

class CatalogoGeneralController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
       // $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */


    public function index($area=false, $marca=false,$rubro=false,$unidad=false){


       if($area){

           
            $consulta= DB::connection('mysql')->select(DB::raw("SELECT * FROM v_catalogo_general WHERE id_area=$area"));

            if($marca){

                 $consulta= DB::connection('mysql')->select(DB::raw("SELECT * FROM v_catalogo_general WHERE id_area=$area and id_marca=$marca"));

            }

                if($rubro){

                    $consulta= DB::connection('mysql')->select(DB::raw("SELECT * FROM v_catalogo_general WHERE id_area=$area and id_marca=$marca and id_rubro=$rubro"));

                }

                    if($unidad){

                        $consulta= DB::connection('mysql')->select(DB::raw("SELECT * FROM v_catalogo_general WHERE id_area=$area and id_marca=$marca and id_rubro=$rubro and id_unidad=$unidad"));

                    }



         }else{

            $consulta= DB::connection('mysql')->select(DB::raw("SELECT * FROM v_catalogo_general"));

         }

       

       return $consulta;




    }
   
}
