
    si(             
          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mZmZm	Z	 ddl
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 ddlmZ ddlmZm Z  ddl!m"Z" ddl#m$Z$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l0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z8 ddl6m9Z: ddl;m<Z< ddl=m>Z> ddl?m@Z@ ddlAmBZB ddlCmDZD ddlEmFZF ddlGmHZHmIZImJZJmKZKmLZLmMZM ddlNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZW ddlXmYZY dd lZm[Z[m\Z\m]Z] dd!l^m_Z_m`Z`maZambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkmlZl dd"lmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZumvZvmwZwmxZxmyZymzZzm{Z{ dd#l|m}Z}m~Z~mZmZmZmZmZmZ dd$lmZmZmZmZmZmZ dd%lmZ dd&lmZ dd'lmZ dd(lmZmZ dd)lmZmZ dd*lmZmZmZmZ dd+lmZmZ dd,lmZ d- ZejF                  ejH                  ejJ                  ejL                  ejN                  ejP                  ejR                  ed.Zd/d0 id/d1 id/d2 id/d3 id4Zd5 Zed6        Ze e>d7d89      d:               Zd; Ze e>d<d=e>      d?               Zeed@               ZeedA               Zee edBe~      dC                      Ze edD      dE               ZdFee+   dGee+eeeee   f   f   fdHZee edD      dI                      Zee edJ      dK                      Zee edL      dM                      Zee edNe~      dO                      Zee edPe~      dQ                      ZdR ZedS        ZeedT               ZeedU               ZeedV               ZdW Zee edP      dX                      Zee edP      dY                      Ze edP      dZ               Ze edP      d[               Ze e<d\g      d]               Ze ed^      d_               Ze ed`       e<d\g      da                      Zdb Ze e>dcd=e>      dd               Ze ed8      de               Ze ed8      df               Ze ed8      dg               Ze edh      di               Ze ed8      dj               Ze e<d\g       ed8      dk                      Ze e<d\g      dl               Ze e<dmg       ed8      dn                      Ze e<dmg      do               Ze ed8       e<d\g      ddp                     Ze edq       e<d\g      ddr                     Ze eds       e<d\g      ddt                     Ze ed8       e<d\g      ddu                     Zee e>dcd=e>      dv                      Ze ed=      edw                      Ze ed=      edx                      Zee ed=      dy                      Ze edz       e<d\g      d{                      Ze edz      d|               Ze edz       e<d\g      d}                      Zee edz      d~                      Ze ed8      d               Ze ed=      d               Ze e>dcd=e>      d               Ze ed       e<d\g      d                      Ze edq       e<d\g      d                      Ze ed       e<d\g      d                      Ze eds       e<d\g      d                      Ze ed       e<d\dmg      d                      Ze edh      d               Ze edh      d               Zd Ze edh      d               Zee edh      d                      Ze ed=      d               Zd Ze e>dd=9      d               Ze ed=      d               Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Ze ed=      d               Zee ed      d                      Zd Zee ed      dd                     Ze ed      d               Z e ed      d               Zee ed      d                      Zee ed      d                      Zee ede~      d                      Ze ed      d               Ze ede~      d               Zed        Ze ed      d               Ze ed      d               Z	e ed=      d               Z
ee ed=      d                      Zed        Zed        Zed        Zed        Zed        Ze ed      d               Zee ed      d                      Zee ed      d                      Zy)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)Optional)parse_qs)apps)settings)messages)User)cache)ObjectDoesNotExist)models)FProtectedError)QuerySet)	DateInputHiddenInputSelect)HttpResponseHttpResponseRedirectJsonResponse	QueryDict)get_object_or_404redirectrender)render_to_string)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JobPositionJobRoleRotatingShiftAssignRotatingWorkTypeAssignShiftRequestWorkTypeRequest)generate_error_report)DocumentRequestFilterEmployeeFilterEmployeeReGroup)BonusPointAddFormBonusPointRedeemFormBulkUpdateFieldFormEmployeeBankDetailsFormEmployeeBankDetailsUpdateFormEmployeeExportExcelFormEmployeeForm EmployeeGeneralSettingPrefixFormEmployeeNoteFormEmployeeTagFormEmployeeWorkInformationForm!EmployeeWorkInformationUpdateFormUserLoginDetailsForm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error_data_templateget_ordered_badge_idsprocess_employee_recordsset_initial_passwordvalid_import_file_headers)
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)dynamic_attrget_horilla_model_class)AccountBlockUnblockHistoryTrackingFields)DocumentFormDocumentRejectFormDocumentRequestFormDocumentUpdateForm)DocumentDocumentRequest)notifyc                      y N )abs     2/var/www/python-projects/worksol/employee/views.pyreturn_nonerx      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     rw   <lambda>r      s    # ) 6 6 9 9$(/
 ry   c                 6    | |j                   j                  ddS )NT)r   shift_id__idr   )shift_idr   r   s     rw   r   r      s    #%..11$(0
 ry   c                     | dddS )NT)r   attendance_overtime_approver   rt   r   s     rw   r   r      s    #+/$(/
 ry   c                     | ddS )NT)r   r   rt   r   s     rw   r   r      s    #$(/
 ry   )r   r   overtime
attendancec                 n   |j                  d      rw|d   }t        j                  j                  |      }d }|j                  j                  d k7  r|j                  j                  }| j
                  j                  }|d k7  r||k(  S y| j
                  j                  j                  j                         S )Nobj_idr   F)	getrW   objectsemployee_work_inforeporting_manager_iduseremployee_getreporting_managerexists)requestargskwargsr   emp
re_managerr   s          rw   _check_reporting_managerr      s    zz(!""f"-
!!66$>//DDJ<<,,))<<$$66==??ry   c           	         | j                   j                  }| j                  j                  d      }|dk7  r[t	        t	        t	        |dd      dd      dd      }t        |      t        |      k7  r!t        j                  | d       t        d      S t        j                         }t        j                         }t        | d	|||d
      S )z>
    This method is used to view own profile of employee.
    selected_companyallr   N
company_idr   0Employee is not working in the selected company.employee-viewz"employee/profile/profile_view.html)r   current_datenow)r   r   sessionr   getattrstrr
   errorr   r   todayr   r   r   )r   r   r   r   r   r   s         rw   employee_profiler      s    
 ||((H**+=>5 GH&:DA<QUV

 z?c"233NN7$VWO,,NNE
,,.C, !	
 ry   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   rW   r   r   firstbadge_idr=   rX   r@   POSTr   is_validsaver   r
   success_r   r   )r   r   r   r   r   r   r   s          rw   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'"	
 ry   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   rW   	employeesr   removeaddr$   r   r   r   deleter#   r   META)r   emp_idr   accessibilityr   r   user_cache_keys          rw   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Fry   employee_detailed_viewemployee.view_employee)r   r   methodc                    	 t         j                  j                  |      }t        | d      S # t        $ r 	 t         j                  j	                         j                  |      }t        t        |dd      dd      }t        |dd      }|| j                  d   k7  r#t        j                  | d       t        d      cY S n&# t        $ r}t        | d	d
      cY d}~cY S d}~ww xY wY w xY w)=
    This method is used to view profile of an employee.
    r   r   Nr   pkr   r   r   z404.htmli  statuszemployee/view/individual.html)rW   r   r   r   entirer   r   r
   r   r   	Exceptionr   )r   r   r   r   companyr   es          rw   employee_view_individualr   %  s    ;##''6'2@ '   ;	;''..0444?H"6=|TG !$5JW__-?@@O  00	 A
  	;':c::	; A;sE    . 	C*BC=C* C*	C$
CC$C*C$$C*)C*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   payrollNleaveztabs/personal_tab.html)r   employee_leaves	contracts)	rW   r   r   r   is_installedcontract_setr   available_leaver   )r   r   r   r   r   r   s         rw   	about_tabr   w  s     ##r#*H/3/@/@/K%%))+QUI*.*;*;G*D  $$&$    ."	
 ry   c                    t         j                  j                  |      }t        j                  d      r*|j
                  j                  d      j                         nd}|r|j                  nd}g }g }|rt        dd      }|j                  j                  |      }|j                  j                  d	
      j                  |      }	|j                  j                  d	      j                  |      }
