<?php 
$seccion      = 'Tiendas';
$position     = '../../';

require_once($position.'../switch/access.php');
require_once($position.'assets/global.php');
require_once($position.'assets/session.php');
require_once($position.'assets/funciones.php');

//Query's
$qrTiendas = "
SELECT 
	 tn.id,
     ut.fk_usuario,
     tn.nombre,
     concat_ws(' ', ua.nombre, ua.apellido_paterno, ua.apellido_materno) as tendero,
     tn.fk_pais,
     tn.fk_estado,
     ce.estado,
     tn.fk_municipio,
     cm.municipio,
     tn.codigo_postal,
     tn.colonia,
     tn.calle,
     tn.no_exterior,
     tn.no_interior,
     tn.referencia,
     tn.lat,
     tn.lng,
     tn.fk_clasificacion,
     tn.status
FROM 
	onecoded_SwitchPointApp.tiendas tn
INNER JOIN usuarios_tiendas ut ON ut.fk_tienda = tn.id
INNER JOIN usuarios_app ua ON ua.id = ut.fk_usuario
INNER JOIN cat_estados ce ON ce.id = tn.fk_estado
INNER JOIN cat_municipios cm ON cm.id = tn.fk_municipio AND cm.fk_estado = tn.fk_estado
";
$tiendas = mysqli_query($mysqli, $qrTiendas);

?>
<!DOCTYPE html>
<html lang="es_MX">
    <head>
        <meta charset="utf-8" />
        <title>Switch Point | <?php echo $seccion;?> </title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <!-- App favicon -->
        <link rel="shortcut icon" href="<?php echo $position; ?>assets/images/favicon.ico">

		<!-- App css -->
		<link href="<?php echo $position; ?>assets/css/bootstrap-corporate.min.css" rel="stylesheet" type="text/css" id="bs-default-stylesheet" />
		<link href="<?php echo $position; ?>assets/css/app-corporate.min.css" rel="stylesheet" type="text/css" id="app-default-stylesheet" />

		<link href="<?php echo $position; ?>assets/css/bootstrap-corporate-dark.min.css" rel="stylesheet" type="text/css" id="bs-dark-stylesheet" />
		<link href="<?php echo $position; ?>assets/css/app-corporate-dark.min.css" rel="stylesheet" type="text/css" id="app-dark-stylesheet" />
        <link href="<?php echo $position; ?>assets/css/style.css" rel="stylesheet" type="text/css" id="app-dark-stylesheet" />

		<!-- icons -->
		<link href="<?php echo $position; ?>assets/css/icons.min.css" rel="stylesheet" type="text/css" />

        <!-- third party css -->
        <link href="<?php echo $position; ?>assets/libs/datatables.net-bs4/css/dataTables.bootstrap4.min.css" rel="stylesheet" type="text/css" />
        <link href="<?php echo $position; ?>assets/libs/datatables.net-responsive-bs4/css/responsive.bootstrap4.min.css" rel="stylesheet" type="text/css" />
        <link href="<?php echo $position; ?>assets/libs/datatables.net-buttons-bs4/css/buttons.bootstrap4.min.css" rel="stylesheet" type="text/css" />
        <link href="<?php echo $position; ?>assets/libs/datatables.net-select-bs4/css//select.bootstrap4.min.css" rel="stylesheet" type="text/css" />
        <!-- third party css end -->

    </head>

    <body class="loading" data-layout='{"mode": "light", "width": "fluid", "menuPosition": "fixed", "sidebar": { "color": "dark", "size": "default", "showuser": false}, "topbar": {"color": "light"}, "showRightSidebarOnPageLoad": false}'>

        <!-- Pagina de inicio -->
        <div id="wrapper">

            <!-- ========== Inicio nav-izq ========== -->
            <?php include_once($position.'assets/nav.php'); ?>
            <!-- Fin nav-izq -->

            <!-- ============================================================== -->
            <!-- Incio de Contenido -->
            <!-- ============================================================== -->

            <div class="content-page">
                <div class="content">

                    <!-- Topbar -->
                    <?php include_once($position.'assets/topbar.php'); ?>
                    <!-- /Topbar -->

                    <!-- Content-->
                    <div class="container-fluid">
                        
                        <!-- page title -->
                        <div class="row">
                            <div class="col-12">
                                <div class="page-title-box">
                                    <h4 class="page-title"><?php echo $seccion; ?></h4>
                                    <div class="page-title-right">
                                        <ol class="breadcrumb m-0">
                                            <li class="breadcrumb-item"><a href="<?php echo $dir; ?>inicio/">Inicio</a></li>
                                            <li class="breadcrumb-item"><a href="<?php echo $dir; ?>tenderos/usuarios/">Tenderos</a></li>
                                            <li class="breadcrumb-item active"><?php echo $seccion; ?></li>
                                        </ol>
                                    </div>
                                </div>
                            </div>
                        </div>     
                        <!-- /page title --> 

                        <!-- secciones  -->
                        <!-- Botones -->
						<div class="row">			
							<div class="col-12 text-right">
								<button type="button" class="btn btn-sp btn-sm" onclick="window.location.href='tienda.php'"><i class="ri-store-2-line"></i>&nbsp; Nueva Tienda</button>
							</div>
							<div class="col-12" style="height: 5px;">&nbsp;</div>
						</div>
						
						<!-- usuarios -->
                        <div class="row">
                            <div class="col-12">
                                <div class="card">
                                    <div class="card-body">										
                                        <h4 class="header-title">Lista de <?php echo $seccion; ?></h4>
                                        <p class="text-muted font-13 mb-4">
                                            Registro de tiendas de Switch Point app.
                                        </p>
										
                                        <table id="basic-datatable" class="table dt-responsive nowrap w-100">
                                            <thead>
                                                <tr>
                                                    <th>Tienda</th>
                                                    <th>Tendero</th>
                                                    <th>Estado</th>
                                                    <th>Municipio</th>
                                                    <th>Codigo Postal</th>
													<th>Estatus</th>
													<th>&nbsp;</th>
                                                    <th>&nbsp;</th>
                                                </tr>
                                            </thead>
                                            <tbody>
