
    siX                        d Z ddl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 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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'm(Z( ddl%m)Z* ddl+m,Z, ddl-m.Z.m/Z/ ddl0m1Z1m2Z2 ddl3m4Z4m5Z5m6Z6m7Z7  e d      rddl8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z? ddl@mAZA ddlBmCZCmDZD  e d       r
dd!lEmFZFmGZGmHZH  e d"      rdd#lImJZJmKZK dd$lLmMZMmNZN  ej                  eP      ZQ ee1d%&       e eCd'(      d%&       G d) d*e4                    ZReRxj                   ed+       ed,      d- ed.       ed/      d-gz  c_S         G d0 d1e      ZT G d2 d3e      ZU G d4 d5e      ZV ee1d%&       e eCd'(      d%&       G d6 d7e5                    ZW ee1d%&       e eCd'(      d%&       G d8 d9e5                    ZX ee1d%&       e eCd'(      d%&       ee	e(:      d;                      ZY ee1d%&       e eCd'(      d%&       G d< d=e5                    ZZ ee1d%&       e eCd'(      d%&       G d> d?e7                    Z[ e d       reRj                  j                   ed@       edA      d-        ee1d%&       e eCd'(      d%&       G dB dCe7                    Z]dD Z^e^eG_^         ee1d%&       e eCd'(      d%&       G dE dFeH                    Z_ e d      reRj                  j                   edG       edH      d-        ee1d%&       e eCd'(      d%&       G dI dJe7                    Z`dK ZadL ZbdM Zceae9_a        ece9_c        ebe9_b         ee1d%&       e eCd'(      d%&       G dN dOe6                    ZddP Ze ee1d%&       e eCd'(      d%&       G dQ dRe7                    Zf ee1d%&       e eCd'(      d%&       G dS dTe7                    Zg ee1d%&       e eDd'(      d%&       G dU dVe7                    Zh e d"      reRj                  j                   edW       edX      d-       eRj                  j                   edY       edZ      d-       d[ ZieieJ_i         ee1d%&       e eCd'(      d%&       G d\ d]e7                    Zj G d^ d_eK      Zkd` ZleleM_l         ee1d%&       e eCd'(      d%&       G da dbe7                    Zm ee1d%&       e eCd'(      d%&       G dc ddeN                    Znde Zodf Zp ee1d%&       e eCd'(      d%&       G dg d+e7                    Zq ee1d%&       e eCd'(      d%&       G dh die                    Zry)jzW
employee/cbv/allocations.py

Detailed view to manage all modules employee information
    N)datetime)messages)Q)	post_save)receiver)HttpResponse)render)reverse_lazy)method_decorator)gettext)View)AddToUserGroupForm	ModelFormforms)paginator_qry)app_installed)get_models_in_app)get_model_class)EmployeeEmployeeBankDetailsEmployeeWorkInformation)models)_thread_locals)APPSNO_PERMISSION_MODALS)login_requiredrender_template)HorillaDetailedViewHorillaFormViewHorillaListViewTemplateViewasset)Asset)AssetFilter)AssetAssignment)asset_allocate_return)AssetReturnForm)all_manager_can_enterrecruitment_manager_can_enterleave)AvailableLeave	LeaveTypeLeaveTypeListViewpayroll)	AllowanceAllowanceListView)	DeductionDeductionListViewdispatch)namezrecruitment.view_recruitment)permc                   8     e Zd ZdZg ZdZeZ fdZ fdZ	 xZ
S )AllocationViewz
    AllocationView
    z cbv/allocations/allocations.htmlc                 $    t        |   di | y N )super__init__selfkwargs	__class__s     </var/www/python-projects/worksol/employee/cbv/allocations.pyr<   zAllocationView.__init__J   s    "6"    c                 :   | j                   d   }|j                  j                  d      }|rwt        |      }|j                  j                  |      }||_        |j                  }|j                          ||j                  s|j                  rt        j                  j                  |j                  |j                  |j                  |j                  |j                   |j"                  |j"                  |j$                  |j&                  |j(                  |j*                        d   }||_        |j                          d|j,                  _        |j,                  j                          nU|sSt1        j2                  |t5        d             t7        j8                         S t        j                  j                  |      }|| _        t=        	|   |g|i |  | j>                  d
i |}||d<   | j@                  |d	<   tC        || jD                  |      S )NpkmodelrD   )employee_first_nameemployee_profileemailphoneaddresscountrystatecityzipdobgenderr   Fz1Allocation feature not possible to this candidateinstancemenuesr:   )#r?   GETgetr   objectsemployee_candidateconverted_employee_idsavehiredonboarding_stager   get_or_creater4   profilerI   mobilerK   rL   rN   rO   rP   rQ   employee_user_id	is_activer   info_r   r   rR   r;   get_context_datarS   r	   template_name)
r>   requestargsr?   rD   rE   	candidaterR   contextr@   s
            rA   rU   zAllocationView.getM   s   [[( $E*E))R)0I)2G& 66HNNY__	8R8R#++99(1%.%6%6#//#**%--%--#++"!!$++ :   3;	/ 6;))3))..0QRS '3355''++r+2H G-d-f-'$''1&1&
 KKgt117;;rB   )__name__