||	z  |
z  }|D ]  }|j                  r|j                  }|j                  }|j                  j                         j!                  dd      }t#        ||      }t$        j                  |      }|= t'        |      |      } |||      r#|j)                  |       n|j)                  |       |D ]Y  }t$        j                  |j*                        }|j,                  dk(  r|nd} |||j.                        rI|j1                  |       [  t        dd      }|j                  j                  |d	d      }|j                  j                  d	d	d      j                  |      }|j                  j                  d	d	d      j                  |      }||z  |z  }t3        t5        |            }|D ]  }|j                  s|j                  }|j                  }|j                  j                         j!                  dd      }t#        ||      }t$        j                  |      }| || t'        |      |            r||j1                  |        |r-t7        j8                  |D cg c]  }|j:                   c}      nd}|r-t7        j8                  |D cg c]  }|j:                   c}      nd}|||r|nd||r|nd||d}t=        | d|      S c c}w c c}w )a  
    Retrieve and render the allowances and deductions applicable to an employee.

    This view function retrieves the active contract, basic pay, allowances, and
    deductions for a specified employee. It filters allowances and deductions
    based on various conditions, including specific employee assignments and
    condition-based rules. The results are then rendered in the allowance and
    deduction tab template.
    r   r   active)contract_statusNr   	app_labelmodel)specific_employeesT)is_condition_based)exclude_employees)include_active_employees r   	basic_payr   	deductionF)r   	is_pretaxis_tax)r   r   r   )r   r   r   )active_contractsr   
allowancesallowance_ids
deductionsdeduction_idsr   z!tabs/allowance_deduction-tab.htmlcontext)rW   r   r   r   r   r   r   r   wagerh   excluder   field	conditionvaluelowerreplacerg   operator_mappingtypeappendif_condition	if_choice	if_amountr   listsetjsondumpsr   r   )r   r   r   r   r   employee_allowancesemployee_deductions	Allowancespecific_allowancesconditional_allowancesactive_employeesr  r   condition_fieldcondition_operatorcondition_valueemployee_valueoperator_func	Deductionspecific_deductionsconditional_deductionactive_employee_deductionr  r   r   r  r  r  s                               rw   allowances_deductions_tabr'    s    ##r#*H Y' 	$$X$>DDF 
 *: %%tI+i{S	'//66(6S!*!2!2!9!9# ": "

'H'
- 	 %,,33%) 4 

'H'
- 	 )+AADTT
# 	:I++"+//%.%8%8""+//"7"7"9"A"A#s"K!-h!H 0 4 45G H!-&:d>&:?&KO$^_E+229=#**950 :	 0 4 4Y5K5K L/8/B/Bk/Q)WX$_i6I6IJ'..y9	:	:* ,i{S	'//66'4 7 
 !* 1 1 8 8#tE !9 !

'H'
- 	 %.$5$5$<$<%)T% %= %

'H'
- 	"  "77:SS 	 #3z?3# 	:I++"+//%.%8%8""+//"7"7"9"A"A#s"K!-h!H 0 4 45G H #.)&(<^(<_(M &-'..y9	:$  	

0CDHHKKDE   	

0CDHHKKDE  --@)d&-@)d&G '>PP% E
 Es   4O!%O&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.htmlr  )rW   r   r   r5   r   r  r  r   r2   r3   r4   r   )r   r   r   work_type_requestsr   r*  r+  r,  r-  r.  shift_requestsr0  r  s                rw   	shift_tabr3    sK    ##r#*H(0077B7G!ZZ%788 (//6626FM

#NHHKK#NO.66=="=M JJDU'V'VW!))00R0@N$PXX[[$PQ ("8&..!6$0G '0'BB+ 	9 $O'V$Ps   E0!E5.E:;E?&horilla_documents.view_documentrequestc                    t        | j                        \  }}}t        |      }t        j                  j                         }t        j                  j                         }t        | d|      }t        ||      j                  }|j                  d      j                  d      }t        |d| j                  j                  d      d      }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
    r4  r   r   querysetr7  Tdocument_request_id__isnull-document_request_iddocument_request_idpage)document_requests	documentsfpdfilter_dictz documents/document_requests.htmlr  )_prepare_document_query_paramsr   r7   rp   r   r   ro   r(   qsr  order_byre   r   r*   r   )r   sanitized_paramsprevious_datarB  filter_classr>  r?  r  s           rw   document_request_viewrI    s     4R40m[ ))9:L'//335  $$&I"5I
 &&6KNNI!!d!CLLI "('++//&*A6I h,."G '=wOOry   query_paramsreturnc                    | xs t        dd      j                         }h d}|D ]  }|j                  |d        t        |j	                               D ]6  }t        d |j                  |      D              r%|j                  |d       8 |j                         }i }|j	                         D ]D  }|dk(  s|j                  d      r|j                  |      D cg c]	  }|d	vs| }}|s@|||<   F |||fS c c}w )
ap  
    Sanitize query parameters for document request views.

    Removes helper parameters (e.g., referrer, nav_url) from the query string that
    should not be treated as active filters while keeping pagination keys intact
    for subsequent requests. Returns the sanitized QueryDict, the cleaned
    querystring, and a dictionary used for rendering filter tags.
     T)mutable>   nav_urlreferrerfilter_appliedNc              3   $   K   | ]  }|d v 
 yw)NrM  Nrt   ).0r  s     rw   	<genexpr>z1_prepare_document_query_params.<locals>.<genexpr>X  s     Ou5
*Os   r=  dynamic_page_rS  )	r   copypopr  keysanygetlist	urlencode
startswith)rJ  	sanitizedhelper_keyskeyrG  rB  r  valuess           rw   rC  rC  F  s    <2t!<BBDI;K !c4 ! INN$% %O	8I8I#8NOOMM#t$% '')M(*K~~ &&=CNN?;%.%6%6s%;WEuJ?V%WW%K& m[00	 Xs   	C=(C=c           
         t         j                  j                         }t        | j                        \  }}}t        |      j                  }t        | d|      }|j                  d      j                  d      }t        |d| j                  j                  d      d      }t        t        |       t        | d|t        | j                        |||d	      S )
1
    This method is used to filter employee.
    r4  r6  Tr9  r;  r<  r=  zdocuments/requests.html)r?  r@  rA  rB  r>  )rp   r   r   rC  r   r7   rD  r(   r  rE  re   r   r*   ro   r   r8   )r   r>  rF  rG  rB  r?  s         rw   document_filter_viewrd  h  s     (//3353Q40m[ &&67::I"5I
 !!d!CLLI "('++//&*A6I h,!",&!2	

 
ry   %horilla_documents.add_documentrequestc                    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
    re  r   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  )rm   r'   r   r   r   r   r
   r   r   r   r   r   rq   sendr   r   r   r   r   )r   r   r   r   r  s        rw   document_request_creatert    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_documentrequestc                 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   id__inemployee_id__inrq  )r   document_requestrr  r  )r   rp   ro   r   r   r   rm   r   r   r   r   r   r  rW   datar[  r  r   r   r   r   )r   r   rz  r?  r   doc_objr  s          rw   document_request_updater}    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 > ry   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  )rn   r   FILESro   r   r   r   )r   r   r   r?  r  s        rw   document_tabr    sU     gllGMM:D  ''B'7I G
 '3WEEry   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.rq  r   r   z#tabs/htmx/document_create_form.htmlr  )rW   r   r   rk   r   r   r  r   r   r
   r   r   r   r   )r   r   r   r   r  s        rw   document_creater    s     ""&&&&1KD QRD~~GLL'--8==?IIKWa(H&IJ LMM G '@'RRry   c                     | j                   j                  d      }t               }|s0t               |j                  d   _        d|j                  d   _        t        d|d|j                  d   d      }t        |      S )Nr  notify_beforerM  zcbv/document/notify_field.htmlr   
