diff --git a/App/Report/__init__.py b/App/Report/__init__.py index 948e5c1..74ffaad 100644 --- a/App/Report/__init__.py +++ b/App/Report/__init__.py @@ -1,13 +1,12 @@ from flask import request, Blueprint, render_template, session, url_for from checker import check_auth from os import path -from .report_model import sales_report, make_report +from .report_model import view_report, make_report import json with open(path.join(path.dirname(__file__), 'reports.json')) as f: report_list = json.load(f) - report_bp = Blueprint('report_bp', __name__, template_folder='templates') @report_bp.route('/menu') @@ -25,14 +24,16 @@ def create(): title='Создание отчета', items = report_list) else: - data = dict(month=request.form.get('month'), year=request.form.get('year')) - id = request.form.get('category') - with open(path.join(path.dirname(__file__), f'access/{id}.json')) as f: + data = dict(id=request.form.get('category'), + month=request.form.get('month'), + year=request.form.get('year')) + + with open(path.join(path.dirname(__file__), f'access/{data['id']}.json')) as f: report_access = json.load(f) if session['role'] in report_access['write']: proc_name = report_access['procedure'] - ready_report = make_report(data, int(id),proc_name) + ready_report = make_report(data, proc_name) if ready_report.status: return render_template("OK.html") else: @@ -49,15 +50,15 @@ def view(): title='Просмотр отчета', items = report_list) else: - data = dict(month=request.form.get('month'), - year=request.form.get('year'), - id = request.form.get('category')) - id = request.form.get('category') - with open(path.join(path.dirname(__file__), f'access/{id}.json')) as f: + data = dict(id=request.form.get('category'), + month=request.form.get('month'), + year=request.form.get('year')) + + with open(path.join(path.dirname(__file__), f'access/{data['id']}.json')) as f: report_access = json.load(f) if session['role'] in report_access['read']: - ready_report = sales_report(data, report_access['view']) + ready_report = view_report(data, report_access['view']) if ready_report.status: title= f'{report_access["title"]} за {data["month"]}-{data["year"]}' return render_template("output.html", items=ready_report.result, diff --git a/App/Report/access/1.json b/App/Report/access/1.json index 9d565c4..5c07c25 100644 --- a/App/Report/access/1.json +++ b/App/Report/access/1.json @@ -1,7 +1,7 @@ { - "title" : "Отчет о продажах", + "title" : "Отчет о поставках заготовок", "write" : ["Менеджер"], "read" : ["Управляющий"], - "view" : "view_report", + "view" : "workpiece_report", "procedure" : "report_workpiece" } \ No newline at end of file diff --git a/App/Report/access/2.json b/App/Report/access/2.json new file mode 100644 index 0000000..d7a7537 --- /dev/null +++ b/App/Report/access/2.json @@ -0,0 +1,7 @@ +{ + "title" : "Отчет о поставках поставщиками", + "write" : ["Бухгалтер"], + "read" : ["Управляющий"], + "view" : "sellers_report", + "procedure" : "report_sellers" +} \ No newline at end of file diff --git a/App/Report/report_model.py b/App/Report/report_model.py index e7d6bd8..c875da2 100644 --- a/App/Report/report_model.py +++ b/App/Report/report_model.py @@ -18,12 +18,13 @@ def check_report(input_data: dict) -> bool: return False return True -def sales_report(input_data: dict, view_script: str) -> InfoRespronse: +def view_report(input_data: dict, view_script: str) -> InfoRespronse: status = check_report(input_data) if not status: return InfoRespronse((), error_message = 'Отчет не найден', status=False) + _sql = sql_provider.get(f'{view_script}.sql', input_data) result = select_list(current_app.config['db_config'], _sql) if result is None: @@ -32,14 +33,15 @@ def sales_report(input_data: dict, view_script: str) -> InfoRespronse: status=False) return InfoRespronse(result, error_message='', status=True) -def make_report(input_data: dict, report_id: int, proc_name: str) -> InfoRespronse: +def make_report(input_data: dict, proc_name: str) -> InfoRespronse: status = check_report(input_data) if status: return InfoRespronse((), error_message = 'Отчет уже существует', status=False) - test_data = (report_id,*input_data.values()) - result = procedure(current_app.config['db_config'], proc_name, test_data) + + data = tuple(input_data.values()) + result = procedure(current_app.config['db_config'], proc_name, data) if result is None: return InfoRespronse((), error_message = 'Ошибка в подключении к базе данных. Свяжитесь с администратором', diff --git a/App/Report/reports.json b/App/Report/reports.json index 0843d80..ccab6f2 100644 --- a/App/Report/reports.json +++ b/App/Report/reports.json @@ -1,3 +1,4 @@ [ - {"id": 1, "name": "Покупки за месяц"} + {"id": 1, "name": "Заготовки"}, + {"id": 2, "name": "Поставщики"} ] \ No newline at end of file diff --git a/App/Report/sql/check_report.sql b/App/Report/sql/check_report.sql index 3c42460..7e6106a 100644 --- a/App/Report/sql/check_report.sql +++ b/App/Report/sql/check_report.sql @@ -1,4 +1,4 @@ SELECT EXISTS ( SELECT 1 FROM reports - WHERE month = $month AND year = $year + WHERE report_category_id = '$id' AND (month = '$month' AND year = '$year') ) AS exist; \ No newline at end of file diff --git a/App/Report/sql/sellers_report.sql b/App/Report/sql/sellers_report.sql new file mode 100644 index 0000000..b02253a --- /dev/null +++ b/App/Report/sql/sellers_report.sql @@ -0,0 +1,8 @@ +SELECT + s.name AS Поставщик, + SUM(reports.count) AS 'Количество поставок', + SUM(reports.sum) AS Сумма +FROM reports +JOIN sellers s ON reports.item_id = s.sel_id +WHERE report_category_id = '$id' AND (month = '$month' AND year = '$year') +GROUP BY s.name; \ No newline at end of file diff --git a/App/Report/sql/view_report.sql b/App/Report/sql/workpiece_report.sql similarity index 66% rename from App/Report/sql/view_report.sql rename to App/Report/sql/workpiece_report.sql index ee3a641..e35c331 100644 --- a/App/Report/sql/view_report.sql +++ b/App/Report/sql/workpiece_report.sql @@ -1,7 +1,8 @@ -SELECT w.material AS Наименование, +SELECT w.name AS Наименование, + w.material AS Материал, sum(sum) AS Сумма, sum(reports.count) AS Количество from reports JOIN workpiece w ON reports.item_id = w.work_id WHERE report_category_id = '$id' AND (month = '$month' AND year = '$year') -GROUP BY material; \ No newline at end of file +GROUP BY w.material, w.name; \ No newline at end of file diff --git a/App/Report/templates/report_basic.html b/App/Report/templates/report_basic.html index 9faef9f..dac88c9 100644 --- a/App/Report/templates/report_basic.html +++ b/App/Report/templates/report_basic.html @@ -10,36 +10,43 @@