__module____qualname____doc__rS   rd   r   rE   r<   rU   __classcell__r@   s   @rA   r7   r7   =   s(    
 F6ME#.< .<rB   r7   Summaryzallocation-summary)menuurlr   zallocation-employee-formsc                   P     e Zd ZdZddddddddddd
Z fdZ G d d      Z xZS )PersonalFormz
    PersonalForm
          )
rK   rL   rM   rN   rO   rP   rQ   emergency_contactemergency_contact_nameemergency_contact_relationc                    t        |   |i | t        d      | j                  d   _        t        d      | j                  d   _        d| j                  d   _        t        j                  ddd	
      | j                  d   _        | j                  d   j                  j                  }d|d<   d|d<   t        j                  |
      | j                  d   _        t        j                  |
      | j                  d   _        | j                  j                  d      }t        | j                  j                               }|j                  dd|f       t        |      | _        y )NzContact namerw   zContact Relationrx   zBadge IDbadge_iddateoh-input w-100typeclassattrsrP   rL   oh-select oh-select2 w-100r   height:45px !important;stylerM   rH      )r;   r<   rb   fieldslabelr   	DateInputwidgetr   Selectpoplistitemsinsertdict)r>   rf   r?   r   profile_fieldr   r@   s         rA   r<   zPersonalForm.__init__   s%   $)&)676G,-3:;<N:O017(2J%$)OO!,<=%
E! I&--335g2g(-5(AI%&+ll&?G# (:;dkk'')*a,m<=6lrB   c                        e Zd ZdZeZdZg dZy)PersonalForm.Meta
        Meta
        __all__)r_   additional_infor`   N)ri   rj   rk   rl   r   rE   r   excluder:   rB   rA   Metar      s    	 
rB   r   ri   rj   rk   rl   colsr<   r   rm   rn   s   @rA   rs   rs      s>    
 "#&'D#*
 
rB   rs   c                   6     e Zd ZdZ fdZ G d d      Z xZS )WorkInfoz
    WorkInfo
    c                     t        |   |i | t        j                  ddd      | j                  d   _        t        j                  ddd      | j                  d   _        y )Nr{   r|   r}   r   date_joiningcontract_end_date)r;   r<   r   r   r   r   )r>   rf   r?   r@   s      rA   r<   zWorkInfo.__init__   s^    $)&)-2__!,<=.
N#* 38//!,<=3
'(/rB   c                        e Zd ZdZeZdZg dZy)WorkInfo.Metar   r   )employee_id
experiencer   N)ri   rj   rk   rl   r   rE   r   r   r:   rB   rA   r   r      s    	 (
rB   r   )ri   rj   rk   rl   r<   r   rm   rn   s   @rA   r   r      s    

 
rB   r   c                   J     e Zd ZdZddddddddZ fdZ G d d      Z xZS )	BankInfoz
    BankInfo
    rt   ru      )rK   rL   rM   rN   	bank_nameaccount_numberbranchc                    t        |   |i | | j                  j                  d      }t	        | j                  j                               }|j                  dd|f       t        |      | _        | j                  d   j                  j                  }d|d<   d|d<   d|d<   t        j                  |	      | j                  d   _        d
|d<   t        j                  |	      | j                  d
   _        y )Nr      rL   r   r   r   r   idr   rM   )r;   r<   r   r   r   r   r   r   r   r   r   r   )r>   rf   r?   r   r   r   r@   s         rA   r<   zBankInfo.__init__   s    $)&))9:dkk'')*a*N;<6lI&--335g2gd(-5(AI%d&+ll&?G#rB   c                        e Zd ZdZeZdZg dZy)BankInfo.Metar   r   )r   r   r`   N)ri   rj   rk   rl   r   rE   r   r   r:   rB   rA   r   r      s    	 $
rB   r   r   rn   s   @rA   r   r      s6    
 D@ 
 
rB   r   c                   n     e Zd ZdZeZeZdZdddddZ	 fdZ
dd fd	
Zdd fd

Zdef fdZ xZS )PersonalFormViewz
    PersonalFormView
    ,cbv/allocations/employee/form_structure.html.NdatafilesrR   c                    | j                   }|r<t        j                  j                         j	                  |      j                         }| j                  |||| j                               S )NrF   )rR   initial)rR   r   rV   entirefilterfirst
