"""Compare specific GoMag order vs Oracle invoice""" import sys, sqlite3, oracledb, os sys.stdout.reconfigure(encoding='utf-8', errors='replace') os.environ['PATH'] = r'C:\app\Server\product\18.0.0\dbhomeXE\bin' + ';' + os.environ.get('PATH','') oracledb.init_oracle_client() ORDER = sys.argv[1] if len(sys.argv) > 1 else '480104185' FACT_NR = sys.argv[2] if len(sys.argv) > 2 else '4105' # GoMag order from SQLite db = sqlite3.connect(r'C:\gomag-vending\api\data\import.db') db.row_factory = sqlite3.Row c = db.cursor() c.execute("SELECT * FROM orders WHERE order_number = ?", (ORDER,)) order = dict(c.fetchone()) c.execute("SELECT * FROM order_items WHERE order_number = ? ORDER BY sku", (ORDER,)) items = [dict(r) for r in c.fetchall()] db.close() print(f"=== GoMag Order {ORDER} ===") print(f" Client: {order['customer_name']}") print(f" Shipping: {order['shipping_name']}") print(f" Billing: {order['billing_name']}") print(f" Date: {order['order_date']}") print(f" Total: {order['order_total']}") print(f" Status: {order['status']}") print(f" Items ({len(items)}):") go_total = 0 for it in items: line = it['quantity'] * it['price'] go_total += line print(f" SKU={it['sku']:25s} qty={it['quantity']:6.1f} x {it['price']:8.2f} = {line:8.2f} {it['product_name']}") print(f" Sum lines: {go_total:.2f}") # Oracle invoice conn = oracledb.connect(user='VENDING', password='ROMFASTSOFT', dsn='ROA') cur = conn.cursor() cur.execute(""" SELECT v.id_vanzare, TO_CHAR(v.data_act, 'YYYY-MM-DD'), v.total_fara_tva, v.total_cu_tva, p.denumire, p.prenume FROM vanzari v LEFT JOIN nom_parteneri p ON v.id_part = p.id_part WHERE v.numar_act = :1 AND v.serie_act = 'VM' AND v.sters = 0 AND v.data_act >= TO_DATE('2026-03-01','YYYY-MM-DD') """, [int(FACT_NR)]) rows = cur.fetchall() for row in rows: id_vanz = row[0] print(f"\n=== Oracle Invoice VM{FACT_NR} (id_vanzare={id_vanz}) ===") print(f" Client: {row[4]} {row[5] or ''}") print(f" Date: {row[1]}") print(f" Total fara TVA: {float(row[2]):.2f}") print(f" Total cu TVA: {float(row[3]):.2f}") cur.execute(""" SELECT vd.id_articol, a.codmat, a.denumire, vd.cantitate, vd.pret, vd.pret_cu_tva, vd.proc_tvav FROM vanzari_detalii vd LEFT JOIN nom_articole a ON vd.id_articol = a.id_articol WHERE vd.id_vanzare = :1 AND vd.sters = 0 ORDER BY vd.id_articol """, [id_vanz]) det = cur.fetchall() print(f" Items ({len(det)}):") roa_total = 0 for d in det: line = float(d[3]) * float(d[4]) roa_total += line print(f" COD={str(d[1] or ''):25s} qty={float(d[3]):6.1f} x {float(d[4]):8.2f} = {line:8.2f} TVA={float(d[6]):.0f}% {d[2]}") print(f" Sum lines (fara TVA): {roa_total:.2f}") conn.close()