
    vgf             	          d Z ddlZddlZddlZddlZddlZddlZddlZddlm	Z	mZm
Z
 ddlm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mZ ddlm Z  ddl!m"Z"m#Z# ddl$m%Z%m&Z&m'Z'm(Z( ddl)m*Z*m+Z+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z3 ddl1m4Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z? ddl@mAZA ddlBmCZCmDZDmEZEmFZFmGZGmHZH ddlImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZV ddlWmXZXmYZYmZZZ ddl[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZcmdZdmeZemfZfmgZgmhZh ddlimjZjmkZkmlZlmmZmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZu ddlvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~ dd lmZmZmZmZmZmZ dd!lmZ dd"lmZ dd#lmZ dd$lmZ dd%lmZmZ dd&lmZmZmZmZ dd'lmZmZ dd(lmZ d) Zej8                  ej:                  ej<                  ej>                  ej@                  ejB                  ejD                  ed*Zd+d, id+d- id+d. id+d/ id0Zd1 Zed2        Zed3        Ze e9d4d56      d7               Zd8 Ze e9d9d:e;      d<               Zeed=               Zee ed>ex      d?                      Ze ed@      dA               Zee ed@      dB                      Zee edC      dD                      Zee edE      dF                      Zee edGex      dH                      Zee edIex      dJ                      ZedK        ZeedL               ZeedM               ZeedN               ZdO Zee edI      dP                      Zee edI      dQ                      Ze edI      dR               Ze edI      dS               Ze e7dTg      dU               Ze edV      dW               Ze edX       e7dTg      dY                      ZdZ Ze e9d[d:e;      d\               Ze ed5      d]               Ze ed5      d^               Ze ed5      d_               Ze ed`      da               Ze ed5      db               Ze e7dTg       ed5      dc                      Ze e7dTg      dd               Ze e7deg       ed5      df                      Ze e7deg      dg               Ze ed5       e7dTg      ddh                     Ze edi       e7dTg      ddj                     Ze edk       e7dTg      ddl                     Zee e9d[d:e;      dm                      Ze ed:      edn                      Ze ed:      edo                      Zee ed:      dp                      Ze edq       e7dTg      dr                      Ze edq      ds               Ze edq       e7dTg      dt                      Zee edq      du                      Ze ed5      dv               Ze ed:      dw               Ze e9d[d:e;      dx               Ze edy       e7dTg      dz                      Ze edi       e7dTg      d{                      Ze ed|       e7dTg      d}                      Ze edk       e7dTg      d~                      Ze ed       e7dTdeg      d                      Ze ed`      d               Ze ed`      d               Zd Zse ed`      d               Ze ed:      d               Zd Zed        Ze ed:      d               Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Ze ed:      d               Zee ed      d                      Zee ed      dd                     Ze ed      d               Ze ed      d               Zee ed      d                      Zee ed      d                      Zee edex      d                      Ze ed      d               Ze edex      d               Zed        Ze ed      d               Ze ed      d               Ze ed:      d               Zee ed:      d                      Zed        Zed        Ze ed      d               Zee ed      d                      Zee ed      d                      Zy)a  
views.py

This module contains the view functions for handling HTTP requests and rendering
responses in your application.

Each view function corresponds to a specific URL route and performs the necessary
actions to handle the request, process data, and generate a response.

This module is part of the recruitment project and is intended to
provide the main entry points for interacting with the application's functionality.
    N)datedatetime	timedelta)parse_qs)apps)settings)messages)User)cache)modelstransaction)FProtectedError)QuerySet)	DateInputSelect)HttpResponseHttpResponseRedirectJsonResponse	QueryDict)get_object_or_404redirectrender)reverse)timezone)gettext)gettext_lazy)require_http_methods)enter_if_accessible)#update_employee_accessibility_cache)ACCESSIBILITY_CACHE_USER_KEYS)DefaultAccessibility)	ModelForm)choosesubordinatesfiltersubordinatesfiltersubordinatesemployeemodelget_key_instancesget_paginationsortby)Company
DepartmentEmailLogEmployeeShiftEmployeeTypeJobPositionJobRoleRotatingShiftAssignRotatingWorkTypeAssignShiftRequestWorkTypeWorkTypeRequestclear_messages)DocumentRequestFilterEmployeeFilterEmployeeReGroup)BonusPointAddFormBonusPointRedeemFormBulkUpdateFieldFormEmployeeBankDetailsFormEmployeeBankDetailsUpdateFormEmployeeExportExcelFormEmployeeForm EmployeeGeneralSettingPrefixFormEmployeeNoteFormEmployeeTagFormEmployeeWorkInformationForm!EmployeeWorkInformationUpdateFormexcel_columns)bulk_create_department_importbulk_create_employee_importbulk_create_employee_typesbulk_create_job_position_importbulk_create_job_role_importbulk_create_shiftsbulk_create_user_importbulk_create_work_info_importbulk_create_work_typesconvert_nanget_ordered_badge_idsset_initial_password)
BonusPointEmployeeEmployeeBankDetailsEmployeeGeneralSettingEmployeeNoteEmployeeTagEmployeeWorkInformation	NoteFiles)hx_request_requiredloggerlogin_requiredmanager_can_enterowner_can_enterpermission_required)HorillaPaginator)group_by_queryset)HORILLA_DATE_FORMATS)get_horilla_model_class)AccountBlockUnblockHistoryTrackingFields)DocumentFormDocumentRejectFormDocumentRequestFormDocumentUpdateForm)DocumentDocumentRequest)notifyc                      y N )abs     "/var/www/horilla/employee/views.pyreturn_nonert      s        )equalnotequalltgtlege	icontainsrangefilterc                 6    | |j                   j                  ddS )NT)employee_idwork_type_id__idattendance_validated)work_type_ididemployee	allowances     rs   <lambda>r      s    # ) 6 6 9 9$(/
 ru   c                 6    | |j                   j                  ddS )NT)r   shift_id__idr   )shift_idr   r   s     rs   r   r      s    #%..11$(0
 ru   c                     | dddS )NT)r   attendance_overtime_approver   rp   r   s     rs   r   r      s    #+/$(/
 ru   c                     | ddS )NT)r   r   rp   r   s     rs   r   r      s    #$(/
 ru   )r   r   overtime
attendancec                 b    | j                   j                  }|j                  j                         S ro   )useremployee_getreporting_managerexists)requestr   s     rs   _check_reporting_managerr      s&    ||((H%%,,..ru   c                 4    | j                   }t        d|i      S )z
    Retrieve the language code for the current request.

    This view function extracts the LANGUAGE_CODE from the request object and
    returns it as a JSON response. This function requires the user to be logged in.
    language_code)LANGUAGE_CODEr   )r   r   s     rs   get_language_coder      s     ))M-899ru   c                     | j                   j                  }t        j                         }t	        j
                         }t        | d|||d      S )z>
    This method is used to view own profile of employee.
    z"employee/profile/profile_view.html)r   current_datenow)r   r   r   todayr   r   r   )r   r   r   r   s       rs   employee_profiler      sK    
 ||((HNNE
,,.C, !	
 ru   profile_editemployee.change_employee)featurepermc                    | j                   }t        j                  j                  |      j	                         }|j
                  }t        t        j                  j                  |      j	                               }t        t        j                  j                  |      j	                               }| j                  r| j                  j                  d      t        j                  j                  | j                         j	                         }t        | j                  |      }|j                         r|j                  d      }||_        |j
                  ||_        |j                          t        j                  | t!        d             n| j                  j                  d      t        j                  j                  |      j	                         }t        | j                  |      }|j                         rH|j                  d      }||_        |j                          t        j                  | t!        d	             t%        | d
||d      S )zC
    This method is used to update own profile of an employee.
    employee_user_idr   instanceemployee_first_nameFcommitProfile updated.any_other_code1zBank details updated.zemployee/profile/profile.html)form	bank_form)r   rT   objectsr~   firstbadge_idr=   rU   r@   POSTgetis_validsaver   r	   success_r   r   )r   r   r   r   r   r   r   s          rs   self_info_updater      s    <<D&&&=CCEH  H'$,,333IOOQI !1!1!8!8$!8!O!U!U!WXD||<<12>''...MSSUHx@D}}99E92,0)$$,(0H%  !,>*?@\\/0<*2299h9OUUWH/xPI!!#$>>>7'/$  !,C*DE'"	
 ru   c                    | j                   j                  dd       }t        j                  j	                  |      j                         }|rt        j                  j	                  |      }|j                         x}r||j                  j                         v r|j                  j                  |       n|j                  j                  |       t        j                  |j                         j                  j                  d       }|r't        j                  |d          t!        |d   |       t#        | j$                  j                  dd            S )Nr   )r   r   HTTP_REFERER/)GETr   r"   r   r~   r   rT   	employeesallremoveaddr!   r   r   r   deleter    r   META)r   emp_idr   accessibilityr   r   user_cache_keys          rs   profile_edit_accessr     s   kkooi.G(00777HNNPM$$++v+6	 ((8(=226688''..x8''++H5:>>!2255tN ^B/03N24FQ 0 0 EFFru   employee_detailed_viewemployee.view_employee)r   r   methodc                 $   t         j                  j                  |      }t        j                  d      r|j
                  j                         nd}t        j                  j                         xr( t        j                  j                         j                  }| j                  j                  dg       }t         j                  j                  |      }t        j                  t        || j                   j                  d            j"                  D cg c]  }|j$                   c}      }	t'        |	t(              rt+        j,                  |	      n|	}
|j$                  }d}d}t/        |
      D ]8  \  }}||k(  s|t1        |
      dz
  k(  rd}n|
|dz      }|dk(  rd}n|
|dz
     } n ||||
t3        j4                         t        j                  g       |d	}| j6                  j8                  |k(  r||d
<   n||d<   t;        | d|      S c c}w )=
    This method is used to view profile of an employee.
    r   leaveNfiltered_employeesid__inpage   r   )r   previousnextrequests_idsr   leave_request_idsenabled_block_unblockuser_leavesemployee_leaveszemployee/view/individual.html)rT   r   r   r   is_installedavailable_leaver   re   r   r   
is_enabledsessionr~   jsondumpspaginator_qryr   object_listr   
isinstancestrastliteral_eval	enumeratelenr   r   r   r   r   )r   obj_idkwargsr   r   r   filtered_employee_idsr   r   request_ids_strr   r   previous_idnext_idindexreq_idcontexts                    rs   employee_view_individualr     s     ##v#.H*.*;*;G*D  $$&$  	##**, 	;''--/:: 
 $OO//0DbI!))008M0Njj *"GKKOOF$;k		
 KK	
O os+ 	)  ++KKG"<0 v[ L)A--&uqy1z"*5195 $

!ZZ^!6G ||  H,!0%4!"' _	
s   Hc                 (   t         j                  j                  |      }t        j                  d      r|j
                  j                         nd}t        j                  d      r|j                  j                         nd}t        | d|||d      S )r   r   payrollNr   ztabs/personal_tab.html)r   r   	contracts)	rT   r   r   r   r   contract_setr   r   r   )r   r   r   r   r   r   s         rs   	about_tabr   g  s     ##v#.H/3/@/@/K%%))+QUI*.*;*;G*D  $$&$    ."	
 ru   zperms.employee.view_employeec                    t         j                  j                  |      }t        j                  j	                  |      }t        j                  |D cg c]  }|j                   c}      }t        j                  j	                  |      }t        j                  |D cg c]  }|j                   c}      }t        j                  j	                  |      }t        j                  |D cg c]  }|j                   c}      }	t        j                  j	                  |      }
t        j                  |
D cg c]  }|j                   c}      }||||||	|
|||d
}t        | d|      S c c}w c c}w c c}w c c}w )z
    This function is used to view shift tab of an employee in employee individual & profile view.

    Parameters:
    request (HttpRequest): The HTTP request object.
    emp_id (int): The id of the employee.

    Returns: return shift-tab template
    r   r   )
	work_datawork_type_requests_idsrshift_assignrshift_assign_idsrwork_type_assignrwork_type_assign_ids
shift_datashift_requests_idsr   r   ztabs/shift-tab.htmlr   )rT   r   r   r5   r~   r   r   r   r1   r2   r3   r   )r   r   r   work_type_requestsr   r   r   r   r   r  shift_requestsr  r   s                rs   	shift_tabr  }  sK    ##v#.H(0077F7K!ZZ%788 (//6666JM