form_classget_initial)r>   r   r   rR   rf   r?   s         rA   	init_formzPersonalFormView.init_form  sa    ==''..07787DJJLH%(D4D4D4F  
 	
rB   c                 D    t        |   di |}| j                  |d<   |S )Nre   r:   )r;   rc   re   r>   r?   rh   r@   s      rA   rc   z!PersonalFormView.get_context_data   s(    '*4V4!\\	rB   rF   c                n    |j                   j                  d      | _        t        |   |g|d|i|S Ninstance_idrD   POSTrU   rR   r;   postr>   re   rD   rf   r?   r@   s        rA   r   zPersonalFormView.post%  7    ((7w|G<d<r<V<<rB   c                n    |j                   j                  d      | _        t        |   |g|d|i|S r   rT   rU   rR   r;   r   r   s        rA   rU   zPersonalFormView.get)  5    6w|G<d<r<V<<rB   formc                    |j                         ri|j                          t        j                  | j                  t        d             t        | j                  | j                  | j                               S t        | )  |      S )NzPersonal Information Updatedre   rd   rh   is_validrY   r   successre   rb   r	   rd   rc   r;   
form_validr>   r   r@   s     rA   r   zPersonalFormView.form_valid-  sj    ==?IIKT\\1-K+LM"00--/  w!$''rB   )ri   rj   rk   rl   rs   r   r   rE   rd   r   rc   r   rU   r   rm   rn   s   @rA   r   r   
  sO    
 JEBM$'sT 

 '+ = &* =(| ( (rB   r   c                   h     e Zd ZdZeZeZdZdddd fd
Z	def fdZ
dd	 fd

Zdd	 fd
Z xZS )WorkFormView
    WorkFormView
    r   .Nr   c                    | j                   j                  j                  dd       }|r<t        j                  j                         j                  |      j                         }t        | $  ||||d|S Nr   employee_id__idr   )
re   rT   rU   r   rV   r   r   r   r;   r   r>   r   r   rR   rf   r?   r@   s         rA   r   zWorkFormView.init_formH  sq    <<##''t<'//6681  w EH
@F
 	
rB   r   c                    |j                         ri|j                          t        j                  | j                  t        d             t        | j                  | j                  | j                               S t        | )  |      S )NzWork Info Updatedr   r   r   s     rA   r   zWorkFormView.form_validU  sj    ==?IIKT\\1-@+AB"00--/  w!$''rB   rF   c                n    |j                   j                  d      | _        t        |   |g|d|i|S r   r   r   s        rA   r   zWorkFormView.posta  r   rB   c                n    |j                   j                  d      | _        t        |   |g|d|i|S r   r   r   s        rA   rU   zWorkFormView.gete  r   rB   )ri   rj   rk   rl   r   r   r   rE   rd   r   r   r   rU   rm   rn   s   @rA   r   r   ;  sJ    
 J#EBM$'sT 

(x 
( '+ = &* = =rB   r   )senderc                    t        t        dd      }|r|rt        |dd      rt        |d      }	 |j                  |_        |j                  |_        |j                  j
                  |_        |j                  j                  |_        t        j                  j                  |       yyyy# t        $ r}t        j                  |       Y d}~Fd}~ww xY w)z
    Work info post save
    re   NrW   )getattrr   joining_dater   job_position_iddepartment_idrecruitment_id
company_id	Exceptionloggererrordjango_modelsModelrY   )r   rR   createdr?   re   rg   es          rA   work_info_post_saver   j  s     ni6G7ww0DdKG%9:		$-$:$:H!'0'@'@H$%.%>%>%L%LH""+":":"E"EH 	  *  L7w  	LLOO	s   AB+ +	C4CCc                   h     e Zd ZdZeZeZdZdddd fd
Z	def fdZ
dd	 fd

Zdd	 fd
Z xZS )BankFormViewr   r   .Nr   c                    | j                   j                  j                  dd       }|r.t        j                  j                  |      j                         }t        |    ||||d|S r   )	re   rT   rU   r   rV   r   r   r;   r   r   s         rA   r   zBankFormView.init_form  so    <<##''t<*2299 ( : eg  w EH
@F
 	
rB   r   c                    |j                         r|j                  j                  sFt        j                  j                  | j                  j                  d         |j                  _        |j                          t        j                  | j                  t        d             t        | j                  | j                  | j                               S t        | A  |      S )Nr   rF   zBank Info Updatedr   )r   rR   r   r   rV   rU   re   r   rY   r   r   rb   r	   rd   rc   r;   r   r   s     rA   r   zBankFormView.form_valid  s    ==?==,,,4,<,<,@,@||((7 -A -) IIKT\\1-@+AB"00--/ 
 w!$''rB   rF   c                n    |j                   j                  d      | _        t        |   |g|d|i|S r   r   r   s        rA   r   zBankFormView.post  r   rB   c                n    |j                   j                  d      | _        t        |   |g|d|i|S r   r   r   s        rA   rU   zBankFormView.get  r   rB   )ri   rj   rk   rl   r   r   r   rE   rd   r   r   r   rU   rm   rn   s   @rA   r   r     sJ    
 JEBM$'sT 
(x ( '+ = &* = =rB   r   c                   &     e Zd ZdZdZ fdZ xZS )EmployeeFormsz
    EmployeeForms
    z#cbv/allocations/employee/forms.htmlc                 &    t        |   di |}|S r9   r;   rc   r   s      rA   rc   zEmployeeForms.get_context_data  s    '*4V4rB   ri   rj   rk   rl   rd   rc   rm   rn   s   @rA   r   r     s    
 :M rB   r   zLeave Policyzallocation-leave-typec                   &     e Zd ZdZdZ fdZ xZS )LeaveTypeViewz
        EmployeeForms
        z cbv/allocations/leave/types.htmlc                 &    t        |   di |}|S r9   r   r   s      rA   rc   zLeaveTypeView.get_context_data  s    g.88GNrB   r   rn   s   @rA   r   r     s    
	 ;	 	rB   r   c                     t        t        d      }| j                  j                  |j                  d         j                         }t        d| |d      S )z5
        Leave type assign toggle allocation
        re   r   r   z&cbv/allocations/leave/toggle_type.html)rR   available_leave)r   r   employee_available_leaver   rT   r   r   )r>   re   r   s      rA   leave_type_toggle_allocationr     s[     .)477>>#KK6 ? 