field_namer	  )	r   r   rk   r   fieldswidgetlabelr   r   )r   r  r   notify_field_htmls       rw   get_notify_fieldr    su    ++//-0K>D.9mO$+-/O$*(()[[1	
 )**ry   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 requestrM  )r   ro   r   r   r   r  r   r
   r   r   r   r   )r   r   documentnames       rw   update_document_titler  %  s     !b1H<<G$D~~!$I"JK  	w"3 45ry   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%        d      S t        j(                  | t        d             	 t%        dddi      S # t*        $ r" t        j(                  | t        d             Y 9w 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_idFr9  zDocument request z for z deleted successfullyr   rM  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>
                        z4<script>$('#reloadMessagesButton').click();</script>zDocument not foundz You cannot delete this document.   
HX-Refreshtruer   headers)ro   r   r   r   has_permr  r   r   r
   r   r   r   r   r   joinsplitr]  endswithr   r   r   r   )r   r   r  document_firstrP  existing_documentss         rw   document_deleter  :  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    VWWNN7A&:$;< s\6,BCC  Gw"D EFGs   E,F) /
F) :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   rh  ri  rq  )r   r  ztabs/htmx/document_form.htmlr  )ro   r   r   rn   r   r   r  r   r   r
   r   r   rq   rs  r   r   get_reporting_managerr   r   r   r   r   )r   r   document_itemr   r  s        rw   file_uploadr  l  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   r     Nrbfile_contentfile_extensioncontent_typeztabs/htmx/view_file.html)ro   r   r   r   r  pathossplitextr  get_content_typeopenreadr   )	r   r   document_objr  	file_pathr  r  filer  s	            rw   	view_filer    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   )r  content_typess     rw   r  r    s6     !YSM ^-GHHry   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 uploadedrq  )
r   ro   r  r   r   r
   r   r   r   r   )r   r   r  s      rw   document_approver    ss     %X"5L(!$?"@A DEE 	w"8 9:DEEry   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   rejectedzDocument request rejectedrq  r  ztabs/htmx/reject_form.html)r   r  )r   ro   rl   r  r   r   r   r   r   r
   r   r   r   r   )r   r   r  r   tests        rw   document_rejectr    s     %X"5LD>>V#%gll\JD}}yy{&0#!!#w*E(FG#$PQQw"8 9:HII$|4 ry   c                    | j                   dk(  r| j                  j                  d      }t        j                  j                  |      j                  d      }|j                  d      }t        |      |j                         z
  }|r"t        j                  | t        | d             |r"t        j                  | t        | d	             t        d
ddi      S )z
    This function is used to bulk-approve uploaded documents.

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

    Returns:
        HttpResponse: A 204 No Content response with HX-Refresh header.
    r   idsrv  rM  )r  r  r   z document request(s) approvedz# document(s) skipped (not uploaded)r  r  r  r  )r   r   r[  ro   r   r   r  updatelencountr
   r   r   infor   )r   r  approved_docscount_approvednot_uploaded_counts        rw   document_bulk_approver    s     ~~ll""5) !((//s/;CCRCP&--Z-@ !X(;(;(==n--JKL MM011TUV s\6,BCCry   c                 6   | j                   dk(  r| j                  j                  d      n| j                  j                  d      }t	        | j                  xs d      }| j                   dk(  r|j                         r|j                  d   }t        j                  j                  |      j                  d      j                  d|      }t        j                  | t        d	      j                  |             t!        d
ddi      S t#        | d||d      S )a,  
    Handle bulk rejection of documents.

    On GET request, display a form to enter the rejection reason for selected documents.
    On POST request, validate the rejection reason and update the status of documents
    (excluding those already rejected) to 'rejected' with the provided reason.
    r   r  Nreject_reasonrv  r  r   )r   r  z{} Document request rejectedr  r  r  r  z%documents/document_reject_reason.html)r  r   )r   r   r[  r   rl   r   cleaned_dataro   r   r   r  r  r
   r   r   formatr   r   )r   r  r   r  updated_counts        rw   document_bulk_rejectr  3  s     >>V# 	U#[[  ' 
 gll2d3D~~DMMO))/:##3#/WJW'V:]VC 	
 	Q56==mL	
 3v0FGG8#t:T ry   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   rX   r   r   r   r>   r   r   r   r   r
   r   r   r   r   r   )r   r   r   r   	bank_infos        rw   employee_profile_bank_detailsr  U  s     ||((H"**11h1GMMOH(ID}}IIUI+	 (	!$:";< 0 0 @AAry   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   rW   r   r   r  r   r@   r   r  r   r   r
   r   r   r   )r   employee_userr   r   s       rw   employee_profile_updater  f  s     LLM##]#CH78>>V#gmmhOD}}		  !,>*?@011ry   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      rw   !employee_user_group_assign_deleter  x  s7     <<v&DKK?@@ry   c                 P    t        | t                     }|j                  |      } | S )z3
    This method is used to paginate query set
    )rd   r+   get_page)qrysetpage_number	paginators      rw   paginator_qryr    s(     !)9:I,FMry   employee_viewc                    | j                   j                  d      }| j                   j                         }| j                   j                  d      }| j                  j	                  dd      }t
        j                  j                         }t        | j                   |      j                  }| j                   j                  d      dk7  r|j                  d	      }t               }t        |      }t        t
        |       t
        j                  j                         }	|D 
cg c]  }
|
j                   c}
| j                  d
<   t        | dt        ||      |t               ||||	t         j"                  |d	      S c c}
w )zF
    This method is used to render template for view all employee
    viewr=  error_messageNr8  	is_activeFalseTr  filtered_employeesz)employee_personal_info/employee_view.html)	r{  rA  r@  update_fields_form	view_typerB  r   	gp_fieldsr  )r   r   r\  r   rX  rW   r   r   r8   rD  r<   r   r*   r   r   r  r9   r  )r   r  rG  r  r  r7  
filter_objupdate_fields	data_dictr   r   s              rw   r  r    s=    'IKK))+M++//&)KOO''>M&&(Hh?BBJ{{{#w.&&&6
')M'Ih	*



!
!
#C JR,RXX[[,RGOO()3!*k:!"/"$(//*
	
  -Ss   #E=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_idsrM  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)r  r  zdata-ppN)__name__
__module____qualname__rW   r   r  widgetslabelsr	  _meta	get_field	field_objr  r  r   
isinstancer   	DateFieldr   r  s   rw   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  )selfr   r   r  r	  EmployeeBulkUpdateForm	__class__s        rw   r  zBview_employee_bulk_update.<locals>.EmployeeBulkUpdateForm.__init__  @    0$@$Q&Q-1[[->->-@ .)
E)-.ry   r  r  r  r  r  __classcell__)r  r  r  s   @rw   r  r    s    % %<. .ry   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   r   r  department_idjob_position_idjob_role_id!employee_work_info__department_idr  Tr  #employee_work_info__job_position_idFemployee_work_info__job_role_idr  r   )emailmobiler'  z
Work Emailz
Work PhoneN)r  r  r  r\   r   r  r  r  r	  r   r  partsr	  r
  r  r  r   r  r  r   r  r   r  r   )rT  itemr  r  r  s   0000rw   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,LIO7A56IJ.G4E,F 1R/<1= -3MM-,HEK7A56I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v r|dk(  s|dk(  rd|_        d	|_        $ y )
Nr!  onchangezdepChange($(this))r"  zjobChange($(this)))r#  r"  r#  FT)r  r  r  r  r  r  r  r  )r  r   r   r  r	  WorkInfoBulkUpdateFormr  s        rw   r  zBview_employee_bulk_update.<locals>.WorkInfoBulkUpdateForm.__init__0  s    0$@$Q&Q&$++5O4;;AAHH *,@
 )DKK7$56==CCJJ *,@
 .2[[->->-@ 2)
E%)KK&-7)->>-2EN-1EN2ry   r  )r  r-  r  s   @rw   r-  r    s    D% D%L2 2ry   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  rX   r   r  r  r  r	  r   r  r)  r	  r
  r  r  r  r   r  r   r  r   r   r  s   rw   r  r1  I  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        rw   r  zBview_employee_bulk_update.<locals>.BankInfoBulkUpdateForm.__init__o  r  ry   r  )r  r4  r  s   @rw   r4  r/  H  s    $% $%L. .ry   r4  employee_work_info__)r   form1form2r  r  z'employee_personal_info/bulk_update.htmlr  z0There are no employees selected for bulk update.)r   r   r[  r   r  r  r&   r  rY  r  r  r   r
   warningr   r   r  )r   r  bulk_employee_ids_strr   r6  r7  rY  	keys_listfields_listiupdate_fields_strr  r4  r  r-  r  s               @@@@rw   view_employee_bulk_updater>    sv    ~~,,_=#LL,,-@A->DJJ()B 	 !". ".H]2 ]2~*. *.X *+D*,E*,E<<$$&DT
