<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl.'/js/distribucion_aporte.js', CClientScript::POS_END); ?>
<h3 style="text-align: center;">Registro de pago de aportes</h3>
<?php
foreach (Yii::app()->user->getFlashes() as $key => $message) {
    echo '<div class="alert alert-'.$key.'">'.$message."</div>\n";
}
?>
<table class="table table-bordered">
    <tr>
        <td  style="text-align: center;"  colspan="4"><b>Informaci&oacute;n de carga inicial</b></td>
    </tr>
    <tr>
        <td><b><?php echo $model->getAttributeLabel('nombre_archivo')?></b></td>
        <td><?php echo $model->nombre_archivo?></td>
        <td><b><?php echo $model->getAttributeLabel('descripcion')?></b></td>
        <td><?php echo $model->descripcion?></td>
    </tr>
    <tr>
        <td><b><?php echo $model->getAttributeLabel('cant_aportantes')?></b></td>
        <td><?php echo $model->cant_aportantes?></td>
        <td><b><?php echo $model->getAttributeLabel('total_aportes')?></b></td>
        <td><?php echo number_format($model->total_aportes, 2, ',', '.'); ?></td>
    </tr>
    <tr>
        <td><b><?php echo $model->getAttributeLabel('fecha_aporte')?></b></td>
        <td><?php echo date('d-m-Y', strtotime($model->fecha_aporte))?></td>
        <td><b><?php echo $model->getAttributeLabel('fecha_registro')?></b></td>
        <td><?php echo date('d-m-Y', strtotime($model->fecha_registro)) ?></td>
    </tr>
    <!--  <tr>
        <td><b><?php echo $model->getAttributeLabel('total_aportes')?></b></td>
        <td><?php echo $model->total_aportes?></td>
        <td><b><?php echo $model->getAttributeLabel('cant_aportantes')?></b></td>
        <td><?php echo $model->cant_aportantes?></td>
    </tr> -->
    <tr>
        <td><b>Asociados con aporte patronal en cero (0)</b></td>
        <td><?php echo $aportesCeroPatrono; ?></td>
        <td><b>Asociado con aporte empleado en cero (0)</b></td>
        <td><?php echo $aportesCeroSocio; ?></td>
    </tr>
    <tr>
        <td colspan="1"><b>Aportantes con aportes propios y del patrono en cero (0)</b></td>
        <td colspan="3" style="text-align: center;"><?php echo $aportesCero; ?></td>
    </tr>
    <tr>
        <td colspan="1"><b><?php echo $model->getAttributeLabel('estatus')?></b></td>
        <td colspan="3" style="text-align: center;"><?php echo $model->getEstatus(); ?></td>
    </tr>
