diff --git a/backend/baekje_api.py b/backend/baekje_api.py index b8ff837..8539291 100644 --- a/backend/baekje_api.py +++ b/backend/baekje_api.py @@ -260,3 +260,46 @@ def api_get_balance(): session = get_baekje_session() result = session.get_balance(year if year else None) return jsonify(result) + + +@baekje_bp.route('/monthly-sales', methods=['GET']) +def api_get_monthly_sales(): + """ + 월간 매출(주문) 합계 조회 + + GET /api/baekje/monthly-sales?year=2026&month=3 + + Returns: + { + "success": true, + "total_amount": 7305877, // 월간 매출 합계 + "total_returns": 0, // 월간 반품 합계 + "net_amount": 7305877, // 순매출 (매출 - 반품) + "total_paid": 0, // 월간 입금 합계 + "ending_balance": 14563978, // 월말 잔액 + "prev_balance": 14565453, // 전월이월금 + "from_date": "2026-03-01", + "to_date": "2026-03-31", + "rotate_days": 58.4 // 회전일수 + } + """ + from datetime import datetime + + year = flask_request.args.get('year', '').strip() + month = flask_request.args.get('month', '').strip() + + # 기본값: 현재 연월 + now = datetime.now() + if not year: + year = now.year + else: + year = int(year) + + if not month: + month = now.month + else: + month = int(month) + + session = get_baekje_session() + result = session.get_monthly_sales(year, month) + return jsonify(result)