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>
79 lines
3.4 KiB
Python
79 lines
3.4 KiB
Python
"""Explore Oracle structure for invoice matching."""
|
|
import oracledb
|
|
import os
|
|
|
|
os.environ['PATH'] = r'C:\app\Server\product\18.0.0\dbhomeXE\bin' + ';' + os.environ.get('PATH','')
|
|
oracledb.init_oracle_client()
|
|
conn = oracledb.connect(user='VENDING', password='ROMFASTSOFT', dsn='ROA')
|
|
cur = conn.cursor()
|
|
|
|
# Recent vanzari (last 10 days)
|
|
cur.execute("""
|
|
SELECT v.id_vanzare, v.numar_act, v.serie_act,
|
|
TO_CHAR(v.data_act, 'YYYY-MM-DD') as data_act,
|
|
v.total_fara_tva, v.total_cu_tva, v.id_part, v.id_comanda,
|
|
p.denumire as partener
|
|
FROM vanzari v
|
|
LEFT JOIN nom_parteneri p ON v.id_part = p.id_part
|
|
WHERE v.sters = 0 AND v.data_act >= SYSDATE - 10
|
|
ORDER BY v.data_act DESC
|
|
""")
|
|
print('=== Recent VANZARI (last 10 days) ===')
|
|
print(f'{"ID_VANZ":>8s} {"NR_ACT":>8s} {"SERIE":>6s} {"DATA":>12s} {"TOTAL_FARA":>12s} {"TOTAL_CU":>12s} {"ID_PART":>8s} {"ID_CMD":>8s} PARTENER')
|
|
for r in cur:
|
|
print(f'{r[0]:8d} {str(r[1] or ""):>8s} {str(r[2] or ""):>6s} {str(r[3]):>12s} {float(r[4] or 0):12.2f} {float(r[5] or 0):12.2f} {r[6] or 0:8d} {str(r[7] or ""):>8s} {r[8] or ""}')
|
|
|
|
print()
|
|
|
|
# Vanzari_detalii for those invoices
|
|
cur.execute("""
|
|
SELECT vd.id_vanzare, vd.id_articol, a.codmat, a.denumire,
|
|
vd.cantitate, vd.pret, vd.pret_cu_tva, vd.proc_tvav
|
|
FROM vanzari_detalii vd
|
|
JOIN vanzari v ON vd.id_vanzare = v.id_vanzare
|
|
LEFT JOIN nom_articole a ON vd.id_articol = a.id_articol
|
|
WHERE v.sters = 0 AND vd.sters = 0 AND v.data_act >= SYSDATE - 10
|
|
ORDER BY vd.id_vanzare, vd.id_articol
|
|
""")
|
|
print('=== Recent VANZARI_DETALII (last 10 days) ===')
|
|
print(f'{"ID_VANZ":>8s} {"ID_ART":>8s} {"CODMAT":>15s} {"DENUMIRE":>40s} {"QTY":>8s} {"PRET":>10s} {"PRET_CU":>10s} {"TVA%":>6s}')
|
|
for r in cur:
|
|
print(f'{r[0]:8d} {r[1]:8d} {str(r[2] or ""):>15s} {str((r[3] or "")[:40]):>40s} {float(r[4] or 0):8.2f} {float(r[5] or 0):10.4f} {float(r[6] or 0):10.4f} {float(r[7] or 0):6.1f}')
|
|
|
|
print()
|
|
|
|
# Also get SQLite orders for comparison
|
|
print('=== SQLite orders (imported, last 10 days) ===')
|
|
import sqlite3
|
|
db = sqlite3.connect(r'C:\gomag-vending\api\data\import.db')
|
|
c = db.cursor()
|
|
c.execute("""
|
|
SELECT o.order_number, o.order_date, o.customer_name, o.status,
|
|
o.id_comanda, o.order_total,
|
|
o.factura_serie, o.factura_numar, o.factura_data
|
|
FROM orders o
|
|
WHERE o.order_date >= date('now', '-10 days')
|
|
ORDER BY o.order_date DESC
|
|
""")
|
|
print(f'{"ORDER_NR":>10s} {"DATE":>12s} {"CLIENT":>30s} {"STATUS":>10s} {"ID_CMD":>8s} {"TOTAL":>10s} {"F_SERIE":>8s} {"F_NR":>8s} {"F_DATA":>12s}')
|
|
for r in c:
|
|
print(f'{str(r[0]):>10s} {str(r[1])[:10]:>12s} {str((r[2] or "")[:30]):>30s} {str(r[3]):>10s} {str(r[4] or ""):>8s} {float(r[5] or 0):10.2f} {str(r[6] or ""):>8s} {str(r[7] or ""):>8s} {str(r[8] or ""):>12s}')
|
|
|
|
print()
|
|
|
|
# Order items
|
|
c.execute("""
|
|
SELECT oi.order_number, oi.sku, oi.product_name, oi.quantity, oi.price, oi.vat, oi.mapping_status
|
|
FROM order_items oi
|
|
JOIN orders o ON oi.order_number = o.order_number
|
|
WHERE o.order_date >= date('now', '-10 days')
|
|
ORDER BY oi.order_number, oi.sku
|
|
""")
|
|
print('=== SQLite order_items (last 10 days) ===')
|
|
print(f'{"ORDER_NR":>10s} {"SKU":>20s} {"PRODUCT":>40s} {"QTY":>6s} {"PRICE":>10s} {"VAT":>6s} {"MAP":>8s}')
|
|
for r in c:
|
|
print(f'{str(r[0]):>10s} {str(r[1] or ""):>20s} {str((r[2] or "")[:40]):>40s} {float(r[3] or 0):6.1f} {float(r[4] or 0):10.2f} {float(r[5] or 0):6.1f} {str(r[6] or ""):>8s}')
|
|
|
|
db.close()
|
|
conn.close()
|