<?php

namespace App\Http\Controllers;

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

class c_Clientes 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."'");
                $clientes = DB::connection('clientesMysql')->select("SELECT * FROM clientes_mz");
                return view('clientes.v_listaClientes', compact('datos', 'clientes'));

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

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

                DB::connection('clientesMysql')->insert('INSERT INTO clientes_mz VALUES("'.$request['rzn_scl'].'","'.$request['rfc'].'")');

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

    public function editarCliente(Request $request)
    {
        $clientes = DB::connection('clientesMysql')->select("UPDATE clientes_mz SET RFC = '".$request['rfc']."', nombre = '".$request['nombre']."' WHERE RFC = '".$request['rfc']."'");
        return back();
    }

    public function word(Request $request)
    {

 
        // New Word Document
        $phpWord = new \PhpOffice\PhpWord\PhpWord();
        
        // Define styles
        $multipleTabsStyleName = 'multipleTab';
        $phpWord->addParagraphStyle(
            $multipleTabsStyleName,
            array(
                'tabs' => array(
                    new \PhpOffice\PhpWord\Style\Tab('left', 1550),
                    new \PhpOffice\PhpWord\Style\Tab('center', 3200),
                    new \PhpOffice\PhpWord\Style\Tab('right', 5300),
                ),
            )
        );
        
        $rightTabStyleName = 'rightTab';
        $phpWord->addParagraphStyle($rightTabStyleName, array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('right', 9090))));
        
        $leftTabStyleName = 'centerTab';
        $phpWord->addParagraphStyle($leftTabStyleName, array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('center', 4680))));
        
        // New portrait section
        $section = $phpWord->addSection();
        
        // Add listitem elements
        $section->addText("Multiple Tabs:\tOne\tTwo\tThree", null, $multipleTabsStyleName);
        $section->addText("Left Aligned\tRight Aligned", null, $rightTabStyleName);
        $section->addText("\tCenter Aligned", null, $leftTabStyleName);
        
        // Save file




}

}