<?php

namespace App\Terms;

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

class RelatorioEstatisticoCadastroTutor
{

    public function getRelatorioEstatisticoCadastroTutorPdf($dados)
    {
        $html = '';
        $html .= '<html>';
        $html .= '<head>';
        $html .= '	<title></title>';
        $html .= '	<style>
	                    h3 {
	                        margin: 40px 0px;
	                    }
	                    .info{
	                        margin: 40px 0px;
	                    }
	                    .rodape{
	                        margin-top: 350px;
	                        text-align: center;
	                    }
	
	
                    </style>';
        $html .= '</head>';
        $html .= '<body>';
        $html .= '<h3>';
        $html .= " <div style='text-align: center;'>";
        $html .= " RELATÓRIO ESTATÍSTICO - CADASTRO DE NOVOS TUTORES <br/>";
        $html .= " </h3>";
        $html .= "";

        $html .= '<table style="font-size: 13px" border="0" width="100%">
                 <tr>
                    <td style="text-align: center"><strong>Id Tutor</strong></td>
                    <td style="text-align: center"><strong>Nome</strong></td>
                    <td style="text-align: center"><strong>Cpf</strong></td>
                    <td style="text-align: center"><strong>Telefone</strong></td>
                    <td style="text-align: center"><strong>Cep</strong></td>
                    <td style="text-align: center"><strong>Cidade</strong></td>
                    <td style="text-align: center"><strong>Bairro</strong></td>
                    <td style="text-align: center"><strong>Logradouro</strong></td>
                    <td style="text-align: center"><strong>Numero</strong></td>
                    <td style="text-align: center"><strong>Cadastro</strong></td>
                </tr>';

        $html .= '
            <tr>
                <td colspan="12"><hr></td>
            </tr>
        ';

        // FOREACH PETS
        foreach ( $dados as $key => $value ) {
            $html .= '
                <tr>
                    <td style="text-align: center;">' . $value["id_tutor"] . ' </td>
                    <td style="text-align: center;">' . $value["nome"] . ' </td>
                    <td style="text-align: center;">' . $value["cpf"] . ' </td>
                    <td style="text-align: center;">' . $value["telefone"] . ' </td>
                    <td style="text-align: center;">' . $value["cep"] . ' </td>
                    <td style="text-align: center;">' . $value["cidade"] . ' </td>
                    <td style="text-align: center;">' . $value["bairro"] . ' </td>
                    <td style="text-align: center;">' . $value["logradouro"] . ' </td>
                    <td style="text-align: center;">' . $value["numero"] . ' </td>
                    <td style="text-align: center;">' . date( "d/m/Y", strtotime( $value["data_execucao"] ) ) . ' </td>
                </tr>
            ';
        }
        $html .= '</table>';


        $html .= "</body>";
        $html .= "</html>";

        return $html;
    }



    public function getRelatorioEstatisticoCadastroTutorExcel($dados) {
        header( 'Content-Type: application/vnd.ms-excel' );
        header( 'Content-Disposition: attachment;filename="relatorio-tutor-unidade.xlsx"' );
        $spreadsheet = new Spreadsheet();

        $sheet = $spreadsheet->getActiveSheet();
        $cols = [
            "Id Tutor",
            "Nome",
            "Cpf",
            "Telefone",
            "Cep",
            "Cidade",
            "Bairro",
            "Logradouro",
            "Numero",
            "Cadastro"
        ];

        $sheet->fromArray( $cols, null, 'A1' );
        $row_start = 2;

        foreach ( $dados as $value ) {
            $array_row [] = $value["id_tutor"];
            $array_row [] = $value["nome"];
            $array_row [] = $value["cpf"];
            $array_row [] = $value["telefone"];
            $array_row [] = $value["cep"];
            $array_row [] = $value["cidade"];
            $array_row [] = $value["bairro"];
            $array_row [] = $value["logradouro"];
            $array_row [] = $value["numero"];
            $array_row [] = date( "d/m/Y", strtotime( $value["data_execucao"] ) );

            $sheet->fromArray( $array_row, null, 'A' . $row_start );
            unset( $array_row );
            $row_start++;
        }

        $writer = new Xlsx( $spreadsheet );
        return $writer;
    }
}