Autosave: 20260527-024934

This commit is contained in:
Flatlogic Bot 2026-05-27 02:49:32 +00:00
parent 4b4a7e2b8b
commit 93b3a0f69d
4 changed files with 113 additions and 10 deletions

View File

@ -100,14 +100,23 @@ $navItems = [
'url' => 'pedidos.php',
'icon' => 'fa-clipboard-list',
'text' => 'Pedidos Rotulados',
'roles' => ['Administrador', 'admin', 'Asesor', 'Control Logistico', 'Logistica']
],
'agregar_pedido' => [
'url' => 'pedido_form.php',
'icon' => 'fa-plus-circle',
'text' => 'Agregar Pedido',
'roles' => ['Administrador', 'admin', 'Asesor', 'Control Logistico']
'roles' => ['Administrador', 'admin', 'Asesor', 'Control Logistico', 'Logistica'],
'submenu' => [
'pedidos_rotulados_list' => [
'url' => 'pedidos.php',
'icon' => 'fa-clipboard-list',
'text' => 'Ver Pedidos Rotulados',
'roles' => ['Administrador', 'admin', 'Asesor', 'Control Logistico', 'Logistica']
],
'agregar_pedido' => [
'url' => 'pedido_form.php',
'icon' => 'fa-plus-circle',
'text' => 'Agregar Pedido',
'roles' => ['Administrador', 'admin']
]
]
],
'agregar_pedidos_contraentrega' => [
'url' => 'pedidos_contraentrega.php',
'icon' => 'fa-hand-holding-usd',

View File

@ -54,7 +54,7 @@ if (isset($_GET['id'])) {
}
} else {
// Security check: Only Administradors, Logistica, Control Logistico and asesores can create new pedidos
if ($user_role !== 'Administrador' && $user_role !== 'Logistica' && $user_role !== 'Control Logistico' && $user_role !== 'Asesor') {
if ($user_role !== 'Administrador' && $user_role !== 'admin' && $user_role !== 'Logistica' && $user_role !== 'Control Logistico' && $user_role !== 'Asesor') {
die('Acceso denegado. No tienes permiso para crear nuevos pedidos.');
}
}
@ -121,6 +121,14 @@ $pageTitle = $page_title;
include 'layout_header.php';
?>
<?php if (($_GET['embed'] ?? '') === '1'): ?>
<style>
.sidebar, .sidebar-toggle { display: none !important; }
.content { margin-left: 0 !important; width: 100% !important; padding: 16px !important; }
.content .container-fluid > h1 { display: none !important; }
</style>
<?php endif; ?>
<?php if (isset($_GET['error'])):
$error_message = htmlspecialchars($_GET['error']);
?>
@ -524,8 +532,25 @@ document.addEventListener('DOMContentLoaded', function() {
<script>
document.addEventListener('DOMContentLoaded', function() {
const urlParams = new URLSearchParams(window.location.search);
let inIframe = false;
try {
inIframe = window.self !== window.top;
} catch (e) {
inIframe = true;
}
if (urlParams.has('success')) {
alert('SE AGREGO CORRECTAMENTE ✅');
if (!inIframe) {
alert('SE AGREGO CORRECTAMENTE ✅');
} else {
try {
window.parent.postMessage({ type: "pedido_form_success" }, "*");
} catch (e) {
// ignore
}
}
// Remove the success parameter from the URL without reloading the page
const newUrl = window.location.pathname + window.location.hash;
window.history.replaceState({}, document.title, newUrl);

View File

@ -157,6 +157,11 @@ include 'layout_header.php';
<div class="col-auto mt-4">
<button type="submit" class="btn btn-info">Filtrar</button>
<a href="pedidos.php" class="btn btn-secondary">Limpiar</a>
<?php if (in_array($user_role, ["Administrador", "admin", "Logistica", "Control Logistico", "Asesor"], true)): ?>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#nuevoPedidoRotuladoModal">
+ Agregar Pedido
</button>
<?php endif; ?>
<?php if ($user_role === 'Administrador' || $user_role === 'Logistica'): ?>
<a href="imprimir_rotulos_grandes.php?<?php echo http_build_query($_GET); ?>" class="btn btn-dark" target="_blank">Generar Todos los Rótulos</a>
<a href="download_report.php" class="btn btn-success">Descargar Todos los Rotulados</a>
@ -253,6 +258,22 @@ include 'layout_header.php';
<?php if (in_array($user_role, ["Administrador", "admin", "Logistica", "Control Logistico", "Asesor"], true)): ?>
<div class="modal fade" id="nuevoPedidoRotuladoModal" tabindex="-1" aria-labelledby="nuevoPedidoRotuladoModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl modal-dialog-scrollable" style="max-width: 95vw;">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="nuevoPedidoRotuladoModalLabel">Agregar Pedido (Rotulado)</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Cerrar"></button>
</div>
<div class="modal-body p-0">
<iframe id="nuevoPedidoRotuladoIframe" title="Formulario de pedido" src="about:blank" style="width:100%; height:90vh; border:0;"></iframe>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php include 'layout_footer.php'; ?>
<script>
@ -270,6 +291,49 @@ $(document).ready(function() {
document.addEventListener('DOMContentLoaded', function() {
const table = document.querySelector('.table');
// Modal: agregar pedido desde "Pedidos Rotulados"
let nuevoPedidoModalReloadGuard = false;
const nuevoPedidoModalEl = document.getElementById("nuevoPedidoRotuladoModal");
if (nuevoPedidoModalEl) {
const nuevoPedidoIframe = document.getElementById("nuevoPedidoRotuladoIframe");
window.addEventListener("message", function(event) {
const data = event.data;
if (!data || typeof data !== "object") return;
if (data.type === "pedido_form_success") {
if (nuevoPedidoModalReloadGuard) return;
nuevoPedidoModalReloadGuard = true;
const modalInstance = bootstrap.Modal.getInstance(nuevoPedidoModalEl) || new bootstrap.Modal(nuevoPedidoModalEl);
modalInstance.hide();
window.location.reload();
}
});
nuevoPedidoModalEl.addEventListener("show.bs.modal", function() {
nuevoPedidoModalReloadGuard = false;
if (nuevoPedidoIframe) {
nuevoPedidoIframe.src = "pedido_form.php?embed=1&t=" + Date.now();
}
});
if (nuevoPedidoIframe) {
nuevoPedidoIframe.addEventListener("load", function() {
if (nuevoPedidoModalReloadGuard) return;
const src = nuevoPedidoIframe.src || "";
if (src.includes("success=1")) {
nuevoPedidoModalReloadGuard = true;
const modalInstance = bootstrap.Modal.getInstance(nuevoPedidoModalEl) || new bootstrap.Modal(nuevoPedidoModalEl);
modalInstance.hide();
window.location.reload();
}
});
}
}
table.addEventListener('click', function(e) {
if (e.target && e.target.classList.contains('editable')) {

View File

@ -317,7 +317,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$redirect_url = $_POST['referer'] ?? 'pedidos.php';
} else {
// Si se está creando un nuevo pedido, redirigir al formulario con un mensaje de éxito.
$redirect_url = 'pedido_form.php?success=1';
$referer = $_POST['referer'] ?? '';
if (is_string($referer) && strpos($referer, 'embed=1') !== false) {
$redirect_url = 'pedido_form.php?success=1&embed=1';
} else {
$redirect_url = 'pedido_form.php?success=1';
}
}
header('Location: ' . $redirect_url);
exit;