56 lines
2.1 KiB
Python
56 lines
2.1 KiB
Python
from django.db.models import Count, Sum, Q
|
|
import os
|
|
import datetime
|
|
|
|
from .models import *
|
|
|
|
def dashBoxData(request):
|
|
|
|
bazdid = os.environ.get('bazdid', 9)
|
|
|
|
debit = Article.objects.filter().aggregate(Sum('debit'))['debit__sum']
|
|
credit = Article.objects.filter().aggregate(Sum('credit'))['credit__sum']
|
|
|
|
try:
|
|
mandehesab = debit - credit
|
|
except:
|
|
mandehesab = 0
|
|
|
|
countCustomers = Customer.objects.all().count()
|
|
allUsers = User.objects.filter().exclude(username='admin').exclude(username='fesahat')
|
|
ActionCount = Action.objects.filter(forUser=request.user.id, status='waite').count()
|
|
|
|
# ---------------------------------------------------------
|
|
# بخش اصلاح شده برای شمارش دقیق نظرسنجیهای در انتظار
|
|
# ---------------------------------------------------------
|
|
now = datetime.datetime.now()
|
|
dt_30_days_ago = now - datetime.timedelta(days=30)
|
|
dt_60_days_ago = now - datetime.timedelta(days=60)
|
|
|
|
rezayatCount = Action.objects.exclude(actionType='vosol').filter(
|
|
status='finish',
|
|
nazarDT__isnull=True, # نظرسنجی هنوز نهایی نشده
|
|
createdDT__gte=dt_60_days_ago # حداکثر ۶۰ روز از ایجاد گذشته باشد
|
|
).filter(
|
|
Q(finishDateTime__isnull=True) | Q(finishDateTime__gte=dt_30_days_ago) # حداکثر ۳۰ روز از اتمام گذشته باشد
|
|
).filter(
|
|
Q(nextNazarDT__isnull=True) | Q(nextNazarDT__lte=now) # موعد پیگیری رسیده یا تعویقی نداشته باشد
|
|
).count()
|
|
# ---------------------------------------------------------
|
|
|
|
try:
|
|
entezarbazdid = CacheTable.objects.get(key='9mahbazdid').value
|
|
except Exception as exp:
|
|
entezarbazdid = 0
|
|
|
|
data = {
|
|
'mandehesab': mandehesab,
|
|
'countCustomers': countCustomers,
|
|
'ActionCount': ActionCount,
|
|
'allUsers': allUsers,
|
|
'rezayatCount': rezayatCount,
|
|
'entezarbazdid': entezarbazdid,
|
|
'bazdid': bazdid
|
|
}
|
|
|
|
return data |