IK &*Q.""1%& ! ,M)!((+, !%

= 9 !2%:G 9  MN M**u  ry   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  rM  _postr  r   r   r   r   r   r   rx  r2  rv  z-{} employees information updated successfullyz"/employee/employee-view/?view=listrt   )r   r   r   r  loads__dict__astliteral_evalrW   r   intr\   get_or_createrX   
ValueErrorOverflowErrorr   r   r  r   r  r  r
   r   r   r  r   )r   r=  r  
dict_valuer9  r  employee_listr   employee_instancer   createdemployee_bankr	  r)  employee_querysetr  s                   rw   save_employee_bulk_updaterO    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$5 B  ,"G
 *=)D)D)R)R 1 *S *&w	) # 	?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   rW   r
   r  r   r   r  r   r   r   is_superuserr  r   r   r  r   )r   r   r   r   rS  s        rw   employee_account_block_unblockrU    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<<ry   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.
    r8  #employee/create_form/form_view.html)r   	work_formr   r@  )r@   rD   r=   r8   rW   r   r   r   )r   r   rX  r   r  s        rw   employee_view_newrY    sS     >D+-I')I)9)9)=)=)?@J-IIJW ry   c                    | j                   d   }t        j                  j                  | j                        j                         }t        j                  j                  d      j                         }t        j                  j                  |      j                         }t        j                  j                         j                  |      j                         }|sw|rut        |d      ri|j                  r]|j                  j                  rG|j                  j                  |k7  r.t        j                  | t        d             t!        t"              S ||}t$        j                  j'                  |      }t(        j                  j                         j                  |	      j                         }	|	r|d
k7  r||	_        |	j+                          |j+                          |r*|j,                  j                  |	      j                         s| j                  j/                  d      rt1        |      }
t3        t(        j                  j                  |	      j                               }t5        t6        j                  j                  |	      j                               }t9        |j:                  r|j:                  nd      }| j<                  r| j<                  j'                  d      dk(  rYt1        | j<                  |      }
|
j?                         r|
j+                          t        j@                  | t        d             n| j<                  j'                  d      dk(  rZt(        j                  j                  |	      j                         }tC        | j<                  |      }|j?                         r|j+                  d      }||_"        |j+                          |jF                  jI                  | j<                  jK                  d             tM        jN                  | j                  jP                  |jD                  j:                  dddddtS        d      d	       t        j@                  | t        d             t3        t(        j                  j                  |	      j                               }n
| j<                  j'                  d      dk(  rt6        j                  j                  |	      j                         }tU        | j<                  |      }|j?                         r|j+                  d      }||_"        |j+                          t        j@                  | t        d             nL| j<                  j'                  d      dk(  r-|j:                  r|j:                  nd}t9        | j<                  |      }|j?                         r	 |j+                  d      }t        |d       rd|_+        |j:                  sG|j+                          ||_        |j+                          t        j@                  | t        d!             n/|j+                          t        j@                  | t        d"             nt        j                  | t        d$             t9        |j:                  r|j:                  nd      }t_        | d%||
||||d&      S ta        | jb                  j'                  d'd(            S # tX        $ rA}t        j                  | t        d#      j[                  t]        |                   Y d}~d}~ww xY w))zA
    This method is used to render update form for employee.
    r   r   T)work_info_trackr   r   r   Nr   r   r   r   r   personalz&Employee personal information updated.workFr   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.rg  	briefcaseri  z"Employee work information updated.bankzEmployee bank details updated.loginis_new_employeez+Employee user account created successfully.z,Employee login details updated successfully.z0An error occurred while saving login details: {}z0Please fix the errors in the login details form.z#employee/update_form/form_view.html)r   r   rX  r   
login_formwork_info_historyr   z/employee/employee-view)2r   rW   r   r   r   r   rj   r   r   hasattrr   r   company_id_idr
   r   r   r   r  r-   r   r\   r   r   r  r@   rD   r=   rX   rF   r   r   r   r   rE   r   r^  r  r[  rq   rs  r   r   r>   rb  r   r  r   r   r   r   )r   r   r   selected_company_idr   rd  r   r   cmpnyr]  r   rX  r   rc  r   user_instancer   s                    rw   employee_view_updaterj    s     "//*<=""GLL"AGGID-55<< = fh  &&&&1779H



