Реализация первого вида отчета
This commit is contained in:
@@ -32,7 +32,7 @@ def create():
|
||||
|
||||
if session['role'] in report_access['write']:
|
||||
proc_name = report_access['procedure']
|
||||
ready_report = make_report(data, proc_name)
|
||||
ready_report = make_report(data, int(id),proc_name)
|
||||
if ready_report.status:
|
||||
return render_template("OK.html")
|
||||
else:
|
||||
@@ -49,7 +49,9 @@ def view():
|
||||
title='Просмотр отчета',
|
||||
items = report_list)
|
||||
else:
|
||||
data = dict(month=request.form.get('month'), year=request.form.get('year'))
|
||||
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:
|
||||
report_access = json.load(f)
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
"write" : ["Менеджер"],
|
||||
"read" : ["Управляющий"],
|
||||
"view" : "view_report",
|
||||
"procedure" : "generate_report"
|
||||
"procedure" : "report_workpiece"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
from dataclasses import dataclass
|
||||
from Database.select import select_list
|
||||
from Database.sql_provider import SQLProvider
|
||||
from .db.work import select_list, procedure
|
||||
from .db.sql_provider import SQLProvider
|
||||
from flask import current_app
|
||||
from os import path
|
||||
|
||||
@@ -11,11 +11,41 @@ class InfoRespronse:
|
||||
error_message: str
|
||||
status: bool
|
||||
|
||||
def quanterly(input_data) -> InfoRespronse:
|
||||
_sql = sql_provider.get('sklad_material.sql', input_data)
|
||||
def check_report(input_data: dict) -> bool:
|
||||
_sql = sql_provider.get('check_report.sql', input_data)
|
||||
result = select_list(current_app.config['db_config'], _sql)
|
||||
if result is None or result[0]['exist'] == 0:
|
||||
return False
|
||||
return True
|
||||
|
||||
def sales_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:
|
||||
return InfoRespronse((),
|
||||
error_message = 'Ошибка в подключении к базе данных. Свяжитесь с администратором',
|
||||
status=False)
|
||||
return InfoRespronse(result, error_message='', status=True)
|
||||
return InfoRespronse(result, error_message='', status=True)
|
||||
|
||||
def make_report(input_data: dict, report_id: int, 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)
|
||||
if result is None:
|
||||
return InfoRespronse((),
|
||||
error_message = 'Ошибка в подключении к базе данных. Свяжитесь с администратором',
|
||||
status=False)
|
||||
elif result['message'] != 'OK':
|
||||
return InfoRespronse((),
|
||||
error_message = 'Невозможно создать отчет (нет продаж за выбранный период)',
|
||||
status=False)
|
||||
return InfoRespronse((), error_message='', status=True)
|
||||
@@ -1,3 +1,3 @@
|
||||
[
|
||||
{"id": 1, "name": "Покупки за месяц", "json_file": "access/sales.json"}
|
||||
{"id": 1, "name": "Покупки за месяц"}
|
||||
]
|
||||
@@ -1,5 +1,7 @@
|
||||
SELECT name_of_product AS 'Наименование',
|
||||
count_of_bought AS 'Количество',
|
||||
sum AS 'Общая стоимость'
|
||||
FROM reports
|
||||
WHERE month = '$month' AND year = '$year';
|
||||
SELECT 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;
|
||||
Reference in New Issue
Block a user