<!DOCTYPE html>
<html lang="en" class="light-style layout-menu-fixed" dir="ltr" data-theme="theme-default" data-assets-path="../assets/" data-template="vertical-menu-template-free">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
    <title>Existencias</title>
    <meta name="description" content="" />
    <!-- Favicon -->
    <link rel="icon" type="image/x-icon" href="../assets/img/favicon/favicon.ico" />
    <!-- Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link href="https://fonts.googleapis.com/css2?family=Public+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&display=swap" rel="stylesheet" />

    <!-- Icons. Uncomment required icon fonts -->
    <link rel="stylesheet" href="../assets/vendor/fonts/boxicons.css" />

    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.datatables.net/1.10.21/css/dataTables.bootstrap4.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" rel="stylesheet">
    <link rel="stylesheet" href="../css/estilosdetablas.css">
    <link rel="stylesheet" href="../css/botonesfiltros.css">
    <link rel="stylesheet" href="../css/botonexportar.css">


    <!-- Core CSS -->
    <link rel="stylesheet" href="../assets/vendor/css/core.css" class="template-customizer-core-css" />
    <link rel="stylesheet" href="../assets/vendor/css/theme-default.css" class="template-customizer-theme-css" />
    <link rel="stylesheet" href="../assets/css/demo.css" />

    <!-- Vendors CSS -->
    <link rel="stylesheet" href="../assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.css" />

    <link rel="stylesheet" href="../assets/vendor/libs/apex-charts/apex-charts.css" />

    <!-- Page CSS -->

    <!-- Helpers -->
    <script src="../assets/vendor/js/helpers.js"></script>
    <script src="../assets/js/config.js"></script>

    <!-- Animate.css -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css">
</head>
<style>
    /* Estilos personalizados para el botón de cierre */
    .swal2-confirm.swal-close-btn {
        background-color: #009DFF !important;
        color: #fff !important;
        border: none !important;
        padding: 10px 20px !important;
        font-size: 16px !important;
        box-shadow: none !important;
        /* Quita cualquier sombra adicional */
        outline: none !important;
        /* Asegura que no aparezca borde negro */
        border-radius: 5px !important;
    }

    .swal2-confirm.swal-close-btn:hover {
        background-color: #007ecc !important;
        color: #fff !important;
        border: none !important;
    }

    .custom-filter {
        margin-right: 8px;
        /* Adjust the spacing as needed */
    }

    .btn1 {
        border: 2px solid #e8fadf !important;
        background-color: #e8fadf !important;
        color: #71dd37 !important;
        padding: .330rem .30rem;
        font-size: 1rem;
        line-height: 1.5;
        border-radius: .25rem;
        transition: all 0.3s ease-out;
    }

    .btn1:hover {
        border: 2px solid #71dd37 !important;
        background-color: #e8fadf !important;
        color: #71dd37 !important;
        padding: .330rem .30rem;
        font-size: 1rem;
        line-height: 1.5;
        border-radius: .25rem;
        transform: translateY(-5px) scale(1.005) translateZ(0);
    }

    .btn2 {
        border: 2px solid #ff3e1d !important;
        background-color: #ffe0db !important;
        color: #ff3e1d !important;
        padding: .330rem .30rem;
        font-size: 1rem;
        line-height: 1.5;
        border-radius: .25rem;
        transition: all 0.3s ease-out;
    }

    .btn2:hover {
        border: 2px solid #ff3e1d !important;
        background-color: #ffe0db !important;
        color: #ff3e1d !important;
        padding: .330rem .30rem;
        font-size: 1rem;
        line-height: 1.5;
        border-radius: .25rem;
        transform: translateY(-5px) scale(1.005) translateZ(0);
    }

    .btn3 {
        border: 2px solid #ffab00 !important;
        background-color: #fff2d6 !important;
        color: #ffab00 !important;
        padding: .330rem .30rem;
        font-size: 1rem;
        line-height: 1.5;
        border-radius: .25rem;
        transition: all 0.3s ease-out;
    }

    .btn3:hover {
        border: 2px solid #ffab00 !important;
        background-color: #fff2d6 !important;
        color: #ffab00 !important;
        padding: .330rem .30rem;
        font-size: 1rem;
        line-height: 1.5;
        border-radius: .25rem;
        transform: translateY(-5px) scale(1.005) translateZ(0);
    }

    .btn4 {
        border: 2px solid #8592a3 !important;
        background-color: #ebeef0 !important;
        color: #8592a3 !important;
        padding: .330rem .30rem;
        font-size: 1rem;
        line-height: 1.5;
        border-radius: .25rem;
        transition: all 0.3s ease-out;
    }

    .btn4:hover {
        border: 2px solid #8592a3 !important;
        background-color: #ebeef0 !important;
        color: #8592a3 !important;
        padding: .330rem .30rem;
        font-size: 1rem;
        line-height: 1.5;
        border-radius: .25rem;
        transform: translateY(-5px) scale(1.005) translateZ(0);
    }

    .btn5 {
        border: 2px solid #009dff !important;
        background-color: #ebf7ff !important;
        color: #009dff !important;
        padding: .330rem .30rem;
        font-size: 1rem;
        line-height: 1.5;
        border-radius: .25rem;
        transition: all 0.3s ease-out;
    }

    .btn5:hover {
        border: 2px solid #009dff !important;
        background-color: #ebf7ff !important;
        color: #009dff !important;
        padding: .330rem .30rem;
        font-size: 1rem;
        line-height: 1.5;
        border-radius: .25rem;
        transform: translateY(-5px) scale(1.005) translateZ(0);
    }

    .btn1:focus {
        outline: none;
        box-shadow: none;
        border: 2px solid #71dd37;
    }

    .btn2:focus {
        outline: none;
        box-shadow: none;
    }

    .btn3:focus {
        outline: none;
        box-shadow: none;
    }

    .btn4:focus {
        outline: none;
        box-shadow: none;
    }

    .btn5:focus {
        outline: none;
        box-shadow: none;
    }

    .btn1.selected {
        background-color: #71dd37 !important;
        color: #fff !important;
        border: 2px solid #71dd37 !important;
    }

    .btn2.selected {
        background-color: #ff3e1d !important;
        color: #ffffff !important;
    }

    .btn3.selected {
        background-color: #ffab00 !important;
        color: #fff !important;
    }

    .btn4.selected {
        background-color: #8592a3 !important;
        color: #fff !important;
    }

    .btn5.selected {
        background-color: #009DFF !important;
        color: #ffffff !important;
    }

    .btn6 {
        border: 2px solid #007ecc !important;
        background-color: #007ecc !important;
        color: #ffffff !important;
        padding: .330rem .30rem;
        font-size: 1rem;
        line-height: 1.5;
        border-radius: .25rem;
        width: 183px;
    }


    .btn6:hover {
        border: 2px solid #005fa3 !important;
        background-color: #005fa3 !important;
        color: #ffffff !important;
        padding: .330rem .30rem;
        font-size: 1rem;
        line-height: 1.5;
        border-radius: .25rem;
    }

    .btn6.selected {
        background-color: #009DFF !important;
        color: #ffffff;
    }

    .btn6:focus {
        outline: none;
        box-shadow: none;
    }

    /* Agregar una clase para el estado activo (al hacer clic) */
    .btn1:active,
    .btn2:active,
    .btn3:active,
    .btn4:active,
    .btn5:active,
    .btn6:active {
        transform: translateY(0px) scale(1) translateZ(0);
        transition: transform 0.2s ease-in-out;
    }

    .wow {
        visibility: hidden;
    }

    .swal-custom-modal {
        z-index: 1050 !important;
        /* Asegura que el modal esté al frente */
    }

    .navbar {
        z-index: 1000 !important;
        /* Baja la barra de búsqueda detrás del modal */
    }

    .navbar-nav {
        position: relative !important;
        z-index: 1 !important;
    }

    .swal2-container {
        z-index: 2000 !important;
        /* Asegura que el fondo oscuro cubra todo */
    }

    .swal2-popup {
        z-index: 2050 !important;
        /* Mantiene el modal por encima del overlay */
    }

    .layout-menu {
        z-index: 1000 !important;
        /* Asegura que el menú quede detrás */
    }