!
!
#
*
*f
*
5
;
;
=C-A B""&&11&&448KK NNMN M**##':#; $++224VV)UW 	 '50#DOIIK 	""))h)?FFH<<  !;<X./,44;;$ < eg
	
 ,(0077H7MSSU
	 *2:2K2KX..QU

 <<||':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!!&)W4=E=V=V 9 9\`1LL=
 &&(v)e< #4):;38D0  (88 IIK8<H5$MMO$,,Wa8e6fg IIK$,,Wa8f6gh
 NN7A.`,ab 2:B:S:SX66Y]
 1 &&(%6
 	
  )BC + % v w2d0e0l0lmpqrms0tuuvs   +B'\ 	]7]]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>)rW   r   r   r  r   r   r
   r   r   r   r   r   r   contentdecode)r   r   r   imgresponses        rw   update_profile_imagert    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   rl  rm  rn  ro  )r   r   r  r   r   r   r
   r   r   r   r   rp  rq  )r   r   rr  rs  s       rw   update_own_profile_imagerv    s     ||((H
--

.
/C #HMMOWa 89:-H (+PP ry   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   rM  No profile image to remove.rm  rn  ro  NProfile image removed.)rW   r   r   r   r  r
   r  r   r   r   rp  rq  r  r  r  r	   
MEDIA_ROOTr   r   r   )r   r   r   rs  r  absolute_paths         rw   remove_profile_imager}    s    ##v#.H  %%+gq!>?@1
 ##G,/TT
 	
 ))..IGGLL!4!4i@MIIm $HMMOWa 89:-H (+PP ry   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
    rM  ry  rm  rn  ro  Nrz  )r   r   r   r  r
   r  r   r   r   rp  rq  r  r  r  r	   r{  r   r   r   )r   r   rs  r  r|  s        rw   remove_own_profile_imager    s    ||((H  %%+gq!>?@1
 ##G,/TT
 	
 ))..IGGLL!4!4i@MIIm $HMMOWa 89:-H (+PP ry   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   rX  r   r{  z
                <div class="oh-alert-container">
                    <div class="oh-alert oh-alert--animated oh-alert--success">
                        Personal Info updated
                    </div>
                </div>

        rW  r   
<li>: , </li><ul class="alert alert-danger"></ul>)rW   r   r   r   r@   r   r   r   r
   r   r   r   rD   r\   r=   rX   r   r   r   r   r  errorsr  r  r   r  )r   r   r   r   rX  r   r	  r  s           rw   $employee_create_update_personal_infor    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>

        r  r  r  r  r  r  r  )rW   r   r   r   rD   r   r\   r  r  r   r   r   r   r  r  r  r   r  )r   r   r   r   	work_infor	  r  s          rw   employee_update_work_infor  G  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>
        r  r  r  r  r  r  r  )rW   r   r   r   r=   r   rX   r   r   r   r   r  r  r  r  r   r  )r   r   r   r   r  r	  r  s          rw   employee_update_bank_detailsr  m  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                    t         j                  j                  |      j                         }|st	        d      S |j
                  }|s
t               }t        | j                  |      }|j                         r>|j                         }|j
                  s||_        |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 )zA
    This method is used to update employee's login details.
    r   z?<ul class="alert alert-danger"><li>Employee not found</li></ul>r   z
            <div class="oh-alert-container">
                <div class="oh-alert oh-alert--animated oh-alert--success">
                    Login details updated
                </div>
            </div>
        r  r  r  r  r  r  r  )rW   r   r   r   r   r   r   rF   r   r   r   r  r  r  r  r   r  )r   r   r   r   r   r	  r  s          rw   employee_update_login_detailsr    s     &&&&1779H]^^ $$Dvt<D}}yy{(((,H%MMO
 	
 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 )rc  r	  r   r8  r  r  Tr  employee_work_info__company_idNr   )r  r=  r  )employee_personal_info/employee_card.htmlr  )employee_personal_info/employee_list.htmlrM  z$employee_personal_info/group_by.htmlorderbyr  )r{  r@  rA  r	  rB  )r   r\  r   rW   r   r   r   r8   rD  r   r*   re   r,   r  r   r   )r   rG  r	  r7  r   r   r  r  r  templater   s              rw   employee_filter_viewr    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.
    searchNrM  r   r  Temployee_first_name__icontainsr  r8  r  r=  r  r  r{  r@  rA  )r   r\  r   r  r  r)   rW   r   r   r8   r   r,   rD  r   r  )r   rG  r  r   r  r  s         rw   employee_cardr    s    KK))+M[[__X&F&$t*%/!!%%')AI {{{#+#KK%%/5 & 

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

 ++//&)Kw
y9I3!)[9	
 ry   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
    r  NrM  r  Tr  r8  r  r   r  r=  r  r  )r   r\  r   r  r  r8   rW   r   r   r)   rD  r,   r   r  )r   rG  r  r  r   r  s         rw   rJ  rJ    s	    KK))+M[[__X&F&$t*%{{{#+#KK%%,,/5 - 

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

 0 8I w	95I++//&)K3!)[9	
 ry   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.htmlr  )rW   r   r   r@   r\   r   r   rX   rD   r>   r   r   r  r   r  r   r   r
   r   r   r   )r   r   r   r   r  r  rX  r   s           rw   employee_updater  ?  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 ry   zemployee.delete_employeec                 t   	 | 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?        d
      dz         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   r   zEmployee deletedEmployee not found.z, - z- {}.r  r   z?error_message=trueNr   z/view=)"r   r   rW   r   r   r   r   r   r   r   r   r   AttributeErrorr
   r   r   DoesNotExistr   r   r  protected_objectsr   r   r	  verbose_name
capitalizer  r  r   r   r   r   r   r   )r   r   r  r   r   contractr   r   model_verbose_names_setobjmodel_names_strr  s               rw   employee_deleter  _  s   J||'##''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 J"%%&& 	QC#''399+A+A+L+L+N(OP	Q ++&=>'..9:M*+8(03HHIIJsO   B&D> )D> D D> D;8D> :D;;D> >2H72H7:B2H2,H72H7c                    t        j                  | j                  j                  dd            }|st	        j
                  | t        d             d}t        j                  j                  |      j                  d      }|D ]  }	 t        j                  d      ri|j                  j                         j                         rA|j                  j                         }|D ]"  }|j                   dk7  s|j#                          $ |j$                  }|j#                          |d	z  } |dkD  r$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 ?w xY w)zA
    This method is used to delete set of Employee instances
    r  z[]zNo IDs provided.r   rv  r   r   r   r  r  zYou cannot delete %(employee)s.r   z$%(deleted_count)s employees deleted.deleted_countmessageSuccess)r  rA  r   r   r
   r   r   rW   r   r   select_relatedr   r   r   r   r   r   r   r   r  r   r   r   )r   r  r  r   r   r   r  r   s           rw   employee_bulk_deleter    s    **W\\%%eT2
3Cw"4 56M  ''s'3BBCUVI 	  +((,,.557 ( 5 5 9 9 ;I$- .#33x?$OO-. ,,DKKMQM" q45./	

 I.// $$ 	>NN7A&;$<= 	NN<=X@VV	s   A+E43E2G,GG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
    r  Fr  TrueTr   r   r  r  %You can't archive the last superuser.z.<script>$('#filterEmployee').click();</script>archivedzun-archivedz is zRelated data found for {}.r  r  )r   r  rA  r   r   rW   r   r   rT  r  r   r
   r   r   r   get_archive_conditionr   r   r8  r  r   )
r   r  r  r   r   r   r  r   	super_empr  s
             rw   employee_bulk_archiver    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.//ry   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  r  z+<script>$('#applyFilter').click();</script>FEmployee archivedHTTP_HX_REQUESTr   r   related_models.htmlrelated_modelsrelated_model_fieldsemployee_choicesCan't Archiver   r  r  r  r  )rW   r   r   r  r   rT  r   r
   r   r   r   r  r   r   r   rY  r   r   )r   r   r   r   r  r   r  r   r  resultr`  s              rw   employee_archiver    s    ##v#.H%///H.6.@.@*@H'D$G""f"-,,E ((//$/?I& &	--::!AIE& zw*Q(RS#$QRR//1D+,G'*gll''))'(8(8(MNN MNN!$"(**-=">(.

3I(J$*JJ/A$B?+

 
	
ry   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   r  rM  r  r   )r   recruitmentrecruitment_managersr   )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   rW   r   r   r   r  r   r   r\   r  r   r   rh   r  r   r   r  r   r
   r   r   r   r  r   r  r  )r   r   r  r   r  r   r  replace_emp_idreplace_empr   Recruitmentrecruitment_queryr  Stagerecruitment_stage_queryr  OnboardingStageonboarding_stage_queryOnboardingTaskonboarding_task_querytasks                        rw   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""ry   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  Tr  Fr  r  r   r   )<script>window.location.reload()</script>r  r  r  r  r  )r   r   rW   r   r   r   r   r  r   r  r   r
   r   r   rY  r   r   r   )	r   r   r   r  r  r   r  r  r`  s	            rw   get_manager_inr  g	  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

 
	
ry   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
    r  r  rM  Tr  r=  r  r  r  r   r  )r{  rA  rB  )r   r\  r8   rD  r   r   r)   r,   r   r*   rW   r   r  )r   r  r  rG  r   r  r  r  s           rw   employee_searchr  	  s     [["F;;vDKK))+Mw{{+..I|$$t$4	++//&)K:Hv~>/4I w	95I'Ih	*!)[9$	
 ry   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 informationr  r  )rW   r   r   r@   rE   r   r>   rX   r   r   r2  r   r   r   r
   r   r   r   )r   r   r   r   rX  r   bank_form_instancer  s           rw   employee_work_info_view_creater  	  s     ##v#.H*D1',,?I-/I,44;; < eg  %133
	 NN%N0	 (	!$>"?@:IIF ry   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 Successfullyr  r  )r\   r   r   r@   r   r>   r2  rE   r   r   r   r
   r   r   r   )r   r   work_informationr   r   rX  s         rw   employee_work_info_view_updater  	  s     /66::f:E!1!=!=>D-!--CCI 2!I !$K"LM:IIF ry   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 Successfullyr  r  )rW   r   r   r@   r>   r   r\   r   r   rE   r   r   r   r
   r   r   r   )r   r   r   r   r   work_form_instancerX  bank_instances           rw   !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 ry   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 Successfullyr  r  )rX   r   r   r@   r   rE   r   r>   r   r   r   r
   r   r   r   )r   r   employee_bank_instancer   rX  r   r  s          rw   !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 ry   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)r\   r   r   r   r
   r   r   r  r   r   r   )r   r   employee_works      rw    employee_work_information_deleter  3
  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   r  recordsphoner'  employee_full_name)usernamerM  r   r  F)r  r'  passwordrT  zz
    <div class='alert-success p-3 border-rounded'>
        Employee data has been imported successfully.
    </div>

    )r  r'  r  columnsapplication/ms-excelr  z-attachment; filename="employee_template.xlsx"Content-Dispositionindex)r   r  rA  
read_excelto_dictr   r   r   r   r  create_userr   striprW   r   r   employee_last_namer'  r  r   r   r  r   	DataFrameto_excel)r   r  
data_frameemployee_dicts
error_listemployee_dictr  r'  r  existing_userr   r	  r   r   rs  s                  rw   employee_importr  H
  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  )rW   r	  
get_fieldsauto_createdr  r   r   values_listrA  r
  r  r   r  )r   r@  field_namesemployee_datar  rs  s         rw   employee_exportr  
  s     $,>>#<#<#>Uaann166UKU)*)*()+,./{# $$00+>Md=1;GJ )?@H&SH"#.O% Vs
   DDc                 l    |j                  |       }	 t        |       y# t        t        f$ r |cY S w xY w)z4
    This method is returns None or field value
    N)r   floatrG  	TypeError)r	  dictsfield_values      rw   convert_nanr#  
  s<     ))E"Kk	" s    33c                 ~    t        j                  g d      }t        d      }d|d<   |j                  |d       |S )	zS
    This method is used to return the excel file of import Employee instances
    )zBadge IDz
First Namez	Last NameEmailPhoneGenderr.   zJob PositionzJob RoleShiftz	Work TypezReporting ManagerzEmployee TypeLocationzDate JoiningzBasic SalaryzSalary HourzContract End Dater-   r  r   r  z.attachment; filename="work_info_template.xlsx"r  Fr  )rA  r
  r   r  )r   r  rs  s      rw   work_info_import_filer*  
  sG     
J0 )?@H&VH"#.Ory   c                 ~   | j                   dk(  rt        | d      S | j                   dk(  r| j                  j                  d      }|st	        d      }t        | dd|i      S |j
                  j                  d      d   j                         }	 |d	k(  rt        j                  |      }n4|d
v rt        j                  |      }nt	        d      }t        | dd|i      S t        |      \  }}|st        | dd|i      S t        |      \  }}}|r	 t        |      }	t        |      }
t        |       t!        |       t#        |       t%        |       t'        |       t)        |       t+        |       t-        j.                  t0        |
f      }|j3                          |rt?        |t@        d      nd }||tC        |      z   tC        |      t	        d      |d}tE        d|      }|dz  }tG        |      S t        | ddi      S # t4        $ rM}t7        j8                  | t	        d      j;                  |             t=        j8                  |       Y d }~d }~ww xY w# t4        $ rU}t7        j8                  | t	        d      j;                  |             t=        j8                  d|        d| }Y d }~d }~ww xY w)Nr   zemployee/employee_import.htmlr   r  zNo file uploaded.r  .r   csv)xlsr  z;Unsupported file format. Please upload a CSV or Excel file.)targetr   zError Occured {}zEmployeesImportError.xlsx	Employees)created_counttotal_counterror_countr   	path_infozimport_popup.htmlz
                        <script>
                            $('#objectCreateModalTarget').css('max-width', '410px');
                        </script>
                    zHFailed to read file. Please ensure it is a valid CSV or Excel file. : {}zFile import error: )$r   r   r  r   r   r  r  r  rA  read_csvr  rU   rS   rN   rI   rH   rK   rL   rP   rM   rJ   rO   	threadingThreadrT   startr   r
   r   r  r_   r6   rQ   r  r   r   )r   r  r  r  r  validsuccess_listr  r1  usersr   threadr   r4  r  r  s                   rw   work_info_importr=  
  s    ~~g>??~~}}  (12M/ -0  -b1779L	6&[[.
?2]]40
 !"Q! 3$m4  $=Z#H E=3$m4 
 7O73L*m $3LAE ;L II1,?3LA/=*<8&|4.|<0>&--39,F LLN  & 35P   "/,s:>":;&G &&97CF  F
  '' 0?M2R G ! $NN7A.@,A,H,H,KLLLOO$4  	6NN^&)	 LL.qc231!5M	6sS   AI I >I BH AI 	IAII II 	J<'AJ77J<c                    | j                   j                  d      r"t               t               d}t	        | d|      S i }g }t               }dddddd	d
d}t        | j
                        j                  }t        | |d      }| j
                  j                  d      }|si|j                  d   j                  }| j
                  j                  d      }t        j                  |      }	t        j                  j                  |	      }t!        t#        d |D                    }
|
r |j$                  |
 }t&        D ]  \  }}||v s|j)                  ||f        d}| j*                  }t-        |dd      }|rt.        j                  j                  |      j1                         }|rRt2        j                  j                  |j4                        j1                         }|r|j6                  r|j6                  }|D ci c]  \  }}|g 
 }}}|D ]  }|D ]  \  }}||v r||   }|j9                  d      }|}|D ]  }t-        ||d      }| n t;        |      r	  |       }|t?        |      nd}tA        |tB              r&	 |jE                  tG        j                  |d            }|dk(  rtI        d      }n|dk(  rtI        d      }||   j)                  |         tK        jL                  |      }tO        d      }d |d!<   |jQ                  |d"#       |S c c}}w # t<        $ r d}Y w xY w# t<        $ r t?        |      }Y w xY w)$r  r  )export_filterexport_formzemployee_export_filter.html-employee_work_info__department_id__department1employee_work_info__job_position_id__job_position)employee_work_info__job_role_id__job_role,employee_work_info__shift_id__employee_shift+employee_work_info__work_type_id__work_type7employee_work_info__reporting_manager_id__get_full_name3employee_work_info__employee_type_id__employee_type)r$  r%  r&  employee_work_info__shift_id employee_work_info__work_type_id(employee_work_info__reporting_manager_id$employee_work_info__employee_type_idr   selected_fieldsr  rv  c              3   N   K   | ]  }d |v s|j                  d       d     yw)r   r   N)r  )rT  r@  s     rw   rU  z#work_info_export.<locals>.<genexpr>Y  s$     VADTUIqwwt}Q/Vs   	%%z
YYYY-MM-DDr   Nr   )r   r   rM  z%Y-%m-%dr  Yesr  Nor  r   r  r  r  Fr  ))r   r   r8   r?   r   r   rD  r)   r[  r  r  r  rA  rW   r   r   r  r  r  rG   r  r   r   r\   r   r-   r   date_formatr  callabler   r   r  r   strftimerf   r   rA  r
  r   r  )r   r  employees_dataselected_columnsr   field_overridesr   rL  r  id_listprefetch_fieldsr  r`  rP  r   r   r  r   r   column_namer   column_valuenested_attrsattrr{  r  rs  s                              rw   work_info_exportr\  5  sZ    ||)*+-24
 g<gFFN"$D-\/b+V(V,Y4m0eO w{{+..I/4I kk))*;<O++&78@@kkooe$**S/$$++7+;	3VVVWO,I,,o>	# 2
