<?php
date_default_timezone_set($_SESSION["zona_horaria"]);
setlocale(LC_ALL,"es_ES@euro","es_ES","esp");
$fecha = date("d-m-Y");
$fechaa = date("d-m-Y");
?>
<input type="hidden" id="moneda" value="<?php echo Session::get('moneda'); ?>"/>
<input type="hidden" id="tribAcr" value="<?php echo Session::get('tribAcr'); ?>"/>
<input type="hidden" id="diAcr" value="<?php echo Session::get('diAcr'); ?>"/>
<style>
/* === VARIABLES CSS === */
:root {
    --primary-color: #5664d2;
    --success-color: #1bc943;
    --warning-color: #f4a100;
    --danger-color: #e74c3c;
    --info-color: #3498db;
    --dark-color: #2c3e50;
    --light-bg: #f8f9fa;
    --card-shadow: 0 4px 20px rgba(0,0,0,0.05);
    --border-radius: 12px;
    --transition: all 0.3s ease;
}

/* === HEADER MODERN === */
.page-titles-modern {
    background: linear-gradient(135deg, var(--primary-color) 0%, #667eea 100%);
    padding: 1.5rem 2rem;
    border-radius: var(--border-radius);
    margin-bottom: 2rem;
    color: white;
    box-shadow: var(--card-shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.page-titles-modern h4 {
    color: white;
    font-weight: 600;
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}

.breadcrumb-modern {
    background: rgba(255, 255, 255, 0.2);
    padding: 0.4rem 1rem;
    border-radius: 20px;
    display: inline-block;
    font-size: 0.9rem;
}

.breadcrumb-modern .breadcrumb-item, .breadcrumb-modern a {
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    transition: color 0.2s;
}

.breadcrumb-modern a:hover {
    color: white;
    text-decoration: underline;
}

.breadcrumb-modern .breadcrumb-item.active {
    color: white;
    font-weight: 500;
}

/* === STATS CONTAINER (GRID) === */
.stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--card-shadow);
    display: flex;
    align-items: center;
    border-bottom: 4px solid transparent;
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 15px rgba(0,0,0,0.1);
}

.stat-icon-wrapper {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    margin-right: 1rem;
    flex-shrink: 0;
}

.stat-content h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0;
    color: #333;
}

.stat-content h6 {
    color: #8898aa;
    font-size: 0.85rem;
    margin-bottom: 0;
    font-weight: 500;
}

/* Variantes de Stats */
.stat-warning { border-color: var(--warning-color); }
.stat-warning .stat-icon-wrapper { background: rgba(244, 161, 0, 0.1); color: var(--warning-color); }

.stat-success { border-color: var(--success-color); }
.stat-success .stat-icon-wrapper { background: rgba(27, 201, 67, 0.1); color: var(--success-color); }

.stat-info { border-color: var(--info-color); }
.stat-info .stat-icon-wrapper { background: rgba(52, 152, 219, 0.1); color: var(--info-color); }

.stat-danger { border-color: var(--danger-color); }
.stat-danger .stat-icon-wrapper { background: rgba(231, 76, 60, 0.1); color: var(--danger-color); }

/* === FILTERS CARD === */
.filters-card {
    background: white;
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--card-shadow);
    margin-bottom: 2rem;
}

.form-group-modern label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 0.5rem;
    display: block;
}

.form-control-modern {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 0.6rem 1rem;
    font-size: 0.95rem;
    height: 45px;
    display: flex;
    align-items: center;
}

/* === TABLE MODERN === */
.table-card {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    overflow: hidden;
}