#NHHKK#NO.66==&=Q JJDU'V'VW!))00V0DN$PXX[[$PQ ("8&..!6$0G '0'BB+ 	9 $O'V$Ps   E0!E5.E:;E?'horilla_documents.view_documentrequestsc                    | j                   j                         }t               }t        j                  j                         }t        j                  j                  d      }t        | d|      }t        |d| j                   j                  d      d      }t        |      }t        t        |       |||||d}t        | d|	      S )
z
    This function is used to view documents requests of employees.

    Parameters:
    request (HttpRequest): The HTTP request object.

    Returns: return document_request template
    Fdocument_request_id__isnullr  )r   r   querysetdocument_request_idr   )document_requests	documentsfpdfilter_dictz documents/document_requests.htmlr  )r   	urlencoder7   rl   r   r   rk   r~   r%   rb   r   r   r'   r   )r   previous_datafilter_classr  r  	data_dictr   s          rs   document_request_viewr    s     KK))+M(*L'//335  ''E'JI"6I
 "('++//&*A6I 'Ih	*. G '=wOOru   c           
         t         j                  j                         }| j                  j	                         }t        | j                        j                  }|j                  d      j                  d      }t        |d| j                  j                  d      d      }t        |      }t        t        |       t        | d|t        | j                        |||d      S )1
    This method is used to filter employee.
    Tr
  z-document_request_idr  r   zdocuments/requests.html)r  r  r  r  r  )rl   r   r   r   r  r7   qsexcludeorder_byrb   r   r   r'   rk   r   r8   )r   r  r  r  r  s        rs   document_filter_viewr    s     (//335KK))+M%gkk255I!!d!CLLI "('++//&*A6I 'Ih	*!",$!2	

 
ru   z&horilla_documents.add_documentrequestsc                    t               }t        | |d      }| j                  dk(  rMt        | j                        }t        | |d      }|j	                         r|j                         }t        j                  | t        d             |j                  j                         D cg c]  }|j                   }}t        j                  | j                  j                  || j                  j                   dd| j                  j                   d| j                  j                   d| j                  j                   d| j                  j                   d	t!        d
      d	       t#        d      S d|i}t%        | d|      S c c}w )z
    This function is used to create document requests of an employee in employee requests view.

    Parameters:
    request (HttpRequest): The HTTP request object.

    Returns: return document_request_create_form template
    z%horilla_documents.add_documentrequestr   z%Document request created successfullyz requested a document.u   طلب u    مستنداً.z hat ein Dokument angefordert.u    solicitó un documento.u    a demandé un document.employee-profilechatbox-ellipses	recipientverbverb_arverb_deverb_esverb_frr   icon*<script>window.location.reload();</script>r   +documents/document_request_create_form.htmlr  )ri   r$   r   r   r   r   r	   r   r   r   r   r   rm   sendr   r   r   r   r   )r   r   r   r   r   s        rs   document_request_creater,    sl     Dgt-TUD~~"7<<0!TB
 ==?99;DWa(O&PQ;?;K;K;O;O;QR4..RIRKK))#1122HI!',,";";!<<LM"<<4455ST"<<4455MN"<<4455MN !34'
   LMM 	G > % Ss   &Fz)horilla_documents.change_documentrequestsc                 l   t        t        |      }t        j                  j	                  |j
                        }t        |      }| j                  dk(  rt        | j                  |      }|j                         r|j                         }|j                  j                  t        j                  j	                  |j                  j                  d                   |j!                  |j                  j#                               j%                          t'        d      S ||d	}t)        | d
|      S )z
    This function is used to update document requests of an employee in employee requests view.

    Parameters:
    request (HttpRequest): The HTTP request object.

    Returns: return document_request_create_form template
    r   )r  r   r   r   r   employee_id__inr)  )r   document_requestr*  r  )r   rl   rk   r   r~   r   ri   r   r   r   r   r   setrT   datagetlistr  r   r   r   r   )r   r   r0  r  r   doc_objr   s          rs   document_request_updater5    s    )R@  ''<L<O<O'PI(89D~~"7<<:JK==?iikG##  ''tyy/@/@/O'P g.A.A.E.E.GHOOQ LMM ,G > ru   zhorilla_documents.view_documentc                     t        | j                  | j                        }t        j                  j                  |      }|||d}t        | d|      S )a	  
    This function is used to view documents tab of an employee in employee individual
    & profile view.

    Parameters:
    request (HttpRequest): The HTTP request object.
    emp_id (int): The id of the employee.

    Returns: return document_tab template
    r   )r  r   r   ztabs/document_tab.htmlr  )rj   r   FILESrk   r   r~   r   )r   r   r   r  r   s        rs   document_tabr8  8  sU     gllGMM:D  ''F';I G
 '3WEEru   zhorilla_documents.add_documentc                 x   t         j                  j                  |      }t        |dd      }| j                  dk(  rjt        | j
                  | j                        }|j                         r:|j                          t        j                  | t        d             t        d      S ||d}t        | d	|
      S )z
    This function is used to create documents from employee individual & profile view.

    Parameters:
    request (HttpRequest): The HTTP request object.
    emp_id (int): The id of the employee

    Returns: return document_tab template
    r   N)r   expiry_dateinitialr   zDocument created successfully.r)  r   r   z#tabs/htmx/document_create_form.htmlr  )rT   r   r   rg   r   r   r7  r   r   r	   r   r   r   r   )r   r   r   r   r   s        rs   document_creater>  R  s     ""&&&&1KD QRD~~GLL'--8==?IIKWa(H&IJ LMM G '@'RRru   c                 N   t        t        |      }| j                  j                  d      }| j                  dk(  rA||_        |j                          t        j                  | t        d             t        d      S t        j                  | t        d             t        d      S )z
    This function is used to create documents from employee individual & profile view.

    Parameters:
    request (HttpRequest): The HTTP request object.

    Returns: return document_tab template
    r   titler   z#Document title updated successfullyzInvalid request )r   rk   r   r   r   r@  r   r	   r   r   errorr   )r   r   documentnames       rs   update_document_titlerE  o  s     !b1H<<G$D~~!$I"JK  	w"3 45ru   c           
         	 t         j                  j                  |      }| j                  j	                  d      s,|j                  | j                        j                  d      }|r|j                         }|j                          t        j                  | t        d| d|j                   d             | j                  j                  d	d
      }ddj                  |j                  d      dd       z   }|j!                  d      s|j#                  d      rOt         j                  j                  |j                        }|s#t%        d|j                  j&                   d      S t%               S t        j(                  | t        d             	 t%        d      S # t*        $ r, t        j(                  | t        d             Y t%        d      S w xY w)a  
    Handle the deletion of a document, with permissions and error handling.

    This view function attempts to delete a document specified by its ID.
    If the user does not have the "delete_document" permission, it restricts
    deletion to documents owned by the user. It provides appropriate success
    or error messages based on the outcome. If the document is protected and
    cannot be deleted, it handles the exception and informs the user.
    r   z!horilla_documents.delete_document)employee_id__employee_user_idFr
  zDocument request z for z deleted successfullyr   rA  r      Nz/employee/employee-view/z/employee/employee-profile/r   zB
                            <span hx-get='/employee/document-tab/z?employee_view=true'
                            hx-target='#document_target' hx-trigger='load'></span>
                        zDocument not foundz You cannot delete this document.r)  )rk   r   r~   r   has_permr  r   r   r	   r   r   r   r   r   joinsplit
startswithendswithr   r   rB  r   )r   r   rC  document_firstreferrerexisting_documentss         rs   document_deleterQ    s   "G##**b*1||$$%HI.5ll ' g%g8  %^^-NOO''7u^=W=W<XXmn ||'';HSXXhnnS&9!"&=>>H""#=>(BSBS-C &.%5%5%<%< . : : &= &" *'BBPB\B\B_B_A` a   >!NN7A&:$;< DEE  Gw"D EFDEEGs   E,F$ /	F$ 9F$ $(GGc                    t         j                  j                  |      }t        |      }| j                  dk(  rkt        | j
                  | j                  |      }|j                         r8|j                          t        j                  | t        d             	 t        j                  | j                  j                  | j                  j                  j!                         j"                  | j                  j                   dd| j                  j                   d| j                  j                   d| j                  j                   d	| j                  j                   d
t%        dd| j                  j                  j&                  i      d	       t)        d      S ||d}t+        | d|      S #  Y t)        d      S xY w)a   
    This function is used to upload documents of an employee in employee individual & profile view.

    Parameters:
    request (HttpRequest): The HTTP request object.
    id (int): The id of the document.

    Returns: return document_form template
    r   r   r   zDocument uploaded successfullyz uploaded a documentu   قام u    بتحميل مستندz hat ein Dokument hochgeladenu    subió un documentou    a téléchargé un documentzemployee-view-individualr   )r   r   r!  r)  )r   rC  ztabs/htmx/document_form.htmlr  )rk   r   r   rj   r   r   r7  r   r   r	   r   r   rm   r+  r   r   get_reporting_managerr   r   r   r   r   )r   r   document_itemr   r   s        rs   file_uploadrU    s    $$((B(/M}5D~~!',,V==?IIKWa(H&IJLL--%ll77MMO``#LL5566JK%gll&?&?%@@XY&||8899VW&||8899MN&||8899UV$2 (',,*C*C*F*FG ,    LMM7G'97KK LMMs    C=F; ;G	c                    t         j                  j                  |      j                         }d|i}|j                  r|j                  j
                  }t        j
                  j                  |      d   dd j                         }t        |      }	 t        |d      5 }|j                         }ddd       |d<   ||d<   ||d<   t        | d	|      S # 1 sw Y   %xY w#  d}Y .xY w)
z
    This function used to view the uploaded document in the modal.
    Parameters:

    request (HttpRequest): The HTTP request object.
    id (int): The id of the document.

    Returns: return view_file template
    r   rC  r   Nrbfile_contentfile_extensioncontent_typeztabs/htmx/view_file.html)rk   r   r~   r   rC  pathossplitextlowerget_content_typeopenreadr   )	r   r   document_objr   	file_pathrY  rZ  filerX  s	            rs   	view_filere    s     ##**b*1779LLG  ))..	)))4Q7B

%' 	 (7	 i& +$#yy{+
 #/$2 !".'5w??+ +	 Ls$   C!  C1C! CC! !C'c                 :    dddddddd}|j                  | d      S )	z}
    This function retuns the content type of a file
    parameters:

    file_extension: The file extension of the file
    zapplication/pdfz
text/plainzGapplication/vnd.openxmlformats-officedocument.wordprocessingml.documentzAapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheetz
image/jpegz	image/png)pdftxtdocxxlsxjpgpngjpegzapplication/octet-stream)r   )rY  content_typess     rs   r_  r_    s6     !YSM ^-GHHru   c                    t        t        |      }|j                  rAd|_        |j	                          t        j                  | t        d             t        d      S t        j                  | t        d             t        d      S )z
    This function used to view the approve uploaded document.
    Parameters:

    request (HttpRequest): The HTTP request object.
    id (int): The id of the document.

    Returns:
    r   approvedzDocument request approvedNo document uploadedr)  )
r   rk   rC  statusr   r	   r   r   rB  r   )r   r   rb  s      rs   document_approvers    ss     %X"5L(!$?"@A DEE 	w"8 9:DEEru   c                    t        t        |      }t               }|j                  r| j                  dk(  rt        | j
                  |      }|j                         r{|j                         }d|_        |j                          t        j                  | t        d             t        d      S t        j                  | t        d             t        d      S t        | d||d	      S )
z
    This function used to view the reject uploaded document.
    Parameters:

    request (HttpRequest): The HTTP request object.
    id (int): The id of the document.

    Returns:
    r   r   r   rejectedDocument request rejectedr)  rq  ztabs/htmx/reject_form.html)r   rb  )r   rk   rh   rC  r   r   r   r   rr  r	   rB  r   r   r   )r   r   rb  r   tests        rs   document_rejectrx  6  s     %X"5LD>>V#%gll\JD}}yy{&0#!!#w*E(FG#$PQQw"8 9:HII$|4 ru   c                 (   | j                   j                  d      }t        j                  j	                  |      j                  d      }|j                  d       t        j                  | t        t        |       d             t        d      S )	z
    This function used to view the approve uploaded document.
    Parameters:

    request (HttpRequest): The HTTP request object.

    Returns:
    idsr   rA  )rC  rp  )rr  z Document request approvedr   )r   r3  rk   r   r~   r  updater	   r   r   r   r   )r   rz  rb  s      rs   document_bulk_approver|  Z  s     ++

e
$C##** + grg  z*Wa3|#4"55O PQR	""ru   c                 (   | j                   j                  d      }| j                   j                  d      }t        j                  j                  |      }|j                  d|       t        j                  | t        d             t        d      S )z
    This function used to view the reject uploaded document.
    Parameters:

    request (HttpRequest): The HTTP request object.

    Returns:
    rz  reasonr   ru  )rr  reject_reasonrv  r   )r   r3  r   rk   r   r~   r{  r	   r   r   r   )r   rz  r~  rb  s       rs   document_bulk_rejectr  o  sy     ,,