sO###UCL12 K<<D
$
-C
&..55#5FLLNoo,,T__,EKKMG7..%11<LM.![k2oMNM "5)9 !	5%L+..|<'--d3LE$ tT2= !GE "'!23u:D%&& >>,00jID v~xw;'..t4C!	5"5F >2J)?@H&SH"#.OS N" ! E ! &u:D&s*   >LL"%L3"L0/L03M
	M
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monthrW   r   r   dayrE  r   ascdobdays_until_birthday)r   last_day_of_monthr   r   s       rw   birthdayrl    s     LLN!E ++EJJDQG  ''ii;;'	 ( 
 hq}  D 12   D'/||'7'7%))'C$Dry   birthday_viewc           
      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 %br   Todayr  TomorrowzIn z DaysrM  )profiler  ri  daysUntilBirthday
departmentjob_positionz"dashboard/birthdays_container.html	birthdays)rl  re  ro  r   r	  ri  rR  rj  r   get_departmentru  get_job_positionrv  r   )r   r   default_avatar_urlr   rw  s        rw   get_employees_birthdayr{    sB    
IN4 32 + 3-  *+C,C,C+DAcF\F\E]^../q1G1G0HI77##G, **a/ '
 ..!3 jMs667u= 473E3E3G""$//R 8;7K7K7M$$&33SU+	
