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