Autosave: 20260415-175623

This commit is contained in:
Flatlogic Bot 2026-04-15 17:56:23 +00:00
parent 67e276f3a4
commit bb70c82e6c
26 changed files with 129 additions and 78 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 397 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 KiB

View File

@ -161,8 +161,10 @@ try {
<th>Celular</th> <th>Celular</th>
<th>Producto</th> <th>Producto</th>
<th>Sede de Envío</th> <th>Sede de Envío</th>
<?php if ($user_role !== 'Logistica'): ?>
<th>Monto Total</th> <th>Monto Total</th>
<th>Monto Debe</th> <th>Monto Debe</th>
<?php endif; ?>
<th> De Orden</th> <th> De Orden</th>
<th>Codigo De Orden</th> <th>Codigo De Orden</th>
<th>CLAVE</th> <th>CLAVE</th>
@ -180,8 +182,10 @@ try {
<td><?php echo htmlspecialchars($pedido['celular']); ?></td> <td><?php echo htmlspecialchars($pedido['celular']); ?></td>
<td><?php echo htmlspecialchars($pedido['producto']); ?></td> <td><?php echo htmlspecialchars($pedido['producto']); ?></td>
<td><?php echo htmlspecialchars($pedido['sede_envio'] ?? 'N/A'); ?></td> <td><?php echo htmlspecialchars($pedido['sede_envio'] ?? 'N/A'); ?></td>
<?php if ($user_role !== 'Logistica'): ?>
<td><?php echo htmlspecialchars($pedido['monto_total']); ?></td> <td><?php echo htmlspecialchars($pedido['monto_total']); ?></td>
<td><?php echo htmlspecialchars($pedido['monto_debe']); ?></td> <td><?php echo htmlspecialchars($pedido['monto_debe']); ?></td>
<?php endif; ?>
<td><?php echo htmlspecialchars($pedido['codigo_rastreo'] ?? 'N/A'); ?></td> <td><?php echo htmlspecialchars($pedido['codigo_rastreo'] ?? 'N/A'); ?></td>
<td><?php echo htmlspecialchars($pedido['codigo_tracking'] ?? 'N/A'); ?></td> <td><?php echo htmlspecialchars($pedido['codigo_tracking'] ?? 'N/A'); ?></td>
<td><?php echo htmlspecialchars($pedido['clave'] ?? 'N/A'); ?></td> <td><?php echo htmlspecialchars($pedido['clave'] ?? 'N/A'); ?></td>

View File

@ -167,7 +167,7 @@ include 'layout_header.php';
<td><?php echo htmlspecialchars($pedido['monto_total']); ?></td> <td><?php echo htmlspecialchars($pedido['monto_total']); ?></td>
<td><?php echo htmlspecialchars($pedido['monto_debe']); ?></td> <td><?php echo htmlspecialchars($pedido['monto_debe']); ?></td>
<td><?php echo htmlspecialchars($pedido['numero_operacion'] ?? 'N/A'); ?></td> <td><?php echo htmlspecialchars($pedido['numero_operacion'] ?? 'N/A'); ?></td>
<td <?php if (in_array($user_role, ['Administrador', 'personal', 'Verificador de Pagos']) || strpos($user_role, 'Asesor') !== false) { echo 'class="editable-recojo" data-id="'.$pedido['id'].'" title="Doble clic para editar"'; } ?>> <td <?php if (in_array($user_role, ['Administrador', 'personal', 'Verificador de Pagos', 'Control Logistico', 'Logistica']) || strpos($user_role, 'Asesor') !== false) { echo 'class="editable-recojo" data-id="'.$pedido['id'].'" title="Doble clic para editar"'; } ?>>
<?php echo !empty($pedido['fecha_recojo']) ? htmlspecialchars($pedido['fecha_recojo']) : 'N/A'; ?> <?php echo !empty($pedido['fecha_recojo']) ? htmlspecialchars($pedido['fecha_recojo']) : 'N/A'; ?>
</td> </td>
<td><span class="badge" style="<?php echo getStatusStyle($pedido['estado']); ?>"><?php echo ($pedido['estado'] == 'Gestion') ? 'GESTIONES ⚙️' : htmlspecialchars($pedido['estado']); ?></span></td> <td><span class="badge" style="<?php echo getStatusStyle($pedido['estado']); ?>"><?php echo ($pedido['estado'] == 'Gestion') ? 'GESTIONES ⚙️' : htmlspecialchars($pedido['estado']); ?></span></td>
@ -219,7 +219,7 @@ include 'layout_header.php';
</td> </td>
<td> <td>
<a href="pedido_form.php?id=<?php echo $pedido['id']; ?>" class="btn btn-sm btn-warning">Editar</a> <a href="pedido_form.php?id=<?php echo $pedido['id']; ?>" class="btn btn-sm btn-warning">Editar</a>
<?php if ($user_role === 'Administrador'): ?> <?php if ($user_role === 'Administrador' || $user_role === 'Logistica'): ?>
<a href="delete_pedido.php?id=<?php echo $pedido['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('¿Estás seguro de que quieres eliminar este pedido?');">Eliminar</a> <a href="delete_pedido.php?id=<?php echo $pedido['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('¿Estás seguro de que quieres eliminar este pedido?');">Eliminar</a>
<?php endif; ?> <?php endif; ?>
</td> </td>
@ -282,7 +282,7 @@ function updateEstadoPago(pedidoId, selectElement) {
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
const userRole = "<?php echo $user_role; ?>"; const userRole = "<?php echo $user_role; ?>";
const authorizedRoles = ['Administrador', 'personal', 'Verificador de Pagos']; const authorizedRoles = ['Administrador', 'personal', 'Verificador de Pagos', 'Control Logistico', 'Logistica'];
if (authorizedRoles.includes(userRole) || userRole.includes('Asesor')) { if (authorizedRoles.includes(userRole) || userRole.includes('Asesor')) {
const table = document.querySelector('.table'); const table = document.querySelector('.table');

View File

@ -63,7 +63,7 @@ $estados = ['RUTA_CONTRAENTREGA', 'RETORNADO', 'ENTREGA EXITOSA', 'ROTULADO 📦
$asesor_data = []; $asesor_data = [];
$chart_data = []; $chart_data = [];
if ($user_role === 'Administrador' || $user_role === 'Control Logistico' || $user_role === 'Asesor') { if ($user_role === 'Administrador' || $user_role === 'Control Logistico' || $user_role === 'Logistica' || $user_role === 'Asesor') {
// 1. Obtener todos los asesores // 1. Obtener todos los asesores
$stmt_asesores = $pdo->query("SELECT id, username, nombre_asesor FROM users WHERE role = 'Asesor'"); $stmt_asesores = $pdo->query("SELECT id, username, nombre_asesor FROM users WHERE role = 'Asesor'");
$asesores = $stmt_asesores->fetchAll(PDO::FETCH_ASSOC); $asesores = $stmt_asesores->fetchAll(PDO::FETCH_ASSOC);
@ -195,7 +195,7 @@ if ($user_role === 'Administrador' || $user_role === 'Control Logistico' || $use
// TABLA DE PEDIDOS POR DÍA Y ASESORA (TIPO EXCEL) // TABLA DE PEDIDOS POR DÍA Y ASESORA (TIPO EXCEL)
$pedidos_mensual_asesora = []; $pedidos_mensual_asesora = [];
$asesoras_mensual = []; $asesoras_mensual = [];
if ($user_role === 'Administrador' || $user_role === 'Control Logistico' || $user_role === 'Asesor') { if ($user_role === 'Administrador' || $user_role === 'Control Logistico' || $user_role === 'Logistica' || $user_role === 'Asesor') {
// 1. Obtener todas las asesoras // 1. Obtener todas las asesoras
$stmt_asesoras = $pdo->query("SELECT id, nombre_asesor FROM users WHERE role = 'Asesor' AND nombre_asesor IS NOT NULL AND nombre_asesor != ''"); $stmt_asesoras = $pdo->query("SELECT id, nombre_asesor FROM users WHERE role = 'Asesor' AND nombre_asesor IS NOT NULL AND nombre_asesor != ''");
$asesoras_mensual = $stmt_asesoras->fetchAll(PDO::FETCH_ASSOC); $asesoras_mensual = $stmt_asesoras->fetchAll(PDO::FETCH_ASSOC);
@ -473,7 +473,7 @@ if ($user_role === 'Administrador' || $user_role === 'Control Logistico' || $use
</div> </div>
<?php endif; ?> <?php endif; ?>
<?php if (($user_role === 'Administrador' || $user_role === 'Control Logistico' || $user_role === 'Asesor')): ?> <?php if (($user_role === 'Administrador' || $user_role === 'Control Logistico' || $user_role === 'Logistica' || $user_role === 'Asesor')): ?>
<!-- Reporte Mensual de Pedidos por Asesora --> <!-- Reporte Mensual de Pedidos por Asesora -->
<div class="card shadow mb-4"> <div class="card shadow mb-4">
<div class="card-header py-3"> <div class="card-header py-3">
@ -535,7 +535,7 @@ if ($user_role === 'Administrador' || $user_role === 'Control Logistico' || $use
</div> </div>
<?php endif; ?> <?php endif; ?>
<?php if ($user_role === 'Administrador' || $user_role === 'Control Logistico' || $user_role === 'Asesor'): ?> <?php if ($user_role === 'Administrador' || $user_role === 'Control Logistico' || $user_role === 'Logistica' || $user_role === 'Asesor'): ?>
<!-- Gráfico de Rendimiento de Asesores --> <!-- Gráfico de Rendimiento de Asesores -->
<div class="card shadow mb-4"> <div class="card shadow mb-4">
<div class="card-header py-3"> <div class="card-header py-3">
@ -649,7 +649,7 @@ $selected_month] . ' ' . $selected_year; ?>)</h6>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script> <script>
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function() {
<?php if (($user_role === 'Administrador' || $user_role === 'Control Logistico' || $user_role === 'Asesor') && !empty($chart_data['labels'])): <?php if (($user_role === 'Administrador' || $user_role === 'Control Logistico' || $user_role === 'Logistica' || $user_role === 'Asesor') && !empty($chart_data['labels'])):
?> ?>
const adminCtx = document.getElementById('adminChart').getContext('2d'); const adminCtx = document.getElementById('adminChart').getContext('2d');
new Chart(adminCtx, { new Chart(adminCtx, {

View File

@ -2,8 +2,8 @@
session_start(); session_start();
header('Content-Type: application/json'); header('Content-Type: application/json');
// Check if user is logged in // Check if user is logged in and is an Administrador, admin, Control Logistico or Logistica
if (!isset($_SESSION['user_id'])) { if (!isset($_SESSION['user_id']) || !in_array($_SESSION['user_role'], ['Administrador', 'admin', 'Control Logistico', 'Logistica'])) {
echo json_encode(['success' => false, 'error' => 'No autorizado']); echo json_encode(['success' => false, 'error' => 'No autorizado']);
exit; exit;
} }

View File

@ -3,7 +3,7 @@ session_start();
require_once 'db/config.php'; require_once 'db/config.php';
// Check if user is logged in and is an Administrador // Check if user is logged in and is an Administrador
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'Administrador') { if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'Administrador') {
header('Location: login.php'); header('Location: login.php');
exit; exit;
} }

View File

@ -2,8 +2,8 @@
session_start(); session_start();
require_once 'db/config.php'; require_once 'db/config.php';
// Check if user is logged in and is an Administrador // Check if user is logged in and is an Administrador, admin, Control Logistico or Logistica
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'Administrador') { if (!isset($_SESSION['user_id']) || !in_array($_SESSION['user_role'], ['Administrador', 'admin', 'Control Logistico', 'Logistica'])) {
header('Location: login.php'); header('Location: login.php');
exit; exit;
} }

View File

@ -202,7 +202,7 @@ include 'layout_header.php';
</td> </td>
<td> <td>
<a href="pedido_form.php?id=<?php echo $pedido['id']; ?>" class="btn btn-sm btn-warning">Editar</a> <a href="pedido_form.php?id=<?php echo $pedido['id']; ?>" class="btn btn-sm btn-warning">Editar</a>
<?php if ($user_role === 'Administrador'): ?> <?php if ($user_role === 'Administrador' || $user_role === 'Logistica'): ?>
<a href="delete_pedido.php?id=<?php echo $pedido['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('¿Estás seguro de que quieres eliminar este pedido?');">Eliminar</a> <a href="delete_pedido.php?id=<?php echo $pedido['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('¿Estás seguro de que quieres eliminar este pedido?');">Eliminar</a>
<?php endif; ?> <?php endif; ?>
</td> </td>

View File

@ -4,6 +4,7 @@ require_once 'db/config.php';
header('Content-Type: application/json'); header('Content-Type: application/json');
$productId = isset($_GET['product_id']) ? (int)$_GET['product_id'] : 0; $productId = isset($_GET['product_id']) ? (int)$_GET['product_id'] : 0;
$sedeId = isset($_GET['sede_id']) ? (int)$_GET['sede_id'] : 0;
if ($productId <= 0) { if ($productId <= 0) {
echo json_encode([]); echo json_encode([]);
@ -12,12 +13,22 @@ if ($productId <= 0) {
try { try {
$db = db(); $db = db();
$stmt = $db->prepare(
"SELECT codigo_unico, estado $query = "SELECT codigo_unico, estado
FROM unidades_inventario FROM unidades_inventario
WHERE producto_id = :product_id AND estado = 'En Almacén'" WHERE producto_id = :product_id AND estado = 'En Almacén'";
);
if ($sedeId > 0) {
$query .= " AND sede_id = :sede_id";
}
$stmt = $db->prepare($query);
$stmt->bindParam(':product_id', $productId, PDO::PARAM_INT); $stmt->bindParam(':product_id', $productId, PDO::PARAM_INT);
if ($sedeId > 0) {
$stmt->bindParam(':sede_id', $sedeId, PDO::PARAM_INT);
}
$stmt->execute(); $stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC); $results = $stmt->fetchAll(PDO::FETCH_ASSOC);

View File

@ -42,7 +42,7 @@ $navItems = [
'url' => 'buscador_general.php', 'url' => 'buscador_general.php',
'icon' => 'fa-search', 'icon' => 'fa-search',
'text' => 'Buscador General', 'text' => 'Buscador General',
'roles' => ['Administrador', 'admin', 'Asesor', 'Control Logistico', 'Soporte Logistico', 'Verificador de Pagos'] 'roles' => ['Administrador', 'admin', 'Asesor', 'Control Logistico', 'Logistica', 'Soporte Logistico', 'Verificador de Pagos']
], ],
'completados' => [ 'completados' => [
'url' => 'completados.php', 'url' => 'completados.php',
@ -66,7 +66,7 @@ $navItems = [
'url' => 'pedidos.php', 'url' => 'pedidos.php',
'icon' => 'fa-clipboard-list', 'icon' => 'fa-clipboard-list',
'text' => 'Pedidos Rotulados', 'text' => 'Pedidos Rotulados',
'roles' => ['Administrador', 'admin', 'Asesor', 'Control Logistico'] 'roles' => ['Administrador', 'admin', 'Asesor', 'Control Logistico', 'Logistica']
], ],
'agregar_pedido' => [ 'agregar_pedido' => [
'url' => 'pedido_form.php', 'url' => 'pedido_form.php',
@ -84,78 +84,84 @@ $navItems = [
'url' => 'ruta_contraentrega.php', 'url' => 'ruta_contraentrega.php',
'icon' => 'fa-route', 'icon' => 'fa-route',
'text' => 'Ruta Contraentrega', 'text' => 'Ruta Contraentrega',
'roles' => ['Administrador', 'admin', 'Asesor', 'Control Logistico', 'Soporte Logistico'] 'roles' => ['Administrador', 'admin', 'Asesor', 'Control Logistico', 'Logistica', 'Soporte Logistico']
], ],
'inventario_group' => [ 'inventario_group' => [
'icon' => 'fa-warehouse', 'icon' => 'fa-warehouse',
'text' => 'Inventario General', 'text' => 'Inventario General',
'roles' => ['Administrador', 'admin', 'Control Logistico'], 'roles' => ['Administrador', 'admin', 'Control Logistico', 'Logistica'],
'submenu' => [ 'submenu' => [
'panel_inventario' => [ 'panel_inventario' => [
'url' => 'panel_inventario.php', 'url' => 'panel_inventario.php',
'icon' => 'fa-warehouse', 'icon' => 'fa-warehouse',
'text' => 'Inventario General', 'text' => 'Inventario General',
'roles' => ['Administrador', 'admin', 'Control Logistico'] 'roles' => ['Administrador', 'admin', 'Control Logistico', 'Logistica']
],
'ingreso_mercaderia' => [
'url' => 'registro_entrada.php',
'icon' => 'fa-plus-square',
'text' => 'Ingreso Mercaderia',
'roles' => ['Administrador', 'admin', 'Control Logistico', 'Logistica']
], ],
'buscador_inventario' => [ 'buscador_inventario' => [
'url' => 'buscador_inventario.php', 'url' => 'buscador_inventario.php',
'icon' => 'fa-search-dollar', 'icon' => 'fa-search-dollar',
'text' => 'Buscador de Unidades', 'text' => 'Buscador de Unidades',
'roles' => ['Administrador', 'admin', 'Control Logistico', 'Asesor', 'Soporte Logistico'] 'roles' => ['Administrador', 'admin', 'Control Logistico', 'Logistica', 'Asesor', 'Soporte Logistico']
], ],
'inventario_por_sede' => [ 'inventario_por_sede' => [
'url' => 'inventario_por_sede.php', 'url' => 'inventario_por_sede.php',
'icon' => 'fa-search-location', 'icon' => 'fa-search-location',
'text' => 'Auditoría por Sede', 'text' => 'Auditoría por Sede',
'roles' => ['Administrador', 'admin', 'Control Logistico'] 'roles' => ['Administrador', 'admin', 'Control Logistico', 'Logistica']
], ],
'generar_etiquetas' => [ 'generar_etiquetas' => [
'url' => 'generar_etiquetas.php', 'url' => 'generar_etiquetas.php',
'icon' => 'fa-barcode', 'icon' => 'fa-barcode',
'text' => 'Etiquetas', 'text' => 'Etiquetas',
'roles' => ['Administrador', 'admin', 'Control Logistico'] 'roles' => ['Administrador', 'admin', 'Control Logistico', 'Logistica']
], ],
'registro_entrada' => [ 'registro_entrada' => [
'url' => 'registro_entrada.php', 'url' => 'registro_entrada.php',
'icon' => 'fa-arrow-circle-down', 'icon' => 'fa-arrow-circle-down',
'text' => 'Registro de Entrada', 'text' => 'Registro de Entrada',
'roles' => ['Administrador', 'admin', 'Control Logistico'] 'roles' => ['Administrador', 'admin', 'Control Logistico', 'Logistica']
], ],
'registro_salida' => [ 'registro_salida' => [
'url' => 'registro_salida.php', 'url' => 'registro_salida.php',
'icon' => 'fa-arrow-circle-up', 'icon' => 'fa-arrow-circle-up',
'text' => 'Registro de Salida', 'text' => 'Registro de Salida',
'roles' => ['Administrador', 'admin', 'Control Logistico'] 'roles' => ['Administrador', 'admin', 'Control Logistico', 'Logistica']
], ],
'sede' => [ 'sede' => [
'url' => 'sedes.php', 'url' => 'sedes.php',
'icon' => 'fa-building', 'icon' => 'fa-building',
'text' => 'Sede', 'text' => 'Sede',
'roles' => ['Administrador', 'admin', 'Control Logistico'] 'roles' => ['Administrador', 'admin', 'Control Logistico', 'Logistica']
], ],
'resumen_stock' => [ 'resumen_stock' => [
'url' => '#', 'url' => '#',
'icon' => 'fa-chart-bar', 'icon' => 'fa-chart-bar',
'text' => 'Resumen de stock', 'text' => 'Resumen de stock',
'roles' => ['Administrador', 'admin', 'Control Logistico'] 'roles' => ['Administrador', 'admin', 'Control Logistico', 'Logistica']
], ],
'agregar_producto' => [ 'agregar_producto' => [
'url' => 'agregar_producto.php', 'url' => 'agregar_producto.php',
'icon' => 'fa-plus', 'icon' => 'fa-plus',
'text' => 'Agregar Producto', 'text' => 'Agregar Producto',
'roles' => ['Administrador', 'admin', 'Control Logistico'] 'roles' => ['Administrador', 'admin', 'Control Logistico', 'Logistica']
], ],
'productos' => [ 'productos' => [
'url' => 'productos.php', 'url' => 'productos.php',
'icon' => 'fa-box', 'icon' => 'fa-box',
'text' => 'Productos', 'text' => 'Productos',
'roles' => ['Administrador', 'admin', 'Control Logistico'] 'roles' => ['Administrador', 'admin', 'Control Logistico', 'Logistica']
], ],
'liquidaciones_provincia' => [ 'liquidaciones_provincia' => [
'url' => 'liquidaciones_provincia.php', 'url' => 'liquidaciones_provincia.php',
'icon' => 'fa-file-invoice-dollar', 'icon' => 'fa-file-invoice-dollar',
'text' => 'Liquidaciones Provincia', 'text' => 'Liquidaciones Provincia',
'roles' => ['Administrador', 'admin', 'Control Logistico'] 'roles' => ['Administrador', 'admin', 'Control Logistico', 'Logistica']
] ]
] ]
], ],

View File

@ -155,6 +155,7 @@ include 'layout_header.php';
<option value="Control Logistico">Control Logístico</option> <option value="Control Logistico">Control Logístico</option>
<option value="Soporte Logistico">Soporte Logístico</option> <option value="Soporte Logistico">Soporte Logístico</option>
<option value="Verificador de Pagos">Verificador de Pagos</option> <option value="Verificador de Pagos">Verificador de Pagos</option>
<option value="Logistica">Logistica</option>
</select> </select>
</div> </div>
<button type="submit" name="create_user" class="btn btn-primary w-100">Crear Usuario</button> <button type="submit" name="create_user" class="btn btn-primary w-100">Crear Usuario</button>
@ -239,6 +240,7 @@ include 'layout_header.php';
<option value="Control Logistico">Control Logístico</option> <option value="Control Logistico">Control Logístico</option>
<option value="Soporte Logistico">Soporte Logístico</option> <option value="Soporte Logistico">Soporte Logístico</option>
<option value="Verificador de Pagos">Verificador de Pagos</option> <option value="Verificador de Pagos">Verificador de Pagos</option>
<option value="Logistica">Logistica</option>
</select> </select>
</div> </div>
</div> </div>

View File

@ -7,7 +7,7 @@ if (!isset($_SESSION['user_id'])) {
// Role check for inventory panel // Role check for inventory panel
$userRole = $_SESSION['user_role'] ?? ''; $userRole = $_SESSION['user_role'] ?? '';
$allowedRoles = ['Administrador', 'admin', 'Control Logistico']; $allowedRoles = ['Administrador', 'admin', 'Control Logistico', 'Logistica'];
if (!in_array($userRole, $allowedRoles)) { if (!in_array($userRole, $allowedRoles)) {
header('Location: dashboard.php?error=access_denied'); header('Location: dashboard.php?error=access_denied');
exit(); exit();
@ -64,7 +64,7 @@ try {
$colores_sedes = []; $colores_sedes = [];
$colores_default = ['#FF6384', '#FFCE56', '#4BC0C0', '#9966FF', '#FF9F40']; $colores_default = ['#FF6384', '#FFCE56', '#4BC0C0', '#9966FF', '#FF9F40'];
$color_map = [ $color_map = [
'Almacen Principal' => '#28a745', // Verde 'ALMACEN PR' => '#28a745', // Verde
'ALIDRV' => '#FFCE56', // Amarillo 'ALIDRV' => '#FFCE56', // Amarillo
'LIMA' => '#36A2EB' // Azul 'LIMA' => '#36A2EB' // Azul
]; ];

View File

@ -48,8 +48,8 @@ if (isset($_GET['id'])) {
die('Acceso denegado. No tienes permiso para editar este pedido.'); die('Acceso denegado. No tienes permiso para editar este pedido.');
} }
} else { } else {
// Security check: Only Administradors and asesores can create new pedidos // Security check: Only Administradors, Logistica and asesores can create new pedidos
if ($user_role !== 'Administrador' && $user_role !== 'Asesor') { if ($user_role !== 'Administrador' && $user_role !== 'Logistica' && $user_role !== 'Asesor') {
die('Acceso denegado. No tienes permiso para crear nuevos pedidos.'); die('Acceso denegado. No tienes permiso para crear nuevos pedidos.');
} }
} }
@ -57,7 +57,7 @@ if (isset($_GET['id'])) {
// Fetch asesores or the current asesor's name // Fetch asesores or the current asesor's name
$asesores = []; $asesores = [];
$current_asesor_nombre = ''; $current_asesor_nombre = '';
if ($user_role === 'Administrador') { if ($user_role === 'Administrador' || $user_role === 'Logistica') {
$stmt_asesores = $pdo->query("SELECT id, nombre_asesor FROM users WHERE role = 'Asesor' ORDER BY nombre_asesor"); $stmt_asesores = $pdo->query("SELECT id, nombre_asesor FROM users WHERE role = 'Asesor' ORDER BY nombre_asesor");
$asesores = $stmt_asesores->fetchAll(); $asesores = $stmt_asesores->fetchAll();
} else if ($user_role === 'Asesor') { } else if ($user_role === 'Asesor') {
@ -93,7 +93,7 @@ include 'layout_header.php';
<input type="hidden" name="referer" value="<?php echo htmlspecialchars($_SERVER['HTTP_REFERER'] ?? 'pedidos.php'); ?>"> <input type="hidden" name="referer" value="<?php echo htmlspecialchars($_SERVER['HTTP_REFERER'] ?? 'pedidos.php'); ?>">
<!-- Asesor ID handling --> <!-- Asesor ID handling -->
<?php if ($user_role === 'Administrador'): ?> <?php if ($user_role === 'Administrador' || $user_role === 'Logistica'): ?>
<div class="mb-3"> <div class="mb-3">
<label for="asesor_id" class="form-label">Asesor Responsable</label> <label for="asesor_id" class="form-label">Asesor Responsable</label>
<select class="form-select" id="asesor_id" name="asesor_id" required> <select class="form-select" id="asesor_id" name="asesor_id" required>
@ -187,6 +187,7 @@ include 'layout_header.php';
<hr> <hr>
<div class="row"> <div class="row">
<?php if ($user_role !== 'Logistica'): ?>
<div class="col-md-3 mb-3"> <div class="col-md-3 mb-3">
<label for="monto_total" class="form-label">Monto Total</label> <label for="monto_total" class="form-label">Monto Total</label>
<input type="number" step="0.01" class="form-control" id="monto_total" name="monto_total" value="<?php echo htmlspecialchars($pedido['monto_total']); ?>" required> <input type="number" step="0.01" class="form-control" id="monto_total" name="monto_total" value="<?php echo htmlspecialchars($pedido['monto_total']); ?>" required>
@ -195,6 +196,10 @@ include 'layout_header.php';
<label for="monto_adelantado" class="form-label">Monto Adelantado</label> <label for="monto_adelantado" class="form-label">Monto Adelantado</label>
<input type="number" step="0.01" class="form-control" id="monto_adelantado" name="monto_adelantado" value="<?php echo htmlspecialchars($pedido['monto_adelantado']); ?>"> <input type="number" step="0.01" class="form-control" id="monto_adelantado" name="monto_adelantado" value="<?php echo htmlspecialchars($pedido['monto_adelantado']); ?>">
</div> </div>
<?php else: ?>
<input type="hidden" name="monto_total" value="<?php echo htmlspecialchars($pedido['monto_total']); ?>">
<input type="hidden" name="monto_adelantado" value="<?php echo htmlspecialchars($pedido['monto_adelantado']); ?>">
<?php endif; ?>
<div class="col-md-3 mb-3"> <div class="col-md-3 mb-3">
<label for="numero_operacion" class="form-label">Número de Operación</label> <label for="numero_operacion" class="form-label">Número de Operación</label>
<input type="text" class="form-control" id="numero_operacion" name="numero_operacion" value="<?php echo htmlspecialchars($pedido['numero_operacion'] ?? ''); ?>"> <input type="text" class="form-control" id="numero_operacion" name="numero_operacion" value="<?php echo htmlspecialchars($pedido['numero_operacion'] ?? ''); ?>">

View File

@ -135,7 +135,7 @@ include 'layout_header.php';
<div class="col-auto mt-4"> <div class="col-auto mt-4">
<button type="submit" class="btn btn-info">Filtrar</button> <button type="submit" class="btn btn-info">Filtrar</button>
<a href="pedidos.php" class="btn btn-secondary">Limpiar</a> <a href="pedidos.php" class="btn btn-secondary">Limpiar</a>
<?php if ($user_role === 'Administrador'): ?> <?php if ($user_role === 'Administrador' || $user_role === 'Logistica'): ?>
<a href="download_report.php" class="btn btn-success">Descargar Todos los Rotulados</a> <a href="download_report.php" class="btn btn-success">Descargar Todos los Rotulados</a>
<?php endif; ?> <?php endif; ?>
</div> </div>
@ -156,8 +156,10 @@ include 'layout_header.php';
<th>Producto</th> <th>Producto</th>
<th>Sede de Envío</th> <th>Sede de Envío</th>
<th>Cantidad</th> <th>Cantidad</th>
<?php if ($user_role !== 'Logistica'): ?>
<th>Monto Total</th> <th>Monto Total</th>
<th>Monto Debe</th> <th>Monto Debe</th>
<?php endif; ?>
<th> De Orden</th> <th> De Orden</th>
<th>Codigo De Orden</th> <th>Codigo De Orden</th>
<th>CLAVE</th> <th>CLAVE</th>
@ -178,8 +180,10 @@ include 'layout_header.php';
<td><?php echo htmlspecialchars($pedido['producto']); ?></td> <td><?php echo htmlspecialchars($pedido['producto']); ?></td>
<td><?php echo htmlspecialchars($pedido['sede_envio'] ?? 'N/A'); ?></td> <td><?php echo htmlspecialchars($pedido['sede_envio'] ?? 'N/A'); ?></td>
<td><?php echo htmlspecialchars($pedido['cantidad'] ?? '1'); ?></td> <td><?php echo htmlspecialchars($pedido['cantidad'] ?? '1'); ?></td>
<?php if ($user_role !== 'Logistica'): ?>
<td><?php echo htmlspecialchars($pedido['monto_total']); ?></td> <td><?php echo htmlspecialchars($pedido['monto_total']); ?></td>
<td><?php echo htmlspecialchars($pedido['monto_debe']); ?></td> <td><?php echo htmlspecialchars($pedido['monto_debe']); ?></td>
<?php endif; ?>
<td class="editable" data-id="<?php echo $pedido['id']; ?>" data-field="codigo_rastreo"><?php echo htmlspecialchars($pedido['codigo_rastreo'] ?? 'N/A'); ?></td> <td class="editable" data-id="<?php echo $pedido['id']; ?>" data-field="codigo_rastreo"><?php echo htmlspecialchars($pedido['codigo_rastreo'] ?? 'N/A'); ?></td>
<td class="editable" data-id="<?php echo $pedido['id']; ?>" data-field="codigo_tracking"><?php echo htmlspecialchars($pedido['codigo_tracking'] ?? 'N/A'); ?></td> <td class="editable" data-id="<?php echo $pedido['id']; ?>" data-field="codigo_tracking"><?php echo htmlspecialchars($pedido['codigo_tracking'] ?? 'N/A'); ?></td>
<td class="editable" data-id="<?php echo $pedido['id']; ?>" data-field="clave"><?php echo htmlspecialchars($pedido['clave'] ?? 'N/A'); ?></td> <td class="editable" data-id="<?php echo $pedido['id']; ?>" data-field="clave"><?php echo htmlspecialchars($pedido['clave'] ?? 'N/A'); ?></td>
@ -195,7 +199,7 @@ include 'layout_header.php';
</td> </td>
<td> <td>
<a href="pedido_form.php?id=<?php echo $pedido['id']; ?>" class="btn btn-sm btn-warning">Editar</a> <a href="pedido_form.php?id=<?php echo $pedido['id']; ?>" class="btn btn-sm btn-warning">Editar</a>
<?php if ($user_role === 'Administrador'): ?> <?php if ($user_role === 'Administrador' || $user_role === 'Logistica'): ?>
<a href="delete_pedido.php?id=<?php echo $pedido['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('¿Estás seguro de que quieres eliminar este pedido?');">Eliminar</a> <a href="delete_pedido.php?id=<?php echo $pedido['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('¿Estás seguro de que quieres eliminar este pedido?');">Eliminar</a>
<?php endif; ?> <?php endif; ?>
</td> </td>

View File

@ -187,6 +187,7 @@ include 'layout_header.php';
<hr> <hr>
<div class="row"> <div class="row">
<?php if ($user_role !== 'Logistica'): ?>
<div class="col-md-3 mb-3"> <div class="col-md-3 mb-3">
<label for="monto_total" class="form-label">Monto Total</label> <label for="monto_total" class="form-label">Monto Total</label>
<input type="number" step="0.01" class="form-control" id="monto_total" name="monto_total" value="<?php echo htmlspecialchars($pedido['monto_total']); ?>" required> <input type="number" step="0.01" class="form-control" id="monto_total" name="monto_total" value="<?php echo htmlspecialchars($pedido['monto_total']); ?>" required>
@ -195,6 +196,10 @@ include 'layout_header.php';
<label for="monto_adelantado" class="form-label">Monto Adelantado</label> <label for="monto_adelantado" class="form-label">Monto Adelantado</label>
<input type="number" step="0.01" class="form-control" id="monto_adelantado" name="monto_adelantado" value="<?php echo htmlspecialchars($pedido['monto_adelantado']); ?>"> <input type="number" step="0.01" class="form-control" id="monto_adelantado" name="monto_adelantado" value="<?php echo htmlspecialchars($pedido['monto_adelantado']); ?>">
</div> </div>
<?php else: ?>
<input type="hidden" name="monto_total" value="<?php echo htmlspecialchars($pedido['monto_total']); ?>">
<input type="hidden" name="monto_adelantado" value="<?php echo htmlspecialchars($pedido['monto_adelantado']); ?>">
<?php endif; ?>
<div class="col-md-3 mb-3"> <div class="col-md-3 mb-3">
<label for="numero_operacion" class="form-label">Número de Operación</label> <label for="numero_operacion" class="form-label">Número de Operación</label>
<input type="text" class="form-control" id="numero_operacion" name="numero_operacion" value="<?php echo htmlspecialchars($pedido['numero_operacion'] ?? ''); ?>"> <input type="text" class="form-control" id="numero_operacion" name="numero_operacion" value="<?php echo htmlspecialchars($pedido['numero_operacion'] ?? ''); ?>">

View File

@ -32,9 +32,9 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
throw new Exception("Esta unidad ya fue vendida y no puede ser ingresada nuevamente."); throw new Exception("Esta unidad ya fue vendida y no puede ser ingresada nuevamente.");
} }
// 2. Actualizar el estado de la unidad // 2. Actualizar el estado de la unidad y la sede
$update_unidad_stmt = $pdo->prepare("UPDATE unidades_inventario SET estado = 'En Almacén', fecha_ingreso = :fecha_ingreso WHERE id = :id"); $update_unidad_stmt = $pdo->prepare("UPDATE unidades_inventario SET estado = 'En Almacén', sede_id = :sede_id, fecha_ingreso = :fecha_ingreso WHERE id = :id");
$update_unidad_stmt->execute(['fecha_ingreso' => $movement_date, 'id' => $unidad['id']]); $update_unidad_stmt->execute(['sede_id' => $sede_id, 'fecha_ingreso' => $movement_date, 'id' => $unidad['id']]);
$product_id = $unidad['producto_id']; $product_id = $unidad['producto_id'];
$quantity = 1; $quantity = 1;

View File

@ -14,9 +14,9 @@ try {
$sedes_stmt = $pdo->query("SELECT id, nombre FROM sedes ORDER BY nombre ASC"); $sedes_stmt = $pdo->query("SELECT id, nombre FROM sedes ORDER BY nombre ASC");
$sedes = $sedes_stmt->fetchAll(PDO::FETCH_ASSOC); $sedes = $sedes_stmt->fetchAll(PDO::FETCH_ASSOC);
// Encontrar el ID de "ALMACEN PRINCIPAL" para la lógica móvil // Encontrar el ID de "ALMACEN PR" para la lógica móvil
foreach ($sedes as $sede) { foreach ($sedes as $sede) {
if (trim(strtolower($sede['nombre'])) === 'almacen principal') { if (trim(strtolower($sede['nombre'])) === 'almacen pr') {
$almacen_principal_id = $sede['id']; $almacen_principal_id = $sede['id'];
break; break;
} }

View File

@ -194,8 +194,10 @@ include 'layout_header.php';
<th>Coordenadas</th> <th>Coordenadas</th>
<th>Producto</th> <th>Producto</th>
<th>Cantidad</th> <th>Cantidad</th>
<?php if ($user_role !== 'Logistica'): ?>
<th>Monto Total</th> <th>Monto Total</th>
<th>Monto Debe</th> <th>Monto Debe</th>
<?php endif; ?>
<th>Estado</th> <th>Estado</th>
<th>Fecha de Entrega</th> <th>Fecha de Entrega</th>
<?php if ($user_role !== 'Asesor'): ?><th>Asesor</th><?php endif; ?> <?php if ($user_role !== 'Asesor'): ?><th>Asesor</th><?php endif; ?>
@ -257,8 +259,10 @@ include 'layout_header.php';
<td><?php echo htmlspecialchars($pedido['coordenadas'] ?? 'N/A'); ?></td> <td><?php echo htmlspecialchars($pedido['coordenadas'] ?? 'N/A'); ?></td>
<td><?php echo htmlspecialchars($pedido['producto']); ?></td> <td><?php echo htmlspecialchars($pedido['producto']); ?></td>
<td><?php echo htmlspecialchars($pedido['cantidad']); ?></td> <td><?php echo htmlspecialchars($pedido['cantidad']); ?></td>
<?php if ($user_role !== 'Logistica'): ?>
<td><?php echo htmlspecialchars($pedido['monto_total']); ?></td> <td><?php echo htmlspecialchars($pedido['monto_total']); ?></td>
<td><?php echo htmlspecialchars($pedido['monto_debe']); ?></td> <td><?php echo htmlspecialchars($pedido['monto_debe']); ?></td>
<?php endif; ?>
<td><span class="badge" style="<?php echo getStatusStyle($pedido['estado']); ?>"><?php echo htmlspecialchars($pedido['estado']); ?></span></td> <td><span class="badge" style="<?php echo getStatusStyle($pedido['estado']); ?>"><?php echo htmlspecialchars($pedido['estado']); ?></span></td>
<td><span class="badge" style="<?php echo getFechaEntregaStyle($pedido['fecha_entrega']); ?>"><?php echo htmlspecialchars(!empty($pedido['fecha_entrega']) && $pedido['fecha_entrega'] != '0000-00-00' ? date('d/m/Y', strtotime($pedido['fecha_entrega'])) : 'N/A'); ?></span></td> <td><span class="badge" style="<?php echo getFechaEntregaStyle($pedido['fecha_entrega']); ?>"><?php echo htmlspecialchars(!empty($pedido['fecha_entrega']) && $pedido['fecha_entrega'] != '0000-00-00' ? date('d/m/Y', strtotime($pedido['fecha_entrega'])) : 'N/A'); ?></span></td>
<?php if ($user_role !== 'Asesor'): ?><td><?php echo htmlspecialchars($pedido['asesor_nombre'] ?? 'N/A'); ?></td><?php endif; ?> <?php if ($user_role !== 'Asesor'): ?><td><?php echo htmlspecialchars($pedido['asesor_nombre'] ?? 'N/A'); ?></td><?php endif; ?>
@ -295,7 +299,11 @@ $(document).ready(function() {
"language": { "language": {
"url": "//cdn.datatables.net/plug-ins/1.10.25/i18n/Spanish.json" "url": "//cdn.datatables.net/plug-ins/1.10.25/i18n/Spanish.json"
}, },
"order": [[ <?php echo ($user_role !== 'Asesor' ? 16 : 15); ?>, "desc" ]], "order": [[ <?php
$orderCol = ($user_role !== 'Asesor' ? 16 : 15);
if ($user_role === 'Logistica') $orderCol -= 2;
echo $orderCol;
?>, "desc" ]],
"paging": false, "paging": false,
"lengthChange": false, "lengthChange": false,
"info": false "info": false

View File

@ -162,7 +162,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
} }
// Conditionally add asesor_id // Conditionally add asesor_id
if ($user_role === 'Administrador' && !empty($_POST['asesor_id'])) { if (($user_role === 'Administrador' || $user_role === 'Logistica') && !empty($_POST['asesor_id'])) {
$sql_parts[] = "asesor_id = :asesor_id"; $sql_parts[] = "asesor_id = :asesor_id";
$params['asesor_id'] = $_POST['asesor_id']; $params['asesor_id'] = $_POST['asesor_id'];
} }

View File

@ -2,6 +2,12 @@
session_start(); session_start();
require_once 'db/config.php'; require_once 'db/config.php';
// Check if user is logged in and is an Administrador, admin, Control Logistico or Logistica
if (!isset($_SESSION['user_id']) || !in_array($_SESSION['user_role'], ['Administrador', 'admin', 'Control Logistico', 'Logistica'])) {
header('Location: login.php');
exit;
}
// Función para generar el código base a partir de las iniciales // Función para generar el código base a partir de las iniciales
function generar_codigo_base($nombre) { function generar_codigo_base($nombre) {
$palabras = explode(' ', trim($nombre)); $palabras = explode(' ', trim($nombre));

View File

@ -1,6 +1,6 @@
<?php <?php
session_start(); session_start();
if (!isset($_SESSION['user_id']) || (!in_array($_SESSION['user_role'], ['Administrador', 'personal', 'Verificador de Pagos']) && strpos($_SESSION['user_role'], 'Asesor') === false)) { if (!isset($_SESSION['user_id']) || (!in_array($_SESSION['user_role'], ['Administrador', 'personal', 'Verificador de Pagos', 'Control Logistico', 'Logistica']) && strpos($_SESSION['user_role'], 'Asesor') === false)) {
header('Content-Type: application/json'); header('Content-Type: application/json');
echo json_encode(['success' => false, 'error' => 'Not authenticated']); echo json_encode(['success' => false, 'error' => 'Not authenticated']);
exit; exit;