add: scripts for invoice-order matching and SKU discovery

Analysis scripts to match GoMag orders with Oracle invoices by
date/client/total, then compare line items by price to discover
SKU → id_articol mappings. Generates SQL for nom_articole codmat
updates and CSV for ARTICOLE_TERTI repackaging/set mappings.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude Agent
2026-03-17 12:01:51 +00:00
parent dafc2df0d4
commit 3d73d9e422
14 changed files with 2451 additions and 0 deletions

30
scripts/count_orders.py Normal file
View File

@@ -0,0 +1,30 @@
import sqlite3, sys
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
db = sqlite3.connect(r'C:\gomag-vending\api\data\import.db')
c = db.cursor()
c.execute("SELECT COUNT(*), MIN(order_date), MAX(order_date) FROM orders")
total, min_d, max_d = c.fetchone()
print(f"Total orders: {total} (from {min_d} to {max_d})")
c.execute("SELECT status, COUNT(*) FROM orders GROUP BY status ORDER BY COUNT(*) DESC")
print("\nBy status:")
for r in c:
print(f" {r[0]:20s} {r[1]:5d}")
c.execute("SELECT COUNT(*) FROM orders WHERE status IN ('IMPORTED','ALREADY_IMPORTED')")
print(f"\nImported (matchable): {c.fetchone()[0]}")
c.execute("SELECT COUNT(*) FROM order_items")
print(f"Total order_items: {c.fetchone()[0]}")
c.execute("""
SELECT COUNT(DISTINCT oi.sku)
FROM order_items oi
JOIN orders o ON oi.order_number = o.order_number
WHERE o.status IN ('IMPORTED','ALREADY_IMPORTED')
""")
print(f"Unique SKUs in imported orders: {c.fetchone()[0]}")
db.close()