<?php
namespace src\controllers;

use \src\Config;
use \core\Controller;
use \src\controllers\UtilsController;
use \src\handlers\CityHandler;
use \src\handlers\LoginHandler;
use \src\handlers\PermissionHandler;
use \src\handlers\ReportsHandler;
use \src\handlers\FiltersHandler;
use \src\models\Bills_to_pay;
use \src\models\Bills_to_receive;
use \src\models\City;
use \src\models\Client;
use \src\models\Deliverie;
use \src\models\Farm;
use \src\models\User;
use \src\models\Product;
use \src\models\Provider;
use \src\models\Purchase;
use \src\models\Request;
use \src\models\Salesman;
use \src\models\Shipping_company;

class ReportsController extends Controller
{
    private $loggedUser;
    private $pageActive;
    private $paramsName;
    private $arrayInfo;

    public function __construct()
    {
        date_default_timezone_set('America/Sao_Paulo');
        $this->loggedUser = LoginHandler::checkLogin();

        if ($this->loggedUser == false) {
            $this->redirect('/login');
        }

        $this->pageActive = 'reports';
        $this->paramsName = PermissionHandler::getPermissions($this->loggedUser->group);

        if (!in_array('reports_view', $this->paramsName)) {
            $this->redirect('/');
        }
    }

    public function index() {

        $this->render('reports', [
            'loggedUser' => $this->loggedUser,
            'pageActive' => $this->pageActive,
            'permissions' => $this->paramsName,
            'titlePage' => 'Relatórios - Supporte Agronegócios'
        ]);
    }

    // Relatório de clientes
    public function clients() {
        $emptyFilter = [
            'searchType' => '',
            'classification' => '',
            'state' => '',
            'print' => '',
            'type' => '',
            'limit' => 50
        ];

        if(isset($_POST['filter']) && !empty($_POST['filter'])) {
            $_SESSION['filter_report_clients'] = $_POST['filter'];
            if($_SESSION['filter_report_clients']['clear'] == 'clear') {
                $_SESSION['filter_report_clients'] = $emptyFilter;
                $this->redirect('/reportclients');
            }
        }

        if(!isset($_SESSION['filter_report_clients'])) {
            $_SESSION['filter_report_clients'] = $emptyFilter;
        }

        $offset = 0;
        $limit = $_SESSION['filter_report_clients']['limit'];

        $filter = FiltersHandler::filterCLients($_SESSION['filter_report_clients']);

        $this->arrayInfo['clientsInfo'] = Client::getClients($offset, $limit, $filter);
        $this->arrayInfo['stateList'] = CityHandler::getStates();
        $this->arrayInfo['filter'] = $_SESSION['filter_report_clients'];

        foreach ($this->arrayInfo['clientsInfo'] as $key => $client) {
            $this->arrayInfo['clientsInfo'][$key]['city_name'] = City::getName($client['city']);
        }        

        $this->render('clients_reports', [
            'loggedUser' => $this->loggedUser,
            'pageActive' => $this->pageActive,
            'permissions' => $this->paramsName,
            'arrayInfo' => $this->arrayInfo,
            'titlePage' => 'Relatório de Clientes - Supporte Agronegócios'
        ]);
    }

    public function clientsToPdf() {
        $format = 'P';

        if(!empty($_SESSION['filter_report_clients']['print'])) {
            $format = $_SESSION['filter_report_clients']['print'];
        }

        $filter = FiltersHandler::filterCLients($_SESSION['filter_report_clients']);
        $clientsList = Client::getClients(0, $_SESSION['filter_report_clients']['limit'], $filter);
        $headerInfo = self::getHeaderInfo();

        $reportsHandler = new ReportsHandler();
        $clientContent = $reportsHandler->prepareClientPdf($clientsList, $headerInfo);

        self::generatePdf($clientContent, 'Relatório de Clientes', $format);
    }

    public function clientsToCsv() {
        $filter = FiltersHandler::filterCLients($_SESSION['filter_report_clients']);
        $clientsList = Client::getClients(0, $_SESSION['filter_report_clients']['limit'], $filter);

        $reportsHandler = new ReportsHandler();
        $clientsReady = $reportsHandler->prepareClientCsv($clientsList);
        $archiveName = 'Relatorio_de_Cliente(s)_'.date('d/m/Y');

        $header = ['Item', 'Status', 'Classe', 'Tipo', 'Nome do Cliente', mb_convert_encoding('Nome do Responsável', 'ISO-8859-1', 'UTF-8'), 'Fone Contato', 'Cidade-UF'];

        self::generateCsv($archiveName, $header, $clientsReady);
    }
    // Fim Relatório de clientes

    // Relatório de Fazendas

    public function farms() {
        $emptyFilter = [
            'searchType' => 1,
            'state' => '',
            'client' => '',
            'client_name' => '',
            'print' => '',
            'limit' => 50
        ];

        if(isset($_POST['filter']) && !empty($_POST['filter'])) {
            $_SESSION['reports_farms'] = $_POST['filter'];
            if($_SESSION['reports_farms']['clear'] == 'clear') {
                $_SESSION['reports_farms'] = $emptyFilter;
                $this->redirect('/reportfarms');
            }
        }

        if(!isset($_SESSION['reports_farms'])) {
            $_SESSION['reports_farms'] = $emptyFilter;
        }

        $offset = 0;
        $limit = $_SESSION['reports_farms']['limit'];
        
        $filter = FiltersHandler::filterFarms($_SESSION['reports_farms']);
        $this->arrayInfo['farmsInfo'] = Farm::getFilterFarms($offset, $limit, $filter);
        $this->arrayInfo['stateList'] = CityHandler::getStates();

        foreach ($this->arrayInfo['farmsInfo'] as $key => $farm) {
            $this->arrayInfo['farmsInfo'][$key]['client_name'] = Client::getName($farm['id_client']);
            $this->arrayInfo['farmsInfo'][$key]['city_name'] = City::getName($farm['city']);
        }

        $this->arrayInfo['filter'] = $_SESSION['reports_farms'];

        $this->render('farms_reports', [
            'loggedUser' => $this->loggedUser,
            'pageActive' => $this->pageActive,
            'permissions' => $this->paramsName,
            'arrayInfo' => $this->arrayInfo,
            'titlePage' => 'Relatório de Fazendas - Supporte Agronegócios'
        ]);
    }