%' 	 4/B
 	
rB   c                   l     e Zd ZdZdZdZddddZg ZdZdZ	dZ
 fd	Z fd
Z fdZd fd	Zd Z xZS )LeaveTypeAllocationListz)
        LeaveTypeAllocationList
        z$cbv/allocations/leave/type_list.htmlNzstyle='width:80px;'style='width:105px;')paymentcountactionF
            onclick="$(this).find('td:first [type=checkbox]').prop('checked',!$(this).find('td:first [type=checkbox]').is(':checked')).change()"
        c                 h    t        |   di | | j                  j                  | _        d| _        y )Nr   r:   r;   r<   re   path
search_urlaction_methodr=   s     rA   r<   z LeaveTypeAllocationList.__init__   s,    G&v&"ll//DO!?DrB   c                     t        |   di |}t        j                  j	                  | j
                  j                  d   | j                        |d<   |S )Nr   )r   leave_type_id__inassigned_typesr:   )r;   rc   r+   rV   r   re   rT   querysetr   s      rA   rc   z(LeaveTypeAllocationList.get_context_data  sW    g.88G(6(>(>(E(E $ 0 0 ?"&-- )F )G$%
 NrB   c                 2    t        t        | 
  |g|i |S z6
            To avoide parent permissions
            )r;   r-   r3   r>   re   rf   r?   r@   s       rA   r3   z LeaveTypeAllocationList.dispatch  "     *D:7TTTVTTrB   c                     t        | j                  dd       sGt        |   ||g|i |j	                  | j
                  j                  j                  d            }| j                  S )Nr  r   ))employee_available_leave__employee_id__id)r   r  r;   get_querysetr   re   rT   rU   r>   r  filteredrf   r?   r@   s        rA   r  z$LeaveTypeAllocationList.get_queryset  sv    4==*d;G ""*HG7;G?EGWBF,,BRBRBVBV)C    == rB   c           	         t        j                  | j                  j                  d         }| j                  j                  d   }t	        d      }t	        d      }|j
                  j                  |      }t        j
                  j                  |      }|D ]r  }	 |       }
||
_	        |	|
_
        |	j                  |
_        	 |
j                          t        j                  | j                  t!        d      d|	j"                   z          t |s)t        j&                  | j                  t!        d             t)        d      S #  t        j$                  | j                  t!        d	      d
|	j"                   dz          Y xY w)z
            post
            idsr   zleave.models.AvailableLeavezleave.models.LeaveType)id__inrF   z	Assigned  z!Cannot Assign or Already Assignedz ``zSelect Types to Assignb
            <script>$("#reloadMessagesButton").click();$(".reload-record").click();</script>
    )astliteral_evalre   r   r   rV   r   r   rU   r   leave_type_id
total_daysavailable_daysrY   r   r   rb   r4   r   ra   r   )r>   rf   r?   r  r   avaiable_model
type_modeltypesrR   
leave_typeavaiable_instances              rA   r   zLeaveTypeAllocationList.post"  s]    ""4<<#4#4U#;<C,,++M:K,-JKN()ABJ&&--S-9E''++{+;H# 
$2$4!08!-2<!/3=3H3H!0
%**,$$an:??:K7L&L  dllA.F,GH NN=>z/q12s   A	E<F)NF)ri   rj   rk   rl   rd   r	  header_attrsrow_status_indicationsfilter_selectedshow_filter_tags	row_attrsr<   rc   r3   r  r   rm   rn   s   @rA   r   r     s[    
	 ? -+,

 "$ 		@
		U	! 	rB   r   r#   zallocation-assetsc                       e Zd ZdZdZy)Assetsz
        Assets
        z!cbv/allocations/asset/assets.htmlNri   rj   rk   rl   rd   r:   rB   rA   r-  r-  N  s    
	 <rB   r-  c                     t        dd| i      S )#
        Allocation method
        z"cbv/allocations/asset/actions.htmlrR   r   r>   s    rA   asset_allocation_metodr3  Y  s     CjRVEWXXrB   c                     t        dd| i      S )r0  z,cbv/allocations/asset/allocation_status.htmlrR   r1  r2  s    rA   asset_allocation_statusr5  _  s     :Z<N
 	
rB   c                     d|  d}|S )zZ
        Method will retun the api to the avatar or path to the question template
        z!https://ui-avatars.com/api/?name=z&background=randomr:   )r>   rq   s     rA   allocation_asset_get_avatarr7  g  s     2$7IJ
rB   c                        e Zd ZdZeZeZdZdddddZ	g Z
dZdZd	Z ed
      ddf ed      df ed      dfgZ ed      dfgZg ZdZ fdZd fd	Z fdZ fdZ xZS )AssetAllocationListz&
        AssetAllocationLists
        z%cbv/allocations/asset/asset_list.htmlzstyle='width:160px !important;'zstyle='width:150px !important;'zstyle='width:140px !important;'r   )
