
    zoi                     T    d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	  G d d      Z
y)	    )ValidationError)Q)Count)CompanyType)Companyc                   L    e Zd Zed        Zed        Zed        Zed        Zy)CompanyRepositoryc                  >    t         j                  j                         S N)r   objectsall     W/var/www/html/dp2/backend_v2.1/server/apps/companies/repositories/company_repository.pyget_querysetzCompanyRepository.get_queryset
   s    ""$$r   c                     t         j                         j                  | d      j                         }|st	        d      |S )NT)id	is_activezCompany not found or inactive)r	   r   filterfirstr   )
company_idcompanys     r   get_active_companyz$CompanyRepository.get_active_company   sJ     $00299 : 
 %' 	
 !"ABBr   c                     | j                   rt        j                         n| j                  j	                         }t        j                  |      S r   )is_superuserr	   r   	companiesr   _with_dashboard_data)userqss     r   qs_with_dashboard_dataz(CompanyRepository.qs_with_dashboard_data   sC        **,##% 	
 !55b99r   c                 
   | j                  dddd      j                  d      j                  t        dd      t        dt	        d	      d
      t        dt	        d	      d
      t        dt	        dd      d
            S )Nmissing_call_notify_tooffice_hourssales_timingscatch_phrasesdefault_transfer_staffusersT)distinct)users__is_active)r   r(   F)r)   users__is_available)
user_countactive_users_countinactive_users_countavailable_users_count)prefetch_relatedselect_relatedannotater   r   )r   s    r   r   z&CompanyRepository._with_dashboard_data(   s    ""$	

 .1
288Wt4$$/ 
 "'%0"
 #(%)(, # 4< 4
	
r   N)__name__
__module____qualname__staticmethodr   r   r    r   r   r   r   r	   r	   	   sP    % % 
 
 : : 
 
r   r	   N)django.core.exceptionsr   django.db.modelsr   django.db.models.aggregatesr   apps.companies.constantsr   apps.companies.modelsr   r	   r   r   r   <module>r;      s    2  - 0 ):
 :
r   