Merge branch 'Report' of ParkSuMin/Cursovaya into main
This commit is contained in:
@@ -1,13 +1,12 @@
|
|||||||
from flask import request, Blueprint, render_template, session, url_for
|
from flask import request, Blueprint, render_template, session, url_for
|
||||||
from checker import check_auth
|
from checker import check_auth
|
||||||
from os import path
|
from os import path
|
||||||
from .report_model import sales_report, make_report
|
from .report_model import view_report, make_report
|
||||||
import json
|
import json
|
||||||
|
|
||||||
with open(path.join(path.dirname(__file__), 'reports.json')) as f:
|
with open(path.join(path.dirname(__file__), 'reports.json')) as f:
|
||||||
report_list = json.load(f)
|
report_list = json.load(f)
|
||||||
|
|
||||||
|
|
||||||
report_bp = Blueprint('report_bp', __name__, template_folder='templates')
|
report_bp = Blueprint('report_bp', __name__, template_folder='templates')
|
||||||
|
|
||||||
@report_bp.route('/menu')
|
@report_bp.route('/menu')
|
||||||
@@ -25,14 +24,16 @@ def create():
|
|||||||
title='Создание отчета',
|
title='Создание отчета',
|
||||||
items = report_list)
|
items = report_list)
|
||||||
else:
|
else:
|
||||||
data = dict(month=request.form.get('month'), year=request.form.get('year'))
|
data = dict(id=request.form.get('category'),
|
||||||
id = request.form.get('category')
|
month=request.form.get('month'),
|
||||||
with open(path.join(path.dirname(__file__), f'access/{id}.json')) as f:
|
year=request.form.get('year'))
|
||||||
|
|
||||||
|
with open(path.join(path.dirname(__file__), f'access/{data['id']}.json')) as f:
|
||||||
report_access = json.load(f)
|
report_access = json.load(f)
|
||||||
|
|
||||||
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, int(id),proc_name)
|
ready_report = make_report(data, proc_name)
|
||||||
if ready_report.status:
|
if ready_report.status:
|
||||||
return render_template("OK.html")
|
return render_template("OK.html")
|
||||||
else:
|
else:
|
||||||
@@ -49,15 +50,15 @@ def view():
|
|||||||
title='Просмотр отчета',
|
title='Просмотр отчета',
|
||||||
items = report_list)
|
items = report_list)
|
||||||
else:
|
else:
|
||||||
data = dict(month=request.form.get('month'),
|
data = dict(id=request.form.get('category'),
|
||||||
year=request.form.get('year'),
|
month=request.form.get('month'),
|
||||||
id = request.form.get('category'))
|
year=request.form.get('year'))
|
||||||
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/{data['id']}.json')) as f:
|
||||||
report_access = json.load(f)
|
report_access = json.load(f)
|
||||||
|
|
||||||
if session['role'] in report_access['read']:
|
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:
|
if ready_report.status:
|
||||||
title= f'{report_access["title"]} за {data["month"]}-{data["year"]}'
|
title= f'{report_access["title"]} за {data["month"]}-{data["year"]}'
|
||||||
return render_template("output.html", items=ready_report.result,
|
return render_template("output.html", items=ready_report.result,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"title" : "Отчет о продажах",
|
"title" : "Отчет о поставках заготовок",
|
||||||
"write" : ["Менеджер"],
|
"write" : ["Менеджер"],
|
||||||
"read" : ["Управляющий"],
|
"read" : ["Управляющий"],
|
||||||
"view" : "view_report",
|
"view" : "workpiece_report",
|
||||||
"procedure" : "report_workpiece"
|
"procedure" : "report_workpiece"
|
||||||
}
|
}
|
||||||
7
App/Report/access/2.json
Normal file
7
App/Report/access/2.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"title" : "Отчет о поставках поставщиками",
|
||||||
|
"write" : ["Бухгалтер"],
|
||||||
|
"read" : ["Управляющий"],
|
||||||
|
"view" : "sellers_report",
|
||||||
|
"procedure" : "report_sellers"
|
||||||
|
}
|
||||||
@@ -18,12 +18,13 @@ def check_report(input_data: dict) -> bool:
|
|||||||
return False
|
return False
|
||||||
return True
|
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)
|
status = check_report(input_data)
|
||||||
if not status:
|
if not status:
|
||||||
return InfoRespronse((),
|
return InfoRespronse((),
|
||||||
error_message = 'Отчет не найден',
|
error_message = 'Отчет не найден',
|
||||||
status=False)
|
status=False)
|
||||||
|
|
||||||
_sql = sql_provider.get(f'{view_script}.sql', input_data)
|
_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:
|
||||||
@@ -32,14 +33,15 @@ def sales_report(input_data: dict, view_script: str) -> InfoRespronse:
|
|||||||
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:
|
def make_report(input_data: dict, proc_name: str) -> InfoRespronse:
|
||||||
status = check_report(input_data)
|
status = check_report(input_data)
|
||||||
if status:
|
if status:
|
||||||
return InfoRespronse((),
|
return InfoRespronse((),
|
||||||
error_message = 'Отчет уже существует',
|
error_message = 'Отчет уже существует',
|
||||||
status=False)
|
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:
|
if result is None:
|
||||||
return InfoRespronse((),
|
return InfoRespronse((),
|
||||||
error_message = 'Ошибка в подключении к базе данных. Свяжитесь с администратором',
|
error_message = 'Ошибка в подключении к базе данных. Свяжитесь с администратором',
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
[
|
[
|
||||||
{"id": 1, "name": "Покупки за месяц"}
|
{"id": 1, "name": "Заготовки"},
|
||||||
|
{"id": 2, "name": "Поставщики"}
|
||||||
]
|
]
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
SELECT EXISTS (
|
SELECT EXISTS (
|
||||||
SELECT 1 FROM reports
|
SELECT 1 FROM reports
|
||||||
WHERE month = $month AND year = $year
|
WHERE report_category_id = '$id' AND (month = '$month' AND year = '$year')
|
||||||
) AS exist;
|
) AS exist;
|
||||||
8
App/Report/sql/sellers_report.sql
Normal file
8
App/Report/sql/sellers_report.sql
Normal file
@@ -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;
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
SELECT w.material AS Наименование,
|
SELECT w.name AS Наименование,
|
||||||
|
w.material AS Материал,
|
||||||
sum(sum) AS Сумма,
|
sum(sum) AS Сумма,
|
||||||
sum(reports.count) AS Количество
|
sum(reports.count) AS Количество
|
||||||
from reports
|
from reports
|
||||||
JOIN workpiece w ON reports.item_id = w.work_id
|
JOIN workpiece w ON reports.item_id = w.work_id
|
||||||
WHERE report_category_id = '$id' AND (month = '$month' AND year = '$year')
|
WHERE report_category_id = '$id' AND (month = '$month' AND year = '$year')
|
||||||
GROUP BY material;
|
GROUP BY w.material, w.name;
|
||||||
@@ -10,36 +10,43 @@
|
|||||||
<a href="{{ url_for('logout') }}"><button>Выход</button></a>
|
<a href="{{ url_for('logout') }}"><button>Выход</button></a>
|
||||||
</div>
|
</div>
|
||||||
<h1>{{ title }}</h1>
|
<h1>{{ title }}</h1>
|
||||||
|
<div class="form">
|
||||||
|
<form action="" method="post">
|
||||||
|
<label for="category">Выберите предмет формирования отчета</label>
|
||||||
|
<select name="category" id="category" required>
|
||||||
|
{% for item in items %}
|
||||||
|
<option value="{{ item['id'] }}">{{ item['name'] }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<label for="month">Выберите отчетный период</label>
|
||||||
|
<div class="period">
|
||||||
|
<select name="month" id="month" required>
|
||||||
|
<option value="1">Январь</option>
|
||||||
|
<option value="2">Февраль</option>
|
||||||
|
<option value="3">Март</option>
|
||||||
|
<option value="4">Апрель</option>
|
||||||
|
<option value="5">Май</option>
|
||||||
|
<option value="6">Июнь</option>
|
||||||
|
<option value="7">Июль</option>
|
||||||
|
<option value="8">Август</option>
|
||||||
|
<option value="9">Сентябрь</option>
|
||||||
|
<option value="10">Октябрь</option>
|
||||||
|
<option value="11">Ноябрь</option>
|
||||||
|
<option value="12">Декабрь</option>
|
||||||
|
</select>
|
||||||
|
<input type="number" name="year" value="2024" min="1990" max="2100" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
<form action="" method="post">
|
{% if write %}
|
||||||
{% for item in items %}
|
<button type="submit" value="write">Создать</button>
|
||||||
<select name="category" required>
|
{% else %}
|
||||||
<option value="{{ item['id'] }}">{{ item['name'] }}</option>
|
<button type="submit" value="read">Просмотр</button>
|
||||||
</select>
|
{% endif %}
|
||||||
{% endfor %}
|
</form>
|
||||||
<select name="month" required>
|
<div class="return">
|
||||||
<option value="1">Январь</option>
|
<a href="{{ url_for('index') }}"><button>Главное меню</button></a>
|
||||||
<option value="2">Февраль</option>
|
</div>
|
||||||
<option value="3">Март</option>
|
|
||||||
<option value="4">Апрель</option>
|
|
||||||
<option value="5">Май</option>
|
|
||||||
<option value="6">Июнь</option>
|
|
||||||
<option value="7">Июль</option>
|
|
||||||
<option value="8">Август</option>
|
|
||||||
<option value="9">Сентябрь</option>
|
|
||||||
<option value="10">Октябрь</option>
|
|
||||||
<option value="11">Ноябрь</option>
|
|
||||||
<option value="12">Декабрь</option>
|
|
||||||
</select>
|
|
||||||
<input type="number" name="year" value="2024" min="1990" max="2100" required>
|
|
||||||
{% if write %}
|
|
||||||
<button type="submit" value="write">Создать</button>
|
|
||||||
{% else %}
|
|
||||||
<button type="submit" value="read">Просмотр</button>
|
|
||||||
{% endif %}
|
|
||||||
</form>
|
|
||||||
<div class="return">
|
|
||||||
<a href="{{ url_for('index') }}"><button>Главное меню</button></a>
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<a href="{{ url_for('logout') }}"><button>Выход</button></a>
|
<a href="{{ url_for('logout') }}"><button>Выход</button></a>
|
||||||
</div>
|
</div>
|
||||||
<h1>Выберите вариант отчетов</h1>
|
<h1>Выберите вариант отчетов</h1>
|
||||||
<div style="text-align: center; margin: 20px 0;">
|
<div class="buttons_menu">
|
||||||
<a href="{{ url_for('report_bp.create') }}"><button>Создать отчет</button></a>
|
<a href="{{ url_for('report_bp.create') }}"><button>Создать отчет</button></a>
|
||||||
<a href="{{ url_for('report_bp.view') }}"><button>Читать отчеты</button></a>
|
<a href="{{ url_for('report_bp.view') }}"><button>Читать отчеты</button></a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
"Управляющий": [
|
"Управляющий": [
|
||||||
"requests_bp",
|
"requests_bp",
|
||||||
"report_bp"],
|
"report_bp"],
|
||||||
|
"Бухгалтер": [
|
||||||
|
"report_bp"],
|
||||||
"Поставщик": [
|
"Поставщик": [
|
||||||
"waybill_bp"]
|
"waybill_bp"]
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
h1,h2 {
|
h1, h2 {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,6 +26,11 @@ div.logout, div.login {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.buttons_menu{
|
||||||
|
text-align: center;
|
||||||
|
margin: 20px 0;
|
||||||
|
}
|
||||||
|
|
||||||
div.logout button {
|
div.logout button {
|
||||||
margin-top: -5px;
|
margin-top: -5px;
|
||||||
background-color: #ff0000;
|
background-color: #ff0000;
|
||||||
@@ -37,11 +42,12 @@ div.login button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
div.return {
|
div.return {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
margin-top: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.return button{
|
div.return button {
|
||||||
background-color: chocolate;
|
background-color: chocolate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,4 +56,35 @@ div.form {
|
|||||||
left: 50%;
|
left: 50%;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
transform: translate(-50%, -50%);
|
transform: translate(-50%, -50%);
|
||||||
}
|
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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user