u
%C\\h'F##**#*6Lz@Wa ;<=	""ru   r   c                    | j                   j                  }t        j                  j	                  |      j                         }t        | j                  |      }|j                         rH|j                  d      }||_
        |j                          t        j                  | t        d             t        | j                  j!                  d            S )z7
    This method is used to fill self bank details
    r   r   Fr   zBank details updatedr   )r   r   rU   r   r~   r   r>   r   r   r   r   r	   r   r   r   r   r   )r   r   r   r   	bank_infos        rs   employee_profile_bank_detailsr    s     ||((H"**11h1GMMOH(ID}}IIUI+	 (	!$:";< 0 0 @AAru   zemployee.view_profilec                 r   | j                   }t        j                  j                  |      }|j	                  d      rp| j
                  dk(  rat        | j                  | j                  |      }|j                         r/|j                          t        j                  | t        d             t        d      S )zJ
    This method is used update own profile of the requested employee
    r   zemployee.change_profiler   r   r   z/employee/employee-profile)r   rT   r   r   rI  r   r@   r   r7  r   r   r	   r   r   r   )r   employee_userr   r   s       rs   employee_profile_updater    s     LLM##]#CH78>>V#gmmhOD}}		  !,>*?@011ru   delete_groupc                     t         j                  j                  |      }|j                  j	                          t        d      S )z9
    This method is used to delete user group assign
    r   z)/employee/employee-user-group-assign-view)r
   r   r   groupsclearr   )r   r   r   s      rs   !employee_user_group_assign_deleter    s7     <<v&DKK?@@ru   c                 P    t        | t                     }|j                  |      } | S )z3
    This method is used to paginate query set
    )ra   r(   get_page)qrysetpage_number	paginators      rs   r   r     s(     !)9:I,FMru   employee_viewc                    | j                   j                  d      }| j                   j                         }| j                   j                  d      }| j                  j                  d      }| j                  j	                  dd      }|dk7  r!t
        j                  j                  d|      nt
        j                  j                  d	      }t        | j                   |
      }t               }t        |      }	t        t
        |	       t
        j                  j                         }
|D cg c]  }|j                   c}| j                  d<   t        | dt        |j                  |      |||||	|
t         j"                  |d	      S c c}w )zF
    This method is used to render template for view all employee
    viewr   selected_companyerror_messageNr   T)	is_activeemployee_work_info__company_idr  r  r   z)employee_personal_info/employee_view.html)	r2  r  r  update_fields_form	view_typer  emp	gp_fieldsr  )r   r   r  r   poprT   r   r~   r8   r<   r   r'   r   r   r   r  r9   fields)r   r  r  r  r  r  r  
filter_objupdate_fieldsr  r  r   s               rs   r  r    s]    'IKK))+M++//&)K**+=>OO''>M
 u$ 	;K 	  	
 $$t$4   h?J')M'Ih	*



!
!
#C JR,RXX[[,RGOO()3!*--="/"$(//*
	
  -Ss   ,Fc                    | j                   dk(  rV| j                  j                  d      | j                  j                  d      }|rt	        j
                  |      nd}|r G fddt               G fddt               G fd	d
t                      }        }        }|j                  j                         }t        |      }g }|D ]  }	d|	z   }	|j                  |	        |D ]  }	|	vsj                  |	        t	        j
                        }
||||
|d}t        | d|      S t        j                  | t        d             t        t               S y )Nr   r  bulk_employee_idsrA  c                   :     e Zd Z G fdd      Z fdZ xZS )9view_employee_bulk_update.<locals>.EmployeeBulkUpdateFormc                      e Zd ZeZg Zi Zi ZW  D ]  Z	 ej                  j                  e      Zej                  dv rDdW  vrej                  d        eddi      ed<   ej                  e        eddi      ee<   nej                  e        eeej"                        r edddd      ee<    y	#  Y xY w)
>view_employee_bulk_update.<locals>.EmployeeBulkUpdateForm.Metacountrystater  requiredTattrsr   F)typer  zdata-ppN)__name__
__module____qualname__rT   modelr  widgetslabelsfield_meta	get_field	field_objrD  appendr   r   r   	DateFieldr   r  s   rs   Metar    s    $EF GF!. %%(0(@(@(GI(~~1EE'0M'A$*MM)$<9?/94.@:&GI$6 !'e 417z4>P1Q &e 4))V5E5EF1:064838+&2"%,%$s   B!B99B=r  c                 v    t        |   |i | | j                  j                         D ]  \  }}d|_         y NTsuper__init__r  itemsr  )selfargsr   
field_namer  EmployeeBulkUpdateForm	__class__s        rs   r  zBview_employee_bulk_update.<locals>.EmployeeBulkUpdateForm.__init__  @    0$@$Q&Q-1[[->->-@ .)
E)-.ru   r  r  r  r  r  __classcell__)r  r  r  s   @rs   r  r    s    % %<. .ru   r  c                   :     e Zd Z G fdd      Z fdZ xZS )9view_employee_bulk_update.<locals>.WorkInfoBulkUpdateFormc                   <   e Zd ZeZg Zi Zi ZW D ]x  Z	  e	e      j                  d      Zed   rWed   dk(  rNej                  j                  ed         Zed   dk(  sed   dk(  sed   dk(  rd	W vrej                  d        ed
di      ed<   dW vrej                  d        ed
di      ed<   dW vrej                  d        ed
di      ed<   ej                  ed           ed
di      ee<   ej                  ed          eD  cg c]  }t#        |t$              s| c}}}} Z eeej(                        r eddi      eed   <   ed   dv r%ej,                  dk(  r ed      n ed      eed   <   { yc c}}}} w #  Y xY w)>view_employee_bulk_update.<locals>.WorkInfoBulkUpdateForm.Meta__r   r   employee_work_infor   department_idjob_position_idjob_role_id!employee_work_info__department_idr  Tr  #employee_work_info__job_position_idemployee_work_info__job_role_idr  r   )emailmobiler  z
Work Emailz
Work PhoneN)r  r  r  rY   r  r  r  r  r  r   rK  partsr  r  r  r  r   r   listr   r  r   rD  r   ).0itemr   r  r  s   0000rs   r  r    s   3EF GF!. ?%>%$'J$4$4T$:E$Ry#(8/C#C0G0M0M0W0W(-b	1&I
 ).aO(C+087H+H+08}+D 1T/<1= -3MM/,JGM7A46HH.GO,D 1V/<1= -3MM:K,LIO7A46HJ.G4E,F 1R/<1= -3MM-,HEK7A46HF.GM,B )/eAh(?9?3=t2D:* %+MM%)$<
 5;.& .&,0/9$/E )-.&F (2)V=M=M'N=F3962B>*b	(: (-Ry4G'G 09~~/H -.lO12< )/uRy(9s?%\.& %$s   DFF4AFFFr  c                 ~   t        |   |i | d| j                  v r4| j                  d   j                  j                  j                  ddi       d| j                  v r4| j                  d   j                  j                  j                  ddi       | j                  j                         D ]  \  }}d|_         y )Nr  onchangezdepChange($(this))r  zjobChange($(this))T)r  r  r  widgetr  r{  r  r  )r  r  r   r  r  WorkInfoBulkUpdateFormr  s        rs   r  zBview_employee_bulk_update.<locals>.WorkInfoBulkUpdateForm.__init__a  s    0$@$Q&Q&$++5O4;;AAHH *,@
 )DKK7$56==CCJJ *,@
 .2[[->->-@ .)
E)-.ru   r  )r  r  r  s   @rs   r  r    s    D% D%L. .ru   r  c                   :     e Zd Z G fdd      Z fdZ xZS )9view_employee_bulk_update.<locals>.BankInfoBulkUpdateFormc                   ,   e Zd ZeZg Zi Zi ZW  D ]  Z	  e	e      j                  d      Zed   red   dk(  rej                  j                  ed         Zej                  ed           eeej$                        r eddi      eed   <   ej(                  dv rnd	W  vrej                  d	        ed
di      ed	<   ej                  ed           ed
di      eed   <   ej(                  d	k(  r ed      n ed      eed   <    y#  Y xY w)>view_employee_bulk_update.<locals>.BankInfoBulkUpdateForm.Metar  r   r   employee_bank_detailsr  r   r  r  r  r  TzBank Countryz
Bank StateN)r  r  r  rU   r  r  r  r  r  r   rK  r  r  r  r  r  r   r   r  r   rD  r   r   r  s   rs   r  r  s  sM   /EF GF!. %%$'J$4$4T$:E$Ry#(8/F#F0C0I0I0S0S(-b	1&I %+MM%)$<'1)V=M=M'N=F3962B>*b	(: (1~~9M'M/8M/I,2MM),DAG7A46HB.GI,> )/eBi(@=C3=t2D>*b	(:
 09~~/J -.n,=12< )/uRy(91%<%$s   C6DDr  c                 v    t        |   |i | | j                  j                         D ]  \  }}d|_         y r  r  )r  r  r   r  r  BankInfoBulkUpdateFormr  s        rs   r  zBview_employee_bulk_update.<locals>.BankInfoBulkUpdateForm.__init__  r  ru   r  )r  r  r  s   @rs   r  r  r  s    $% $%L. .ru   r  employee_work_info__)r   form1form2r  r  z'employee_personal_info/bulk_update.htmlr  z0There are no employees selected for bulk update.)r   r   r3  r   r   r   r#   r  keysr  r  r   r	   warningr   r   r  )r   r  bulk_employee_ids_strr   r  r  r  	keys_listfields_listiupdate_fields_strr   r  r  r  r  s               @@@@rs   view_employee_bulk_updater    sv    ~~,,_=#LL,,-@A->DJJ()B 	 !". ".HV. V.p*. *.X *+D*,E*,E<<$$&DT
IK &*Q.""1%& ! ,M)!((+, !%

= 9 !2%:G 9  MN M**g  ru   c           
      T   | j                   dk(  rg| j                  j                  dd      }|rt        j                  |      ng }| j
                  d   }| j                  j                  dd      }|rt        j                  |      ng }t        j                  |      }|D ]r  }	 t        j                  j                  t        |            }t        j                  j                  |      \  }	}
t        j                  j                  |      \  }}
t |D ]  }t#        |      j%                  d      }|d	   s$|d
   dk(  rLt        j                  j'                  |      }|j                  |d	         } |j(                  di |d	   |i x|d
   dk(  rS|D ]M  }t        j                  j'                  |      }|j                  |d	         } |j(                  di |d	   |i O t        j                  j'                  |      }|j                  |      } |j(                  di ||i  t+        |      d
kD  r7t-        j.                  | t1        dj3                  t+        |                         t5        d      S # t        t        f$ r |j!                  |       Y w xY w)Nr   r  rA  _postr  r   r   r  r   r   r  r.  r  r   z-{} employees information updated successfullyz"/employee/employee-view/?view=listrp   )r   r   r   r   loads__dict__r   r   rT   r   intrY   get_or_createrU   
ValueErrorOverflowErrorr   r   rK  r~   r{  r   r	   r   r   formatr   )r   r  r  
dict_valuer  r  employee_listr   employee_instancer  createdemployee_bankr  r  employee_querysetvalues                   rs   save_employee_bulk_updater    s    ~~#LL,,_bA9J

#45PR%%g.
 ' 0 01Db I1FDJJ,-B 	 (():; 	B$,$4$4$8$8CG$8$D! ,33AA 1 B & (//== 1 > !	$ # 	?EJ$$T*ERy833(?(G(G(N(N(5 )O )% 'NN595E,%,,Bb	5/AB1X!88+ G,?,G,G,N,N,9 -O -) !+uRy 90)00FE"Iu3EFG )1(8(8(?(?}(?(U%&NN51E,%,,>u~>)	?* }!CJJM* 899C . $$R(s   %A/J J'&J'c                    t        t        |      }|s.t        j                  | t	        d             t        t              S t        t        |j                  j                        }|s.t        j                  | t	        d             t        t              S |j                  su|j                   |_        |j                  st	        d      n
