<?php

namespace App\Terms;

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

class RelatorioEstatisticoPrimeiraConsulta
{

    public function getRelatorioEstatisticoPrimeiraConsultaPdf($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 DE PRIMEIRAS CONSULTAS <br/>";
        $html .= " </h3>";
        $html .= "";

        $html .= '<table style="font-size: 13px" border="0" width="100%">
                 <tr>
                    <td style="text-align: center"><strong>Id Pet</strong></td>
                    <td style="text-align: center"><strong>Nome do Pet</strong></td>
                    <td style="text-align: center"><strong>Procedimento</strong></td>
                    <td style="text-align: center"><strong>Data Execução</strong></td>
                    <td style="text-align: center"><strong>Hora Execução</strong></td>
                    <td style="text-align: center"><strong>Unidade</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_pet"] . ' </td>
                    <td style="text-align: center;">' . $value["nome"] . ' </td>
                    <td style="text-align: center;">' . $value["descricao_procedimento"] . ' </td>
                    <td style="text-align: center;">' . date( "d/m/Y", strtotime( $value["data_execucao"] ) ) . ' </td>
                    <td style="text-align: center;">' . $value["hora_execucao"] . ' </td>
                    <td style="text-align: center;">' . $value["descricao_unidade"] . ' </td>
                </tr>
            ';
        }
        $html .= '</table>';


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

        return $html;
    }



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

        $sheet = $spreadsheet->getActiveSheet();
        $cols = [
            "Id Pet",
            "Nome do Pet",
            "Procedimento",
            "Data de Execução",
            "Hora de Execução",
            "Unidade"
        ];

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

        foreach ( $dados as $value ) {
            $array_row [] = $value["id_pet"];
            $array_row [] = $value["nome"];
            $array_row [] = $value["descricao_procedimento"];
            $array_row [] = date( "d/m/Y", strtotime( $value["data_execucao"] ) );
            $array_row [] = $value["hora_execucao"];
            $array_row [] = $value["descricao_unidade"];

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

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