    public function farmsToPdf() {
        $format = 'P';

        if(!empty($_SESSION['reports_farms']['print'])) {
            $format = $_SESSION['reports_farms']['print'];
        }

        $filter = FiltersHandler::filterFarms($_SESSION['reports_farms']);
        $farmsList = Farm::getFilterFarms(0, $_SESSION['reports_farms']['limit'], $filter);
        $headerInfo = self::getHeaderInfo();

        $reportsHandler = new ReportsHandler();
        $farmContent = $reportsHandler->prepareFarmPdf($farmsList, $headerInfo);

        self::generatePdf($farmContent, 'Relatório de Fazendas', $format);
    }

    public function farmsToCsv() {
        $filter = FiltersHandler::filterFarms($_SESSION['reports_farms']);
        $farmsList = Farm::getFilterFarms(0, $_SESSION['reports_farms']['limit'], $filter);

        $reportsHandler = new ReportsHandler();
        $farmsReady = $reportsHandler->prepareFarmsCsv($farmsList);
        $archiveName = 'Relatorio_de_Fazenda(s)_'.date('d/m/Y');

        $header = [
            'Item', 
            'Status', 
            'Cliente', 
            'Fazenda', 
            mb_convert_encoding('Inscrição Estadual', 'ISO-8859-1', 'UTF-8'), 
            mb_convert_encoding('Responsável na Fazenda', 'ISO-8859-1', 'UTF-8'), 
            'Fone resp na Fazenda', 
            'Cidade-UF'
        ];

        self::generateCsv($archiveName, $header, $farmsReady);
    }
    // Fim Relatório de Fazendas

    // Relatório de Produtos por Fornecedor
    public function providersAndProducts() {
        $emptyFilter = array(
            'onlystock' => 'on',
            'searchType' => 1,
            'state' => '',
            'p_group' => '',
            'provider' => '',
            'provider_name' => '',
            'print' => '',
            'clear' => '',
            'limit' => 50
        );
        
        if(isset($_POST['filter']) && !empty($_POST['filter'])) {
            $_SESSION['reports_providers'] = $_POST['filter'];
            if($_SESSION['reports_providers']['clear'] == 'clear') {
                $_SESSION['reports_providers'] = $emptyFilter;
                $this->redirect('/reportprovidersproducts');
            }
        }

        if(!isset($_SESSION['reports_providers'])) {
            $_SESSION['reports_providers'] = $emptyFilter;
        }        

        $offset = 0;
        $limit = '';

        $filter = FiltersHandler::filterProviders($_SESSION['reports_providers']);
        $providersList = Provider::getProviders($offset, $limit, $filter, 'providers');
        $unicList = array();

        if($providersList) {

            $unicList = self::getResultProductsFromProvider($providersList, $filter);
        }

        $this->arrayInfo['stateList'] = CityHandler::getStates();
        $this->arrayInfo['filter'] = $_SESSION['reports_providers'];

        $this->render('providers_reports', [
            'loggedUser' => $this->loggedUser,
            'pageActive' => $this->pageActive,
            'permissions' => $this->paramsName,
            'arrayInfo' => $this->arrayInfo,
            'newItems' => $unicList,
            'titlePage' => 'Relatório de Produtos por Fornecedor(es) - Supporte Agronegócios'
        ]);
    }

    public function productsForProviderPdf() {
        $format = 'P';

        if(!empty($_SESSION['reports_providers']['print'])) {
            $format = $_SESSION['reports_providers']['print'];
        }

        $filter = FiltersHandler::filterProviders($_SESSION['reports_providers']);
        $providersList = Provider::getProviders(0, '', $filter, 'providers');
        $productsList = array();

        if($providersList) {
            $productsList = self::getResultProductsFromProvider($providersList, $filter);
        }

        $headerInfo = self::getHeaderInfo();
        $reportsHandler = new ReportsHandler();
        $productsContent = $reportsHandler->prepareProductsPdf($productsList, $headerInfo);

        self::generatePdf($productsContent, 'Relatório de Produtos por Fornecedor', $format);
    }

    public function productsToCsv() {
        $filter = FiltersHandler::filterProviders($_SESSION['reports_providers']);
        $providersList = Provider::getProviders(0, '', $filter, 'providers');
        $productsList = array();

        if($providersList) {
            $productsList = self::getResultProductsFromProvider($providersList, $filter);
        }

        $reportsHandler = new ReportsHandler();
        $productsReady = $reportsHandler->prepareProductsCsv($productsList);
        $archiveName = 'Relatorio_de_produtos_por_Fornecedor_'.date('d/m/Y');

        $header = [
            'Item', 
            'Status do Fornecedor', 
            'Fornecedor', 
            'Cidade-UF', 
            'Grupo de Produto', 
            'Status do Produto', 
            'Produto', 
            'Estoque',
            'Custo R$'
        ];

        self::generateCsv($archiveName, $header, $productsReady);
    }

    // Buscar resultado para relatório de Produtos por fornecedor
    public static function getResultProductsFromProvider($providersList, $filter) {
        $unicList = array();

        foreach ($providersList as $key => $provider) {                
            $productsList[] = Product::getListReports($filter, $provider['id']);
        }            

        $productsList = array_values(array_filter($productsList));

        foreach ($productsList as $key => $productsProvider) {
            foreach ($productsProvider as $keyProduct => $product) {
                $providerInfo = Provider::getProvider($product['id_provider'], 'providers');

                $product['provider_status'] = ($providerInfo['status'] == 1)?'Ativo':'Inativo';
                $product['provider_name'] = $providerInfo['company_name'];
                $product['group_product'] = Product::getProductGroup($product['id_group']);
                $cityName = City::getName($providerInfo['city']);
                $product['provider_location'] = $cityName.'-'.$providerInfo['state'];
                $unicList[] = $product;
            }
        }

        if($unicList) {
           foreach ($unicList as $newKey => $newProduct) {
                $unicList[$newKey]['cost_price'] = UtilsController::convertToRealBr($newProduct['cost_price']);
                $provider_name[$newKey] = $newProduct['provider_name'];
                $product_name[$newKey] = $newProduct['name'];
            }

            array_multisort($provider_name, SORT_ASC, $product_name, SORT_ASC, $unicList); 
        }        

        return $unicList;
    }
    // Fim Relatório de Produtos por Fornecedor

