Реализация первого вида отчета
This commit is contained in:
@@ -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)
|
||||
Reference in New Issue
Block a user