# -*- coding: utf-8 -*-
import pyodbc

conn_str = (
    'DRIVER={ODBC Driver 17 for SQL Server};'
    'SERVER=192.168.0.4\\PM2014;'
    'DATABASE=PM_DRUG;'
    'UID=sa;'
    'PWD=tmddls214!%(;'
    'TrustServerCertificate=yes;'
)
conn = pyodbc.connect(conn_str, timeout=10)
cursor = conn.cursor()

cursor.execute('''
    SELECT G.GoodsName, G.Saleprice, ISNULL(IT.IM_QT_sale_debit, 0) AS Stock
    FROM CD_GOODS G
    LEFT JOIN IM_total IT ON G.DrugCode = IT.DrugCode
    WHERE G.GoodsName LIKE '%티어가드%'
    ORDER BY G.GoodsName
''')

rows = cursor.fetchall()
print('=== 티어가드 보유 현황 ===')
for row in rows:
    print(f'{row.GoodsName} | {row.Saleprice:,.0f}원 | 재고: {int(row.Stock)}개')

conn.close()
