Commit Graph

38 Commits

Author SHA1 Message Date
Claude Agent
70267d9d8d corectie pljson 2026-03-24 11:48:13 +00:00
Claude Agent
b625609645 feat: configurable invoice line sorting via RF_SORTARE_COMANDA option
cursor_comanda in PACK_FACTURARE now reads RF_SORTARE_COMANDA from OPTIUNI:
1=alphabetical (default, existing behavior), 0=original web order (by ID_COMANDA_ELEMENT).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 09:15:17 +00:00
Claude Agent
61ae58ef25 fix: kit discount amount + price sync no auto-insert + repackaging kit detection
Kit discount: v_disc_amt is per-kit, not per-unit — remove division by
v_cantitate_web so discount lines compute correctly (e.g. -2 x 5 = -10).

Price sync: stop auto-inserting missing articles into price policies
(was inserting with wrong proc_tvav from GoMag). Log warning instead.

Kit detection: extend to single-component repackagings (cantitate_roa > 1)
in both PL/SQL package and price sync/validation services.

Add repackaging kit pricing test for separate_line and distributed modes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-21 11:04:09 +00:00
Claude Agent
5addeb08bd fix: NULL SUMA in PACK_FACTURARE for discount lines + SKU enrichment fallback
PACK_FACTURARE: use PTVA from COMENZI_ELEMENTE (NVL2) in adauga_articol_factura
instead of fetching PROC_TVAV from price list, fixing NULL SUMA for discount
lines with multiple TVA rates (11%, 21%).

sync.py: broaden direct SKU enrichment to all unmapped SKUs regardless of
mapping_status, fixing stale status edge cases.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 22:32:28 +00:00
Claude Agent
3fabe3f4b1 kituri 2026-03-20 21:07:32 +00:00
Claude Agent
b221b257a3 fix: price sync kit components + vat_included type bug
- Fix vat_included comparison: GoMag API returns int 1, not str "1",
  causing all prices to be multiplied by TVA again (double TVA)
- Normalize vat_included to string in gomag_client at parse time
- Price sync now processes kit components individually by looking up
  each component's CODMAT as standalone GoMag product
- Add _insert_component_price for components without existing Oracle price
- resolve_mapped_codmats: ROW_NUMBER dedup for CODMATs with multiple
  NOM_ARTICOLE entries, prefer article with current stock
- pack_import_comenzi: merge_or_insert_articol to merge quantities when
  same article appears from kit + individual on same order

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 15:07:53 +00:00
Claude Agent
0666d6bcdf fix: defer kit discount insertion to avoid duplicate check collision (separate_line)
When 2+ kits produce discount lines with the same unit price and VAT rate,
adauga_articol_comanda raises RAISE_APPLICATION_ERROR(-20000) on the duplicate
(ID_ARTICOL, PTVA, PRET, SIGN(CANTITATE)) check. Defer discount insertion
until after the main article loop, accumulating cross-kit discounts and merging
collisions by summing qty. Different prices remain as separate lines.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 11:57:57 +00:00
Claude Agent
5a10b4fa42 chore: add version comments (20.03.2026) to pack_import_comenzi and pack_import_parteneri
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 10:39:43 +00:00
Claude Agent
9a545617c2 chore: add version comments (20.03.2026) to pack_comenzi and pack_facturare
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 10:37:09 +00:00
Claude Agent
95565af4cd fix: discriminare pe PRET+SIGN(CANTITATE) pentru duplicate CODMAT pe comanda
Permite articole duplicate cu preturi diferite pe aceeasi comanda (kit + direct
cu acelasi CODMAT) si articol + retur la acelasi pret. Cheia de unicitate devine
(ID_COMANDA, ID_ARTICOL, PTVA, PRET, SIGN(CANTITATE)).

Modificari in 8 locuri: duplicate check (pack_comenzi), cursor_comanda factura/aviz,
cursor_lucrare ambele ramuri, adauga_articol_lucrare_pret, adauga_articol_factura,
inchide_comanda. Zero signatura schimbata, zero schema change, zero VFP impact.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 10:32:55 +00:00
Claude Agent
d802a08512 mapari sql 2026-03-19 23:57:52 +00:00
Claude Agent
aa6e035c02 fix(oracle): use na.cont instead of na.cont_vanzare in kit pricing
The column cont_vanzare does not exist in nom_articole. The correct
column name is cont, consistent with all Python code references.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 22:32:20 +00:00
Claude Agent
9e5901a8fb feat(pricing): kit/pachet pricing with price list lookup, replace procent_pret
- Oracle PL/SQL: kit pricing logic with Mode A (distributed discount) and
  Mode B (separate discount line), dual policy support, PRETURI_CU_TVA flag