asset_nameasset_category_idasset_statusr  Fr  r#   r:  r7  Categoryr;  Statusr5  
   c                 h    t        |   di | | j                  j                  | _        d| _        y )Nr3  r:   r  r=   s     rA   r<   zAssetAllocationList.__init__  s,    G&v&"ll//DO!9DrB   c           	         t        | dd       sq| j                  j                  | _        | j	                  | j                  j                  | j
                  | j                        j                  j                  t        d| j                  j                  d         t        d      t        d      z  z  t        d	d
      z        j                  t        | j                  j                  j                  dd            t        | j                  j                  j                  dd            z        | _        t        | ,  | j
                  |g|i || _        | j
                  j                  d      | _        | j
                  S )Nr  )r   r  re   Tr   )&assetassignment__return_status__isnull,assetassignment__assigned_to_employee_id__id)assetassignment__isnull	Availabler<  Healthy)assetassignment__return_statusr<  search )1asset_category_id__asset_category_name__icontains)asset_name__icontainsIn use)r   re   rT   _saved_filtersfilter_classr  qsr   r   rU   r;   r  assigned_assetsr  s        rA   r  z AssetAllocationList.get_queryset  sg   4T2&*ll&6&6# %%!\\--!% $ & 
 RCGIMIYIY -J d;[9:	 ;D)4  VNRllN^N^NbNb ("O
 $,,2B2B2F2FxQS2TUV- @ !& 4MM8!.2!6<! (,}}';';';'R$== rB   c                 D    t        |   di |}| j                  |d<   |S )NrQ  r:   )r;   rc   rQ  r   s      rA   rc   z$AssetAllocationList.get_context_data  s+    g.88G)-)=)=G%&NrB   c                 H   t        |   |i |}t        j                  | j                  j
                  d         }| j                  j
                  d   }t        j                  j                  |      }t        j                  j                  |      j                  d      }| j                  j                  j                  }|D ]o  }	t               }
|	|
_        ||
_        ||
_        t#        j$                         j'                         |
_        d|	_        |
j-                          |	j-                          q |r4t/        j0                  | j                  t3        d             t7        d
      S t/        j4                  | j                  t3        d	             t7        d
      S )Nr  r   rF   pk__inrE  rF  rM  z#Selected Available Assets AllocatedzSelect Available Assets to Addr  )r;   r   r  r  re   r   r   rV   rU   r#   r   useremployee_getr%   asset_idassigned_to_employee_idassigned_by_employee_idr   todayr{   assigned_dater<  rY   r   r   rb   ra   r   )r>   rf   r?   	_responser  r   rR   assetsassigned_byr"   
assignmentr@   s              rA   r   zAssetAllocationList.post  s]   d5f5I""4<<#4#4U#;<C,,++M:K''++{+;H]])))5<<+<VF,,++88K ,.
&+
#5=
25@
2+3>>+;+@+@+B
(%-"!

   q1V/WX    dllA.N,OP rB   )NT)ri   rj   rk   rl   r#   rE   r$   rO  rd   r'  r(  r)  r*  r+  rb   columnssortby_mappingbulk_update_fieldsrecords_per_pager<   r  rc   r   rm   rn   s   @rA   r9  r9  r  s    
	 "? <!B=,	
 "$ 	 wZ'DEz]/0x[34
 x[34
  	:
)	!V	
	 	rB   r9  c                 Z   |d   }| j                   dk(  r	 t        | |       t        d      S t               }t        j                  j                  |d      j                         }||d}||d<   t        | d	|      S #  t        j                  | t	        d             Y t        d      S xY w)
z*
        Return allocation method
        rX  r   zAn error occuredz
                <script>$("#reloadMessagesButton").click();$(".reload-record").click();$("#genericModal").removeClass('oh-modal--show');</script>
        T)rX  return_status__isnull)asset_return_formrX  asset_alocationz&cbv/allocations/asset/return_form.html)methodr&   r   r   rb   r   r'   r%   rV   r   r   r	   )re   rf   r?   rX  rg  asset_allocationrh   s          rA   return_allocationrk    s     *%>>V#?%gx8   
 ,-*2299T : 

%' 	 ):xP%5!"gGQQ?w*<(=> s   A= =!B*c                       e Zd ZdZdZy)
GroupsViewz
    GroupsView
    z$cbv/allocations/auth/group_view.htmlNr.  r:   rB   rA   rm  rm    s    
 ;MrB   rm  c                       e Zd ZdZdZd Zy)Groupsz
    Groups
    z cbv/allocations/auth/groups.htmlc                    i }t         j                  j                  |j                  d         }|j	                         }||d<   g }t
        }t        D ]  }	g }
t        |	      D ]e  }|j                  j                  |vs|
j                  |j                  j                  j                         |j                  j                  d       g |j                  |	j                         j                  dd      |
d        ||d<   ||d	<   t        ||j                  j                  d
            |d<   t!        || j"                  |      S )Nr   r   employee)verbose_name
