<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl.'/js/jquery.mask.min.js', CClientScript::POS_HEAD); ?>

<div class="form">
    <?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', [
        'id' => 'ajuste-haberes-form',
        'enableAjaxValidation' => false,
        'enableClientValidation' => true,
        'clientOptions' => [
            'validateOnSubmit' => true,
            'validateOnChange' => true,
            'validateOnType' => true,
        ],
    ]);

    $this->widget('bootstrap.widgets.TbAlert', [
        'block' => true,
        'fade' => true,
        'closeText' => '×',
        'alerts' => [
            'error' => ['block' => true, 'fade' => true, 'closeText' => '×'],
        ],
    ]);
    ?>

    <p class="help-block">Campos con <span class="required">*</span> son requerido.</p>
    <?= $form->errorSummary($model); ?>
    <br>
    <fieldset>
        <legend style=" font-size: 17px;"><b>Datos del solicitante</b></legend>
        <table class="table table-bordered">
            <tr>
                <td style="width: 25%"><b>
                        <?= $form->labelEx($model, 'cedula'); ?></b></td>
                <td style="width: 25%">
                    <div style="display:table">
                        <div style="float:left; width: 65%;">
                            <?= $form->textField($model, 'cedula', ['maxlength' => '10', 'class' => 'input-medium']); ?>
                            <?=  $form->error($model, 'cedula'); ?>
                        </div>
                        <div style="float:right;width: 35%;">
                            <?= CHtml::htmlButton('Buscar <i class="icon-search"></i>', ['type' => 'button', 'class' => 'btn btn-success icon button', 'onClick' => 'datosPersonalesCredito()']); ?>
                        </div>
                    </div>
                    <div id="mensajesSistema" class="datosPersonales"></div>
                </td>
                <td style="width: 20%"><b>Nombres y apellidos</b></td>
                <td style="width: 30%">
                    <div id="nombres_apellidos" class="datosPersonales"></div>
                </td>
            </tr>
            <tr>
                <td><b>Empresa</b></td>
                <td>
                    <div id="empresa" class="datosPersonales"></div>
                </td>
                <td><b>Unidad</b></td>
                <td>
                    <div id="unidad" class="datosPersonales"></div>
                </td>
            </tr>
            <tr>
                <td><b>&Uacute;ltimo sueldo</b></td>
                <td>
                    <div id="sueldo" class="datosPersonales"></div>
                </td>
                <td><b>Porcentaje de aporte</b></td>
                <td>
                    <div id="porcentaje" class="datosPersonales"></div>
                </td>
            </tr>
            <tr>
                <td><b>Fecha de inscripci&oacute;n</b></td>
                <td>
                    <div id="fecha_inscripcion" class="datosPersonales"></div>
                </td>
                <td><b>Estatus</b></td>
                <td>
                    <div id="estatus" class="datosPersonales"></div>
                </td>
            </tr>
            <tr>
                <td colspan="4" id="calculadoraHaberesSocio" class="datosCredito" style="display: none"></td>
            </tr>

        </table>
    </fieldset>
    <h4>Datos del ajuste</h4>
    <fieldset>
        <table class="table table-bordered" id="datos_prestamos_calculadora">
            <tr>
                <td style="width: 25%"><b>
                        <?= $form->labelEx($model, 'id_tipo_ajuste'); ?></b></td>
                <td>
                    <?= $form->dropDownList($model, 'id_tipo_ajuste', TipoAjuste::getAll(), [
                        'prompt' => 'Seleccione',
                        'ajax' => [
                            'type' => 'POST',
                            'url' => CController::createUrl('/comun/conceptos'),
                            'data' => ['id_tipo_ajuste' => 'js:this.value'],
                            'update' => '#id_concepto_ajuste',
                        ],
                    ]); ?><br>
                    <?= $form->error($model, 'id_tipo_ajuste'); ?>
                </td>
            </tr>
            <tr>
                <td style="width: 25%"><b>
                        <?= $form->labelEx($model, 'id_concepto_ajuste'); ?></b></td>
                <td>
                    <?= $form->dropDownList($model, 'id_concepto_ajuste', [], [
                        'prompt' => 'Seleccione',
                        'id' => 'id_concepto_ajuste',
                    ]); ?><br>
                    <?= $form->error($model, 'id_concepto_ajuste'); ?>
                </td>
            </tr>
            <tr>
                <td style="width: 25%"><b>
                        <?= $form->labelEx($model, 'id_tipo_movimiento'); ?></b></td>
                <td>
                    <?= $form->dropDownList($model, 'id_tipo_movimiento', CHtml::listData(TipoMovimiento::model()->findAll(), 'id', 'descripcion'), ['prompt' => 'Seleccione']); ?><br>
                    <?= $form->error($model, 'id_tipo_movimiento'); ?>
                </td>
            </tr>
            <tr id="monto_asociado" style="display: <?= ($model->id_tipo_movimiento == 1 || $model->id_tipo_movimiento == 3) ? 'block' : 'none'; ?>">
                <td style="width: 25%"><b>
                        <?= $form->labelEx($model, 'monto_asociado'); ?></b></td>
                <td>
                    <?= $form->textField($model, 'monto_asociado', ['class' => 'moneda']); ?><br>
                    <?= $form->error($model, 'monto_asociado'); ?>
                </td>
            </tr>
            <tr id="monto_patrono" style="display: <?= ($model->id_tipo_movimiento == 2 || $model->id_tipo_movimiento == 3) ? '
                block' : 'none'; ?>">
                <td style="width: 25%"><b>
                        <?= $form->labelEx($model, 'monto_patrono'); ?></b></td>
                <td>
                    <?= $form->textField($model, 'monto_patrono', ['class' => 'moneda']); ?><br>
                    <?= $form->error($model, 'monto_patrono'); ?>
                </td>
            </tr>
            <tr>
                <td style="width: 25%"><b>
                        <?= $form->labelEx($model, 'numero_operacion'); ?></b></td>
                <td>
                    <?= $form->textField($model, 'numero_operacion'); ?><br>
                    <?= $form->error($model, 'numero_operacion'); ?>
                </td>
            </tr>
            <tr>
                <td style="width: 25%"><b>
                        <?= $form->labelEx($model, 'fecha_operacion'); ?></b></td>
                <td>
                    <?php $this->widget('zii.widgets.jui.CJuiDatePicker', [
                        'model' => $model,
                        'attribute' => 'fecha_operacion',
                        'value' => $model->fecha_operacion,
                        'language' => 'es',
                        'htmlOptions' => ['readonly' => 'readonly', 'class' => 'input-small'],
                        'options' => [
                            'autoSize' => true,
                            'dateFormat' => 'dd-mm-yy',
                            'buttonImage' => Yii::app()->baseUrl.'/images/calendar.png',
                            'buttonImageOnly' => true,
                            'buttonText' => 'Fecha',
                            'selectOtherMonths' => true,
                            'showAnim' => 'slide',
                            'showButtonPanel' => true,
                            'showOn' => 'button',
                            'changeMonth' => 'true',
                            'changeYear' => 'true',
                            'maxDate' => '+0D',
                        ],
                    ]); ?>
                    <br>
                    <?= $form->error($model, 'fecha_operacion'); ?>
                </td>
            </tr>
            <tr>
                <td style="width: 25%"><b>
                        <?= $form->labelEx($model, 'observacion'); ?></b></td>
                <td>
                    <?= $form->textArea($model, 'observacion', ['rows' => 6, 'class' => 'span9']); ?><br>
                    <?= $form->error($model, 'observacion'); ?>
                </td>
            </tr>
        </table>
    </fieldset>
    <div class="form-actions text-center" style="text-align: center">
        <?php $this->widget('bootstrap.widgets.TbButton', [
            'buttonType' => 'submit',
            'type' => 'success',
            'icon' => 'icon-ok',
            'label' => 'Registrar ajuste',
            'htmlOptions' => ['id' => 'btn_registrar'],
        ]); ?>

        <?php $this->endWidget(); ?>
    </div>
