<?php $__env->startSection('content'); ?>
<div class="bg-body-light">
    <div class="content content-full">
        <div class="d-flex flex-column flex-sm-row justify-content-sm-between align-items-sm-center py-2">
            <div class="flex-grow-1">
                <h1 class="h3 fw-bold mb-2">
                    Expediente de Contrato
                </h1>
                <h2 class="fs-base lh-base fw-medium text-muted mb-0">
                    Visualizando el contrato maestro <span class="text-primary fw-bold">#<?php echo e($contrato->id); ?></span>
                </h2>
            </div>
            <div class="flex-shrink-0 mt-3 mt-sm-0 ms-sm-3">
                <span class="badge bg-<?php echo e($contrato->estado_badge); ?> px-3 py-2 fs-6">
                    <?php echo e(strtoupper($contrato->estado_texto)); ?>

                </span>
            </div>
        </div>
    </div>
</div>

<div class="content">
    
    <?php if(session('success')): ?>
        <div class="alert alert-success d-flex align-items-center" role="alert">
            <i class="fa fa-check-circle me-2"></i>
            <p class="mb-0"><?php echo e(session('success')); ?></p>
            <button type="button" class="btn-close ms-auto" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    <?php endif; ?>

<div class="row">
    
    <div class="col-6 col-md-4">
        <div class="block block-rounded block-link-shadow text-center">
            <div class="block-content block-content-full">
                <div class="fs-sm fw-semibold text-uppercase text-muted">Inversión Total</div>
                <div class="fs-2 fw-bold text-dark">$us <?php echo e(number_format($contrato->total, 2)); ?></div>
            </div>
        </div>
    </div>
    
    
    <div class="col-6 col-md-4">
        <div class="block block-rounded block-link-shadow text-center">
            <div class="block-content block-content-full border-start">
                <div class="fs-sm fw-semibold text-uppercase text-success">Total Pagado</div>
                <div class="fs-2 fw-bold text-success">$us <?php echo e(number_format($totalPagado, 2)); ?></div>
            </div>
        </div>
    </div>
    
    
    <div class="col-12 col-md-4">
        <div class="block block-rounded block-link-shadow text-center">
            <div class="block-content block-content-full border-start">
                <div class="fs-sm fw-semibold text-uppercase text-<?php echo e($saldo > 0 ? 'danger' : 'success'); ?>">Saldo Pendiente</div>
                <div class="fs-2 fw-bold text-<?php echo e($saldo > 0 ? 'danger' : 'success'); ?>">$us <?php echo e(number_format($saldo, 2)); ?></div>
            </div>
        </div>
    </div>
