Skip to content

Commit

Permalink
Merge pull request #3661 from mikhailprivalov/turnovers-1.3
Browse files Browse the repository at this point in the history
Turnovers 1.3
  • Loading branch information
urchinpro authored Mar 27, 2024
2 parents 9bf985d + e8e5ab4 commit 5f8f861
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
19 changes: 12 additions & 7 deletions api/dashboards/views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import calendar
import json
import logging
from decimal import Decimal

from dateutil.relativedelta import relativedelta
from django.http import JsonResponse

from dashboards.models import Dashboard
from dashboards.views import exec_query, get_dashboard
from integration_framework.employees.sql_func import get_cash_resister_by_depatment_period, get_total_cash_register_by_day
from integration_framework.employees.sql_func import get_cash_resister_by_depatment_period, get_total_cash_register_by_dates
from laboratory.settings import DASH_REPORT_LIMIT_DURATION_DAYS
from laboratory.utils import current_time, str_date
from django.contrib.auth.decorators import login_required
Expand Down Expand Up @@ -112,26 +113,30 @@ def cash_register(request):
if mode == "department":
query_result = get_cash_resister_by_depatment_period(date_start_query, date_end_query)
data = {}
all_cash = []
for qr in query_result:
if not data.get(qr.department_id):
data[qr.department_id] = {"office": qr.depart_name, **{f"{i}.{date_start_month}.{date_start_year}": "" for i in date_per_month}, "officeRow": True}
data[f"Наличные {qr.department_id}"] = {"office": "Наличные", **{f"{i}.{date_start_month}.{date_start_year}": "" for i in date_per_month}, "only1stCol": True}
data[f"Терминал {qr.department_id}"] = {"office": "Терминал", **{f"{i}.{date_start_month}.{date_start_year}": "" for i in date_per_month}, "only1stCol": True}
data[f"Возврат нал {qr.department_id}"] = {"office": "Возврат нал ", **{f"{i}.{date_start_month}.{date_start_year}": "" for i in date_per_month}}
data[f"Возврат терм {qr.department_id}"] = {"office": "Возврат терм ", **{f"{i}.{date_start_month}.{date_start_year}": "" for i in date_per_month}}
data[f"Итого {qr.department_id}"] = {"office": "Итого", **{f"{i}.{date_start_month}.{date_start_year}": "" for i in date_per_month}, "total": 0, "totalDepartment": True}
data[f"Итого {qr.department_id}"] = {"office": "Итого", **{f"{i}.{date_start_month}.{date_start_year}": "" for i in date_per_month}, "total": "0", "totalDepartment": True}
data[f"Наличные {qr.department_id}"][qr.char_day] = f"{qr.received_cash:,.2f}"
data[f"Терминал {qr.department_id}"][qr.char_day] = f"{qr.received_terminal:,.2f}"
data[f"Возврат нал {qr.department_id}"][qr.char_day] = f"{qr.return_cash:,.2f}"
data[f"Возврат терм {qr.department_id}"][qr.char_day] = f"{qr.return_terminal:,.2f}"
data[f"Итого {qr.department_id}"][qr.char_day] = f"{(qr.received_cash + qr.received_terminal - qr.return_cash - qr.return_terminal):,.2f}"
data[f"Итого {qr.department_id}"]["total"] += qr.received_cash + qr.received_terminal - qr.return_cash - qr.return_terminal
tmp_total_depart = qr.received_cash + qr.received_terminal - qr.return_cash - qr.return_terminal
data[f"Итого {qr.department_id}"]["total"] = f'{(Decimal(data[f"Итого {qr.department_id}"]["total"].replace(",", "")) + tmp_total_depart):,.2f}'

data["Всего"] = {"office": "Всего", **{f"{i}.{date_start_month}.{date_start_year}": "" for i in date_per_month}, "total": 0, "totalDay": True}
all_cash = get_total_cash_register_by_day(date_start_query, date_end_query)
if len(data) > 0:
data["Всего"] = {"office": "Всего", **{f"{i}.{date_start_month}.{date_start_year}": "" for i in date_per_month}, "total": "0", "totalDay": True}
all_cash = get_total_cash_register_by_dates(date_start_query, date_end_query)
for cash in all_cash:
data["Всего"][cash.char_day] = cash.received_cash + cash.received_terminal - cash.return_cash - cash.return_terminal
data["Всего"]["total"] += data["Всего"][cash.char_day]
data["Всего"][cash.char_day] = f"{(cash.received_cash + cash.received_terminal - cash.return_cash - cash.return_terminal):,.2f}"
tmp_total_total = cash.received_cash + cash.received_terminal - cash.return_cash - cash.return_terminal
data["Всего"]["total"] = f'{(Decimal(data["Всего"]["total"].replace(",", "")) + tmp_total_total):,.2f}'
table_data = [v for v in data.values()]

return JsonResponse({"columns": columns, "tableData": table_data})
Expand Down
2 changes: 1 addition & 1 deletion integration_framework/employees/sql_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def get_cash_resister_by_depatment_period(date_start, date_end):
return rows


def get_total_cash_register_by_day(date_start, date_end):
def get_total_cash_register_by_dates(date_start, date_end):
with connection.cursor() as cursor:
cursor.execute(
"""
Expand Down
5 changes: 4 additions & 1 deletion l2-frontend/src/pages/Turnovers/Turnovers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
>
<i class="fa fa-arrow-left" />
</button>
<div class="date">{{ currentDate.toLocaleDateString('ru-RU', { month: "long", year: "numeric" }) }}</div>
<div class="date">
{{ currentDate.toLocaleDateString('ru-RU', { month: "long", year: "numeric" }) }}
</div>
<button
class="btn btn-blue-nb arrow-button"
@click="setNextMonth"
Expand All @@ -28,6 +30,7 @@
<VeTable
id="table"
:columns="columns"
:max-height="500"
:table-data="tableData"
:scroll-width="0"
:border-y="true"
Expand Down

0 comments on commit 5f8f861

Please sign in to comment.