- Updated README.md to reflect new project structure and conventions. - Refactored component imports and paths to align with new layout. - Removed legacy components (AppConfig.vue, AppTopbar.vue) and created new layout components (MainLayout.vue, Sidebar.vue, TopBar.vue). - Implemented warehouse module with components for inventory management (WarehouseDashboard.vue, InventoryTable.vue). - Added composables and services for warehouse logic and API interactions. - Introduced shared components (KpiCard.vue) for KPI display. - Enhanced API service for handling HTTP requests. - Defined TypeScript types for warehouse entities and global application types.
153 lines
4.2 KiB
TypeScript
153 lines
4.2 KiB
TypeScript
import type { Product, WarehouseMovement, WarehouseStats } from '../types/warehouse';
|
|
|
|
// Simulación de datos de ejemplo
|
|
const mockProducts: Product[] = [
|
|
{
|
|
id: '1',
|
|
name: 'Laptop Dell XPS 15',
|
|
sku: 'LAP-001',
|
|
category: 'Electrónica',
|
|
quantity: 45,
|
|
minStock: 10,
|
|
maxStock: 100,
|
|
unitPrice: 1299.99,
|
|
location: 'A-1-01',
|
|
lastUpdated: new Date('2025-11-01')
|
|
},
|
|
{
|
|
id: '2',
|
|
name: 'Mouse Logitech MX Master',
|
|
sku: 'MOU-001',
|
|
category: 'Accesorios',
|
|
quantity: 8,
|
|
minStock: 15,
|
|
maxStock: 50,
|
|
unitPrice: 99.99,
|
|
location: 'B-2-03',
|
|
lastUpdated: new Date('2025-11-03')
|
|
},
|
|
{
|
|
id: '3',
|
|
name: 'Teclado Mecánico RGB',
|
|
sku: 'KEY-001',
|
|
category: 'Accesorios',
|
|
quantity: 120,
|
|
minStock: 20,
|
|
maxStock: 150,
|
|
unitPrice: 149.99,
|
|
location: 'B-2-05',
|
|
lastUpdated: new Date('2025-11-04')
|
|
}
|
|
];
|
|
|
|
const mockMovements: WarehouseMovement[] = [
|
|
{
|
|
id: '1',
|
|
productId: '1',
|
|
productName: 'Laptop Dell XPS 15',
|
|
type: 'in',
|
|
quantity: 20,
|
|
reason: 'Compra a proveedor',
|
|
date: new Date('2025-11-01'),
|
|
user: 'Admin'
|
|
},
|
|
{
|
|
id: '2',
|
|
productId: '2',
|
|
productName: 'Mouse Logitech MX Master',
|
|
type: 'out',
|
|
quantity: 5,
|
|
reason: 'Venta',
|
|
date: new Date('2025-11-03'),
|
|
user: 'Admin'
|
|
}
|
|
];
|
|
|
|
/**
|
|
* Servicio para gestionar operaciones del almacén
|
|
*/
|
|
export const warehouseService = {
|
|
/**
|
|
* Obtiene todos los productos del inventario
|
|
*/
|
|
async getProducts(): Promise<Product[]> {
|
|
// Simular llamada API
|
|
return new Promise((resolve) => {
|
|
setTimeout(() => resolve(mockProducts), 500);
|
|
});
|
|
},
|
|
|
|
/**
|
|
* Obtiene un producto por ID
|
|
*/
|
|
async getProductById(id: string): Promise<Product | null> {
|
|
return new Promise((resolve) => {
|
|
setTimeout(() => {
|
|
const product = mockProducts.find(p => p.id === id);
|
|
resolve(product || null);
|
|
}, 300);
|
|
});
|
|
},
|
|
|
|
/**
|
|
* Obtiene los movimientos del almacén
|
|
*/
|
|
async getMovements(): Promise<WarehouseMovement[]> {
|
|
return new Promise((resolve) => {
|
|
setTimeout(() => resolve(mockMovements), 500);
|
|
});
|
|
},
|
|
|
|
/**
|
|
* Obtiene las estadísticas del almacén
|
|
*/
|
|
async getStats(): Promise<WarehouseStats> {
|
|
return new Promise((resolve) => {
|
|
setTimeout(() => {
|
|
const stats: WarehouseStats = {
|
|
totalProducts: mockProducts.reduce((sum, p) => sum + p.quantity, 0),
|
|
totalValue: mockProducts.reduce((sum, p) => sum + (p.quantity * p.unitPrice), 0),
|
|
lowStockItems: mockProducts.filter(p => p.quantity < p.minStock).length,
|
|
recentMovements: mockMovements.length
|
|
};
|
|
resolve(stats);
|
|
}, 300);
|
|
});
|
|
},
|
|
|
|
/**
|
|
* Crea un nuevo movimiento de inventario
|
|
*/
|
|
async createMovement(movement: Omit<WarehouseMovement, 'id' | 'date'>): Promise<WarehouseMovement> {
|
|
return new Promise((resolve) => {
|
|
setTimeout(() => {
|
|
const newMovement: WarehouseMovement = {
|
|
...movement,
|
|
id: String(mockMovements.length + 1),
|
|
date: new Date()
|
|
};
|
|
mockMovements.push(newMovement);
|
|
resolve(newMovement);
|
|
}, 500);
|
|
});
|
|
},
|
|
|
|
/**
|
|
* Actualiza la cantidad de un producto
|
|
*/
|
|
async updateProductQuantity(productId: string, quantity: number): Promise<Product | null> {
|
|
return new Promise((resolve) => {
|
|
setTimeout(() => {
|
|
const product = mockProducts.find(p => p.id === productId);
|
|
if (product) {
|
|
product.quantity = quantity;
|
|
product.lastUpdated = new Date();
|
|
resolve(product);
|
|
} else {
|
|
resolve(null);
|
|
}
|
|
}, 500);
|
|
});
|
|
}
|
|
};
|