t	        d      }|j                          t        j                  | t	        d      j                  ||             n/t        j                  | t	        d      j                  |             t        t        |	      S )
Nr   zEmployee not foundblocked	unblockedz3{employee}'s account {action_message} successfully!)r   action_messagez0{employee} is a superuser and cannot be blocked.)r   )r   )r   rT   r	   infor   r   r  r
   r   r   is_superuserr  r   r   r  r   )r   r   r   r   r  s        rs   employee_account_block_unblockr
    s    !f5Hgq!567&&Th&?&?&B&BCDgq!567&&!^^+-1^^9;		CDKK!. L 	
 	@AHH! I 	
 ,V<<ru   zemployee.add_employeec           	          t               }t               }t               }t        t        j
                  j                               }t        | d||||d      S )zF
    This method is used to render form to create a new employee.
    r  #employee/create_form/form_view.html)r   	work_formr   r  )r@   rD   r=   r8   rT   r   r   r   )r   r   r  r   r  s        rs   employee_view_newr  "  sS     >D+-I')I)9)9)=)=)?@J-IIJW ru   c                 P
   | j                   d   }t        j                  j                  | j                        j                         }t        j                  j                         }d}|r|j                  dk(  rd}t        j                  j                  |      j                         }t        j                  j                         }|j                  |      j                         }	||	}t        j                  j                         }
t        j                  j                  |      }|
j                  |      j                         }|dk7  r||_        |j                          |j                          |r*|j                  j                  |      j                         s| j                  j!                  d      rFt#        |	      }t%        t        j                  j                  |      j                         	      }t'        t(        j                  j                  |      j                         	      }| j*                  r| j*                  j                  d
      dk(  rYt#        | j*                  |	      }|j-                         rd|j                          t/        j0                  | t3        d             n3| j*                  j                  d
      dk(  rYt        j                  j                  |      j                         }t5        | j*                  |	      }|j-                         r|j                  d      }||_        |j                          |j8                  j;                  | j*                  j=                  d             t?        j@                  | j                  jB                  |j6                  jD                  dddddtG        d      d	       t/        j0                  | t3        d             t%        t        j                  j                  |      j                         	      }n| j*                  j                  d
      dk(  rt(        j                  j                  |      j                         }tI        | j*                  |	      }|j-                         rH|j                  d      }||_        |j                          t/        j0                  | t3        d             tK        | d|||||d      S tM        | jN                  j                  dd            S )zA
    This method is used to render update form for employee.
    r  r   FTr   r   r   r   r   r   personalz&Employee personal information updated.workr   tagsz#Your work details has been updated.u&   تم تحديث تفاصيل عملك.z(Ihre Arbeitsdetails wurden aktualisiert.z.Se han actualizado los detalles de su trabajo.u:   Vos informations professionnelles ont été mises à jour.r  	briefcaser!  z"Employee work information updated.bankzEmployee bank details updated.z#employee/update_form/form_view.html)r   r   r  r   work_info_historyr   z/employee/employee-view)(r   rT   r   r~   r   r   rf   work_info_trackget_allrY   r*   r   
company_idr   r   r   rI  r@   rD   r=   rU   r   r   r	   r   r   rE   r   r  r1  r3  rm   r+  r   r   r   r>   r   r   r   )r   r   r   companyr   	work_infor  r   all_employeesr  all_work_infocmpnyr  r   r  r   r   s                    rs   employee_view_updater  3  s:    oo01G""GLL"AGGID%--335IY..$6 &&&&1779H$$,,.M


&

)
/
/
1C/77??A##w#/###9??Ae#DOIIK 	""))h)?FFH<<  !;<X./,44;;$ < eg
	
 ,(0077H7MSSU
	 <<||':5#GLL8D==?IIK$$#K!L !!&)V32::AA ( B %'  >LL8	 %%'(~~U~;H+3H(MMOMM%%gll&:&:6&BCKK11"*"6"6"G"GB H J P \!();!<(
 $$Wa0T.UV74<<CC$, D eg	
 !!&)V3.66== ( > %'  :LL8	 %%'(~~U~;H+3H(MMO$$Wa0P.QR1 &&%6

 
	
  )BC ru   c                    	 t         j                  j                  |      }| j                  d   }||_        |j                          t        j                  | t        d             t        | d      }t        |j                  j                  d      dz         S # t        $ r" t        j                  | t        d             Y ]w xY w)z7
    This method is used to upload a profile image
    r   r   Profile image updated.zNo image chosen.#employee/profile/profile_modal.htmlutf-8#<script>location.reload();</script>)rT   r   r   r7  r   r   r	   r   r   	ExceptionrB  r   r   contentdecode)r   r   r   imgresponses        rs   update_profile_imager)    s    7##''6'2mm./$'!!$<"=> -H (+PP   7w"4 567s   A%B (CCc                 6   | j                   j                  }| j                  j                  d      }||_        |j                          t        j                  | t        d             t        | d      }t        |j                  j                  d      dz         S )zP
    This method is used to update own profile image from profile view form
    r   r   r!  r"  r#  )r   r   r7  r   r   r   r	   r   r   r   r   r%  r&  )r   r   r'  r(  s       rs   update_own_profile_imager+    s     ||((H
--

.
/C #HMMOWa 89:-H (+PP ru   DELETEc                    t         j                  j                  |      }|j                  j                  dk(  rRt        j                  | t        d             t        | d      }t        |j                  j                  d      dz         S |j                  j                  }t        j                  j                  t        j                   |      }t        j"                  |       d|_        |j%                          t        j&                  | t        d             t        | d      }t        |j                  j                  d      dz         S )	zd
    This method is used to remove uploaded image
    Args: obj_id : Employee model instance id
    r   rA  No profile image to remove.r!  r"  r#  NProfile image removed.)rT   r   r   r   rD  r	   r  r   r   r   r%  r&  r[  r\  rJ  r   
MEDIA_ROOTr   r   r   )r   r   r   r(  rc  absolute_paths         rs   remove_profile_imager2    s    ##v#.H  %%+gq!>?@1
 ##G,/TT
 	
 ))..IGGLL!4!4i@MIIm $HMMOWa 89:-H (+PP ru   c                    | j                   j                  }|j                  j                  dk(  rRt	        j
                  | t        d             t        | d      }t        |j                  j                  d      dz         S |j                  j                  }t        j                  j                  t        j                  |      }t        j                   |       d|_        |j#                          t	        j$                  | t        d             t        | d      }t        |j                  j                  d      dz         S )z9
    This method is used to remove own profile image
    rA  r.  r!  r"  r#  Nr/  )r   r   r   rD  r	   r  r   r   r   r%  r&  r[  r\  rJ  r   r0  r   r   r   )r   r   r(  rc  r1  s        rs   remove_own_profile_imager4    s    ||((H  %%+gq!>?@1
 ##G,/TT
 	
 ))..IGGLL!4!4i@MIIm $HMMOWa 89:-H (+PP ru   c                    t         j                  j                  |      j                         }t	        | j
                  |      }|j                         r|j                          |t        j                  | t        d             t	        | j
                  |j                        }t        t        j                  j                  |      j                               }t        t        j                  j                  |      j                               }t!        d|j                  j"                   d|||d      S t%        d	      S |t'        | d
d|i      S dj)                  |j*                  j-                         D cg c]A  \  }}d|j.                  j1                  ||      j2                   ddj)                  |       dC c}}      }t%        d| d      S c c}}w )zA
    This method is used to update employee's personal info.
    r   r   zNew Employee Added.r   zemployee-view-update/r   r   r  r   r2  z
                <div class="oh-alert-container">
                    <div class="oh-alert oh-alert--animated oh-alert--success">
                        Personal Info updated
                    </div>
                </div>

        r  r   
<li>: , </li><ul class="alert alert-danger"></ul>)rT   r   r~   r   r@   r   r   r   r	   r   r   r   rD   rY   r=   rU   r   r   r   r   rJ  errorsr  r  r   label)r   r   r   r   r  r   r  r?  s           rs   $employee_create_update_personal_inforA  	  s    &&&&1779Hx8D}}		>Wa(=&>?t}}ED3088?? ( @ %'I
 0,44;; ( < %'I
 '(8(8'9;"S  	
 		
 ~1
 	
 YY "&!2!2!4	
v 4;;??5%0667r$))F:K9LER	
F 9&GHH	
s   AG"
z'employee.change_employeeworkinformationc                    t         j                  j                  |      j                         }t	        | j
                  t        j                  j                  |      j                               }d|j                  d   _        ||_	        |j                         r6|4|j                  d      }||_	        |j                          t        d      S dj                  |j                  j                         D cg c]A  \  }}d	|j                  j!                  ||      j"                   d
dj                  |       dC c}}      }t        d| d      S c c}}w )z:
    This method is used to update employee work info
    r   r   r   Fr   r   z

                <div class="oh-alert-container">
                    <div class="oh-alert oh-alert--animated oh-alert--success">
                        Personal Info updated
                    </div>
                </div>

        r8  r9  r:  r;  r<  r=  r>  )rT   r   r~   r   rD   r   rY   r  r  r   r   r   r   rJ  r?  r  r   r@  )r   r   r   r   r  r  r?  s          rs   employee_update_work_inforC  @  s8    &&&&1779H&(0077H7MSSUD +0DKK'D}}8/IIUI+	 (	

 
	
 YY "&!2!2!4	
v 4;;??5%0667r$))F:K9LER	
F 9&GHH	
s   ;AE
z#employee.change_employeebankdetailsc                    t         j                  j                  |      j                         }t	        | j
                  t        j                  j                  |      j                               }|j                         r6|4|j                  d      }||_	        |j                          t        d      S dj                  |j                  j                         D cg c]A  \  }}d|j                  j                  ||      j                    d	d
j                  |       dC c}}      }t        d| d      S c c}}w )zS
    This method is used to render form to create employee's bank information.
    r   r   r   Fr   z
            <div class="oh-alert-container">
                <div class="oh-alert oh-alert--animated oh-alert--success">
                    Bank details updated
                </div>
            </div>
        r8  r9  r:  r;  r<  r=  r>  )rT   r   r~   r   r=   r   rU   r   r   r   r   rJ  r?  r  r  r   r@  )r   r   r   r   r  r  r?  s          rs   employee_update_bank_detailsrE  f  s    &&&&1779H"$,,333IOOQD }}8/IIUI+	 (	
 	
 YY "&!2!2!4	
v 4;;??5%0667r$))F:K9LER	
F 9&GHH	
s    AD=
c           
         | j                   j                         }| j                   j                  d      }t        j                  j                         }| j                  j                  d      }t        | j                   |      j                  }| j                   j                  d      dk7  r|j                  d      }| j                   j                  d      d	k(  r|d
k7  r|j                  |      }| j                   j                  d      }| j                   j                  d      }t        |      }t        t        |       d}	|dk(  rd}	|dk7  r|t        |||d      }d}	n@t        | |d      }t        ||      }|D 
cg c]  }
|
j                   c}
| j                  d<   t        | |	|t        | j                         |||d      S c c}
w )r  r  r  r  r  FalseTr  r  Nr   )r  r   r  )employee_personal_info/employee_card.htmlr  )employee_personal_info/employee_list.htmlrA  z$employee_personal_info/group_by.htmlorderbyr   )r2  r  r  r  r  )r   r  r   rT   r   r~   r   r8   r  r   r'   rb   r)   r   r   r   )r   r  r  r  r  r   r  r  r  templater   s              rs   employee_filter_viewrL    s    KK))+MKKOOG$E&&(H**+=>w{{X>AAI{{{#w.$$t$4	89TA%$$DT$U	++//&)K;;??6"D'Ih	*:Hv~>{u(%iVL	97Iy9	!)[9	 NW0W0W,-,$	

 
 1Xs   Gc                 \   | j                   j                         }| j                   j                  d      }t        |t	        d            rd}t        | t        j                  j                         d      }| j                   j                  d      )t        | j                   |j                  |d            }n't        | j                   |j                  |	            }| j                   j                  d
      }t        | |j                  d      }t        | dt        ||      ||d      S )zB
    This method renders card template to view all employees.
    searchNrA  r   r  Temployee_first_name__icontainsr  r  rP  r   rJ  rH  r2  r  r  )r   r  r   r   r  r&   rT   r   r   r8   r~   r)   r  r   r   )r   r  rN  r   r  r  s         rs   employee_cardrS    s    KK))+M[[__X&F&$t*%/!!%%')AI {{{#+#KK%%/5 & 

 $KK%%V%L

 ++//&)Kw
y9I3!)[9	
 ru   c                 \   | j                   j                         }| j                   j                  d      }t        |t	        d            rd}| j                   j                  d      7t        | j                   t        j                  j                  |d            }n5t        | j                   t        j                  j                  |            }t        | |j                  d	      }t        | |d
      }| j                   j                  d      }t        | dt        ||      ||d      S )z<
    This method renders template to view all employees
    rN  NrA  r  TrO  r  rQ  r   rJ  r   rI  rR  )r   r  r   r   r  r8   rT   r   r~   r&   r  r)   r   r   )r   r  rN  r  r   r  s         rs   r  r    s	    KK))+M[[__X&F&$t*%{{{#+#KK%%,,/5 - 

 $KK%%,,F,S

 0 8I w	95I++//&)K3!)[9	
 ru   c                    t         j                  j                  |      }t        |      }t        j                  j                  |      j                         }t        j                  j                  |      j                         }t               }t               }|t        |      }|t        |      }| j                  dk(  r|| j                  j                  d      rat        | j                  | j                  |      }|j                         r/|j!                          t#        j$                  | t'        d             t)        | d|||d      S )	zl
    This method is used to update employee if the form is valid
    args:
        obj_id : employee id
    r   r   r   r   r   zEmployee updated.0employee_personal_info/employee_update_form.htmlr6  )rT   r   r   r@   rY   r~   r   rU   rD   r>   r   r   rI  r   r7  r   r   r	   r   r   r   )r   r   r   r   r  r  r  r   s           rs   employee_updaterW    s    ##v#.H*D'//6686LRRTI#++22x2HNNPI+-I-/I/C	19E	~~<<  !;<gmmhOD}}		  !,?*@A:IIF ru   zemployee.delete_employeec                 d   	 | j                   j                  d      }t        j                  j                  |      }t	        j
                  d      ri|j                  j                         j                         rA|j                  j                         }|D ]"  }|j                  dk7  s|j                          $ |j                  }	 |j                          t        j                  | t        d             tA        | jB                  j                  dd             S # t        $ r |j                          Y bw xY w# t        j                   $ r" t        j"                  | t        d             Y {t$        $ r}t'               }|j(                  D ]>  }	|j+                  t-        |	j.                  j0                  j3                                      @ dj5                  |      }