    // Relatório de Compras
    public function purchases() {
        $emptyFilter = array(
            'by' => 'provider',
            'by_selected' => '',
            'text' => '',
            'p_group' => '',
            'd_init' => '',
            'd_end' => '',
            'payment_form' => array(),
            'print' => '',
            'clear' => '',
            'limit' => 50            
        );

        if(isset($_POST['filter']) && !empty($_POST['filter'])) {
            $_SESSION['reports_purchases'] = $_POST['filter'];
            if($_SESSION['reports_purchases']['clear'] == 'clear') {
                $_SESSION['reports_purchases'] = $emptyFilter;
                $this->redirect('/reportpurchases');
            }
        }

        if(!isset($_SESSION['reports_purchases'])) {
            $_SESSION['reports_purchases'] = $emptyFilter;
        }

        switch ($_SESSION['reports_purchases']['by']) {
            case 'provider':
                $title = 'Relatório de Compras por Fornecedor(es) - Supporte Agronegócios';
                break;

            case 'product':
                $title = 'Relatório de Compras por Produto(s) - Supporte Agronegócios';
                break;
            
            default:
                $title = 'Relatório de Compras - Supporte Agronegócios';
                break;
        }

        $offset = 0;
        $limit = $_SESSION['reports_purchases']['limit'];

        $filter = FiltersHandler::filterPurchasesReports($_SESSION['reports_purchases']);
        $purchaseReturns = Purchase::getPurchasesReports($offset, $limit, $filter);
        $resultToShow = self::prepareContentPurchaseReports($purchaseReturns, $_SESSION['reports_purchases']);
        $resultToShow['total'] = UtilsController::convertToRealBr($resultToShow['total']);

        $this->arrayInfo['paymentForm'] = Bills_to_pay::getAllPaymentForm();
        $this->arrayInfo['filter'] = $_SESSION['reports_purchases'];

        $this->render('purchases_reports', [
            'loggedUser' => $this->loggedUser,
            'pageActive' => $this->pageActive,
            'permissions' => $this->paramsName,
            'arrayInfo' => $this->arrayInfo,
            'data' => $resultToShow,
            'titlePage' => $title
        ]);
    }

    public function purchasesPdf() {
        $format = 'P';

        if(!empty($_SESSION['reports_purchases']['print'])) {
            $format = $_SESSION['reports_purchases']['print'];
        }

        switch ($_SESSION['reports_purchases']['by']) {
            case 'provider':
                $title = 'Relatório de Compras por Fornecedor(es)';
                break;

            case 'product':
                $title = 'Relatório de Compras por Produto(s)';
                break;
            
            default:
                $title = 'Relatório de Compras';
                break;
        }

        $offset = 0;
        $limit = $_SESSION['reports_purchases']['limit'];

        $filter = FiltersHandler::filterPurchasesReports($_SESSION['reports_purchases']);
        $purchaseReturns = Purchase::getPurchasesReports($offset, $limit, $filter);
        $resultToShow = self::prepareContentPurchaseReports($purchaseReturns, $_SESSION['reports_purchases']);
        $resultToShow['total'] = UtilsController::convertToRealBr($resultToShow['total']);

        $headerInfo = self::getHeaderInfo();
        $reportsHandler = new ReportsHandler();
        $purchasesContent = $reportsHandler->preparePurchasesPdf($resultToShow, $headerInfo, $title);

        self::generatePdf($purchasesContent, $title, $format);
    }

    public function purchasesCsv() {
        $offset = 0;
        $limit = $_SESSION['reports_purchases']['limit'];

        $filter = FiltersHandler::filterPurchasesReports($_SESSION['reports_purchases']);
        $purchaseReturns = Purchase::getPurchasesReports($offset, $limit, $filter);
        $resultToShow = self::prepareContentPurchaseReports($purchaseReturns, $_SESSION['reports_purchases']);

        // Ultima linha do arquivo caso precise de total
        $aditionalRow['total_title'] = $resultToShow['total_title'];
        $aditionalRow['total'] = UtilsController::convertToRealBr($resultToShow['total']);

        $reportsHandler = new ReportsHandler();
        $purchasesReady = $reportsHandler->preparePurchasesCsv($purchaseReturns, $_SESSION['reports_purchases']['by']);
        $header = ReportsHandler::getHeadReportPurchase($resultToShow['type']);
        $archiveName = 'Relatorio_de_compras_'.date('d/m/Y');

        self::generateCsv($archiveName, $header['csv'], $purchasesReady, $aditionalRow);
    }

    public static function prepareContentPurchaseReports($data, $filter) {
        $response = array();
        $provider_name = array();
        $date_note = array();
        $body = '';

        foreach ($data as $key => $purch_item) {
            $purch_item['provider_name'] = Provider::getProviderName($purch_item['id_provider']);

            $provider_name[$key] = $purch_item['provider_name'];
            $date_note[$key] = $purch_item['note_date'];
        }

        if($provider_name && $date_note) {
            array_multisort($provider_name, SORT_ASC, $date_note, SORT_DESC, $data);
        }

        $response['total'] = array_sum(array_column($data, 'total_amount'));

        if($filter['by'] == 'provider') {
            $response['type'] = 1;
            $response['colspan'] = 'colspan="7"';
            $response['total_title'] = 'Total em R$ de Compras por Fornecedor:';

            $response['head'] = '
                <tr>
                  <th scope="col">Item</th>
                  <th scope="col">Fornecedor</th>
                  <th scope="col">Origem Pagamento</th>
                  <th scope="col">grupo de produto</th>
                  <th scope="col">Data de compra</th>
                  <th scope="col">Nr Nota</th>
                  <th scope="col" style="width: 300px!important;">Valor Total da Compra-Nota R$</th>
                </tr>
            ';            

            foreach ($data as $key => $item) {
                $items = Purchase::getProductsPurchase($item['id']);
                $productGroup = Product::getProductGroup($items[0]['id_product_group']);

                $body .= '<tr>';
                $body .= '<td>'.($key + 1).'</td>';
                $body .= '<td>'.Provider::getProviderName($item['id_provider']).'</td>';
                $body .= '<td>'.Bills_to_pay::getPaymentForm($item['id_payment_form']).'</td>';
                $body .= '<td>'.$productGroup['name'].'</td>';
                $body .= '<td>'.UtilsController::convertDate($item['release_date']).'</td>';
                $body .= '<td>'.$item['note_number'].'</td>';
                $body .= '<td>'.UtilsController::convertToRealBr($item['total_amount']).'</td>';
                $body .= '</tr>';
            }

            $response['body'] = $body;

        } else if($filter['by'] == 'product') {
            $response['type'] = 2;
            $response['colspan'] = 'colspan="8"';
            $response['total_title'] = 'Total em R$ dos Itens de Compras:';

            $response['head'] = '
                <tr>
                    <th scope="col">Item</th>
                    <th scope="col">Grupo de Produto</th>
                    <th scope="col">Origem Pagamento</th>
                    <th scope="col">Produto</th>
                    <th scope="col">Fornecedor</th>
                    <th scope="col">Data da Compra</th>
                    <th scope="col">Nr Nota</th>
                    <th scope="col" style="width: 300px!important;">Valor do item da Compra R$</th>
                </tr>
            ';

            foreach ($data as $key => $item) {
                $items = Purchase::getProductsPurchase($item['id']);
                $productGroup = Product::getProductGroup($items[0]['id_product_group']);

                $body .= '<tr>';
                $body .= '<td>'.($key + 1).'</td>';
                $body .= '<td>'.$productGroup['name'].'</td>';
                $body .= '<td>'.Bills_to_pay::getPaymentForm($item['id_payment_form']).'</td>';
                $body .= '<td>'.Product::getName($items[0]['id_product']).'</td>';
                $body .= '<td>'.Provider::getProviderName($item['id_provider']).'</td>';                
                $body .= '<td>'.UtilsController::convertDate($item['release_date']).'</td>';
                $body .= '<td>'.$item['note_number'].'</td>';
                $body .= '<td>'.UtilsController::convertToRealBr($item['total_amount']).'</td>';
                $body .= '</tr>';
            }

            $response['body'] = $body;
        }

        return $response;
    }
    // Fim Relatório de Compras