</table>
<table class="table table-bordered">
    <tr>
        <td colspan="7" style="text-align: center;"><b>Resultado de la depuraci&oacute;n de carga </b></td>
    </tr>
    <tr>
        <td colspan="6" ><b>Arportes activos</b></td>
        <td style="text-align: center;"><b>Totales</b></td>
    </tr>
    <tr>
        <td>Cant. asociados activos</td>
        <td style="text-align: center;"><?php echo $totalAportantes?></td>
        <td>Total aporte empleado</td>
        <td style="text-align: right;"><?php  echo number_format($totalMontoAporteActivo->aporte_asociado, 2, ',', '.')?> Bs.</td>
        <td>Total aporte patronal</td>
        <td style="text-align: right;"><?php  echo number_format($totalMontoAporteActivo->aporte_patrono, 2, ',', '.')?> Bs.</td>
        <td style="text-align: right;"><b><?php  echo number_format($totalMontoAporteActivo->aporte_asociado + $totalMontoAporteActivo->aporte_patrono, 2, ',', '.')?> Bs.</b></td>
    </tr>
    <tr>
        <td colspan="7" ><b>Descuentos a ex-asociados</b></td>
    </tr>
    <tr>
        <td>Cant. ex-asociados</td>
        <td style="text-align: center;"><?php echo $modelAportesLiquidados; ?></td>
        <td>Total empleado</td>
        <td style="text-align: right;"><?php  echo number_format($totalMontoAporteLiquidados->aporte_asociado, 2, ',', '.')?> Bs.</td>
        <td>Total patronal</td>
        <td style="text-align: right;"><?php  echo number_format($totalMontoAporteLiquidados->aporte_patrono, 2, ',', '.')?> Bs.</td>
        <td style="text-align: right;"><b><?php echo number_format($totalMontoAporteLiquidados->aporte_asociado + $totalMontoAporteLiquidados->aporte_patrono, 2, ',', '.') ?> Bs.</b></td>
    </tr>
    <tr>
        <td colspan="7" ><b>Descuentos a no asociados</b></td>
    </tr>
    <tr>
        <td>Cant. no asociados</td>
        <td style="text-align: center;"><?php echo $modelAportesTotalDiferidos; ?></td>
        <td>Total empleado</td>
        <td style="text-align: right;"><?php  echo number_format($totalMontoAporteDiferidos->aporte_asociado, 2, ',', '.')?> Bs.</td>
        <td>Total patronal</td>
        <td style="text-align: right;"><?php  echo number_format($totalMontoAporteDiferidos->aporte_patrono, 2, ',', '.')?> Bs.</td>
        <td style="text-align: right;"><b><?php echo number_format($totalMontoAporteDiferidos->aporte_asociado + $totalMontoAporteDiferidos->aporte_patrono, 2, ',', '.')?> Bs.</td>
    </tr>
    <tr>
        <td><b>Total de trabajadores</b></td>
        <td><b><?php echo $totalAportantes + $modelAportesTotalDiferidos + $modelAportesLiquidados?></b></td>
        <td><b>Total carga por empleado</b></td>
        <td style="text-align: right;"><b><?php  echo number_format(($totalMontoAporteActivo->aporte_asociado + $totalMontoAporteLiquidados->aporte_asociado + $totalMontoAporteDiferidos->aporte_asociado), 2, ',', '.')?> Bs.</b></td>
        <td><b>Total carga por patrono</b></td>
        <td style="text-align: right;"><b><?php  echo number_format(($totalMontoAporteActivo->aporte_patrono + $totalMontoAporteLiquidados->aporte_patrono + $totalMontoAporteDiferidos->aporte_patrono), 2, ',', '.')?> Bs.</b></td>
        <td   style="text-align: right;"><b><?php  echo number_format(($totalMontoAporteActivo->aporte_asociado + $totalMontoAporteLiquidados->aporte_asociado + $totalMontoAporteDiferidos->aporte_asociado + $totalMontoAporteActivo->aporte_patrono + $totalMontoAporteLiquidados->aporte_patrono + $totalMontoAporteDiferidos->aporte_patrono), 2, ',', '.')?> Bs.</b></td>
    </tr>