I 6 5Y7O 7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)rw  r  inactive_employeestotal_employeesactive_ratioinactive_ratio)	rl  rW   r   r   r(   r   r   r  r   )r   upcoming_birthdaysr   r  r~  r  r  s          rw   	dashboardr    s     "  $$&I"7I7OPI ''$'7"))E):LN/03y>ASHM !34s9~ELSQ4+ #$4 5"%&8"9"9~(,	
 ry   c                 p    t         j                  j                         j                         }t	        |      S rs   )rW   r   r   r  r   )r   r   s     rw   total_employees_countr    s*      $$&,,.I	""ry   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   rh   r   r   r   r   r   r  r   )r   newbies_today	Candidates      rw   joining_today_countr    sv    M'+m;W	!))00!%tzz|iQ>O/O P 1 
 %' 	 &&ry   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  r  r   r     T)r  r  hired)r   r   rh   r   r   r   r   r   weekdayr  r   )r   newbies_weekr  s      rw   joining_week_countr    s    L'+m;W	 ((//

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

ya$**,2F2F2H.HII!  0 
 %' 	 %%ry   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-Activer0  Tr  Fr  r{  dataSetr  r   rW   r   r   r  r   r   r  r   rs  s       rw   dashboard_employeer    s     	
(	+F   '')I ;	((4(89	((5(9:
 H !!ry   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  r0  male)genderfemaleotherr  r  r  r  s       rw   dashboard_employee_genderr  +  s    
 i8aj1F  ''$'7I
 ;	(((78	(((9:	(((89	
 H !!ry   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)rA  r  r.   r  zNo Data Found...)r  r  r  )
r.   r   r   r  rW   r   r  ru  r   r   )r   r  r  departmentsdeptrs  s         rw   dashboard_employee_departmentr  C  s    
 FE$$((*K ##>Bd $ 

 MM$//*LL$$++FJ"& ,   +E:;'(H
 !!ry   c                 6   | j                   j                         }t        |j                               D ]'  }t	        d |j                  |      D              s%||= ) t        |      j                  j                  dd      }t        dt        |      i      S )zD
    This method is used to return all the ids of the employees
    c              3   >   K   | ]  }|j                            y wrs   )r  )rT  vs     rw   rU  z widget_filter.<locals>.<genexpr>j  s     ?1779}?s   r  r   T)flatr  )
r   rW  r  rY  r   r[  r8   rD  r  r   )r   cleaned_getr`  r  s       rw   widget_filterr  b  s    
 ++""$KK$$&' !?k&9&9#&>??C ! k
*
-
-
9
9$T
9
JCS	*++ry   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_idsr2  F)safe)	r   r   rW   r   r   r   r   r  r   )r   r  r   r   r  r2  r  s          rw   employee_selectr  p  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   r8  r   )r   r7  r   r  N)r   r   r8   rW   r   r   r)   rD  r   r   r  r   )r   r  employee_filterr  r   r  r2  r  s           rw   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/main_note_tab.html)r   notes)rW   r   r   rZ   r   rE  r   )r   r   employee_objr  s       rw   note_tabr    s\     ##''2'.L  ''B'7@@GE!!E2 ry   c                 `    t         j                  j                  |      }t        | dd|i      S )a  
    This function is used to view history 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 history template

    r   ztabs/history.htmlr   )rW   r   r   r   )r   r   r  s      rw   history_tabr    s8     ##''2'.L	\" ry   zemployee.add_employeenotec                 Z   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|       S t        j                  j                  |      }t'        | d	||d
      S )z
    Handles the addition of a note to a specific employee, including file attachments.
    Saves the note and redirects to the employee's note tab upon successful submission.
    r   r  r   Fr   r   zNote added successfully../employee/note-tab/ztabs/add_note.html)r   r   )rB   r   r   r  r   r   rW   r   r   r   r   r   
updated_by
note_filesr  r
   r   r   r   r   )r   r   r   noteattachment_idsr   r  s          rw   add_noter    s    ]F$;<D~~LLMM

 ==?#'99E9#: D.''++v+6H'D%ll77DOIIKOO/Wa(C&DE1&:;;##''6'2L$	
 ry   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   rn  ro  )rZ   r   r   rB   r   r   r   r
   r   r   r   r   rp  rq  )r   note_idr  r   rs  s        rw   employee_note_updater    s     ##w#/DT*D||t<==?IIKWa(F&GH'H
    ''03XX  D	
 ry   zemployee.delete_employeenotec                     t         j                  j                  |      }|j                  j                  }|j                          t        j                  | t        d             t        d|       S )z^
    This method is used to delete the note
    Args:
        id : stage note instance id
    r   zNote deleted successfully.r  )
rZ   r   r   r   r   r   r
   r   r   r   )r   r  r  r   s       rw   employee_note_deleter    s`     ##w#/D  FKKMWa <=>)&233ry   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  )rZ   r   r   r   r   r   r  r[  r]   creater  r  r   r   )r   r  r  r   r  	files_idsr  r   s           rw   add_more_employee_filesr    s     ##w#/D""%%K~~%%g.	 	-D ((//d/;HX[[)OO,		-
 )+788ry   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   )r]   r   r   r   r   )r   note_file_idr  s      rw   delete_employee_note_filer  4  s.       L 1DKKM>ry   zemployee.view_bonuspointc                    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}
t1        | d|
      S # t.        $ r	 |dg d}
Y w xY w)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  r   r  pairr   r  r   N)r  r   pointsr   reasonzRedeemed pointsc                     | d   S )Nr   rt   )xs    rw   r   z"bonus_points_tab.<locals>.<lambda>y  s
    AfI ry   T)r`  r   )r   r  activity_listztabs/bonus_points.html)rW   r   r   rV   r   r   rh   r   r   nonetrackingr  history_dater  r   r   history_user_idr   r  
created_atbonus_to_encashr   sortedr   r   )r   r   r  r  Reimbursementrequested_bonus_points	trackingsr  historyr  r  s              rw   bonus_points_tabr  B  s    ##''2'.L2
##''B'7Y'3#?M &3%:%:%A%A%7 &B &" &.Z__%6"OO%	  	G  #FO#FOA.;;%foa077'&/!:L:S:SS#++&vq1AA , %'& &foa077	  0 		I  '%00'77(99/		 }2EtT$*
     
$

s   FF6 6GG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  )rV   r   r   r:   r   r   r  r   r   r  r  r  r
   r   r   r  r   r   r   )r   r   bonus_pointr   s       rw   add_bonus_pointsr    s    $$((V(<KD~~ LLMM
 ==?IIUI#$"3"3H"==!%!2!28!<K89@@%%h/ ((8(8(MNN$	
 ry   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_onrq  z"tabs/forms/redeem_points_form.html)r   r   )rW   r   r   rV   r   r   r   r  r;   r   r   r   r   rh   bonus_amountr   r   r   r   r  r  r   r   r   r   )
r   r   r   avialable_pointsr   amount_for_bonus_pointEncashmentGeneralSettingsr  r  r  s
             rw   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, 	
 ry   c                   	
 | j                   j                  d      }| j                  j                  d      dk(  r6|dk7  r1t        j                  j                  dd|      j                         }n/t        j                  j                  dd      j                         }|D ci c]  }|j                  |j                          c}g 
	
fd		| j                   j                  d      }| j                  j                  d      dk(  r6|dk7  r1t        j                  j                  dd|      j                         }n/t        j                  j                  d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   TF)r  reporting_manager__isnullr  )r  r  c                 ~   g }| j                   j                         v rj                  |        t        j                  j                  d|       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
        T)r  rJ  r   rv  Not setr  r  childrenzmiddle-level)r  r  	classNamer  )r   rY  r  rW   r   r   r  get_full_namer   ry  r   )managernodessubordinatesr   create_hierarchyentered_req_managersresult_dicts       rw   r  z,organisation_chart.<locals>.create_hierarchy  s6    ::))++ ''0''..W / 

'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 ry   r   zMy viewr   
manager_idr   rv  r  r  act_datasourcezorganisation_chart/chart.htmlr  )r  reporting_manager_dictact_manager_idz!organisation_chart/org_chart.html)r   r   r   rW   r   r   distinctr   r  r   r   r  r   r   r   rE  r   ry  r   )r   r   reporting_managersr*  r  new_dictr  noder  r  r   r  s            @@@rw   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e 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  rh   r   r   r   r  r   r   r   r   r
   r   r   r   r   r   r   r8  )r   r  r  r   r  s        rw   encashment_condition_creater  l  s!    #E$;'B%