</style>


<body>
    <!-- Layout wrapper -->
    <div class="layout-wrapper layout-content-navbar">
        <div class="layout-container">
            <!-- Menu -->

            <aside id="layout-menu" class="layout-menu menu-vertical menu bg-menu-theme">
                <div class="app-brand demo">
                    <a href="index.html" class="app-brand-link">
                        <span class="app-brand-logo demo">
                            <svg
                                version="1.1"
                                xmlns="http://www.w3.org/2000/svg"
                                xmlns:xlink="http://www.w3.org/1999/xlink"
                                x="0px"
                                y="0px"
                                viewBox="0 0 2000 2000"
                                style="enable-background:new 0 0 2000 2000;"
                                xml:space="preserve"
                                width="100"
                                height="100">
                                <style type="text/css">
                                    .st0 {
                                        display: none;
                                    }

                                    .st1 {
                                        fill: #009DFF;
                                    }
                                </style>
                                <g id="Capa_1" class="st0">
                                    <image style="display:inline;overflow:visible;" width="2550" height="1558" transform="matrix(1 0 0 1 494.3726 289.1373)"></image>
                                </g>
                                <g id="Capa_2">
                                    <g>
                                        <rect x="183.89" y="18.31" class="st1" width="1632.23" height="526.02" />
                                        <polygon class="st1" points="1031.3,1629.99 1031.3,1711.86 1308.44,1711.86 1308.44,1825.3 1031.3,1825.3 1031.3,1907.13 1308.44,1907.13 1308.44,1981.69 691.56,1981.69 691.56,682.4 1308.44,682.4 1308.44,1629.99" />
                                    </g>
                                </g>
                                <g id="Capa_3" class="st0"></g>
                            </svg>
                        </span>
                        <span class="app-brand-text demo menu-text fw-bolder ms-2">Trax</span>
                    </a>

                    <a href="javascript:void(0);" class="layout-menu-toggle menu-link text-large ms-auto d-block d-xl-none">
                        <i class="bx bx-chevron-left bx-sm align-middle"></i>
                    </a>
                </div>

                <div class="menu-inner-shadow"></div>

                <ul class="menu-inner py-1">
                    <!-- Dashboard
            <li class="menu-item active">
              <a href="index.html" class="menu-link">
                <i class="menu-icon tf-icons bx bx-home-circle"></i>
                <div data-i18n="Analytics">Dashboard</div>
              </a>
            </li> -->
                    <!-- Layouts -->
                    <li class="menu-item ">
                        <a href="#" class="menu-link menu-toggle">
                            <i class="menu-icon tf-icons bx bx-layout"></i>
                            <div data-i18n="Layouts">Inicio</div>
                        </a>

                        <ul class="menu-sub">
                            <li class="menu-item">
                                <a href="nuevo_cliente.phpp" class="menu-link">
                                    <div data-i18n="Without menu">Tablero</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="nuevo_cliente.php" class="menu-link">
                                    <div data-i18n="Without navbar">Agregar Cliente</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="nuevo_proveedor.php" class="menu-link">
                                    <div data-i18n="Container">Agregar Proveedor</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="nueva_cotizacion.php" class="menu-link">
                                    <div data-i18n="Fluid">Agregar Cotizacion</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="nuevo_producto.php" class="menu-link">
                                    <div data-i18n="Blank">Agregar Producto</div>
                                </a>
                            </li>

                            <li class="menu-item">
                                <a href="nueva_compra.php" class="menu-link">
                                    <div data-i18n="Blank">Agregar Compra</div>
                                </a>
                            </li>

                            <li class="menu-item">
                                <a href="nueva_factura.php" class="menu-link">
                                    <div data-i18n="Blank">Agregar Factura</div>
                                </a>
                            </li>

                        </ul>
                    </li>

                    <li class="menu-header small text-uppercase">
                        <span class="menu-header-text">Aspel SAE</span>
                    </li>
                    <li class="menu-item">
                        <a href="#" class="menu-link menu-toggle">
                            <i class="menu-icon tf-icons bx bx-line-chart"></i>
                            <div data-i18n="Account Settings">Ventas</div>
                        </a>
                        <ul class="menu-sub">
                            <li class="menu-item">
                                <a href="facturas.php" class="menu-link">
                                    <div data-i18n="Account">Facturas</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="notasdeventa.php" class="menu-link">
                                    <div data-i18n="Notifications">Notas de Venta</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="trasladoscartaporte.php" class="menu-link">
                                    <div data-i18n="Connections">Carta Porte</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="remisiones.php" class="menu-link">
                                    <div data-i18n="Connections">Remisiones</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="pedidos.php" class="menu-link">
                                    <div data-i18n="Connections">Pedidos</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="cotizaciones.php" class="menu-link">
                                    <div data-i18n="Connections">Cotizaciones</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="devoluciones.php" class="menu-link">
                                    <div data-i18n="Connections">Devoluciones</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="notasdecredito.php" class="menu-link">
                                    <div data-i18n="Connections">Notas de Crédito</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="parcialidades.php" class="menu-link">
                                    <div data-i18n="Connections">Parcialidades</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="comprobantesdepago.php" class="menu-link">
                                    <div data-i18n="Connections">Comprobantes</div>
                                </a>
                            <li class="menu-item">
                                <a href="estadisticas.php" class="menu-link">
                                    <div data-i18n="Connections">Estadisticas</div>
                                </a>
                            </li>
                        </ul>
                    </li>


                    <li class="menu-item">
                        <a href="#" class="menu-link menu-toggle">
                            <i class="menu-icon tf-icons bx bx-user"></i>
                            <div data-i18n="Authentications">Clientes</div>
                        </a>
                        <ul class="menu-sub">
                            <li class="menu-item">
                                <a href="clientes.php" class="menu-link">
                                    <div data-i18n="Basic">Clientes</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="cuentasxcobrar.php" class="menu-link">
                                    <div data-i18n="Basic">Cuentas X Cobrar</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="clientespoliza.php" class="menu-link">
                                    <div data-i18n="Basic">Clientes con Póliza</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="estadisticascli.php" class="menu-link">
                                    <div data-i18n="Statistics">Estadísticas</div>
                                </a>
                            </li>


                            <li class="menu-item">
                                <a href="clientestimbres.php" class="menu-link">
                                    <div data-i18n="ClientStamps">Clientes Timbres</div>
                                </a>
                            </li>

                            <li class="menu-item">
                                <a href="clientesistemas.php" class="menu-link">
                                    <div data-i18n="ClientSystems">Clientes Sistemas</div>
                                </a>
                            </li>
                        </ul>
                    </li>


                    <li class="menu-item active open">
                        <a href="#" class="menu-link menu-toggle">
                            <i class="menu-icon tf-icons bx bx-package"></i>
                            <div data-i18n="Misc">Inventarios</div>
                        </a>
                        <ul class="menu-sub">
                            <li class="menu-item">
                                <a href="productos.php" class="menu-link">
                                    <div data-i18n="Error">Productos</div>
                                </a>
                            </li>
                            <li class="menu-item active">
                                <a href="existencias.php" class="menu-link">
                                    <div data-i18n="Under Maintenance">Existencias</div>
                                </a>
                            </li>
                        </ul>
                    </li>


                    <li class="menu-item">
                        <a href="#" class="menu-link menu-toggle">
                            <i class="menu-icon tf-icons bx bx-shopping-bag"></i>
                            <div data-i18n="Misc">Compras</div>
                        </a>
                        <ul class="menu-sub">
                            <li class="menu-item">
                                <a href="compras.php" class="menu-link">
                                    <div data-i18n="Error">Compras</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="recepciones.php" class="menu-link">
                                    <div data-i18n="Under Maintenance">Recepciones</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="ordenes.php" class="menu-link">
                                    <div data-i18n="Under Maintenance">Ordenes</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="requisiciones.php" class="menu-link">
                                    <div data-i18n="Under Maintenance">Requisiciones</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="devolucionescom.php" class="menu-link">
                                    <div data-i18n="Under Maintenance">Devoluciones</div>
                                </a>
                            </li>
                        </ul>
                    </li>


                    <li class="menu-item">
                        <a href="#" class="menu-link menu-toggle">
                            <i class="menu-icon tf-icons bx bx-group"></i>
                            <div data-i18n="Misc">Proveedores</div>
                        </a>
                        <ul class="menu-sub">
                            <li class="menu-item">
                                <a href="proveedores.php" class="menu-link">
                                    <div data-i18n="Error">Proveedores</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="cuentasxpagar.php" class="menu-link">
                                    <div data-i18n="Under Maintenance">Cuentas X Pagar</div>
                                </a>
                            </li>
                        </ul>
                    </li>


                    <!-- Aspel COI -->
                    <li class="menu-header small text-uppercase"><span class="menu-header-text">Aspel COI</span></li>

                    <!-- Extended components -->
                    <li class="menu-item">
                        <a href="#" class="menu-link menu-toggle">
                            <i class="menu-icon tf-icons bx bx-copy"></i>
                            <div data-i18n="Extended UI">Cuentas y Pólizas</div>
                        </a>
                        <ul class="menu-sub">
                            <li class="menu-item">
                                <a href="cuentas.php" class="menu-link">
                                    <div data-i18n="Perfect Scrollbar">Cuentas</div>
                                </a>
                            </li>
                            <li class="menu-item">
                                <a href="polizas.php" class="menu-link">
                                    <div data-i18n="Text Divider">Pólizas</div>
                                </a>
                            </li>
                        </ul>
                    </li>

                    <!-- Aspel BANCO -->
                    <li class="menu-header small text-uppercase"><span class="menu-header-text">Aspel BANCO</span></li>
                    <!-- Forms -->
                    <li class="menu-item">
                        <a href="#" class="menu-link menu-toggle">
                            <i class="menu-icon tf-icons bx bx-credit-card"></i>
                            <div data-i18n="Form Elements">Movimientos</div>
                        </a>
                        <ul class="menu-sub">
                            <li class="menu-item">
                                <a href="movimientos.php" class="menu-link">
                                    <div data-i18n="Basic Inputs">Movimientos</div>
                                </a>
                            </li>
                        </ul>
                    </li>
                </ul>
            </aside>
            <!-- / Menu -->

            <!-- Layout container -->
            <div class="layout-page">
                <!-- Navbar -->

                <nav class="layout-navbar container-xxl navbar navbar-expand-xl navbar-detached align-items-center bg-navbar-theme" id="layout-navbar">
                    <div class="layout-menu-toggle navbar-nav align-items-xl-center me-3 me-xl-0 d-xl-none">
                        <a class="nav-item nav-link px-0 me-xl-4" href="javascript:void(0)">
                            <i class="bx bx-menu bx-sm"></i>
                        </a>
                    </div>

                    <div class="navbar-nav-right d-flex align-items-center" id="navbar-collapse">
                        <!-- Search -->
                        <div class="navbar-nav align-items-center">
                            <div class="nav-item d-flex align-items-center">
                                <i class="bx bx-search fs-4 lh-0"></i>
                                <input
                                    type="text"
                                    class="form-control border-0 shadow-none"
                                    placeholder="Search..."
                                    aria-label="Search..." />
                            </div>
                        </div>
                        <!-- /Search -->

                        <ul class="navbar-nav flex-row align-items-center ms-auto">


                            <!-- icono de idioma  -->
                            <li class="nav-item dropdown-language dropdown me-2 me-xl-0">
                                <a class="nav-link dropdown-toggle hide-arrow" href="javascript:void(0);" data-bs-toggle="dropdown" aria-expanded="false">
                                    <i class="icon-base bx bx-globe icon-md"></i>
                                </a>
                            </li>


                            <!-- Icono de modo oscuro -->
                            <li class="nav-item dropdown me-2 me-xl-0">
                                <a class="nav-link dropdown-toggle hide-arrow" id="nav-theme" href="javascript:void(0);" data-bs-toggle="dropdown" aria-label="Toggle theme (light)">
                                    <i class="bx-sun icon-base bx icon-md theme-icon-active"></i>
                                    <span class="d-none ms-2" id="nav-theme-text">Toggle theme</span>
                                </a>


                                <!-- Submenu de modo oscuro -->
                                <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="nav-theme-text" data-bs-popper="static">
                                    <li>
                                        <button type="button" class="dropdown-item align-items-center active" data-bs-theme-value="light" aria-pressed="true">
                                            <span>
                                                <i class="icon-base bx bx-sun icon-md me-3" data-icon="sun"></i>Light
                                            </span>
                                        </button>
                                    </li>

                                    <li>
                                        <button type="button" class="dropdown-item align-items-center" data-bs-theme-value="dark" aria-pressed="false">
                                            <span>
                                                <i class="icon-base bx bx-moon icon-md me-3" data-icon="moon"></i>Dark
                                            </span>
                                        </button>
                                    </li>

                                    <li>
                                        <button type="button" class="dropdown-item align-items-center" data-bs-theme-value="system" aria-pressed="false">
                                            <span>
                                                <i class="icon-base bx bx-desktop icon-md me-3" data-icon="desktop"></i>System
                                            </span>
                                        </button>
                                    </li>

                                </ul>
                                <!-- Aquí termina submenu -->
                            </li>


                            <li class="nav-item dropdown-shortcuts navbar-dropdown dropdown me-2 me-xl-0">
                                <a class="nav-link dropdown-toggle hide-arrow" href="javascript:void(0);" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false">
                                    <i class="icon-base bx bx-grid-alt icon-md"></i>
                                </a>
                                <!-- submenu -->
                                <div class="dropdown-menu dropdown-menu-end p-0">
                                    <div class="dropdown-menu-header border-bottom">
                                        <div class="dropdown-header d-flex align-items-center py-3">
                                            <h6 class="mb-0 me-auto">Shortcuts</h6>
                                            <a href="javascript:void(0)" class="dropdown-shortcuts-add py-2" data-bs-toggle="tooltip" data-bs-placement="top" aria-label="Add shortcuts" data-bs-original-title="Add shortcuts"><i class="icon-base bx bx-plus-circle text-heading"></i></a>
                                        </div>
                                    </div>
                                    <div class="dropdown-shortcuts-list scrollable-container ps">
                                        <div class="row row-bordered overflow-visible g-0">
                                            <div class="dropdown-shortcuts-item col">
                                                <span class="dropdown-shortcuts-icon rounded-circle mb-3">
                                                    <i class="icon-base bx bx-calendar icon-26px text-heading"></i>
                                                </span>
                                                <a href="app-calendar.html" class="stretched-link">Calendar</a>
                                                <small>Appointments</small>
                                            </div>
                                            <div class="dropdown-shortcuts-item col">
                                                <span class="dropdown-shortcuts-icon rounded-circle mb-3">
                                                    <i class="icon-base bx bx-food-menu icon-26px text-heading"></i>
                                                </span>
                                                <a href="app-invoice-list.html" class="stretched-link">Invoice App</a>
                                                <small>Manage Accounts</small>
                                            </div>
                                        </div>
                                        <div class="row row-bordered overflow-visible g-0">
                                            <div class="dropdown-shortcuts-item col">
                                                <span class="dropdown-shortcuts-icon rounded-circle mb-3">
                                                    <i class="icon-base bx bx-user icon-26px text-heading"></i>
                                                </span>
                                                <a href="app-user-list.html" class="stretched-link">User App</a>
                                                <small>Manage Users</small>
                                            </div>
                                            <div class="dropdown-shortcuts-item col">
                                                <span class="dropdown-shortcuts-icon rounded-circle mb-3">
                                                    <i class="icon-base bx bx-check-shield icon-26px text-heading"></i>
                                                </span>
                                                <a href="app-access-roles.html" class="stretched-link">Role Management</a>
                                                <small>Permission</small>
                                            </div>
                                        </div>
                                        <div class="row row-bordered overflow-visible g-0">
                                            <div class="dropdown-shortcuts-item col">
                                                <span class="dropdown-shortcuts-icon rounded-circle mb-3">
                                                    <i class="icon-base bx bx-pie-chart-alt-2 icon-26px text-heading"></i>
                                                </span>
                                                <a href="index.html" class="stretched-link">Dashboard</a>
                                                <small>User Dashboard</small>
                                            </div>
                                            <div class="dropdown-shortcuts-item col">
                                                <span class="dropdown-shortcuts-icon rounded-circle mb-3">
                                                    <i class="icon-base bx bx-cog icon-26px text-heading"></i>
                                                </span>
                                                <a href="pages-account-settings-account.html" class="stretched-link">Setting</a>
                                                <small>Account Settings</small>
                                            </div>
                                        </div>
                                        <div class="row row-bordered overflow-visible g-0">
                                            <div class="dropdown-shortcuts-item col">
                                                <span class="dropdown-shortcuts-icon rounded-circle mb-3">
                                                    <i class="icon-base bx bx-help-circle icon-26px text-heading"></i>
                                                </span>
                                                <a href="pages-faq.html" class="stretched-link">FAQs</a>
                                                <small>FAQs &amp; Articles</small>
                                            </div>
                                            <div class="dropdown-shortcuts-item col">
                                                <span class="dropdown-shortcuts-icon rounded-circle mb-3">
                                                    <i class="icon-base bx bx-window-open icon-26px text-heading"></i>
                                                </span>
                                                <a href="modal-examples.html" class="stretched-link">Modals</a>
                                                <small>Useful Popups</small>
                                            </div>
                                        </div>
                                        <div class="ps__rail-x" style="left: 0px; bottom: 0px;">
                                            <div class="ps__thumb-x" tabindex="0" style="left: 0px; width: 0px;"></div>
                                        </div>
                                        <div class="ps__rail-y" style="top: 0px; right: 0px;">
                                            <div class="ps__thumb-y" tabindex="0" style="top: 0px; height: 0px;"></div>
                                        </div>
                                    </div>
                                </div>
                                <!-- aqui termina submenu -->

                            </li>

                            <li class="nav-item dropdown-notifications navbar-dropdown dropdown me-3 me-xl-2">
                                <a class="nav-link dropdown-toggle hide-arrow" href="javascript:void(0);" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false">
                                    <span class="position-relative">
                                        <i class="icon-base bx bx-bell icon-md"></i>
                                        <span class="badge rounded-pill bg-danger badge-dot badge-notifications border"></span>
                                    </span>
                                </a>

                                <!--empiezan las notificaciones -->
                                <ul class="dropdown-menu dropdown-menu-end p-0">
                                    <li class="dropdown-menu-header border-bottom">
                                        <div class="dropdown-header d-flex align-items-center py-3">
                                            <h6 class="mb-0 me-auto">Notification</h6>
                                            <div class="d-flex align-items-center h6 mb-0">
                                                <span class="badge bg-label-primary me-2">8 New</span>
                                                <a href="javascript:void(0)" class="dropdown-notifications-all p-2" data-bs-toggle="tooltip" data-bs-placement="top" aria-label="Mark all as read" data-bs-original-title="Mark all as read"><i class="icon-base bx bx-envelope-open text-heading"></i></a>
                                            </div>
                                        </div>
                                    </li>


                                    <li class="dropdown-notifications-list scrollable-container ps">
                                        <ul class="list-group list-group-flush">
                                            <li class="list-group-item list-group-item-action dropdown-notifications-item">
                                                <div class="d-flex">
                                                    <div class="flex-shrink-0 me-3">
                                                        <div class="avatar">
                                                            <img src="../../assets/img/avatars/1.png" alt="" class="rounded-circle">
                                                        </div>
                                                    </div>
                                                    <div class="flex-grow-1">
                                                        <h6 class="small mb-0">Congratulation Lettie 🎉</h6>
                                                        <small class="mb-1 d-block text-body">Won the monthly best seller gold badge</small>
                                                        <small class="text-body-secondary">1h ago</small>
                                                    </div>
                                                    <div class="flex-shrink-0 dropdown-notifications-actions">
                                                        <a href="javascript:void(0)" class="dropdown-notifications-read"><span class="badge badge-dot"></span></a>
                                                        <a href="javascript:void(0)" class="dropdown-notifications-archive"><span class="icon-base bx bx-x"></span></a>
                                                    </div>
                                                </div>
                                            </li>
                                            <li class="list-group-item list-group-item-action dropdown-notifications-item">
                                                <div class="d-flex">
                                                    <div class="flex-shrink-0 me-3">
                                                        <div class="avatar">
                                                            <span class="avatar-initial rounded-circle bg-label-danger">CF</span>
                                                        </div>
                                                    </div>
                                                    <div class="flex-grow-1">
                                                        <h6 class="small mb-0">Charles Franklin</h6>
                                                        <small class="mb-1 d-block text-body">Accepted your connection</small>
                                                        <small class="text-body-secondary">12hr ago</small>
                                                    </div>
                                                    <div class="flex-shrink-0 dropdown-notifications-actions">
                                                        <a href="javascript:void(0)" class="dropdown-notifications-read"><span class="badge badge-dot"></span></a>
                                                        <a href="javascript:void(0)" class="dropdown-notifications-archive"><span class="icon-base bx bx-x"></span></a>
                                                    </div>
                                                </div>
                                            </li>
                                            <li class="list-group-item list-group-item-action dropdown-notifications-item marked-as-read">
                                                <div class="d-flex">
                                                    <div class="flex-shrink-0 me-3">
                                                        <div class="avatar">
                                                            <img src="../../assets/img/avatars/2.png" alt="" class="rounded-circle">
                                                        </div>
                                                    </div>
                                                    <div class="flex-grow-1">
                                                        <h6 class="small mb-0">New Message ✉️</h6>
                                                        <small class="mb-1 d-block text-body">You have new message from Natalie</small>
                                                        <small class="text-body-secondary">1h ago</small>
                                                    </div>
                                                    <div class="flex-shrink-0 dropdown-notifications-actions">
                                                        <a href="javascript:void(0)" class="dropdown-notifications-read"><span class="badge badge-dot"></span></a>
                                                        <a href="javascript:void(0)" class="dropdown-notifications-archive"><span class="icon-base bx bx-x"></span></a>
                                                    </div>
                                                </div>
                                            </li>
                                        </ul>

                                        <div class="ps__rail-x" style="left: 0px; bottom: 0px;">
                                            <div class="ps__thumb-x" tabindex="0" style="left: 0px; width: 0px;"></div>
                                        </div>
                                        <div class="ps__rail-y" style="top: 0px; right: 0px;">
                                            <div class="ps__thumb-y" tabindex="0" style="top: 0px; height: 0px;"></div>
                                        </div>
                                    </li>

                                    <li class="border-top">
                                        <div class="d-grid p-4">
                                            <a class="btn btn-primary btn-sm d-flex" href="javascript:void(0);">
                                                <small class="align-middle">View all notifications</small>
                                            </a>
                                        </div>
                                    </li>
                                </ul> <!-- termina submenu de notificaciones -->
                            </li>


                            <!-- Place this tag where you want the button to render. -->
                            <li class="nav-item lh-1 me-3">
                                <a
                                    class="github-button"
                                    href="https://github.com/themeselection/sneat-html-admin-template-free"
                                    data-icon="octicon-star"
                                    data-size="large"
                                    data-show-count="true"
                                    aria-label="Star themeselection/sneat-html-admin-template-free on GitHub">Star</a>
                            </li>

                            <!-- User -->
                            <li class="nav-item navbar-dropdown dropdown-user dropdown">
                                <a class="nav-link dropdown-toggle hide-arrow" href="javascript:void(0);" data-bs-toggle="dropdown">
                                    <div class="avatar avatar-online">
                                        <img src="../assets/img/avatars/1.png" alt class="w-px-40 h-auto rounded-circle" />
                                    </div>
                                </a>
                                <ul class="dropdown-menu dropdown-menu-end">
                                    <li>
                                        <a class="dropdown-item" href="#">
                                            <div class="d-flex">
                                                <div class="flex-shrink-0 me-3">
                                                    <div class="avatar avatar-online">
                                                        <img src="../assets/img/avatars/1.png" alt class="w-px-40 h-auto rounded-circle" />
                                                    </div>
                                                </div>
                                                <div class="flex-grow-1">
                                                    <span class="fw-semibold d-block">John Doe</span>
                                                    <small class="text-muted">Admin</small>
                                                </div>
                                            </div>
                                        </a>
                                    </li>
                                    <li>
                                        <div class="dropdown-divider"></div>
                                    </li>



                                    <li>
                                        <a class="dropdown-item" href="auth-login-basic.html">
                                            <i class="bx bx-power-off me-2"></i>
                                            <span class="align-middle">Cerrar Sesión</span>
                                        </a>
                                    </li>
                                </ul>
                            </li>
                            <!--/ User -->
                        </ul>
                    </div>
                </nav>
                <!-- / Navbar -->
                <?php
                session_start();
                $host = 'localhost';
                $database = 'C:\Program Files (x86)\Common Files\Aspel\Sistemas Aspel\SAE9.00\Ejemplos\Ejemplos.fdb';
                $username = 'SYSDBA';
                $password = 'masterkey';

                try {
                    $dbh = new PDO("firebird:host=$host;dbname=$database;charset=UTF8", $username, $password);

                    // Contamos productos por categoría de existencias
                    $counts = [
                        'con_existencias' => 0,
                        'sin_existencias' => 0,
                        'pocas_existencias' => 0,
                        'demasiadas_existencias' => 0
                    ];

                    // Consulta para contar productos con existencias dentro del rango mínimo y máximo
                    $stmt = $dbh->query("SELECT COUNT(*) FROM INVE01 WHERE EXIST > 0 AND EXIST >= STOCK_MIN AND EXIST <= STOCK_MAX");
                    $counts['con_existencias'] = $stmt->fetchColumn();

                    // Consulta para contar productos sin existencias
                    $stmt = $dbh->query("SELECT COUNT(*) FROM INVE01 WHERE EXIST = 0");
                    $counts['sin_existencias'] = $stmt->fetchColumn();

                    // Consulta para contar productos con pocas existencias (por debajo del mínimo)
                    $stmt = $dbh->query("SELECT COUNT(*) FROM INVE01 WHERE EXIST > 0 AND EXIST < STOCK_MIN");
                    $counts['pocas_existencias'] = $stmt->fetchColumn();

                    // Consulta para contar productos con demasiadas existencias (por encima del máximo)
                    $stmt = $dbh->query("SELECT COUNT(*) FROM INVE01 WHERE EXIST > STOCK_MAX");
                    $counts['demasiadas_existencias'] = $stmt->fetchColumn();
                } catch (PDOException $e) {
                    echo "<div class='container mt-5'><h2>AUN NO HAY CONEXION:</h2>";
                    echo "<p>" . htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8') . "</p></div>";
                    exit;
                }
                ?>
                <!-- Content wrapper -->
                <div class="content-wrapper">
                    <!-- Content -->
                    <!-- Content wrapper -->
                    <div class="content-wrapper">
                        <!-- Content -->


                        <div class="container-xxl flex-grow-1 container-p-y">
                            <div class="row">
                                <!--/ Total Revenue -->
                                <div class="col-12 col-md-12 col-lg-12 order-3 order-md-2">
                                    <div class="row">

                                        <div class="col-sm-6 col-xl-3 mb-4 wow animate__animated animate__fadeInUp" data-wow-delay="0.2s">
                                            <div class="card">
                                                <div class="card-body">
                                                    <div class="d-flex align-items-center justify-content-between">
                                                        <div class="content-left">
                                                            <small>Con Existencias</small>
                                                            <h4><?php echo $counts['con_existencias']; ?></h4>
                                                        </div>
                                                        <span class="badge bg-label-success rounded-circle p-2">
                                                            <i class="icon-base bx bx-dollar icon-lg"></i>
                                                        </span>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="col-sm-6 col-xl-3 mb-4 wow animate__animated animate__fadeInUp" data-wow-delay="0.4s">
                                            <div class="card">
                                                <div class="card-body">
                                                    <div class="d-flex align-items-center justify-content-between">
                                                        <div class="content-left">
                                                            <small>Sin Existencias</small>
                                                            <h4><?php echo $counts['sin_existencias']; ?></h4>
                                                        </div>
                                                        <span class="badge bg-label-danger rounded-circle p-2">
                                                            <i class="icon-base bx bx-task-x icon-lg"></i>
                                                        </span>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="col-sm-6 col-xl-3 mb-4 wow animate__animated animate__fadeInUp" data-wow-delay="0.8s">
                                            <div class="card">
                                                <div class="card-body">
                                                    <div class="d-flex align-items-center justify-content-between">
                                                        <div class="content-left">
                                                            <small>Pocas Existencias</small>
                                                            <h4><?php echo $counts['pocas_existencias']; ?></h4>
                                                        </div>
                                                        <span class="badge bg-label-warning rounded-circle p-2">
                                                            <i class="icon-base bx bx-task-x icon-lg"></i>
                                                        </span>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="col-sm-6 col-xl-3 mb-4 wow animate__animated animate__fadeInUp" data-wow-delay="0.2s">
                                            <div class="card">
                                                <div class="card-body">
                                                    <div class="d-flex align-items-center justify-content-between">
                                                        <div class="content-left">
                                                            <small>Demasiadas existencias</small>
                                                            <h4><?php echo $counts['demasiadas_existencias']; ?></h4>
                                                        </div>
                                                        <span class="badge bg-label-dark rounded-circle p-2">
                                                            <i class="icon-base bx bx-task icon-lg"></i>
                                                        </span>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                        <!-- </div>
                    <div class="row"> -->
                                    </div>
                                </div>
                            </div>

                            <!-- <h4 class="fw-bold py-3 mb-4"><span class="text-muted fw-light">Tables /</span> Basic Tables</h4> -->

                            <!-- Basic Bootstrap Table -->
                            <div class="card wow animate__animated animate__fadeInUp" data-wow-delay="0.8s">
                                <!-- <h5 class="card-header">Compras</h5> -->
                                <div class="table-responsive text-nowrap">

                                    <?php
                                    $host = 'localhost';
                                    $database = 'C:\Program Files (x86)\Common Files\Aspel\Sistemas Aspel\SAE9.00\Ejemplos\Ejemplos.fdb';
                                    $username = 'SYSDBA';
                                    $password = 'masterkey';

                                    try {
                                        $dbh = new PDO("firebird:host=$host;dbname=$database;charset=UTF8", $username, $password);

                                        // Nueva consulta para contar productos por línea de producto
                                        // Consulta para obtener el número de productos y la suma de existencias por categoría
                                        $sqlCategorias = "SELECT LIN_PROD, COUNT(CVE_ART) AS NUM_PRODUCTOS, SUM(EXIST) AS TOTAL_EXIST
    FROM INVE01
    GROUP BY LIN_PROD";
                                        $stmtCategorias = $dbh->query($sqlCategorias);
                                        $categoriaData = [];
                                        while ($row = $stmtCategorias->fetch(PDO::FETCH_ASSOC)) {
                                            $categoriaData[] = $row;
                                        }

                                        // Convierte los datos de categorías a formato JSON
                                        $categoriaLabels = json_encode(array_column($categoriaData, 'LIN_PROD')); // Etiquetas (líneas de producto)
                                        $categoriaValues = json_encode(array_column($categoriaData, 'NUM_PRODUCTOS')); // Número de productos por categoría
                                        $categoriaExistencias = json_encode(array_column($categoriaData, 'TOTAL_EXIST')); // Existencias totales por categoría


                                        // Nueva consulta para obtener productos de la tabla INVE01
                                        $sql = "SELECT INVE01.CVE_ART, INVE01.DESCR, INVE01.UNI_MED, INVE01.STOCK_MIN, INVE01.STOCK_MAX, INVE01.EXIST, INVE01.LIN_PROD
            FROM INVE01";

                                        // Aplica filtros según el botón seleccionado
                                        if (isset($_POST['filter'])) {
                                            switch ($_POST['filter']) {
                                                case 'con_existencias':
                                                    $sql .= " WHERE INVE01.EXIST > 0 AND INVE01.EXIST >= INVE01.STOCK_MIN AND INVE01.EXIST <= INVE01.STOCK_MAX";
                                                    break;
                                                case 'sin_existencias':
                                                    $sql .= " WHERE INVE01.EXIST = 0";
                                                    break;
                                                case 'pocas_existencias':
                                                    $sql .= " WHERE INVE01.EXIST > 0 AND INVE01.EXIST < INVE01.STOCK_MIN";
                                                    break;
                                                case 'demasiadas_existencias':
                                                    $sql .= " WHERE INVE01.EXIST > INVE01.STOCK_MAX";
                                                    break;
                                            }
                                        }

                                        $selectedFilter = isset($_POST['filter']) ? $_POST['filter'] : ''; // Capture selected button value
                                        $stmt = $dbh->query($sql);

                                        echo "<div class='container mt-5'>";
                                        echo "<h1 class='mb-4'><strong>Existencias</strong></h1>";

                                        echo "<div class='row mb-3'>";

                                        // Columna 1: Botones de filtro
                                        echo "<div class='col-sm-12 col-md-8'>";
                                        echo "<div class='btn-group' role='group'>";

                                        echo "<form method='POST' style='display: inline;'>";

                                        echo "<button name='filter' value='con_existencias' class='btn1 custom-filter " . ($selectedFilter == 'con_existencias' ? 'selected' : '') . "'>Con Existencias</button>";
                                        echo "<button name='filter' value='sin_existencias' class='btn2 custom-filter " . ($selectedFilter == 'sin_existencias' ? 'selected' : '') . "'>Sin Existencias</button>";
                                        echo "<button name='filter' value='pocas_existencias' class='btn3 custom-filter " . ($selectedFilter == 'pocas_existencias' ? 'selected' : '') . "'>Pocas Existencias</button>";
                                        echo "<button name='filter' value='demasiadas_existencias' class='btn4 custom-filter " . ($selectedFilter == 'demasiadas_existencias' ? 'selected' : '') . "'>Demasiadas Existencias</button>";
                                        echo "<button name='filter' value='all' class='btn5 custom-filter " . ($selectedFilter == 'all' ? 'selected' : '') . "'>Todas</button>";
                                        echo "</form>";

                                        echo "</div>";
                                        echo "</div>"; // Cierre de la primera columna

                                        // Columna 2: Botón "Eliminar Filtro" (alineado a la derecha)
                                        echo "<div class='col-sm-12 col-md-4 text-md-right text-sm-left'>";
                                        echo "<form method='POST' style='display: inline;'>";
                                        echo "<button type='submit' name='eliminar_filtro' class='btn6 btn6-warning'>Borrar Filtros</button>";
                                        echo "</form>";
                                        echo "</div>"; // Cierre de la segunda columna

                                        echo "</div>"; // Cierre de la fila principal


                                        echo "<table id='clientesTable' class='table table-hover '>";
                                        echo "<thead class='thead-dark'><tr><th>Clave</th><th>Descripción</th><th>Unidad</th><th>Línea</th><th>Stock Min</th><th>Stock Max</th><th>Existencias</th><th>Semáforo</th><th>Imagen</th></tr></thead><tbody>";

                                        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                                            echo "<tr>";
                                            echo "<td>" . $row['CVE_ART'] . "</td>";
                                            echo "<td>" . $row['DESCR'] . "</td>";
                                            echo "<td>" . $row['UNI_MED'] . "</td>";
                                            echo "<td>" . $row['LIN_PROD'] . "</td>";
                                            echo "<td>" . $row['STOCK_MIN'] . "</td>";
                                            echo "<td>" . $row['STOCK_MAX'] . "</td>";
                                            echo "<td class='num'>" . $row['EXIST'] . "</td>";

                                            // Definir variables para colores y el ícono según las existencias
                                            $existencias = $row['EXIST'];
                                            $stockMin = $row['STOCK_MIN'];
                                            $stockMax = $row['STOCK_MAX'];

                                            if ($existencias == 0) {
                                                $semaforoColor = '#ffe0db';
                                                $borderColor = '#ff3e1d';
                                                $textColor = '#ff3e1d';
                                                $icon = 'fas fa-times-circle'; // Ícono para sin existencias
                                            } elseif ($existencias < $stockMin) {
                                                $semaforoColor = '#fff2d6';
                                                $borderColor = '#ffab00';
                                                $textColor = '#ffab00';
                                                $icon = 'fas fa-exclamation-circle'; // Ícono para pocas existencias
                                            } elseif ($existencias > $stockMax) {
                                                $semaforoColor = '#eff2f6';
                                                $borderColor = '#8592a3';
                                                $textColor = '#525b75';
                                                $icon = 'fas fa-exclamation-triangle'; // Ícono para existencias superiores al stock máximo
                                            } else {
                                                $semaforoColor = '#e8fadf';
                                                $borderColor = '#71dd37';
                                                $textColor = '#71dd37';
                                                $icon = 'fas fa-check-circle'; // Ícono para existencias dentro del rango adecuado
                                            }

                                            echo "<td>
        <span style='
            display: flex;
            align-items: center;
            justify-content: center;
            width: 25px;
            height: 25px;
            background-color: $semaforoColor;
            border: 2px solid $borderColor;
            border-radius: 50%;
        '>
            <i class='$icon' style='color: $textColor; font-size: 12px;' title='"
                                                . ($existencias == 0 ? "Producto sin existencias" : ($existencias < $stockMin ? "Producto en stock mínimo" : ($existencias > $stockMax ? "Producto en exceso de existencias" : "Producto en existencias adecuadas")))
                                                . "'></i>
        </span>
    </td>";

                                            echo "<td><a href='#' data-toggle='modal' data-target='#imageModal' data-image='/imagenes-productos/" . $row['CVE_ART'] . ".jpg' data-cve_art='" . $row['CVE_ART'] . "'><img src='/imagenes-productos/" . $row['CVE_ART'] . ".jpg' alt='Imagen del Producto' style='width: 50px; height: 50px; cursor: pointer;'></a></td>";
                                            echo "</tr>";
                                        }
                                        echo "</tbody></table>";
                                        echo "</div>";
                                    } catch (PDOException $e) {
                                        echo "<div class='container mt-5'><h2>AUN NO HAY CONEXION:</h2>";
                                        echo "<p>" . $e->getMessage() . "</p></div>";
                                    }
                                    ?>


                                </div>
                                <!-- / Content -->



                                <div class="content-backdrop fade"></div>
                            </div>
                            <!-- Content wrapper -->
                        </div>


                        <!-- Overlay -->
                        <div class="layout-overlay layout-menu-toggle"></div>
                    </div>
                    <!-- / Layout wrapper -->


                    <script src="https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.min.js"></script>
                    <script>
                        new WOW().init();
                    </script>


                    <!-- Core JS -->
                    <!-- build:js assets/vendor/js/core.js -->
                    <script src="../assets/vendor/libs/jquery/jquery.js"></script>
                    <script src="../assets/vendor/libs/popper/popper.js"></script>
                    <script src="../assets/vendor/js/bootstrap.js"></script>
                    <script src="../assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.js"></script>

                    <script src="../assets/vendor/js/menu.js"></script>
                    <!-- endbuild -->

                    <!-- Vendors JS -->
                    <script src="../assets/vendor/libs/apex-charts/apexcharts.js"></script>

                    <!-- Main JS -->
                    <script src="../assets/js/main.js"></script>

                    <!-- Page JS -->
                    <script src="../assets/js/dashboards-analytics.js"></script>

                    <!-- Place this tag in your head or just before your close body tag. -->
                    <script async defer src="https://buttons.github.io/buttons.js"></script>


