
    vg)                     `   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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)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/horilla/recruitment/views/dashboard.pystage_type_candidate_countr      s\     ]]))Z)@ 
	+c##**T*:/
 

     zrecruitment.view_recruitment)permc           
         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	                  d      }%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}+t,        j                  j	                  d      },t/        | di d|d|*d|'d|(d|+d|%j	                  d      d|d|#d|d|)d|d |d!|d"|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!   T)start_onboard)r*   d   z.1fr   zdashboard/dashboard.htmlongoing_recruitmentstotal_candidate_ratiototal_hired_candidatesconversion_ratioacceptance_ratioonboard_candidates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   r   )-request
candidatesr;   vacancy_chartr:   employee_infojoining_listr   r9   jobsall_jobjobjobposr%   inir(   tesr)   interr*   hirer+   cancelled_candidatesr5   recruitment_objr/   typedatair<   r7   recruitment_titlemanagersmanagernamer6   openingshired_candidatesr=   r1   r2   r8   r0   r3   r>   s-                                                r   	dashboardre   !   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"	# ! !" !((//d/C'--/"$ BII//335 	"G((*DOOD!	" :B#$56B M# .t#X---M	. "((t(4: !12K1 69I ISPRUV1MASH#N%5%E$Lc"R" 03I ISPRUV""))D)9J"	
"$8	
#%:	
 %&<	
  0		

  0	
 !"2"9"9"9"M	
 	
 ]	
 *+F	
 ;	
 w	
 ;	
  !2	
  0	
  0	
  *!	
 [ Xs   5Q+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
                    labelr]   z#No records available at the moment.)dataSetlabelsmessage)r   r?   r   r   rH   r   	candidater@   rC   rI   r&   
start_dater   _)rM   r[   data_setr\   rj   r   r]   s          r   dashboard_pipelinerp      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))rh   r]   backgroundColorri   rj   )GETgetr	   r?   r   
isinstancerB   datetimedatemonthrn   r   )rM   selected_yearrP   employee_count_per_monthinfomonth_indexrj   ro   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    Openingsrg   )job_position_id__department_idr   r]   r   )r   r?   r   r   r@   rn   rL   rC   
departmentintsumr   )	_requestr[   r   rh   ro   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)rr   json)openPositionsrecruitmentInfo)	r   r   r?   r   open_positionsr@   r   	serializer   )rM   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_sent)offer_letter_statussentacceptedrejectedjoined)zNot SentSentAcceptedRejectedJoinedrg   r   )r   r?   r   rE   ranger   rC   r   )
r   not_sent_candidatessent_candidatesaccepted_candidatesrejected_candidatesjoined_candidatesro   rj   r]   r^   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.httpr   django.shortcutsr   django.utils.translationr   rn   base.modelsr   r   employee.modelsr	   horilla.decoratorsr
   recruitment.decoratorsr   recruitment.modelsr   r   r   r   r   re   rp   r   r   r   r    r   r   <module>r      s     # $ # 6 / 3 - 4 G G	 67C 8 CL 67 8 < 67-A 8 -A` 67@ 8 @8R 67)A 8 )Ar   