<?php
$this->PageTitle = 'Relatório de Prospectos / Clientes';

if (isset($_GET['busca'])) {
    $this->menu = array(

        array('label' => FaHtml::iconExcel(),
              'url' => array('generateExcel',
                             'token' => $model->TOKEN),
              'linkOptions' => array('class' => 'novo exportar')),

        array('label' => FaHtml::iconCsv('Exportar lista de e-mails'),
              'url' => array('exportEmails',
                             'page' => 'relatorio_clientes',
                             'format' => 'csv',
                             'token' => $model->TOKEN),
              'linkOptions' => array('class' => 'novo exportarCsv')),

        array('label' => FaHtml::iconTxt('Exportar lista de e-mails'),
              'url' => array('exportEmails',
                             'page' => 'relatorio_clientes',
                             'format' => 'txt',
                             'token' => $model->TOKEN),
              'linkOptions' => array('class' => 'novo exportarTxt')),

        array('label' => FaHtml::iconSetaClose(), 'url' => '#', 'linkOptions' => array('class' => 'search-button')),
        array('label' => FaHtml::iconRefresh(),
              'url' => 'javascript:void(0);',
              'linkOptions' => array('onclick' => 'reloadFrame();',
                                     'class' => 'refresh-button'))
    );
} else {
    $this->menu = array(
        array('label' => FaHtml::iconSetaClose(), 'url' => '#', 'linkOptions' => array('class' => 'search-button')),
        array('label' => FaHtml::iconRefresh(), 'url' => 'javascript:void(0);', 'linkOptions' => array('onclick' => 'reloadFrame();', 'class' => 'refresh-button'))
    );
}

$dataProvider = $model->search();
?>
<div class="search-form" style="display:<?php echo (isset($_GET['busca'])) ? 'none' : 'block'; ?>" >
    <?php $this->renderPartial('_searchrelatorioclientes', array('model' => $model)); ?>
</div><!-- search-form -->
<style type="text/css">
    /* ultima atividade comercial */
    /* ultima atividade suporte */
    #admin-grid table th:nth-child(1),
    #admin-grid table td:nth-child(1):not(.empty),
    #admin-grid table th:nth-child(2),
    #admin-grid table td:nth-child(2):not(.empty) {
        text-align: center;
        min-width: 60px!important;
        max-width: 60px!important;
            width: 60px!important;
    }
    /* telefone */
    #admin-grid table th:nth-child(4),
    #admin-grid table td:nth-child(4) {
        text-align: center;
        min-width: 80px!important;
        max-width: 80px!important;
            width: 80px!important;
    }
</style>
<?php

if (isset($_GET['busca'])) {
    $columns = array();
    if (Yii::app()->cache->get($model->TOKEN.'_camposData') == 'DataCadastro') {
        $columns[] = 'CLI_DTCADASTRO';
    } else {
        $columns[] = array(
            'name' => 'CLI_DT_ULTIMA_ATIVIDADE_COMERCIAL',
            'header' => 'Última atividade comercial',
        );
        $columns[] = array(
            'name' => 'CLI_DT_ULTIMA_ATIVIDADE_SUPORTE',
            'header' => 'Última atividade suporte',
        );
    }
    $columns[] = 'CLI_NOME';
    $columns[] = 'CLI_FONE1';
    $columns[] = 'CLI_FONE2';
    $columns[] = 'CLI_FONE3';

    $columns[] = 'CLI_EMAIL';
    $columns[] = array(
        'name' => 'Cidade',
        'value' => 'GxHtml::valueEx($data->Cidade)',
    );
    $columns[] = array(
        'name' => 'CLI_SITUACAO',
        'value' => 'Util::getStatusCliente($data->CLI_SITUACAO)',
    );
    $columns[] = array(
        'name' => 'ComoConheceu',
        'value' => 'GxHtml::valueEx($data->ComoConheceu)',
    );
    $columns[] = array(
        'name' => 'VendedorResponsavel',
        'value' => 'GxHtml::valueEx($data->VendedorResponsavel)',
    );
    $columns[] = array(
        'name' => 'RevendaResponsavel',
        'value' => 'GxHtml::valueEx($data->getRevendaResponsavel2())',
    );
    $columns[] = array(
        'class' => 'CButtonColumn',
        'template' => '{view}',
        'viewButtonOptions' => array('target' => '_blank'),
        'buttons' => array(
            'view' => array(
                'label' => 'Exibir',
                'url' => 'Yii::app()->createUrl("clientes/view", array("id"=>$data->CLI_IDCLIENTE))',
            ),
        ),
    );
    $this->widget('ext.Utils.widgets.CrmGridView', array(
        'id' => 'admin-grid',
        'dataProvider' => $dataProvider,
        'afterAjaxUpdate'=>'updated',
        'selectableRows' => 1,
        'pager' => Util::getPagerDefaultConfig(),
        'columns' => $columns
        )
    );
}