</div><!-- form -->
<?php
    Yii::app()->clientScript->registerScript('datosPersonales', '

	var datosPostDatos = '.(($postDatos) ? 1 : 0).';
    function datosPersonalesCredito(){
        let cedula = $("#'.CHtml::activeId($model, 'cedula').'").val();
        if($.isNumeric(cedula)&& cedula>6){
            $.ajax({
                url:"'.CController::createUrl('/Comun/DatosPersonales').'",
                cache: false,
                type: "POST",
                dataType: "json",
                data: ({cedula:cedula}),
                beforeSend: function(xkr){
                    $(".datosPersonales").html("");
                    $("#mensajesSistema").html("");
                    $("#error_submit").html("");
                    $("#btn_registrar").prop("disabled", true);

                },
                success: function(data){
                    $("#nombres_apellidos").html(data.nombres_apellidos);
                    $("#empresa").html(data.empresa);
                    $("#unidad").html(data.unidad);
                    $("#sueldo").html("Bs. "+data.sueldo);
                    $("#porcentaje").html(data.porcentaje);
                    $("#fecha_inscripcion").html(data.fecha_inscripcion);
                    $("#estatus").html(data.estatus);
                    $("#btn_registrar").prop("disabled", false);
                    if(data.error==1){
                        $("#mensajesSistema").html(data.mensajeError);
                        $("#btn_registrar").prop("disabled", true);
                    }

                }
            });
            datosPostDatos= 0;
        }
        else{
            $(".datosCredito").html("");
            $(".detalle_capacidad_pago").remove();
            $(".detalle_tabla_amortizacion").remove();
            $(".datosPersonales").html("");
            $("#mensajesSistema").html("");
            $(".desicionCuotasEspeciales").hide();
        }

    };


	$(\'.moneda\').mask(\'#.##0,00\', {reverse: true});

	', CClientScript::POS_HEAD);
    Yii::app()->clientScript->registerScript('tablaAmortizacion2', '
        $("#'.CHtml::activeId($model, 'id_tipo_movimiento').'").change(function(){

            $("#monto_asociado").hide("slow");
            $("#monto_patrono").hide("slow");
            if($(this).val()==1){
                $("#monto_asociado").show("slow");
            }
            else if($(this).val()==2){
                $("#monto_patrono").show("slow");
            }
            else if($(this).val()==3){
               $("#monto_patrono").show("slow");
               $("#monto_asociado").show("slow");
            }
        });
			$(document).ready(function() {
                            $(\'.moneda\').mask(\'#.##0,00\', {reverse: true});

                            $("form").keypress(function(e) {
                                if (e.which == 13) {
                                    return false;
                                }
                            });
                            if($("#'.Chtml::activeId($model, 'cedula').'").val()!=""){
                                    consultarTablaAmortizacionPost();
                            }

                            $("#btn_registrar").prop("disabled", true);
                            $("#error_submit").html("");
			});
	');
