Refactor: categorías server-side en add.php, elimina fetch async en add.js
- pagos/add.php: nueva página que renderiza el formulario de alta con las categorías ya cargadas desde PHP/SQLite, sin depender de un fetch asíncrono a api/categorias.php tras cargar la página. - pagos/js/add.js: quita cargarCategorias() y la llamada a apiFetch, ya innecesarias con el nuevo flujo server-side. - CLAUDE.md: documentar remote real (Gitea, no GitHub), stack técnico y estructura del proyecto.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
# rm-PAGOs — Sistema de Gestión de Gastos y Pagos
|
||||
|
||||
## Repositorio Git
|
||||
|
||||
**Remote actual:** Gitea DIIAA — `http://10.0.10.205:3000/rmonla/rm-PAGOs.git`
|
||||
|
||||
> ⚠️ La carpeta local está en `~/Documentos/GitHub/rm-PAGOs/` por convención de nombre de directorio,
|
||||
> pero el repositorio **ya fue migrado a Gitea** y NO apunta a GitHub.
|
||||
> Verificar siempre con `git remote -v` antes de operar.
|
||||
|
||||
## Stack Técnico
|
||||
|
||||
| Capa | Tecnología |
|
||||
| :--- | :--- |
|
||||
| **Frontend** | HTML + CSS Vainilla + JS (diseño Lumina Finance / Quiet Wealth) |
|
||||
| **Backend** | PHP 8.2 |
|
||||
| **Base de Datos** | SQLite3 |
|
||||
| **Despliegue** | LXC `srvv-nginx-rm` (Debian 12, NGINX 1.22.1, HTTPS) |
|
||||
|
||||
## Estructura
|
||||
|
||||
```
|
||||
pagos/ → Aplicación desplegable (index.html, css/, api/, db/)
|
||||
docs/plan/ → Plan de desarrollo (00_PLAN.md)
|
||||
```
|
||||
|
||||
## Plan de Desarrollo
|
||||
|
||||
Ver [`docs/plan/00_PLAN.md`](docs/plan/00_PLAN.md) — fases: Frontend estático → Backend PHP/SQLite → Integración → Despliegue.
|
||||
+190
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
// Auth y categorías server-side — elimina dependencia del fetch asíncrono
|
||||
ini_set('session.cookie_httponly', '1');
|
||||
ini_set('session.cookie_samesite', 'Lax');
|
||||
session_save_path(__DIR__ . '/db/sessions');
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['qw_auth'])) {
|
||||
header('Location: login.html');
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/api/db.php';
|
||||
$pdo = getDB();
|
||||
$cats = $pdo->query("SELECT id, nombre FROM categorias ORDER BY nombre")->fetchAll(PDO::FETCH_ASSOC);
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
|
||||
<title>Nuevo Movimiento — Quiet Wealth</title>
|
||||
<script src="js/tailwind.cdn.js"></script>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Manrope:wght@300;400;500;600;700;800&display=swap" rel="stylesheet"/>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:wght,FILL@100..700,0..1&display=swap" rel="stylesheet"/>
|
||||
<script>
|
||||
tailwind.config = {
|
||||
theme: {
|
||||
extend: {
|
||||
colors: {
|
||||
"background":"#f8faf9","primary-container":"#006a6a","surface-container-lowest":"#ffffff",
|
||||
"on-background":"#191c1c","surface-container-high":"#e6e9e8","surface-container-highest":"#e1e3e2",
|
||||
"surface-container-low":"#f2f4f3","on-primary":"#ffffff","on-surface":"#191c1c",
|
||||
"on-surface-variant":"#3e4948","outline-variant":"#bec9c8","outline":"#6e7979",
|
||||
"surface-container":"#eceeed","error":"#ba1a1a","secondary":"#4d6357",
|
||||
"surface":"#f8faf9","primary":"#005050","on-secondary":"#ffffff"
|
||||
},
|
||||
fontFamily: { headline:["Manrope"], body:["Manrope"] }
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
body { font-family:'Manrope',sans-serif; }
|
||||
.material-symbols-outlined { font-variation-settings:'FILL' 0,'wght' 400,'GRAD' 0,'opsz' 24; }
|
||||
.numpad-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:0.75rem; }
|
||||
</style>
|
||||
</head>
|
||||
<body class="bg-background text-on-background min-h-screen">
|
||||
|
||||
<!-- SIDEBAR (desktop) -->
|
||||
<aside class="hidden md:flex flex-col fixed left-0 top-0 h-screen w-56 bg-surface-container-lowest border-r border-outline-variant z-40 py-7 px-4 gap-1">
|
||||
<div class="flex items-center gap-2 px-2 mb-7">
|
||||
<span class="material-symbols-outlined text-[#006a6a] text-2xl" style="font-variation-settings:'FILL' 1;">account_balance_wallet</span>
|
||||
<span class="font-extrabold text-[#006a6a] tracking-tight text-lg">Quiet Wealth</span>
|
||||
</div>
|
||||
<a href="index.html" class="flex items-center gap-3 px-3 py-2.5 rounded-xl text-on-surface-variant hover:bg-surface-container text-sm font-medium transition-colors">
|
||||
<span class="material-symbols-outlined text-[20px]">home</span>Dashboard
|
||||
</a>
|
||||
<a href="historial.html" class="flex items-center gap-3 px-3 py-2.5 rounded-xl text-on-surface-variant hover:bg-surface-container text-sm font-medium transition-colors">
|
||||
<span class="material-symbols-outlined text-[20px]">history</span>Historial
|
||||
</a>
|
||||
<a href="add.php" class="flex items-center gap-3 px-3 py-2.5 rounded-xl bg-[#005050]/10 text-primary font-bold text-sm">
|
||||
<span class="material-symbols-outlined text-[20px]" style="font-variation-settings:'FILL' 1;">add_circle</span>Nuevo movimiento
|
||||
</a>
|
||||
<a href="categorias.html" class="flex items-center gap-3 px-3 py-2.5 rounded-xl text-on-surface-variant hover:bg-surface-container text-sm font-medium transition-colors">
|
||||
<span class="material-symbols-outlined text-[20px]">category</span>Categorías
|
||||
</a>
|
||||
<div class="mt-auto">
|
||||
<button onclick="fetch('api/login.php?action=logout').then(()=>location.href='login.html')"
|
||||
class="flex items-center gap-3 px-3 py-2.5 rounded-xl text-on-surface-variant hover:bg-surface-container text-sm font-medium transition-colors w-full">
|
||||
<span class="material-symbols-outlined text-[20px]">logout</span>Salir
|
||||
</button>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<!-- CONTENIDO -->
|
||||
<div class="md:ml-56 min-h-screen flex flex-col">
|
||||
|
||||
<header class="bg-background sticky top-0 z-30 border-b border-outline-variant/30 px-6 md:px-8 py-4 flex items-center gap-4">
|
||||
<button onclick="window.location.href='index.html'" class="p-2 -ml-2 hover:bg-surface-container rounded-full transition-colors">
|
||||
<span class="material-symbols-outlined text-primary">arrow_back</span>
|
||||
</button>
|
||||
<h1 class="text-xl font-bold text-on-surface">Nuevo Movimiento</h1>
|
||||
</header>
|
||||
|
||||
<main class="flex-1 px-6 md:px-8 py-6 pb-28 md:pb-10">
|
||||
<div class="max-w-4xl mx-auto md:grid md:grid-cols-2 md:gap-10 md:items-start space-y-6 md:space-y-0">
|
||||
|
||||
<!-- COLUMNA IZQUIERDA -->
|
||||
<div class="space-y-6">
|
||||
|
||||
<!-- Tipo -->
|
||||
<div class="p-1.5 bg-surface-container-low rounded-xl flex items-center" id="ui-tipo-selector">
|
||||
<button id="btn-gasto" data-tipo="gasto"
|
||||
class="flex-1 py-2.5 text-sm font-bold bg-surface-container-lowest text-primary rounded-lg shadow-sm transition-all">Gasto</button>
|
||||
<button id="btn-ingreso" data-tipo="ingreso"
|
||||
class="flex-1 py-2.5 text-sm font-semibold text-on-surface-variant hover:opacity-80 transition-opacity">Ingreso</button>
|
||||
</div>
|
||||
|
||||
<!-- Monto mobile -->
|
||||
<div class="md:hidden relative text-center py-8 bg-surface-container-low rounded-[2rem]">
|
||||
<label class="block text-xs uppercase tracking-[0.15em] font-bold text-on-surface-variant mb-2">Monto</label>
|
||||
<div class="flex items-baseline justify-center gap-1">
|
||||
<span class="text-3xl font-light text-on-surface-variant">$</span>
|
||||
<span id="ui-monto-mobile" class="text-6xl font-extrabold tracking-tight text-primary">0</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Categoría: opciones renderizadas por PHP -->
|
||||
<div class="space-y-2">
|
||||
<label class="text-[11px] uppercase tracking-widest font-bold text-on-surface-variant">Categoría</label>
|
||||
<div class="relative">
|
||||
<select id="ui-categoria" class="appearance-none bg-surface-container-lowest px-4 py-3.5 pr-10 rounded-xl w-full font-semibold text-on-surface focus:outline-none focus:ring-2 focus:ring-primary/30 text-sm">
|
||||
<?php foreach ($cats as $c): ?>
|
||||
<option value="<?= $c['id'] ?>"><?= htmlspecialchars($c['nombre']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<span class="material-symbols-outlined absolute right-3 top-1/2 -translate-y-1/2 text-outline pointer-events-none text-[18px]">expand_more</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Fecha y Notas -->
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div class="space-y-2">
|
||||
<label class="text-[11px] uppercase tracking-widest font-bold text-on-surface-variant">Fecha</label>
|
||||
<div class="bg-surface-container-lowest px-4 py-3 rounded-xl flex items-center gap-2">
|
||||
<span class="material-symbols-outlined text-primary text-[18px]">calendar_today</span>
|
||||
<input type="date" id="ui-fecha" class="bg-transparent text-sm font-semibold w-full focus:outline-none"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-[11px] uppercase tracking-widest font-bold text-on-surface-variant">Notas</label>
|
||||
<div class="bg-surface-container-lowest px-4 py-3 rounded-xl flex items-center gap-2">
|
||||
<span class="material-symbols-outlined text-outline text-[18px]">edit_note</span>
|
||||
<input type="text" id="ui-notas" placeholder="Opcional…" class="bg-transparent text-sm font-medium w-full focus:outline-none placeholder-outline"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Guardar desktop -->
|
||||
<button id="btn-save"
|
||||
class="hidden md:flex w-full h-14 bg-gradient-to-br from-primary to-primary-container text-white rounded-xl font-bold text-base shadow-lg shadow-primary/20 active:scale-[0.98] transition-transform items-center justify-center gap-2">
|
||||
<span>Guardar Movimiento</span>
|
||||
<span class="material-symbols-outlined text-[20px]" style="font-variation-settings:'FILL' 1;">check_circle</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- COLUMNA DERECHA: monto + numpad -->
|
||||
<div class="space-y-5">
|
||||
<div class="hidden md:block text-center py-8 bg-surface-container-low rounded-[2rem]">
|
||||
<label class="block text-xs uppercase tracking-[0.15em] font-bold text-on-surface-variant mb-2">Monto</label>
|
||||
<div class="flex items-baseline justify-center gap-1">
|
||||
<span class="text-3xl font-light text-on-surface-variant">$</span>
|
||||
<span id="ui-monto" class="text-6xl font-extrabold tracking-tight text-primary">0</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="ui-numpad" class="numpad-grid bg-surface-container-lowest rounded-[2rem] p-4">
|
||||
<?php foreach (['1','2','3','4','5','6','7','8','9','.','0','⌫'] as $k): ?>
|
||||
<button class="h-14 rounded-xl flex items-center justify-center text-2xl font-semibold text-on-surface hover:bg-surface-container-high transition-colors"
|
||||
<?= $k === '⌫' ? '' : '' ?>>
|
||||
<?php if ($k === '⌫'): ?>
|
||||
<span class="material-symbols-outlined" data-icon="backspace">backspace</span>
|
||||
<?php else: ?>
|
||||
<?= $k ?>
|
||||
<?php endif; ?>
|
||||
</button>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<!-- Guardar mobile -->
|
||||
<div class="md:hidden fixed bottom-0 inset-x-0 p-4 bg-gradient-to-t from-background via-background/95 to-transparent">
|
||||
<button id="btn-save-mobile"
|
||||
class="w-full h-14 bg-gradient-to-br from-primary to-primary-container text-white rounded-xl font-bold text-base shadow-lg shadow-primary/20 active:scale-[0.98] transition-transform flex items-center justify-center gap-2">
|
||||
<span>Guardar Movimiento</span>
|
||||
<span class="material-symbols-outlined text-[20px]" style="font-variation-settings:'FILL' 1;">check_circle</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="js/ui.js"></script>
|
||||
<script src="js/add.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
+1
-21
@@ -13,27 +13,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
// Default a hoy
|
||||
iptFecha.valueAsDate = new Date();
|
||||
|
||||
// Cargar categorías
|
||||
cargarCategorias();
|
||||
|
||||
async function cargarCategorias() {
|
||||
const sel = document.getElementById('ui-categoria');
|
||||
try {
|
||||
const r = await apiFetch('api/categorias.php');
|
||||
if (!r) return; // redirigió a login
|
||||
const data = await r.json();
|
||||
if (!data.categorias?.length) {
|
||||
sel.innerHTML = '<option value="">Sin categorías</option>';
|
||||
return;
|
||||
}
|
||||
sel.innerHTML = data.categorias.map(c =>
|
||||
`<option value="${c.id}">${c.nombre}</option>`
|
||||
).join('');
|
||||
} catch (e) {
|
||||
console.error('Error cargando categorías:', e);
|
||||
sel.innerHTML = '<option value="">Error al cargar</option>';
|
||||
}
|
||||
}
|
||||
// Categorías ya vienen renderizadas por PHP (add.php)
|
||||
|
||||
// Tipo selector
|
||||
const updateTipoUI = () => {
|
||||
|
||||
Reference in New Issue
Block a user