.table-responsive-modern {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-modern {
    margin-bottom: 0;
}

.table-modern thead {
    background: linear-gradient(135deg, #667eea 0%, var(--primary-color) 100%);
    color: white;
}

.table-modern thead th {
    border: none;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    padding: 1rem;
    white-space: nowrap;
}

.table-modern tbody tr {
    transition: var(--transition);
    border-bottom: 1px solid #f1f3f5;
}

.table-modern tbody tr:hover {
    background-color: #f8f9fa;
    transform: scale(1.01);
}

.table-modern tbody td {
    padding: 1rem;
    vertical-align: middle;
}

/* === SCROLLBAR PERSONALIZADO === */
.table-responsive-modern::-webkit-scrollbar {
    height: 8px;
}

.table-responsive-modern::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.table-responsive-modern::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 10px;
}

.table-responsive-modern::-webkit-scrollbar-thumb:hover {
    background: #667eea;
}

    .animate-in { animation: fadeInUp 0.6s ease; }
    @keyframes fadeInUp {
        from { opacity: 0; transform: translateY(20px); }
        to { opacity: 1; transform: translateY(0); }
    }

    /* === RESPONSIVE STATS (MOBILE) === */
    @media (max-width: 767px) {
        .stats-container {
            grid-template-columns: repeat(2, 1fr);
            gap: 10px;
        }
        .stat-card {
            padding: 15px;
            flex-direction: column;
            text-align: center;
            align-items: center;
            justify-content: center;
        }
        .stat-icon-wrapper {
            margin-right: 0;
            margin-bottom: 10px;
            width: 45px; 
            height: 45px;
            font-size: 1.1rem;
        }
        .stat-content h2 {
            font-size: 1.1rem;
        }
        .stat-content h6 {
            font-size: 0.7rem;
        }

    /* Header Mobile Improvements */
    .page-titles-modern {
        flex-direction: column;
        text-align: center;
        padding: 1.5rem 1rem;
    }
    .page-titles-modern > div {
        width: 100%;
        margin-bottom: 1rem;
    }
    .page-titles-modern .btn-group {
        width: 100%;
        margin-bottom: 0;
    }
    .page-titles-modern .btn {
        flex: 1;
    }
}
</style>

<!-- HEADER -->
<div class="page-titles-modern animate-in">
    <div>
        <h4><i class="fas fa-chart-line mr-2"></i>Reporte de Ventas</h4>
        <div class="breadcrumb-modern">
            <a href="<?php echo URL; ?>informe" class="breadcrumb-item"><i class="fas fa-home mr-1"></i>Informe</a>
            <span class="breadcrumb-item">/</span>
            <span class="breadcrumb-item">Ventas</span>
            <span class="breadcrumb-item active">General</span>
        </div>
    </div>
    <div class="btn-group">
        <button type="button" class="btn btn-light dropdown-toggle font-weight-bold shadow-sm" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            <i class="fas fa-download mr-1"></i> Exportar
        </button>
        <div class="dropdown-menu dropdown-menu-right">
            <a class="dropdown-item" href="javascript:void(0);" id="excel"><i class="fas fa-file-excel text-success mr-2"></i> Excel</a>
            <a class="dropdown-item" href="javascript:void(0);" id="pdf"><i class="fas fa-file-pdf text-danger mr-2"></i> PDF</a>
        </div>
    </div>
</div>

<div class="wrapper wrapper-content animated fadeIn">
    <!-- STATS GRID -->
    <div class="stats-container animate-in">
        <!-- N° Operaciones -->
        <div class="stat-card stat-info">
            <div class="stat-icon-wrapper">
                <i class="fas fa-clipboard-list"></i>
            </div>
            <div class="stat-content">
                <h2 class="ventas-operaciones">0</h2>
                <h6>N° Operaciones</h6>
            </div>
        </div>
        <!-- Total Ventas -->
        <div class="stat-card stat-success">
            <div class="stat-icon-wrapper">
                <i class="fas fa-dollar-sign"></i>
            </div>
            <div class="stat-content">
                <h2 class="ventas-total">0.00</h2>
                <h6>Total Ventas</h6>
            </div>
        </div>
        <!-- Total Facturas -->
        <div class="stat-card stat-warning">
            <div class="stat-icon-wrapper">
                <i class="fas fa-file-invoice"></i>
            </div>
            <div class="stat-content">
                <h2 class="ventas-fe">0.00</h2>
                <h6>Facturas</h6>
            </div>
        </div>
         <!-- Total Boletas -->
         <div class="stat-card stat-warning">
            <div class="stat-icon-wrapper">
                <i class="fas fa-receipt"></i>
            </div>
            <div class="stat-content">
                <h2 class="ventas-bv">0.00</h2>
                <h6>Boletas</h6>
            </div>
        </div>
        <!-- Total Notas Venta -->
        <div class="stat-card stat-warning">
            <div class="stat-icon-wrapper">
                <i class="fas fa-sticky-note"></i>
            </div>
            <div class="stat-content">
                <h2 class="ventas-nv">0.00</h2>
                <h6>Notas Venta</h6>
            </div>
        </div>
        <!-- Anulados -->
        <div class="stat-card stat-danger">
            <div class="stat-icon-wrapper">
                <i class="fas fa-ban"></i>
            </div>
            <div class="stat-content">
                <h2 class="ventas-an">0.00</h2>
                <h6>Anulados</h6>
            </div>
        </div>
    </div>

    <!-- FILTERS -->
    <div class="filters-card animate-in">
        <div class="row align-items-end">
             <div class="col-lg-3 col-md-6 mb-3">
                <div class="form-group-modern">
                    <label>Rango de Fechas</label>
                    <div class="input-group">
                        <input type="text" class="form-control form-control-modern text-center" name="start" id="start" value="<?php echo ''.$fechaa; ?>" autocomplete="off" placeholder="Inicio"/>
                        <div class="input-group-append">
                             <span class="input-group-text bg-light border-0">al</span>
                        </div>
                        <input type="text" class="form-control form-control-modern text-center" name="end" id="end" value="<?php echo $fecha; ?>" autocomplete="off" placeholder="Fin"/>
                    </div>
                </div>
            </div>
             <div class="col-lg-2 col-md-6 mb-3">
                <div class="form-group-modern">
                    <label>Canal Venta</label>
                    <select class="selectpicker form-control" name="tipo_ped" id="tipo_ped" data-style="btn-white border" data-live-search="true" autocomplete="off" data-size="5" title="Mostrar Todo">
                        <option value="%" selected>Mostrar Todo</option>
                        
                            <?php foreach($this->TipoPedido as $key => $value): ?>
                                <option value="<?php echo $value['id_tipo_pedido']; ?>"><?php echo $value['descripcion']; ?></option>
                            <?php endforeach; ?>
                        
                    </select>
                </div>
            </div>
            <div class="col-lg-3 col-md-6 mb-3">
                <div class="form-group-modern">
                    <label>Cliente</label>
                    <select class="selectpicker form-control" name="cliente" id="cliente" data-style="btn-white border" data-live-search="true" autocomplete="off" data-size="5" title="Mostrar Todo">
                        <option value="%" selected>Mostrar Todo</option>
                        
                            <?php foreach($this->Cliente as $key => $value): ?>
                                <option value="<?php echo $value['id_cliente']; ?>"><?php echo $value['nombre']; ?></option>
                            <?php endforeach; ?>
                        
                    </select>
                </div>
            </div>
            <div class="col-lg-2 col-md-6 mb-3">
                <div class="form-group-modern">
                     <label>Tipo Comprobante</label>
                     <select class="selectpicker form-control" name="tipo_doc" id="tipo_doc" data-style="btn-white border" data-live-search="true" autocomplete="off" data-size="5" title="Mostrar Todo">
                        <option value="%" selected>Mostrar Todo</option>
                        
                            <?php foreach($this->TipoDocumento as $key => $value): ?>
                                <option value="<?php echo $value['id_tipo_doc']; ?>"><?php echo $value['descripcion']; ?></option>
                            <?php endforeach; ?>
                        
                     </select>
                </div>
            </div>
            <div class="col-lg-2 col-md-6 mb-3">
                <div class="form-group-modern">
                    <label>Estado</label>
                    <select class="selectpicker form-control" name="estado" id="estado" data-style="btn-white border" autocomplete="off" title="Mostrar Todo">
                        <option value="%" selected>Mostrar Todo</option>
                        <option value="a">APROBADO</option>
                        <option value="i">ANULADO</option>
                    </select>
                </div>
            </div>
        </div>
    </div>

    <!-- TABLE -->
    <div class="table-card animate-in">
        <div class="table-responsive-modern">
            <table id="table" class="table table-modern" width="100%">
                <thead>
                    <tr>
                        <th width="15%">Fecha</th>
                        <th width="10%">Caja</th>
                        <th width="20%">Cliente</th>
                        <th width="15%">Documento</th>                               
                        <th width="10%">Canal</th>   
                        <th width="10%">Pago</th>                            
                        <th class="text-right" width="10%">Total</th>
                        <th width="5%" class="text-center">Est</th>
                        <th class="text-right" width="5%">Acc</th>
                    </tr>
                </thead>
                <tbody class="tb-st"></tbody>
            </table>
        </div>
    </div>
</div>
<div class="modal inmodal" id="detalle" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content animated bounceInRight">
            <div class="modal-header" style="background: linear-gradient(135deg, var(--primary-color) 0%, #667eea 100%); color: white; border-radius: 12px 12px 0 0;">
                <h5 class="modal-title title-detalle" style="font-weight: 600;">Detalle</h5>
                <button type="button" class="close text-white" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Cerrar</span></button>
            </div>
            <div class="modal-body p-0">
                <div class="table-responsive">
                    <table class="table table-modern m-b-0">
                        <thead class="table-head">
                            <tr>
                                <th width="10%">Cant.</th>
                                <th width="60%">Producto</th>
                                <th width="15%">P.U.</th>
                                <th width="15%" class="text-right">Total</th>
                            </tr>
                        </thead>
                    </table>
                    <div class="table-responsive scroll_detalle">
                        <table class="table table-modern table-hover">
                            <tbody class="tb-st" id="lista_pedidos"></tbody>
                        </table>
                    </div>
                    <table class="table m-b-0">
                        <tfooter>
                            <tr>
                                <td width="85%" class="text-right">Total consumido:</td>
                                <td class="total-consumido text-right"></td>
                            </tr>
                            <tr>
                                <td width="85%" class="text-right text-info">Comision delivery:</td>
                                <td class="total-comision text-right"></td></tr>
                            <tr>
                                <td width="85%" class="text-right text-danger">Descuento:</td>
                                <td class="total-descuento text-right"></td></tr>
                            <tr>
                                <td width="80%" class="text-right text-success">Total facturado:</td>
                                <td class="total-facturado text-right"></td></tr>
                        </tfooter>
                    </table>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Cerrar</button>
            </div>
        </div>
    </div>
</div>