    // Aniversariantes
    public function birthdays() {
        $dateNow = date('d-m-Y');

        $emptyFilter = [
            'by' => '',
            'd_init' => $dateNow,
            'd_end' => date('d-m-Y', strtotime('+ 30 days', strtotime($dateNow))),
            'print' => '',
            'limit' => 50
        ];

        if(isset($_POST['filter']) && !empty($_POST['filter'])) {
            $_SESSION['reports_birthdays'] = $_POST['filter'];
            if($_SESSION['reports_birthdays']['clear'] == 'clear') {
                $_SESSION['reports_birthdays'] = $emptyFilter;
                $this->redirect('/reportbirthdays');
            }
        }

        if(!isset($_SESSION['reports_birthdays'])) {
            $_SESSION['reports_birthdays'] = $emptyFilter;
        }

        $offset = 0;
        $limit = $_SESSION['reports_birthdays']['limit'];

        $this->arrayInfo['content'] = self::getBirthdaysList($_SESSION['reports_birthdays']);
        $this->arrayInfo['filter'] = $_SESSION['reports_birthdays'];

        $this->render('birthdays_reports', [
            'loggedUser' => $this->loggedUser,
            'pageActive' => $this->pageActive,
            'permissions' => $this->paramsName,
            'arrayInfo' => $this->arrayInfo,
            'titlePage' => 'Relatório de Aniversariantes - Supporte Agronegócios'
        ]);
    }

    public function birthdaysPdf() {
        $format = 'P';

        if(!empty($_SESSION['reports_birthdays']['print'])) {
            $format = $_SESSION['reports_birthdays']['print'];
        }
        
        $birthdaysList = self::getBirthdaysList($_SESSION['reports_birthdays']);

        $headerInfo = self::getHeaderInfo();
        $reportsHandler = new ReportsHandler();
        $birthdaysContent = $reportsHandler->prepareBirthdaysPdf($birthdaysList, $headerInfo);

        self::generatePdf($birthdaysContent, 'Relatório de Aniversariantes', $format);
    }

    public function birthdaysCsv() {
        $birthdaysList = self::getBirthdaysList($_SESSION['reports_birthdays']);

        $reportsHandler = new ReportsHandler();
        $birthdaysReady = $reportsHandler->prepareBirthdaysToCsv($birthdaysList);
        $archiveName = 'Relatorio_de_aniversariantes_'.date('d/m/Y');

        $header = [
            'Item', 
            mb_convert_encoding('Data do aniversário', 'ISO-8859-1'),
            'Nome', 
            mb_convert_encoding('Módulo', 'ISO-8859-1'), 
            'Status', 
            'Fone de contato', 
            'E-mail', 
            'Cidade-UF'
        ];

        self::generateCsv($archiveName, $header, $birthdaysReady);
    }

    private static function getBirthdaysList($filter) {
        $dateIni = false;
        $dateEnd = false;

        if(UtilsController::isDate($filter['d_init'])) {
            $dateIni = UtilsController::convertDate($filter['d_init']);
        }

        if(UtilsController::isDate($filter['d_end'])) {
            $dateEnd = UtilsController::convertDate($filter['d_end']);
        }

        if(!$dateIni) {
            $dateIni = date('Y-m-d');
            $_SESSION['reports_birthdays']['d_init'] = UtilsController::convertDate($dateIni);
        }

        if(!$dateEnd) {
            $dateEnd = date('Y-m-d', strtotime('+ 30 days', strtotime($dateIni)));
            $_SESSION['reports_birthdays']['d_end'] = UtilsController::convertDate($dateEnd);
        }

        switch($filter['by']) {
            case 'clients':
                $birthdatesInfo['model'] = 'Clientes';
                $birthdatesInfo['result'] = Client::getBirthdays($dateIni, $dateEnd);
                break;
            case 'providers':
                $birthdatesInfo['model'] = 'Fornecedores';
                $birthdatesInfo['result'] = Provider::getBirthdays($dateIni, $dateEnd);
                break;
            case 'salesman':
                $birthdatesInfo['model'] = 'Vendedores';
                $birthdatesInfo['result'] = Salesman::getBirthdays($dateIni, $dateEnd);
                break;
            case 'shippingconpany':
                $birthdatesInfo['model'] = 'Transportadoras';
                $birthdatesInfo['result'] = Shipping_company::getBirthdays($dateIni, $dateEnd);
                break;
            case 'users':
                $birthdatesInfo['model'] = 'Usuários';
                $birthdatesInfo['result'] = User::getBirthdays($dateIni, $dateEnd);
                break;
            
            default:
                $birthdatesInfo = [
                    0 => [
                        'model' => 'Clientes',
                        'result' => Client::getBirthdays($dateIni, $dateEnd)
                    ],
                    1 => [
                        'model' => 'Fornecedores',
                        'result' => Provider::getBirthdays($dateIni, $dateEnd)
                    ],
                    2 => [
                        'model' => 'Vendedores',
                        'result' => Salesman::getBirthdays($dateIni, $dateEnd)
                    ],
                    3 => [
                        'model' => 'Transportadoras',
                        'result' => Shipping_company::getBirthdays($dateIni, $dateEnd)
                    ],
                    4 => [
                        'model' => 'Usuários',
                        'result' => User::getBirthdays($dateIni, $dateEnd)
                    ]
                ];
                break;
        }

        if(count($birthdatesInfo) == 5) {
            $i = 0;
            foreach ($birthdatesInfo as $key => $models) {                
                
                foreach ($models['result'] as $keyModel => $item) {
                    $memory = 0;
                    if($i == 0){$i = $memory;}

                    $birthdays_data['result'][$i] = $item;
                    $birthdays_data['result'][$i]['model'] = $birthdatesInfo[$key]['model'];

                    $i++;
                    $memory = $i;
                }
            }

            foreach ($birthdays_data['result'] as $keyOrder => $value) {
                $birthdate[$keyOrder] = date('m-d', strtotime($value['birth_date']));

                $birthdays_data['result'][$keyOrder]['birth_date'] = UtilsController::convertDate($value['birth_date']);
            }

            array_multisort($birthdate, SORT_ASC, $birthdays_data['result']);

        } else {

            foreach ($birthdatesInfo['result'] as $key => $value) {
                $birthdatesInfo['result'][$key]['birth_date'] = UtilsController::convertDate($value['birth_date']);
            }

            $birthdays_data = $birthdatesInfo;    
        }

        return $birthdays_data;
    }
    // Fim Aniversariantes