- Eliminate procent_pret from entire stack (Oracle, Python, JS, HTML)
- New settings: kit_pricing_mode, kit_discount_codmat, price_sync_enabled
- Settings UI: cards for Kit Pricing and Price Sync configuration
- Mappings UI: kit badges with lazy-loaded component prices from price list
- Price sync from orders: auto-update ROA prices when web prices differ
- Catalog price sync: new service to sync all GoMag product prices to ROA
- Kit component price validation: pre-check prices before import
- New endpoint GET /api/mappings/{sku}/prices for component price display
- New endpoints POST /api/price-sync/start, GET status, GET history
- DDL script 07_drop_procent_pret.sql (run after deploy confirmation)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 22:29:18 +00:00
Claude Agent
c534a972a9 feat: multi-gestiune stock verification setting
Replace single-select gestiune dropdown with multi-select checkboxes.
Settings stores comma-separated IDs, Python builds IN clause with bind
variables, Oracle PL/SQL splits CSV via REGEXP_SUBSTR for stock lookup.
Empty selection = all warehouses (unchanged behavior).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 16:15:40 +00:00
Claude Agent
7a2408e310 fix(import): resolve correct id_articol for duplicate CODMATs + gestiune setting
Unified id_articol selection logic in Python (resolve_codmat_ids) and PL/SQL
(resolve_id_articol): filters sters=0 AND inactiv=0, prefers article with
stock in configured gestiune, falls back to MAX(id_articol). Eliminates
mismatch where Python and PL/SQL could pick different id_articol for the
same CODMAT, causing ORA-20000 price-not-found errors.

- Add resolve_codmat_ids helper in validation_service.py (single batch query)
- Refactor validate_skus/validate_prices/ensure_prices to use it
- Add resolve_id_articol function in PL/SQL package body
- Add p_id_gestiune parameter to importa_comanda (spec + body)
- Add /api/settings/gestiuni endpoint and id_gestiune setting
- Add gestiune dropdown in settings UI

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-17 12:18:18 +00:00
Claude Agent
84b24b1434 feat(invoice+import): refresh facturi, detalii factura, fix duplicate CODMAT + rollback
- PL/SQL: handle duplicate CODMAT in nom_articole with MAX(id_articol)
- import_service: add explicit conn.rollback() on Oracle errors
- sync_service: auto-fix stale ERROR orders that exist in Oracle
- invoice_service: add data_act (invoice date) from vanzari table
- sync router: new POST /api/dashboard/refresh-invoices endpoint
- order detail: enrich with invoice data (serie, numar, data factura)
- dashboard: refresh invoices button (desktop + mobile icon)
- quick map modal: compact single-row layout, pre-populate existing mappings
- quick map: link on SKU column instead of CODMAT

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 17:30:23 +00:00
Claude Agent
43327c4a70 feat(oracle): support per-article id_pol in PACK_IMPORT_COMENZI + deploy docs
- PACK_IMPORT_COMENZI: reads optional "id_pol" per article from JSON, uses it
  via NVL(v_id_pol_articol, p_id_pol) — enables separate price policy for
  transport/discount articles vs regular order articles