<!--											<?php mysqli_data_seek($tiendas, 0);while($tnd = mysqli_fetch_array($tiendas)) {?>-->
                                                <tr>
                                                    <td><?php echo $tnd['nombre']; ?></td>
                                                    <td><?php echo $tnd['tendero']; ?></td>
                                                    <td><?php echo $tnd['estado']; ?></td>
                                                    <td><?php echo $tnd['municipio']; ?></td>
                                                    <td><?php echo $tnd['codigo_postal']; ?></td>
                                                    <td>
														<?php if ($tnd['status'] == 1){$btnClass = "btn-success"; $btnStatus = "Activo";}else{$btnClass = "btn-primary"; $btnStatus = "Inactivo";}?> 
														<button class="btn <?php echo $btnClass ?> btn-xs"><?php echo $btnStatus ?></button>
													</td>
													<td>
														<a class="btn btn-outline-info waves-effect waves-light btn-xs" href="tienda.php?id=<?php echo $tnd['id'];?>"><i class="ri-eye-line"></i> Ver</a>
													</td>
													<td>
														<a class="btn btn-outline-secondary waves-effect btn-xs" href="tienda.php?id=<?php echo $tnd['id'];?>"><i class="fe-edit-1"></i> Editar</a>
													</td>
                                                </tr>
<!--											<?php } ?>-->
                                            </tbody>
                                        </table>

                                    </div> <!-- end card body-->
                                </div> <!-- end card -->
                            </div><!-- end col-->
                        </div>
                        <!-- /secciones -->
                        
                    </div> <!-- /container -->

                </div> <!-- /content -->

                <!-- Footer -->
                <?php include_once($position.'assets/footer.php'); ?>
                <!-- /Footer -->

            </div>

            <!-- ============================================================== -->
            <!-- Fin de Contenido -->
            <!-- ============================================================== -->


        </div>
        <!--  /wrapper -->

        <!-- Vendor js -->
        <script src="<?php echo $position; ?>assets/js/vendor.min.js"></script>

        <!-- App js -->
        <script src="<?php echo $position; ?>assets/js/app.min.js"></script>


        <!-- third party js -->
        <script src="<?php echo $position; ?>assets/libs/datatables.net/js/jquery.dataTables.min.js"></script>
        <script src="<?php echo $position; ?>assets/libs/datatables.net-bs4/js/dataTables.bootstrap4.min.js"></script>
        <script src="<?php echo $position; ?>assets/libs/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
        <script src="<?php echo $position; ?>assets/libs/datatables.net-responsive-bs4/js/responsive.bootstrap4.min.js"></script>
        <script src="<?php echo $position; ?>assets/libs/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
        <script src="<?php echo $position; ?>assets/libs/datatables.net-buttons-bs4/js/buttons.bootstrap4.min.js"></script>
        <script src="<?php echo $position; ?>assets/libs/datatables.net-buttons/js/buttons.html5.min.js"></script>
        <script src="<?php echo $position; ?>assets/libs/datatables.net-buttons/js/buttons.flash.min.js"></script>
        <script src="<?php echo $position; ?>assets/libs/datatables.net-buttons/js/buttons.print.min.js"></script>
        <script src="<?php echo $position; ?>assets/libs/datatables.net-keytable/js/dataTables.keyTable.min.js"></script>
        <script src="<?php echo $position; ?>assets/libs/datatables.net-select/js/dataTables.select.min.js"></script>
        <script src="<?php echo $position; ?>assets/libs/pdfmake/build/pdfmake.min.js"></script>
        <script src="<?php echo $position; ?>assets/libs/pdfmake/build/vfs_fonts.js"></script>
        <!-- third party js ends -->

        <!-- Datatables init -->
        <script src="<?php echo $position; ?>assets/js/pages/datatables.init.js"></script>
        
    </body>
</html>