
    oif'	                     J    d dl mZ d dlmZ d dlmZmZ d dlmZ d dlm	Z	 d Z
y)    )login_required)Count)now	timedelta)datetime)	Customersc           	      j   	 t               j                         }|t        |j                               z
  }|j	                  d      }|j	                  dd      }t
        j                  j                  |       }|j                         }|j                  |      j                         }|j                  |      j                         }|j                  |      j                         }	|j                  |      j                         }
|j                  d	      j                  d
      j                         }|j                  d
d g      j                         }g }t        d      D ]  }|j	                  d      t        |dz        z
  }|j	                  d      t        d      z   j	                  d      t        d      z
  }|j                  ||      j                         }|j                  |j                  d      |d        ||||	|
|||dS # t        $ r}i cY d }~S d }~ww xY w)N)days   )day)monthr   )$batch__category__created_by__company)created__date)created__date__gteF)password__isnull )password)password__in            )r   created__date__ltez%Y-%m)r   count)total_customerscustomers_todaycustomers_this_weekcustomers_this_monthcustomers_this_year
registeredunregisteredlast_12_months_customers)r   dater   weekdayreplacer   objectsfilterr   excluderangeappendstrftime	Exception)companytodaystart_of_weekstart_of_monthstart_of_year	customersr   r   r   r   r   r    r!   r"   ifirst_day_of_monthlast_day_of_monthmonth_customerses                      BD:\Rescue Scanner\qr_onkar\website\company_view\dashboard_views.pyget_customer_statisticsr9   	   s/   .

	u}} ??1-A15%%,,RY,Z	#//+#***?EEG'..-.PVVX(//>/RXXZ'..-.PVVX%%u%=EErERXXZ
 ''b$Z'@FFH#% r 	A!&1!5	q2v8N!N!3!;!;!;!CiUVFW!W ` `ef ` gjsk ! (..#5#4 /  eg 
 %+++44W=(- 	"  /.#6$8#6$('?	
 		
  	s   HH 	H2&H-'H2-H2N)django.contrib.auth.decoratorsr   django.db.modelsr   django.utils.timezoner   r   r   accounts.modelsr   r9        r8   <module>r@      s    9 " 0  %/r?   