!
   + &--335" 	 >>V#;xO '')$$&  !,?*@A+GLL,<,<^S,QRR;XNO/0
 	
 Wa ;<= 0 0 EFFry   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)rY   r   r   r   rA   r   r   r   r
   r   r   r   r   r   r   )r   r   r   s      rw   initial_prefixr    s     &--335H)+~~/xP==?IIKW&LM'(8(8(MNNNN7$MN/B'3mT5JKKry   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)rR   r   )r   r  s     rw   first_last_badger    s'     &'I6	i  ry   c                    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 # t        $ r t        | ddg i      cY S w xY w)zG
    This method is used to track mails sent along with the status
    r   )to__icontainsz-created_atztabs/mail_log.htmltracked_mails)
rW   r   r   r/   r   r'  r   rE  r   r   )r   r   r   r  s       rw   employee_get_mail_logr    s     ##r#*H$$++(..+IM	L&&8+F+F+L+L)H,<,<,C,C&99?? -D - M &..}=g3o}5UVV Lg3or5JKKLs   A8C C C c                    | j                   j                  d      }|r0t        j                  j	                  |      j                  dd      ng }|r0| j                   j                  d      xs |j                         d   nd }|r0t        j                  j	                  |      j                  dd      ng }t        t        |      t        |      d	      S )
Nr!  r!  r   rv  job_idr   r"  job_role)job_positions	job_roles)
r   r   r0   r   r   r  r   r1   r   dict)r   r!  r  r  r   s        rw   get_job_positionsr"    s    KKOOO4M
  	"""?KK.	
   BO!=]%8%8%:1%=TX   	v6BB4T 
 }-DOL ry   c                    | j                   j                  d      }| j                   j                  d      }t               }|rt        j                  j                  |      }||j                  d   _        |r||j                  d   _        nC|j                  d   j                  j                         j                  |j                  d   _        t        d|d|j                  d   d      }t        |      S )Nr!  r"  r  z%cbv/dashboard/job_position_field.htmlr  )r   r   rE   r0   r   r   r  r7  r  r   r   r   r   )r   r!  r"  r   r  job_position_field_htmls         rw   get_job_positions_hxr%    s    KKOOO4Mkkoo&78O,.D#++222O2?%&/5DDKK)*2 -.77==?BB KK)*2 //+[[!23	
 /00ry   c                    | j                   j                  d      }t        j                  j	                  |      j                         }|r|j                  nd}|r0t        j                  j	                  |      j                  dd      ng }t        j                  j                  dd      }t        |r|j                  nd|r|j                  ndt        |      t        |      d      S )	  
    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.
    r"  r   Nr  r   r  ru  )r!  department_namer   r  )r   r   r0   r   r   r   r!  r1   r  r.   r   r   ru  r!  )r   r"  rv  ru  r   all_departmentss         rw   get_job_rolesr*    s     kkoo&78O&&---AGGIL/;++J
  	?KK*	
   !((44T<HO.8Z]]d8Bz44i0		
 ry   c           	      h   | j                   j                  d      }t        j                  j	                  |      j                         }|r|j                  nd}|r|j                  j                  nd}t        j                  j                  dd      }|r:t        j                  j	                  |j                        j                  dd      ng }t        |r|j                  nd|r|j                  ndt        |      t        |      |r|j                  nd|r|j                  d      S dd      S )	a  
    Retrieve job position and department associated with a specific job roles.

    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.
    r#  r   Nr   ru  r  rv  )r"  job_position_namer  r  r!  r(  )r   r   r1   r   r   r   r"  r!  r.   r  r0   r   r   rv  r!  ru  )r   r#  r  rv  ru  r)  all_job_positions          rw   get_position_departmentr.     s    ++//-0K%%%5;;=H/78++TL;C))77J ((44T<HO
  	"""?KK.	
   2>|D>J!:!:PT!"230.8Z]]d8Bz44	
	 	 IM	
	 	ry   c                 j   | j                   j                  d      }| j                   j                  d      }t               }|rJt        j                  j                  |      }||j                  d   _        |r||j                  d   _        t        d|d|j                  d   d      }t        |      S )r'  r"  r#  r  z!cbv/dashboard/job_role_field.htmlr  )r   r   rE   r1   r   r   r  r7  r  r   r   )r   r"  r#  r   r  job_role_field_htmls         rw   get_job_roles_hxr1  C  s     kkoo&78O++//-0K,.D??))/)J.6M"+1<DKK&.*+'[[/	
 +,,ry   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)r[   r   r   r   )r   r3  s     rw   employee_tag_viewr4  _  s3     &&**,L&	& ry   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     rw   employee_tag_creater8  m  ss     D~~w||,==?IIK"$DWa(L&MN2D	
 ry   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 )r6  r   r   r   z"Tag has been updated successfully!r  r7  )r   tag_id)r[   r   r   rC   r   r   r   r   r
   r   r   r   r   )r   r:  tagr   s       rw   employee_tag_updater<    s     


!
!V
!
,CC(D~~w||c:==?IIK"$DWa(L&MN KLL2( ry   rs   (  __doc__rC  rc  r  operatorr  r6  r   r   r   typingr   urllib.parser   pandasrA  django.appsr   django.confr	   django.contribr
   django.contrib.auth.modelsr   django.core.cacher   django.core.exceptionsr   	django.dbr   django.db.modelsr   r   django.db.models.queryr   django.formsr   r   r   django.httpr   r   r   r   django.shortcutsr   r   r   django.template.loaderr   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/   r0   r1   r2   r3   r4   r5   
base.viewsr6   employee.filtersr7   r8   r9   employee.formsr:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   employee.methods.methodsrH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   employee.modelsrV   rW   rX   rY   rZ   r[   r\   r]   horilla.decoratorsr^   r_   r`   ra   rb   rc   horilla.filtersrd   horilla.group_byre   horilla.horilla_settingsrf   horilla.methodsrg   rh   horilla_audit.modelsri   rj   horilla_documents.formsrk   rl   rm   rn   horilla_documents.modelsro   rp   notifications.signalsrq   rx   eqner|   r}   r~   r   containsr  filter_mappingr   r   r   r   r   r   r'  r3  rI  tupler   r!  r  rC  rd  rt  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r>  rO  rU  rY  rj  rt  rv  r}  r  r  r  r  r  r  r  rJ  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r#  r*  r=  r\  rl  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r  r  r  r"  r%  r*  r.  r1  r4  r8  r<  rt   ry   rw   <module>rm     s%       	  . .  !     # + # 5  . + 7 7 S S @ @ 3  ! 2 6 = 8 E C 5   
 
 
 - S S        	 	 	  - . 9 A K  ? (
 [[
++
++
++
++""	  	 
 	 
 	 
 	 
->@  < 	#%	 
%PG, $	!#
I IX   ( dQ  dQN /:"C ;  "CJ ;<#P = #PL19%1
9c4T#Y//01D ;<  =   F :;' <  'T => ?  > 2H=F >  F. 18<S =  S4+"  ( -D  -D` &L  &LR !@  !@HI, 34F 5  F, 34 5  B 34D 5 DB 34 5 @ vhB   B ,-2 . 2  ^$vhA   % A 	!#
$ $N /0[+ 1 [+| /06: 1 6:r /0= 1 =: ,- .  -.Y / Yx vh/0 1   * vh   $ xj!/0 1 " < xj! " < -.vh1I   / 1Ih <=vh I   >  IF 89vhI   : I> -.vh'I   / 'IT 	!#
+  +\ +,!  - !H +,!  - !H +, -  : /0vh"S   1 "SJ /0 0 1  0F /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	 ,- . D ,-_ .  _D +,] - ]@$ _3KL# M #L +, - : # #
 ' ' & & " "0 " ". " "< 
, 
, - -" +,% - %* 45 6  ,* 34 5  D 67 8 @ 674 8 4 019 2  9& 34 5   +X6D 7  DN 12& 3 &R +X69 7 9x sQ sQl <="G > "GJ :;L < L, +,
 - 
 +,L -  L$  . 1 12  <  D - -6 01	 2 	 /0 1  ( /0 1  ry   