<h3 class="text-center">Detalles del comprobante</h3>
<div>
    <?= CHtml::link("<i class='icon-print'></i> Descargar comprobante contable", CHtml::normalizeUrl(['ComprobantePdf', 'id_comprobante' => $model->id]), ['class' => 'btn']); ?>
</div>
<?php
$this->widget('bootstrap.widgets.TbGridView', [
    'id' => 'comprobante-grid',
    'enableSorting' => false,
    'dataProvider' => new CActiveDataProvider('Comprobante', [
        'criteria' => [
            'condition' => 'id='.$model->id.'',
        ],
        'pagination' => [
            'pageSize' => 10,
        ],
    ]),
    'columns' => [
        [
            'header' => 'Fecha Compr.',
            'name' => 'fecha_comprobante',
            'value' => 'date("d-m-Y",strtotime($data->fecha_comprobante))',
            'htmlOptions' => ['style' => 'text-align: justify'],
        ],
        [
            'header' => 'N° Comp',
            'name' => 'numero',
            'value' => '$data->num_comprobante',
            'htmlOptions' => ['style' => 'text-align: justify'],
        ],
        [
            'header' => 'Descripción',
            'name' => 'descripcion',
            'value' => '$data->descripcion',
        ],
        [
            'header' => 'Estatus',
            'name' => 'status',
            'value' => '$data->estatus->descripcion',
            'htmlOptions' => ['style' => 'text-align: justify'],
        ],
        [
            'header' => 'Usuario creación',
            'name' => 'id_usuario',
            'value' => '$data->usuario->username',
            'htmlOptions' => ['style' => 'text-align: justify'],
        ],
        [
            'header' => 'Motivo anulación',
            'name' => 'observacion_anulacion',
            'htmlOptions' => ['style' => 'text-align: justify'],
            'visible' => $model->status == 3,
        ],
        [
            'header' => 'Fecha anulación',
            'name' => 'fecha_anulacion',
            'type' => 'datetime',
            'htmlOptions' => ['style' => 'text-align: justify'],
            'visible' => $model->status == 3,
        ],
        [
            'header' => 'Usuario anulación',
            'name' => 'usuario_anulacion',
            'value' => '$data->usuario2->nombres',
            'htmlOptions' => ['style' => 'text-align: justify'],
            'visible' => $model->status == 3,
        ],
    ],
]); ?>
<br>
<h3 class="text-center">Movimientos</h3>
<?php $this->widget('bootstrap.widgets.TbGridView', [
    'id' => 'detalle-comprobante-grid',
    'enableSorting' => false,
    'dataProvider' => $model->searchDetalleComprobante(),
    'columns' => [
        [
            'header' => 'Cód. cuenta',
            'name' => 'id_cuenta',
            'value' => '$data["codigo_cuenta"]',
        ],
        [
            'header' => 'Descripción',
            'name' => 'descripcion',
            'value' => '$data["descripcion"]',
        ],
        [
            'header' => 'Fecha Ref',
            'name' => 'fecha_referencia',
            'value' => '$data["fecha_referencia"]',
            'type' => 'date',
            'htmlOptions' => ['style' => 'text-align: justify; width: 8%;'],
        ],
        [
            'header' => 'Referencia',
            'name' => 'referencia',
            'value' => '$data["referencia"]',
            'htmlOptions' => ['style' => 'text-align: justify; width: 8%;'],
        ],
        [
            'header' => 'Monto Debe',
            'name' => 'monto_debe',
            'value' => '$data["monto_debe"]',
            'type' => 'number',
            'htmlOptions' => ['style' => 'text-align: right'],
        ],
        [
            'header' => 'Monto Haber',
            'name' => 'monto_haber',
            'value' => '$data["monto_haber"]',
            'type' => 'number',
            'htmlOptions' => ['style' => 'text-align: right'],
        ],
    ],
]); ?>
<?php $dif = DiferenciaComprobante::model()->find('clv_comprobante='.$_GET['id']); ?>
<?php if (isset($dif)): ?>
<table width="100%">
    <tr>
        <td colspan="5" align="right" width="90%"><b>Sub Totales </b></td>
        <td width="6%"></td>
        <td align="right"><b><?= Yii::app()->format->number($dif->monto_d); ?></b></td>
        <td></td>
        <td align="right"><b><?= Yii::app()->format->number($dif->monto_h); ?></b></td>
        <td></td>
    </tr>
    <tr>
        <td colspan="5" align="right" width="70%"><b>Diferencia:</b></td>
        <td></td>
        <?php if (abs($dif->diferencia) == 0): ?>
        <td align="right">
            <font color="blue"><b><?= Yii::app()->format->number($dif->diferencia); ?></b></font>
        </td>
        <?php else: ?>
        <td align="right">
            <font color="red"><b><?= Yii::app()->format->number($dif->diferencia); ?></b></font>
        </td>
        <?php endif; ?>
        <td width="6%"></td>
    </tr>
</table>
<br>
<?php endif;