    // Pedidos
    public function requests() {
        $dateNow = date('Y-m-d');

        $emptyFilter = [
            'status' => array(),
            'd_init' => date('d/m/Y', strtotime('- 30 days', strtotime($dateNow))),
            'd_end' => date('d/m/Y'),
            'client' => '',
            'client_name' => '',
            'provider' => '',
            'provider_name' => '',
            'products' => array(),
            'p_group' => '',
            'salesman' => '',
            'salesman_name' => '',
            'print' => '',
            'limit' => 50
        ];

        if(isset($_POST['filter']) && !empty($_POST['filter'])) {
            $_SESSION['reports_requests'] = $_POST['filter'];
            if($_SESSION['reports_requests']['clear'] == 'clear') {
                $_SESSION['reports_requests'] = $emptyFilter;
                $this->redirect('/reportrequests');
            }
        }

        if(!isset($_SESSION['reports_requests'])) {
            $_SESSION['reports_requests'] = $emptyFilter;
        }

        $offset = 0;
        $limit = $_SESSION['reports_requests']['limit'];

        $this->arrayInfo['content'] = self::getContentRequestReport();
        $this->arrayInfo['status_list'] = Request::getAllStatus();
        $this->arrayInfo['group_list'] = Product::allProductGroup();
        $this->arrayInfo['products_list'] = Product::getAll();
        $this->arrayInfo['filter'] = $_SESSION['reports_requests'];

        $this->arrayInfo['content']['total_requests'] = UtilsController::convertToRealBr($this->arrayInfo['content']['total_requests']);
        $this->arrayInfo['content']['total_estimative'] = UtilsController::convertToRealBr($this->arrayInfo['content']['total_estimative']);

        $this->render('requests_reports', [
            'loggedUser' => $this->loggedUser,
            'pageActive' => $this->pageActive,
            'permissions' => $this->paramsName,
            'arrayInfo' => $this->arrayInfo,
            'titlePage' => 'Relatório de Pedidos - Supporte Agronegócios'
        ]);
    }

    public function requestsPdf() {
        $format = 'P';

        if(!empty($_SESSION['reports_requests']['print'])) {
            $format = $_SESSION['reports_requests']['print'];
        }
        
        $requestsContent = self::getContentRequestReport();

        $headerInfo = self::getHeaderInfo();
        $reportsHandler = new ReportsHandler();
        $requestsReady = $reportsHandler->prepareRequestsPdf($requestsContent, $headerInfo);

        self::generatePdf($requestsReady, 'Relatório de Pedidos', $format);
    }

    public function requestsCsv() {
        $requestsContent = self::getContentRequestReport();

        $reportsHandler = new ReportsHandler();
        $requestsReady = $reportsHandler->prepareRequestsCsv($requestsContent);
        $archiveName = 'Relatorio_de_pedidos_'.date('d/m/Y');

        $header = [
            'Item',
            'Data',
            mb_convert_encoding('Nº', 'ISO-8859-1'),
            'Status do Pedido',
            'Cliente',
            'Fornecedor',
            'Produto de Item',
            mb_convert_encoding('Vendedor intermediário', 'ISO-8859-1'),
            'Peso',
            'Saldo',
            'Total do Pedido', 
            'Resultado Estimado'
        ];

        self::generateCsv($archiveName, $header, $requestsReady);
    }

    private static function getContentRequestReport() {
        $response = array();        
        $filter = FiltersHandler::getFilterReportsRequests($_SESSION['reports_requests']);

        $list = $filter['requestProduct'];
        unset($filter['requestProduct']);

        foreach ($list as $reqKey => $reqItem) {            
            $response[$reqKey] = Request::getRequestsReports($filter, $reqItem['id_request']);
            $response[$reqKey]['id_product'] = $reqItem['id_product'];
        }

        foreach ($response as $keyRemove => $valueRemove) {
            if(empty($valueRemove['id'])) {
                unset($response[$keyRemove]);
            }            
        }

        array_values($response);

        foreach ($response as $key => $item) {
            $date_request[$key] = date('Y-m-d', strtotime($item['date_created']));

            $response[$key]['client'] = Client::getName($item['id_client']);
            $response[$key]['provider_name'] = Provider::getProviderName($item['id_provider']);
            $response[$key]['salesman_name'] = Salesman::getSalesmanName($item['id_salesman']);

            $response[$key]['amount'] = Request::select()
                ->table('request_items')
                ->where('id_request', '=', $item['id'])
            ->sum('quantity');

            $response[$key]['balance'] = Deliverie::select()
                ->table('deliveries')
                ->where('id_request', '=', $item['id'])
            ->sum('balance');

            $result = Request::select('estimative_result')
                ->table('estimative_request')
                ->where('id_request', '=', $item['id'])
            ->one();

            $response[$key]['product'] = Product::getProduct($item['id_product']);
            $response[$key]['group_name'] = Product::getProductGroup($response[$key]['product']['id_group']);
            $response[$key]['status_name'] = Request::getNameStatus($item['status']);
            $response[$key]['estimative_result'] = $result['estimative_result'];
            $response[$key]['estimative_real'] = ($result['estimative_result'] * $item['total']) / 100;
        }

        $total_requests = array_sum(array_column($response, 'total'));
        $total_estimative = array_sum(array_column($response, 'estimative_real'));

        if($date_request && $response) {
            array_multisort($date_request, SORT_DESC, $response);
        }

        $data['data'] = $response;
        $data['total_requests'] = $total_requests;
        $data['total_estimative'] = $total_estimative;

        return $data;
    }
    // Fim Pedidos

