<?php Yii::app()->getClientScript()->registerCssFile(Yii::app()->baseUrl.'/css/bootstrap2-toggle.css'); ?>
<?php Yii::app()->getClientScript()->registerScriptFile(Yii::app()->baseUrl.'/js/bootstrap2-toggle.js'); ?>

<h2 style="text-align: center;">Generar reporte situación financiera trimestral <?= $periodo->nombre_periodo; ?></h2>
<br>

<?php
   $this->widget('bootstrap.widgets.TbAlert', [
       'block' => true, 
       'fade' => true,
       'closeText' => '&times;',
       'alerts' => [
           'info' => ['block' => true, 'fade' => true, 'Text' => '&times;'], 
       ],
   ]);
?>

<div class="form">
    <?php $form = $this->beginWidget('CActiveForm', [
        'id' => 'detalle-analitico-busca_balance_comprobacion-form',
        'enableAjaxValidation' => false,
    ]); ?>
            <fieldset>
                <h4>Cuentas contables</h4>
                <div class="span12">
                    <div class="span5">
                        <?php echo $form->labelEx($model, 'id_cuenta_desde'); ?>
                        <?php
                            if ($model->cuentamov != '') {
                                $value = $model->cuentamov->codigo_cuenta;
                            } else {
                                $value = '';
                            }
                            echo $form->hiddenField($model, 'id_cuenta_desde');
                            $this->widget('zii.widgets.jui.CJuiAutoComplete', [
                                'name' => 'cuenta_desde',
                                'model' => $model,
                                'value' => $value,
                                'sourceUrl' => $this->createUrl('CuentaRealmovId'),
                                'options' => [
                                    'minLength' => '1',
                                    'showAnim' => 'fold',
                                    'select' => 'js:function(event, ui)
                                    { jQuery("#ReportesContables_id_cuenta_desde").val(ui.item["id"]); }',
                                    'search' => 'js:function(event, ui)
                                    { jQuery("#ReportesContables_id_cuenta_desde").val(); }',
                                ],
                                'htmlOptions' => [
                                    'class' => 'span5',
                                ],
                            ]);

                            ?>
                        <?php echo $form->error($model, 'cuenta_desde'); ?>
                    </div>
                    <div class="span5">
                        <?php echo $form->labelEx($model, 'id_cuenta_hasta'); ?>
                        <?php
                            if ($model->cuentamov != '') {
                                $value = $model->cuentamov->codigo_cuenta;
                            } else {
                                $value = '';
                            }
                            echo $form->hiddenField($model, 'id_cuenta_hasta');
                            $this->widget('zii.widgets.jui.CJuiAutoComplete', [
                                'name' => 'cuenta_hasta',
                                'model' => $model,
                                'value' => $value,
                                'sourceUrl' => $this->createUrl('CuentaRealmovId'),
                                'options' => [
                                    'minLength' => '1',
                                    'showAnim' => 'fold',
                                    'select' => 'js:function(event, ui)
                                    { jQuery("#ReportesContables_id_cuenta_hasta").val(ui.item["id"]); }',
                                    'search' => 'js:function(event, ui)
                                    { jQuery("#ReportesContables_id_cuenta_hasta").val(); }',
                                ],
                                'htmlOptions' => [
                                    'class' => 'span5',
                                ],
                            ]);
                        ?>
                        <?php echo $form->error($model, 'cuenta_hasta'); ?>
                    </div>
                </div>
            </fieldset>
            <fielset>
                <h4>Trimestre</h4>
                <div class="span12">
                    <div class="span5">
                        <?php echo $form->labelEx($model, 'Trimestre'); ?>
                        <?php echo $form->dropDownList($model, 'trimestre', ['1' => 'Trimestre 1: Enero-Febrero-Marzo',
                                                                                '2' => 'Trimestre 2: Abril-Mayo-Junio',
                                                                                '3' => 'Trimestre 3: Julio-Agosto-Septiembre',
                                                                                '4' => 'Trimestre 4: Octubre-Noviembre-Diciembre',
                                                                                        ], ['class' => 'span5']); ?>
                        <?php echo $form->error($model, 'Trimestre'); ?>
                    </div>
                    <div class="span5">
                        <?php echo $form->labelEx($model, 'Año'); ?>
                        <?php echo $form->dropDownList($model, 'anyo', CHtml::listData(AnosContables::model()->findAll('anyo=:ano', [
                            'ano' => date('Y', strtotime($periodo->fecha_inicio))
                        ]), 'anyo', 'anyo'), ['class' => 'span5']); ?>
                        <?php echo $form->error($model, 'anyo'); ?>
                    </div>
                </div>
            </fieldset>
            <br/>
            <fieldset>
                <h4>Habilitar firmas en reporte</h4>
                <?php if (! empty($categorias)): ?>
                    <?php foreach ($categorias as $key => $value): ?>
                        <div class="row-fluid">
                            <div class="span12"><h4 align="center"><?php echo $value->nombre_dept; ?></h4></div>
                        </div>
                            <?php

                                $funcionarios = Funcionario::model()->findAll(['condition' => 'id_dpto=:dpto and activo=true', 'order' => 'id_jerarquia asc', 'params' => [':dpto' => $value->id]]);
                                if (! empty($funcionarios)) {
                                    ?>
                                <div class="row-fluid">
                                <?php foreach ($funcionarios as $funcionario => $datos): ?>
                                    <?php if ($datos->id_dpto == $value->id) {
                                        ?>
                                        <div class="span3">
                                            <div align="center"><?php echo CHtml::label($datos->nombre.' '.$datos->apellido.'<br/>'.$datos->idJerarquia->nombre_cargo, ''); ?></div>
                                            <div align="center" class='bot_marg'><?php echo CHtml::checkBox($value->nombre_dept.'['.$datos->id.']', false); ?></div>
                                        </div>
                                    <?php
                                    } ?>
                                <?php endforeach; ?>
                                </div><br/>
                            <?php
                                } else {
                                    ?>
                                <div class="row-fluid">
                                    <div class="span12" align="center"><span>No hay funcionarios registrados en este Dpto.</span></div>
                                </div><br/>
                            <?php
                                } ?>
                    <?php endforeach; ?>
                <?php else: ?>
                    <div class="row-fluid">
                        <div class="span12" align="center"><span>No hay departamentos. registrados.</span></div>
                    </div>
                <?php endif; ?>
            </fieldset>
            <br/>
            <fielset>
                <h4>Otras opciones</h4>
                <div class="row">
                    <div class="span3">
                        <?php echo $form->labelEx($model, 'nivel'); ?>
                        <?php echo $form->dropDownList($model, 'nivel', [1 => '1 ) Rubro', '2' => '2 ) Grupo', '3' => '3 ) Cuenta',
                            '4' => '4 )  1 era Subcuenta', '5' => '5 )  2 da Subcuenta', '6' => '6 )  3 era Subcuenta',
                            '7' => '7 )  Auxiliar', ], ['class' => 'span2']); ?>
                        <?php echo $form->error($model, 'nivel'); ?>
                    </div>
                    <div class="span3">
                        <?php echo $form->labelEx($model, 'sin_ceros'); ?>
                        <?php echo $form->checkBox($model, 'sin_ceros'); ?>
                        <?php echo $form->error($model, 'sin_cero'); ?>
                    </div>
                    <div class="span3">
                        <?= $form->labelEx($model, 'excluir_movimiento_cierre'); ?>
                        <?= $form->checkBox($model, 'excluir_movimiento_cierre'); ?>
                        <?= $form->error($model, 'excluir_movimiento_cierre'); ?>
                    </div>
                    <div class="span3">
                        <?= $form->label($model, 'formato') ?>
                        <?= $form->checkBox($model, 'formato', [
                            'data-toggle' => 'toggle',
                            'data-on' => 'PDF',
                            'data-off' => 'Excel',
                            'data-size' => 'normal',
                            'data-onstyle' => 'primary',
                            'data-offstyle' => 'success',
                        ]); ?>
                    </div>
                </div>
            </fielset>
            <div class="form-actions text-center">
                <?php $this->widget('bootstrap.widgets.TbButton', ['buttonType' => 'submit', 'label' => 'Buscar', 'type' => 'primary']); ?>
            </div>
        </div>
    <?php $this->endWidget(); ?>
</div>
