# ERP Bolivia - Agent Notes

## Project Setup
- Laravel 11 + MySQL on XAMPP
- Project root: `C:\Users\Sistema\Documents\Default Project\erp-bolivia-app`
- Running via `php artisan serve --host=127.0.0.1 --port=8000`
- Default admin user: `admin@erp.com` / `erp12345`

## Key Architecture
- Routes split by module: `routes/inventory.php`, `routes/sales.php`, `routes/hr.php`, etc.
- Included from `routes/web.php` under `middleware('auth')`
- Uses Alpine.js (loaded in `layouts.app`) for interactive JS
- Tailwind CSS for styling
- Blade templates in `resources/views/`

## Product Form — Account Searchable Dropdowns
- The 3 account fields (Inventory, COGS, Sales) use searchable dropdowns
- Each has a text input for search, a hidden `<select>` for form submission, and a dropdown of filtered results
- Accounts JSON embedded via `$accountsJson` from controller (map of id + label)
- JS in `form.blade.php` handles filtering and selection → sets hidden select value
- All JS wrapped properly in `<script>` tags (not visible as page text)
- **Migration** `2026_07_29_171635_add_unit_measure_to_products_table` adds `unit_measure` (varchar 20) and `units_per_box` (nullable int)
- **QuickAddController**: `storeCategory` and `storeBrand` for AJAX quick-add

## Sales Module
- Invoice and Order forms show `data-measure` and `data-perbox` on product options
- `updateBoxInfo()` JS function shows equivalent units when product type is CAJA
- Both controllers (`SalesInvoiceController`, `SalesOrderController`) include `unit_measure` and `units_per_box` in product queries

## AI Assistant
- Model: `opencode/big-pickle` via OpenCode Zen (free, anonymous, no API key)
- Config: `.env` → `AI_BASE_URL`, `AI_MODEL=big-pickle`, `AI_API_KEY=""`
- `AiService` has simplified prompt, schema context with ENUM type/value info, fallback SQL extraction from plain text

## Common Patterns
- View compiled cache: `php artisan view:clear`
- After editing Blade files, always run `php artisan view:clear` before testing
- Quick-add routes: `POST /inventario/categorias/rapida`, `POST /inventario/marcas/rapida`
- Product validation in `StoreProductRequest` / `UpdateProductRequest`

## Database
- `migrate:fresh --seed` resets DB
- Current pending migrations check via `php artisan migrate:status`
- Plan de cuentas importado desde `database/seeders/plan_de_cuenta.csv` (copiado de `C:\Users\Sistema\Downloads\PLAN DE CUENTA.csv`)
- Mapeo de tipos: PATRIM. → PATRIMONIO, COSTO → GASTO, EGRESO → GASTO
- Para reimportar el plan de cuentas sin perder datos: `php artisan accounts:import-csv`
- El seeder `ChartOfAccountsSeeder` lee automáticamente el CSV desde `database/seeders/plan_de_cuenta.csv`