    // Entregas
    public function deliveries() {
        $dateEnd = date('Y-m-d');

        $emptyFilter = [
            'status' => array(),
            'd_init' => date('d/m/Y', strtotime('- 10 days', strtotime($dateEnd))),
            'd_end' => date('d/m/Y', strtotime('+ 10 days', strtotime($dateEnd))),
            'client' => '',
            'client_name' => '',
            'provider' => '',
            'provider_name' => '',
            'product' => '',
            'p_group' => '',
            'request' => '',
            'doc_number' => '',
            'shipping_comp' => '',
            'print' => '',
            'limit' => 50
        ];

        if(isset($_POST['filter']) && !empty($_POST['filter'])) {
            $_SESSION['reports_deliveries'] = $_POST['filter'];
            if($_SESSION['reports_deliveries']['clear'] == 'clear') {
                $_SESSION['reports_deliveries'] = $emptyFilter;
                $this->redirect('/reportdeliveries');
            }
        }

        if(!isset($_SESSION['reports_deliveries'])) {
            $_SESSION['reports_deliveries'] = $emptyFilter;
        }

        $offset = 0;
        $limit = $_SESSION['reports_deliveries']['limit'];

        $this->arrayInfo['content'] = self::getContentDeliveries($offset, $limit);
        $this->arrayInfo['status_list'] = Deliverie::getAllSituation();
        $this->arrayInfo['group_list'] = Product::allProductGroup();
        $this->arrayInfo['products_list'] = Product::getAll();
        $this->arrayInfo['shipping_comp'] = Shipping_company::getAll();
        $this->arrayInfo['filter'] = $_SESSION['reports_deliveries'];

        $this->arrayInfo['content']['total_balance'] = UtilsController::convertToRealBr($this->arrayInfo['content']['total_balance']);
        $this->arrayInfo['content']['total_vdelivery'] = UtilsController::convertToRealBr($this->arrayInfo['content']['total_vdelivery']);

        $this->render('deliveries_reports', [
            'loggedUser' => $this->loggedUser,
            'pageActive' => $this->pageActive,
            'permissions' => $this->paramsName,
            'arrayInfo' => $this->arrayInfo,
            'titlePage' => 'Relatório de Entregas - Supporte Agronegócios'
        ]);
    }

    public function deliveriesPdf() {
        $format = 'P';

        if(!empty($_SESSION['reports_deliveries']['print'])) {
            $format = $_SESSION['reports_deliveries']['print'];
        }
        $offset = 0;
        $limit = $_SESSION['reports_deliveries']['limit'];
        
        $deliveriesContent = self::getContentDeliveries($offset, $limit);

        $headerInfo = self::getHeaderInfo();
        $reportsHandler = new ReportsHandler();
        $deliveriesReady = $reportsHandler->prepareDeliveiresPdf($deliveriesContent, $headerInfo);

        self::generatePdf($deliveriesReady, 'Relatório de Entregas', $format);
    }

    public function deliveriesCsv() {
        $offset = 0;
        $limit = $_SESSION['reports_deliveries']['limit'];
        
        $deliveriesContent = self::getContentDeliveries($offset, $limit);

        $reportsHandler = new ReportsHandler();
        $deliveriesReady = $reportsHandler->prepareDeliveriesCsv($deliveriesContent);
        $archiveName = 'Relatorio_de_entregas_'.date('d/m/Y');

        $header = [
            'Item',
            'Dt da Entrega',
            mb_convert_encoding('Situação da entrega', 'ISO-8859-1'),
            'Nr do pedido',
            'Nr da entrega',
            'Fornecedor',
            'Cliente',            
            'Produto',
            'Transportadora',
            'Qtde', 
            mb_convert_encoding('Nº Documento', 'ISO-8859-1'),
            mb_convert_encoding('Valor da entrega R$', 'ISO-8859-1'),
        ]; 

        self::generateCsv($archiveName, $header, $deliveriesReady);
    }

    // Conteúdo filtrado para relatórios de Entregas
    private static function getContentDeliveries($offset, $limit) {
        $response = array();
        $filter = FiltersHandler::getFilterReportsDeliveries($_SESSION['reports_deliveries']);

        $response['result'] = Deliverie::getResultReports($offset, $limit, $filter);
        $response['total_balance'] = array_sum(array_column($response['result'], 'amount'));
        $response['total_vdelivery'] = array_sum(array_column($response['result'], 'value_delivery'));

        foreach ($response['result'] as $key => $item) {                
            $response['result'][$key]['date_deliverie'] = UtilsController::convertDate($item['date_deliverie']);
            $response['result'][$key]['situation_name'] = Deliverie::getSituationName($item['status']);
            $response['result'][$key]['deliveryInfo'] = Deliverie::getDeliveryInfo($item['id_deliverie']);
            $response['result'][$key]['provider'] = Provider::getProviderName($item['id_provider']);
            $response['result'][$key]['client'] = Client::getName($item['id_client']);
            $response['result'][$key]['product'] = Product::getName($item['id_product']);


            if($item['amount_balance']) {
                $response['result'][$key]['amount_balance'] = number_format($item['amount_balance'], 2, ',', '.');                
            } else {
                $response['result'][$key]['amount'] = number_format($item['amount'], 2, ',', '.');    
            }

            if($item['value_delivery_balance']) {
                $response['result'][$key]['value_delivery_balance'] = number_format($item['value_delivery_balance'], 2, ',', '.');                
            } else {
                $response['result'][$key]['value_delivery'] = number_format($item['value_delivery'], 2, ',', '.');    
            }            

            if($item['id_shipping_company']) {
                $response['result'][$key]['shipping_company'] = Shipping_company::getName($item['id_shipping_company']);    
            } else {
               $response['result'][$key]['shipping_company'] = '';
            }
        }

        return $response;
    }
    // Fim Entregas