</body>

<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.21/js/dataTables.bootstrap4.min.js"></script>
<script src="https://cdn.datatables.net/plug-ins/1.10.21/i18n/Spanish.json"></script>
<script src="https://cdn.datatables.net/plug-ins/1.10.25/sorting/natural.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.13/jspdf.plugin.autotable.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/exceljs/4.3.0/exceljs.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/countup.js/2.0.8/countUp.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@sweetalert2/theme-material-ui/material-ui.min.css">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>


<script>
    $(document).ready(function() {
        $.fn.dataTable.ext.type.order['numeric-comma-asc'] = function(data) {
            return parseFloat(data.replace(/[^0-9.-]/g, '')) || 0;
        };
        $.fn.dataTable.ext.type.order['numeric-comma-desc'] = function(data) {
            return -parseFloat(data.replace(/[^0-9.-]/g, '')) || 0;
        };


        var table = $('#clientesTable').DataTable({
            language: {
                url: '../json/Spanish.json'
            },
            pageLength: 10,
            lengthMenu: [
                [10, 25, 50, -1],
                [10, 25, 50, "Todos"]
            ],
            columnDefs: [{
                targets: 2,
                type: 'numeric-comma'
            }],
            order: [
                [2, 'asc']
            ]
        });

    });
</script>

