feat: Implementar PWA, Analytics, Reportes PDF y mejoras OCR

FASE 1 - PWA y Frontend:
- Crear templates/base.html, dashboard.html, analytics.html, executive.html
- Crear static/css/main.css con diseño responsivo
- Agregar static/js/app.js, pwa.js, camera.js, charts.js
- Implementar manifest.json y service-worker.js para PWA
- Soporte para captura de tickets desde cámara móvil

FASE 2 - Analytics:
- Crear módulo analytics/ con predictions.py, trends.py, comparisons.py
- Implementar predicción básica con promedio móvil + tendencia lineal
- Agregar endpoints /api/analytics/trends, predictions, comparisons
- Integrar Chart.js para gráficas interactivas

FASE 3 - Reportes PDF:
- Crear módulo reports/ con pdf_generator.py
- Implementar SalesReportPDF con generar_reporte_diario y ejecutivo
- Agregar comando /reporte [diario|semanal|ejecutivo]
- Agregar endpoints /api/reports/generate y /api/reports/download

FASE 4 - Mejoras OCR:
- Crear módulo ocr/ con processor.py, preprocessor.py, patterns.py
- Implementar AmountDetector con patrones múltiples de montos
- Agregar preprocesador adaptativo con pipelines para diferentes condiciones
- Soporte para corrección de rotación (deskew) y threshold Otsu

Dependencias agregadas:
- reportlab, matplotlib (PDF)
- scipy, pandas (analytics)
- imutils, deskew, cachetools (OCR)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-19 03:26:16 +00:00
parent ed1658eb2b
commit 9936deaa90
25 changed files with 5501 additions and 282 deletions

View File