</table>
<?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id' => 'form-pago',
    'type' => 'horizontal',
    'enableAjaxValidation' => false,
    // 'htmlOptions' => array('onsubmit' => 'activar_barra();'),
)); ?>
    <h3 style="text-align: center">Información del pago</h3>
    <div class="metodo_pago" style="display: none;">
        <div class="alert">
            <button type="button" class="close" data-dismiss="alert">&times;</button>
            <strong>Debe seleccionar el metodo de distribución del pago faltante.</strong>
        </div>
    </div>
    <?= $this->renderPartial('formulario_pago', array(
        'form' => $form,
        'model' => $model,
        'modelComprobantePago' => $modelComprobantePago,
    )) ?>
    <div class="metodo_pago" style="display: none;">
        <?= $form->radioButtonListRow($model, 'metodo_pago', MetodoPago::getAll(), array('name' => 'metodos_pago')); ?>
    </div>
    <div class="form-actions">
        <?= CHtml::link('Cancelar', Yii::app()->createUrl('/aportes/datosTxtIntegrado/adminAO'), array('class' => 'btn btn-danger')); ?>
        <button type="button" id="btn_pagar" class="btn btn-success">Pagar</button>
    </div>
    <div class="metodo_pago" style="display: none;">
        <div class="row">
            <div id="mensaje_distribucion" class="span12" style="display: none;">
                <div class="alert alert-danger">
                    <button type="button" class="close" data-dismiss="alert">&times;</button>
                    <strong id="mensaje"></strong>
                </div>
            </div>
            <div class="span12">
                <h4 class="text-center">Consolidado asociados diferidos</h4>
                <br>
                <table class="table">
                    <thead>
                        <tr>
                            <th style="text-align: center; width: 25%;">Cant. Asociados activos</th>
                            <th style="text-align: center; width: 25%;">Total asociados activos</th>
                            <th style="text-align: center; width: 25%;">Monto pagado</th>
                            <th style="text-align: center; width: 25%;">Diferencia de pago</th>
                        </tr>
                    </thead>
                    <tr>
                        <td style="text-align: center;"><?= $totalAportantes ?></td>
                        <td style="text-align: center;"><?= Yii::app()->format->number($totalMontoAporteActivo->aporte_asociado + $totalMontoAporteActivo->aporte_patrono) ?></td>
                        <td id="resumen_monto_pagado" style="text-align: center;">0,00</td>
                        <td id="resumen_diferencia_pago" style="text-align: center;">0,00</td>
                    </tr>
                </table>
                <table class="table">
                    <thead>
                        <tr>
                            <th colspan="6" style="text-align: center;">Distribución</th>
                        </tr>
                    </thead>
                    <tr>
                        <th style="text-align: center; width: 17.66%;">Cant. Asoc. Seleccionados</th>
                        <th style="text-align: center; width: 16.66%;">Total aporte patrono</th>
                        <th style="text-align: center; width: 16.66%;">Total aporte socio</th>
                        <th style="text-align: center; width: 16.66%;">Total aporte</th>
                        <th style="text-align: center; width: 16.66%;" title="Total aporte - Diferencia de pago">Aporte pagado a distribuir</th>
                        <th style="text-align: center; width: 16.66%;" title="Total aporte - Aporte pagado a distribuir">Aporte pendiente a distribuir</th>
                    </tr>
                    <tr>
                        <td id="cant_aportes" style="text-align: center;">0</td>
                        <td id="aporte_patrono" style="text-align: center;">0,00</td>
                        <td id="aporte_asociado" style="text-align: center;">0,00</td>
                        <td id="total_aportes" style="text-align: center;">0,00</td>
                        <th id="aporte_pagado" style="text-align: center;">0,00</th>
                        <th id="aporte_pendiente" style="text-align: center;">0,00</th>
                    </tr>
                </table>
            </div>
        </div>
    </div>
    <input type="hidden" id="asociados_seleccionados" name="asociados" value="[]" data-url="<?= Yii::app()->createUrl('aportes/datosTxtIntegrado/consolidado') ?>" data-resumen="<?= Yii::app()->createUrl('aportes/datosTxtIntegrado/resumen') ?>" data-nomina="<?= $model->id ?>">
    <div class="row" id="asociados_activos" style="display: none;">
        <div class="span12">
            <h4 class="text-center">Asociados activos</h4>
            <?php $this->widget('ext.selgridview.BootSelGridView', array(
                'id' => 'asociados',
                'filter' => $modelAportes,
                'selectableRows' => 100,
                'dataProvider' => $modelAportes->searchV($model->id),
                'selectionChanged' => 'addAsociado',
                'columns' => array(
                    array(
                        'class' => 'CCheckBoxColumn',
                        'value' => '$data->id',
                        'htmlOptions' => array('style' => 'width: 1%;'),
                    ),
                    array(
                        'name' => 'cedula',
                        'value' => '$data->idAsociado->cedula',
                        'htmlOptions' => array('style' => 'width: 15%;'),
                    ),
                    array(
                        'name' => 'nombre_completo',
                        'value' => '$data->getNombreCompleto()',
                        'htmlOptions' => array('style' => 'width: 35%;'),
                    ),
                    array(
                        'name' => 'aporte_patrono',
                        'value' => 'number_format($data->aporte_patrono,2,",", ".")',
                        'htmlOptions' => array('style' => 'text-align: right; width: 11%;'),
                    ),
                    array(
                        'name' => 'aporte_asociado',
                        'value' => 'number_format($data->aporte_asociado,2,",", ".")',
                        'htmlOptions' => array('style' => 'text-align: right; width: 12%;'),
                    ),
                    array(
                        'name' => 'aporte_total',
                        'value' => '$data->total_aporte',
                        'htmlOptions' => array('style' => 'width: 9%;text-align: right'),
                        'filter' => false,
                    ),
                ),
            )) ?>
        </div>
    </div>
