Evo-ERP/app/web/views/report.py
2024-11-06 02:39:48 +08:00

46 lines
1.5 KiB
Python

from flask import Blueprint, send_file, render_template, request
from ...services.report_service import ReportService
from datetime import datetime, timedelta
bp = Blueprint('report', __name__, url_prefix='/reports')
@bp.route('/')
def index():
return render_template('report/index.html')
@bp.route('/inventory', methods=['GET'])
def inventory_report():
output = ReportService.generate_inventory_report()
return send_file(
output,
mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
as_attachment=True,
download_name=f'inventory_report_{datetime.now().strftime("%Y%m%d")}.xlsx'
)
@bp.route('/transactions', methods=['GET', 'POST'])
def transaction_report():
if request.method == 'POST':
start_date = datetime.strptime(request.form['start_date'], '%Y-%m-%d')
end_date = datetime.strptime(request.form['end_date'], '%Y-%m-%d')
end_date = end_date + timedelta(days=1) - timedelta(seconds=1)
output = ReportService.generate_transaction_report(start_date, end_date)
return send_file(
output,
mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
as_attachment=True,
download_name=f'transaction_report_{start_date.strftime("%Y%m%d")}_{end_date.strftime("%Y%m%d")}.xlsx'
)
# 傳入初始日期範圍
today = datetime.now()
return render_template(
'report/transaction_form.html',
today=today,
timedelta=timedelta
)