/home/dvjjulio/softtrash/app/Http/Controllers/ReportController.php
<?php

namespace Trash\Http\Controllers;

use Illuminate\Http\Request;

use Trash\Http\Requests;
use Trash\Http\Controllers\Controller;
use Maatwebsite\Excel\Facades\Excel;
use Trash\User;
use Trash\Ordenes;
use Trash\Clientes;
use Trash\ReportConfig;
use Trash\UserCliente;
use Fpdf;
use URL;
use Helper;
use Auth;

class ReportController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function reportOrder()
    {
        //
        $users = User::where('tipo_usuario_id','=',2)->orderBy('username')->get();
        $clientes = Clientes::where('status_id','=',1)->orderBy('nombre_comercial')->get();
        return view('report.reportOrden')->with(compact('users','clientes'));
    }

    public function reportCliente(){
        $reportConfig = new ReportConfig();
        $years = $reportConfig->year_orden();
        $months = $reportConfig->mes_orden();
        if(Auth::user()->tipo_usuario_id == 3){
          $clientes = UserCliente::where('user_id','=',Auth::user()->id)->get();
          $id_clientes = [];
          foreach ($clientes as $key => $value) {
            $id_clientes[$key] = $value->cliente_id;
          }
          $clientes = Clientes::where('status_id','=',1)->whereIn('id',$id_clientes)->orderBy('nombre_comercial')->get();
        }else{
          $clientes = Clientes::where('status_id','=',1)->orderBy('nombre_comercial')->get();
        }
        return view('report.reportCliente')->with(compact('clientes','months','years'));;
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function ordenReport($fecha_ini,$fecha_ter,$conductores,$clientes){
       $ordenes = new Ordenes();
       $orden = $ordenes->ordenReport($fecha_ini,$fecha_ter,$conductores,$clientes);

       if(!$orden->getData()->status){
         return "No hay resultados disponibles";
       }

        $ordenes = $orden->getData()->data;

        header('Content-Type: text/html; charset=utf-8');
        header("Content-type: application/vnd.ms-excel" ) ;
        header("Content-Disposition: attachment; filename=reporte.xls" );


        $tabla = "<table border=1 color='gray'>
                        <tr>
                            <th>No Orden</th>
                            <th>Fecha</th>
                            <th>Dia</th>
                            <th>Mes</th>
                            <th>Razon Social</th>
                            <th>SEMADES</th>
                            <th>Nombre Comercial</th>
                            <th>Cuota</th>
                            <th>Unidad</th>
                            <th>P.U.</th>
                            <th>Placas</th>
                            <th>Conductor</th>
                            <th>Peso</th>
                            <th>Toneladas</th>
                            <th>Cantidad</th>
                            <th>Reciclable</th>
                            <th>Clasificacion</th>
                            <th>Peso Reciclable</th>
                            <th>Toneladas Reciclable</th>
                            <th>Observaciones</th>
                            <th>Hora Inicio</th>
                            <th>Hora Termino</th>
                            <th>Km</th>
                            <th>Inorganicos</th>
                            <th>Organicos</th>
                            <th>Sanitarios</th>
                            <th>Costo Pago</th>
                            <th>Total Pago</th>
                            <th>Costo Cliente</th>
                            <th>Total Cliente</th>
                        </tr>";
        foreach ($ordenes as $key => $orden) {
                   $tabla .= "<tr>
                                <td>".$orden->orden_no."</td>
                                <td>".$orden->fecha."</td>
                                <td>".$orden->dia."</td>
                                <td>".$orden->Mes."</td>
                                <td>".$orden->razon_social."</td>
                                <td>".$orden->semades."</td>
                                <td>".$orden->cliente."</td>
                                <td>".$orden->cuota."</td>
                                <td>".$orden->unidad."</td>
                                <td>".$orden->pu."</td>
                                <td>".$orden->placas."</td>
                                <td>".$orden->username."</td>
                                <td>".$orden->peso."</td>
                                <td>".$orden->toneladas."</td>
                                <td>".$orden->cantidad."</td>
                                <td>".$orden->reciclable."</td>
                                <td>".utf8_decode($orden->clasificacion)."</td>
                                <td>".$orden->peso_reciclable."</td>
                                <td>".$orden->toneladas_r."</td>
                                <td>".$orden->observaciones."</td>
                                <td>".$orden->hora_inicio."</td>
                                <td>".$orden->hora_termino."</td>
                                <td>".$orden->km_dif."</td>
                                <td>".$orden->inorganicos."</td>
                                <td>".$orden->organicos."</td>
                                <td>".$orden->sanitarios."</td>
                                <td>".$orden->costo_pago."</td>
                                <td>$".number_format($orden->costo_pago * $orden->peso_reciclable,3)."</td>
                                <td>".$orden->costo_cliente."</td>
                                <td>$".number_format($orden->costo_cliente * $orden->peso_reciclable,3)."</td>
                            </tr>";
            }
            //($key == 0)? \Helper::km_rest($orden->km, $orden->kilometraje_inicio) : \Helper::km_rest($orden->km, $ordenes[$key-1]->km)
            $tabla ."</table>";
            return $tabla;
    }

    public function newSheet(){
      $pdf = new Fpdf();
      $pdf::AddPage('P','Letter');
      $pdf::Image(__DIR__.'/../../../public/img/reporte/marca_agua.jpg',0,0,217,'jpg');
      return $pdf;
    }

    public function pdfReport(Request $request){
      $data = $request->all();
      $m = (int)date('m');
      $date = date('Y')."-".$m;
      if(Auth::user()->tipo_usuario_id == 3 && $date == $data['year-select']."-".$data['month-select'] && date('d') <= 10){
          
        return "Disculpa las molestias este reporte esta en proceso. Te agradecemos tu preferencia Recolectora Metropolitana.";
      }
      
       
        $hojaTotal = 0;
        if($data['tipo-select'] == "" || $data['clientes-select'] == "" || $data['month-select'] == "" || $data['year-select'] == ""){
          return "Se debe Seleccionar Tipo de Reporte, Cliente, Mes y Año";
        }else{
          $id = $data['clientes-select'];
          $month = $data['month-select'];
          $year = $data['year-select'];
          switch ($data['tipo-select']) {
            case 1:
                return $this->ReportManifiesto($id,$year,$month);
              break;
            case 2:
                return $this->ReportReciclable2($id,$year,$month);
              break;
            case 3:
              return $this->ReportReciclableCosto($id,$year,$month);
            break;

            default:
              # code...
              break;
          }
        }
    }

    public function ReportManifiesto($id,$year,$month){

        $ordenes = new Ordenes();
        $orden = $ordenes->tota_orden($id, $year, $month);
        $dataOrden = $orden->getData()->data;

        if($dataOrden == ""){
           return "No hay Ordenes Registradas";
        }
        $x = 18;
        $pdf = $this->infoCompany($x);


        /*$pdf::SetFont('Arial','B',12);
        $pdf::Cell(120,10,utf8_decode("Ubicación del vertedero autorizado:"),0);
        $pdf::Cell(50,10,strtoupper(utf8_decode("Autorizacion Vigente:")),0);
        $pdf::SetXY($x,$pdf::GetY()+$y);
        $pdf::SetFont('Arial','',12);
        $pdf::Cell(120,10,strtoupper(utf8_decode($data->vertedero2)),0);
        $pdf::Cell(50,10,strtoupper(utf8_decode($data->codigo2)),0);
        $pdf::SetXY($x,$pdf::GetY()+$y);
        $pdf::Cell(50,10,(utf8_decode($data->direccion2)),0);
        $pdf::SetXY($x,$pdf::GetY()+$y);
        $pdf::Cell(50,10,(utf8_decode($data->direccion2_2)),0);*/

        $pdf::SetXY($x,185);
        $pdf::SetFont('Arial','B',9);
        $pdf::SetTextColor(255,255,255,1);
        $pdf::SetDrawColor(255,255,255,1);
        $pdf::SetFillColor(71,147,200);
        $pdf::Cell(120,10,utf8_decode("Cliente: ".$dataOrden[0]->cliente),0);

        $pdf::SetXY($x,195);
        $pdf::Cell(30,10,(utf8_decode("AÑO")),1,0,'C',1);
        $pdf::Cell(30,10,(utf8_decode("MES")),1,0,'C',1);
        $pdf::MultiCell(30,5,(utf8_decode("TONELADAS INORGANICO")),1,'C',1);
        $pdf::SetXY(108,195);
        $pdf::MultiCell(30,5,(utf8_decode("TONELADAS ORGANICO")),1,'C',1);
        $pdf::SetXY(138,195);
        $pdf::MultiCell(30,5,(utf8_decode("TONELADAS SANITARIO")),1,'C',1);
        $pdf::SetXY(168,195);
        $pdf::MultiCell(30,5,(utf8_decode("TOTAL TONELADAS")),1,'C',1);

        $pdf::SetFont('Arial','B',11);
        $pdf::SetTextColor(0,0,0);
        $pdf::SetFillColor(221,235,246);
        $pdf::SetXY($x,205);
        $pdf::Cell(30,7,$dataOrden[0]->Year,1,0,'C',1);
        $pdf::Cell(30,7,$dataOrden[0]->Mes,1,0,'C',1);
        $pdf::MultiCell(30,7,Helper::redondeado($dataOrden[0]->inorganicos,3),1,'C',1);
        $pdf::SetXY(108,205);
        $pdf::MultiCell(30,7,Helper::redondeado($dataOrden[0]->organicos,3),1,'C',1);
        $pdf::SetXY(138,205);
        $pdf::MultiCell(30,7,Helper::redondeado($dataOrden[0]->sanitarios,3),1,'C',1);
        $pdf::SetXY(168,205);
        $pdf::MultiCell(30,7,Helper::redondeado($dataOrden[0]->Total,3),1,'C',1);

        $this->deshechos_detail_month($id, $year, $month);

        $pdf::Output();
        exit;
    }

    public function infoCompany($x){

      $report = new ReportConfig();
      $data = $report->find(1);

      $y = 6;

      $pdf = $this->newSheet();


      $pdf::SetFont('Arial','B',12);
      $pdf::SetXY(70,15);
      $pdf::Cell(80,10,"Guadalajara, Jalisco ".Helper::mostrar_fecha_completa(date('Y-m-d')));


      $pdf::SetXY($x,25);
      $pdf::SetFont('Arial','B',11);
      $pdf::Cell(50,10,"A quien corresponda:",0);
      $pdf::SetXY($x,33);
      $pdf::SetFont('Arial','',11);
      $pdf::Cell(50,10,"Presente",0);
      $pdf::SetXY($x,41);
      $pdf::MultiCell(150,5,utf8_decode("Por medio de la presente, envío la información solicitada, de la recolección y transporte de residuos de manejo especial no peligrosos, como: alimento, jardinería, sanitarios y otros inorgánicos, en su separación primaria, residuos orgánicos, inorgánicos y sanitarios; según la norma ambiental NAE-SEMADES-007/2008 , que realizamos en sus instalaciones."));


      $pdf::SetXY($x,65);
      $pdf::SetFont('Arial','B',11);
      $pdf::Cell(50,10,"Datos Generales de la Empresa Recolectora:",0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::SetFont('Arial','',11);
      $pdf::Cell(50,10,(utf8_decode($data->nombre)),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(90,10,(utf8_decode($data->direccion.", Col.".$data->colonia)),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(90,10,(utf8_decode("C.P.".$data->cp.", ".$data->ciudad.", ".$data->estado)),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(90,10,strtoupper(utf8_decode("RFC.".$data->rfc)),0);

      $pdf::SetXY($x,94);
      $pdf::SetFont('Arial','B',11);
      $pdf::Cell(120,10,"Registro ante SEMADET:",0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::SetFont('Arial','',11);
      $pdf::Cell(120,10,strtoupper("OFICIO SEMADET: ".utf8_decode("/DGIR/1994/DRT/2017 | DGPGA/DGIR/00649/RSD/1574/2016  DR 554/16")),0);
      // $pdf::Cell(50,10,strtoupper("DR 554/16"),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(50,10,(utf8_decode("Expedido: 04 Diciembre 2017")),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(50,10,(utf8_decode("Vencimiento: 03 Diciembre 2027")),0);

      $pdf::SetXY($x,118);
      $pdf::SetFont('Arial','B',11);
      $pdf::Cell(120,10,utf8_decode("Ubicación del Relleno Sanitario autorizado:"),0);
      //$pdf::Cell(50,10,strtoupper(utf8_decode("Autorizacion Vigente:")),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::SetFont('Arial','',11);
      $pdf::Cell(120,10,(utf8_decode($data->vertedero)),0);
      //$pdf::Cell(50,10,strtoupper(utf8_decode($data->codigo)),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      //$pdf::Cell(50,10,(utf8_decode($data->direccion1)),0);
      $pdf::Cell(50,10,(utf8_decode('Av. San Francisco (carretera a el salto ) # 1019 col. Los Laureles Tonalá , Jalisco.')),0);
      //$pdf::SetXY($x,$pdf::GetY()+$y);
      //$pdf::Cell(50,10,(utf8_decode($data->direccion1_1)),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(120,10,"GESTION INTEGRAL Y ACOPIO. S.A. DE C.V.",0);
      //$pdf::Cell(50,10,strtoupper(utf8_decode($data->codigo)),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      //$pdf::Cell(50,10,(utf8_decode($data->direccion1)),0);
      $pdf::Cell(50,10,(utf8_decode('Av. Vallarta no.641 Int 6 Col. San Juan de Ocotan, Zapopan, Jalisco CP 45519')),0);

      $pdf::SetXY($x,148);

      $pdf::SetFont('Arial','B',11);
      $pdf::Cell(120,10,utf8_decode("Autorizacion Vigente:"),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      // $pdf::Cell(50,10,(utf8_decode("Permiso:".$data->codigo)),0);
      $pdf::Cell(50,10,(utf8_decode("Permiso: SEMADET/DGPGA/DGIR/2204/RSD/2018/2027")),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(50,10,(utf8_decode("Permiso: SEMADET/DGPGA/DGIR/00649/RSD/1574/2016")),0);
      // $pdf::Cell(50,10,(utf8_decode("Vigencia: ")),0);

      // New values added
      $pdf::SetFont('Arial','',11);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(50,10,(utf8_decode("GRUPO ENERWASTE SA DE CV")),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(50,10,(utf8_decode("La Estancia, KM 9+300 del camino Acueducto Calderon San Gaspar, en Zapotlanejo, Jalisco.")),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::SetFont('Arial','B',11);
      $pdf::Cell(50,10,(utf8_decode("Autorización: DREMI 1412400121 DF/16")),0);

      $pdf::SetFont('Arial','B',10);
      $pdf::SetTextColor(0,0,0,1);
      $pdf::SetDrawColor(0,0,0);
      $pdf::SetXY(192,253);
      $pdf::Cell(15,5,'Hoja: '.$pdf::PageNo(),0);

      return $pdf;
    }

    public function deshechos_detail_month($id, $year, $month){


      $ordenes = new Ordenes();
      $orden = $ordenes->total_month($id,$month,$year);
      if($orden->getData()->status){

        $x = 18;
      
        $pdf = $this->newSheet();
        $data = $orden->getData()->data;
        $pdf::SetXY($x,20);
        $pdf::SetFont('Arial','B',12);
        $pdf::SetTextColor(0,0,0);
        $pdf::Cell(120,7,utf8_decode("Cliente: ".(ucwords(strtolower($data[0]->cliente_n)))),0);
        $pdf::SetXY($x,27);
        $pdf::Cell(120,7,utf8_decode("Sucursal: ".(ucwords(strtolower($data[0]->cliente)))),0);
        $pdf::SetXY($x,34);
        $pdf::Cell(120,7,(ucwords(strtolower(utf8_decode("Domicilio: ".$data[0]->direccion." Col. ".$data[0]->colonia)))),0);

        $pdf::SetFont('Arial','B',9);
        $pdf::SetTextColor(255,255,255,1);
        $pdf::SetDrawColor(255,255,255,1);
        $pdf::SetFillColor(94,156,211);
        $pdf::SetXY($x,45);
        $pdf::Cell(23,10,(utf8_decode("NO. ORDEN")),1,0,'C',1);
        $pdf::Cell(23,10,(utf8_decode("FECHA")),1,0,'C',1);
        $pdf::Cell(18,10,(utf8_decode("UNIDAD")),1,0,'C',1);
        $pdf::Cell(18,10,(utf8_decode("CANTIDAD")),1,0,'C',1);
        $pdf::SetXY(100,45);
        $pdf::MultiCell(25,5,(utf8_decode("TONELADAS INORGANICO")),1,'C',1);
        $pdf::SetXY(125,45);
        $pdf::MultiCell(25,5,(utf8_decode("TONELADAS ORGANICO")),1,'C',1);
        $pdf::SetXY(150,45);
        $pdf::MultiCell(25,5,(utf8_decode("TONELADAS SANITARIO")),1,'C',1);
        $pdf::SetXY(175,45);
        $pdf::MultiCell(23,5,(utf8_decode("TOTAL TONELADAS")),1,'C',1);
        $y = 55;
        $inorganicos = 0;
        $organicos = 0;
        $sanitarios = 0;
        $cantidad = 0;

        foreach($data as $key => $value){
          if($pdf::GetY() >= 200){
              $pdf = $this->newSheet();
              $x=18;$y=20;
          }
          $pdf::SetXY($x,$y);
          $pdf::SetFont('Arial','',10);
          $pdf::SetTextColor(0,0,0);
          $pdf::SetFillColor(221,235,246);
          $pdf::Cell(23,5,$value->orden_no,1,0,'C',1);
          $pdf::Cell(23,5,$value->fecha,1,0,'C',1);
          $pdf::Cell(18,5,$value->unidad,1,0,'C',1);
          $pdf::Cell(18,5,Helper::redondeado($value->cantidad,2),1,0,'C',1);
          $pdf::SetXY(100,$y);
          $pdf::MultiCell(25,5,Helper::redondeado($value->inorganicos,3),1,'C',1);
          $pdf::SetXY(125,$y);
          $pdf::MultiCell(25,5,Helper::redondeado($value->organicos,3),1,'C',1);
          $pdf::SetXY(150,$y);
          $pdf::MultiCell(25,5,Helper::redondeado($value->sanitarios,3),1,'C',1);
          $pdf::SetXY(175,$y);
          $pdf::MultiCell(23,5,Helper::redondeado($value->total,3),1,'C',1);
          $y += 5;

          $inorganicos += $value->inorganicos;
          $organicos += $value->organicos;
          $sanitarios += $value->sanitarios;
          $cantidad += $value->cantidad;
          

        }
        $y = $pdf::GetY();
        $pdf::SetXY($x,$y);
        $pdf::SetFont('Arial','B',11);
        $pdf::SetTextColor(255,255,255,1);
        $pdf::SetFillColor(94,156,211);
        $pdf::Cell(64,7,"Total General",1,0,'C',1);
        $pdf::MultiCell(18,7,Helper::redondeado($cantidad,2),1,'C',1);
        $pdf::SetXY(100,$y);
        $pdf::MultiCell(25,7,Helper::redondeado($inorganicos,3),1,'C',1);
        $pdf::SetXY(125,$y);
        $pdf::MultiCell(25,7,Helper::redondeado($organicos,3),1,'C',1);
        $pdf::SetXY(150,$y);
        $pdf::MultiCell(25,7,Helper::redondeado($sanitarios,3),1,'C',1);
        $pdf::SetXY(175,$y);
        $pdf::MultiCell(23,7,Helper::redondeado($inorganicos+$organicos+$sanitarios, 3),1,'C',1);


        if($pdf::GetY() >= 230){
            $pdf = $this->newSheet();
            $x=18;$y=20;
        }else{
            $pdf::SetTextColor(0,0,0);
            $this->signature($pdf);
        }

        $pdf::SetFont('Arial','B',10);
        $pdf::SetTextColor(0,0,0,1);
        $pdf::SetDrawColor(0,0,0);
        $pdf::SetXY(190,230);
        $pdf::Cell(15,5,'Hoja: '.$pdf::PageNo(),0);

      }
      $this->anualReport($id, $year, $month);
      //$this->category_report($id,$month,$year);

    }

    public function ReportReciclable($id,$year,$month){

      $ordenes = new Ordenes();

      $orden = $ordenes->ordenReciclable($id,$year,$month);

      if(!$orden){
        return "No hay Información para este reporte";
      }

      $x = 18;
      $pdf = $this->infoCompany($x);

      $pdf::SetXY(60,$pdf::GetY()+15);
      $pdf::SetFont('Arial','B',11);
      $pdf::Cell(50,10,"Cliente: ".strtoupper(utf8_decode($orden[0]->cliente)),0);

      //tabla
      $x = 28;
      $y = 180;
      $total_kg = 0;
      $total_tn = 0;
      $pdf::SetFont('Arial','B',9);
      $pdf::SetTextColor(255,255,255,1);
      $pdf::SetDrawColor(255,255,255,1);
      $pdf::SetFillColor(94,156,211);
      $pdf::SetXY($x,$y);
      $pdf::Cell(32,10,(utf8_decode("NO. ORDEN")),1,0,'C',1);
      $pdf::Cell(32,10,(utf8_decode("FECHA")),1,0,'C',1);
      $pdf::Cell(32,10,(utf8_decode("MATERIAL")),1,0,'C',1);
      $pdf::Cell(32,10,(utf8_decode("RECOLECCION KG")),1,0,'C',1);
      $pdf::Cell(32,10,(utf8_decode("RECOLECCION TN")),1,0,'C',1);

      foreach($orden as $key => $value){
        if($pdf::GetY() >= 200){
            $pdf = $this->newSheet();
            $x=28;$y=20;
        }
        $pdf::SetXY($x,$y+10);
        $pdf::SetFont('Arial','',10);
        $pdf::SetTextColor(0,0,0);
        $pdf::SetFillColor(221,235,246);
        $pdf::Cell(32,5,$value->orden_no,1,0,'C',1);
        $pdf::Cell(32,5,$value->fecha,1,0,'C',1);
        $pdf::Cell(32,5,$value->reciclable,1,0,'C',1);
        $pdf::Cell(32,5,number_format($value->peso_kg,2),1,0,'C',1);
        $pdf::Cell(32,5,number_format($value->peso_tn,2),1,0,'C',1);
        $y += 5;

        $total_kg += $value->peso_kg;
        $total_tn += $value->peso_tn;

      }

      $y = $pdf::GetY();
      $pdf::SetXY($x,$y);
      $pdf::SetFont('Arial','B',11);
      $pdf::SetTextColor(255,255,255,1);
      $pdf::SetFillColor(94,156,211);
      $pdf::Cell(32,7,"Total:",1,0,'C',1);
      $pdf::Cell(32,7,"",1,0,'C',1);
      $pdf::Cell(32,7,"",1,0,'C',1);
      $pdf::Cell(32,7,number_format($total_kg,2),1,0,'C',1);
      $pdf::Cell(32,7,number_format($total_tn,2),1,0,'C',1);

      if($pdf::GetY() >= 230){
          $pdf = $this->newSheet();
          $x=18;$y=20;
      }else{
          $pdf::SetTextColor(0,0,0);
          $this->signature($pdf);
      }

      $pdf::SetFont('Arial','B',10);
      $pdf::SetTextColor(0,0,0,1);
      $pdf::SetDrawColor(0,0,0);
      $pdf::SetXY(190,230);
      $pdf::Cell(15,5,'Hoja: '.$pdf::PageNo(),0);


      $pdf::Output();
      exit;
    }

    public function ReportReciclable2($id,$year,$month){

      $report = new ReportConfig();
      $data = $report->find(1);

      $ordenes = new Ordenes();

      $orden = $ordenes->ordenReciclable($id,$year,$month);

      if(!$orden){
        return "No hay Información para este reporte";
      }

      $x = 18;
      $y = 6;

      $pdf = $this->newSheet();


      $pdf::SetFont('Arial','B',12);
      $pdf::SetXY(70,15);
      $pdf::Cell(80,10,"Guadalajara, Jalisco ".Helper::mostrar_fecha_completa(date('Y-m-d')));


      $pdf::SetXY($x,45);
      $pdf::SetFont('Arial','B',11);
      $pdf::Cell(50,10, utf8_decode($orden[0]->cliente),0);
      $pdf::SetXY($x,53);
      $pdf::SetFont('Arial','',11);
      //$pdf::Cell(50,10,"Presente",0);
      $pdf::SetXY($x,61);
      $pdf::MultiCell(150,5,utf8_decode("Por medio de la presente, envío la información solicitada, de la recolección y transporte de residuos de manejo especial no peligrosos,como: papel, carton, aluminio, chatarra, vidrio y plastico, en su separación primaria, residuos orgánicos, inorgánicos y sanitarios; según la norma ambiental NAE-SEMADES-007/2008 , que realizamos en sus instalaciones."));


      $pdf::SetXY($x,88);
      $pdf::SetFont('Arial','B',11);
      $pdf::Cell(50,10,"Datos Generales de la Empresa:",0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::SetFont('Arial','',11);
      $pdf::Cell(50,10,(utf8_decode($data->nombre)),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(90,10,(utf8_decode($data->direccion.", Col.".$data->colonia)),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(90,10,(utf8_decode("C.P.".$data->cp.", ".$data->ciudad.", ".$data->estado)),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(90,10,strtoupper(utf8_decode("RFC.".$data->rfc)),0);

      $pdf::SetXY($x,120);
      $pdf::SetFont('Arial','B',11);
      $pdf::Cell(50,10,"Registro ante SEMADET:",0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::SetFont('Arial','',12);
      $pdf::Cell(50,10,strtoupper('Oficio de SEMADET: '.utf8_decode($data->semades). " | DGPGA/DGIR/00649/RSD/1574/2016"),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(50,10,strtoupper(utf8_decode($data->semades2)),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(50,10,(utf8_decode("Expedido: 04 Diciembre 2017")),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(50,10,(utf8_decode("Vencimiento: 03 Diciembre 2027")),0);

      $pdf::SetXY($x,155);
      $pdf::SetFont('Arial','B',11);
      $pdf::Cell(120,10,utf8_decode("Ubicación del centro de acopio autorizado:"),0);
      //$pdf::Cell(50,10,strtoupper(utf8_decode("Autorizacion Vigente:")),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::SetFont('Arial','',11);
      $pdf::Cell(120,10,strtoupper(utf8_decode($data->vertedero3)." | GESTION INTEGRAL Y ACOPIO. S.A. DE C.V."),0);
      //$pdf::Cell(50,10,strtoupper(utf8_decode($data->codigo3)),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(50,10,(utf8_decode("AV. 8 de Julio # 3029 CP 44960 Col Echeverria")),0);
      // $pdf::Cell(50,10,(utf8_decode('Av. San Francisco (Carretera el Salto) #1019 Col. Los Laureles, Tonala, Jalisco.')),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      //$pdf::Cell(50,10,strtoupper(utf8_decode($data->codigo3)),0);
      $pdf::Cell(50,10,(utf8_decode($data->direccion3_3)),0);
      
      // New info added
      $pdf::SetXY($x,170);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(50,10,(utf8_decode("Bio pappel sab de C.V.")),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(50,10,(utf8_decode("Oficio semandet/DGPA/DGIR/1314/DREMI/2685/2015")),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(50,10,(utf8_decode("Permiso: DREMI/1403900441/CA20")),0);

      $pdf::SetXY($x,$pdf::GetY()+$y+2);
      $pdf::Cell(50,10,(utf8_decode("Desperdicios y reciclados gallo sa de C.V.")),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(50,10,(utf8_decode("Permiso semadet: 1409800583/CA 18")),0);

      $pdf::SetXY($x,$pdf::GetY()+$y+2);
      $pdf::Cell(50,10,(utf8_decode("Zitlali Esperanza Delgadillo Salcedo")),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(50,10,(utf8_decode("Permiso: DREMI14101005561/RE")),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(50,10,(utf8_decode("Oficio semadet: DGIR/1994/DRT/2017/DGPGA/DGIR/00649/1574/2016.")),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(50,10,(utf8_decode("DR55/16")),0);

      

      $pdf = $this->newSheet();

      $x = 28;
      $pdf::SetFont('Arial','B',11);      
      $pdf::SetXY($x,20);
      $pdf::Cell(120,7,utf8_decode("Cliente: ".(ucwords(strtolower($orden[0]->cliente)))),0);
      $pdf::SetXY($x,27);
      $pdf::Cell(120,7,utf8_decode("Sucursal: ".(ucwords(strtolower($orden[0]->nombre_comercial)))),0);
      $pdf::SetXY($x,34);
      $pdf::Cell(120,7,(ucwords(strtolower(utf8_decode("Domicilio: ".$orden[0]->direccion.", Col.: ".$orden[0]->colonia)))),0);

      //tabla
      $y = 45;
      $total_kg = 0;
      $total_tn = 0;
      $pdf::SetFont('Arial','B',9);
      $pdf::SetTextColor(255,255,255,1);
      $pdf::SetDrawColor(255,255,255,1);
      $pdf::SetFillColor(94,156,211);
      $pdf::SetXY($x,$y);
      $pdf::Cell(32,10,(utf8_decode("NO. ORDEN")),1,0,'C',1);
      $pdf::Cell(32,10,(utf8_decode("FECHA")),1,0,'C',1);
      $pdf::Cell(32,10,(utf8_decode("MATERIAL")),1,0,'C',1);
      $pdf::Cell(32,10,(utf8_decode("RECOLECCION KG")),1,0,'C',1);
      $pdf::Cell(32,10,(utf8_decode("RECOLECCION TN")),1,0,'C',1);

      foreach($orden as $key => $value){
        if($pdf::GetY() >= 200){
            $pdf = $this->newSheet();
            $x=28;$y=20;
        }
        $pdf::SetXY($x,$y+10);
        $pdf::SetFont('Arial','',10);
        $pdf::SetTextColor(0,0,0);
        $pdf::SetFillColor(221,235,246);
        $pdf::Cell(32,5,$value->orden_no,1,0,'C',1);
        $pdf::Cell(32,5,$value->fecha,1,0,'C',1);
        $pdf::Cell(32,5,utf8_decode($value->reciclable),1,0,'C',1);
        $pdf::Cell(32,5,number_format($value->peso_kg,2),1,0,'R',1);
        $pdf::Cell(32,5,number_format($value->peso_tn,3),1,0,'R',1);
        $y += 5;

        $total_kg += $value->peso_kg;
        $total_tn += $value->peso_tn;

      }

      $y = $pdf::GetY()+5;
      $pdf::SetXY($x,$y);
      $pdf::SetFont('Arial','B',11);
      $pdf::SetTextColor(255,255,255,1);
      $pdf::SetFillColor(94,156,211);
      $pdf::Cell(32,7,"Total:",1,0,'C',1);
      $pdf::Cell(32,7,"",1,0,'C',1);
      $pdf::Cell(32,7,"",1,0,'C',1);
      $pdf::Cell(32,7,number_format($total_kg,2),1,0,'R',1);
      $pdf::Cell(32,7,number_format($total_tn,3),1,0,'R',1);

      if($pdf::GetY() >= 200){
          $pdf = $this->newSheet();
          $x=18;$y=20;
          $pdf::SetTextColor(0,0,0);
          $this->signature($pdf);
      }else{
          $pdf::SetTextColor(0,0,0);
          $this->signature($pdf);
      }

      $pdf::SetFont('Arial','B',10);
      $pdf::SetTextColor(0,0,0,1);
      $pdf::SetDrawColor(0,0,0);
      $pdf::SetXY(190,230);
      $pdf::Cell(15,5,'Hoja: '.$pdf::PageNo(),0);

      $pdf = $this->anualReportReciclable($id, $year, $month);

      $pdf::Output();
      exit;
    }

    public function ReportReciclableCosto($id,$year,$month){

      $report = new ReportConfig();
      $data = $report->find(1);

      $ordenes = new Ordenes();

      $orden = $ordenes->ordenReciclable($id,$year,$month);

      if(!$orden){
        return "No hay Información para este reporte";
      }

      $x = 18;
      $y = 6;

      $pdf = $this->newSheet();


      $pdf::SetFont('Arial','B',12);
      $pdf::SetXY(70,30);
      $pdf::Cell(80,10,"Guadalajara, Jalisco ".Helper::mostrar_fecha_completa(date('Y-m-d')));


      $pdf::SetXY($x,45);
      $pdf::SetFont('Arial','B',11);
      $pdf::Cell(50,10,"ATN: ".$orden[0]->cliente,0);
      $pdf::SetXY($x,53);
      $pdf::SetFont('Arial','',11);
      //$pdf::Cell(50,10,"Presente",0);
      $pdf::SetXY($x,61);
      $pdf::MultiCell(150,5,utf8_decode("Por medio de la presente reciba nuestros saludos cordiales; y le anexo detalle el pago que se realizo por concepto de compra de reciclables."));

      /*
      $pdf::SetXY($x,83);
      $pdf::SetFont('Arial','B',11);
      $pdf::Cell(50,10,"Datos Generales de la Empresa:",0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::SetFont('Arial','',11);
      $pdf::Cell(50,10,(utf8_decode($data->nombre)),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(90,10,(utf8_decode($data->direccion.", COL.".$data->colonia)),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(90,10,(utf8_decode("C.P.".$data->cp.", ".$data->ciudad.", ".$data->estado)),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(90,10,strtoupper(utf8_decode("RFC.".$data->rfc)),0);

      $pdf::SetXY($x,115);
      $pdf::SetFont('Arial','B',11);
      $pdf::Cell(50,10,"Registro ante SEMADET:",0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::SetFont('Arial','',12);
      $pdf::Cell(50,10,strtoupper('Oficio de SEMADET: '.utf8_decode($data->semades)),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(50,10,strtoupper(utf8_decode($data->semades2)),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(50,10,(utf8_decode("Expedido: 04 Diciembre 2017")),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(50,10,(utf8_decode("Vencimiento: 03 Diciembre 2027")),0);

      $pdf::SetXY($x,148);
      $pdf::SetFont('Arial','B',11);
      $pdf::Cell(120,10,utf8_decode("Ubicación del vertedero autorizado:"),0);
      //$pdf::Cell(50,10,strtoupper(utf8_decode("Autorizacion Vigente:")),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::SetFont('Arial','',11);
      $pdf::Cell(120,10,strtoupper(utf8_decode($data->vertedero3)),0);
      //$pdf::Cell(50,10,strtoupper(utf8_decode($data->codigo3)),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(50,10,(utf8_decode($data->direccion3)),0);
      $pdf::SetXY($x,$pdf::GetY()+$y);
      $pdf::Cell(50,10,strtoupper(utf8_decode($data->codigo3)),0);
      //$pdf::Cell(50,10,(utf8_decode($data->direccion3_3)),0);
      $pdf = $this->newSheet();
      

      $x = 20;
      $pdf::SetFont('Arial','B',11);      
      $pdf::SetXY($x,20);
      $pdf::Cell(120,7,utf8_decode("Cliente: ".(ucwords(strtolower($orden[0]->cliente)))),0);
      $pdf::SetXY($x,27);
      $pdf::Cell(120,7,utf8_decode("Sucursal: ".(ucwords(strtolower($orden[0]->nombre_comercial)))),0);
      $pdf::SetXY($x,34);
      $pdf::Cell(120,7,(ucwords(strtolower(utf8_decode("Domicilio: ".$orden[0]->direccion.", Col.: ".$orden[0]->colonia)))),0);
      */

      //tabla
      $y = 75;
      $total_kg = 0;
      $total_tn = 0;
      $costo = 0;
      $pdf::SetFont('Arial','B',9);
      $pdf::SetTextColor(255,255,255,1);
      $pdf::SetDrawColor(255,255,255,1);
      $pdf::SetFillColor(94,156,211);
      $pdf::SetXY($x,$y);
      $pdf::Cell(28,10,(utf8_decode("NO. ORDEN")),1,0,'C',1);
      $pdf::Cell(28,10,(utf8_decode("FECHA")),1,0,'C',1);
      $pdf::Cell(28,10,(utf8_decode("MATERIAL")),1,0,'C',1);
      $pdf::Cell(32,10,(utf8_decode("RECOLECCION KG")),1,0,'C',1);
      $pdf::Cell(32,10,(utf8_decode("PRECIO")),1,0,'C',1);
      $pdf::Cell(28,10,(utf8_decode("TOTAL CLIENTE")),1,0,'C',1);

      foreach($orden as $key => $value){
        if($pdf::GetY() >= 200){
            $pdf = $this->newSheet();
            $x=28;$y=20;
        }
        $pdf::SetXY($x,$y+10);
        $pdf::SetFont('Arial','',10);
        $pdf::SetTextColor(0,0,0);
        $pdf::SetFillColor(221,235,246);
        $pdf::Cell(28,5,$value->orden_no,1,0,'C',1);
        $pdf::Cell(28,5,$value->fecha,1,0,'C',1);
        $pdf::Cell(28,5,utf8_decode($value->reciclable),1,0,'C',1);
        $pdf::Cell(32,5,number_format($value->peso_kg,2),1,0,'R',1);
        $pdf::Cell(32,5,"$".number_format($value->costo_cliente,2),1,0,'R',1);
        $pdf::Cell(28,5,"$".number_format($value->peso_kg * $value->costo_cliente,2),1,0,'R',1);
        $y += 5;

        $total_kg += $value->peso_kg;
        $total_tn += $value->costo_cliente;
        $costo += ($value->peso_kg * $value->costo_cliente);

      }

      $y = $pdf::GetY()+5;
      $pdf::SetXY($x,$y);
      $pdf::SetFont('Arial','B',11);
      $pdf::SetTextColor(255,255,255,1);
      $pdf::SetFillColor(94,156,211);
      $pdf::Cell(28,7,"Total:",1,0,'C',1);
      $pdf::Cell(28,7,"",1,0,'C',1);
      $pdf::Cell(28,7,"",1,0,'C',1);
      $pdf::Cell(32,7,number_format($total_kg,2),1,0,'R',1);
      $pdf::Cell(32,7,"$".number_format($total_tn,2),1,0,'R',1);
      $pdf::Cell(28,7,"$".number_format($costo,2),1,0,'R',1);

      if($pdf::GetY() >= 200){
          $pdf = $this->newSheet();
          $x=18;$y=20;
          $pdf::SetTextColor(0,0,0);
          $this->signature($pdf);
      }else{
          $pdf::SetTextColor(0,0,0);
          $this->signature($pdf);
      }

      $pdf::SetFont('Arial','B',10);
      $pdf::SetTextColor(0,0,0,1);
      $pdf::SetDrawColor(0,0,0);
      $pdf::SetXY(190,230);
      $pdf::Cell(15,5,'Hoja: '.$pdf::PageNo(),0);

      //$pdf = $this->anualReportReciclable($id, $year, $month);

      $pdf::Output();
      exit;
    }

    public function signature($pdf){
        $report = new ReportConfig();
        $data = $report->find(1);
        $pdf::SetXY(80,210);
        $pdf::SetFont('Arial','',11);
        $pdf::image(__DIR__.'/../../../public/img/reporte/firma.png',90,215,40,'png');
        $pdf::Cell(60,10,strtoupper("Sin mas por el momento quedo a sus ordenes."),0,0,'C');
        $pdf::SetXY(80,230);
        $pdf::Cell(60,10,strtoupper("__________________________"),0,0,'C');
        $pdf::SetXY(80,236);
        $pdf::Cell(60,10,strtoupper($data->nombre),0,0,'C');

        return $pdf;
    }

    public function anualReport($id, $year, $month){

      $ordenes = new Ordenes();
      $orden = $ordenes->tota_orden($id, $year, $month,1);
      $dataOrden = $orden->getData()->data;

      if($dataOrden == ""){
         return "No hay Ordenes Registradas";
      }

      $pdf = $this->newSheet();

      $pdf::SetXY(15,35);
      $pdf::SetFont('Arial','',12);
      $pdf::Cell(50,10,utf8_decode("Cliente: ".(ucwords(strtolower($dataOrden[0]->cliente2)))),0);
      $pdf::SetXY(15,42);
      $pdf::Cell(50,10,utf8_decode("Sucursal: ".(ucwords(strtolower($dataOrden[0]->cliente)))),0);
      $pdf::SetXY(15,49);
      $pdf::Cell(50,10,utf8_decode("Domicilio: ".(ucwords(strtolower($dataOrden[0]->direccion." Col. ".$dataOrden[0]->colonia)))),0);

      $pdf::SetFillColor(208,208,208);
      $pdf::Rect(10,65,35,27,'DF');
      $pdf::SetXY(12,80);
      $pdf::MultiCell(30,5,"Residuo Recolectado",0,'C');
      $pdf::SetXY(45,65);
      $pdf::Cell(132,9,"Cantidades en Tn.",1,1,'C',1);

      $pdf::SetXY(45,74);
      $pdf::SetFont('Arial','',9);
      $pdf::Cell(132,9,utf8_decode("Año - ".$year),1,1,'C',0);

      $mes =["Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic"];
      $x = 45; $y = 83;
      foreach ($mes as $key => $value) {
        $pdf::SetXY($x,$y);
        $pdf::Cell(11,9,utf8_decode($value),1,1,'C',0);
        $x += 11;
      }

      /*$pdf::Rect(177,65,30,27,'DF');
      $pdf::SetXY(182,74);
      $pdf::MultiCell(20,5,"Total (Tn)",0,'C');*/

      $pdf::SetFont('Arial','',9);

      $_x = 10; $_y = 92;
      $tipo = ['inorganicos'=>'Inorganico','organicos'=>'Organico','sanitarios'=>'Sanitario'];
      $total_tn = 0;
      foreach ($tipo as $key => $tip) {
        $pdf::SetXY($_x,$_y);
        $pdf::Cell(35,9,strtoupper(utf8_decode($tip)),1,1,'C',0);

        $array =["120","30.5","50.5","60","0","0","0","0","0","0","0","0"];
        $x = 45; $total = 0; $months = 1;
        for($i=1; $i<=12; $i++) {
          $pdf::SetXY($x,$_y);

          if(isset($dataOrden[$months-1]->NoMes) and $dataOrden[$months-1]->NoMes == $i){
            //echo "no.Mes".$dataOrden[$months-1]->NoMes ."==". ($dataOrden[$months-1]->organicos)."i =".($i - 1)." <br>";
            $pdf::Cell(11,9,number_format($dataOrden[$months-1]->$key,2),1,1,'C',0);
            $total += $dataOrden[$months-1]->$key;
            $months++;
          }else{
            //echo "mon".$months ."== 0 i".($i - 1) ." <br>";
            $pdf::Cell(11,9,round(0,2),1,1,'C',0);
          }
          $x += 11;

        }
        $pdf::SetXY(177,$_y);
        $pdf::Cell(30,9,number_format($total,2),1,1,'R',0);
        $total_tn += $total;
        $_y += 9;
      }

      $pdf::Rect(177,65,30,27,'DF');
      $pdf::SetFont('Arial','',12);
      $pdf::SetXY(182,74);
      $pdf::MultiCell(20,5,"Total (Tn): ".number_format($total_tn,2),0,'C');

      $pdf::SetXY(10,119);
      $pdf::SetFont('Arial','',9);
      $pdf::Cell(35,9,"Total por Mes",1,1,'C',1);
      $x = 45; $_y = 119; $total_m = 0;
      
      $j = 0;
        for($i=0; $i<=11; $i++) {
          $pdf::SetXY($x,$_y);
          //echo ($i+1)." => i ";
          //echo $j." => j ";
          if(isset($dataOrden[$j]->NoMes) && $dataOrden[$j]->NoMes == $i+1){
            //echo $dataOrden[$j]->NoMes;
            $pdf::Cell(11,9,number_format($dataOrden[$j]->Total,2),1,1,'C',0);
            $total_m += $dataOrden[$j]->Total;
            $j++;
          }else{
            //echo 0;
            $pdf::Cell(11,9,0,1,1,'C',0);
            if(isset($dataOrden[$j]->NoMes) && $dataOrden[$j]->NoMes < $i+1){
              $j++;
            }
          }
          $x += 11;

        }
      
      $pdf::SetXY(177,119);
      $pdf::SetFont('Arial','',9);
      $pdf::Cell(30,9,number_format($total_m,2),1,0,'R');
      //$pdf::SetTextColor(189,0,0,1);
      //$pdf::Cell(162,9,"Caabsa Eagle Guadalajara SA de CV",1,1,'C',1);

      $pdf::SetXY(10,128);
      $pdf::SetTextColor(0,0,0,1);
      $pdf::Cell(35,9,ucwords(strtolower(utf8_decode("Registro")))." SEMADET",1,1,'C',1);
      $pdf::SetXY(45,128);
      $pdf::SetFont('Arial','',11);
      $pdf::SetTextColor(189,0,0,1);
      $pdf::Cell(162,9,ucwords(strtolower(utf8_decode("Permiso: 140100083 Vigencia: 25-08-17"))),1,1,'C',1);

      $pdf::SetFont('Arial','B',10);
      $pdf::SetTextColor(0,0,0,1);
      $pdf::SetDrawColor(0,0,0);
      $pdf::SetXY(190,230);
      $pdf::Cell(15,5,'Hoja: '.$pdf::PageNo(),0);

      $this->signature($pdf);

      return $pdf;

    }

    public function anualReportReciclable($id, $year, $month){

      $ordenes = new Ordenes();
      $orden = $ordenes->ordenReciclableAnual($id, $year, $month);

      if(!$orden){
         return "No hay Ordenes Registradas";
      }

      $pdf = $this->newSheet();

      $pdf::SetXY(15,35);
      $pdf::SetFont('Arial','',13);
      $pdf::Cell(50,10,utf8_decode("Cliente: ".(ucwords(strtolower($orden[0]->cliente)))),0);
      $pdf::SetXY(15,42);
      $pdf::Cell(50,10,utf8_decode("Sucursal: ".(ucwords(strtolower($orden[0]->nombre_comercial)))),0);
      $pdf::SetXY(15,49);
      $pdf::Cell(50,10,utf8_decode("Domicilio: ".(ucwords(strtolower($orden[0]->direccion." Col. ".$orden[0]->colonia)))),0);

      $pdf::SetFillColor(208,208,208);
      $pdf::Rect(10,65,35,27,'DF');
      $pdf::SetXY(12,80);
      $pdf::MultiCell(30,5,"Residuo Recolectado",0,'C');
      $pdf::SetXY(45,65);
      $pdf::Cell(132,9,"Cantidades en Kg.",1,1,'C',1);

      $pdf::SetXY(45,74);
      $pdf::SetFont('Arial','',9);
      $pdf::Cell(132,9,utf8_decode("Año - ".$year),1,1,'C',0);

      $mes =["Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic"];
      $x = 45; $y = 83;
      foreach ($mes as $key => $value) {
        $pdf::SetXY($x,$y);
        $pdf::Cell(11,9,utf8_decode($value),1,1,'C',0);
        $x += 11;
      }

      $pdf::Rect(177,65,30,27,'DF');
      $pdf::SetXY(182,74);
      $pdf::SetFont('Arial','',13);
      $pdf::MultiCell(20,5,"Total (Tn)",0,'C');
      $pdf::SetFont('Arial','',9);

      $_x = 10; $_y = 92;

      $tipo = [];
      $i= 0;
      foreach ($orden as $key => $value) {
        if($value->peso_tn != 0){
          $reciclable = ($value->reciclable);
          if(!in_array($reciclable, $tipo)){
            array_push($tipo,$reciclable);
            $i++;
          }
        }
      }

      $_x = 10; $_y = 92;
      foreach ($tipo as $key => $tip) {
        $pdf::SetXY($_x,$_y);
        $pdf::Cell(35,9,(ucwords(strtolower((utf8_decode($tip))))),1,1,'C',0);
        $_y += 9;
      }
      $pdf::SetFont('Arial','B',7);
      $pdf::Cell(35,9,strtoupper(utf8_decode("Total General Kg")),1,1,'C',0);

      $_x = 45;$_y = 92;
      for($i=1; $i<=12; $i++) {
         $total = 0;
         $pdf::SetFont('Arial','',7);
           foreach ($tipo as $key => $tip) {
             $pdf::SetXY($_x,$_y);
             if($i <= $month){
               $orden = $ordenes->ordenReciclableAnual($id, $year, $i, $tip);
               if(!$orden){
                 $pdf::Cell(11,9,round(0,2),1,1,'C',0);
                 $_y += 9;
               }else{
                 $pdf::Cell(11,9,number_format($orden[0]->peso_tn,2),1,1,'C',0);
                 $total += $orden[0]->peso_tn;
                 $_y += 9;
               }
             }else{
               $pdf::Cell(11,9,round(0,2),1,1,'C',0);
               $_y += 9;
             }
           }
         $pdf::SetFont('Arial','B',7);
         $pdf::SetXY($_x,$_y);
         $pdf::Cell(11,9,number_format(($total),2),1,1,'C',0);
         $_x += 11;
         $_y = 92;
      }

      $_x = 177;
      $_y = 92;
      $total_tn = 0;
      $pdf::SetFont('Arial','',9);
      $total = $ordenes->totalReciclable($id,$year,$month);
      foreach ($total as $key => $value) {
        $total_tn += $value->peso_tn;
        $pdf::SetXY($_x,$_y);
        $pdf::Cell(30,9,number_format($value->peso_tn,2),1,1,'R',0);
        $_y += 9;
      }
      $_x = 177;
      $pdf::SetXY($_x,$pdf::getY());
      $pdf::SetFont('Arial','B',9);
      $pdf::Cell(30,9,number_format($total_tn,2),1,1,'R',0);

      $y = $pdf::GetY();
      $pdf::SetXY(10,$y);
      $pdf::SetFont('Arial','',9);
      $pdf::Cell(35,9,"Centro de Acopio",1,1,'C',1);
      $pdf::SetXY(45,$y);
      $pdf::SetTextColor(189,0,0,1);
      $pdf::Cell(162,9,"Javier Torres Rodriguez Av. 8 de Julio #3029 C.P. 44960 Col. Echeverria",1,1,'C',1);
      $y = $y +9;
      $pdf::SetXY(10,$y);
      $pdf::SetTextColor(0,0,0,1);
      $pdf::SetFont('Arial','',9);
      $pdf::Cell(35,9,ucwords(strtolower(utf8_decode("Registro")))." SEMADET",1,1,'C',1);
      $pdf::SetXY(45,$y);
      $pdf::SetFont('Arial','',11);
      $pdf::SetTextColor(189,0,0,1);
      $pdf::Cell(162,9,ucwords(strtolower(utf8_decode("Permiso:")))." DEMI 14033900139",1,1,'C',1);


      if($pdf::GetY() >= 210){
          $pdf = $this->newSheet();
          $x=18;$y=20;
          $pdf::SetTextColor(0,0,0);
          $this->signature($pdf);
      }else{
          $pdf::SetTextColor(0,0,0);
          $this->signature($pdf);
      }

      $pdf::SetFont('Arial','B',10);
      $pdf::SetTextColor(0,0,0,1);
      $pdf::SetDrawColor(0,0,0);
      $pdf::SetXY(190,230);
      $pdf::Cell(15,5,'Hoja: '.$pdf::PageNo(),0);

      return $pdf;

    }

}