- README.md: add Windows deploy section (deploy.ps1, update.ps1, .env example)
- CLAUDE.md: add reference to Windows deploy docs

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-16 16:42:41 +00:00
Claude Agent
a9d0cead79 chore: commit all pending changes including deploy scripts and Windows config
- deploy.ps1, iis-web.config: Windows Server deployment scripts
- api/app/routers/sync.py, dashboard.py: router updates
- api/app/services/import_service.py, sync_service.py: service updates
- api/app/static/css/style.css, js/*.js: UI updates
- api/database-scripts/08_PACK_FACTURARE.pck: Oracle package
- .gitignore: add .gittoken
- CLAUDE.md, agent configs: documentation updates

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-16 15:05:04 +00:00
82196b9dc0 feat(sqlite): refactor orders schema + dashboard period filter
Replace import_orders (insert-per-run) with orders table (one row per
order, upsert on conflict). Eliminates dedup CTE on every dashboard
query and prevents unbounded row growth at 4-500 orders/sync.

Key changes:
- orders table: PK order_number, upsert via ON CONFLICT DO UPDATE;
  COALESCE preserves id_comanda once set; times_skipped auto-increments
- sync_run_orders: lightweight junction (sync_run_id, order_number)
  replaces sync_run_id column on orders
- order_items: PK changed to (order_number, sku), INSERT OR IGNORE
- Auto-migration in init_sqlite(): import_orders → orders on first boot,
  old table renamed to import_orders_bak
- /api/dashboard/orders: period_days param (3/7/30/0=all, default 7)
- Dashboard: period selector buttons in orders card header
- start.sh: stop existing process on port 5003 before restart;
  remove --reload (broken on WSL2 /mnt/e/)
- Add invoice_service, E2E Playwright tests, Oracle package updates

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-13 16:18:57 +02:00
69841872d1 pljson 2026-03-11 12:32:25 +02:00
8e94c05901 actualizare 2026-03-10 15:23:12 +02:00
d421baccf0 Remove IdGestiune parameter and update IdPol example value
Changes:
- Remove p_id_gestiune parameter from PACK_IMPORT_COMENZI.importa_comanda signature
  (both package spec and body)
- Update VFP sync-comenzi-web.prg to remove ?goSettings.IdGestiune from Oracle call
- Update settings.ini.example with IdPol=39 as example value

Simplified order import: IdGestiune is no longer needed as a configurable parameter.
Orders now use only IdPol and IdSectie.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 00:57:43 +02:00
7a50d2156a Change ROA settings defaults to NULL and remove obsolete script
Changes:
1. Update settings.ini.example with [ROA] section using NULL defaults
2. Modify ApplicationSetup.prg to handle NULL values properly:
   - CreateDefaultIni writes "NULL" string to INI file
   - LoadSettings converts "NULL" string to VFP .NULL. value
3. Update Oracle package defaults from (0, 1, 2) to (NULL, NULL, NULL):
   - p_id_pol DEFAULT NULL
   - p_id_gestiune DEFAULT NULL
   - p_id_sectie DEFAULT NULL
4. Remove obsolete 02_import_parteneri.sql (replaced by 05_pack_import_parteneri.pck)
5. Update local settings.ini with NULL values

Rationale:
- NULL is semantically correct (no policy/gestiune/sectie specified)
- Previous defaults (0, 1, 2) were invalid IDs in ROA system
- Maintains backward compatibility through Oracle DEFAULT NULL

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 00:02:50 +02:00
ef6a318aed Add configurable ROA settings (IdPol, IdGestiune, IdSectie) to VFP integration
Implement global configuration for ROA system IDs via settings.ini:

VFP Changes:
- Add [ROA] section to settings.ini with IdPol, IdGestiune, IdSectie
- Update ApplicationSetup.LoadSettings to read ROA configuration
- Update ApplicationSetup.CreateDefaultIni with default values (0, 1, 2)
- Modify sync-comenzi-web.prg to pass ROA settings to Oracle package

Oracle Package Changes (06_pack_import_comenzi.pck):
- Add optional parameters to importa_comanda signature with defaults
  * p_id_pol (default: 0)
  * p_id_gestiune (default: 1)
  * p_id_sectie (default: 2)
- Remove hardcoded constants (c_id_pol, c_id_sectie, c_id_gestiune)
- Update PACK_COMENZI.adauga_comanda call to use p_id_sectie parameter
- Update PACK_COMENZI.adauga_articol_comanda to use p_id_pol and p_id_sectie

Benefits:
- Flexible configuration without code changes
- Maintains backward compatibility with default values
- Centralized ROA system configuration

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-19 22:36:21 +02:00
05bb0b1b01 Reorganize Oracle packages into database-scripts for unified git tracking
Move Oracle package files from docs/ to api/database-scripts/ with sequential numbering:
- PACK_COMENZI.pck → 04_pack_comenzi.pck (renamed with git)
- PACK_IMPORT_PARTENERI.pck → 05_pack_import_parteneri.pck
- PACK_IMPORT_COMENZI.pck → 06_pack_import_comenzi.pck

Remove 04_import_comenzi.sql (replaced by 06_pack_import_comenzi.pck actual version)

Update VFP integration files and project structure.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-19 22:32:41 +02:00
d1858f86b6 Phase 2 implementation: VFP Integration with Oracle synchronization
Major architectural changes:
- Convert Oracle IMPORT_PARTENERI.cauta_sau_creeaza_partener from FUNCTION to PROCEDURE with OUT parameter for VFP compatibility
- Add IS_PERSOANA_JURIDICA parameter to support individual vs company detection
- Implement sync-comenzi-web.prg orchestrator for generic web order processing with 5-minute timer automation
- Create ApplicationSetup class for proper object-oriented configuration management
- Add comprehensive Oracle connection and sync settings via settings.ini configuration system
- Implement generic web order processing functions (ProcessWebOrder, ValidateWebOrder, CleanWebText, ConvertWebDate)
- Add proper VFP-Oracle integration with correct procedure call syntax using OUT parameters
- Rename gomag-vending.prg to gomag-adapter.prg for clarity and platform-specific functionality
- Move CheckIniFile function to utils.prg for better code organization
- Add settings.ini.example template and update .gitignore to exclude actual settings files
- Implement comprehensive logging system with rotation and error handling
- Add connection validation and retry logic for robust Oracle integration

Technical improvements:
- Proper JSON processing integration with existing nfjson library
- Comprehensive error handling with categorized logging (INFO, ERROR, WARN)
- Timer-based automation with configurable intervals
- Settings validation and default value creation
- Generic function naming for multi-platform support
- Class-based setup system replacing procedural approach

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-10 16:01:42 +03:00
86e9d32b76 Complete Phase 1: Oracle Import System - 95% Functional
## Major Achievements

###  PACK_COMENZI Issues Resolved
- Fixed V_INTERNA=2 parameter for client orders (was causing CASE statement errors)
- Corrected FK constraints: ID_GESTIUNE=NULL, ID_SECTIE=2 for INTERNA=2
- All Oracle packages now compile and function correctly

###  Comprehensive Test Suite
- Created test_complete_import.py with full end-to-end validation
- Automated setup/teardown with proper trigger handling (trg_NOM_ARTICOLE_befoins)
- Test data management with specific ID ranges (9999001-9999003)

###  Database Foundation Complete
- PACK_IMPORT_PARTENERI: 100% functional partner creation/retrieval
- PACK_IMPORT_COMENZI: 95% functional with gaseste_articol_roa working perfectly
- ARTICOLE_TERTI mappings: Complex SKU mapping system operational
- All individual components validated with real data

### 🧹 Code Cleanup
- Removed 8 temporary/debug files
- Consolidated into 5 essential files
- Updated documentation with execution methods and results

## Test Results
- **Article Mapping:**  3 mappings found for CAFE100→CAF01
- **JSON Parsing:**  Oracle PACK_JSON integration working
- **Partner Management:**  Automatic partner creation functional
- **Order Import:** ⚠️ 95% success (order creation works, minor article processing optimization needed)

## Ready for Phase 2 VFP Integration
All core components validated and operational for Visual FoxPro integration.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-10 14:18:45 +03:00
a47af979b8 Reorganize testing infrastructure and fix Oracle cursor loop syntax
Major changes:
- Fix cursor loop syntax in 04_import_comenzi.sql using BULK COLLECT pattern
- Remove obsolete test scripts (apply_fix.py, check_*.py, debug_functions.py, test_*.py)
- Add comprehensive README.md files for api/ and api/tests/ directories
- Keep only essential testing scripts (final_validation.py, test_syntax.py)
- Update PRD.md with latest project status

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-10 13:09:32 +03:00
52454a5925 Complete P1-004: Testing Manual Packages and reorganize test files
- Complete manual testing of all Oracle PL/SQL packages
- Document 75% success rate (3/4 components passing)
- Move all test scripts from api/ to api/tests/ subdirectory
- Update P1-004 story with comprehensive test results
- Identify external dependency blocking full order import
- Mark Phase 1 as 95% complete, ready for Phase 2

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-10 01:25:27 +03:00
1dc5da4ed2 Fix Oracle PL/SQL compilation errors by adding NULL statements to empty IF blocks
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-10 00:26:24 +03:00
4d712642c1 Add optional IS_PERSOANA_JURIDICA parameter to PACK_IMPORT_PARTENERI
- Add p_is_persoana_juridica parameter to cauta_sau_creeaza_partener function
- Enable explicit person type detection from GoMag orders data
- Maintain backward compatibility with NULL default value
- Priority logic: explicit parameter > CNP auto-detection
- Improve accuracy when CNP is not available for individuals
- Support 1=persoana juridica, 0=persoana fizica, NULL=auto-detect

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-10 00:08:51 +03:00
ae9fc2c3d3 Optimize performance by disabling verbose pINFO logging in PACK_IMPORT_PARTENERI
- Comment out non-critical pINFO calls to reduce I/O overhead
- Keep ERROR and WARNING logs for debugging critical issues
- Preserve logging for address creation warnings and validation errors
- Reduce procedure execution time by eliminating unnecessary log writes
- Maintain error tracking through g_last_error system

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-10 00:06:28 +03:00
ee8463fcda Remove Romanian diacritics from PACK_IMPORT_PARTENERI comments
- Replace ÎNCEPUT → INCEPUT in log messages
- Replace SFÂRȘIT → SFARSIT in log messages
- Replace NEAȘTEPTAT → NEASTEPTAT in error messages
- Replace În → In in comments
- Ensure ASCII compatibility for Oracle database systems

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-10 00:02:59 +03:00
f4145f773c Implement unified error handling system for PACK_IMPORT_PARTENERI
- Add g_last_error package variable matching PACK_JSON/PACK_IMPORT_COMENZI pattern
- Implement get_last_error() and clear_error() functions for VFP orchestrator integration
- Replace exceptions with error storage in validation and main functions
- Return -1 on errors instead of raising exceptions for deferred error handling
- Enable orchestrator to read errors before deciding when to log them

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-09 23:59:26 +03:00
0b9814114d Implement error handling system for PACK_IMPORT_COMENZI similar to PACK_JSON
- Add g_last_error package variable for VFP orchestrator integration
- Replace immediate pINFO logging with error storage for deferred logging
- Implement get_last_error() and clear_error() functions matching PACK_JSON pattern
- Update Oracle 10g compatibility for PACK_JSON regex patterns
- Enhance PACK_COMENZI with OUT parameter version for ID_COMANDA return

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-09 23:57:26 +03:00
dc91372760 Add PACK_JSON generic parser and refactor IMPORT_COMENZI package
- Create PACK_JSON: Generic JSON parser for Oracle 10g/11g/12c compatibility
  * Uses only standard Oracle functions (no dependencies)
  * Functions: parse_array, get_string, get_number, get_boolean
  * Built-in error tracking with g_last_error property
  * Comprehensive test suite with 4 test functions
  * Supports nested objects and complex JSON structures

- Refactor IMPORT_COMENZI to use PACK_JSON instead of manual parsing
  * Clean separation of concerns - JSON parsing vs business logic
  * Improved error handling and logging consistency
  * Uses pINFO for consistent logging across packages

- Update IMPORT_PARTENERI logging to use pINFO consistently
  * Remove custom log_operatie function
  * Standardize logging format across all packages

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-09 22:36:03 +03:00
3a4029cc6e Fix PACK_IMPORT_PARTENERI compilation errors and update logging
- Fix pack_def procedure calls with correct parameter signatures
- Change from function calls to procedure calls with OUT parameters
- Remove diacritics from all Romanian text in package
- Simplify NULL comparisons to use IS NULL only
- Update logging to use INFO table instead of system_log
- Rename package to PACK_IMPORT_PARTENERI for consistency

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-09 21:21:09 +03:00
3a234b5240 Remove FXP files from tracking and update gitignore
- Remove nfjson/nfjsonread.FXP from git tracking
- Add Python cache patterns (__pycache__/, *.py[cod], *$py.class)
- Add environment file patterns (.env, .env.local, .env.*.local)
- Reorganize project structure with VFP files moved to vfp/ directory
- Add comprehensive database scripts and documentation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-09 19:38:31 +03:00