<h1 style="text-align: center"> Configuración cierre trimestral</h1>
<?php $this->widget('bootstrap.widgets.TbAlert', [
    'block' => true,
    'fade' => true,
    'closeText' => '&times;',
    'alerts' => [
        'success' => ['block' => true, 'fade' => true, 'Text' => '&times;'],
    ],
]);
?>
<?php
$this->widget('bootstrap.widgets.TbAlert', [
    'block' => true,
    'fade' => true,
    'closeText' => '&times;',
    'alerts' => [
        'error' => ['block' => true, 'fade' => true, 'Text' => '&times;'],
    ],
]);
$modelc = CierreTrimestral::model()->findBySql(
    'select min(id) as id from contable.cierre_trimestral where estatus=false and id_periodo=(select id from contable.ejercicios where activo=1)'
);
$modeld = CierreTrimestral::model()->findBySql(
    'select max(id) as id from contable.cierre_trimestral where estatus=false and id_periodo=(select id from contable.ejercicios where activo=1)'
);
$campo = $modelc->id;
$campo2 = $modeld->id;
?>
<?php $this->widget('bootstrap.widgets.TbGridView', [
    'id' => 'cierre-trimestral-grid',
    'dataProvider' => $model->search(),
    'filter' => $model,
    'rowCssClassExpression' => '$data->color',
    'columns' => [
        'id',
        'trimestre',
        'meses',
        [
            'header' => 'Estatus',
            'name' => 'estatus',
            'value' => '$data->estatus($data->estatus)',
            'filter' => CHtml::activeDropDownList(
                $model,
                'estatus',
                ['0' => 'ABIERTO', '1' => 'CERRADO'],
                ['prompt' => 'SELECCIONE']
            ),
        ],
        [
            'header' => 'Periodo contable',
            'name' => 'id_periodo',
            'value' => '$data->periodo->nombre_periodo',
            'filter' => CHtml::activeDropDownList(
                $model,
                'id_periodo',
                CHtml::listData(EjerciciosContables::model()->findAll('estatus in (1,2)'), 'id', 'nombre_periodo'),
                ['prompt' => 'SELECCIONE']
            ),
        ],
        [
            'class' => 'bootstrap.widgets.TbButtonColumn',
            'template' => '{cambiar} ',
            'buttons' => [
                'cambiar' => [
                    'label' => 'Cerrar trimestre',
                    'url' => "CHtml::normalizeUrl(array('/contable/cierreTrimestre/create', 'id'=>\$data->id))",
                    'icon' => 'check',
                    'visible' => '$data->estatus==false && $data->id=='.$campo.' && $data->id<='.$campo2.'',
                ],
            ],
        ],
    ],
]);
