Spaces:
Running
Running
File size: 27,113 Bytes
5aec823 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | <!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sistema de Gestión de Almacén</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.fade-in {
animation: fadeIn 0.3s ease-in-out;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.product-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}
.modal {
transition: all 0.3s ease;
}
.modal.active {
opacity: 1;
visibility: visible;
}
.modal:not(.active) {
opacity: 0;
visibility: hidden;
}
</style>
</head>
<body class="bg-gray-100 font-sans">
<div class="container mx-auto px-4 py-8">
<header class="mb-8">
<h1 class="text-3xl font-bold text-indigo-700 flex items-center">
<i class="fas fa-warehouse mr-3"></i> Gestión de Almacén
</h1>
<p class="text-gray-600">Control de entradas y salidas de productos</p>
</header>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
<!-- Panel de control -->
<div class="lg:col-span-1 bg-white rounded-lg shadow p-6">
<h2 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
<i class="fas fa-tachometer-alt mr-2"></i> Panel de Control
</h2>
<div class="mb-6">
<button id="addProductBtn" class="w-full bg-indigo-600 hover:bg-indigo-700 text-white py-2 px-4 rounded-lg flex items-center justify-center transition">
<i class="fas fa-plus-circle mr-2"></i> Agregar Producto
</button>
</div>
<div class="mb-6">
<h3 class="font-medium text-gray-700 mb-2">Filtrar productos</h3>
<input type="text" id="searchInput" placeholder="Buscar producto..." class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-indigo-400 focus:border-indigo-400">
</div>
<div class="bg-indigo-50 p-4 rounded-lg">
<h3 class="font-medium text-indigo-700 mb-2">Resumen de stock</h3>
<div class="grid grid-cols-2 gap-4">
<div class="bg-white p-3 rounded-lg shadow-sm">
<p class="text-sm text-gray-500">Productos totales</p>
<p id="totalProducts" class="text-2xl font-bold text-indigo-600">0</p>
</div>
<div class="bg-white p-3 rounded-lg shadow-sm">
<p class="text-sm text-gray-500">Valor total</p>
<p id="totalValue" class="text-2xl font-bold text-green-600">$0</p>
</div>
</div>
</div>
</div>
<!-- Lista de productos -->
<div class="lg:col-span-2 bg-white rounded-lg shadow overflow-hidden">
<div class="p-4 border-b">
<h2 class="text-xl font-semibold text-indigo-600 flex items-center">
<i class="fas fa-boxes mr-2"></i> Inventario Actual
</h2>
</div>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Código</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Producto</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Precio</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Stock</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Acciones</th>
</tr>
</thead>
<tbody id="productTableBody" class="bg-white divide-y divide-gray-200">
<!-- Los productos se cargarán aquí dinámicamente -->
</tbody>
</table>
</div>
<div class="p-4 border-t">
<div class="flex justify-between items-center">
<div>
<p class="text-sm text-gray-600">Mostrando <span id="showingCount">0</span> de <span id="totalCount">0</span> productos</p>
</div>
</div>
</div>
</div>
</div>
<!-- Gráfico de stock -->
<div class="mt-8 bg-white rounded-lg shadow p-6">
<h2 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
<i class="fas fa-chart-bar mr-2"></i> Gráfico de Stock
</h2>
<div class="h-80">
<canvas id="stockChart"></canvas>
</div>
</div>
</div>
<!-- Modal para agregar/editar producto -->
<div id="productModal" class="modal fixed inset-0 flex items-center justify-center bg-black bg-opacity-50 z-50">
<div class="bg-white rounded-lg shadow-xl w-full max-w-md fade-in">
<div class="p-6">
<div class="flex justify-between items-center mb-4">
<h3 id="modalTitle" class="text-xl font-semibold text-indigo-600">Agregar Nuevo Producto</h3>
<button id="closeModalBtn" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<form id="productForm" class="space-y-4">
<input type="hidden" id="productId">
<div>
<label for="productName" class="block text-sm font-medium text-gray-700">Nombre del Producto</label>
<input type="text" id="productName" required class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
</div>
<div>
<label for="barcode" class="block text-sm font-medium text-gray-700">Código de Barras</label>
<div class="flex">
<input type="text" id="barcode" required class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-l-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
<button type="button" id="generateBarcode" class="mt-1 px-3 py-2 bg-gray-200 border border-l-0 border-gray-300 rounded-r-md hover:bg-gray-300">
<i class="fas fa-barcode"></i>
</button>
</div>
</div>
<div>
<label for="productPrice" class="block text-sm font-medium text-gray-700">Precio Unitario</label>
<div class="relative mt-1">
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<span class="text-gray-500">$</span>
</div>
<input type="number" id="productPrice" min="0" step="0.01" required class="pl-7 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
</div>
</div>
<div>
<label for="initialStock" class="block text-sm font-medium text-gray-700">Stock Inicial</label>
<input type="number" id="initialStock" min="0" value="0" class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
</div>
<div class="flex justify-end space-x-3 pt-4">
<button type="button" id="cancelBtn" class="px-4 py-2 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
Cancelar
</button>
<button type="submit" class="px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
Guardar
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Modal para movimiento de stock -->
<div id="movementModal" class="modal fixed inset-0 flex items-center justify-center bg-black bg-opacity-50 z-50">
<div class="bg-white rounded-lg shadow-xl w-full max-w-md fade-in">
<div class="p-6">
<div class="flex justify-between items-center mb-4">
<h3 id="movementModalTitle" class="text-xl font-semibold text-indigo-600">Movimiento de Stock</h3>
<button id="closeMovementModalBtn" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<form id="movementForm" class="space-y-4">
<input type="hidden" id="movementProductId">
<div>
<p class="text-sm font-medium text-gray-700">Producto: <span id="movementProductName" class="font-semibold"></span></p>
<p class="text-sm text-gray-500">Stock actual: <span id="currentStock" class="font-medium"></span></p>
</div>
<div>
<label for="movementType" class="block text-sm font-medium text-gray-700">Tipo de Movimiento</label>
<select id="movementType" class="mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 rounded-md">
<option value="in">Entrada (Ingreso)</option>
<option value="out">Salida (Egreso)</option>
</select>
</div>
<div>
<label for="movementQuantity" class="block text-sm font-medium text-gray-700">Cantidad</label>
<input type="number" id="movementQuantity" min="1" value="1" class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
</div>
<div>
<label for="movementNotes" class="block text-sm font-medium text-gray-700">Notas (Opcional)</label>
<textarea id="movementNotes" rows="2" class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500"></textarea>
</div>
<div class="flex justify-end space-x-3 pt-4">
<button type="button" id="cancelMovementBtn" class="px-4 py-2 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
Cancelar
</button>
<button type="submit" class="px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
Confirmar
</button>
</div>
</form>
</div>
</div>
</div>
<script>
// Base de datos simulada
let products = [
{ id: 1, name: "Laptop HP 15", barcode: "123456789012", price: 899.99, stock: 15 },
{ id: 2, name: "Mouse Inalámbrico", barcode: "234567890123", price: 24.99, stock: 42 },
{ id: 3, name: "Teclado Mecánico", barcode: "345678901234", price: 59.99, stock: 23 },
{ id: 4, name: "Monitor 24\" Full HD", barcode: "456789012345", price: 199.99, stock: 8 },
{ id: 5, name: "Disco SSD 500GB", barcode: "567890123456", price: 79.99, stock: 31 }
];
// Elementos del DOM
const productTableBody = document.getElementById('productTableBody');
const searchInput = document.getElementById('searchInput');
const totalProducts = document.getElementById('totalProducts');
const totalValue = document.getElementById('totalValue');
const showingCount = document.getElementById('showingCount');
const totalCount = document.getElementById('totalCount');
// Elementos del modal
const productModal = document.getElementById('productModal');
const modalTitle = document.getElementById('modalTitle');
const productForm = document.getElementById('productForm');
const productId = document.getElementById('productId');
const productName = document.getElementById('productName');
const barcode = document.getElementById('barcode');
const productPrice = document.getElementById('productPrice');
const initialStock = document.getElementById('initialStock');
const generateBarcode = document.getElementById('generateBarcode');
const addProductBtn = document.getElementById('addProductBtn');
const closeModalBtn = document.getElementById('closeModalBtn');
const cancelBtn = document.getElementById('cancelBtn');
// Elementos del modal de movimiento
const movementModal = document.getElementById('movementModal');
const movementModalTitle = document.getElementById('movementModalTitle');
const movementForm = document.getElementById('movementForm');
const movementProductId = document.getElementById('movementProductId');
const movementProductName = document.getElementById('movementProductName');
const currentStock = document.getElementById('currentStock');
const movementType = document.getElementById('movementType');
const movementQuantity = document.getElementById('movementQuantity');
const movementNotes = document.getElementById('movementNotes');
const closeMovementModalBtn = document.getElementById('closeMovementModalBtn');
const cancelMovementBtn = document.getElementById('cancelMovementBtn');
// Gráfico
let stockChart;
// Inicializar la aplicación
document.addEventListener('DOMContentLoaded', () => {
renderProducts();
updateSummary();
initChart();
// Event listeners
addProductBtn.addEventListener('click', () => openProductModal());
closeModalBtn.addEventListener('click', () => closeProductModal());
cancelBtn.addEventListener('click', () => closeProductModal());
closeMovementModalBtn.addEventListener('click', () => closeMovementModal());
cancelMovementBtn.addEventListener('click', () => closeMovementModal());
productForm.addEventListener('submit', handleProductSubmit);
movementForm.addEventListener('submit', handleMovementSubmit);
searchInput.addEventListener('input', () => {
renderProducts();
});
generateBarcode.addEventListener('click', generateRandomBarcode);
});
// Renderizar la lista de productos
function renderProducts() {
const searchTerm = searchInput.value.toLowerCase();
const filteredProducts = products.filter(product =>
product.name.toLowerCase().includes(searchTerm) ||
product.barcode.includes(searchTerm)
);
productTableBody.innerHTML = '';
filteredProducts.forEach(product => {
const row = document.createElement('tr');
row.className = 'hover:bg-gray-50';
row.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${product.barcode}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${product.name}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">$${product.price.toFixed(2)}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm ${product.stock < 5 ? 'text-red-600 font-bold' : 'text-gray-500'}">
${product.stock}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<div class="flex space-x-2">
<button onclick="openMovementModal(${product.id}, 'in')" class="text-green-600 hover:text-green-800" title="Entrada">
<i class="fas fa-arrow-down"></i>
</button>
<button onclick="openMovementModal(${product.id}, 'out')" class="text-red-600 hover:text-red-800" title="Salida">
<i class="fas fa-arrow-up"></i>
</button>
<button onclick="editProduct(${product.id})" class="text-blue-600 hover:text-blue-800" title="Editar">
<i class="fas fa-edit"></i>
</button>
<button onclick="deleteProduct(${product.id})" class="text-red-600 hover:text-red-800" title="Eliminar">
<i class="fas fa-trash"></i>
</button>
</div>
</td>
`;
productTableBody.appendChild(row);
});
showingCount.textContent = filteredProducts.length;
totalCount.textContent = products.length;
updateChart();
}
// Actualizar el resumen
function updateSummary() {
totalProducts.textContent = products.length;
const total = products.reduce((sum, product) => sum + (product.price * product.stock), 0);
totalValue.textContent = `$${total.toFixed(2)}`;
}
// Inicializar el gráfico
function initChart() {
const ctx = document.getElementById('stockChart').getContext('2d');
stockChart = new Chart(ctx, {
type: 'bar',
data: {
labels: [],
datasets: [{
label: 'Stock de Productos',
data: [],
backgroundColor: 'rgba(79, 70, 229, 0.7)',
borderColor: 'rgba(79, 70, 229, 1)',
borderWidth: 1
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
y: {
beginAtZero: true
}
},
plugins: {
legend: {
position: 'top',
},
tooltip: {
callbacks: {
label: function(context) {
return `Stock: ${context.raw}`;
}
}
}
}
}
});
}
// Actualizar el gráfico
function updateChart() {
const topProducts = [...products]
.sort((a, b) => b.stock - a.stock)
.slice(0, 8);
stockChart.data.labels = topProducts.map(p => p.name);
stockChart.data.datasets[0].data = topProducts.map(p => p.stock);
stockChart.update();
}
// Abrir modal de producto
function openProductModal(product = null) {
if (product) {
modalTitle.textContent = 'Editar Producto';
productId.value = product.id;
productName.value = product.name;
barcode.value = product.barcode;
productPrice.value = product.price;
initialStock.value = product.stock;
} else {
modalTitle.textContent = 'Agregar Nuevo Producto';
productForm.reset();
productId.value = '';
}
productModal.classList.add('active');
}
// Cerrar modal de producto
function closeProductModal() {
productModal.classList.remove('active');
}
// Abrir modal de movimiento
function openMovementModal(productId, type = 'in') {
const product = products.find(p => p.id === productId);
if (!product) return;
movementProductId.value = product.id;
movementProductName.textContent = product.name;
currentStock.textContent = product.stock;
movementType.value = type;
movementQuantity.value = 1;
movementNotes.value = '';
movementModalTitle.textContent = type === 'in' ? 'Registrar Entrada' : 'Registrar Salida';
movementModal.classList.add('active');
}
// Cerrar modal de movimiento
function closeMovementModal() {
movementModal.classList.remove('active');
}
// Manejar el envío del formulario de producto
function handleProductSubmit(e) {
e.preventDefault();
const productData = {
name: productName.value,
barcode: barcode.value,
price: parseFloat(productPrice.value),
stock: parseInt(initialStock.value) || 0
};
if (productId.value) {
// Editar producto existente
const index = products.findIndex(p => p.id === parseInt(productId.value));
if (index !== -1) {
products[index] = { ...products[index], ...productData };
}
} else {
// Agregar nuevo producto
const newId = products.length > 0 ? Math.max(...products.map(p => p.id)) + 1 : 1;
products.push({ id: newId, ...productData });
}
renderProducts();
updateSummary();
closeProductModal();
}
// Manejar el envío del formulario de movimiento
function handleMovementSubmit(e) {
e.preventDefault();
const productId = parseInt(movementProductId.value);
const quantity = parseInt(movementQuantity.value);
const type = movementType.value;
const notes = movementNotes.value;
const productIndex = products.findIndex(p => p.id === productId);
if (productIndex === -1) return;
if (type === 'in') {
products[productIndex].stock += quantity;
} else {
if (products[productIndex].stock < quantity) {
alert('No hay suficiente stock para esta salida');
return;
}
products[productIndex].stock -= quantity;
}
// Aquí podrías guardar el movimiento en un historial si lo deseas
renderProducts();
updateSummary();
closeMovementModal();
}
// Editar producto
function editProduct(id) {
const product = products.find(p => p.id === id);
if (product) {
openProductModal(product);
}
}
// Eliminar producto
function deleteProduct(id) {
if (confirm('¿Estás seguro de que deseas eliminar este producto?')) {
products = products.filter(p => p.id !== id);
renderProducts();
updateSummary();
}
}
// Generar código de barras aleatorio
function generateRandomBarcode() {
const randomBarcode = Math.floor(100000000000 + Math.random() * 900000000000).toString();
barcode.value = randomBarcode;
}
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=FactoryTex/almacen" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |