
    si*                     l   d Z ddlZ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 ddlmZmZ dd	lmZ dd
lmZ ddlmZ ddlmZmZmZmZ d Ze ed      d               Ze ed      d               Ze ed      d               Ze ed      d               Zd Z e ed      d               Z!y)zD
dashboard.py

This module is used to write dashboard related views
    N)serializers)Q)JsonResponse)render)gettext_lazy)
DepartmentJobPosition)EmployeeWorkInformation)login_required)manager_can_enter)	CandidateRecruitment	SkillZoneStagec                     d}| j                   j                  |      D ]*  }|t        |j                  j                  d            z   }, |S )zH
    This method is used find the count of candidate in recruitment
    r   )
stage_typeT	is_active)	stage_setfilterlencandidate_set)recr   candidates_count	stage_objs       ?/var/www/python-projects/worksol/recruitment/views/dashboard.pystage_type_candidate_countr      s\     ]]))Z)@ 
	+c##**T*:/
 

     zrecruitment.view_recruitment)permc           
      d	   t         j                  j                         }d}t        j                  j	                  dd      }|j                         rd}nd}t        j                  j                         }g }|D ]#  }|j                  dk7  s|j                  d       % |g k7  rd}nd}t        j                  j                         }	g }
|	D ]  }|j                  }|
j                  |       ! g }|	D ]B  }t         j                  j	                  |d      }|j                  |j                                D g }|	D ]B  }t         j                  j	                  |d	      }|j                  |j                                D g }|	D ]B  }t         j                  j	                  |d
      }|j                  |j                                D g }|	D ]B  }t         j                  j	                  |d      }|j                  |j                                D g }|	D ]B  }t         j                  j	                  |d      }|j                  |j                                D t        t        |
|||||            }t        j                  j	                  d      }t        |      }|D ]@  }t        j                   D cg c]  }t#        ||d          }}|D ]  }||z  }	 |dk\  s?d}B t         j                  j	                  d      }|j                         }i }|D ]U  }|j$                  } g }!|j&                  j                         D ]#  }"|"j)                         }#|!j                  |#       % |!|| <   W d}$|D ]!  }%|%j*                  dk(  r|$|%j*                  z  }$# |j	                  t-        d      t-        d      z        j/                         }&t        |      }'t        |&      }(d})d}*d}+d},|'dk7  r
|(|'z  dz  d})|$dk7  r|(|$z  dz  d}*|'|$z  dz  d}+|(dk7  r
||(z  dz  d},t0        j                  j	                  d      }-t3        | di d|d|+d|(d|)d|,d|&j	                  d      d|d|$d |d!|*d"|d#|d$|d%|&j	                  d      j                         d&|'d'|-      S c c}w )(zH
    This method is used to render dashboard for recruitment module
    r   Fclosedis_event_based   NOKinitial)job_position_idstage_id__stage_typetest	interviewhired	cancelledr"   acceptedoffer_letter_statusT)r+   )r(   d   z.1fr   zdashboard/dashboard.htmlongoing_recruitmentstotal_candidate_ratiototal_hired_candidatesconversion_ratioacceptance_ratioonboard_candidates)onboarding_stage__isnulljob_datatotal_vacancyrecruitment_manager_mappinghired_ratiojoiningdep_vacancystage_chart_countonboarding_counttotal_candidates
skill_zone)r   objectsallr   r   existsr
   date_joiningappendr	   job_positioncountlistzipr   r   stage_typesr   titlerecruitment_managersget_full_namevacancyr   distinctr   r   ).request
candidatesr?   vacancy_chartr>   employee_infojoining_listr   r=   jobsall_jobjobjobposr&   inir)   tesr*   interr+   hirer,   cancelled_candidatesr9   recruitment_objr2   typedatair.   accepted_countr;   recruitment_titlemanagersmanagernamer:   openingshired_candidatesrA   r4   r5   r<   r3   r6   rB   s.                                                 r   	dashboardrk   "   s    ""&&(J''..eE.RM+33779ML &t#%& r""$DG !!v G $&&i ' 
 	syy{#	$ D !&&sQW&XCIIK ! I (!!((k ) 
 	'	( E #  ''g ( 
 	TZZ\"	#
 I 7(0077k  8  
 	-3356	7 C$	5)LMH!))000>O/ "EJEVEVWT*3Q8WW 	#A"	# ! !"   ''J'GH^^%N"$ BII//335 	"G((*DOOD!	" :B#$56B M# .t#X---M	. "((	w77hj  : !12K1 69I ISPRUV1MASH#N%5%E$Lc"R" .1G G3NPST""))D)9J"	
"$8	
#%:	
 %&<	
  0		

  0	
 !"2"9"9). #: #	
 	
 ]	
 *+F	
 ;	
 w	
 ;	
  !2	
   0 7 7). !8 !eg%	