<script>
    // Cambia el evento al hacer clic en el enlace de la imagen para abrir el modal de SweetAlert2
    $('#clientesTable').on('click', 'a[data-toggle="modal"]', function(event) {
        event.preventDefault();
        var button = $(this);
        var imageUrl = button.data('image'); // Ruta de la imagen
        var cveArt = button.data('cve_art'); // Clave del producto

        // Captura los datos adicionales necesarios
        var descripcion = button.closest('tr').find('td:eq(1)').text(); // Descripción
        var linea = button.closest('tr').find('td:eq(3)').text(); // Línea
        var existencias = button.closest('tr').find('td:eq(6)').text(); // Existencias

        // Llama a SweetAlert2 para mostrar el modal personalizado
        Swal.fire({
            title: `<strong>Producto: ${cveArt}</strong>`,
            html: `
            <img src="${imageUrl}" alt="Imagen del Producto" style="width: 100%; height: auto; margin-bottom: 20px;">
            <p><strong>Descripción:</strong> ${descripcion}</p>
            <p><strong>Línea:</strong> ${linea}</p>
            <p><strong>Existencias:</strong> ${existencias}</p>
        `,
            showCloseButton: false, // Desactiva la "X" para cerrar
            showConfirmButton: true, // Muestra el botón de confirmación
            confirmButtonText: 'Cerrar', // Texto del botón de cierre
            customClass: {
                popup: 'swal-custom-modal', // Clase personalizada para el modal
                confirmButton: 'swal-close-btn' // Clase personalizada para el botón de cierre
            }
        });
    });