t        dj7                  |
            }t9        |      }|| j:                  d	<   t=        t>              cY d
}~S d
}~ww xY w)zT
    This method is used to delete employee
    args:
        id  : employee id
    r  r   r   activezEmployee deletedEmployee not found.z, - z- {}.r  Nr   z/view=)"r   r   rT   r   r   r   r   r   r   contract_statusr   r   AttributeErrorr	   r   r   DoesNotExistrB  r   r1  protected_objectsr   r  r  verbose_name
capitalizerJ  r  r   r   r   r  r   r   )r   r   r  r   r   contractr   emodel_verbose_names_setobjmodel_names_strr  s               rs   employee_deleterf  +  s   '||'##''6'2Y'$$((*113$11557	 ) *H//8; )* ((	KKM 	!$6"78   0 06$ QRR  	OO	    :w"7 89 '"%%&& 	QC#''399+A+A+L+L+N(OP	Q ++&=>'..9:M*+8(&&'sO   B&D> )D> D D> D;8D> :D;;D> >2H/2H/:B*H*$H/*H/c                     | j                   d   }t        j                  |      }|D ]  }	 t        j                  j                  |      }t        j                  d      ri|j                  j                         j                         rA|j                  j                         }|D ]"  }|j                  dk7  s|j                          $ |j                  }|j                          t        j                  | t!        d      d|iz          t)        d	d
i      S # t        j"                  $ r# t        j$                  | t!        d             Y &t&        $ r( t        j$                  | t!        d      diz         Y Uw xY w)zA
    This method is used to delete set of Employee instances
    rz  r   r   rY  z%(employee)s deleted.r   rZ  zYou cannot delete %(employee)s.messageSuccess)r   r   r  rT   r   r   r   r   r   r   r   r[  r   r   r	   r   r   r]  rB  r   r   )r   rz  r   r   r   ra  r   s          rs   employee_bulk_deleterj  S  sO    ,,u
C
**S/C 	''++{+;H  +((,,.557 ( 5 5 9 9 ;I$- .#33x?$OO-. ,,DKKM23z86LL* I.// $$ 	>NN7A&;$<= 	NN<=X@VV	s   BD7AD2E=,E=<E=c                    | j                   d   }t        j                  |      }d}| j                  j	                  d      dk(  rd}|D ]x  }t
        j                  j	                  |      }t
        j                  j	                  |      }|j                  j                  r|j                  rvd}t
        j                  j                  d      }|D ]  }|j                  j                  s|d	z   }  |d	k(  r,t        j                  | t        d
             t        d      c S ||_	        ||j                  _	        |j                         du rE|j!                          t        d      }	|rt        d      }	t        j"                  | | d|	        Kt        j$                  | t        d      j'                  |             { t)        ddi      S )zC
    This method is used to archive bulk of Employee instances
    rz  Fr  TrueTr   r   r  r   %You can't archive the last superuser..<script>$('#filterEmployee').click();</script>archivedzun-archivedz is zRelated data found for {}.rh  ri  )r   r   r  r   r   rT   r   r   r	  r  r~   r	   rB  r   r   get_archive_conditionr   r   r  r  r   )
r   rz  r  r   r   r  countr   	super_emprh  s
             rs   employee_bulk_archivers  s  s    ,,u
C
**S/CI{{{#v-	 X##'';'7""k"2,,E ((//$/?I& &	--::!AIE& zw*Q(RS#$TUU&.7!!+))+u4MMO
mGM*W
$wi&@AWa(D&E&L&LX&VW/X0 I.//ru   c                    t         j                  j                  |      }|j                   |_        |j                   |j                  _        d}d}|j                  st         j                  j                  |      }|j                  j
                  rtd}t         j                  j                  d      }|D ]  }|j                  j
                  s|dz   }  |dk(  r*t        j                  | t        d             t        d      S |j                         }	|	rd	}nt        d
      }|rt|j                          t        j                  | |       d}
|
| j                  j                         vr%t!        | j                  j                  dd            S t        d      S t#        | d|	j                  d      |	j                  d      |	j                  d      t        d      d      S )zn
    This method is used to archive employee instance
    Args:
            obj_id : Employee instance id
    r   TEmployee un-archivedr   r  r   rm  rn  FEmployee archivedHTTP_HX_REQUESTr   r   related_models.htmlrelated_modelsrelated_model_fieldsemployee_choicesCan't Archiver   ry  rz  r{  r@  )rT   r   r   r  r   r	  r~   r	   rB  r   r   rp  r   r   r   r  r   r   )r   r   r   r   rh  r  rq  r   rr  resultkeys              rs   employee_archiver    s    ##v#.H%///H.6.@.@*@H'D$G""f"-,,E ((//$/?I& &	--::!AIE& zw*Q(RS#$TUU//1D+,G'*gll''))'(8(8(MNN PQQ!$"(**-=">(.

3I(J$*JJ/A$B?+

 
	
ru   c                    | j                   j                  d      }t        j                  j	                  |      j                         }|r |j                         j                  dd      nd }|r|r|D ]  } |j                  dd      }|s| j                  j                  |      }t        j                  j	                  |      j                         }|dk(  r?t        |      |k7  r1t        j                  j	                  |      j                  |      }	t        j                  d      r~|d	k(  ryt        |      |k7  rkt        dd
      }
|
j                  j	                  |      }|s|D ]8  }|j                  j                  |       |j                  j!                  |       : :t        j                  d      r|dk(  rzt        |      |k7  rlt        dd
      }|j                  j	                  |      }|s|D ]8  }|j"                  j                  |       |j"                  j!                  |       : t        j                  d      r|dk(  rzt        |      |k7  rlt        dd
      }|j                  j	                  |      }|s#|D ]8  }|j$                  j                  |       |j$                  j!                  |       : bt        j                  d      r|dk(  rzt        |      |k7  rlt        dd
      }|j                  j	                  |      }|s|D ]8  }|j$                  j                  |       |j$                  j!                  |       :  |j                         }|dk(  r*t'        j(                  | t+        d             t-        d      S |du rJ|dk7  rEd|_        |j1                          t'        j(                  | t+        d      j3                  |             t-        t4              S )Nr@  r   ry  rA  r  reporting_manager_id)r  recruitmentrecruitment_managers	app_labelr  )r  recruitment_stage_managersstage)stage_managers
onboardingonboarding_stage_manageronboardingstager   onboarding_task_manageronboardingtaskChange the DesignationszDesignation changed.z!/offboarding/offboarding-pipelineFz{} archived successfully)r   r   rT   r   r~   r   rp  r   r   rY   r{  r   r   rd   r  r   r   r  r   r	   r   r   r   r  r   r  r  )r   r   r@  r   ry  r   r  replace_emp_idreplace_empr   Recruitmentrecruitment_queryr  Stagerecruitment_stage_queryr  OnboardingStageonboarding_stage_queryOnboardingTaskonboarding_task_querytasks                        rs   replace_employeer    s    KKOOG$E&&&&1779HFN&&(,,-=rBTX  ($ I	F#L"5J!(!1!1*!=&..555HNNP"88F~5(?(G(G(N(N-3 )O )f+f> & %%m4"&<<F~5"9"/}#K )4(;(;(B(B-3 )C )% )+< NK'<<CCFK'<<@@MN %%m4"&BBF~53"/wE /4mm.B.B'- /C /+ /%< BE!0077?!0044[AB %%l3"&@@F~5&=".6G'O .=-D-D-K-K$* .L .* .%; ?E!--44V<!--11+>? %%l3"&??F~5%<".6F&N -;,B,B,I,I$* -J -) -$9 >D ,,33F; ,,00=> SI	T 335N))!$:";<;<<5,E#E"!$>"?"F"Fx"PQM""ru   c           
      $   | j                   j                  d      }t        j                  j	                  |      j                         }| j                   j                  d      }|rt        d      }nt        d      }|j                   |_        |j                   |j                  _        d}d}|j                  s |j                         }|rd}nt        d	      }|rt|j                          t        j                  | |       d
}|| j                  j                         vr%t        | j                  j                  dd            S t!        d      S t#        | d|j                  d      |j                  d      |j                  d      |d      S )zA
    This method is used to get the manager in records model
    r   r   offboardingr  r|  Tru  Frv  rw  r   r   )<script>window.location.reload()</script>rx  ry  rz  r{  r}  )r   r   rT   r   r~   r   r   r  r   rp  r   r	   r   r   r  r   r   r   )	r   r   r   r  r@  r   rh  r~  r  s	            rs   get_manager_inr  .  sa    ++//-0K&&+&6<<>H++//-0K+,/"%///H.6.@.@*@H'D$G//1D+,G'*gll''))'(8(8(MNN KLL!$"(**-=">(.

3I(J$*JJ/A$B

 
	
ru   c                    | j                   d   }| j                   d   }| j                   j                         }t        | j                         j                  }|dk(  r|j	                  d      }| j                   j                  d      }d}|dk(  rd	}t        | |d
      }t        | |d      }t        |      }t        t        |       t        | |t        ||      ||d      S )z0
    This method is used to search employee
    rN  r  rA  Tr  r   rH  r  rI  r   rJ  )r2  r  r  )r   r  r8   r  r~   r   r&   r)   r   r'   rT   r   r   )r   rN  r  r  r   r  rK  r  s           rs   employee_searchr  [  s     [["F;;vDKK))+Mw{{+..I|$$t$4	++//&)K:Hv~>/4I w	95I'Ih	*!)[9$	
 ru   z$employee.add_employeeworkinformationc                    t         j                  j                  |      }t        |      }t	        | j
                        }t               }t        j                  j                  |      j                         }|t        |j                        }|j                         rH|j                  d      }||_        |j                          t        j                  | t!        d             t#        | d|||d      S )	z
    This method is used to create employee work information from employee single view template
    args:
        obj_id : employee instance id
    r   r   r   Fr   zCreated work informationrV  r6  )rT   r   r   r@   rE   r   r>   rU   r~   r   r  r   r   r   r	   r   r   r   )r   r   r   r   r  r   bank_form_instancer  s           rs   employee_work_info_view_creater    s     ##v#.H*D1',,?I-/I,44;; < eg  %133
	 NN%N0	 (	!$>"?@:IIF ru   c                 |   t         j                  j                  |      }t        |j                        }t        |j                  j                        }t        | j                  |      }|j                         r/|j                          t        j                  | t        d             t        | d|||d      S )z
    This method is used to update employee work information from single view template
    args:
        obj_id  : employee work information id
    r   r   z%Work Information Updated SuccessfullyrV  r6  )rY   r   r   r@   r   r>   r  rE   r   r   r   r	   r   r   r   )r   r   work_informationr   r   r  s         rs   employee_work_info_view_updater    s     /66::f:E!1!=!=>D-!--CCI 2!I !$K"LM:IIF ru   z employee.add_employeebankdetailsc                    t         j                  j                  |      }t        |      }t	        | j
                        }t        j                  j                  |      j                         }t               }|t        |      }|j                         rH|j                  d      }||_        |j                          t        j                  | t        d             t!        | d|||d      S )	z
    This method used to create bank details object from the view template
    args:
        obj_id : employee instance id
    r   r   r   Fr   z!Bank Details Created SuccessfullyrV  r6  )rT   r   r   r@   r>   r   rY   r~   r   rE   r   r   r   r	   r   r   r   )r   r   r   r   r   work_form_instancer  bank_instances           rs   !employee_bank_details_view_creater    s     ##v#.H*D-gll;I088?? @ eg  23I%5?QR	!e4$,!!$G"HI:IIF ru   c                    t         j                  j                  |      }t        |j                        }t        |j                  j                        }t        | j                  |      }|j                         rR|j                  d      }|j                  |_        |j                          t        j                  | t        d             t        | d|||d      S )z>
    This method is used to update employee bank details.
    r   r   Fr   z!Bank Details Updated SuccessfullyrV  r6  )rU   r   r   r@   r   rE   r  r>   r   r   r   r	   r   r   r   )r   r   employee_bank_instancer   r  r   r  s          rs   !employee_bank_details_view_updater    s     188<<<G!7!C!CDD1'33FFI .5I !e4$:$F$F!!$G"HI:IIF ru   z'employee.delete_employeeworkinformationc                    	 t         j                  j                  |      }|j                          t	        j
                  | t        d             t        d      S # t         j                  $ r, t	        j                  | t        d             Y t        d      S t        $ r, t	        j                  | t        d             Y t        d      S w xY w)zy
    This method is used to delete employee work information
    args:
        obj_id : employee work information id
    r   z!Employee work information deletedz$Employee work information not found.z0You cannot delete this Employee work informationz(/employee/employee-work-information-view)rY   r   r   r   r	   r   r   r]  rB  r   r   )r   r   employee_works      rs    employee_work_information_deleter    s    W/77;;v;F!$G"HI >?? #// Kw"H IJ >??  Ww"T UV>??Ws   AA 2C'CCc                    | j                   dk(  r| j                  d   }t        j                  |      }|j	                  d      }g }|D ]  }	 |d   }|d   }|d   }t
        j                  j                  |      j                         }	|	|}