<?php $this->endWidget(); ?>





<?php /*
Yii::import('application.modules.configuracion.models.*',true);
if (ConfContable::config('CONFCONTABLE')=='SI'){
?>
<h4 style="text-align: center">Detalles del comprobante</h4>
<table class="table table-striped table-hover ">
    <tr>
        <td><b>Fecha Compr.<b/></td>
        <td><b>N° Comp<b/></td>
        <td><b>Descripción<b/></td>
        <td><b>Estatus</b></td>
    </tr>
    <tr>
        <td><?php echo date('d-m-Y'); ?></td>
        <td></td>
        <td><?php echo $model->descripcion.', segun archivo '.$model->nombre_archivo;  ?></td>
        <td>CONTABILIZADO</td>
    </tr>
</table>
<h4  style="text-align: center">Movimientos</h4>
<table class="table table-striped table-hover ">
    <tr>
        <td><b>Escenario<b/></td>
        <td><b>Cód. cuenta<b/></td>
        <td><b>Descripción<b/></td>
        <td><b>Fecha Ref<b/></td>
        <td><b>Referencia</b></td>
        <td style="text-align:right"><b>Monto Debe</b></td>
        <td style="text-align:right"><b>Monto Haber</b></td>
    </tr>
    <?php
    Yii::import('application.modules.contable.models.*',true);
    $montod=0;
    $montoh=0;
    //trae los escenarios para ese txt
    $montosaportes= VistaNominaAportes::model()->findAll('id_txt=:txt ',array(':txt'=>$model->id));
    $escenarios='';
    foreach ($montosaportes as $montos):
    $escenarios.="'".$montos->escenario."',";
    if ($montos === end($montosaportes)) {
    $escenarios.="'".$montos->escenario."'";
    }
    endforeach;

    if (ConfContable::config('CONFUNIDAD')=='SI'){
    $asientocontable= VswParametrosContables::model()->findAllBySql("SELECT * FROM contable.vsw_parametros_contables WHERE id_escenario=3 and id_unidad=1 and escenario in ($escenarios)
    UNION
    SELECT * FROM contable.vsw_parametros_contables WHERE id_escenario=3 and valor='6'
    ORDER BY 2, 1, 9;");
    }else {
    $asientocontable= VswParametrosContables::model()->findAll("id_escenario=3 and escenario in ($escenarios)  and id_unidad is null");
    }
    foreach ($asientocontable as $contable):
    $fecha= date('d-m-Y');
    $montos= VistaNominaAportes::model()->findBySql('select '.$contable->monto.' as aporte from retenciones.vista_nomina_aportes where id_txt='.$model->id.' and escenario in ('.$contable->clave.')');
    $montom= number_format($montos->aporte,2,",",".");
    $montov='0,00';
    echo "<tr>
        <td>$contable->escenario &nbsp;</td>
        <td>$contable->codigo_cuenta &nbsp; $contable->descripcion_cuenta</td>
        <td>$contable->descripcion</td>
        <td>$fecha</td>
        <td></td>";
        if ($contable->naturaleza==1){
        echo "<td style='text-align:right'> $montom </td>
        <td style='text-align:right'></td>";
        $montod+=$montos->aporte;
        }else{
        echo "<td style='text-align:right'> </td>
        <td style='text-align:right'> $montom </td>";
        $montoh+=$montos->aporte;
        }
        endforeach;
        $diferencia=$montoh-$montod;
        ?>
    </table>
</table>
<table width="100%">
    <tr>
        <td colspan="5" align="right" width="90%"><b>Sub Totales </b></td>
        <td width="6%"></td>
        <td align="right"><b><?php echo number_format($montod,2,",","."); ?></b></td>
        <td></td>
        <td align="right"><b><?php echo number_format($montoh,2,",","."); ?></b></td>
        <td></td>
    </tr>
    <tr>
        <td colspan="5" align="right" width="70%"><b>Diferencia:</b></td>
        <td></td>
        <td align="right"><font color="blue"><b><?php echo number_format($diferencia,2,",","."); ?></b></font></td>
        <td width="6%"></td>
    </tr>
</table>
<?php } else {}*/?>
