<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/datepicker.min.css" />
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/datepicker3.min.css" />
<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/bootstrap-datepicker.min.js"></script>
<h3 style="text-align: center">Vista del periodo rezagados por unidad </h3>
<br>
<?php $this->widget('bootstrap.widgets.TbAlert', [
    'block' => true,
    'fade' => true,
    'closeText' => '×',
    'alerts' => [
        'success' => ['block' => true, 'fade' => true, 'closeText' => '×'],
        'error' => ['block' => true, 'fade' => true, 'closeText' => '×'],
    ],
]); ?>
<table class="table table-bordered table-condensed" >
    <thead>
        <tr>
            <th style="text-align: center;">Unidad</th>
            <th style="text-align: center;">Tipo de n&oacute;mina </th>
            <th style="text-align: center;">N&uacute;mero de periodo</th>
            <th style="text-align: center;">Fecha desde</th>
            <th style="text-align: center;">Fecha hasta</th>
        </tr>
    </thead>
    <tr>
        <td style="text-align: center;"><?=$modelUnidad->descripcion; ?></td>
        <td style="text-align: center;"><?=$modelPeriodo->idTipoNomina->nombre_nomina; ?></td>
        <td style="text-align: center;"><?=$modelPeriodo->numero_periodo; ?></td>
        <td style="text-align: center;"><?= Yii::app()->format->date($modelPeriodo->fecha_desde); ?></td>
        <td style="text-align: center;"><?= Yii::app()->format->date($modelPeriodo->fecha_hasta); ?></td>
    </tr>
</table>
<?= CHtml::link('Ir a bandeja de prenómina rezagadas', Yii::app()->createUrl('/prestamo/datosPreNominaCredito/ViewRezagado'), ['class' => 'btn btn-inverse']); ?>
<br>
<br>
<table class="table table-bordered table-condensed" >
    <thead>
        <tr>
            <th style="text-align: center">Categor&iacute;a del pr&eacute;stamo</th>
            <th style="text-align: center">Plazo</th>
            <th style="text-align: center">Cantidad de cuotas</th>
            <th style="text-align: center">Monto capital</th>
            <th style="text-align: center">Monto interés</th>
            <th style="text-align: center">Monto total</th>
        </tr>
    </thead>
    <?php    $sumaCuota = $sumaMonto = $sumaCapita = $sumaInteres = 0;
    foreach ($data as $key => $value) {
    $sumaCuota += $value['cantidad_cuota'];
    $sumaInteres += $value['interes'];
    $sumaCapita += $value['capital'];
    $sumaMonto += $value['monto']; ?>
    <tr>
        <td><?php echo $value['nombre_titulo']; ?></td>
        <td><?php echo $value['descripcion']; ?></td>
        <td style="text-align: center"><?php echo $value['cantidad_cuota']; ?></td>
        <td style="text-align: right">Bs. <?php echo Yii::app()->format->number($value['capital']); ?></td>
        <td style="text-align: right">Bs. <?php echo Yii::app()->format->number($value['interes']); ?></td>
        <td style="text-align: right">Bs. <?php echo Yii::app()->format->number($value['monto']); ?></td>
    </tr>
    <?php } ?>
    <tr class="info" >
        <th colspan="2" style="text-align: center"><b>Totales</b></th>
        <th style="text-align: center"><b><?php echo $sumaCuota; ?></b></th>
        <th style="text-align: right"><b>Bs. <?php echo Yii::app()->format->number($sumaCapita); ?></b></th>
        <th style="text-align: right"><b>Bs. <?php echo Yii::app()->format->number($sumaInteres); ?></b></th>
        <th style="text-align: right"><b>Bs. <?php echo Yii::app()->format->number($sumaMonto); ?></b></th>
    </tr>
</table>
<h3 style="margin-top: 30px; text-align: center;">Administrador de cuotas rezagada</h3>
<?php $this->widget('bootstrap.widgets.TbGridView', [
    'id' => 'credito-grid',
    'dataProvider' => $model->searchGeneradorPreNominaRezagados($modelUnidad->idunidad, $modelPeriodo->id),
    'columns' => [
        [
            'name' => 'cedula',
            'value' => '$data->idCredito->idAsociado->cedula',
            'type' => 'text', ],
        [
            'name' => 'nombre',
            'value' => '$data->idCredito->idAsociado->nombre',
            'type' => 'text', ],
        [
            'name' => 'apellido',
            'value' => '$data->idCredito->idAsociado->apellidos',
            'type' => 'text', ],
        [
            'name' => 'unidad',
            'filter' => Unidad::getUnidadUsario(),
            'value' => '$data->idCredito->idAsociado->unidad->descripcion',
            'type' => 'text', ],
        [
            'name' => 'numero_periodo',
            'value' => '$data->getPeriodo($data->fecha_vencimiento,$data->idCredito->id_tipo_nomina)',
            'type' => 'text',
        ],
        [
            'name' => 'id_tipo_credito',
            'value' => '(isset($data->idCredito->idTipoCredito))?$data->idCredito->idTipoCredito->descripcion:""',
            'htmlOptions' => ['style' => 'text-align: center', 'width' => '80px'],
        ],
        [
            'name' => 'fecha_vencimiento',
            'value' => 'date("d-m-Y",strtotime($data->fecha_vencimiento))',
            'class' => 'SYDateColumn',
        ],
        'numero_cuota',
        [
            'name' => 'monto_cuota',
            'value' => "number_format(\$data->monto_cuota, 2,',','.')",
        ],
        [
            'name' => 'tipo_cuota',
            'value' => '$data->tipo_cuota',
            'filter' => ['O' => 'Ordinaria', 'E' => 'Especiales'],
        ],
    ],
]); ?>
<?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', [
    'id' => 'asociado-cuenta-banco-form',
    'enableAjaxValidation' => false,
    'type' => 'horizontal',
]); ?>

<?php Yii::import('application.modules.contable.models.*', true); ?>
<?php if (ParamEscenarios::fechaComprobante(['cuenta_x_cobrar_retenciones' => 9])): ?>
<div class="well">
    <?= $form->textFieldRow($model, 'fecha_comprobante', array('class' => 'datepicker', 'readOnly' => true)) ?>
</div>
<?php endif ?>

<div style="text-align: center">
    <?php $this->widget('bootstrap.widgets.TbButton', [
        'buttonType' => 'submit',
        'type' => 'success',
        'id' => 'btn_registrar',
        'label' => 'Generar prenómina',
        'icon' => 'icon-ok',
    ]); ?>
    &nbsp;
    <?php $this->widget('bootstrap.widgets.TbButton', [
        'buttonType' => 'submit',
        'type' => 'info',
        'id' => 'btn_registrar',
        'label' => 'Prenómina estimada',
        'icon' => 'icon-ok',
    ]); ?>
</div>
<?php $this->endWidget(); ?>

<script type="text/javascript">
    $('.datepicker').datepicker({
        format: 'dd-mm-yyyy',
        daysOfWeekDisabled: '0,6',
        orientation: 'bottom auto',
        todayHighlight: true,
        toggleActive: true,
        language: 'es',
        autoclose: true
    });
</script>