d}d	|v r|j                  d	d
      \  }
}t
        j                  j                  ||t        |      j                         d      }t               }||_        |
|_        ||_        ||_        ||_        |j'                           t-        d      S t        j.                  g d      }t-        d      }d|d<   |j1                  |d       |S # t(        $ r |j+                  |       Y ?w xY w)zH
    This method is used to create employee and corresponding user.
    r   rd  recordsphoner  employee_full_name)usernamerA   r   F)r  r  passwordr	  zz
    <div class='alert-success p-3 border-rounded'>
        Employee data has been imported successfully.
    </div>

    )r  r  r  columnsapplication/ms-excelrZ  z-attachment; filename="employee_template.xlsx"Content-Dispositionr   )r   r7  r  
read_excelto_dictr
   r   r~   r   rK  create_userr   striprT   r   r   employee_last_namer  r  r   r$  r  r   	DataFrameto_excel)r   rd  
data_frameemployee_dicts
error_listemployee_dictr  r  r  existing_userr   r  r   r   r(  s                  rs   employee_importr  	  s    ~~}}V$]]4(
#++I6
+ 	1M1%g.%g.%23G%H" $ 3 3U 3 C I I K (*<')+&00 /44S!</.  <<33!&#!$U!1!1!3%*	 4 D  (zH04H-3FH02DH/%*HN%*HNMMO7	1< 
 	
 &NOJ)?@H&UH"#.O  1!!-01s   CE,,F
	F
c                     t         j                  j                         D cg c]  }|j                  r|j                   }}|j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       t        j                  j                  | }t        j                  t        |      |      }t        d	      }d
|d<   |j                  |d       |S c c}w )=
    This method is used to export employee data to xlsx
    r   r   additional_infois_from_onboardingis_directly_convertedr  r  r  r  +attachment; filename="employee_export.xlsx"r  Fr  )rT   r  
get_fieldsauto_createdrD  r   r   values_listr  r  r  r   r  )r   r  field_namesemployee_datar  r(  s         rs   employee_exportr  K	  s     $,>>#<#<#>Uaann166UKU)*)*()+,./{# $$00+>Md=1;GJ )?@H&SH"#.O% Vs
   DDc                 `    |j                  |       }	 t        |       y# t        $ r |cY S w xY w)z4
    This method is returns None or field value
    N)r   floatr  )r  dictsfield_values      rs   rP   rP   g	  s7     ))E"Kk s    --c                    t        j                  g d      }i dg dg dg dg dg dg d	g d
g dg dg dg dg dg dg dg dg dg g g g g g g g g g g g g d}t        d      }d|d<   |j                  |d       d}| j                  j                  d      dk(  rd}| j                  dk(  r| j                  j                  d      d!}g }g }d}| j                  d   }	|	j                  j                  d"      d#   j                         }
|
d$k(  rt        j                  |	      nt        j                  |	      }|j                  d%      }t        t        j                   j#                  d&d'            }t        t$        j                   j#                  d(d'            }t        t        j                   j#                  d)d*d+            }g }|D ]  }d}	 |d   }|d   }t'        d|      }t'        d|      }|d   }|d   }|d   }t'        d,|      }t'        d-|      }d.}	 t        j(                  |      st+        j,                  ||      sd/|d0<   d}	 t        j.                  |       	 t        j.                  |       t        j(                  |      rd5|d6<   d}t        j(                  |      rd7|d8<   d}|||f}||v rd9|d:<   d}n|j3                  |       	 t        j4                  |      j7                          	 t        j4                  |      j7                          ||v rd>|d?<   d}n|j3                  |       ||v rd@|dA<   d}n|j3                  |       |r|j9                  |       n|j9                  |        |s|s	 tA        |      }tC        |      }tE        jF                  tH        |fB      }|jK                          tM        |      }tO        |       tQ        |       tS        |       tU        |       tW        |       tY        |       t[        |       |ret]        j>                  | dC       t        j                  dDgdEg      }tM        |      } t        d      }dF|d<   |j                  |d       | |dG<   |S |r|D ]D  }!|j_                         D ]/  \  }"}#|"|!v r|#j9                  |!|"          |#j9                  d        1 F |j_                         D "#cg c]  \  }"}#ta        dH |#D              r|" }$}"}#|$D ]  }"||"=  t        j                  ||jc                               }tM        |      } t        d      }dF|d<   |j                  |d       | |dG<   |S te        dI|dJ      S |S #  d}d/|d0<   Y 6xY w# t0        $ r d1|d2<   d}Y 6w xY w# t0        $ r d3|d4<   d}Y 7w xY w#  d;|d<<   d}Y xY w#  d;|d=<   d}Y xY w# t:        $ r"}d}t=        j>                  |       Y d }~0d }~ww xY w# t:        $ r"}d}t=        j>                  |       Y d }~
d }~ww xY wc c}#}"w )KzV
    This method is used to import Employee instances and creates related objects
    )Badge id
First Name	Last NamePhoneEmailGenderr+   Job PositionJob Role	Work TypeShiftEmployee TypeReporting Managerr*   LocationDate joiningContract End DateBasic SalarySalary Hourr  r  r  r  r  r  r  r+   r  r  r  r  r  r  r*   r  r  r  )r  r  Email ErrorFirst Name errorName and Email ErrorPhone errorJoining Date ErrorContract ErrorBadge ID ErrorBasic Salary ErrorSalary Hour ErrorUser ID Errorr  r  z.attachment; filename="work_info_template.xlsx"r  Fr  create_work_infotrueTr   rd  Nr   .r   csvr  r   flatr  r   r  r  r  r  z0^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$zInvalid Email addressr  zBasic Salary must be a numberr  zSalary Hour must be a numberr  zFirst Name can't be emptyr  zPhone Number can't be emptyr  zFAn employee with this first name, last name, and email already exists.r  z5Invalid Date format. Please use the format YYYY-MM-DDr  r  z,An Employee with the badge ID already existsr  z%User with the email ID already existsr  )targetr  zsomething went wrong....z3The provided titles don't match the default titles.zTitle Errorz'attachment; filename="ImportError.xlsx"zX-Error-Countc              3   $   K   | ]  }|d u  
 y wro   rp   )r  vs     rs   	<genexpr>z#work_info_import.<locals>.<genexpr>W
  s     0QqDy0s   zEmployees Imported Succefully)ri  success_count)3r  r  r   r  r   r   r   r7  rD  rK  r^  read_csvr  r  r1  rT   r   r  r
   rP   isnarematch
to_numericr  r   to_datetimer   r  r$  r\   rB  rM   rH   	threadingThreadrR   startr   rG   rJ   rK   rO   rL   rI   rN   r	   r  r   r  r   )%r   r  
error_datar(  r  total_counterror_listssuccess_listserror_occuredrd  rY  work_info_dictsexisting_badge_idsexisting_usernamesexisting_name_emailsusersr  rB  r  r  
first_name	last_namer   date_joiningcontract_end_datebasic_salarysalary_hourpatternname_email_tuplerb  r   threaderror_countr  r  r  keys_to_removes%                                        rs   work_info_importr!  s	  sC    
J.Bb 	R 		
 	 	" 	b 	 	B 	R 	 	 	R 	2 	B  	!" 	R#$  "  ;JB )?@H&VH"#.||*+v5~~GMM$5$5f$=$I}}V$-b1779!/5!8BKKbmmD>Q 	 %,,Y7 !1!1!=!=jt!=!TU !9!9*4!9!PQ"((%';W 

 ( Z	 IEX !'*!'*(yA
'Y?	$Z0(8$-.A$B!*>9E)-CMHwwu~RXXgu-E5J	-0 $
!MM,/
!MM+.
 77:&6OI01 E775>1LIm, E$.	5#A #';;` 45 !E(,,-=>!NN<0557!NN#45::< 11F ./ !E&**84..? o. !E&**51&&y1!((3mZ	 x ; />7F	"))/yl !)n-m</>+M:&}5"=1*=9,]; NN7$>?FG&J
 k*K#1GHH.WH*+6(3H_%O# +","2"2"4 +JCd{T#Y/T*	++ #-"2"2"4C0%00 N  & $sO$j*//:KLJk*K#1GHH.WH*+6(3H_%O:!,
 	
 O]H E1FIm, " !8UI23 E! " !7SI12 E!.!O 23 !E!O ./ !E.    $Q ,    $Q 6s   AW'2VV0V)AW #W #W'AWBX -X:	VWV&"W%V&&W)V=9W<V==W 	W	W	WW	X	'XX		X7X22X7c                     | j                   j                  d      r"t               t               d}t	        | d|      S i }g }t               }t        | j
                        j                  }t        | |d      }| j
                  j                  d      }|si|j                  d   j                  }| j
                  j                  d      }t        j                  |      }t        j                  j                  |      }t         D ]$  }	|	d   }
|	d	   }|
|v s|j#                  |
|f       & |D ]  \  }}|j%                  d
      }g ||<   |D ]q  }|}
|D ]  }t'        |
|d      }
|
 n |
t)        |
      nd}t+        |
      t,        k(  r| j.                  }|j0                  }t2        j                  j                  |      }|j5                         rT|D ]  }|j6                  } t8        j                  j                        }|j;                         }|r|j<                  nd}nd}t?        j@                  t)        |
      d      j-                         }tC        jD                         D ]  \  }}||k(  s|jG                  |      } |dk(  rtI        d      }n|dk(  rtI        d      }||   j#                  |       t  tK        jL                  |      }tO        d      }d|d<   |jQ                  |d       |S )r  rw  )export_filterexport_formzemployee_export_filter.htmlr   selected_fieldsrz  r   r   r   r  NrA  r   )r  zMMM. D, YYYYz%Y-%m-%drl  YesrG  Nor7  r  r  r  r  Fr  ))r   r   r8   r?   r   r   r  r&   r3  r  r<  r   r  rT   r   r~   rF   r  rK  getattrr   r  r   r   r   rY   r   r  r*   r   date_formatr   strptimerc   r  strftimer   r  r  r   r  )r   r   employees_dataselected_columnsr   r   r%  rz  id_listr  r  r  column_valuecolumn_namenested_attributesr   attrr2  r   r  r  r  employee_companycompany_nameemp_companyr)  
start_dateformat_nameformat_stringr  r(  s                                  rs   work_info_exportr9  n
  s    ||)*+-24
 g<gFFN"$Dw{{+..I/4I kk))*;<O++&78@@kkooe$**S/$$++7+;	 2aAhO###UCL1	2
 &6 )5!k(..t4&({#! &	5HE) tT2= "'!23u:DE{d"||'' /66==#=N;;=! 8+,<<(8#*??#9#9BR#9#SL"."4"4"6K 4?//N   #1K%..s5z:FKKM
 3G2L2L2N B.K"k1)22=AB v~xw;'..t4M&	5)5V >2J)?@H&SH"#.Oru   c                     t        j                         j                         } t        j                  | j
                  | j                        d   }t        j                  j                  d| j                  | j                  |      j                  t        d      j                  d            }|D ]*  }|j                  j                  | j                  z
  |_        , |S )zP
    This method is used to find upcoming birthday and returns the queryset
    r   T)r  dob__day__gte
