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 @@

{{ title }}

+
+
+ + + + +
+ + +
- - {% for item in items %} - - {% endfor %} - - - {% if write %} - - {% else %} - - {% endif %} -
-
- + {% if write %} + + {% else %} + + {% endif %} + +
- \ No newline at end of file + diff --git a/App/Report/templates/report_menu.html b/App/Report/templates/report_menu.html index 53906e3..7af3b21 100644 --- a/App/Report/templates/report_menu.html +++ b/App/Report/templates/report_menu.html @@ -10,7 +10,7 @@

Выберите вариант отчетов

-
+
diff --git a/App/data/db_access.json b/App/data/db_access.json index a64f3e9..a6ba414 100644 --- a/App/data/db_access.json +++ b/App/data/db_access.json @@ -5,7 +5,8 @@ "Управляющий": [ "requests_bp", "report_bp"], + "Бухгалтер": [ + "report_bp"], "Поставщик": [ "waybill_bp"] - } \ No newline at end of file diff --git a/App/static/css/main.css b/App/static/css/main.css index d641103..5cd5ee1 100644 --- a/App/static/css/main.css +++ b/App/static/css/main.css @@ -1,4 +1,4 @@ -h1,h2 { +h1, h2 { text-align: center; } @@ -26,6 +26,11 @@ div.logout, div.login { text-align: center; } +div.buttons_menu{ + text-align: center; + margin: 20px 0; +} + div.logout button { margin-top: -5px; background-color: #ff0000; @@ -37,11 +42,12 @@ div.login button { } div.return { - display: flex; - justify-content: center; + display: flex; + justify-content: center; + margin-top: 15px; } -div.return button{ +div.return button { background-color: chocolate; } @@ -50,4 +56,35 @@ div.form { left: 50%; top: 50%; transform: translate(-50%, -50%); -} \ No newline at end of file + text-align: center; + background-color: white; + padding: 20px; + border-radius: 10px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); +} + +div.form label { + display: block; + margin-bottom: 5px; + font-size: 16px; + font-weight: bold; + color: #333; +} + +div.form select, div.form input[type=number] { + margin-bottom: 15px; + padding: 5px; + font-size: 14px; + width: 100%; + box-sizing: border-box; +} + +div.form .period { + display: flex; + gap: 10px; + justify-content: center; +} + +div.form button { + margin-top: 15px; +}