&  0'	
( *)	
 _ Xs   5R-c           	         t         j                  j                  d      }g }t        j                  D cg c]  }|d   	 }}|D ]  }t        j                  D cg c]  }t        ||d          }}|j                  j                         sH|j                  |j                  |j                  n|j                   d|j                   |d        t        ||t        d      d      S c c}w c c}w )	zL
    This method is used generate recruitment dataset for the dashboard
    Fr-   r$   r   z
                    labelrb   z#No records available at the moment.)dataSetlabelsmessage)r   rC   r   r   rL   r   	candidaterD   rG   rM   r'   
start_dater   _)rR   r`   data_setra   rp   r   rb   s          r   dashboard_pipelinerv      s     "))000>OH"'"3"34$d1g4F4 EJEVEVWT*3Q8WW==OO 990 		"%"5"5!6 7^^$( !
 >?	
  5Ws   C,C1c                 b   | j                   j                  d      }t        j                  j	                  |      }dgdz  }|D ]M  }t        |j                  t        j                        s(|j                  j                  dz
  }||xx   dz  cc<   O t        d      t        d      t        d      t        d	      t        d
      t        d      t        d      t        d      t        d      t        d      t        d      t        d      g}t        d      d|iz  |ddg}t        ||d      S )zP
    This method is used generate employee joining status for the dashboard
    id)date_joining__yearr      r$   JanuaryFebruaryMarchAprilMayJuneJulyAugust	SeptemberOctoberNovemberDecemberzEmployees joined in %(year)syearzrgba(236, 131, 25))rn   rb   backgroundColorro   rp   )GETgetr
   rC   r   
isinstancerF   datetimedatemonthrt   r   )rR   selected_yearrU   employee_count_per_monthinfomonth_indexrp   ru   s           r   dashboard_hiringr      s+    KKOOD)M+33::( ; M
 !"sRx  d''7++11A5K$  	
)	*	'
	'
	%	&		&		(	+	)	*	*F" 56&-9PP,3	
H H?@@r   c                    t         j                  j                  dd      }t        j                  j	                         }g }t        d      g dg}|D ]  }|j                  |      }|D ]*  }|j                  |j                  |j                         , |D cg c]%  }|j                  t        |j                        nd' }}|d   d   j                  t        |      g        t        ||d      S c c}w )	zW
    This method is used to generate a recruitment vacancy chart for the dashboard
    Fr!   Openingsrm   )job_position_id__department_idr   rb   r   )r   rC   r   r   rD   rt   rP   rG   
departmentintsumr   )	_requestr`   r   rn   ru   depvacancies_for_departmentr   	vacanciess	            r   dashboard_vacancyr     s	    "))00e0TO##'')JEJ-45H 5#2#9#9+. $: $
  , 	-C{{&S^^,	- 0
 !$ 7CQ>
	 

 	F""C	N#345 H>??
s   *C8c                 
   | j                   d   }t        j                  j                  |      }|j                  j                         }t        j                  d|      }t        j                  d|g      }t        ||d      S )z
    This is an ajax method to render the open position to the recruitment

    Returns:
        obj: it returns the list of job positions
    recId)rx   json)openPositionsrecruitmentInfo)	r   r   rC   r   open_positionsrD   r   	serializer   )rR   rec_idr`   querysetjob_inforec_infos         r   get_open_positionr      sv     [[!F!))---8O--113H$$VX6H$$Vo->?H(xPQQr   c                 j   t         j                  j                  d      j                         }t         j                  j                  d      j                         }t         j                  j                  d      j                         }t         j                  j                  d      j                         }t         j                  j                  d      j                         }g }g d}|||||g}t	        t        |            D ]  }	|j                  ||	   ||	   d        t        ||d	      S )
zT
    This method is used to generate a CAndidate status chart for the dashboard
    not_sentr/   sentr.   rejectedjoined)zNot SentSentAcceptedRejectedJoinedrm   r   )r   rC   r   rI   ranger   rG   r   )
r   not_sent_candidatessent_candidatesaccepted_candidatesrejected_candidatesjoined_candidatesru   rp   rb   rc   s
             r   candidate_statusr   /  s,    $++22& 3 eg   ''..6.JPPRO#++22& 3 eg  $++22& 3 eg  "))00X0NTTVHCFD 3t9 ?&)T!W=>? H?@@r   )"__doc__r   django.corer   django.db.modelsr   django.httpr   django.shortcutsr   django.utils.translationr   rt   base.modelsr   r	   employee.modelsr
   horilla.decoratorsr   recruitment.decoratorsr   recruitment.modelsr   r   r   r   r   rk   rv   r   r   r   r    r   r   <module>r      s     #  $ # 6 / 3 - 4 G G	 67I 8 IX 67 8 < 67-A 8 -A` 67@ 8 @8R 67)A 8 )Ar   