dob__monthdob__day__ltedob__day)
nulls_last)r   r   r   calendar
monthrangeyearmonthrT   r   r~   dayr  r   ascdobdays_until_birthday)r   last_day_of_monthr   r   s       rs   birthdayrI  
  s     LLN!E ++EJJDQG  ''ii;;'	 ( 
 hq}  D 12   D'/||'7'7%))'C$Dru   c           
      p   t               }d}|D cg c]  }t        |d      r|j                         n| |j                   d|j                   |j                   d|j                   |j
                  j                  d      |j                  dk(  rt        d      n)|j                  dk(  rt        d	      nd
|j                   d|j                         r|j                         j                  nd|j                         r|j                         j                  ndd }}t        | dd|i      S c c}w )zJ
    Render all upcoming birthday employee details for the dashboard.
    z3https://ui-avatars.com/api/?background=random&name=
get_avatar+r  z%d %b %Yr   Todayr   TomorrowzIn z DaysrA  )profilerD  rF  daysUntilBirthday
departmentjob_positionzbirthdays_container.html	birthdays)rI  hasattrrK  r   r  rF  r+  rG  r   get_departmentrQ  get_job_positionrR  r   )r   r   default_avatar_urlr  rS  s        rs   get_employees_birthdayrX  
  s=   
 
IN4 32 + 3-  *+C,C,C+DAcF\F\E]^../q1G1G0HI77##J/ **a/ '
 ..!3 jMs667u= 473E3E3G""$//R 8;7K7K7M$$&33SU+	
I 6 '5Y7OPP7s   DD3c                    t               }t        j                  j                         }t	        | |d      }|j                  d      }|j                  d      }d}d}|j                         r8t        |      t        |      z  dz  d}t        |      t        |      z  dz  d}t        | d|t        |      t        |      t        |      ||d	      S )
zP
    This method is used to render individual dashboard for employee module
    r   Tr  Fr   d   z.1fz*employee/dashboard/dashboard_employee.html)rS  active_employeesinactive_employeestotal_employeesactive_ratioinactive_ratio)	rI  rT   r   r   r%   r~   r   r   r   )r   upcoming_birthdaysr   r[  r\  r^  r_  s          rs   	dashboardra  
  s     "  $$&I"7I7OPI ''$'7"))E):LN/03y>ASHM !34s9~ELSQ4+ #$4 5"%&8"9"9~(,	
 ru   c                 p    t         j                  j                         j                         }t	        |      S ro   )rT   r   r~   rq  r   )r   r   s     rs   total_employees_countrc    s*      '')//1I	""ru   c                    d}t        j                  d      rkt        dd      }|j                  j	                  t        j                         t        j                         t        d      z   gd      j                         }t        |      S )	Nr   r  	candidater  r   daysT)joining_date__ranger  )
r   r   rd   r   r~   r   r   r   rq  r   )r   newbies_today	Candidates      rs   joining_today_countrk    sv    M'+m;W	!))00!%tzz|iQ>O/O P 1 
 %' 	 &&ru   c           	         d}t        j                  d      rt        dd      }|j                  j	                  t        j                         t        t        j                         j                               z
  t        j                         t        dt        j                         j                         z
        z   gdd      j                         }t        |      S )	Nr   r  re  r  rf     T)rh  r  hired)r   r   rd   r   r~   r   r   r   weekdayrq  r   )r   newbies_weekrj  s      rs   joining_week_countrq  '  s    L'+m;W	 ((//

ydjjl.B.B.DEE

ya$**,2F2F2H.HII!  0 
 %' 	 %%ru   c                    t        d      t        d      g}t        j                  j                         }t        d      t	        |j                  d            t	        |j                  d            gdg|d}t        |      S )	z1
    Active and in-active employee dashboard
    Activez	In-Active	EmployeesTr  Fr@  r2  dataSetr  r   rT   r   r~   r   r   r   r  r   r(  s       rs   dashboard_employeerz  7  s     	
(	+F   '')I ;	((4(89	((5(9:
 H !!ru   c                 X   t        d      t        d      t        d      g}t        j                  j                  d      }t        d      t	        |j                  d            t	        |j                  d	            t	        |j                  d
            gdg|d}t        |      S )zA
    This method is used to filter out gender vise employees
    MaleFemaleOtherTr  rt  male)genderfemaleotherru  rv  rx  ry  s       rs   dashboard_employee_genderr  P  s    
 i8aj1F  ''$'7I
 ;	(((78	(((9:	(((89	
 H !!ru   c           	         g }g }t         j                  j                         }|D ]  }t        t        j                  j                  |d            s.|j                  |j                         |j                  t        t        j                  j                  |d                    d|dg|t        d      d}t        |      S )z]
    This method is used to find the count of employees corresponding to the departments
    T)-employee_work_info__department_id__departmentr  r+   ru  zNo Data Found...)rw  r  rh  )
r+   r   r   r   rT   r~   r  rQ  r   r   )r   r  rq  departmentsdeptr(  s         rs   dashboard_employee_departmentr  h  s    
 FE$$((*K ##>Bd $ 

 MM$//*LL$$++FJ"& ,   +E:;'(H
 !!ru   c                     t        | j                        j                  j                  dd      }t	        dt        |      i      S )zD
    This method is used to return all the ids of the employees
    r   Tr  rz  )r8   r   r  r  r   r  )r   rz  s     rs   widget_filterr    s<    
 
%
(
(
4
4T
4
ECS	*++ru   c                 P   | j                   j                  d      }t        j                  j	                         }|dk(  r t        j                  j	                  d      }|D cg c]  }t        |j                         }}|j                         }||d}t        |d      S c c}w )z^
    This method is used to return all the id of the employees to select the employee row
    r   r   Tr  employee_idsr  F)safe)	r   r   rT   r   r~   r   r   rq  r   )r   r  r   r  r  r  r   s          rs   employee_selectr    s    
 ++//&)K  '')Ie$$++d+;	+45CCK5L5//#K+KHGe,, 6s   #B#c                 h   | j                   j                  d      }|dk(  rt        | j                   t        j                  j                               }t        | |j                  d      }|D cg c]  }t        |j                         }}|j                         }||d}t        |      S yc c}w )zM
    This method is used to return all the ids of the filtered employees
    r   r   r  r   )r   r  r   r  N)r   r   r8   rT   r   r~   r&   r  r   r   rq  r   )r   r  employee_filterr   r  r  r  r   s           rs   employee_select_filterr    s     ++//&)Ke(KK("2"2"9"9";

 =o&8&8?W
 0BBCFFBB(..0#/LG$$  Cs   0B/zemployee.view_employeenote)r   c                     t         j                  j                  |      }t        j                  j	                  |      j                  d      }t        | d||d      S )a  
    This function is used to view note tab of an employee in employee individual
    & profile view.

    Parameters:
    request (HttpRequest): The HTTP request object.
    emp_id (int): The id of the employee.

    Returns: return note-tab template

    r   r   z-idztabs/note_tab.html)r   notes)rT   r   r   rW   r~   r  r   )r   r   employee_objr  s       rs   note_tabr    s\     ##''6'2L  ''F';DDUKE!E2 ru   zemployee.add_employeenotec                 x   t        d|i      }| j                  dk(  rt        | j                  | j                        }|j	                         r|j                  d      \  }}t        j                  j                  |      }||_	        | j                  j                  |_        |j                          |j                  j                  |       t        j                   | t#        d             t%        | dd	|i      }t'        d
|       S t        j                  j                  |      }t%        | d||d      S )zH
    This method renders template component to add candidate remark
    r   r;  r   Fr   r   zNote added successfully..ztabs/add_note.htmlr   /employee/note-tab/)r   r   )rB   r   r   r7  r   r   rT   r   r   r   r   r   
updated_by
note_filesr1  r	   r   r   r   r   )r   r   r   noteattachment_idsr   r(  r  s           rs   add_noter    s    ]F$;<D~~LLMM

 ==?#'99E9#: D.''++v+6H'D%ll77DOIIKOO/Wa(C&DEg';fd^LH1&:;;##''6'2L$	
 ru   zemployee.change_employeenotec                    t         j                  j                  |      }t        |      }| j                  rt        | j                  |      }|j                         re|j                          t        j                  | t        d             t        | dd|i      }t        |j                  j                  d      dz         S t        | dd|i      S )z^
    This method is used to update the note
    Args:
        id : stage note instance id
    r   r   zNote updated successfully...ztabs/update_note.htmlr   r"  r#  )rW   r   r   rB   r   r   r   r	   r   r   r   r   r%  r&  )r   note_idr  r   r(  s        rs   employee_note_updater    s     ##w#/DT*D||t<==?IIKWa(F&GH'H
    ''03XX  D	
 ru   zemployee.delete_employeenotec                     t         j                  j                  |      }|j                          t	        j
                  | t        d             t               S )z^
    This method is used to delete the note
    Args:
        id : stage note instance id
    r   zNote deleted successfully.)rW   r   r   r   r	   r   r   r   )r   r  r  s      rs   employee_note_deleter    sD     ##w#/DKKMWa <=>>ru   zemployee.add_notefilesc                    t         j                  j                  |      }|j                  j                  }| j
                  dk(  r| j                  j                  d      }g }|D ]b  }t        j                  j                  |      }|j                  |j                         |j                  j                  |j                         d t        d|       S )zs
    This method is used to Add more files to the Employee note.
    Args:
        id : stage note instance id
    r   r   files)r  r  )rW   r   r   r   r   r   r7  r3  rZ   creater  r  r   r   )r   r  r  r   r  	files_idsrd  r   s           rs   add_more_employee_filesr  )  s     ##w#/D""%%K~~%%g.	 	-D ((//d/;HX[[)OO,		-
 )+788ru   zemployee.delete_notefilesc                 v    t         j                  j                  |      }|j                          t	               S )zi
    This method is used to delete the stage note file
    Args:
        id : stage file instance id
    r   )rZ   r   r   r   r   )r   note_file_idrd  s      rs   delete_employee_note_filer  ?  s.       L 1DKKM>ru   zemployee.view_bonuspointc                 j   t         j                  j                  |      }t        j                  j                  |      }t	        j
                  d      r,t        dd      }|j                  j                  |dd      }nt               j                         }|j                         }g }|D ]  }|j                  |d	   |d
   d   j                  |d
   d   j                  |d
   d   j                  z
  t        t        j                  j                  |d
   d   j                         j#                         dd      |d
   d   j$                  d        |D ]7  }	|j                  d|	j&                  |	j(                  |j*                  dd       9 t-        |d d      }|||d}
t/        | d|
      S )a  
    This function is used to view Bonus Points tab of an employee in employee individual
    & profile view.

    Parameters:
    request (HttpRequest): The HTTP request object.
    emp_id (int): The id of the employee.

    Returns: return bonus_points template

    r   r   r   reimbursementr  bonus_encashment	requested)r   r  rr  r  pairr   r   r   N)r  r   pointsr   r~  zRedeemed pointsc                     | d   S )Nr   rp   )xs    rs   r   z"bonus_points_tab.<locals>.<lambda>  s
    &	 ru   T)r  r   )r   r  activity_listztabs/bonus_points.html)rT   r   r   rS   r   r   rd   r~   r   nonetrackingr  history_dater  r(  r
   history_user_idr   r~  
created_atbonus_to_encashr   sortedr   )r   r   r  r  Reimbursementrequested_bonus_points	trackingsr  historyr  r   s              rs   bonus_points_tabr  M  s    ##''6'2L###7F#/
 "/!6!6!=!=%7 "> "
 "*!2!IM 
*77!&/!,33gfoa6H6O6OOLL''76?1+=+M+M'NTTV"
 "&/!,33
	

 , 	
	#!,,#33$55+	
	
 =.A4PM &G
   ru   zemployee.add_bonuspointc                 d   t         j                  j                  |      }t               }| j                  dk(  rt        | j
                  | j                        }|j                         r|j                  d       |xj                  |j                  d   z  c_	        |j                  d   |_        |j                          t        j                  | t        d      j                  |j                  d                t!        | j"                  j                  dd	            S t%        | d
