<?php

namespace Daite\Coopdigital\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

use Illuminate\Support\Facades\DB;

class ControladorAfiliar extends Controller {

    function identificacion($identificacion) {

        $cliente = DB::select(
            "SET NOCOUNT ON; EXEC [AppMovil].[p_traer_datos_cliente] ?, ?",
            ['', $identificacion]
        );

        $padron = DB::select("SET NOCOUNT ON; EXEC [AppMovil].[p_traer_cedula_padron] ?, ?, ?, ?", ['', '', '', "$identificacion"]);

        if (count($cliente)) {

            foreach ($padron[0] as $campo => $valor)
                $padron[0]->$campo = ''
            ;

            $padron[0]->mensaje = $cliente[0]->mensaje;

        }

        return $padron;

    }

    function sexos(Request $request) {

        return DB::select("EXEC [AppMovil].[p_traer_filtros_registros] ?, ?", ['', 'SEXOS']);

    }

    function provincias(Request $request) {

        return DB::select("EXEC [AppMovil].[p_traer_filtros_registros] ?, ?", ['', 'PROVINCIAS']);

    }

    function municipios(Request $request) {

        return DB::select("EXEC [AppMovil].[p_traer_filtros_registros] ?, ?, ?", ['', 'MUNICIPIOS', $request->id_provincia]);

    }

    function sectores(Request $request) {

        return DB::select("EXEC [AppMovil].[p_traer_filtros_registros] ?, ?, ?", ['', 'SECTORES', $request->id_municipio]);

    }

}