# CLAUDE.md This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. ## Project Overview **System:** Import Comenzi Web โ†’ Sistem ROA Oracle This is a multi-tier system that automatically imports orders from web platforms (GoMag, etc.) into the ROA Oracle ERP system. The project combines Oracle PL/SQL packages, Visual FoxPro orchestration, and a Flask web admin interface for SKU mapping management. **Current Status:** Phase 1 (Database Foundation) - 75% Complete - โœ… P1-001: ARTICOLE_TERTI table created - โœ… P1-002: IMPORT_PARTENERI package complete - โœ… P1-003: IMPORT_COMENZI package complete - ๐Ÿ”„ P1-004: Manual testing packages (NEXT UP) ## Architecture ``` [Web Platform API] โ†’ [VFP Orchestrator] โ†’ [Oracle PL/SQL] โ†’ [Web Admin Interface] โ†“ โ†“ โ†‘ โ†‘ JSON Orders Process & Log Store/Update Configuration ``` ### Tech Stack - **Backend:** Oracle PL/SQL packages - **Integration:** Visual FoxPro 9 - **Admin Interface:** Flask + Oracle connection pool - **Data:** Oracle 11g/12c (ROA system) ## Core Components ### Oracle PL/SQL Packages #### 1. IMPORT_PARTENERI Package **Location:** `api/database-scripts/02_import_parteneri.sql` **Functions:** - `cauta_sau_creeaza_partener()` - Search/create partners with priority: cod_fiscal โ†’ denumire โ†’ create new - `parseaza_adresa_semicolon()` - Parse addresses in format "JUD:Bucureศ™ti;BUCURESTI;Str.Victoriei;10" **Logic:** - Individual vs company detection (CUI 13 digits) - Automatic address defaults to Bucureศ™ti Sectorul 1 - All new partners get ID_UTIL = -3 (system) #### 2. IMPORT_COMENZI Package **Location:** `api/database-scripts/03_import_comenzi.sql` **Functions:** - `gaseste_articol_roa()` - Complex SKU mapping with pipelined functions - `importa_comanda_web()` - Complete order import with JSON parsing **Mapping Types:** - Simple: SKU found directly in nom_articole (not stored in ARTICOLE_TERTI) - Repackaging: SKU โ†’ CODMAT with different quantities - Complex sets: One SKU โ†’ multiple CODMATs with percentage pricing ### Visual FoxPro Integration #### gomag-vending.prg **Location:** `vfp/gomag-vending.prg` Current functionality: - GoMag API integration with pagination - JSON data retrieval and processing - HTML entity cleaning (ฤƒโ†’a, ศ™โ†’s, ศ›โ†’t, รฎโ†’i, รขโ†’a) **Future:** Will be adapted for JSON output to Oracle packages #### sync-comenzi-web.prg (Phase 2) **Planned orchestrator with:** - 5-minute timer automation - Oracle package integration - Comprehensive logging system - Error handling and retry logic ### Database Schema #### ARTICOLE_TERTI Table **Location:** `api/database-scripts/01_create_table.sql` ```sql CREATE TABLE ARTICOLE_TERTI ( sku VARCHAR2(100), -- SKU from web platform codmat VARCHAR2(50), -- CODMAT from nom_articole cantitate_roa NUMBER(10,3), -- ROA units per web unit procent_pret NUMBER(5,2), -- Price percentage for sets activ NUMBER(1), -- 1=active, 0=inactive PRIMARY KEY (sku, codmat) ); ``` ### Flask Admin Interface #### admin.py **Location:** `api/admin.py` **Features:** - Oracle connection pool management - SKU mappings CRUD operations - Web interface for configuration - Real-time validation ## Development Commands ### Database Setup ```bash # Start Oracle container docker-compose up -d # Run database scripts in order sqlplus CONTAFIN_ORACLE/password@ROA_ROMFAST @01_create_table.sql sqlplus CONTAFIN_ORACLE/password@ROA_ROMFAST @02_import_parteneri.sql sqlplus CONTAFIN_ORACLE/password@ROA_ROMFAST @03_import_comenzi.sql ``` ### VFP Development ```foxpro DO vfp/gomag-vending.prg ``` ### Flask Admin Interface ```bash cd api python admin.py ``` ## Project Structure ``` / โ”œโ”€โ”€ api/ # โœ… Flask Admin & Database โ”‚ โ”œโ”€โ”€ admin.py # โœ… Flask app with Oracle pool โ”‚ โ”œโ”€โ”€ database-scripts/ # โœ… Oracle SQL scripts โ”‚ โ”‚ โ”œโ”€โ”€ 01_create_table.sql # โœ… ARTICOLE_TERTI table โ”‚ โ”‚ โ”œโ”€โ”€ 02_import_parteneri.sql # โœ… Partners package โ”‚ โ”‚ โ””โ”€โ”€ 03_import_comenzi.sql # โœ… Orders package โ”‚ โ”œโ”€โ”€ Dockerfile # โœ… Oracle client container โ”‚ โ”œโ”€โ”€ tnsnames.ora # โœ… Oracle connection config โ”‚ โ”œโ”€โ”€ .env # โœ… Environment variables โ”‚ โ””โ”€โ”€ requirements.txt # โœ… Python dependencies โ”œโ”€โ”€ docs/ # ๐Ÿ“‹ Project Documentation โ”‚ โ”œโ”€โ”€ PRD.md # โœ… Product Requirements โ”‚ โ”œโ”€โ”€ LLM_PROJECT_MANAGER_PROMPT.md # โœ… Project Management โ”‚ โ””โ”€โ”€ stories/ # ๐Ÿ“‹ User Stories โ”‚ โ”œโ”€โ”€ P1-001-ARTICOLE_TERTI.md # โœ… Story P1-001 (COMPLETE) โ”‚ โ”œโ”€โ”€ P1-002-Package-IMPORT_PARTENERI.md # โœ… Story P1-002 (COMPLETE) โ”‚ โ”œโ”€โ”€ P1-003-Package-IMPORT_COMENZI.md # โœ… Story P1-003 (COMPLETE) โ”‚ โ””โ”€โ”€ P1-004-Testing-Manual-Packages.md # ๐Ÿ“‹ Story P1-004 (READY) โ”œโ”€โ”€ vfp/ # โณ VFP Integration โ”‚ โ”œโ”€โ”€ gomag-vending.prg # โœ… Current GoMag client โ”‚ โ”œโ”€โ”€ utils.prg # โœ… Utility functions โ”‚ โ”œโ”€โ”€ nfjson/ # โœ… JSON parsing library โ”‚ โ””โ”€โ”€ sync-comenzi-web.prg # โณ Future orchestrator โ”œโ”€โ”€ docker-compose.yaml # โœ… Container setup โ””โ”€โ”€ logs/ # โœ… Application logs ``` ## Configuration ### Environment Variables (.env) ```env ORACLE_USER=CONTAFIN_ORACLE ORACLE_PASSWORD=******** ORACLE_DSN=ROA_ROMFAST TNS_ADMIN=/app INSTANTCLIENTPATH=/opt/oracle/instantclient ``` ### Business Rules #### Partners - Search priority: cod_fiscal โ†’ denumire โ†’ create new - Individuals (CUI 13 digits): separate nume/prenume - Default address: Bucureศ™ti Sectorul 1 - All new partners: ID_UTIL = -3 #### Articles - Simple SKUs: found directly in nom_articole (not stored) - Special mappings: only repackaging and complex sets - Inactive articles: activ=0 (not deleted) #### Orders - Uses existing PACK_COMENZI packages - Default: ID_GESTIUNE=1, ID_SECTIE=1, ID_POL=0 - Delivery date = order date + 1 day - All orders: INTERNA=0 (external) ## Phase Implementation Status ### โœ… Phase 1: Database Foundation (75% Complete) - **P1-001:** โœ… ARTICOLE_TERTI table + Docker setup - **P1-002:** โœ… IMPORT_PARTENERI package complete - **P1-003:** โœ… IMPORT_COMENZI package complete - **P1-004:** ๐Ÿ”„ Manual testing (READY TO START) ### โณ Phase 2: VFP Integration (Planned) - Adapt gomag-vending.prg for JSON output - Create sync-comenzi-web.prg orchestrator - Oracle packages integration - Logging system with rotation ### โณ Phase 3: Web Admin Interface (Planned) - Flask app with Oracle connection pool - HTML/CSS admin interface - JavaScript CRUD operations - Client/server-side validation ### โณ Phase 4: Testing & Deployment (Planned) - End-to-end testing with real orders - Complex mappings validation - Production environment setup - User documentation ## Key Functions ### Oracle Packages - `IMPORT_PARTENERI.cauta_sau_creeaza_partener()` - Partner management - `IMPORT_PARTENERI.parseaza_adresa_semicolon()` - Address parsing - `IMPORT_COMENZI.gaseste_articol_roa()` - SKU resolution - `IMPORT_COMENZI.importa_comanda_web()` - Order import ### VFP Utilities (utils.prg) - `LoadSettings` - INI configuration management - `InitLog`/`LogMessage`/`CloseLog` - Logging system - `TestConnectivity` - Connection verification - `CreateDefaultIni` - Default configuration ## Success Metrics ### Technical KPIs - Import success rate > 95% - Average processing time < 30s per order - Zero downtime for main ROA system - 100% log coverage ### Business KPIs - 90% reduction in manual order entry time - Elimination of manual transcription errors - New mapping configuration < 5 minutes ## Error Handling ### Categories 1. **Oracle connection errors:** Retry logic + alerts 2. **SKU not found:** Log warning + skip item 3. **Invalid partner:** Create attempt + detailed log 4. **Duplicate orders:** Skip with info log ### Logging Format ``` 2025-09-09 14:30:25 | ORDER-123 | OK | ID:456789 2025-09-09 14:30:26 | ORDER-124 | ERROR | SKU 'XYZ' not found ``` ## Project Manager Commands Available commands for project tracking: - `status` - Overall progress and current story - `stories` - List all stories with status - `phase` - Current phase details - `risks` - Identify and prioritize risks - `demo [story-id]` - Demonstrate implemented functionality - `plan` - Re-planning for changes