model_namerb   r  )app
app_modelspermissionsno_permission_modelspage	employees)r   rV   r   rT   r   r   r   r   _metart  appendrs  
capitalizereplacer   rU   r	   rd   )r>   re   rf   r?   rh   rz  emoloyeerw  rx  app_namerv  rE   s               rA   rU   z
Groups.get  s=   $$++w{{=/I+J	??$&
3 	HJ*84 ;;))1EE%%,1KK,D,D,O,O,Q*/++*@*@ #..088cB",	  "-*>&',Y8OP
 	
rB   N)ri   rj   rk   rl   rd   rU   r:   rB   rA   ro  ro  
  s    
 7M
rB   ro  c                        e Zd ZdZdZd Zd Zy)GroupAssignViewz=
    View to assign multiple groups to a single employee
    z$cbv/allocations/auth/group_form.htmlc                 v   |j                   j                  d      }t        j                  j                  |      }|j                  j
                  j                         }t        ||j                   j                  d      d      }t        || j                  ||j                   j                  d      d      S )z
        Get
        rr  rq  )grouprr  )r   r   r   )
rT   rU   r   rV   r_   groupsallr   r	   rd   )r>   re   rf   r?   r   rr  r  r   s           rA   rU   zGroupAssignView.getA  s     kkooj1##'';'7**11557!#KKOOJ7
 '++//**EF
 	
rB   c                 &   t        |j                        }|j                         r:|j                          t	        j
                  |t        d             t        d      S t        || j                  ||j                  j                  d      d      S )z
        Post
        zEmployee assigned to groupa;  <script>
                $('#groupAssignBody').closest('.oh-modal.oh-modal--show').removeClass('oh-modal--show');
                $('.oh-inner-sidebar__link--active').click();
                $("#reloadMessagesButton").click();
                $(".reload-record").click();
                </script>
                rr  r  )r   r   r   rY   r   r   rb   r   r	   rd   rU   )r>   re   rf   r?   r   s        rA   r   zGroupAssignView.postT  s~     "',,/==?IIKWa(D&EF  ',,*:*::*FG
 	
rB   N)ri   rj   rk   rl   rd   rU   r   r:   rB   rA   r  r  6  s    
 ;M
&
rB   r  r/   zallocation-allowancer1   zallocation-deductionc                 <    t        d| t        j                  d      S )r0  z.cbv/allocations/payroll/allowance/actions.htmlrR   rr  )r   r   allowance_employeer2  s    rA   allowance_allocation_metodr  |  "     <>+L+LM
 	
rB   c                       e Zd ZdZdZy)AllowanceView
        AllowanceView
        z5cbv/allocations/payroll/allowance/allowance_view.htmlNr.  r:   rB   rA   r  r        
	 PrB   r  c                        e Zd ZdZdZ fdZdZdZdZg Z	dZ
 ed      ddfgZd	 Z fd
Z fdZ fdZ fdZ xZS )AllowanceList
        AllowanceList
        r  c                 h    t        |   di | | j                  j                  | _        d| _        y )Nr  r:   r  r=   s     rA   r<   zAllowanceList.__init__  ,    G&v&"ll//DO!=DrB   z5cbv/allocations/payroll/allowance/allowance_list.htmlFr/   title
get_avatarc                    | j                   j                  d   }t        j                  j	                  |      | _        | j
                  t        _        | j                   j                  j	                  d      rt        j                  j	                  | j                   j                  d         }|j                  j                  | j
                         |j                  j                  | j
                         t        j                  | j                   t!        d      d| z          t-        d      S t#        j$                  | j                   j                  d         }t        j                  j'                  |      }|D ]Y  }|j                  j                  | j
                         |j(                  r5|j                  j                  | j
                         [ |r4t        j                  | j                   t!        d	             t-        d      S t        j*                  | j                   t!        d
             t-        d      S )Nr   rF   r   allowance_idzAllowance excludedr  r  rT  zAdded to Selected AllowanceszSelect Allowances to Addr  )re   r   r   rV   rU   rR   r   r  rT   r/   exclude_employeesaddspecific_employeesremover   r   rb   r  r  r   include_active_employeesra   r   )r>   rf   r?   r   	allowancer  
