# CLAUDE.md - Data Entry App ## Scop Aplicatie pentru introducere date in ERP (bonuri fiscale, chitante) cu workflow de aprobare. ## Documentatie de Referinta - **Cerinte**: `docs/data-entry/REQUIREMENTS.md` - **Arhitectura**: `docs/data-entry/ARCHITECTURE.md` - **Quick Start**: `README.md` ## Decizii Tehnice - **ORM**: SQLModel (Pydantic + SQLAlchemy) - **Migrari**: Alembic - **Database**: SQLite (Faza 1) → Oracle (Faza 2) - **Frontend**: Vue.js 3 + PrimeVue (consistent cu reports-app) ## Workflow Bonuri ``` 1. DRAFT → utilizator completeaza + upload poza 2. PENDING_REVIEW → sistem genereaza note contabile 3. APPROVED/REJECTED → contabil aproba sau respinge 4. SYNCED → (Faza 2) date in Oracle ``` ## Structura Directoare ``` data-entry-app/ ├── backend/ # FastAPI API (port 8003) │ ├── app/ │ │ ├── db/ # SQLModel models + CRUD │ │ ├── schemas/ # Pydantic schemas │ │ ├── services/ # Business logic │ │ └── routers/ # API endpoints │ ├── migrations/ # Alembic migrations │ └── data/ # SQLite DB + uploads ├── frontend/ # Vue.js UI (port 3010) │ └── src/ │ ├── views/ # Page components │ ├── components/ # Reusable components │ └── stores/ # Pinia stores └── docs/ # Documentatie specifica ``` ## Componente Partajate ### Backend - `shared/database/oracle_pool.py` - Conexiune Oracle pentru nomenclatoare si autentificare - `shared/auth/` - JWT authentication (middleware, routes, service) ### Frontend - `shared/frontend/components/LoginView.vue` - Componenta login partajata - `shared/frontend/stores/auth.js` - Pinia auth store factory - `shared/frontend/styles/login.css` - Stiluri login ## Servere Oracle (Producție vs Test) **IMPORTANT**: Există două servere Oracle separate. Verifică întotdeauna la care ești conectat! | Server | IP Oracle | Tunel SSH | Schema Verificare | Company ID | |--------|-----------|-----------|-------------------|------------| | **PRODUCȚIE** | `10.0.20.36` | `./ssh_tunnel.sh` | `ROMFAST` | 114 | | **TEST** | `10.0.20.121` | `./ssh-tunnel-test.sh` | `MARIUSM_AUTO` | 110 | ### Scripturi de Pornire **IMPORTANT**: Folosește scriptul corespunzător mediului dorit! ```bash # Pentru PRODUCȚIE (10.0.20.36) ./start-data-entry-dev.sh # Pornește tot (tunel + backend + frontend) ./start-data-entry-dev.sh stop # Oprește tot ./start-data-entry-dev.sh status # Verifică status # Pentru TEST (10.0.20.121) ./start-data-entry-test.sh # Pornește tot (tunel + backend + frontend) ./start-data-entry-test.sh stop # Oprește tot ./start-data-entry-test.sh status # Verifică status ``` Scripturile fac automat: 1. Opresc tunelul celuilalt mediu (dacă rulează) 2. Pornesc tunelul corect 3. Copiază `.env.prod` sau `.env.test` în `.env` 4. Rulează migrările pe baza de date corectă 5. Pornesc frontend și backend ### Fișiere .env | Fișier | Server | Database | Schema Test | |--------|--------|----------|-------------| | `.env.prod` | PRODUCȚIE (10.0.20.36) | `receipts_prod.db` | ROMFAST (id=114) | | `.env.test` | TEST (10.0.20.121) | `receipts_test.db` | MARIUSM_AUTO (id=110) | ### Verificare conexiune ```bash # Verifică la ce server ești conectat ./ssh_tunnel.sh status # Dacă rulează = PRODUCȚIE ./ssh-tunnel-test.sh status # Dacă rulează = TEST # Verifică schema disponibilă (din backend/) python3 -c " import asyncio from dotenv import load_dotenv load_dotenv() import sys; sys.path.insert(0, '../../shared') from database.oracle_pool import oracle_pool async def check(): await oracle_pool.initialize() async with oracle_pool.get_connection() as conn: with conn.cursor() as cur: cur.execute('SELECT SCHEMA, NUME FROM CONTAFIN_ORACLE.V_NOM_FIRME ORDER BY NUME') for row in cur.fetchall()[:10]: print(f'{row[0]}: {row[1]}') asyncio.run(check()) " ``` ### Sincronizare Nomenclatoare Query-ul pentru furnizori folosește `CORESP_TIP_PART`: - `id_tip_part = 17` → Furnizori - `id_tip_part = 22` → Casa LEI - `id_tip_part = 23` → Casa Valută - `id_tip_part = 24` → Bancă LEI - `id_tip_part = 25` → Bancă Valută ```sql -- Exemplu query furnizori pentru schema MARIUSM_AUTO (TEST) SELECT B.ID_PART, B.DENUMIRE, B.COD_FISCAL, B.ADRESA FROM MARIUSM_AUTO.CORESP_TIP_PART A INNER JOIN MARIUSM_AUTO.VNOM_PARTENERI B ON A.ID_PART = B.ID_PART WHERE A.ID_TIP_PART = 17 AND (B.INACTIV = 0 OR B.INACTIV IS NULL) ORDER BY B.DENUMIRE; ``` ## Comenzi Dezvoltare ```bash # Backend cd data-entry-app/backend pip install -r requirements.txt alembic upgrade head uvicorn app.main:app --reload --port 8003 # Frontend cd data-entry-app/frontend npm install npm run dev -- --port 3010 # Migrari cd data-entry-app/backend alembic revision --autogenerate -m "description" alembic upgrade head ``` ## Tipuri Cheltuieli (hardcoded in Faza 1) | Cod | Tip | Cont | TVA | |-----|-----|------|-----| | FUEL | Combustibil | 6022 | 19% | | MATERIALS | Materiale | 6028 | 19% | | OFFICE | Rechizite | 6024 | 19% | | PHONE | Telefonie | 626 | 19% | | PARKING | Parcare | 6022 | 19% | | FOOD | Alimentatie | 6028 | 0% | | TRANSPORT | Transport | 624 | 19% | | OTHER | Altele | 628 | 19% | ## Integrare Oracle (Faza 2) Vezi `docs/PACK_CONTAFIN.pck` pentru procedurile stocate: - `pack_contafin.init_scriere_act_rul_local()` - `INSERT INTO ACT_TEMP (...)` - `pack_contafin.finalizeaza_scriere_act_rul()` ## API Endpoints Summary ### Receipts CRUD - `POST /api/receipts/` - Create - `GET /api/receipts/` - List (filterable) - `GET /api/receipts/{id}` - Detail - `PUT /api/receipts/{id}` - Update (DRAFT only) - `DELETE /api/receipts/{id}` - Delete (DRAFT only) ### Workflow - `POST /api/receipts/{id}/submit` - Send for review - `POST /api/receipts/{id}/approve` - Approve - `POST /api/receipts/{id}/reject` - Reject - `POST /api/receipts/{id}/resubmit` - Resubmit after rejection ### Attachments - `POST /api/receipts/{id}/attachments` - Upload - `GET /api/attachments/{id}/download` - Download - `DELETE /api/attachments/{id}` - Delete ### Nomenclatures - `GET /api/receipts/partners` - Partners from Oracle - `GET /api/receipts/accounts` - Accounts from Oracle - `GET /api/receipts/cash-registers` - Cash registers from Oracle - `GET /api/receipts/expense-types` - Expense types (hardcoded) ## Testing ```bash # Backend tests cd backend && pytest # Frontend tests cd frontend && npm run test ``` ## Common Issues ### Nomenclatoare goale / furnizori lipsă - Verifică la ce server Oracle ești conectat: `./ssh_tunnel.sh status` - Verifică dacă schema firmei selectate există pe acel server - Sincronizează manual: `POST /api/nomenclature/sync/all` ### Conectat la serverul greșit - PRODUCȚIE are schema `ROMFAST`, TEST are schema `MARIUSM_AUTO` - Oprește tunelul curent și pornește cel corect (vezi secțiunea "Servere Oracle") ### SQLite locked - Asigura-te ca nu ai multiple procese care acceseaza DB-ul ### Upload fails - Verifica permisiuni pe `data/uploads/` - Verifica MIME type (doar image/*, application/pdf) ### Migration errors - `alembic downgrade -1` pentru rollback - Sterge migration file si regenereaza