<h3 style="text-align: center">Aprobar solicitud de prestamo</h3>

<?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', [
    'id' => 'credito-form',
    'enableClientValidation' => true,
    'clientOptions' => [
        'validateOnSubmit' => true,
    ],
]); ?>
    <?php echo $form->errorSummary($model); ?>
    <?php foreach (Yii::app()->user->getFlashes() as $key => $message) {
        echo '<div class="alert alert-error flash-'.$key.'">'.$message."</div>\n";
    } ?>
    <?= $this->renderPartial('application.modules.asociado.views.asociado.haberesSocio', [
        'modelAsociado' => $modelAsociado,
        'haberes' => $modelHaberesSocio,
        'porcentaje' => $porcentaje,
        'etiquetaFecha' => 'Fecha de Inscripci&oacute;n',
        'montoTotaSolicitud' => $model->habereDisponibles,
        'fecha' => $modelAsociado->fechaingreso,
        'disponible' => new Disponibilidad([
            'asociado' => $modelAsociado->idasociado,
            'proceso' => 1,
        ]),
    ]); ?>

    <?php echo $this->renderPartial('application.modules.asociado.views.asociado.detallesHaberesSocio', ['id' => $modelAsociado->idasociado]); ?>

    <br>
    <h4>Información del prestamo solicitado</h4>
    <table class="table table-bordered table-striped table-condensed">
        <thead>
            <tr>
                <th style="text-align: center"><b>Fecha solicitud</b></th>
                <th style="text-align: center"><b>Tipo de prestamo</b></th>
                <th style="text-align: center"><b>Monto solicitado</b></th>
                <th style="text-align: center"><b>Cuota a pagar</b></th>
                <th style="text-align: center"><b>Interes(%)</b></th>
                <th style="text-align: center"><b>Gastos administrativo</b></th>
                <?php if ($model->gastos_administrativos_afianzadora != 0) { ?>
                <th style="text-align: center"><b>Gastos administrativo afianzadora</b></th>
                <?php } ?>
                <th style="text-align: center"><b>Monto a otorgar</b></th>
                <th style="text-align: center"><b>Tabla amortización</b></th>
            </tr>
        </thead>
        <tr>
            <td style="text-align: center"><?= Yii::app()->format->date($model->fecha_registro); ?></td>
            <td style="text-align: center"><?= $model->idTipoCredito->descripcion; ?></td>
            <td style="text-align: center"><?= Yii::app()->format->number($model->monto_credito); ?></td>
            <td style="text-align: center"><?= Yii::app()->format->number($model->cuota_pagar); ?></td>
            <td style="text-align: center"><?= Yii::app()->format->number($model->taza_interes); ?></td>
            <td style="text-align: center"><?= Yii::app()->format->number($model->gastos_administrativo); ?></td>
            <?php if ($model->gastos_administrativos_afianzadora != 0) { ?>
            <td style="text-align: center"><?= Yii::app()->format->number($model->gastos_administrativos_afianzadora); ?></td>
            <?php } ?>
            <td style="text-align: center"><?= Yii::app()->format->number(($model->monto_credito - ($model->gastos_administrativo + $model->gastos_administrativos_afianzadora))); ?></td>
            <td style="text-align: center">
                <a data-toggle="modal" data-target="#myModal" class="btn btn-link">Ver</a>
            </td>
        </tr>
    </table>

    <div class="row">
        <div class="span2">
            <?php $this->beginWidget('bootstrap.widgets.TbModal', ['id' => 'myModal', 'htmlOptions' => ['style' => 'width: 800px; margin-left: -400px']]); ?>
                <div class="modal-header">
                    <a class="close" data-dismiss="modal">&times;</a>
                    <h4>Informaci&oacute;n de amortizaci&oacute;n del prestamo</h4>
                </div>
                <div class="modal-body">
                    <?php $this->widget('bootstrap.widgets.TbGridView', [
                        'type' => 'bordered',
                        'id' => 'creditospagos-grid',
                        'dataProvider' => CreditoTablaAmortizacion::model()->search($model->id),
                        'columns' => [
                            [
                                'name' => 'numero_cuota',
                                'value' => '$data->numero_cuota',
                            ],
                            [
                                'name' => 'monto_base',
                                'value' => 'number_format($data->monto_base, 2,",",".")',
                            ],
                            [
                                'name' => 'monto_capital',
                                'value' => 'number_format($data->monto_capital, 2,",",".")',
                            ],
                            [
                                'name' => 'monto_interes',
                                'value' => 'number_format($data->monto_interes, 2,",",".")',
                            ],
                            [
                                'name' => 'monto_cuota',
                                'value' => 'number_format($data->monto_cuota, 2,",",".")',
                            ],
                            [
                                'name' => 'monto_credito',
                                'value' => 'number_format($data->monto_credito, 2,",",".")',
                            ],
                        ],
                    ]); ?>
                </div>
                <div class="modal-footer">
                    <?php $this->widget('bootstrap.widgets.TbButton', [
                        'label' => 'Cerrar',
                        'url' => '#',
                        'htmlOptions' => ['data-toggle' => 'modal', 'data-target' => '#myModal'],
                    ]); ?>
                </div>
            <?php $this->endWidget(); ?>
        </div>
    </div>

    <?php if (count($modelCreditoSeleccionado) > 0) { ?>
    <h4>Pr&eacute;stamos <?= ($model->refinanciado > 0) ? (($model->refinanciado == 1) ? 'Refinanciado(s)' : 'Reestructurado(s)') : ''; ?></h4>
    <table class="table display items table table-bordered table-condensed">
        <thead>
            <tr>
                <th style="width: 18%; text-align: center;">Categor&iacute;a</th>
                <th style="width: 18%; text-align: center;">Plazo del pr&eacute;stamo</th>
                <th style="width: 10%; text-align: center;">Monto solicitado</th>
                <th style="width: 10%; text-align: center;">Monto aprobado</th>
                <th style="width: 11%; text-align: center;">Fecha del pr&eacute;stamo</th>
                <th style="width: 9%"; text-align: center;>Cuotas pagadas</th>
                <th style="width: 8%; text-align: center;">Saldo deudor</th>
            </tr>
        </thead>
        <?php foreach ($modelCreditoSeleccionado as $key => $value) { ?>
        <tr>
            <td><?= $value['categoria']; ?></td>
            <td><?= $value['plazo_prestamo']; ?></td>
            <td style="text-align: right;"><?= number_format($value['prestamo'], 2, ',', '.'); ?></td>
            <td style="text-align: right;"><?= number_format($value['prestamo'], 2, ',', '.'); ?></td>
            <td style="text-align: center;"><?= Yii::app()->format->date($value['fecha_registro']) ?></td>
            <td style="text-align: center;"><?= (int) $value['cuotas_pagadas']; ?></td>
            <td style="text-align: right;"><?= number_format($value['deuda_actual'], 2, ',', '.'); ?></td>
        </tr>
        <?php } ?>
    </table>
    <?php } ?>

    <br>
    <?php
    echo $form->labelEx($model, 'fecha_primer_descuento');
    $this->widget('zii.widgets.jui.CJuiDatePicker', [
        'model' => $model,
        'attribute' => 'fecha_primer_descuento',
        'value' => $model->fecha_primer_descuento,
        'language' => 'es',
        'htmlOptions' => ['readonly' => 'readonly'],
        'options' => [
            'autoSize' => true,
            'defaultDate' => $model->fecha_primer_descuento,
            'dateFormat' => 'dd-mm-yy',
            'buttonImage' => Yii::app()->baseUrl.'/images/calendar.png',
            'buttonImageOnly' => true,
            'buttonText' => 'Fecha',
            'selectOtherMonths' => true,
            'showAnim' => 'slide',
            'showButtonPanel' => true,
            'showOn' => 'button',
            'showOtherMonths' => true,
            'changeMonth' => 'true',
            'changeYear' => 'true',
        ],
    ]);
    echo $form->error($model, 'fecha_primer_descuento');
    ?>
    <span class="help-block">Fecha en la cual se comenzara hacer el primer descuento del préstamo.</span>

    <?= $form->textAreaRow($modelCreditoSeguimiento, 'observacion', ['rows' => 6, 'cols' => 50, 'class' => 'span8']); ?>

    <div class="form-actions text-center">
        <?php $this->widget('bootstrap.widgets.TbButton', [
            'type' => 'success',
            'buttonType' => 'submit',
            'id' => 'btn_registrar',
            'icon' => 'icon-ok',
            'label' => 'Aprobar',
        ]); ?>
        <?php $this->widget('bootstrap.widgets.TbButton', [
            'type' => 'danger',
            'buttonType' => 'submit',
            'id' => 'btn_registrar',
            'label' => 'Denegar',
            'icon' => 'icon-remove',
        ]); ?>
        <?php $this->widget('bootstrap.widgets.TbButton', [
            'type' => 'info',
            'id' => 'btn_registrar',
            'label' => 'Regresar',
            'icon' => 'icon-circle-arrow-left',
            'url' => Yii::app()->createUrl('prestamo/credito/admin'),
        ]); ?>
    </div>
<?php $this->endWidget();