allowancess          rA   r   zAllowanceList.post     ,,++M:K$,,00K0@DM04N-||##I.%--11T\\5F5F~5V1W	++//>,,33DMMB  LL!$8"9a	{O"K    &&t||'8'8'?@&..55S5A
!+ HI//66t}}E$==!4488GH $$T\\15S3TU    MM$,,2L0MN rB   c                     t         j                  j                  |j                  d         | _        | j                  t
        _        t        |   |g|i |S Nr   rF   )r   rV   rU   rT   rR   r   r  r;   r  s       rA   rU   zAllowanceList.get  L    $,,00GKK4N0ODM04N-7;w8888rB   c                 D    t        |   di |}| j                  |d<   |S )Nassigned_allowancesr:   )r;   rc   r  r   s      rA   rc   zAllowanceList.get_context_data  +    g.88G-1-E-EG)*NrB   c                 |   t         |          j                  t        d      t        | j                        z        j                  | j
                  j                  j                  dd            j                         | _	        | j                  j                  | j                        | _        | j                  S NT)r  )r  rI  rJ  )title__icontains)r  )r;   r  r   r   rR   re   rT   rU   distinctr  r   r  r>   r@   s    rA   r  zAllowanceList.get_queryset       t44==9: )9)9)=)=h)KL M (,}}'<'<"&-- (= (D$ == rB   c                 2    t        t        | 
  |g|i |S r  )r;   r0   r3   r  s       rA   r3   zAllowanceList.dispatch  r  rB   )ri   rj   rk   rl   r+  r<   rd   r*  r(  rc  r)  rb   ra  r   rU   rc   r  r3   rm   rn   s   @rA   r  r    sf    			>
 P !&kNG\:;	:	9	
	! 	U 	UrB   r  c                 <    t        d| t        j                  d      S )r0  z.cbv/allocations/payroll/deduction/actions.htmlr  )r   r   deduction_employeer2  s    rA   deduction_allocation_metodr    r  rB   c                       e Zd ZdZdZy)DeductionViewr  z5cbv/allocations/payroll/deduction/deduction_view.htmlNr.  r:   rB   rA   r  r    r  rB   r  c                   n     e Zd ZdZdZ fdZdZdZdZg Z	dZ
dgZd Z fdZ fd	Z fd
Z fdZ xZS )DeductionListr  r  c                 h    t        |   di | | j                  j                  | _        d| _        y )Nr  r:   r  r=   s     rA   r<   zDeductionList.__init__
  r  rB   z5cbv/allocations/payroll/deduction/deduction_list.htmlF)r1   r  r  c                    | j                   j                  d   }t        j                  j	                  |      | _        | j
                  t        _        | j                   j                  j	                  d      rt        j                  j	                  | j                   j                  d         }|j                  j                  | j
                         |j                  j                  | j
                         t        j                  | j                   t!        d      d| z          t-        d      S t#        j$                  | j                   j                  d         }t        j                  j'                  |      }|D ]Y  }|j                  j                  | j
                         |j(                  r5|j                  j                  | j
                         [ |r4t        j                  | j                   t!        d	             t-        d      S t        j*                  | j                   t!        d
             t-        d      S )Nr   rF   r   deduction_idzDeduction excludedr  r  rT  zAdded to Selected DeductionszSelect Deductions to Addr  )re   r   r   rV   rU   rR   r   r  rT   r1   r  r  r  r  r   r   rb   r  r  r   r  ra   r   )r>   rf   r?   r   	deductionr  