    // Contas a Pagar
    public function billsToPay() {
        $dateInit = date('Y-m-d');

        $emptyFilter = [
            'expirate_where' => 'expirate_date',
            'status' => '1',
            'd_init' => date('d/m/Y'),
            'd_end' => date('d/m/Y', strtotime('+ 30 days', strtotime($dateInit))),
            'document_number' => '',
            'bills_type' => array(),
            'provider' => '',
            'provider_name' => '',
            'payment_form' => array(),
            'situation_account' => array(),            
            'print' => '',
            'limit' => 50
        ];

        if(isset($_POST['filter']) && !empty($_POST['filter'])) {
            $_SESSION['reports_billstopay'] = $_POST['filter'];
            if($_SESSION['reports_billstopay']['clear'] == 'clear') {
                $_SESSION['reports_billstopay'] = $emptyFilter;
                $this->redirect('/reportbillstopay');
            }
        }

        if(!isset($_SESSION['reports_billstopay'])) {
            $_SESSION['reports_billstopay'] = $emptyFilter;
        }

        $offset = 0;
        $limit = $_SESSION['reports_billstopay']['limit'];

        $this->arrayInfo['content'] = self::getContentBillsToPay($offset, $limit);
        $this->arrayInfo['billstype_list'] = Bills_to_pay::getAllBillsToPaytype();        
        $this->arrayInfo['payment_form'] = Bills_to_pay::getAllPaymentForm();
        $this->arrayInfo['situations'] = Bills_to_pay::getAllBillsToPaySituation();
        $this->arrayInfo['filter'] = $_SESSION['reports_billstopay'];

        $this->arrayInfo['content']['total_pay'] = UtilsController::convertToRealBr($this->arrayInfo['content']['total_pay']);
        $this->arrayInfo['content']['total'] = UtilsController::convertToRealBr($this->arrayInfo['content']['total']);

        $this->render('billstopay_reports', [
            'loggedUser' => $this->loggedUser,
            'pageActive' => $this->pageActive,
            'permissions' => $this->paramsName,
            'arrayInfo' => $this->arrayInfo,
            'titlePage' => 'Relatório de Contas a Pagar - Supporte Agronegócios'
        ]);
    }

    public function billsToPayPdf() {
        $format = 'P';

        if(!empty($_SESSION['reports_billstopay']['print'])) {
            $format = $_SESSION['reports_billstopay']['print'];
        }
        $offset = 0;
        $limit = $_SESSION['reports_billstopay']['limit'];
        
        $billstopayContent = self::getContentBillsToPay($offset, $limit);

        $headerInfo = self::getHeaderInfo();
        $reportsHandler = new ReportsHandler();
        $billstopayReady = $reportsHandler->prepareBillsToPayPdf($billstopayContent, $headerInfo);

        self::generatePdf($billstopayReady, 'Relatório de Contas a Pagar', $format);
    }

    public function billsToPayCsv() {
        $offset = 0;
        $limit = $_SESSION['reports_billstopay']['limit'];
        
        $billstopayContent = self::getContentBillsToPay($offset, $limit);

        $reportsHandler = new ReportsHandler();
        $billstopayReady = $reportsHandler->prepareBillstopayCsv($billstopayContent);
        $archiveName = 'Relatorio_de_contas_a_pagar_'.date('d/m/Y');

        $header = [
            'Item',
            'Dt de vencimento',
            'Status',
            'Nr Documento',
            'Nr Pedido',
            mb_convert_encoding('Descrição do Recebedor', 'ISO-8859-1'),
            'Tipo de conta',
            'Origem do Pgto',
            mb_convert_encoding('Situação da Conta', 'ISO-8859-1'),
            'Data do Pgto',
            'Valor a pagar',            
            mb_convert_encoding('Valor pago R$', 'ISO-8859-1')
        ]; 

        self::generateCsv($archiveName, $header, $billstopayReady);
    }

    public static function getContentBillsToPay($offset, $limit) {
        $response = array();
        $filter = FiltersHandler::filterReportsBillsToPay($_SESSION['reports_billstopay']);

        $response['result'] = Bills_to_pay::getContentReports($offset, $limit, $filter);
        $response['total_pay'] = array_sum(array_column($response['result'], 'value_to_pay'));
        $response['total'] = array_sum(array_column($response['result'], 'paid_out_value'));

        foreach ($response['result'] as $key => $item) {            
            $response['result'][$key]['expirate_date'] = UtilsController::convertDate($item['expirate_date']);
            $response['result'][$key]['type_name'] = Bills_to_pay::getBillsToPayType($item['billstopay_type']);
            $response['result'][$key]['formpay_name'] = Bills_to_pay::getPaymentForm($item['form_to_pay']);
            $response['result'][$key]['situation'] = Bills_to_pay::getBillsToPaySituation($item['id_situation']);
            $response['result'][$key]['value_to_pay'] = UtilsController::convertToRealBr($item['value_to_pay']);
            $response['result'][$key]['paid_out_value'] = UtilsController::convertToRealBr($item['paid_out_value']);


            if($item['payment_date']) {
                $response['result'][$key]['payment_date'] = UtilsController::convertDate($item['payment_date']);
            } else {
                $response['result'][$key]['payment_date'] = '';
            }
        }

        return $response;
    }
    // Fim Contas a Pagar