||d      S )z
    This function is used to add bonus points to an employee

    Args:
        request (HttpRequest): The HTTP request object.
        emp_id (int): The id of the employee.

    Returns: returns add_points form
    r   r   Fr   r  r~  z$Added {} points to the bonus accountr   r   ztabs/forms/add_points.htmlr=  )rS   r   r   r:   r   r   r7  r   r   r  cleaned_datar~  r	   r   r   r  r   r   r   )r   r   bonus_pointr   s       rs   add_bonus_pointsr    s    $$((V(<KD~~ LLMM
 ==?IIUI#$"3"3H"==!%!2!28!<K89@@%%h/ ((8(8(MNN$	
 ru   c                    t         j                  j                  |      }d}t        j                  j	                  |      j                         r8t        j                  j	                  |      j                         j                  }t        d|i      }||j                  _
        d}t        j                  d      rMt        dd      }|j                  j                         r$|j                  j                         j                  nd	}| j                  d
k(  rt        | j                         }||j                  _
        |j#                         r|j%                  d       |j&                  d   }||z  }t        j                  d      rJt        dd      }	|	j                  j)                  d| d|||| d| dt+        j,                                t/        d      S t1        | d||d      S )z
    This function is used to redeem bonus points for an employee

    Args:
        request (HttpRequest): The HTTP request object.
        emp_id (int): The id of the employee.

    Returns: returns redeem_points_form form
    r   r   r   r  r;  r   encashmentgeneralsettingsr  r   r   Fr   r  zBonus point Redeem for r  z want to redeem z points)r@  r  r   r  amountdescriptionallowance_onr)  z"tabs/forms/redeem_points_form.html)r   r   )rT   r   r   rS   r~   r   r   r  r;   r   r   r   r   rd   bonus_amountr   r   r   r   r  r  r   r   r   r   )
r   r   r   avialable_pointsr   amount_for_bonus_pointEncashmentGeneralSettingsr  r  r  s
             rs   redeem_pointsr    s    ##v#.H  X 6==?%%(%;AACJJ 	  3C(DED (DMM#$;'B%
!
 )00668 &--335BB 	
 ~~#GLL1$,!==?IIUI#&&x0F+f4F  + 7'! %%,,3H:>+ ($*!#+*,<VHG L!% -    LMM, 	
 ru   c                   	
 | j                   j                  d      }| j                  j                  d      dk(  r5|dk7  r0t        j                  j                  d|      j                         }n.t        j                  j                  d      j                         }|D ci c]  }|j                  |j                          c}g 
	
fd	| j                   j                  d      }| j                  j                  d      dk(  r5|dk7  r0t        j                  j                  d|      j                         }n.t        j                  j                  d      j                         }| j                  j                  }t        |      d	k(  ri }n|d	   j                  t        d
      i}| j                  dk(  r| j                  j                  d      rDt        | j                  j                  d            }t        j                  j                  |      }|j                         t!        |j#                         dt        d             	|      d}d|i}t%        | d|      S |j                         t!        |j#                         dt        d             	|      d}|||j                  d}t%        | d|      S c c}w )z7
    This method is used to view oganisation chart
    r  r  Nr   F)reporting_manager__isnullr  )r  c                 |   g }| j                   j                         v rj                  |        t        j                  j                  |       j                  | j                         }|D ]  }|v r|j                   j                         v r]|j                  |j                         t        |j                         dt        d             |      d       j                  |       |j                  |j                         t        |j                         dt        d            d |      d        |S )z,
        Hierarchy generator method
        )(employee_work_info__reporting_manager_idr   rR  Not setrD  r@  childrenzmiddle-level)rD  r@  	classNamer  )r   r  r  rT   r   r~   r  get_full_namer(  rV  r   )managernodessubordinatesr   create_hierarchyentered_req_managersresult_dicts       rs   r  z,organisation_chart.<locals>.create_hierarchy  s4    ::))++ ''0''..5< / 

'WZZ'
  	
 % 	H// {{k..00 ( 6 6 8!($5579" %5X$> %++H5  ( 6 6 8!($5579" &4$4X$>	%	8 ru   r   zMy viewr   
manager_idr   rR  r  r  act_datasourcezorganisation_chart/chart.htmlr  )r  reporting_manager_dictact_manager_idz!organisation_chart/org_chart.html)r   r   r   rT   r   r~   distinctr   r  r   r   r   r   r   r   r  r(  rV  r   )r   r  reporting_managersr  r  new_dictr  noder   r  r  r  s            @@@rs   organisation_chartr    s   
 **+=>89TA%%--44&++; 5 
 (* 	
 &--44&+ 5 

(* 	
 >PPT477D..00PK*X **+=>89TA%%--44&++; 5 
 (* 	
 &--44&+ 5 

(* 	 ll''G
!#&q),,a	lJkJ~~<<L)W\\--l;<J&&**j*9G))+W5579V(1

 $T*g>PP %%'113^Qy\R$W-D "*!**G
 '>PP{ Qs   $"Kz%payroll.add_encashmentgeneralsettingsc                    t        j                  d      rddlm} t	        dd      }t        j                  d      r|j
                  j                         nt               j                         }| j                  dk(  rx || j                  |      }|j                         r]|j                          t        j                  | t        d             t!        | j"                  j%                  d	d
            S  ||      }t'        | dd|i      S t        j(                  | t        d             t!        | j"                  j%                  d	d
            S )zJ
    Handle the creation and updating of encashment general settings.
    r   r   )EncashmentGeneralSettingsFormr  r  r   r   zSettings updated.r   r   z!settings/encashment_settings.htmlencashment_formzPayroll app not installed)r   r   payroll.forms.formsr  rd   r   r   r   r  r   r   r   r   r	   r   r   r   r   r   r   r  )r   r  r  r   r  s        rs   encashment_condition_creater  k  s!    #E$;'B%
!
   + &--335" 	 >>V#;xO '')$$&  !,?*@A+GLL,<,<^S,QRR;XNO/0
 	
 Wa ;<= 0 0 EFFru   z#employee.add_employeegeneralsettingc                    t         j                  j                         }|s
t               }| j                  dk(  rt	        | j
                  |      }|j                         rK|j                          t        j                  | d       t        | j                  j                  dd            S t        j                  | d       nt	        |      }t        | dd|i      S )	zE
    This method is used to set the initial prefix using a form.
    r   r   z$Initial prefix updated successfully.r   r   z'There was an error updating the prefix.zsettings/settings.htmlprefix_form)rV   r   r   r   rA   r   r   r   r	   r   r   r   r   rB  r   )r   r   r   s      rs   initial_prefixr    s     &--335H)+~~/xP==?IIKW&LM'(8(8(MNNNN7$MN/B'3mT5JKKru   c                 4    t               }t        | dd|i      S )zV
    This method is used to return the first last badge ids in grouped and ordere
    z,employee_personal_info/first_last_badge.html	badge_ids)rQ   r   )r   r  s     rs   first_last_badger    s'     &'I6	i  ru   c                    | j                   d   }t        j                  j                  |      }t        j                  j                  |j                        }|j                  rM|j                  j                  r7|t        j                  j                  |j                  j                        z  }|j                  d      }t        | dd|i      S )zG
    This method is used to track mails sent along with the status
    r   r   )to__icontainsz-created_atztabs/mail_log.htmltracked_mails)
r   rT   r   r   r,   r~   r  r  r  r   )r   r   r   r  s       rs   employee_get_mail_logr    s     ++h'K##{#3H$$++(..+IM""x'B'B'H'H%(8(8(?(?"55;; )@ )
 
 "**=9M'//=1QRRru   c                     | j                   j                  d      }|r0t        j                  j	                  |      j                  dd      ng }t        dt        |      i      S )Nr  )r  r   rR  job_positions)r   r   r/   r   r~   r  r   dict)r   r  r  s      rs   get_job_positionsr    sc    KKOOO4M
  	"""?KK.	
   $}*=>??ru   c                     | j                   j                  d      }t        j                  j	                  |      j                  dd      }t        dt        |      i      S )a  
    Retrieve job roles associated with a specific job position.

    This view function extracts the job_id from the GET request, queries the
    JobRole model for job roles that match the provided job_position_id, and
    returns the results as a JSON response.
    job_id)r  r   job_role	job_roles)r   r   r0   r   r~   r  r   r  )r   r  r  s      rs   get_job_rolesr    sS     [[__X&F&&v&>JJjI d9o677ru   zemployee.view_employeetagc                 \    t         j                  j                         }t        | dd|i      S )z.
    This method is used to Employee tags
    zbase/tags/employee_tags.htmlemployeetags)rX   r   r   r   )r   r  s     rs   employee_tag_viewr     s3     &&**,L&	& ru   zemployee.add_employeetagc                    t               }| j                  dk(  r^t        | j                        }|j                         r9|j	                          t               }t        j                  | t        d             t        | dd|i      S )E
    This method renders form and template to create Ticket type
    r   z"Tag has been created successfully!(base/employee_tag/employee_tag_form.htmlr   )	rC   r   r   r   r   r	   r   r   r   )r   r   s     rs   employee_tag_creater    ss     D~~w||,==?IIK"$DWa(L&MN2D	
 ru   c                 n   t         j                  j                  |      }t        |      }| j                  dk(  rkt        | j
                  |      }|j                         rD|j                          t               }t        j                  | t        d             t        d      S t        | d||d      S )r  r   r   r   z"Tag has been updated successfully!r  r  )r   tag_id)rX   r   r   rC   r   r   r   r   r	   r   r   r   r   )r   r  tagr   s       rs   employee_tag_updater    s     


!
!V
!
,CC(D~~w||c:==?IIK"$DWa(L&MN KLL2( ru   ro   (   __doc__r   r@  r   operatorr\  r  r	  r   r   r   urllib.parser   pandasr  django.appsr   django.confr   django.contribr	   django.contrib.auth.modelsr
   django.core.cacher   	django.dbr   r   django.db.modelsr   r   django.db.models.queryr   django.formsr   r   django.httpr   r   r   r   django.shortcutsr   r   r   django.urlsr   django.utilsr   django.utils.translationr   r  r   r   django.views.decorators.httpr   accessibility.decoratorsr   accessibility.methodsr    accessibility.middlewaresr!   accessibility.modelsr"   
base.formsr#   base.methodsr$   r%   r&   r'   r(   r)   base.modelsr*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   employee.filtersr7   r8   r9   employee.formsr:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   employee.methods.methodsrG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   employee.modelsrS   rT   rU   rV   rW   rX   rY   rZ   horilla.decoratorsr[   r\   r]   r^   r_   r`   horilla.filtersra   horilla.group_byrb   horilla.horilla_settingsrc   horilla.methodsrd   horilla_audit.modelsre   rf   horilla_documents.formsrg   rh   ri   rj   horilla_documents.modelsrk   rl   notifications.signalsrm   rt   eqnerx   ry   rz   r{   containsoperator_mappingfilter_mappingr   r   r   r   r   r   r   r  r  r  r,  r5  r8  r>  rE  rQ  rU  re  r_  rs  rx  r|  r  r  r  r  r   r  r  r  r
  r  r  r)  r+  r2  r4  rA  rC  rE  rL  rS  r  rW  rf  rj  rs  r  r  r  r  r  r  r  r  r  r  r  r!  r9  rI  rX  ra  rc  rk  rq  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  rp   ru   rs   <module>r5     s#       	 	  . . !     # + # ) . + * S S @ @  ! 2 6 = 8 E C 5       T S      	 	 	  - . 9 3 K  ? (
 [[
++
++
++
++""	  	 
 	 
 	 
 	 
->/ : :  $ 	#%	 
%PG, $	!#
D DN   ( /:"C ;  "CJ <=P > PB <= >  < ;<' =  'T >? @  > 2H=F >  F. 18<S =  S4  ( -F  -F` &L  &LR !@  !@HI, 34F 5  F, 34 5  B 34# 5 #& 34# 5 #" vhB   B ,-2 . 2  ^$vhA   % A 	!#
( (V /0T+ 1 T+n /0:: 1 ::z /0= 1 =: ,- .  -.d / dN vh/0 1   * vh   $ xj!/0 1 " < xj! " < -.vh1I   / 1Ih <=vh I   >  IF 89vhI   : I> 	!#
+  +\ +,!  - !H +,!  - !H +, -  : /0vh"S   1 "SJ /00 1 0< /0vh!0   1 !0H /00
 1  0
f /0Y# 1 Y#x -.(
 / (
V 	!#
 > 9:vh   ; B <=vh   > 4 56vh   7 6 89vh   : 0 >?vx()@ * @ @$ ,-7 . 7t ,- . 4	 ,-v . vr +,L - L^$ !Q !QH +, - : # #
 ' ' & & " "0 " ". " "< , , - -" +,% - %, 45 6  , 34 5  D 67 8 @ 67
 8 
 019 2  9& 34 5   +X6; 7  ;| 12& 3 &R +X69 7 9x pQ pQf <="G > "GJ :;L < L, +,
 - 
 +,S -  S  	@ 	@ 8 8 01	 2 	 /0 1  ( /0 1  ru   