@@ -0,0 +1,591 @@
/* ==================== RESET & BASE ==================== */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--primary: #00d4ff;
--secondary: #00ff88;
--warning: #ffaa00;
--purple: #aa00ff;
--bg-dark: #1a1a2e;
--bg-darker: #16213e;
--bg-card: rgba(255, 255, 255, 0.05);
--border-color: rgba(255, 255, 255, 0.1);
--text-primary: #ffffff;
--text-secondary: #888888;
--text-muted: #666666;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-darker) 100%);
min-height: 100vh;
color: var(--text-primary);
}
/* ==================== NAVBAR ==================== */
.navbar {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px 20px;
background: rgba(0, 0, 0, 0.3);
border-bottom: 1px solid var(--border-color);
position: sticky;
top: 0;
z-index: 100;
backdrop-filter: blur(10px);
}
.nav-brand {
display: flex;
align-items: center;
gap: 10px;
}
.brand-icon {
width: 36px;
height: 36px;
background: linear-gradient(135deg, var(--primary), var(--secondary));
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
font-size: 18px;
}
.brand-text {
font-size: 20px;
font-weight: 600;
}
.nav-links {
display: flex;
gap: 5px;
}
.nav-link {
color: var(--text-secondary);
text-decoration: none;
padding: 8px 16px;
border-radius: 8px;
transition: all 0.2s;
font-size: 14px;
}
.nav-link:hover {
color: var(--text-primary);
background: var(--bg-card);
}
.nav-link.active {
color: var(--primary);
background: rgba(0, 212, 255, 0.1);
}
.nav-actions {
display: flex;
gap: 10px;
}
/* ==================== CONTAINER ==================== */
.container {
max-width: 1400px;
margin: 0 auto;
padding: 20px;
}
/* ==================== HEADER ==================== */
.page-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 30px;
padding-bottom: 20px;
border-bottom: 1px solid var(--border-color);
}
.page-header h1 {
font-size: 28px;
font-weight: 600;
}
.page-header h1 span {
color: var(--primary);
}
.fecha {
color: var(--text-secondary);
font-size: 14px;
}
/* ==================== BUTTONS ==================== */
.btn {
padding: 10px 20px;
border-radius: 8px;
font-size: 14px;
cursor: pointer;
transition: all 0.2s;
border: none;
font-weight: 500;
}
.btn-primary {
background: var(--primary);
color: #000;
}
.btn-primary:hover {
background: #33ddff;
transform: translateY(-2px);
}
.btn-secondary {
background: var(--bg-card);
border: 1px solid var(--primary);
color: var(--primary);
}
.btn-secondary:hover {
background: rgba(0, 212, 255, 0.2);
}
.refresh-btn {
background: rgba(0, 212, 255, 0.2);
border: 1px solid var(--primary);
color: var(--primary);
padding: 8px 16px;
border-radius: 8px;
cursor: pointer;
font-size: 14px;
transition: all 0.2s;
}
.refresh-btn:hover {
background: rgba(0, 212, 255, 0.3);
}
/* ==================== STATS GRID ==================== */
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin-bottom: 30px;
}
.stat-card {
background: var(--bg-card);
border-radius: 16px;
padding: 24px;
border: 1px solid var(--border-color);
transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 40px rgba(0, 212, 255, 0.1);
}
.stat-card .label {
color: var(--text-secondary);
font-size: 12px;
text-transform: uppercase;
letter-spacing: 1px;
margin-bottom: 8px;
}
.stat-card .value {
font-size: 32px;
font-weight: 700;
color: var(--primary);
}
.stat-card .subvalue {
font-size: 14px;
color: var(--text-muted);
margin-top: 4px;
}
.stat-card.green .value { color: var(--secondary); }
.stat-card.orange .value { color: var(--warning); }
.stat-card.purple .value { color: var(--purple); }
/* ==================== PANELS ==================== */
.main-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}
@media (max-width: 900px) {
.main-grid {
grid-template-columns: 1fr;
}
}
.panel {
background: var(--bg-card);
border-radius: 16px;
padding: 24px;
border: 1px solid var(--border-color);
}
.panel h2 {
font-size: 18px;
margin-bottom: 20px;
display: flex;
align-items: center;
gap: 10px;
}
.panel h2 .icon {
font-size: 24px;
}
/* ==================== RANKING ==================== */
.ranking-list {
list-style: none;
}
.ranking-item {
display: flex;
align-items: center;
padding: 12px 0;
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.ranking-item:last-child {
border-bottom: none;
}
.ranking-position {
width: 32px;
height: 32px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-weight: 700;
font-size: 14px;
margin-right: 12px;
}
.ranking-position.gold { background: linear-gradient(135deg, #ffd700, #ffaa00); color: #000; }
.ranking-position.silver { background: linear-gradient(135deg, #c0c0c0, #888); color: #000; }
.ranking-position.bronze { background: linear-gradient(135deg, #cd7f32, #8b4513); color: #fff; }
.ranking-position.default { background: rgba(255, 255, 255, 0.1); color: var(--text-secondary); }
.ranking-info {
flex: 1;
}
.ranking-name {
font-weight: 600;
margin-bottom: 2px;
}
.ranking-stats {
font-size: 12px;
color: var(--text-secondary);
}
.ranking-value {
text-align: right;
}
.ranking-tubos {
font-size: 24px;
font-weight: 700;
color: var(--primary);
}
.ranking-comision {
font-size: 12px;
color: var(--secondary);
}
/* ==================== VENTAS RECIENTES ==================== */
.ventas-list {
max-height: 400px;
overflow-y: auto;
}
.venta-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 12px;
margin-bottom: 8px;
background: rgba(255, 255, 255, 0.03);
border-radius: 8px;
}
.venta-info .vendedor {
font-weight: 600;
color: var(--primary);
}
.venta-info .cliente {
font-size: 12px;
color: var(--text-secondary);
}
.venta-monto {
font-size: 18px;
font-weight: 700;
color: var(--secondary);
}
/* ==================== CHARTS ==================== */
.chart-container {
position: relative;
height: 300px;
margin: 20px 0;
}
.chart-container canvas {
max-height: 100%;
}
/* ==================== LOADING ==================== */
.loading {
text-align: center;
padding: 40px;
color: var(--text-secondary);
}
.loading-spinner {
display: inline-block;
width: 30px;
height: 30px;
border: 3px solid rgba(255, 255, 255, 0.1);
border-radius: 50%;
border-top-color: var(--primary);
animation: spin 1s ease-in-out infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
/* ==================== PROGRESS BAR ==================== */
.meta-progress {
height: 8px;
background: rgba(255, 255, 255, 0.1);
border-radius: 4px;
overflow: hidden;
margin-top: 8px;
}
.meta-progress-bar {
height: 100%;
background: linear-gradient(90deg, var(--primary), var(--secondary));
border-radius: 4px;
transition: width 0.5s;
}
/* ==================== KPI CARDS ==================== */
.kpi-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 15px;
margin-bottom: 20px;
}
.kpi-card {
background: var(--bg-card);
border-radius: 12px;
padding: 16px;
text-align: center;
border: 1px solid var(--border-color);
}
.kpi-card .kpi-value {
font-size: 28px;
font-weight: 700;
color: var(--primary);
}
.kpi-card .kpi-label {
font-size: 11px;
color: var(--text-secondary);
text-transform: uppercase;
letter-spacing: 1px;
margin-top: 4px;
}
.kpi-card .kpi-trend {
font-size: 12px;
margin-top: 8px;
}
.kpi-card .kpi-trend.up { color: var(--secondary); }
.kpi-card .kpi-trend.down { color: #ff4444; }
.kpi-card .kpi-trend.stable { color: var(--text-secondary); }
/* ==================== TABLES ==================== */
.data-table {
width: 100%;
border-collapse: collapse;
margin-top: 15px;
}
.data-table th,
.data-table td {
padding: 12px;
text-align: left;
border-bottom: 1px solid var(--border-color);
}
.data-table th {
background: rgba(0, 0, 0, 0.2);
font-weight: 600;
font-size: 12px;
text-transform: uppercase;
letter-spacing: 1px;
color: var(--text-secondary);
}
.data-table tr:hover {
background: rgba(255, 255, 255, 0.02);
}
/* ==================== CAMERA MODAL ==================== */
.camera-modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.9);
z-index: 1000;
align-items: center;
justify-content: center;
}
.camera-modal.active {
display: flex;
}
.camera-container {
position: relative;
max-width: 90%;
max-height: 90%;
}
.camera-container video {
max-width: 100%;
max-height: 80vh;
border-radius: 12px;
}
.camera-controls {
display: flex;
justify-content: center;
gap: 20px;
margin-top: 20px;
}
.camera-btn {
width: 60px;
height: 60px;
border-radius: 50%;
border: none;
font-size: 24px;
cursor: pointer;
transition: transform 0.2s;
}
.camera-btn:hover {
transform: scale(1.1);
}
.camera-btn.capture {
background: var(--primary);
color: #000;
}
.camera-btn.close {
background: rgba(255, 255, 255, 0.2);
color: #fff;
}
/* ==================== MOBILE RESPONSIVE ==================== */
@media (max-width: 768px) {
.navbar {
flex-wrap: wrap;
gap: 10px;
}
.nav-links {
order: 3;
width: 100%;
justify-content: center;
}
.nav-link {
padding: 6px 12px;
font-size: 12px;
}
.stats-grid {
grid-template-columns: repeat(2, 1fr);
}
.stat-card .value {
font-size: 24px;
}
.page-header h1 {
font-size: 22px;
}
.panel {
padding: 16px;
}
}
@media (max-width: 480px) {
.stats-grid {
grid-template-columns: 1fr;
}
.container {
padding: 10px;
}
}
/* ==================== PWA INSTALL PROMPT ==================== */
.install-prompt {
display: none;
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
background: var(--bg-darker);
border: 1px solid var(--primary);
border-radius: 12px;
padding: 16px 24px;
z-index: 1000;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.install-prompt.show {
display: flex;
align-items: center;
gap: 15px;
}
.install-prompt p {
margin: 0;
font-size: 14px;
}
.install-prompt .btn {
white-space: nowrap;
}