import pymysql

conn = pymysql.connect(host='85.215.144.168', port=3306, user='asesoft', password='Pantera1', database='pastelerias')
cur = conn.cursor()

cur.execute("SHOW COLUMNS FROM ge_clientes")
cols_cli = [row[0] for row in cur.fetchall()]
print("ge_clientes cols with 'cuenta':", [c for c in cols_cli if 'cuenta' in c.lower()])

cur.execute("SHOW COLUMNS FROM ge_proveedores")
cols_pro = [row[0] for row in cur.fetchall()]
print("ge_proveedores cols with 'cuenta':", [c for c in cols_pro if 'cuenta' in c.lower()])

cur.execute("SELECT id, nombre, subcuenta_contable FROM ge_empresas WHERE activo = 1")
print("ge_empresas:", cur.fetchall())

# Check if any tables like ge_clientes_subcuentas already exist
cur.execute("SHOW TABLES LIKE '%subcuenta%'")
print("Existing subcuenta tables:", cur.fetchall())

# Check if ge_clientes has any non-null subcuenta_contable
if 'subcuenta_contable' in cols_cli:
    cur.execute("SELECT COUNT(*), COUNT(NULLIF(subcuenta_contable, '')) FROM ge_clientes")
    print("ge_clientes total rows and rows with subcuenta_contable:", cur.fetchone())

if 'subcuenta_contable' in cols_pro:
    cur.execute("SELECT COUNT(*), COUNT(NULLIF(subcuenta_contable, '')) FROM ge_proveedores")
    print("ge_proveedores total rows and rows with subcuenta_contable:", cur.fetchone())

conn.close()
