o
    Qg(	                     @   sL   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d Z
dS )	    )login_required)Count)now	timedelta)datetime)	Customersc              
   C   sv  zt   }|t| d }|jdd}|jddd}tjj| d}| }|j|d }|j|d }|j|d }	|j|d }
|jdd	j	d
d }|jd
d gd }g }t
dD ]7}|jddt|d d }|jddtdd jddtdd }|j||d }||d|d qc||||	|
|||dW S  ty } zi W  Y d }~S d }~w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e r6   ?/var/www/rescue_company/website/company_view/dashboard_views.pyget_customer_statistics	   sT   


r8   N)django.contrib.auth.decoratorsr   django.db.modelsr   django.utils.timezoner   r   r   accounts.modelsr   r8   r6   r6   r6   r7   <module>   s    