kdrug-inventory-system/dev_scripts/check_totals.py
시골약사 ad9ac396e2 chore: 개발 파일 정리 및 구조화
- 개발/테스트 스크립트를 dev_scripts/ 폴더로 이동
- 스크린샷을 screenshots/ 폴더로 이동
- 백업 파일 보존 (.backup)
- 처방 관련 추가 스크립트 포함

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-18 04:44:48 +00:00

65 lines
2.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sqlite3
# 데이터베이스 연결
conn = sqlite3.connect('database/kdrug.db')
conn.row_factory = sqlite3.Row
cursor = conn.cursor()
print("=== 입고장별 총금액 확인 ===\n")
# 각 입고장의 라인별 총액 확인
cursor.execute("""
SELECT
pr.receipt_id,
pr.receipt_date,
s.name as supplier_name,
COUNT(prl.line_id) as line_count,
SUM(prl.quantity_g) as total_quantity,
SUM(prl.line_total) as calculated_total
FROM purchase_receipts pr
JOIN suppliers s ON pr.supplier_id = s.supplier_id
LEFT JOIN purchase_receipt_lines prl ON pr.receipt_id = prl.receipt_id
GROUP BY pr.receipt_id
ORDER BY pr.receipt_date DESC
""")
results = cursor.fetchall()
for row in results:
print(f"입고장 ID: {row['receipt_id']}")
print(f" 날짜: {row['receipt_date']}")
print(f" 도매상: {row['supplier_name']}")
print(f" 품목 수: {row['line_count']}")
print(f" 총 수량: {row['total_quantity']}g")
print(f" 총 금액: {row['calculated_total']:,.0f}" if row['calculated_total'] else " 총 금액: 0원")
print("-" * 40)
print("\n=== 입고장 라인 상세 (첫 번째 입고장) ===\n")
# 첫 번째 입고장의 라인 상세 확인
if results:
first_receipt_id = results[0]['receipt_id']
cursor.execute("""
SELECT
herb_item_id,
quantity_g,
unit_price_per_g,
line_total
FROM purchase_receipt_lines
WHERE receipt_id = ?
LIMIT 5
""", (first_receipt_id,))
lines = cursor.fetchall()
for line in lines:
print(f"약재 ID: {line['herb_item_id']}")
print(f" 수량: {line['quantity_g']}g")
print(f" 단가: {line['unit_price_per_g']}원/g")
print(f" 라인 총액: {line['line_total']}")
print(f" 계산 검증: {line['quantity_g']} × {line['unit_price_per_g']} = {line['quantity_g'] * line['unit_price_per_g']}")
print()
conn.close()