deductionss          rA   r   zDeductionList.post  r  rB   c                     t         j                  j                  |j                  d         | _        | j                  t
        _        t        |   |g|i |S r  )r   rV   rU   rT   rR   r   r  r;   r  s       rA   rU   zDeductionList.get5  r  rB   c                 D    t        |   di |}| j                  |d<   |S )Nassigned_deductionsr:   )r;   rc   r  r   s      rA   rc   zDeductionList.get_context_data;  r  rB   c                 |   t         |          j                  t        d      t        | j                        z        j                  | j
                  j                  j                  dd            j                         | _	        | j                  j                  | j                        | _        | j                  S r  )r;   r  r   r   rR   re   rT   rU   r  r  r   r  r  s    rA   r  zDeductionList.get_queryset@  r  rB   c                 2    t        t        | 
  |g|i |S r  )r;   r2   r3   r  s       rA   r3   zDeductionList.dispatchP  r  rB   )ri   rj   rk   rl   r+  r<   rd   r*  r(  rc  r)  ra  r   rU   rc   r  r3   rm   rn   s   @rA   r  r    s[    
			>
 P !&9:	:	9	
	! 	U 	UrB   r  c                    | j                   j                  d      xsh | j                   j                  d      xsK | j                   j                  d      xs. | j                   j                  j                  j	                         S )z1
    check the user is a recruitment manager
    zrecruitment.change_recruitmentzauth.add_groupzauth.add_permission)rV  has_permrW  recruitment_setexists)re   rR   rf   r?   s       rA   is_any_recruitment_managerr  W  so    
 	>? 	><<  !12	><<  !67	> <<$$44;;=	rB   c                      t         j                  j                        dz
  }t         fd j                  j                  D              }|dkD  r||z  dz  S dS )Nr   c              3   P   K   | ]  }t        |j                        sd   ywr   N)r   r4   ).0fieldr>   s     rA   	<genexpr>z(completion_percentage.<locals>.<genexpr>e  s     VeGD%**<UVs   &&r   d   )lenr{  r   sum)r>   total_fieldsfilled_fieldss   `  rA   completion_percentager  c  sR    tzz(()A-LVtzz'8'8VVM3?!3CML(C/JJrB   c                   &     e Zd ZdZdZ fdZ xZS )ro   z
    Summary
    zcbv/allocations/summary.htmlc                    t        |   di |}t        j                  j	                  | j
                  j                  d         |d<   g d}g d}g d}t        fd|D              }t        |      }t        j                  j                        j                         }t        j                  j                        j                         }	d	|d
<   d	|d<   |	r*t        fd|D              }
t        |      }|
|z  dz  |d
<   |r*t        fd|D              }t        |      }||z  dz  |d<   ||z  dz  |d<   |S )Nr   rF   rR   )rz   rG   employee_last_namerH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   qualificationr   marital_statusrv   rw   rx   )r   r   work_type_idemployee_type_idjob_role_idreporting_manager_idr   locationrI   r^   shift_idr   r   basic_salarysalary_hour)	r   r   r   rK   rL   rM   rN   any_other_code1any_other_code2c              3   <   K   | ]  }t        |      sd   ywr  )r   r  r  rR   s     rA   r  z+Summary.get_context_data.<locals>.<genexpr>  s      %
78U3KA%
s   )r   r   work_percentagebank_percentagec              3   N   K   | ]  }t        j                  |      rd   ywr  )r   employee_work_infor  s     rA   r  z+Summary.get_context_data.<locals>.<genexpr>  s)      %866> %   "%r  c              3   N   K   | ]  }t        j                  |      rd   ywr  )r   employee_bank_detailsr  s     rA   r  z+Summary.get_context_data.<locals>.<genexpr>  s)      %8995A %r  personal_percentager:   )r;   rc   r   rV   rU   re   rT   r  r  r   r   r   r   )r>   r?   rh   personal_info_fieldswork_info_fieldsbank_info_fieldspersonal_filled_fieldstotal_personal_fieldsbank_instancework_instancework_filled_fieldstotal_work_fieldsbank_filled_fieldstotal_bank_fieldsrR   r@   s                 @rA   rc   zSummary.get_context_datau  s   '*4V4##''4<<+;+;M+J'K&
 
*
"

 "% %
/%
 "
 !$$8 9+33::x:PVVX/77>>  ? 

%' 	 &'!"%&!"!$ %-% "
 !$$4 5*<?P*PTW)WG%&!$ %-% "
 !$$4 5*<?P*PTW)WG%& #%::*%& rB   r   rn   s   @rA   ro   ro   j  s    
 3MU UrB   c                       e Zd ZdZd Zy)ToggleDashboardAccessz
    ToggleDashboardAccess
    c                    t         j                  j                  |j                  d         }|j                  j
                   |j                  _        |j                  j                          |j                  j
                  r*t        j                  |t        d             t        d      S t        j                  |t        d             t        d      S )z
        post
        r   rF   zDashboard access providedzDashboard access removedzZ
        <script>$("#reloadMessagesButton").click();$(".reload-record").click();</script>
)r   rV   rU   rT   r_   r`   rY   r   r   rb   r   )r>   re   rf   r?   rR   s        rA   r   zToggleDashboardAccess.post  s     ##''7;;}+E'F2:2K2K2U2U.U!!+!!&&($$..Wa(C&DE 
 	
 Wa(B&CD
 	
rB   N)ri   rj   rk   rl   r   r:   rB   rA   r  r    s    

rB   r  )srl   r  loggingr   django.contribr   django.db.modelsr   django.db.models.signalsr   django.dispatchr   django.httpr   django.shortcutsr	   django.urlsr
   django.utils.decoratorsr   django.utils.translationr   rb   django.views.genericr   
base.formsr   r   r   base.methodsr    base.templatetags.horillafiltersr   
base.viewsr   employee.methods.methodsr   employee.modelsr   r   r   r   r   horilla.horilla_middlewaresr   horilla.horilla_settingsr   r   horilla_views.cbv_methodsr   r   horilla_views.generic.cbv.viewsr   r   r    r!    asset.cbv.request_and_allocationr#   asset.filtersr$   asset.modelsr%   asset.viewsr&   asset.formsr'   onboarding.cbv_decoratorsr(   r)   leave.cbv.leave_typesr+   r,   r-   payroll.cbv.allowancesr/   r0   payroll.cbv.deductionr1   r2   	getLoggerri   r   r7   rS   rs   r   r   r   r   r   r   r   r|  r   r   r   r-  r3  r5  r7  r9  rk  rm  ro  r  r  r  r  r  r  r  r  r  ro   r  r:   rB   rA   <module>r     s      #  . $ $ # $ 4 1 % ; ; & : ( 4 R R 3 6 ? E  6),1+
 RRCB			8	$ .z2=>Z:<( :< 3:<z   )01 *78  2
9 2
j
y 
8*
y *
Z .z2=>Z*( *( 3*(Z .z2=>Z(=? (= 3(=V .z2=>Z 
)34+ 5 3
+" .z2=>Z(=? (= 3(=V .z2=>Z	L 	 3	   n% 78	
 n:6#AB	 	 7	
 .JI*n:6#ABW"3 W 7Wt   gJ 34	
 n:6#AB< < 7<Y
 $:E (CE%$;E!n:6#ABno n 7n`R0 .z2=>Z; ; 3; .z2=>Z%
\ %
 3%
P .z2!'EFZ/
l /
 3/
d   kN 67	
   kN 67	

 ,FI(n:6#ABP P 7PSU) SUj
 ,FI(n:6#ABP P 7P n:6#ABSU) SU 7SUl	K .z2=>Z\l \ 3\~ .z2=>Z
D 
 3
rB   