</script>




<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
    // Obtén los datos de categorías desde PHP
    const labels = <?php echo $categoriaLabels; ?>;
    const data = <?php echo $categoriaValues; ?>;
    const existenciasTotales = <?php echo $categoriaExistencias; ?>;

    // Configuración de la gráfica de dona
    const ctx = document.getElementById('productosPorCategoria').getContext('2d');
    new Chart(ctx, {
        type: 'doughnut',
        data: {
            labels: labels,
            datasets: [{
                data: data, // Mostrar número de productos en cada categoría
                backgroundColor: [
                    '#009DFF', '#007ECC', '#00C49A', '#FFC107', '#FF7A48', '#B0BEC5'
                ],
                hoverBackgroundColor: [
                    '#007ECC', '#009DFF', '#00B58A', '#FFB206', '#FF6A38', '#90A4AE'
                ],
                borderWidth: 2,
                borderColor: '#fff'
            }]
        },
        options: {
            responsive: true,
            cutout: '65%', // Configuración para hacerla tipo dona
            plugins: {
                legend: {
                    position: 'bottom', // Mueve la leyenda debajo de la gráfica
                    labels: {
                        boxWidth: 20,
                        padding: 10,
                        color: '#333',
                        font: {
                            family: 'Arial',
                            size: 12,
                            weight: 'bold'
                        },
                        maxWidth: 150,
                    },
                    // Ajustar la distribución de las leyendas a filas
                    align: 'start',
                    fullWidth: true,
                    reverse: false,
                },
                tooltip: {
                    callbacks: {
                        label: function(tooltipItem) {
                            const totalExistencias = existenciasTotales[tooltipItem.dataIndex];
                            return `${tooltipItem.label}: ${tooltipItem.raw} productos (${totalExistencias} existencias)`;
                        }
                    }
                },
                // Agregar el texto al centro de la dona
                beforeDraw: function(chart) {
                    const ctx = chart.ctx;
                    const chartArea = chart.chartArea;
                    const centerX = (chartArea.left + chartArea.right) / 2;
                    const centerY = (chartArea.top + chartArea.bottom) / 2;

                    ctx.save();
                    ctx.font = '16px Arial';
                    ctx.fillStyle = '#000';
                    ctx.textAlign = 'center';
                    ctx.textBaseline = 'middle';

                    // Mostrar existencias totales de la categoría activa
                    if (chart.active && chart.active.length > 0) {
                        const activeIndex = chart.active[0].index;
                        const totalExistencias = existenciasTotales[activeIndex];
                        ctx.fillText(`${totalExistencias} existencias`, centerX, centerY);
                    } else {
                        ctx.fillText('Pasa el cursor', centerX, centerY);
                    }

                    ctx.restore();
                }
            }
        }
    });
</script>

</html>