# Configuracion Contabilidad Proveedores Implementation Plan

> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.

**Goal:** Add user-level permissions, evolve Caja into simple accounting, add suppliers, and fix CRM/Pipeline/Calendar visual behavior.

**Architecture:** Keep the app modular: shared domain functions for permissions, pipeline colors, and accounting math; PocketBase collections for persisted configuration; pages remain thin clients over `src/lib/pb/*`. Existing Caja data remains untouched and new accounting fields are optional for legacy rows.

**Tech Stack:** Next.js 16, React 19, TypeScript, PocketBase, Node test runner via `tsx --test`.

---

### Task 1: Visual Fixes and Shared Pipeline Colors

**Files:**
- Modify: `src/lib/pedidos/pipeline.ts`
- Modify: `src/lib/pedidos/pipeline.test.ts`
- Modify: `src/app/(dashboard)/pipeline/page.tsx`
- Modify: `src/app/(dashboard)/calendario/page.tsx`
- Modify: `src/app/(dashboard)/crm/page.tsx`

- [ ] Add failing tests for `PIPELINE_COLORS` containing one color entry per `PIPELINE_ETAPAS`.
- [ ] Implement `PIPELINE_COLORS`, `pipelineColorClass`, and `pipelineCalendarClass`.
- [ ] Replace CRM grid with horizontal fixed-column flex layout.
- [ ] Apply pipeline colors to Pipeline cards and Calendar event labels.
- [ ] Run `npm run test` and `npm run build`.

### Task 2: User Permission Model

**Files:**
- Modify: `backend/create_collections.py`
- Create: `src/lib/permissions/domain.ts`
- Create: `src/lib/permissions/domain.test.ts`
- Create: `src/lib/pb/user-permissions.ts`
- Modify: `src/lib/store/useAuthStore.ts`
- Modify: `src/components/layout/Sidebar.tsx`
- Modify: `src/components/layout/MobileNav.tsx`
- Create: `src/components/auth/PermissionGate.tsx`
- Create: `src/app/(dashboard)/configuracion/page.tsx`

- [ ] Add failing tests for Edd admin access and Anibal default permissions.
- [ ] Add `user_permissions` schema with `user`, `module`, `can_view`, `can_create`, `can_edit`, `can_delete`.
- [ ] Implement permission helpers and client fetch/update helpers.
- [ ] Filter navigation by `can_view`.
- [ ] Add Configuracion page for admin user-permission editing.
- [ ] Run schema update, tests, and build.

### Task 3: Caja / Contabilidad Domain

**Files:**
- Modify: `backend/create_collections.py`
- Create: `src/lib/contabilidad/domain.ts`
- Create: `src/lib/contabilidad/domain.test.ts`
- Modify: `src/lib/pb/movimientos.ts`
- Modify: `src/lib/pb/cuentas.ts`
- Modify: `src/app/(dashboard)/caja/page.tsx`

- [ ] Add failing tests for account balances including initial balance and transfers.
- [ ] Extend `cuentas` with `saldo_inicial`, `fecha_saldo_inicial`, `activa`.
- [ ] Extend `movimientos` with `categoria`, `proveedor`, `cuenta_destino`, and `notas`.
- [ ] Add movement type `transferencia`.
- [ ] Redesign Caja as Caja / Contabilidad with tabs: Movimientos, Saldos, Categorias, Proveedores, Transferencias.
- [ ] Run schema update, tests, and build.

### Task 4: Proveedores

**Files:**
- Modify: `backend/create_collections.py`
- Create: `src/lib/types/proveedor.ts`
- Create: `src/lib/pb/proveedores.ts`
- Create: `src/app/(dashboard)/proveedores/page.tsx`
- Modify: `src/components/layout/Sidebar.tsx`
- Modify: `src/components/layout/MobileNav.tsx`

- [ ] Add `proveedores` schema.
- [ ] Add provider list/create/edit helpers.
- [ ] Add admin-only Proveedores page.
- [ ] Link optional supplier selector from egreso modal.
- [ ] Run tests and build.