    // Contas a Receber
    public function billsToReceiver() {
        $dateInit = date('Y-m-d');

        $emptyFilter = [
            'expirate_where' => 'expirate_date',
            'status' => '1',
            'd_init' => date('d/m/Y'),
            'd_end' => date('d/m/Y', strtotime('+ 30 days', strtotime($dateInit))),
            'request_number' => '',
            'document_number' => '',
            'provider_name' => '',
            'origin_type' => '',
            'payment_form' => array(),
            'situation_account' => array(0 => 1, 1 => 2),                    
            'print' => '',
            'limit' => 50
        ];

        if(isset($_POST['filter']) && !empty($_POST['filter'])) {
            $_SESSION['reports_billstoreceiver'] = $_POST['filter'];
            if($_SESSION['reports_billstoreceiver']['clear'] == 'clear') {
                $_SESSION['reports_billstoreceiver'] = $emptyFilter;
                $this->redirect('/reportbillstoreceiver');
            }
        }

        if(!isset($_SESSION['reports_billstoreceiver'])) {
            $_SESSION['reports_billstoreceiver'] = $emptyFilter;
        }

        $offset = 0;
        $limit = $_SESSION['reports_billstoreceiver']['limit'];

        $this->arrayInfo['content'] = self::getContentBillsToReceiver($offset, $limit);
        $this->arrayInfo['receiver_origin'] = Bills_to_receive::getAllReceiverOrigin();
        $this->arrayInfo['payment_form'] = Bills_to_receive::getAllReceiverForm();        
        $this->arrayInfo['situations'] = Bills_to_pay::getAllBillsToPaySituation();
        $this->arrayInfo['filter'] = $_SESSION['reports_billstoreceiver'];

        $this->arrayInfo['content']['total_pay'] = UtilsController::convertToRealBr($this->arrayInfo['content']['total_pay']);
        $this->arrayInfo['content']['total'] = UtilsController::convertToRealBr($this->arrayInfo['content']['total']);

        $this->render('billstoreceiver_reports', [
            'loggedUser' => $this->loggedUser,
            'pageActive' => $this->pageActive,
            'permissions' => $this->paramsName,
            'arrayInfo' => $this->arrayInfo,
            'titlePage' => 'Relatório de Contas a Receber - Supporte Agronegócios'
        ]);
    }

    public function billsToReceiverPdf() {
        $format = 'P';

        if(!empty($_SESSION['reports_billstoreceiver']['print'])) {
            $format = $_SESSION['reports_billstoreceiver']['print'];
        }
        $offset = 0;
        $limit = $_SESSION['reports_billstoreceiver']['limit'];
        
        $billstoreceiverContent = self::getContentBillsToReceiver($offset, $limit);

        $headerInfo = self::getHeaderInfo();
        $reportsHandler = new ReportsHandler();
        $billstopayReady = $reportsHandler->prepareBillsToReceiverPdf($billstoreceiverContent, $headerInfo);

        self::generatePdf($billstopayReady, 'Relatório de Contas a Receber', $format);
    }

    public function billsToReceiverCsv() {
        $offset = 0;
        $limit = $_SESSION['reports_billstoreceiver']['limit'];
        
        $billstoreceiverContent = self::getContentBillsToReceiver($offset, $limit);

        $reportsHandler = new ReportsHandler();
        $billstopayReady = $reportsHandler->prepareBillstoreceiverCsv($billstoreceiverContent);
        $archiveName = 'Relatorio_de_contas_a_receber_'.date('d/m/Y');

        $header = [
            'Item',
            'Dt a receber',
            'Status',
            mb_convert_encoding('Descrição do Pagador', 'ISO-8859-1'),
            'Nr Documento',
            'Nr Pedido',
            'Origem do Recebimento',
            'Forma de recebimento',            
            mb_convert_encoding('Situação da Conta', 'ISO-8859-1'),            
            'Data do recebimento',
            mb_convert_encoding('Valor a receber R$', 'ISO-8859-1'),
            mb_convert_encoding('Valor recebido R$', 'ISO-8859-1')
        ]; 

        self::generateCsv($archiveName, $header, $billstopayReady);
    }

    public static function getContentBillsToReceiver($offset, $limit) {
        $response = array();
        $filter = FiltersHandler::filterReportsBillsToReceiver($_SESSION['reports_billstoreceiver']);

        $response['result'] = Bills_to_receive::getContentReports($offset, $limit, $filter);
        $response['total_pay'] = array_sum(array_column($response['result'], 'value_to_pay'));
        $response['total'] = array_sum(array_column($response['result'], 'paid_out_value'));

        foreach ($response['result'] as $key => $item) {            
            $response['result'][$key]['expirate_date'] = UtilsController::convertDate($item['expirate_date']);
            $response['result'][$key]['origin'] = Bills_to_receive::getReceiverOrigin($item['receiver_origin']);
            $response['result'][$key]['situation'] = Bills_to_pay::getBillsToPaySituation($item['id_situation']);
            $response['result'][$key]['value_to_pay'] = UtilsController::convertToRealBr($item['value_to_pay']);
            $response['result'][$key]['paid_out_value'] = UtilsController::convertToRealBr($item['paid_out_value']);

            if($item['form_to_pay']) {
                $response['result'][$key]['receiver_name'] = Bills_to_receive::getReceiverForm($item['form_to_pay']);
            } else {
                $response['result'][$key]['receiver_name'] = '';
            }

            if($item['payment_date']) {
                $response['result'][$key]['payment_date'] = UtilsController::convertDate($item['payment_date']);
            } else {
                $response['result'][$key]['payment_date'] = '';
            }
        }

        return $response;
    }

    // Função generica para criação do PDF
    public function generatePdf($content, $title, $orientation) {
        $format = $orientation;

        $mpdf = new \Mpdf\Mpdf([
            'margin_left' => 5,
            'margin_right' => 5,
            'margin_top' => 5,
            'margin_bottom' => 8,
            'orientation' => $format
        ]);

        $mpdf->SetProtection(array('print'));
        $mpdf->SetTitle($title.' - Supporte Agronegócios');
        $mpdf->SetAuthor($this->loggedUser->name);
        // $mpdf->SetWatermarkText("Paid");
        // $mpdf->showWatermarkText = true;
        // $mpdf->watermark_font = 'DejaVuSansCondensed';
        // $mpdf->watermarkTextAlpha = 0.1;
        $mpdf->SetDisplayMode('real');
        $mpdf->WriteHTML($content);
        $mpdf->Output();
    }

    // Função generica para criação do Arquivo Excel
    public function generateCsv($archiveName, $header, $data, $total = array()) {
        header('Content-Type: text/csv; charset=UTF-8');
        header('Content-Disposition: attachment; filename='.$archiveName.'.csv');

        $result = fopen("php://output", 'w');        

        fputcsv($result, $header, ';');

        foreach($data as $item) {
            fputcsv($result, $item, ';');
        }

        if(!empty($total)) {
            $lastRow = array($total['total_title'], $total['total']);

            fputcsv($result, $lastRow, ';');
        }

        fclose($result);
    }

    // Informações do Header arquivo PDF
    private static function getHeaderInfo() {
        $headerInfo = UtilsController::getConfigReports();
        $headerInfo['img_soon'] = Config::SITE_URL.'assets/images/'.$headerInfo['img_soon'];

        return $headerInfo;
    }
}