</div>

    <div class="row">
        
        <div class="col-xl-7">
            <div class="block block-rounded">
                <div class="block-header block-header-default">
                    <h3 class="block-title">
                        <i class="fa fa-file-invoice-dollar me-1 text-muted"></i> Información Financiera
                    </h3>
                </div>
                <div class="block-content p-0">
                    <table class="table table-vcenter table-striped table-sm fs-sm mb-0">
                        <tbody>
                            <tr>
                                <td class="fw-semibold bg-body-light" style="width: 35%;">Fecha de Emisión</td>
                                <td><?php echo e(\App\Helpers\FechaHelper::bdToLocal($contrato->fecha)); ?></td>
                            </tr>
                            <tr>
                                <td class="fw-semibold bg-body-light">Cliente Titular</td>
                                <td>
                                    <div class="fw-bold">
                                        <a href="<?php echo e(route('clientes.show', $contrato->idcliente)); ?>" class="link-fx"><?php echo e($contrato->cliente->nombre ?? '—'); ?></a>
                                    </div>
                                    <div class="text-muted fs-xs">C.I.: <?php echo e($contrato->cliente->ci ?? 'N/A'); ?></div>
                                </td>
                            </tr>
                            <?php $__currentLoopData = $codeudores; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cod): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td class="fw-semibold bg-body-light">Codeudor</td>
                                <td>
                                    <div class="fw-semibold text-dark"><?php echo e($cod->nombre); ?></div>
                                    <div class="text-muted fs-xs">C.I.: <?php echo e($cod->ci); ?></div>
                                </td>
                            </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td class="fw-semibold bg-body-light">Plan de Pago</td>
                                <td><span class="badge bg-info-light text-info"><?php echo e($contrato->plan_pago_texto); ?></span></td>
                            </tr>
                            <tr>
                                <td class="fw-semibold bg-body-light">Monto Subtotal</td>
                                <td>$us <?php echo e(number_format($contrato->subtotal, 2)); ?></td>
                            </tr>
                            <tr class="table-info">
                                <td class="fw-bold">TOTAL CONTRATO</td>
                                <td class="fw-bold fs-base text-dark">$us <?php echo e(number_format($contrato->total, 2)); ?></td>
                            </tr>
                            <?php if($contrato->numcuotas > 1): ?>
                            <tr>
                                <td class="fw-semibold bg-body-light text-primary">Detalle de Cuotas</td>
                                <td>
                                    <div class="row py-2">
                                        <div class="col-4 border-end">
                                            <div class="fs-xs text-muted text-uppercase">Inicial</div>
                                            <div class="fw-bold">$us <?php echo e(number_format($contrato->cuotainicial, 2)); ?></div>
                                        </div>
                                        <div class="col-4 border-end">
                                            <div class="fs-xs text-muted text-uppercase">Cantidad</div>
                                            <div class="fw-bold"><?php echo e($contrato->numcuotas); ?></div>
                                        </div>
                                        <div class="col-4">
                                            <div class="fs-xs text-muted text-uppercase">Mensual</div>
                                            <div class="fw-bold">$us <?php echo e(number_format($contrato->cuotamensual, 2)); ?></div>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <?php endif; ?>
                            <tr>
                                <td class="fw-semibold bg-body-light">Vendedor Asignado</td>
                                <td><i class="fa fa-user-tie me-1 opacity-50"></i> <?php echo e($contrato->vendedor->nombre ?? '—'); ?></td>
                            </tr>
                            <tr>
                                <td class="fw-semibold bg-body-light">Observaciones</td>
                                <td class="font-italic text-muted">
                                    <?php echo e($contrato->obsanul ?: $contrato->observaciones ?: 'Sin observaciones registradas.'); ?>

                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        
        <div class="col-xl-5">
            <div class="block block-rounded">
                <div class="block-header block-header-default">
                    <h3 class="block-title">
                        <i class="fa fa-map-marked-alt me-1 text-muted"></i> Ubicación del Inmueble
                    </h3>
                </div>
                <div class="block-content p-0">
                    <table class="table table-vcenter table-sm fs-sm mb-0">
                        <tbody>
                            <tr>
                                <td class="fw-semibold bg-body-light" style="width: 40%;">ID Lote</td>
                                <td class="fw-bold">
                                    <a href="<?php echo e(route('lotes.show', $contrato->idlote)); ?>" class="link-fx text-primary">#<?php echo e($contrato->idlote); ?></a>
                                </td>
                            </tr>
                            <tr>
                                <td class="fw-semibold bg-body-light">Urbanización</td>
                                <td><?php echo e($contrato->urbanizacionRel->nombre ?? $contrato->urbanizacion); ?></td>
                            </tr>
                            <tr>
                                <td class="fw-semibold bg-body-light">Distrito / Zona</td>
                                <td><?php echo e($contrato->distritoRel->nombre ?? $contrato->distrito); ?></td>
                            </tr>
                            <tr>
                                <td class="fw-semibold bg-body-light">Manzano / Lote</td>
                                <td>
                                    <span class="badge bg-dark">Mzo: <?php echo e($contrato->manzano); ?></span>
                                    <span class="badge bg-primary">Lote: <?php echo e($contrato->lote); ?></span>
                                </td>
                            </tr>
                            <tr>
                                <td class="fw-semibold bg-body-light">Superficie</td>
                                <td class="fw-bold"><?php echo e(number_format($contrato->superficie, 2)); ?> m²</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>

            <div class="d-none d-xl-block">
                <div class="block block-rounded">
                    <div class="block-content">
                        <div class="row g-2 mb-3">
                            <div class="col-12">
                                <a href="<?php echo e(route('extractos.show', $contrato->idcliente)); ?>" class="btn btn-alt-info w-100">
                                    <i class="fa fa-list-ol me-1"></i> Gestionar Extracto
                                </a>
                            </div>
                            <div class="col-6">
                                <a href="<?php echo e(route('contratos.pdf', $contrato->id)); ?>" target="_blank" class="btn btn-alt-secondary w-100">
                                    <i class="fa fa-print me-1"></i> Imprimir
                                </a>
                            </div>
                            <div class="col-6">
                                <a href="<?php echo e(route('contratos.registro-pdf', $contrato->id)); ?>" target="_blank" class="btn btn-alt-secondary w-100">
                                    <i class="fa fa-file-pdf me-1"></i> Registro
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    
    <div class="block block-rounded">
        <div class="block-header block-header-default">
            <h3 class="block-title">
                <i class="fa fa-history me-1 text-muted"></i> Últimos Movimientos
            </h3>
            <div class="block-options">
                <a href="<?php echo e(route('extractos.show', $contrato->idcliente)); ?>" class="btn btn-sm btn-alt-secondary">
                    Ver Extracto Completo
                </a>
            </div>
        </div>
        <div class="block-content p-0">
            <div class="table-responsive">
                <table class="table table-vcenter table-hover table-sm mb-0 fs-sm">
                    <thead class="bg-body-dark">
                        <tr>
                            <th class="text-center" style="width: 80px;">N°</th>
                            <th class="text-center">Vencimiento</th>
                            <th>Descripción</th>
                            <th class="text-end">Cargo</th>
                            <th class="text-end">Abono</th>
                            <th class="text-end">Saldo Acum.</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $acumulado = 0; ?>
                        <?php $__currentLoopData = $extractos; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $e): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php $acumulado += ($e->cargo - $e->abono); ?>
                            <tr class="<?php echo e($e->cargo == $e->abono && $e->abono > 0 ? 'table-success' : ''); ?>">
                                <td class="text-center fw-bold"><?php echo e($e->numcuo); ?></td>
                                <td class="text-center"><?php echo e(\App\Helpers\FechaHelper::bdToLocal($e->fechaven)); ?></td>
                                <td class="fs-xs">
                                    <span class="fw-semibold"><?php echo e($e->titulo); ?></span>
                                </td>
                                <td class="text-end text-danger"><?php echo e(number_format($e->cargo, 2)); ?></td>
                                <td class="text-end text-success"><?php echo e(number_format($e->abono, 2)); ?></td>
                                <td class="text-end fw-bold <?php echo e($acumulado > 0 ? 'text-danger' : 'text-success'); ?>">
                                    <?php echo e(number_format($acumulado, 2)); ?>

                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    
    <div class="d-xl-none mb-4">
        <div class="row g-2">
            <div class="col-6">
                <a href="<?php echo e(route('contratos.index')); ?>" class="btn btn-alt-secondary w-100">
                    <i class="fa fa-arrow-left me-1"></i> Volver
                </a>
            </div>
            <div class="col-6">
                <a href="<?php echo e(route('extractos.index', ['idcontrato' => $contrato->id])); ?>" class="btn btn-alt-info w-100">
                    <i class="fa fa-list me-1"></i> Extracto
                </a>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /var/www/proyect-laravel/cosmos-app/resources/views/contratos/show.blade.php ENDPATH**/ ?>