feat: 주문 모달 한도/매출 표시 및 UI 개선
- 도매상 한도 API 추가 (wholesaler_limits 테이블) - 다중 도매상 모달: 월 한도 + 실제 월 매출 표시 - 주문 후 예상 사용량 계산 및 경고 표시 - 이모지 대신 로고 이미지 사용 - 약가 → 매출액 헤더 변경 - 매출액 계산: SUM(DRUPRICE)
This commit is contained in:
@@ -1056,3 +1056,125 @@ def api_ai_order_pattern(drug_code):
|
||||
'pattern': None,
|
||||
'message': '주문 이력이 없습니다'
|
||||
})
|
||||
|
||||
|
||||
# ─────────────────────────────────────────────
|
||||
# 도매상 한도 관리 API
|
||||
# ─────────────────────────────────────────────
|
||||
|
||||
@order_bp.route('/wholesaler/limits', methods=['GET'])
|
||||
def api_wholesaler_limits():
|
||||
"""
|
||||
전체 도매상 한도 조회 (현재 월 사용량 포함)
|
||||
|
||||
GET /api/order/wholesaler/limits
|
||||
"""
|
||||
import sqlite3
|
||||
from datetime import datetime
|
||||
|
||||
# 절대 경로 사용
|
||||
db_path = r'c:\Users\청춘약국\source\pharmacy-pos-qr-system\backend\db\orders.db'
|
||||
conn = sqlite3.connect(db_path)
|
||||
conn.row_factory = sqlite3.Row
|
||||
cur = conn.cursor()
|
||||
|
||||
# 현재 월
|
||||
year_month = datetime.now().strftime('%Y-%m')
|
||||
|
||||
# 한도 정보 조회
|
||||
cur.execute('SELECT * FROM wholesaler_limits WHERE is_active = 1 ORDER BY priority')
|
||||
limits = cur.fetchall()
|
||||
|
||||
result = []
|
||||
for row in limits:
|
||||
ws_id = row['wholesaler_id']
|
||||
monthly_limit = row['monthly_limit']
|
||||
|
||||
# 이번 달 실제 주문 금액 조회 (성공한 것만)
|
||||
cur.execute('''
|
||||
SELECT COALESCE(SUM(oi.unit_price * oi.order_qty), 0) as total_amount
|
||||
FROM order_items oi
|
||||
JOIN orders o ON oi.order_id = o.id
|
||||
WHERE o.wholesaler_id = ?
|
||||
AND strftime('%Y-%m', o.order_date) = ?
|
||||
AND o.status IN ('submitted', 'success', 'confirmed')
|
||||
''', (ws_id, year_month))
|
||||
|
||||
usage_row = cur.fetchone()
|
||||
current_usage = usage_row['total_amount'] if usage_row else 0
|
||||
|
||||
usage_percent = (current_usage / monthly_limit * 100) if monthly_limit > 0 else 0
|
||||
remaining = monthly_limit - current_usage
|
||||
|
||||
result.append({
|
||||
'wholesaler_id': ws_id,
|
||||
'monthly_limit': monthly_limit,
|
||||
'current_usage': current_usage,
|
||||
'remaining': remaining,
|
||||
'usage_percent': round(usage_percent, 1),
|
||||
'warning_threshold': row['warning_threshold'],
|
||||
'is_warning': usage_percent >= (row['warning_threshold'] * 100),
|
||||
'priority': row['priority']
|
||||
})
|
||||
|
||||
conn.close()
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'year_month': year_month,
|
||||
'limits': result
|
||||
})
|
||||
|
||||
|
||||
@order_bp.route('/wholesaler/limits/<wholesaler_id>', methods=['PUT'])
|
||||
def api_update_wholesaler_limit(wholesaler_id):
|
||||
"""
|
||||
도매상 한도 수정
|
||||
|
||||
PUT /api/order/wholesaler/limits/geoyoung
|
||||
{
|
||||
"monthly_limit": 30000000,
|
||||
"warning_threshold": 0.85
|
||||
}
|
||||
"""
|
||||
import sqlite3
|
||||
|
||||
data = request.get_json()
|
||||
|
||||
db_path = r'c:\Users\청춘약국\source\pharmacy-pos-qr-system\backend\db\orders.db'
|
||||
conn = sqlite3.connect(db_path)
|
||||
cur = conn.cursor()
|
||||
|
||||
updates = []
|
||||
params = []
|
||||
|
||||
if 'monthly_limit' in data:
|
||||
updates.append('monthly_limit = ?')
|
||||
params.append(data['monthly_limit'])
|
||||
|
||||
if 'warning_threshold' in data:
|
||||
updates.append('warning_threshold = ?')
|
||||
params.append(data['warning_threshold'])
|
||||
|
||||
if 'priority' in data:
|
||||
updates.append('priority = ?')
|
||||
params.append(data['priority'])
|
||||
|
||||
if updates:
|
||||
updates.append("updated_at = datetime('now')")
|
||||
params.append(wholesaler_id)
|
||||
|
||||
cur.execute(f'''
|
||||
UPDATE wholesaler_limits
|
||||
SET {', '.join(updates)}
|
||||
WHERE wholesaler_id = ?
|
||||
''', params)
|
||||
|
||||
conn.commit()
|
||||
|
||||
conn.close()
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'message': f'{wholesaler_id} 한도 업데이트 완료'
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user