403Webshell
Server IP : 65.108.144.40  /  Your IP : 216.73.217.165
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux ubuntu-8gb-hel1-1 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64
User : dev ( 1000)
PHP Version : 8.2.30
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/erp/base/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/erp/base/__pycache__/views.cpython-310.pyc
o

hͦh`��@sjdZddlZddlZddlZddlZddlmZmZddlmZddlm	Z	ddl
mZmZm
Z
ddlZddlmZddlmZdd	lmZdd
lmZddlmZmZmZddlmZmZmZdd
l m!Z!m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,m-Z-ddl.m/Z/m0Z0m1Z1m2Z2ddl3m4Z4m5Z5m6Z6ddl7m8Z8ddl9m:Z:m;Z;ddl<m=Z=ddl>m?Z?ddl@mAZAddlBmCZDddlEmFZFddlGmHZHddlImJZJddlKmLZLmMZMddlNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYdd lZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZm�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�dd!l�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�dd"l�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�dd#l�m�Z�dd$l�m�Z�m�Z�dd%l�m�Z�m�Z�m�Z�m�Z�m�Z�dd&l�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�dd'l�m�Z�dd(l�m�Z�m�Z�m�Z�m�Z�m�Z�dd)l�m�Z�m�Z�dd*l�m�Z�dd+l�m�Z�m�Z�m�Z�dd,l�m�Z�dd-l�m�Z�d.d/�Z�d0d1�Z�d2d3�Z�d4d5�Z�d6d7�Z�e�d8d9��Z�e�d:d;��Z�e�d<d=��Z�e�d>d?��Z�e�d@dA��Z�e�dBdC��Z�e�dDdE��Z�e�dFdG��Z�dHdI�Z�dJdK�Z�dLdM�Z�GdNdO�dOe"�Z�GdPdQ�dQe"�Z�e�e!dRdS�e�e!dTes�e�e!dUdV�e�dWdX��Z�dYdZ�Z�Gd[d\�d\�Z�e�d]d^��Z�e�e�d_�d`da���Z�e�dbdc��Z�e�e�e�dd�dedf����Z�e�eHdgg�e�dh�didj����Z�e�e�dk�dldm���Z�e�e�dk�dndo���Z�e�e�e�dd�dpdq����Z�e�e�dk�drds���Z�e�e�dk�dtdu���Z�e�e�dv�eHdgg�dwdx����Z�e�e�dv�eHdgg�dydz����Z�e�eƒeHdgd{g�d|d}����Z�e�e�eÃd~d�����Ze�e�eÃd�d������Ze�e�d��d�d�����Ze�e�d��d�d�����Ze�e�d��d�d�����Zd�d���Ze�e�e�d��d�d������Ze�e�d��d�d�����Ze�e�e�d��d�d������Ze�eHdgg�e�d��d�d������Z	e�e�d��d�d�����Z
e�e�e�d��d�d������Ze�e�d��d�d�����Ze�e�e�d��d�d������Z
e�e�e�d��d�d������Ze�e�d��d�d�����Ze�e�e�d��d�d������Ze�e�d��d�d�����Ze�e�e�d��d�d������Ze�e�e�d��d�d������Ze�e�e�d��d�d������Ze�e�d��d�d�����Ze�e�e�d��d�d������Ze�e�e�d��d�d������Ze�e�dƒd�dĄ���Ze�e�e�dŃd�dDŽ����Ze�e�e�dȃd�dʄ����Ze�e�d˃d�d̈́���Ze�e�e�d΃d�dЄ����Ze�e�dуd�dӄ���Ze�e�e�dԃd�dք����Ze�e�e�dуd�d؄����Ze�e�d�dڄ���Z e�e�e�dۃd�d݄����Z!e�e�dۃd�d߄���Z"�d4d�d��Z#e�e�e�dۃd�d�����Z$e�e�dۃd�d����Z%e�e�d�d�d����Z&e�e�e�d�eHdgg�d�d������Z'e�e�d�d�d����Z(e�e�e�d�d�d�����Z)e�e�e�d�d�d�����Z*e�e�d�d�d�����Z+e�e�e�d��d�d������Z,e�e�e�d��d�d������Z-e�e�d��d�d�����Z.e�e�eǐd��d�d�����Z/e�e�eǐd��d�d�����Z0e�eǐd��d�d����Z1e�e�eǐd	��d
�d�����Z2e�e�eǐd��d
�d�����Z3e�eƐd��d�d����Z4e�e�eƐd��d�d�����Z5e�e�eƐd��d�d�����Z6e�eĐd�d����Z7e�e�eƐd��d�d�����Z8e�eƐd��d�d����Z9�d�d��Z:e�e�eƐd��d �d!�����Z;e�eƐd��d"�d#����Z<e�eƐd$��d%�d&����Z=e�e�eƐd$�eHdgg��d'�d(������Z>�d)�d*��Z?e�eƐd+��d,�d-����Z@e�eǐd.��d4�d/�d0����ZAe�eHdgg�e�dh��d1�d2�����ZBe�e�e�dh��d3�d4�����ZCeŐd5�d6���ZDe�eƐd7��d8�d9����ZEe�eĐd:�d;����ZF�d<�d=��ZGe�eĐd>�d?����ZH�d@�dA��ZIeŐdB�dC���ZJe�eƐdD��dE�dF����ZKeŐdG�dH���ZLeŐdI�dJ���ZMe�e�eM��dK�dL�����ZNe�e�eHdgg��dM�dN�����ZOeŐdO�dP���ZPe�eǐdQ�eHdgg��dR�dS�����ZQe�eĐdT�dU����ZReŐdV�dW���ZSe�eĐdX�dY����ZTeŐdZ�d[���ZUe�eƐd\��d]�d^����ZVeŐd_�d`���ZWe�eĐda�db����ZXe�eĐdc�dd����ZYe�e�eL��de�df�����ZZeŐdg�dh���Z[eŐdi�dj���Z\eŐdk�dl���Z]e�eƐdm�eHdgg��dn�do�����Z^e�eƐdm��dp�dq����Z_eŐdr�ds���Z`e�eHdgg�eƐdm��dt�du�����Zae�eHdgg��dv�dw����Zbe�eǐdx�eHdgg��dy�dz�����ZceŐd{�d|���ZdeŐd}�d~���ZeeŐd�d����ZfeŐd��d����ZgeŐd��d����ZheŐd��d����ZieŐd��d����ZjeŐd��d����ZkeŐd��d����Zle�e�d���d��d�����Zme�d��eF�d��d�����ZneŐd��d����Zoe�d��eF�d��d�����ZpeŐd��d����ZqeŐd��d����Zre�eǐd���d��d�����ZseŐd��d����ZteŐd��d����ZueŐd��d����ZveŐd��d����ZweŐd��d����ZxeŐd��d����ZyeŐd��d����ZzeŐd��d����Z{e�eǐd���d��d�����Z|e�eǐd���d��d�����Z}e�e�eǐd���d��d������Z~e�e�eǐd���d��d������Ze�e�eǐd���d��d������Z�e�e�eǐd���d��d������Z�e�eǐd���d��d�����Z�e�e�eǐd���d��d„����Z�e�e�eǐdÃ�dĐdń����Z�e�e�eǐdÃ�dƐdDŽ����Z�e�e�eǐdÃ�dȐdɄ����Z�e�e�eǐdÃ�dʐd˄����Z��d̐d̈́�Z�e�e�eǐd΃�dϐdЄ����Z�e�eǐdу�dҐdӄ���Z�e�eĐdԐdՄ���Z�e�eĐd֐dׄ���Z�e�eĐdؐdل���Z�e�eĐdڐdۄ���Z�e�eĐdܐd݄���Z�e�eĐdސd߄���Z�e�eĐd�d����Z�e�eĐd�d����Z�eŐd�d���Z�e�eǐd��d�d����Z�e�e�eǐd��d�d�����Z�e�e�eǐd��d�d�����Z�e�e�eǐd��d�d�����Z�eŐd�d���Z�eŐd�d����Z��d��d���Z�eŐd��d����Z�e�eǐd���d��d�����Z�e�eǐd���d��d�����Z�eŐd�d���Z��d�d��Z�e�eĐd�d����Z�e�e�eǐd��d�d�����Z��d	�d
��Z��d�d��Z��d
�d��Z�e�eǐd��d�d����Z�eŐd�d���Z�eŐd�d���Z�e�eĐd�d����Z�e�e�eǐd��d�d�����Z�e�e�eǐd��d�d�����Z�e�eHdgg�eǐd��d�d �����Z�eŐd!�d"���Z�eŐd#�d$���Z�e�e�eǐd%��d&�d'�����Z�eŐd(�d)���Z�e�eĐd*�d+����Z�e�e�eǐd,��d-�d.�����Z�e�e�eǐd/��d0�d1�����Z�e�eĐd2�d3����Z�dS(5zO
views.py

This module is used to map url pattens with django views or methods
�N)�datetime�	timedelta)�	MIMEImage)�path)�parse_qs�unquote�	urlencode)�forms)�apps)�settings)�messages)�authenticate�login�logout)�Group�
Permission�User)�PasswordResetConfirmView�PasswordResetView)�ContentFile)�EmailMultiAlternatives)�call_command)�	Paginator)�ProtectedError�Q)�Http404�HttpResponse�HttpResponseRedirect�JsonResponse)�get_object_or_404�redirect�render)�render_to_string)�reverse�reverse_lazy)�timezone)�
strip_tags)�	localdate)�gettext)�csrf_exempt)�require_http_methods)�ConfiguredEmailBackend)�shift_request_change_permission�#work_type_request_change_permission)�CompanyLeaveFilter�
HolidayFilter�
PenaltyFilter�RotatingShiftAssignFilters�RotatingShiftRequestReGroup�RotatingWorkTypeAssignFilter�RotatingWorkTypeRequestReGroup�ShiftRequestFilter�ShiftRequestReGroup�WorkTypeRequestFilter�WorkTypeRequestReGroup),�AnnouncementExpireForm�AssignPermission�AssignUserGroup�AuditTagForm�ChangePasswordForm�CompanyForm�CompanyLeaveForm�DepartmentForm�
DriverForm�DynamicMailConfForm�DynamicMailTestForm�DynamicPaginationForm�EmployeeShiftForm�EmployeeShiftScheduleForm�EmployeeShiftScheduleUpdateForm�EmployeeTypeForm�HolidayForm�HolidaysColumnExportForm�JobPositionForm�JobPositionMultiForm�JobRoleForm�MailTemplateForm�MultipleApproveConditionForm�PassWordResetForm�ResetPasswordForm�RotatingShiftAssign�RotatingShiftAssignExportForm�RotatingShiftAssignForm�RotatingShiftAssignUpdateForm�RotatingShiftForm� RotatingWorkTypeAssignExportForm�RotatingWorkTypeAssignForm� RotatingWorkTypeAssignUpdateForm�RotatingWorkTypeForm�ShiftAllocationForm�ShiftRequestColumnForm�ShiftRequestCommentForm�ShiftRequestForm�TagsForm�
UserGroupForm�WorkTypeForm�WorkTypeRequestColumnForm�WorkTypeRequestCommentForm�WorkTypeRequestForm)
�choosesubordinates�closest_numbers�export_data�filtersubordinates�filtersubordinatesemployeemodel�format_date�generate_colors�get_key_instances�get_pagination�is_reportingmanager�
paginator_qry�random_color_generator�sortby) �	WEEK_DAYS�WEEKS�Announcement�AnnouncementExpire�AnnouncementView�BaserequestFile�BiometricAttendance�Company�
CompanyLeaves�DashboardEmployeeCharts�
Department�DynamicEmailConfiguration�DynamicPagination�
EmployeeShift�EmployeeShiftDay�EmployeeShiftSchedule�EmployeeType�Holidays�HorillaMailTemplate�JobPosition�JobRole�MultipleApprovalCondition�MultipleApprovalManagers�
RotatingShift�RotatingWorkType�RotatingWorkTypeAssign�ShiftRequest�ShiftRequestComment�Tags�WorkType�WorkTypeRequest�WorkTypeRequestComment)�EmployeeFilter)�ActiontypeForm� EmployeeGeneralSettingPrefixForm)�
Actiontype�DisciplinaryAction�Employee�EmployeeGeneralSetting�EmployeeWorkInformation)�delete_permission�duplicate_permission�hx_request_required�login_required�manager_can_enter�permission_required)�group_by_queryset)�APPS�DB_INIT_PASSWORD�DYNAMIC_URL_PATTERNS�FILE_STORAGE�NO_PERMISSION_MODALS)�get_horilla_model_class�remove_dynamic_url)�HistoryTrackingFieldsForm)�AccountBlockUnblock�AuditTag�HistoryTrackingFields)�Notification)�notifycC�
t|d�S)z
    Custom 404 method
    z404.html�r!��request�r��/var/www/erp/base/views.py�	custom404�s
r�cCs8|jj}z
|jjj}W||kStytd�YSw)z�
    If the instance have employee id field then you can use this method to know the request
    user employee is the reporting manager of the instance
    z,This Employee Dont Have any work information)�user�employee_get�employee_id�employee_work_info�reporting_manager_id�	Exceptionr)r��instance�manager�employee_work_info_managerr�r�r��is_reportingmanger�s���r�cCsDtj��}|s d}tjjdd�}|D]}t|d�rd}|Sq|S)a�
    Determines if the database initialization process should be triggered.

    This function checks whether there are any users in the database. If there are no users,
    or if there are superusers without associated employees, it indicates that the database
    needs to be initialized.

    Returns:
        bool: True if the database needs to be initialized, False otherwise.
    T)�is_superuserr�F)r�objects�exists�filter�hasattr)�initialize_database�
superusersr�r�r�r��initialize_database_condition�s
�r�c	Cs�t�rT|jdkrP|j�d�tkrHgd�}dddddd	d
dd�}|d
d�|��D�7}|D]}t�tj	d|�}t
d|�q,t�|t
d��tt�St�|t
d��tt�Std�S)N�POST�load_data_password)zuser_data.jsonzemployee_info_data.jsonzbase_data.jsonzwork_info_data.jsonzattendance_data.jsonzleave_data.jsonzasset_data.jsonzrecruitment_data.jsonzonboarding_data.jsonzoffboarding_data.jsonz
pms_data.jsonzpayroll_data.json)�
attendance�leave�asset�recruitment�
onboarding�offboarding�pms�payrollcSsg|]\}}t�|�r|�qSr�)r
�is_installed)�.0�app�filer�r�r��
<listcomp>�s��z&load_demo_database.<locals>.<listcomp>�	load_data�loaddatazDatabase loaded successfully.zDatabase Authentication Failed�/)r��methodr��getr��itemsr�joinr�BASE_DIRrr�success�_�errorr �home)r��
data_files�
optional_appsr��	file_pathr�r�r��load_demo_database�s0
���r�cCsbt�r-|jdkr(|j�d�}ddlm}||krtt�St�	|t
d��td�St|d�Std�S)	z�
    Handles the database initialization process via a user interface.

    Parameters:
        request (HttpRequest): The request object.

    Returns:
        HttpResponse: The rendered HTML template or a redirect response.
    r��passwordr)r�z8The password you entered is incorrect. Please try again.�)<script>window.location.reload()</script>z%initialize_database/horilla_user.htmlr�)
r�r��_postr��horilla.horilla_settingsr�r �initialize_database_userr�warningr�rr!)r�r��db_passwordr�r�r�r�s

�
r�cCs |jdkr�|j�d�}|�d�}|�d�}|�d�}||kr#t|d�S|�d�}|�d�}|�d	�}|�d
�}|�d�}	tjj|d���}
|
rPt|
d
�sP|
�	�tjj
|||d�}
t�}|
|_||_
||_||_||_|	|_|��t|||d�}
t||
�t|ddtddid�i�St|d�S)z�
    Handles the user creation step during database initialization.

    Parameters:
        request (HttpRequest): The request object.

    Returns:
        HttpResponse: The rendered HTML template for company creation or user signup.
    r�r��usernamer��confirm_passwordz,initialize_database/horilla_user_signup.html�	firstname�lastname�badge_id�email�phone�r�r�)r�r�r��r�r��(initialize_database/horilla_company.html�form�hqT��initial)r��__dict__r�r!rr�r��firstr��delete�create_superuserr��employee_user_idr��employee_first_name�employee_last_namer�r��saver
rr>)r��	form_datar�r�r��
first_name�	last_namer�r�r�r��employeer�r�r�r�*sD









�
�
r�cCs�t�}|jdkr8t|j|j�}|��r8|��}z|jj}||j_	|j��WnYt
|ddtd|id�i�St
|dd|i�S)z�
    Handles the company creation step during database initialization.

    Parameters:
        request (HttpRequest): The request object.

    Returns:
        HttpResponse: The rendered HTML template for department creation or company creation.
    r�z+initialize_database/horilla_department.htmlr��
company_idr�r�)r>r�r��FILES�is_validrr�r�r�rr!r@)r�r��companyrr�r�r��initialize_database_companyYs"
�rcCsntj��}tdtj��id�}|jdkr.t|j�}|��r.|j	�
d�}|��td|id�}t|d||d��S)z�
    Handles the department creation step during database initialization.

    Parameters:
        request (HttpRequest): The request object.

    Returns:
        HttpResponse: The rendered HTML template for department creation.
    rr�r��0initialize_database/horilla_department_form.html�r��departments)
r|r��allr@ryr�r�r�r	�cleaned_datar�rr!)r�rr�r
r�r�r��initialize_database_departmentws


�rcCs�t�|�}t|d�}|jdkr5t|j|d�}|��r5|j�d�}|��t	|dtd|id�tj
��d��St	|d||tj
��d��S)a+
    Handles editing of an existing department during database initialization.

    Parameters:
        request (HttpRequest): The request object.
        obj_id (int): The ID of the department to be edited.

    Returns:
        HttpResponse: The rendered HTML template for department editing.
    �r�r�rrr�r
)r��
departmentr)r|�findr@r�r�r	rr�rr!r�r)r��obj_idrr�r
r�r�r��initialize_department_edit�s,


����rcCs,t�|�}|r|��ndtt�Stt�S)a3
    Handles the deletion of an existing department during database initialization.

    Parameters:
        request (HttpRequest): The request object.
        obj_id (int): The ID of the department to be deleted.

    Returns:
        HttpResponse: A redirect response to the department creation page.
    N)r|rr�r r)r�rrr�r�r��initialize_department_delete�s

�rcCs�tj��}td|id�}|jdkr5t|j�}|��r(|��tdtj��id�}t|d|t	j�
�|d��St|d|t	j�
�|d��S)z�
    Handles the job position creation step during database initialization.

    Parameters:
        request (HttpRequest): The request object.

    Returns:
        HttpResponse: The rendered HTML template for job position creation.
    rr�r��2initialize_database/horilla_job_position_form.html�r��
job_positionsr
z-initialize_database/horilla_job_position.html)ryr�r�rLr�r�r	rr!r�r)r�r
r�r�r�r�� initialize_database_job_position�s(


��	�rcCs�tj��}t�|�}t|d�}|jdkr5t|j|d�}|��r5|�	�t
|dtd|id�tj��|d��St
|d||tj��|d��S)a1
    Handles editing of an existing job position during database initialization.

    Parameters:
        request (HttpRequest): The request object.
        obj_id (int): The ID of the job position to be edited.

    Returns:
        HttpResponse: The rendered HTML template for job position editing.
    rr�rrr�r)r��job_positionrr
)
ryr�r�r�rrKr�r�r	rr!rLr)r�rr
rr�r�r�r��initialize_job_position_edit�s0



��	��rcCsztj��}t�|�}|r|��ndt|dtdtj��id�tj��|d��St|dtdtj��id�tj��|d��S)a9
    Handles the deletion of an existing job position during database initialization.

    Parameters:
        request (HttpRequest): The request object.
        obj_id (int): The ID of the job position to be deleting.

    Returns:
        HttpResponse: The rendered HTML template for job position creating.
    Nrrr�r)	ryr�r�r�rr�r!rLr)r�rr
rr�r�r��initialize_job_position_deletes0

�������rc	Cs\|jdkr�|j�d�dkr|j�d�n|j�d���}|j�d�}|j�dd�}|j��}|�dd�t|�}t|||d�}|sft	j
j|d	���}|rZ|j
sZt�|td
��td�St�|td��td�St|d
d�}|dur|t�|td��td�S|j
s�t�|td��td�St||�t�|td��|r�|d|��7}t|�St|ddt�i�S)z0
    Handles user login and authentication.
    r�r��Adminr��nextr�Nr�r�z'Access Denied: Your account is blocked.zInvalid username or password.rr�z>An employee related to this user's credentials does not exist.zGThis user is archived. Please contact the manager for more information.zLogin successful.�?z
login.htmlr�)r�r�r��lower�GET�dict�poprr
rr�r�r��	is_activerr�r�r�r �getattrrr�r!r�)	r�r�r��next_url�query_params�paramsr��user_objectrr�r�r��
login_user.sL
,

����
�r,cCsZ|jdj}tjj|jd�}|��dur+|j|��jd���dur+||B}||jd_|S)zx
    This method is used to include the employee instance to the form
    Args:
        form: django forms instance
    r��r�N��id)�fields�querysetr�r�r�r�r�r/)r�r�r1rr�r�r��include_employee_instance`sr2cCr�)Nzreset_send.htmlr�r�r�r�r��reset_send_successos
r3c@s(eZdZdZdZeZed�Zdd�Z	dS)�HorillaPasswordResetViewz)
    Horilla View for Reset Password
    �forgot_password.html�reset-send-successc		Cs�t�}d}d}ttdd�}|r||krd}|r'|js't�|jtd��td�S|j	d}t
jj|d	��
�}|rr|j��|j|j|j|j|j|j|jd
�}|jdi|��|jjjrlt�|jtd��t|jj�dd
��Sttd��St�|jtd��td�S)N�$base.backends.ConfiguredEmailBackendT�
EMAIL_BACKEND�F�%Primary mail server is not configuredzforgot-passwordr�r���	use_https�token_generator�
from_email�email_template_name�subject_template_namer��html_email_template_name�extra_email_context�%Password reset link sent successfully�HTTP_REFERERr�r6zNo user found with the usernamer�)r+r'r�
configurationrr�r�r�r rrr�r�r��	is_securer=�$dynamic_from_email_with_display_namer?r@rArBrr��is_authenticatedr�r�METAr�r$�info)	�selfr��
email_backend�default�is_default_backendr8r�r��optsr�r�r��
form_valid|s<

�


�z#HorillaPasswordResetView.form_validN)
�__name__�
__module__�__qualname__�__doc__�
template_namerP�
form_classr$�success_urlrPr�r�r�r�r4ssr4c@s eZdZdZdZeZdd�ZdS)�EmployeePasswordResetViewz2
    Horilla View for Employee Reset Password
    r5c

Cs:zyt�}d}d}ttdd�}|r||krd}|r/|js/t�|jtd��t|jj	�
dd��WS|jd	}tj
j|d
���}|rf|j��|j|j|j|j|j|j|jd�}|jdi|��t�|jtd��n	t�|jtd
��t|jj	�
dd��WSty�}	zt�|jd�t|jj	�
dd��WYd}	~	Sd}	~	ww)Nr7Tr8r9Fr:rDr�r�r�r;rCzNo user with the given usernamezSomething went wrong.....r�)r+r'rrErr�r�r�rrIr�rrr�r�r�rFr=rGr?r@rArBrr�r�)
rKr�rLrMrNr8r�r�rO�er�r�r�rP�sB

�

� ��z$EmployeePasswordResetView.form_validN)rQrRrSrTrUrPrVrPr�r�r�r�rX�s
rXrUzreset_password.htmlrVrWr�cCs�|j}t|d�}|jdkrRt||j�}|��rJ|jd}|�|�|��t||j	|d�}t
|d�r9d|_|��t||�t
�|td��td�St|d	d
|i�St|dd
|i�S)a�
    Handles the password change process for a logged-in user.

    Args:
        request (HttpRequest): The HTTP request object containing metadata about
                               the request and user.

    Returns:
        HttpResponse: Renders the password change form if the request method is GET or
                      the form is invalid. If the form is valid and the password is changed
                      successfully, the page reloads with a success message.
    )r�r��new_passwordr��is_new_employeeFzPassword changed successfullyz*<script>window.location.href='/';</script>z#base/auth/password_change_form.htmlr�zbase/auth/password_change.html)r�r=r�r�r	r�set_passwordrr
r�r�r[rrr�r�rr!)r�r�r�rZr�r�r��change_password�s"





r]cCs|jrt|�t�}d|_|S)z-
    This method used to logout the user
    z�
        <script>
            localStorage.clear();
        </script>
        <meta http-equiv="refresh" content="0;url=/login">
    )r�rr�content)r��responser�r�r��logout_user�s
r`c@seZdZddd�ZdS)�Workinfo�returnNcCs||_||_|j|_dS�N)r�r�r/)rKrr�r�r��__init__szWorkinfo.__init__)rbN)rQrRrSrdr�r�r�r�rasrac	Cs�t��}|��}|t|d�}|tdd�}tjj|jjd�d}|j}t	�
���}d}|jjdkrB|jjj
|j
koA|jjj|jk}|�d�|�d�|j|d�}t|d|�S)	z2
    This method is used to render index page
    )�days��rrNz%Y-%m-%d)�first_day_of_week�last_day_of_week�charts�is_birthdayz
index.html)r�today�weekdayrr{r��
get_or_creater�r�r%�now�date�dob�month�day�strftimerjr!)	r�rl�
today_weekdayrhri�employee_chartsr�rk�contextr�r�r�r�s,����r��%employee.view_employeeworkinformationc
s�g}gd�}|j�dd�}t|tjj|dd�dd�}|D]%�t�fdd	�|D��}|d
kr@|d
dd�}�|d
�}|�|�q	qt|t	jjdd�dd�}|D]}	|�
dt|	d�dd
��qP|jdd�d�t
||j�d��}t|dd|i�S)N)�job_position_id�
department_id�work_type_id�employee_type_id�job_role_idr�r�locationr��mobile�shift_id�date_joining�contract_end_date�basic_salary�salary_hour�searchr9T)�+employee_id__employee_first_name__icontains�employee_id__is_activerx)r1�permc3s"�|]}t�|�durdVqdS)N�)r')r��
field_namergr�r��	<genexpr>Ts���z-employee_workinfo_complete.<locals>.<genexpr>��dz.1f)r�completed_field_count)�employee_work_info__isnull)r�rrg�0cSst|d�S)Nr�)�float��xr�r�r��<lambda>rsz,employee_workinfo_complete.<locals>.<lambda>)�key�pagezwork_info_complete.html�employees_with_pending)r#r�rhr�r�r��sum�appendrir��insertra�sortror!)
r�r��fields_to_focusr��employees_workinfosr��percent�
employee_info�emps�empr�rgr��employee_workinfo_complete2sV���������r�cCr�)z=
    This method is used to render setting page template
    z
settings.htmlr�r�r�r�r��common_settingss
r�zauth.add_groupcCs�g}t}t}t�}|D]#}g}t|�D]}|�|jj��|jjd��q|�|��|d��q|j	dkrMt|j
�}|��rM|��t
�|td��td�St|d|||d��S)z 
    Group assign htmx view
    ��verbose_name�
model_name�r��
app_modelsr�zUser group created.r��base/auth/group_assign.html��permissionsr��no_permission_models)r�r�r`�get_models_in_appr��_metar��
capitalizer�r�r�r	rrr�r�rr!)r�r�r
r�r��app_namer��modelr�r�r��user_group_table�s6
��

��r�r�zauth.add_permissioncCs�|jd}tjj|d�}t|j|d�}|��r"|��tddd��S|j�d�rH|jd}t|�d	krA||_	|��td
dd��Stddd��S|j
�d�}|s\|j��td
dd��Stddd��S)�8
    This method is used to remove user permission.
    r/r.r�Updated the permissionsr���message�type�name_update�name�zName updatedzAt least 4 characters requiredr��All permission clearedrJ�Something went wrong�danger)
r�rr�r�r`r	rr�lenr�rr��clear)r��group_idr�r�r��permsr�r�r��update_group_permission�s(
	
�
r�zauth.view_groupc	
Cs�g}t}t}t�}|D]#}g}t|�D]}|�|jj��|jjd��q|�|��|d��qt	j
��}t|d||t
||j�d��|d��S)�=
    This method is used to create user permission group
    r�r�zbase/auth/group.htmlr��r�r��groupsr�)r�r�r`r�r�r�r�r�r�rr�rr!ror#r�)	r�r�r
r�r�r�r�r�r�r�r�r��
user_group�s.
��
��r�c

Cs�g}t}t}t�}|D]#}g}t|�D]}|�|jj��|jjd��q|�|��|d��qd}|j	�
d�r>t|j	d�}tj
j|d�}	t|d||t|	|j	�
d��|d��S)	r�r�r�r9r���name__icontainszbase/auth/group_lines.htmlr�r�)r�r�r`r�r�r�r�r�r�r#r��strrr�r�r!ro)
r�r�r
r�r�r�r�r�r�r�r�r�r��user_group_search�s4
����r�cCs�|j�d�}t|tjj|d�jddd�d�d�}|jr?|jd}t||j�d�d��}|�	�r?|�
�t�|t
d	��td
�St|d||d��S)
z@
    This method is used to assign user group to the users.
    �group)�employee_user_id__groups__idr/T��flat)r�rr�rzUser group assigned.r�z base/auth/group_user_assign.html)r�r�)r#r�r;r�r�r��values_listr��getlistr	rrr�r�rr!)r�r�r�r�r�r��group_assigns0����
��r�cCsXd}|j�d�dur|j�d�}tjj|d�}|j��}t|dt||j�d��|d��S)z7
    This method is used to search the user groups
    r9r�Nr�z base/auth/group_assign_view.htmlr�)r��pd)r#r�rr�r�rr!ro)r�r�r��
previous_datar�r�r��group_assign_view3s
�r�cCs8d}|j�d�dur|jd}tj��}t|dd|i�S)zD
    This method is used to render template for view all groups
    r9r�Nr��data)r#r�rr�r�r!)r�r�r�r�r�r��user_group_viewEs


r��change_groupcCs:tjjdd�}tjjdd�}|j�|�t|j�dd��S)zy
    This method is used to remove permission from group.
    args:
        pid: permission id
        gid: group id
    r�r.�rDr�)rr�r�rr��removerrI)r��pid�gidr��
permissionr�r�r��user_group_permission_removeR�
r�cCs:tjj|d�}tjj|d�}|j�|�t|j�dd��S)z�
    This method is used to remove an user from group permission.
    args:
        uid: user instance id
        gid: group instance id
    r.rDr�)rr�r�r�user_setr�rrI)r��uidr�r�r�r�r�r��group_remove_userbr�r��DELETEc
Ks�|�d�}|�d�}d}z|jj|d�}|��t�|td��|��WnR|jy=d}t�|td��|j	j
��Yn:tyv}z.t�}|j
D]
}	|�t|	j	j
����qJd�|�}
d}t�|td	��||
��fWYd
}~nd
}~wwt�d�r�|dkr�tdd
d�}|j��}|��r�|j��}
|d|
}t|�Std�S|r�|j��}
|d|
}t|�S|�d�r�|r�d}n|�d�dur�d}n|�d�}t|��St|j�dd��S)a�
    Handles the deletion of an object instance from the database.

    Args:
        request (HttpRequest): The HTTP request object containing metadata about
                               the request and user.
        obj_id (int): The ID of the object to be deleted.
        **kwargs: Additional keyword arguments including:
            - model (Model): The Django model class to which the object belongs.
            - redirect_path (str): The URL path to redirect to after deletion.
    Returns:
        HttpResponse: Redirects to the specified `redirect_path` or reloads the
                      previous page. In case of a ProtectedError, it shows an error
                      message indicating that the object is in use.
    r��
redirect_pathFr.z%The {} has been deleted successfully.Tz
{} not found.z, z!This {} is already in use for {}.Nr�z/pms/filter-key-result/�	keyresult��	app_labelr�r!r�rr9rDr�)r�r�r�rr�r��format�DoesNotExistr�r�r�r�set�protected_objects�addr�r�r
r�r�rr�r#rr rrrI)r�r�kwargsr�r��delete_errorr�rY�model_verbose_names_set�obj�model_names_str�	KeyResult�key_resultsr��return_partr�r�r��
object_deletersX

�

���





r�c
Ks|d}|d}|d}|jj|d�}||d�}|jdkrS|j��D]&\}}	t|	tj�rH|	jr3|	j}
n
|j�|d��d�}
|
|j|<|
|j|_q"t	|j
d	�rSd
|j
_|jdkrr||j�}|�
�rr|jdd
�}d
|_|��td�S|�dd�|d|ddi}t|||�S)aX
    Handles the duplication of an object instance in the database.

    Args:
        request (HttpRequest): The HTTP request object containing metadata about
                               the request and user.
        obj_id (int): The ID of the object to be duplicated.
        **kwargs: Additional keyword arguments including:
            - model (Model): The Django model class to which the object belongs.
            - form (Form): The Django form class used to handle the object data.
            - template (str): The template to render for the duplication process.
            - form_name (str, optional): The name to use for the form in the template context.

    Returns:
        HttpResponse: Renders the duplication form on GET requests and, on successful
                      POST, reloads the page after saving the duplicated object.
    r�r��templater.rr#r9z (copy)r/Nr�F��commitr��	form_namer�	duplicateT)r�r�r�r0r��
isinstancer	�	CharFieldr�r�r�r/r�r	rrr!)
r�rr�r�rVr��original_objectr�r��field�
initial_value�
new_objectrwr�r�r��object_duplicate�s8


�

�rcKs*|jdkr�|d}|d}|d}|�d�}|d}|�d�}|j�d�}|r�t|�d	�d
�d}	|�d	d�d�d	|	��}
|�}|�|	��}|rd|d
krdtjtjd|d|��d�d�dd�|j	|<ntj
|j��tj
d|d|��d�d�d|d�|j	|<|	||��||
d�}
t||
�}t|�St�S)a_
    Handles the dynamic addition and removal of form fields in a Django form.

    Args:
        request (HttpRequest): The HTTP request object containing metadata about
                               the request and user.
        **kwargs: Additional keyword arguments including:
            - model (Model): The Django model class used for `ModelChoiceField`.
            - form_class (Form): The Django form class to which dynamic fields will be added.
            - template (str): The template used to render the newly added field.
            - empty_label (str, optional): The label to show for empty choices in a `ModelChoiceField`.
            - field_name_pre (str): The prefix for the dynamically generated field names.
            - field_type (str, optional): The type of field to add, either "character" or "model_choice".

    Returns:
        HttpResponse: Returns the HTML for the newly added field, rendered in the context of the
                      specified template. If the request is not POST or if no valid HTMX target
                      is provided, it returns an empty HTTP response.
    r�r�rVr��empty_label�field_name_pre�
field_type�HTTP_HX_TARGETr����r�r�	characterzoh-input w-100�id_��classr�r/��attrsF)�widget�required�oh-select oh-select-2 mb-3)r1rr
r)�field_counts�
field_html�current_hx_target�next_hx_target)r�r�rI�int�split�rsplitr	r��	TextInputr0�ModelChoiceFieldr�r�Select�	as_widgetr"r)r�r�r�rVr�rrr�	hx_targetrrr�r�rwrr�r�r��add_remove_dynamic_fields�sT


������
�
rz#base.view_dynamicemailconfigurationcCs6tj��}d}tjjdd���rd}t|d||d��S)NT��
is_primaryFz!base/mail_server/mail_server.html)�mail_servers�primary_mail_not_exist)r}r�rr�r�r!)r�rrr�r�r��mail_server_conf4s
��r cCsh|j�d�}t�}|jdkr�t|j�}|��r�|jd}td�}d}t|�}t	�}t
jj|d��
�}||_zDt|||j|g|d�}	|	�|d�t�tjd	�}
t|
d
��}t|���}|�dd�|	�|�Wd�n1sowY|	��Wn%ty�}
zt�|d
�td�t|
�g��t d�WYd}
~
Sd}
~
wwt�!|td��t d�St"|d||d��S)N�instance_idr��to_emailzTest mail from Horillaa�
            <html>
                <body style="font-family: Arial, sans-serif; margin: 0; padding: 0;">
                    <table align="center" width="600" cellpadding="0" cellspacing="0" border="0" style="border: 1px solid #e0e0e0; border-radius: 10px; overflow: hidden;">
                        <tr>
                            <td align="center" bgcolor="#4CAF50" style="padding: 20px 0;">
                                <h1 style="color: #ffffff; margin: 0;">Horilla</h1>
                            </td>
                        </tr>
                        <tr>
                            <td style="padding: 20px;">
                                <h3 style="color: #4CAF50;">Email tested successfully</h3>
                                <b><p style="font-size: 14px;">Hi,<br>
                                    This email is being sent as part of mail sever testing from Horilla.</p></b>
                                <img src="cid:unique_image_id" alt="Test Image" style="width: 200px; height: auto; margin: 20px 0;">
                            </td>
                        </tr>
                        <tr>
                            <td bgcolor="#f0f0f0" style="padding: 10px; text-align: center;">
                                <p style="font-size: 12px; color: black;">&copy; 2025 Growthnatives, Inc.</p>
                            </td>
                        </tr>
                    </table>
                </body>
            </html>
            r.)�
connectionz	text/htmlzimages/ui/horilla-logo.png�rbz
Content-IDz<unique_image_id>� zSomething went wrong :r�zMail sent successfullyz%base/mail_server/form_email_test.html)r�r!)#r#r�rCr�r�r	rr�r&r+r}r�r�r�rErrG�attach_alternativerr�r�STATIC_ROOT�openr�read�
add_header�attach�sendr�rr�r�rr�r!)r�r!r��email_to�subject�html_content�text_contentrL�emailconfig�msg�
image_path�img�msg_imgrYr�r�r��mail_server_test_emailEs\


��������r6z%base.delete_dynamicemailconfigurationcCs�|j�d�}d}|D]}tjj|d���}|jrd}q
|r0tjj|d���t�	|d�t
d�Stj����dkrCt�
|d	�t
d�Stj��jdd
�}t|d|td�d
��S)z3
    This method is used to delete mail server
    �idsTr.F��id__inz!Mail server configuration deletedr�r�z?You have only 1 Mail server configuration that can't be deletedrz"base/mail_server/replace_mail.htmlzCan't Delete)�mails�title)r#r�r}r�r�r�rr�rr�rr�countr��excluder!r�)r�r7r�r/r1r:r�r�r��mail_server_delete�s2����r>cCsR|j�d�}tjj|d�}d|_|��tjjdd�����t	�
|d�td�S)z<
    This method is used to replace primary mail server
    �replace_mailr.Trz*Primary Mail server configuration replacedzmail-server-conf)r�r�r}r�rrr�r�r�rr�r )r��emailconfig_id�email_configr�r�r��replace_primary_mail�srBz"base.add_dynamicemailconfigurationcCsr|j�d�}d}|rtjj|d���}t|d�}|jdkr0t|j|d�}|�	�r0|�
�td�St|d||d��S)Nr!r.rr�r�zbase/mail_server/form.html)r�r�)
r#r�r}r�r�r�rBr�r�r	rrr!)r�r!r�r�r�r�r��mail_server_create_or_update�s

�rCzbase.view_horillamailtemplatecCs>tj��}t�}|��rd}nd}|��}t|||||d��S)zN
    This method will render template to disply the offerletter templates
    zmail/view_templates.htmlzmail/empty_mail_template.html)�	templatesr��searchWords)r�r�rrNr��get_template_languager!)r�rDr�r�rEr�r�r��view_mail_templates�s

�rGzbase.change_horillamailtemplatecCsptjj|d�}t|d�}|��}|jdkr.t|j|d�}|��r.|��t	�
|d�td�St|d|d|d��S)	zB
    This method is used to display the template/form to edit
    r.rr�zTemplate updatedr�zmail/htmx/form.htmlF)r�r�rE)
r�r�r�rNrFr�r�r	rrr�rr!)r�rr�r�rEr�r�r��view_mail_template�s


�rHzbase.add_horillamailtemplatecCsH|jdkr t|j�}|��r |��}|��t�|d�td�Stt	�S)z<
    This method is used to create offerletter template
    r�zTemplate createdr�)
r�rNr�r	rrr�rr rG)r�r�r�r�r�r��create_mail_templatess

rIzbase.delete_horillamailtemplatecCs2|j�d�}tjj|d���}t�|d�tt	�S)Nr7r8zTemplate deleted)
r#r�r�r�r�r�rr�r rG)r�r7�resultr�r�r��delete_mail_templatessrKzbase.add_companycCsbt�}tj��}|jdkr(t|j|j�}|��r(|��t	�
|td��td�St
|d||d��S)z^
    This method render template and form to create company and save if the form is valid
    r�z&Company has been created successfully!r��base/company/company_form.html)r��	companies)r>ryr�rr�r�rr	rrr�r�rr!)r�r�rMr�r�r��company_create"s

�rNzbase.view_companycC�tj��}t|dd|i�S)z4
    This method used to view created companies
    zbase/company/company.htmlrM)ryr�rr!)r�rMr�r�r��company_view<s
rPzbase.change_companycKsntjj|d�}t|d�}|jdkr.t|j|j|d�}|��r.|��t	�
|td��td�St
|d||d��S)z[
    This method is used to update company
    args:
        id : company instance id

    r.rr�zCompany updatedr�rL)r�r
)ryr�r�r>r�r�rr	rrr�r�rr!)r�r/r�r
r�r�r�r��company_updateGs


�rQzbase.add_departmentcC�Xt�}|jdkr$t|j�}|��r$|��t�}t�|td��td�St	|dd|i�S)zD
    This method renders form and template to create department
    r�z)Department has been created successfully!r��$base/department/department_form.htmlr�)
r@r�r�r	rrr�r�rr!�r�r�r�r�r��department_create^s

��rUzbase.view_departmentcCrO)z%
    This method view department
    zbase/department/department.htmlr)r|r�rr!)r�rr�r�r��department_viewws
��rVzbase.change_departmentcK�ft�|�}t|d�}|jdkr*t|j|d�}|��r*|��t�|t	d��t
d�St|d||d��S)z`
    This method is used to update department
    args:
        id : department instance id
    rr�zDepartment updated.r�rS)r�r)r|rr@r�r�r	rrr�r�rr!)r�r/r�rr�r�r�r��department_update�s
	

�rXzbase.view_jobpositioncCsjtj��}d}tj��rd}t�}|jdkr+t|j�}|��r+|�	�t
�|td��t
|d|||d��S)z2
    This method is used to view job position
    FTr��+Job Position has been created successfully!z#base/job_position/job_position.html)r�r�jobs)r|r�rr�r�rKr�r�r	rrr�r�r!)r�rrZr�r�r�r�r�s




�rzbase.add_jobpositioncCsp|j�d�r|j�d�nd}t�}|jdkr/t|j�}|��r/|��t�|t	d��t
d�St|d||d��S)z4
    This method is used to create job position
    �dynamicr9r�rYr��(base/job_position/job_position_form.html�r�r[)r#r�rLr�r�r	rrr�r�rr!�r�r[r�r�r�r��job_position_creation�s

��r_zbase.change_jobpositioncK�jt�|�}t|d�}|jdkr,t|j|d�}|��r,|jdd�t�|t	d��t
d�St|d||d��S)	ze
    This method is used to update job position
    args:
        id : job position instance id

    rr�Tr�zJob position updated.r�r\)r�r)r�rrKr�r�r	rrr�r�rr!)r�r/r�rr�r�r�r��job_position_update�s



�razbase.add_jobrolecCs�|j�d�}t�}|jdkrLt|j�}|jjr*|��r*|jdd�t	�
|td��n"|jjsL|j�
d�rL|j�d�rL|jdd�t	�
|td��td�St|d	||d
��S)z1
    This method is used to create job role.
    r[r�Tr�z'Job role has been created successfully!ry�job_roler�� base/job_role/job_role_form.htmlr])r#r�rMr�r�r��pkr	rrr�r�r�r�rr!r^r�r�r��job_role_create�s.

�
�
���rezbase.view_jobrolecCs.tj��}d}tj��rd}t|d||d��S)z/
    This method is used to view job role.
    FTzbase/job_role/job_role.html)rrb)r�r�rr�r�r!)r�rZrbr�r�r��
job_role_view
s

�rfzbase.change_jobrolecKr`)	zg
    This method is used to update job role instance
    args:
        id  : job role instance id

    rr�Tr�zJob role updated.r�rc)r�rb)r�rrMr�r�r	rrr�r�rr!)r�r/r�rbr�r�r�r��job_role_updates


��rgzbase.add_worktypecC�r|j�d�}t�}tj��}|jdkr/t|j�}|��r/|�	�t�}t
�|td��t
d�St|d|||d��S)z1
    This method is used to create work type
    r[r�z(Work Type has been created successfully!r��"base/work_type/work_type_form.html)r��
work_typesr[)r#r�rar�r�rr�r�r	rrr�r�rr!)r�r[r�rjr�r�r��work_type_create;s



�rkzbase.view_worktypecCrO)z/
    This method is used to view work type
    zbase/work_type/work_type.htmlrj)r�r�rr!)r�rjr�r�r��work_type_viewUs
�rlzbase.change_worktypecKrW)zh
    This method is used to update work type instance
    args:
        id : work type instance id

    rr�zWork type updated.r�ri)r��	work_type)r�rrar�r�r	rrr�r�rr!)r�r/r�rmr�r�r�r��work_type_updated�


�rnzbase.add_rotatingworktypecCs`t�}|jdkr$t|j�}|��r$|��t�}t�|td��td�St	|d|t
j��d��S)z>
    This method is used to create rotating work type   .
    r�zRotating work type created.r��9base/rotating_work_type/htmx/rotating_work_type_form.html)r��
rwork_type)
rZr�r�r	rrr�r�rr!r�r�rrTr�r�r��rotating_work_type_create~s

�rrzbase.view_rotatingworktypecC�t|ddtj��i�S)z<
    This method is used to view rotating work type   .
    z/base/rotating_work_type/rotating_work_type.htmlrq)r!r�r�rr�r�r�r��rotating_work_type_view��
�rtzbase.change_rotatingworktypecKrW)z{
    This method is used to update rotating work type instance.
    args:
        id : rotating work type instance id

    rr�zRotating work type updated.r�rp)r��r_type)r�rrZr�r�r	rrr�r�rr!)r�r/r��rotating_work_typer�r�r�r��rotating_work_type_update�s


�rx� base.view_rotatingworktypeassignc	Cs�ttjjdd�d�}tj��}|j�d�}t||d�}|jdd�}t�	dd�t
||j�d	��j
D��}t|d
|t
||j�d	��||tjd��S)zL
    This method is used to assign rotating work type to employee users
    T�r&�r1�-idry�r�cS�g|]}|j�qSr�r.�r�r�r�r�r�r�����z-rotating_work_type_assign.<locals>.<listcomp>r�z6base/rotating_work_type/rotating_work_type_assign.html)�f�rwork_type_assign�
assign_ids�	rwork_all�	gp_fields)r3r�r�r�r�qs�order_byrh�json�dumpsror#r��object_listr!r4r0)r�r�r�r�r�r�r�r��rotating_work_type_assign�s:�
�������r��base.add_rotatingworktypeassigncC�t�}|j�d�r|j�d�}td|id�}t||d�}|jdkrwt|j�}t||d�}|��rw|��|j�	d�}t
jj|d��
d�}dd	�|D�}tj|jj|d
ddd
ddtd�d�	t�|td��t|dd|i�}t|j�d�d�St|dd|i�S)z:
    This method is used to assign rotating work type
    �emp_idr�r�r�r�r8r�cSr~r�r-�r�rr�r�r�r���z1rotating_work_type_assign_add.<locals>.<listcomp>z#You are added to rotating work typeu=تمت إضافتك إلى نوع العمل المتناوبu2Sie werden zum rotierenden Arbeitstyp hinzugefügtz(Se le agrega al tipo de trabajo rotativou-Vous êtes ajouté au type de travail rotatif�infinite�employee-profile��	recipient�verb�verb_ar�verb_de�verb_es�verb_fr�iconr zRotating work type assigned.z@base/rotating_work_type/htmx/rotating_work_type_assign_form.htmlr��utf-8�#<script>location.reload();</script>)rXr#r�rYrer�r�r	rr�r�r�r��select_relatedr�r,r�r�r#rr�r�r!rr^�decode�r�r�r�employee_ids�	employees�usersr_r�r�r��rotating_work_type_assign_add��P

�����r�c	CsT|j��}t|j�j�d�}|j�d�}|j�d�r"|j�d�dvr(|jdd�}|j�d�dkr6|jdd�}t||d	�}|j�d
�rHt||d
�}d}t	|�}t
t|�|dkr�|d
ur�t|||j�d�d�}dd�|D�}g}|D]}|j
D]}	|�|	j�qvqqt�t|��}
d}nt||j�d��}t�dd�|j
D��}
t||||||
|d��S)zI
    This method renders template to view rotating work type objects
    r|r�r&)�true�unknownTrz�falseFry�orderbyz;base/rotating_work_type/rotating_work_type_assign_view.htmlr9Nr�cS�g|]}|d�qS��listr��r��entryr�r�r�r�6�z2rotating_work_type_assign_view.<locals>.<listcomp>z*base/rotating_work_type/htmx/group_by.htmlcSr~r�r.rr�r�r�r�Br�)r�r��filter_dictr�r�)r#rr3r�r�r�r�rhrqrrlr�r�r�r�r/r�r�r�ror!)r�r�r�r�r��	data_dict�list_values�id_list�valuer�r�r�r�r��rotating_work_type_assign_viewsR
�
�
����r�c
Cs|j��}|�dd�|��}tjj|d���}||d�}|j�d�}|r=t	�
|�}t||�\}}	||d<|	|d<||d<|j�dd�}
d	|d
<d	|d<|
r\|
�
d�r\d
|d
<d|d<n)|
r�dd�|
�d�D�}zt|d�}d|��|d
<d|d<Wn	ty�Ynwt|d|�S)zQ
    This view is used render detailed view of the rotating work type assign
    �
instances_idsNr.�r�r��previousr r�rDr9�close_hx_url�close_hx_targetzrotating-work-type-assign/z/rotating-work-type-assign-view�#view-containercS�g|]}|r|�qSr�r��r��partr�r�r�r�kr�z1rotating_work_individual_view.<locals>.<listcomp>r�r�/employee/shift-tab/�
#shift_targetz,base/rotating_work_type/individual_view.html)r#�copyr%rr�r�r�r�r�r��loadsrfrI�endswithrr�
ValueErrorr!)
r�r!�request_copyr�r�rw�assign_ids_jsonr��previous_id�next_idrD�
HTTP_REFERERSr�r�r�r��rotating_work_individual_viewRs8



�r��"base.change_rotatingworktypeassigncCs�tjj|d�}t|d�}t||d�}|jdkrFt|j|d�}t||d�}|��rF|��t	�
|td��t|dd|i�}t
|j�d�d	�St|dd|i�S)
zC
    This method is used to update rotating work type instance
    r.rr�r�z"Rotating work type assign updated.zGbase/rotating_work_type/htmx/rotating_work_type_assign_update_form.html�update_formr�r�)r�r�r�rYrer�r�r	rrr�r�r!rr^r�)r�r/�rotating_work_type_assign_objr�r_r�r�r�� rotating_work_type_assign_updateus0

����r�cCs>|j�d�dkrt�t�d�}t|d|d�St|tttdd�S)N�HTTP_HX_REQUESTr���
export_filter�export_columnsz=base/rotating_work_type/rotating_work_type_assign_export.html�rw�Rotating_work_type_assign�r�r��filter_classrV�	file_name)rIr�r3rWr!rgr��r�rwr�r�r�� rotating_work_type_assign_export�s ���r�cC��|j��}|�dd�|��}|j�dd�}|r#|dkr#td|���S|r[|dkr[|j�d�}t�|�}||vr=|�	|�t
t�|�|�\}}	d|	�d�}
d|�d	|��}t|
|�S|rj|d
krj|rjtd|���S|rptd�St|j�d
d��S)Nr�r�view-containerz /rotating-work-type-assign-view?�objectDetailsModalTargetz/rwork-individual-view/r�r!�&instances_ids=�shift_targetr�r�rD�
r#r�r%rrIr�r r�r�r�rfrr�r�rr�r�r�rr��instances_list�previous_instance�
next_instance�urlr*r�r�r��"rotating_work_type_assign_redirect�s,



�r�cCs�zEtt|d�}|jj}tjjd|jd�}|j|_|jr%|r%t�|d�n|�	�|jr0t
d�nt
d�}t�|t
d��|��t
|||�WStyVt�|t
d��Ynwt
|||�S)	z:
    Archive or un-archive rotating work type assigns
    r.T�r&r��Already on record is active�un-archived�archivedzRotating work type assign is {}�$Rotating work type assign not found.)rr�r�r/r�r�r&rr�rr�r�r�r�r)r�rrqr��employees_rwork_typesr�r�r�r��!rotating_work_type_assign_archive�s&�

��r�cCs�t�|jd�}|j�d�dk}|rtd�ntd�}d}|D]1}tjj|d�}tjjd|jd	�}|rD|�	�rDt
�|td
�j|jd��q||_
|��|d7}q|dkrat
�|td
�j||d��t|�S)zT
    This method is used to archive/un-archive bulk rotating work type assigns.
    r7r&r�r�r�rr.Tr�z3Rotating work type for {employee_id} already exists�r�r�z5Rotating work type for {count} employees is {message})r<r�)r�r�r�r�r�r�r�r�r�r�rr�r�r&rr�r�)r�r7r&r�r<r/r��employees_rwork_type_assignr�r�r��&rotating_work_type_assign_bulk_archive�s6���
��r�z"base.delete_rotatingworktypeassignc
C�|jd}t�|�}|D]B}ztjj|d�}|��t�|t	d�j
|jd��Wqtjy:t�
|t	d��YqtyNt�
|t	d�j
|d��Yqwtdd	i�S)
zS
    This method is used to archive/un-archive bulk rotating work type assigns
    r7r.z{employee} deleted.rgz{rwork_type_assign} not found.z%You cannot delete {rwork_type_assign})r�r��Success)r�r�r�r�r�r�r�rr�r�r�r�r�r�rr)r�r7r/r�r�r�r��%rotating_work_type_assign_bulk_delete
	s*

����r�cCs�ztjj|d�}|jj}|��t�|td��Wn"tj	y+t�
|td��Ynty;t�
|td��Ynwt|||�S)z:
    This method is used to delete rotating work type
    r.z"Rotating work type assign deleted.r�z*You cannot delete this rotating work type.)
r�r�r�r�r/r�rr�r�r�r�rr�)r�rr�r�r�r�r�� rotating_work_type_assign_delete)	s�r�zbase.view_employeetypecCrO)z3
    This method is used to view employee type
    z%base/employee_type/employee_type.html�employee_types)r�r�rr!)r��typesr�r�r��employee_type_view>	s
��r�zbase.add_employeetypecCrh)z5
    This method is used to create employee type
    r[r�zEmployee type created.�*<script>window.location.reload();</script>�*base/employee_type/employee_type_form.html)r�r�r[)r#r�rHr�r�rr�r�r	rrr�r�rr!)r�r[r�r�r�r�r��employee_type_createO	s



�r�zbase.change_employeetypecKrW)zp
    This method is used to update employee type instance
    args:
        id : employee type instance id

    rr�zEmployee type updated.r�r�)r��
employee_type)r�rrHr�r�r	rrr�r�rr!)r�r/r�r�r�r�r�r��employee_type_updateg	ror�zbase.view_employeeshiftcCsJtj��}t�d�rtddd�}|j��jdd�}nd}t|d||d��S)	z4
    This method is used to view employee shift
    r��	gracetimer�T)�
is_defaultNzbase/shift/shift.html)�shifts�grace_times)rr�rr
r�r�r=r!)r�r��	GraceTimer�r�r�r��employee_shift_view�	s

�rzbase.add_employeeshiftcCrh)z6
    This method is used to create employee shift
    r[r�z-Employee Shift has been created successfully!r��base/shift/shift_form.html)r�r�r[)r#r�rErr�rr�r�r	rrr�r�rr!)r�r[r�r�r�r�r��employee_shift_create�	s"


�
�rzbase.change_employeeshiftcKrW)zj
    This method is used to update employee shift instance
    args:
        id  : employee shift id

    rr�z
Shift updatedr�r)r��shift)rrrEr�r�r	rrr�r�rr!)r�r/r��employee_shiftr�r�r�r��employee_shift_update�	s



�rzbase.view_employeeshiftschedulecCs.d}tj��r	d}tj��}t|d||d��S)z8
    This method is used to view schedule for shift
    FTzbase/shift/schedule.html)r��shift_schedule)r�r�r�rrr!)r�rr�r�r�r��employee_shift_schedule_view�	s

�rzbase.add_employeeshiftschedulecCsdt�}tj��}|jdkr)t|j�}|��r)|��t�}t�	|t
d��td�St|d||d��S)z:
    This method is used to create schedule for shift
    r�z6Employee Shift Schedule has been created successfully!r��base/shift/schedule_form.html)r�r�)
rFrr�rr�r�r	rrr�r�rr!)r�r�r�r�r�r��employee_shift_schedule_create�	s


��r	z!base.change_employeeshiftschedulecKrW)zq
    This method is used to update employee shift instance
    args:
        id : employee shift instance id
    rr�zShift schedule created.r�r)r�r)r�rrGr�r�r	rrr�r�rr!)r�r/r��employee_shift_scheduler�r�r�r��employee_shift_schedule_update�	s



��rzbase.view_rotatingshiftcCrs)z4
    This method is used to view rotating shift
    z'base/rotating_shift/rotating_shift.html�rshifts)r!r�r�rr�r�r�r��rotating_shift_view

rur
zbase.add_rotatingshiftcCsht�}|jdkr%t|j�}|��r$|��t�}t�|td��td�Snt�}t	|d|t
j��d��S)z6
    This method is used to create rotating shift
    r�zRotating shift created.r��1base/rotating_shift/htmx/rotating_shift_form.html)r�r)
rVr�r�r	rrr�r�rr!r�r�rrTr�r�r��rotating_shift_create
s

��rzbase.change_rotatingshiftcKslt�|�}t|d�}|jdkr-t|j|d�}|��r-|��t�}t�|t	d��t
d�St|d||d��S)zq
    This method is used to update rotating shift instance
    args:
        id : rotating shift instance id
    rr�zRotating shift updated.r�r)r��rshift)r�rrVr�r�r	rrr�r�rr!)r�r/r��rotating_shiftr�r�r�r��rotating_shift_update1
s 



��r�base.view_rotatingshiftassigncCs�t�}t||d�}ttjjdd�d�}|j}tj��}t||d�}|jdd�}t	�
dd�t||j�
d	��jD��}t|d
||t�t�t||j�
d	��||tjd��S)z6
    This method is used to assign rotating shift
    �base.add_rotatingshiftassignTrzr{rr}cSr~r�r.rr�r�r�r�a
r�z)rotating_shift_assign.<locals>.<listcomp>r�z.base/rotating_shift/rotating_shift_assign.html)r�r�r�r��
rshift_assignr��
rshift_allr�)rTrer1rRr�r�r�rrhr�r�ror#r�r�r!rSr2r0)r�r�r�rrr�r�r�r��rotating_shift_assignN
s@�
����	��rrcCr�)z:
    This method is used to add rotating shift assign
    r�r�r�rr�r8r�cSr~r�r-r�r�r�r�r��
r�z-rotating_shift_assign_add.<locals>.<listcomp>zYou are added to rotating shiftu4تمت إضافتك إلى وردية الدوريةu6Sie werden der rotierenden Arbeitsschicht hinzugefügtu Estás agregado a turno rotativou.Vous êtes ajouté au quart de travail rotatifr�r�r�zRotating shift assigned.z8base/rotating_shift/htmx/rotating_shift_assign_form.htmlr�r�r�)rTr#r�rUrer�r�r	rr�r�r�r�r�r�r,r�r�r#rr�r�r!rr^r�r�r�r�r��rotating_shift_assign_addy
r�rc	Cs0|j��}t|j�j�d�}|j�d�}|j�d�dus$|j�d�dkr*|jdd�}t||d�}t||d	�}t	|�}t
t|�d
}|dkrx|durxt|||j�d�d�}d
d�|D�}g}|D]}|j
D]}	|�|	j�qdq_t�t|��}
d}nt||j�d��}t�dd�|j
D��}
t||||||
|d��S)zQ
    This method renders all instance of rotating shift assign to a template
    r|r�r&Nr�Trzrr�z3base/rotating_shift/rotating_shift_assign_view.htmlr9r�cSr�r�r�r�r�r�r�r��
r�z.rotating_shift_assign_view.<locals>.<listcomp>z&base/rotating_shift/htmx/group_by.htmlcSr~r�r.rr�r�r�r��
r�)rr�r�r�r�)r#rr1r�r�r�r�rhrqrrlrRr�r�r�r/r�r�r�ror!)r�r�rr�r�r�r�r�r�r�r�r�r�r��rotating_shift_assign_view�
sJ
�
�
���rc
Cs|j��}|�dd�|��}tjj|d���}||d�}|j�d�}|j	�dd�}d|d<d|d<|rB|�
d	�rBd
|d<d|d<n)|rkdd
�|�d�D�}zt|d�}	d|	��|d<d|d<Wn	t
yjYnw|r�t�|�}
t|
|�\}}||d<||d<|
|d<t|d|�S)zL
    This view is used render detailed view of the rotating shit assign
    r�Nr.r�rDr9r�r�zrotating-shift-assign/z/rotating-shift-assign-viewr�cSr�r�r�r�r�r�r�r��
r�z2rotating_shift_individual_view.<locals>.<listcomp>r�rr�r�r�r r�z(base/rotating_shift/individual_view.html)r#r�r%rrRr�r�r�r�rIr�rrr�r�r�rfr!)
r�r!r�r�r�rwr�rDr�r�r�r�r�r�r�r��rotating_shift_individual_view�
s8


�
r�base.change_rotatingshiftassigncCs�t�|�}t|d�}t||d�}|jdkrDt|j|d�}t||d�}|��rD|��t�	|t
d��t|dd|i�}t|j
�d�d�St|dd|i�S)	z�
    This method is used to update rotating shift assign instance
    args:
        id : rotating shift assign instance id

    rrr�zRotating shift assign updated.z?base/rotating_shift/htmx/rotating_shift_assign_update_form.htmlr�r�r�)rRrrUrer�r�r	rrr�r�r!rr^r�)r�r/�rotating_shift_assign_objr�r_r�r�r��rotating_shift_assign_updates4



������rcCs:|j�d�rt�t�d�}t|d|d�St|tttdd�S)Nr�r�z5base/rotating_shift/rotating_shift_assign_export.htmlr��Rotating_shift_assign_exportr�)rIr�r1rSr!rgrRr�r�r�r��rotating_shift_assign_export*s ���rcCr�)Nr�rr�z/rotating-shift-assign-view?r�z/rshit-individual-view/r�r!r�r�r�r�rDr�r�r�r�r��rotating_shift_assign_redirect@s,



�r cCs�z@tt|d�}|jj}tjjd|jd�}|j|_|jr%|r%t�|d�n|�	�|jr0t
d�nt
d�}t�|t
d��|��Wnt
yQt�|t
d��Ynwt|||�S)	zT
    This method is used to archive and unarchive rotating shift assign records
    r.Tr�r�r�r�zRotating shift assign is {}� Rotating shift assign not found.)rrRr�r/r�r�r&rr�rr�r�r�rr )r�rrr��employees_rshift_assignsr�r�r�r��rotating_shift_assign_archiveZs"�

��r#cCs�|jd}t�|�}d}td�}|j�d�dkrd}td�}|D]I}tjj|d�}tjjd|j	d	�}d}|rBt
|�d
krAd}||_nd}||_|��|s\t
�|td�j|j	|d��q t
�|td
�j|j	d��q tddi�S)zO
    This method is used to archive/un-archive bulk rotating shift assigns
    r7Tr�r&�FalseFr�r.r�r�z*Rotating shift for {employee} is {message})rr�z/Rotating shift for {employee} is already existsrgr�r�)r�r�r�r�r#r�rRr�r�r�r�r&rrr�r�r�r)r�r7r&r�r/r�employees_rshift_assign�flagr�r�r��"rotating_shift_assign_bulk_archivetsF

������r'zbase.delete_rotatingshiftassignc
Cr�)
zF
    This method is used to bulk delete for rotating shift assign
    r7r.z{employee} assign deleted.rgz{rshift_assign} not found.z!You cannot delete {rshift_assign})rr�r�)r�r�r�rRr�r�r�rr�r�r�r�r�r�rr)r�r7r/rr�r�r��!rotating_shift_assign_bulk_delete�s.

�����r(cCs�ztjj|d�}|jj}|��t�|td��Wn$tj	y-d}t�
|td��Ynty=t�
|td��Ynwt|||�S)z
    This method is used to delete rotating shift assign instance
    args:
        id : rotating shift assign instance id
    r.zRotating shift assign deleted.Nr!z-You cannot delete this rotating shift assign.)
rRr�r�r�r/r�rr�r�r�r�rr )r�rrr�r�r�r��rotating_shift_assign_delete�s
�r)cCs0zt�|�}|��}|WStygYSw)z
    get app models
    )r
�get_app_config�
get_models�LookupError)r��
app_config�modelsr�r�r�r��s
�r�zauth.view_permissioncsi}d}|j�d�r!d}tjj|jdd���}|��}||d<n
tjjdd���}d	|d
<g}gd���fdd
�tjD�}t	}|D]-}g}	t
|�D]}
|
jj|vr`|	�
|
jj��|
jjd��qJ|�
|���dd�|	d��qB||d<||d<t||j�d��|d<t|||�S)zD
    This method is used to assign permissions to employee user
    zbase/auth/permission.html�profile_tabztabs/group_permissions.htmlr�r.rF��*employee_user_id__user_permissions__isnullT�show_assign)
�baser�rr�r�r�r�r�r��authr��horilla_documents�helpdeskcsg|]}|�vr|�qSr�r�)r�r���horilla_appsr�r�r�sz.employee_permission_assign.<locals>.<listcomp>r�r�r%r�r�r�r�r�)r#r�r�r�r��distinctr�r�INSTALLED_APPSr�r�r�r�r�r�r��replaceror!)r�rwr�r��emoloyeer��installed_appsr�r�r�r�r�r7r��employee_permission_assign�sL
��
�����r>�view_permissionscCs�i}d}t|j�j}|j�d�rd}|j|jdd���}n|jdd���}d|d	<g}t}|D]#}g}	t|�D]}
|	�|
j	j
��|
j	jd
��q8|�|��|	d��q0||d<t
||j�d
��|d<t|||�S)zP
    This method renders template to view all instances of user permissions
    zbase/auth/permission_lines.htmlr/z#base/auth/permission_accordion.htmlr�r.Fr0Tr2r�r�r�r�r�)r�r#r�r�r�r9r�r�r�r�r�r�r�ror!)r��codenamer�rwr�r�r�r
r�r�r�r�r�r��employee_permission_searchs<��
���rAcCs�t|j�}|��r|��tddd��S|j�d�r=tjj	|jdd��
�r=tjj	|jdd��
�jj�
�tddd��Stdd	d��S)
r�r�r�r�rr.r�rJr�r�)r:r�r	rrr�r�r�r�r�r�r��user_permissionsr�rTr�r�r��update_permissionEs
	
���rCcCs�g}t}t�}t}|D]'}g}t|�D]}||vr'|�|jj��|jjd��q|�|��|d��q|j	dkrQt|j
�}|��rQ|��t
�|td��td�St|d|||d��S)z<
    This method is used to render the permission table
    r�r�r�zEmployee permission assigned.r�z base/auth/permission_assign.htmlr�)r�r:r�r�r�r�r�r�r�r�r�r	rrr�r�rr!)r�r�r
r�r�r�r�r�r�r�r��permission_table]s:
���

��rDc
Cs�|j��}tjj|jd���}|j�d�rtj�	�}nt
|tj�	�d�}|tjj|d�B}|jdd�}t�dd�t
||j�d	��jD��}t|j|d
�}t|�}tt|�t�}t||d�}t||�}t|dt
|j|j�d	��||||tjd
��S)zF
    This method renders template to  view all work type requests
    r-�base.view_worktyperequest�base.add_worktyperequestr�Tr}cSr~r�r.rr�r�r�r��r�z*work_type_request_view.<locals>.<listcomp>r�r{zbase.add_worktypereqeustz-work_type_request/work_type_request_view.html)r�r�r�r��requests_idsr�)r#rr�r�r�r�r��has_permr�rrhr�r�ror�r�r7rrlrdrer2r!r�r8r0)r�r�r�work_type_requestsrGr�r�r�r�r�r��work_type_request_view�sP
�����
�
��rJrEcCsD|j�d�dkrt�}t�}||d�}t|d|d�St|tttd�S)Nr�r���
export_fieldsr�z/work_type_request/work_type_request_export.htmlr��Work_type_request)rIr�r7rbr!rgr�)r�r�rLrwr�r�r��work_type_request_export�s ���rNc	Csftjj|jd���}|j��}|j�d�}t|j�}|j�	d�s't
||jd�n|j}tt
jj|d��}t|�}tt||��}t
jjdd�|D�d�}	t||	d	�}d
}
|dkr�|dur�t|||j�d
�d
�}dd�|D�}g}|D]}
|
jD]}|�|j�qvqqt�t|��}d}
nt||j�d
��}t�dd�|jD��}t|�}tt
|�t||
|||||d��S)z:
    This method is used to search work type request.
    r-r�rErFr�cSr~r�r.)r��reqr�r�r�r��r�z,work_type_request_search.<locals>.<listcomp>r8r�z$work_type_request/htmx/requests.htmlr9Nr�cSr�r�r�r�r�r�r�r��r�z$work_type_request/htmx/group_by.htmlcSr~r�r.rr�r�r�r��r�)r�r�r�rGr�)r�r�r�r�r�r#rr�r7rHrhr�r�r�r�rqr�r�r�r/r�r�rorrlr!)r�rr�r�r��work_typ_requests�employee_work_requests�subordinates_work_requests�combined_requests�combined_requests_qsr�r�r�r�r�rGr�r�r�r��work_type_request_search�sX


����
��
��rUcCs|jjj}|j�dd�}t|j���dd��}d}d}|r7dd�	|�
d�dd��dkr7td�}d}||fS|rI|�d�rId	|��}d
}||fS|r\|�d�r\d|�d
�}d}||fS|r�dd�|�
d�D�}zt
|d�}d|��}d}W||fSty�Y||fSw||fS)NrDr9�pd=r�r��dashboard-work-type-requestz#WorkTypeRequestApproveBodyzwork-type-request-view/�/work-type-request-search?r�zemployee-profile/r�z
?profile=truer�cSr�r�r�r�r�r�r�r�
r�z+handle_wtr_close_hx_url.<locals>.<listcomp>r)r�r�r/rIr�rr#rr;r�rr#r�rr�)r�rrDr�r�r�r�r�r�r�r��handle_wtr_close_hx_url
s:
$�
�	�
��rYc
Cs�|j��}t|�dd��}t�}|jjj}|j�d�r!|j�d�}td|id�}t	||d�}t
||�}t�}||d�}t|�\|d<|d	<|j
d
kr�t|j�}t	||d�}t
||�}|��r�|��}z1tj|j|jjjjd|j��d|j��d
|j��d|j��d|j��dtd�d|j��d�	Wnty�}zWYd}~nd}~wwt�|td��tj��}	t|	�dkr�t d�St�}||d<t!|d|d�S)z@
    This method is used to create request for work type  .
    rVr9r�r�r�rF)r�r�r�r�r�zKYou have new work type request to                             validate for uYلديك طلب نوع وظيفة جديد للتحقق من                             uWSie haben eine neue Arbeitstypanfrage zur                             Validierung für z[Tiene una nueva solicitud de tipo de trabajo para                             validar para u]Vous avez une nouvelle demande de type de travail                            à valider pour �information�work-type-request-view�?id=r�NzWork type request added.r�r�r�z#work_type_request/request_form.htmlr�)"r#rrr;rdr�r�r/r�rer2r7rYr�r�r	rr�r,r�r�r�r�r#r�rr�r�r�r�rr�rr!)
r��encoded_datar�r�rr�rwr�r�rIr�r�r��work_type_request"
sz

�

�

�

�����
���
r^cCs|j�d�dk}|st|j�dd��Sdd�|j�dd��d�dd��}|j�d�}|s2td	�S|d
krW|j�d�}|j�d�}td
d|jid�}t	|�d|�d|���S|dkrat	td��Sd|vrot	d|j�
����Sd|vr|t	d|jj���Std	�S)Nr�r�rDr��HTTP_HX_CURRENT_URLr9r�rr�r�r��	dashboardzwork-type-request-single-viewr)r�z?instances_ids=z&dashboard=rWz/work-type-request-view/rXz/employee-view/r�)rIr�rr�rrr#r#r/r rr�)r�r^�
hx_request�current_urlrr�r`r�r�r�r��handle_wtr_redirectc
s0��rccCst�|�}|st�|td��t|j�dd��St||�s@|j	�
d�s@|j|j	jkr/|j
dks@t�|td��t|j�dd��Sd|_d|_
tjj|jd�}|��r^|j|jj_|jj��|��t�|td	��tj|j	j|jjd
ddd
dtd�d|j��dd�	t||�S)zg
    This method is used to cancel work type request
    args:
        id  : work type request id

    �Work type request not found.rDr��base.cancel_worktyperequestF�You don't have permissionTr�z$Work type request has been rejected.z)Your work type request has been rejected.u*تم إلغاء طلب نوع وظيفتكz&Ihre Arbeitstypanfrage wurde storniertz1Su solicitud de tipo de trabajo ha sido canceladau1Votre demande de type de travail a été annuléer[r\�close�r�r�r�r�r�r�r r�)r�rrr�r�rrIr�r�r�rHr�r��approved�canceledr�r�r�r��previous_work_type_idr�r{rr�r�r,r�r#r/rc)r�r/r^�	work_infor�r�r��work_type_request_cancel�
sF
�
�
���
rm�base.change_worktyperequestcCs�|jd}t�|�}d}|D]Z}tjj|d�}t||�s.|j�d�s.|j	|jj
krh|jdkrhd|_d|_|j
|j	j_|j	j��|��t�|td��tj|jj
|j	jddd	d
dtd�d
|j��dd�	d}qtd|i�S)zA
    This method is used to cancel a bunch work type request
    r7Fr.reTz$Work type request has been canceled.z)Your work type request has been canceled.u+تم إلغاء طلب نوع وظيفتك.z'Ihre Arbeitstypanfrage wurde storniert.z2Su solicitud de tipo de trabajo ha sido cancelada.u2Votre demande de type de travail a été annulée.r[r\rgrhrJ)r�r�r�r�r�r�r�r�rHr�r�rirjrkr�r{rrr�r�r�r,r�r#r/r)r�r7rJr/r^r�r�r��work_type_request_bulk_cancel�
sD

�
�
�
���rocCs�t�|�}|st�|td��t|j�dd��St||�s=|j	�
d�s=|j	�
d�r,|jr=t�|td��t|j�dd��S	|��sod|_d|_
|��t�|td	��tj|j	j|jjd
ddd
dtd�d|j��dd�	nt�|td��t||�S)z<
    This method is used to approve requested work type
    rdrDr��approve_worktyperequest�change_worktyperequestrfTF�$Work type request has been approved.�)Your work type request has been approved.�:تمت الموافقة على طلب نوع وظيفتك.�'Ihre Arbeitstypanfrage wurde genehmigt.�1Su solicitud de tipo de trabajo ha sido aprobada.�4Votre demande de type de travail a été approuvée.r[r\�	checkmarkrhzEAn approved work type request already exists during this time period.)r�rrr�r�rrIr�r�r�rHri�is_any_work_type_request_existsrjrr�r�r,r�r�r�r#r/rc)r�r/r^r�r�r��work_type_request_approve�
sH
�
�
����
rzcCs�|jd}t�|�}d}|D]W}tjj|d�}t||�s+|j�d�s+|j�d�re|j	sed|_	d|_
|jj}|j
|_
|��|��t�|td��tj|jj|jjdd	d
ddtd
�d|j��dd�	d}qtd|i�S)zD
    This method is used to approve bulk of requested work type
    r7Fr.rprqTrrrsrtrurvrwr[r\rxrhrJ)r�r�r�r�r�r�r�r�rHrirjr�r�r{rrr�r�r�r,r�r�r#r/r)r�r7rJr/r^r�r�r�r��work_type_request_bulk_approve
sH

�
�
��	
���r{cCs�tjj|d�}t|d�}t||d�}t||�}|jdkrPt|dd|i�}t|j|d�}t||d�}t||�}|�	�rP|�
�t�|t
d��t|j�d�d	�St|dd|i�S)
zx
    This method is used to update work type request instance
    args:
        id : work type request instance id

    r.rrnr�z*work_type_request/request_update_form.htmlr��Request Updated Successfullyr�r�)r�r�r�rdrer2r�r!r�r	rrr�r�rr^r�)r��work_type_request_idr^r�r_r�r�r��work_type_request_update4s*



��
�r~cCslz)tjj|d�}|j}t�|td��|��tj	|j
j|jddddddd	d
�	Wn$tj
y=d}t�|td��YntyMt�|td
��Ynw|j�dd�}|r�|dkr�|j�d�}t�|�}||vro|�|�tt�|�|�\}}td|�d|���S|r�|dkr�|j��}	tj��}
|
��r�td|	���Std�S|r�|dkr�|r�td|j���Std�S)�o
    This method is used to delete work type request
    args:
        id : work type request instance id

    r.�Work type request deleted.�(Your work type request has been deleted.�'تم حذف طلب نوع وظيفتك.�'Ihre Arbeitstypanfrage wurde gelöscht.�2Su solicitud de tipo de trabajo ha sido eliminada.�4Votre demande de type de travail a été supprimée.�#�trashrhNrdz)You cannot delete this work type request.rr�r�z/work-type-request-single-view/z/?instances_ids=r�rXr�r�r�)r�r�r�r�rr�r�r�r�r,r�r�r�r�r�rrIr#r�r�r�rfr rrr�rr/)r�rr^rrr�r�r�r�r�rIr�r�r��work_type_request_deleteWsV

��


��

r�cCs�tjj|d���}||j�d�d�}|j�d�}|r2t�|�}t||�\}}||d<||d<||d<t	|�\|d<|d	<t
|d
|�S)zE
    This method is used to view details of an work type request
    r.r`)r^r`r�rGr�r r�r�z9work_type_request/htmx/work_type_request_single_view.html)r�r�r�r�r#r�r�r�rfrYr!)r�rr^rw�requests_ids_jsonrGr�r�r�r�r��work_type_request_single_view�s&
�
��r�zbase.delete_worktyperequestcCs�|jd}t�|�}|D]W}z)tjj|d�}|jj}|��t	�
|td��tj
|jj|dddddd	d
d�	Wn)tjyIt	�|td��Ynty`t	�|td
�j|j|jd��Ynwd}qtd|i�S)rr7r.r�r�r�r�r�r�r�r�rhrdzCYou cannot delete {employee} work type request for the date {date}.�rrpTrJ)r�r�r�r�r�r�r�r�r�rr�r�r�r,r�r�r�r�rr��requested_dater)r�r7r/r^r�rJr�r�r��work_type_request_bulk_delete�sF



�����
r�cCs^t�}|jjj}|j�d�r|j�d�}td|id�}t||d�}t||�}t�}|j	dkr�t|j
�}t||d�}t||�}t|d||d��}|��r�|�
�}z2tj|j|jjjjd|j��d	|j��d
|j�d�d|j��d
|j��dtd�d|j��d�	Wnty�}zWYd}~nd}~wwt�|td��t|j�d�d�St|d||d��S)z5
    This method is used to create shift request
    r�r�r��base.add_shiftrequestr�z1shift_request/htmx/shift_request_create_form.html�r�r�zBYou have new shift request to approve                         for uCلديك طلب وردية جديد للموافقة عليه لـ uBSie müssen eine neue Schichtanfrage                         für z genehmigenzMTiene una nueva solicitud de turno para                         aprobar para u\Vous avez une nouvelle demande de quart de                        travail à approuver pour rZ�shift-request-viewr\r�NzShift request addedr�r�)r^r�r�r/r#r�rer2r5r�r�r!r	rr�r,r�r�r�r�r#r�rr�r�rr^r�)r�r�rr�r_r�rYr�r�r��
shift_request�sp
�



�
�
���
�����r�cCsh|j�d�}t�}tjj|d���}|jjddd�}t	jj|d�}||j
d_d|i}td	|�}t
|�S)
Nr�r.r�Tr�r8�
reallocate_tor�z2shift_request/htmx/shift_reallocate_employees.html)r#r�r[rr�r�r��employeeworkinformation_setr�r�r0r1r"r)r�rr�r�r�rw�
html_templater�r�r��update_employee_allocations��r�cCs�t�}|j�d�r|j�d�}td|id�}t||d�}t||�}t�}|jdkr�t|j�}t||d�}t||�}t|d||d��}|�	�r�|�
�}|jd}z6tj
|j|jjjjd	|j�d
�d|j�d
�d|j�d
�d
|j�d
�d|j�d
�dtd�d|j��d�	Wnty�}zWYd}~nd}~wwz2tj
|j|d|j�d
�d|j�d
�d|j�d
�d|j�d
�d|j�d
�dtd�d|j��d�	Wnty�}zWYd}~nd}~wwt�|td��t|j�d�d�St|d||d��S)zB
    This method is used to create shift request reallocation
    r�r�r�r�r�z-shift_request/htmx/shift_allocation_form.htmlr�r��9You have a new shift reallocation request to approve for �.�hلديك طلب تخصيص جديد للورديات يتعين عليك الموافقة عليه لـ �WSie haben eine neue Anfrage zur Verschiebung der Schichtzuteilung zur Genehmigung für �HTienes una nueva solicitud de reasignación de turnos para aprobar para �LVous avez une nouvelle demande de réaffectation de shift à approuver pour rZr�r\r�N�/You have a new shift reallocation request from �:لديك طلب تخصيص جديد للورديات من �FSie haben eine neue Anfrage zur Verschiebung der Schichtzuteilung von �9Tienes una nueva solicitud de reasignación de turnos de �=Vous avez une nouvelle demande de réaffectation de shift de z
Request Addedr�r�)r[r#r�rer2r5r�r�r!r	rrr�r,r�r�r�r�r#r/r�rr�r�rr^r�)r�r�rr�r_r��reallocate_emprYr�r�r��shift_request_allocation's��



�


�
��
�����r�cCsf|j��}tjj|jd���}t|tjjdd�d�}|tjj|d�B}|jdd�}t|tjjdd�d�}tjjdd�}|j�	d�sN|�t
|d�t
|d�B�}||B}t�d	d
�t
||j�d��jD��}t�dd
�t
||j�d��jD��}t|j|d
�}t|�}	tt|	�t�}
t||
d�}
t||
�}
t|dt
||j�d��t
|j|j�d��||
|	||tjd��S)zG
    This method renders all shift request instances to a template
    r-T��reallocate_to__isnull�base.view_shiftrequestr�r}F�r�cSr~r�r.rr�r�r�r��r�z&shift_request_view.<locals>.<listcomp>r�cSr~r�r.rr�r�r�r��r�r{r�z%shift_request/shift_request_view.html)�allocated_datar�r�r�r�rG�
allocated_idsr�)r#rr�r�r�r�r�rhr�rHrr�r�ror�r�r5rrlr^rer2r!r�r6r0)r�r�r�shift_requests�allocated_shift_requests�allocated_requestsrGr�r�r�r�r�r�r��shift_request_viewosz
���������
�
���r�r�cCsD|j�d�dkrt�}t�}||d�}t|d|d�St|tttd�S)Nr�r�rKz'shift_request/shift_request_export.htmlr��Shift_requests)rIr�r\r5r!rgr�)r�rLr�rwr�r�r��shift_request_export�s ���r�cCs`tjj|jd���}|j��}|j�d�}t|j�}t	||j
d�}t||jdd�d�}||j|jd�B}t||jdd�d�}|j�d	�sS||�t
|d
�t
|d�B�B}t�dd
�t||j�d��jD��}t�dd
�t||j�d��jD��}t|�}	d}
|dkr�|dur�t|||j�d�d�}t|||j�d�d�}dd
�|D�}dd
�|D�}g}
g}|D]}|jD]}|
�|j�q�q�|D]}|jD]}|�|j�q�q�t�t|
��}t�t|��}d}
n6t||j�d��}t||j�d��}t�dd
�t||j�d��jD��}t�dd
�t||j�d��jD��}tt|	�t||
|t||j�d��||	|||d��S)ze
    This method is used search shift request by employee and also used to filter shift request.
    r-r�rqTr�r���employee_id__employee_user_idFr�r�r�cSr~r�r.rr�r�r�r��r�z(shift_request_search.<locals>.<listcomp>r�cSr~r�r.rr�r�r�r��r�z shift_request/htmx/requests.htmlr9NcSr�r�r�r�r�r�r�r�r�cSr�r�r�r�r�r�r�r�r�z shift_request/htmx/group_by.htmlcSr~r�r.rr�r�r�r�r�cSr~r�r.rr�r�r�r�#r�)r�r�r�r�rGr�r�)r�r�r�r�r�r#rr�r5rqr�rhrHrr�r�ror�rr�r�r/r�rlr�r!)r�rr�r�r�r�r�rGr�r�r��shift_list_values�allocated_list_values�
shift_id_list�allocated_id_listr�r�r�r�r��shift_request_search�s�

�������	���	��
�
�����	���
	��r�cC�ht�|�}|j�d�}||j�d�d�}|r.t�|�}t||�\}}||d<||d<||d<t|d|�S)�w
    This method is used to show shift request details in a modal
    args:
        id : shift request instance id
    r�r`�r�r`r�r rGz,shift_request/htmx/shift_request_detail.html�r�rr#r�r�r�rfr!�r�r/r�r�rwrGr�r�r�r�r��shift_request_details;� 

�
�r�cCr�)r�r�r`r�r�r �allocation_idsz*shift_request/htmx/allocation_details.htmlr�r�r�r�r�� shift_allocation_request_detailsVr�r�cCs�tjj|d�}t|d�}t||d�}t||�}|jdkr`|jsTt|dd|i�}t|j	|d�}t||d�}t||�}|�
�rS|��t�
|td��t|j�d�d	�Snt�|td
��td	�St|dd|i�S)�o
    This method is used to update shift request instance
    args:
        id : shift request instance id
    r.r�base.change_shiftrequestr��&shift_request/request_update_form.htmlr�r|r�r�z!Can't edit approved shift request)r�r�r�r^rer2r�rir!r�r	rrr�r�rr^r�rJ)r��shift_request_idr�r�r_r�r�r��shift_request_updateqs6	


��

���r�cCs�tjj|d�}t|d�}t||d�}t||�}|jdkr�t|dd|i�}t|j|d�}t||d�}t||�}|�	�r�|�
�|�
�}|jd}z6tj
|j|jjjjd|j�d	�d
|j�d	�d|j�d	�d|j�d	�d
|j�d	�dtd�d|j��d�	Wnty�}zWYd}~nd}~wwz2tj
|j|d|j�d	�d|j�d	�d|j�d	�d|j�d	�d|j�d	�dtd�d|j��d�	Wnty�}zWYd}~nd}~wwt�|td��t|j�d�d�St|dd|i�S)r�r.rr�r�r�r�r�r�r�r�r�r�r�rZr�r\r�Nr�r�r�r�r�r|r�r�z1shift_request/allocation_request_update_form.html)r�r�r�r[rer2r�r!r�r	rrr�r,r�r�r�r�r#r/r�rr�r�rr^r�)r�r�r�r�r_r�r�rYr�r�r��shift_allocation_request_update�sr


��



�
��
����
�r�cCs�t�|�}|st�|td��t|j�dd��St||�s@|j	�
d�s@|j|j	jkr/|j
dks@t�|td��t|j�dd��St����}|j
rf|j|krU|jkrfnn|jsf|j|jj_|jj��d|_d|_
tjj|jd�}|��r~|j|jj_|jr�|��r�|j|jj_|jj��|��r�|jj��|��t�|td	��tj |j	j|jj!d
ddd
dt"d�d|j#��dd�	|jr�tj |j	j|jj!dddd
dt"d�d|j#��dd�	t|j�dd��S)�h
    This method is used to update or cancel shift request
    args:
        id : shift request id

    �Shift request not found.rDr��base.cancel_shiftrequestFrfTr�zShift request rejected�%Your shift request has been canceled.�(تم إلغاء طلبك للوردية.�"Ihr Schichtantrag wurde storniert.�&Se ha cancelado su solicitud de turno.�(Votre demande de quart a été annulée.r�r\rgrhz%Your shift request has been rejected.)$r�rrr�r�rrIr�r�r�rHr�r�rirrlrpr��requested_till�is_permanent_shift�previous_shift_idr�r�rrjr�r�r�r�r�r�r�r,r�r#r/)r�r/r��
today_daterlr�r�r��shift_request_cancel�sx
	�
�
�������r�cCs�t�|�}d|_d|_tjj|jd�}|��r#|j	|jj
_|jj
��|��t
�|td��tj|jj|jjddddd	td
�d|j��dd
�	t|j�dd��S)r�TFr��Shift request canceledr�r�r�r�r�r�r\rgrhrDr�)r�r�reallocate_canceled�reallocate_approvedr�r�r�r�r�r�r�r�rrr�r�r�r,r�r�r�r#r/rrIr�)r�r/r�rlr�r�r��shift_allocation_request_cancel$s0
	���r�r�cCs6|jd}t�|�}d}|D]�}tjj|d�}t||�s.|j�d�s.|j	|jj
kr�|jdkr�d|_d|_|j
|j	j_|jrI|j|jj_|jj��|j	j��|��t�|td��tj|jj
|j	jddd	d
dtd�d
|j��dd�	|jr�tj|jj
|j	jddd	d
dtd�d
|j��dd�	d}qtd|i�S)zA
    This method is used to cancel a bunch of shift request.
    r7Fr.r�Tr�r�r�r�r�r�r�r\rgrhrJ)r�r�r�r�r�r�r�r�rHr�r�rirjr�r�r�r�rrr�r�r�r,r�r#r/r)r�r7rJr/r�r�r�r��shift_request_bulk_cancelJs`

�
�
�����r�cCs�t�|�}|st�|td��t|j�dd��S|j}t	||�s>|�
d�s>|�
d�r-|jr>t�|td��t|j�dd��S|��rSt�|td��t|j�dd��St
����}|jsv|j|krh|jkrvnn|j|jj_|jj��d|_d	|_|jr�|j|jj_|jj��|��t�|td
��|jjg}|jr�|�|jj�|D]}tj|j|ddd
ddt d�d|j!��dd�	q�t|j�dd��S)zP
    Approve shift request
    args:
        id : shift request instance id
    r�rDr��approve_shiftrequest�change_shiftrequestrf�AAn approved shift request already exists during this time period.TFzShift has been approved.�%Your shift request has been approved.�7تمت الموافقة على طلبك للوردية.�"Ihr Schichtantrag wurde genehmigt.�%Se ha aprobado su solicitud de turno.�*Votre demande de quart a été approuvée.r�r\rxrh)"r�rrr�r�rrIr�r�r�rHri�is_any_request_existsrrlrpr�r�r�r�r�r�rrjr�r�r�r�r�r�r,r�r#r/)r�r/r�r�r��
recipientsr�r�r�r��shift_request_approve�sf
	�������
�r�cCs�t�|�}|��sWd|_d|_|��t�|td��t	j
|jj|j
j|jj�d�|jj�d�|jj�d�|jj�d�|jj�d�td	�d
|j��dd�	t|j�d
d��St�|td��t|j�d
d��S)zg
    This method is used to approve shift request
    args:
        id : shift request instance id
    TFz)You are available for shift reallocation.z% is available for shift reallocation.u3 متاح لإعادة توزيع الورديات.uA steht für die Verschiebung der Schichtzuteilung zur Verfügung.u2 está disponible para la reasignación de turnos.u0 est disponible pour la réaffectation de shift.r�r\rxrhrDr�r�)r�rr�r�r�rrr�r�r�r,r�r�r�r�r#r/rrIr�r�)r�r/r�r�r�r�� shift_allocation_request_approve�s.
��r�cCs�|jd}t�|�}d}|D]g}tjj|d�}t||�s+|j�d�s+|j�d�rs|j	ss	d|_	d|_
|jrA|j|jj
_|jj
��|jj
}|j|_|��|��t�|td��tj|jj|jjdd	d
ddtd
�d|j��dd�	d}qtd|i�S)zA
    This method is used to approve a bunch of shift request
    r7Fr.r�r�TzShifts have been approved.r�r�r�r�r�r�r\rxrhrJ)r�r�r�r�r�r�r�r�rHrirjr�r�r�r�rr�rr�r�r�r,r�r�r#r/r)r�r7rJr/r�r�r�r�r��shift_request_bulk_approve�sL

�
�
����r�cCs�z%t�|�}|jj}t�|d�|��tj|j	j
|dddddddd	�	Wn"tjy7t�|t
d
��YntyGt�|t
d��Ynw|j�dd
�}|ra|dkra|jratd|jj���St|j�dd��S)�p
    This method is used to delete shift request instance
    args:
        id : shift request instance id

    zShift request deleted�$Your shift request has been deleted.�2تم حذف طلب الوردية الخاص بك.�"Ihr Schichtantrag wurde gelöscht.�&Se ha eliminado su solicitud de turno.�*Votre demande de quart a été supprimée.r�r�rhr�z%You cannot delete this shift request.rNr�r�rDr�)r�rr�r�rr�r�r�r,r�r�r�r�r�rrIr�r r/r)r�r/r�r�rr�r�r��shift_request_delete!s2	

��r��delete_shiftrequestcCs�|jd}t�|�}d}|D]W}z)tjj|d�}|jj}|��t	�
|td��tj
|jj|ddddd	d
dd�	Wn)tjyKt	�|td
��Yntybt	�|td�j|j|jd��Ynwd}qtd|i�S)r�r7Fr.zShift request deleted.r�r�r�r�r�r�r�rhr�z?You cannot delete {employee} shift request for the date {date}.r�TrJ)r�r�r�r�r�r�r�r�r�rr�r�r�r,r�r�r�r�rr�r�r)r�r7rJr/r�r�r�r�r��shift_request_bulk_deleteFsH



�����
r�cCs|jj��}t|dd|i�S)z4
    This method will render notification items
    �$notification/notification_items.html�
notifications)r�r��unreadr!)r��all_notificationsr�r�r�r�ts�r�c
Csrz|jj����t�|td��Wnty*}zt�||�WYd}~nd}~ww|jj��}t	|dd|i�S)z3
    This method is used to clear notification
    zUnread notifications removed.Nr�r�)
r�r�r�r�rr�r�r�r�r!�r�rYr�r�r�r��clear_notification�s���r�c
Cs�z|jj����|jj����t�|td��Wnty2}zt�	||�WYd}~nd}~ww|jj�
�}t|dd|i�S)NzAll notifications removed.�#notification/all_notifications.htmlr�)r�r�r)r�r�rr�r�r�r�rr!r�r�r�r��delete_all_notifications�s��
�r�c
Csvd}z|jjj|d���t�|td��Wnty.}zt�||�WYd}~nd}~ww|jj�	�s7d}t
|�S)z4
    This method is used to delete notification
    r9r.zNotification deleted.Nz\<span hx-get='/all-notifications' hx-target='#allNotificationBody' hx-trigger='load'></span>)r�r�r�r�rr�r�r�r�rr)r�r/�scriptrYr�r�r��delete_notification�s��r�cCs2d}tjj|d�}|��|jj��sd}t|�S)Nr9r.zZ<span hx-get='/notifications' hx-target='#notificationContainer' hx-trigger='load'></span>)r�r�r��mark_as_readr�r�r�r)r��notification_idr��notificationr�r�r��mark_as_read_notification�sr�cCsPz|jd}t|�}tjj|d�}|��tddi�WStddd��YS)Nr�r.r�TFzInvalid request)r�r�)r�rr�r�r�r�r)r�r�r�r�r�r��mark_as_read_notification_json�s
r�c
Csrz|jj����t�|td��Wnty*}zt�||�WYd}~nd}~ww|jj�	�}t
|dd|i�S)z9
    This method is to mark as read the notification
    zNotifications marked as readNr�r�)r�r�r�mark_all_as_readrrJr�r�r�r�r!r�r�r�r��read_notifications�s���r�cCst|dd|jj��i�S)z=
    This method to render all notifications to template
    r�r�)r!r�r�rr�r�r�r�r��s
�r�cCs�t�d�r2tddd�}tddd�}ddlm}ddlm}|j��}||d�}|j��}||d�}nd	}d	}|j	�
d
�}	|	dksB|	sHtj��}
ntjj
|	d�}
tj��}t|d�}tj��}
t|
d�}tj��omtj��j}tj��}i}|r�|jr�d
|jd
i}t|d�}tjj
|jd���r�tjj
|jd���}t|d�}nt�}|jdkr�t|j|
d�}|��r�|��t� |t!d��t"|j#�
dd��St$|d|||||||||
|	d�
�S)z9
    This method is used to render settings template
    r��payrollsettingsr��encashmentgeneralsettingsr)�PayrollSettingsForm)�EncashmentGeneralSettingsFormrN�selected_companyrr.�tracking_fieldsr���user_idr��Settings updated.rDr�zbase/general_settings.html)
r��
currency_form�pagination_form�encashment_form�history_fields_form�history_tracking_instance�enabled_block_unblock�prefix_formrM�selected_company_id)%r
r�r��payroll.forms.component_formsr�payroll.forms.formsrr�r��sessionr�ryrr�r�r�rur9r�r��
is_enabledr�rr�r~r�rDr�r�r	rrr�r�rrIr!)r��PayrollSettings�EncashmentGeneralSettingsrr�currency_instancer�encashment_instancer	rrM�prefix_instancer
r�r�rr�history_fields_form_initialr
�
paginationrr�r�r��general_settings�sv
��








�

��

��rcCr�)zH
    This method is used to render Date format selector in settings
    zbase/company/date.htmlr�r�r�r�r��
date_settings4s
rc	C��|jdkrg|j�d�}t|�st�|td��nO|j}|j}t	j
j|d�}|��rY|D]}|j
}q+tj
j|d�}|��}|durIt�|td��n||_|��t�|td��nt�|td��td	d
i�Stddd
�dd�S)Nr��selected_formatz"Please select a valid date format.r��r
�-Please update the company field for the user.zDate format saved successfully.z5Date format cannot saved. You are not in the company.r�TF�Unsupported method�r�r����status)r�r�r�r�rr�r�r�r�r�r�r�r�rryr�r��date_formatrr�r�	r�rr�rrJr��employee_company�company_name�emp_companyr�r�r��save_date_format=�0
��r*c	Csr|j}|j}tjj|d�}|��r1|D]}|j}qtjj|d�}|��}|r.|r+|j	nd}nd}nd}t
d|i�S)Nr�rzMMM. D, YYYYr)r�r�r�r�r�r�rryr�r%r)	r�r�rrJr�r'r(r)r%r�r�r��get_date_formatisr,c	Cr)Nr�rz"Please select a valid time format.r�rrzTime format saved successfully.z5Time format cannot saved. You are not in the company.r�TFr r!r"r#)r�r�r�r�rr�r�r�r�r�r�r�r�rryr�r��time_formatrr�rr&r�r�r��save_time_format�r+r.c	Csj|j}|j}tjj|d�}|��r-|D]}|j}qtjj|d�}|��}|r*|j	}nd}nd}t
d|i�S)Nr�rzhh:mm Ar)r�r�r�r�r�r�rryr�r-r)	r�r�rrJr�r'r(r)r-r�r�r��get_time_format�sr/cCs�|jdkr=|j�d�}|j�d�}tjjddd|iid�\}}|s=d|i|_|dkr.d|_nd|_t	�
|td	��|��t
t�S)
Nr�r�work_info_trackr�)rd�defaults�onTFr)r�r�r�r�r�r�rnrr0rr�r�rr r)r�r0�check�history_object�createdr�r�r��history_field_settings�s

�
r6z(horilla_audit.change_accountblockunblockcCs�|jdkr@|j�d�dk}tj��}|r||_|��ntjj|d�t	�
|td|r,dnd�d���|j�d	�r<t
�Stt�St
d
d�S)Nr��enable_block_accountr2)rz'Account block/unblock setting has been �enabled�disabledr�r�r"r#)r�r�r�r�r�r�rr�createrr�r�rIrr r)r�r8r�r�r�r��enable_account_block_unblock�s"


��
r;cC�x|j�d�}|dkr&|j�d�rtj��}ntjj|jd�tjj|jd�B}dd�|D�}|��}||d�}t	|d	d
�S)Nr�rr�r���Gemployee_id__employee_work_info__reporting_manager_id__employee_user_idcS�g|]}t|j��qSr��r�r/�r�r�r�r�r�r���z shift_select.<locals>.<listcomp>�r��total_countF��safe)
r#r�r�rHr�r�rr�r<r�r��page_numberr�r�rDrwr�r�r��shift_select�s���
rIc	C�v|j�d�}|j�d�}|rt�|�ni}|dkr9t|tj��d�}|j}dd�|D�}|�	�}||d�}t
|�SdS)Nr�r�rr{cSr?r�r@rAr�r�r�r�rBz'shift_select_filter.<locals>.<listcomp>rC)r#r�r�r�r5r�r�rr�r<r�	r�rH�filtered�filters�employee_filter�filtered_employeesr�rDrwr�r�r��shift_select_filter�
�
�rPcCr<)Nr�rrEr�r=cSr?r�r@rAr�r�r�r�*rBz$work_type_select.<locals>.<listcomp>rCFrE)
r#r�r�rHr�r�rr�r<rrGr�r�r��work_type_selects���
rRc	CrJ)Nr�r�rr{cSr?r�r@rAr�r�r�r�@rBz+work_type_select_filter.<locals>.<listcomp>rC)r#r�r�r�r7r�r�rr�r<rrKr�r�r��work_type_select_filter2rQrScC�x|j�d�}|dkr!|j�d�rtjjdd�}ntjj|jd�}ntj��}dd�|D�}|��}||d	�}t	|d
d�S)Nr�rrTrzr=cSr?r�r@rAr�r�r�r�VrBz)rotating_shift_select.<locals>.<listcomp>rCFrE)
r#r�r�rHrRr�r�rr<rrGr�r�r��rotating_shift_selectH��

rUc	CrJ)Nr�r�rr{cSr?r�r@rAr�r�r�r�lrBz0rotating_shift_select_filter.<locals>.<listcomp>rC)r#r�r�r�r1rRr�rr�r<rrKr�r�r��rotating_shift_select_filter^rQrWcCrT)Nr�rryTrzr=cSr?r�r@rAr�r�r�r��rBz-rotating_work_type_select.<locals>.<listcomp>rCFrE)
r#r�r�rHr�r�r�rr<rrGr�r�r��rotating_work_type_selecttrVrXc	CrJ)Nr�r�rr{cSr?r�r@rAr�r�r�r��rBz4rotating_work_type_select_filter.<locals>.<listcomp>rC)r#r�r�r�r3r�r�rr�r<rrKr�r�r�� rotating_work_type_select_filter�rQrYzhorilla_audit.view_audittagcCrO)z0
    This method is used to show Audit tags
    zbase/tags/tags.html�	audittags)r�r�rr!)r�rZr�r�r��tag_view��
�r[zhelpdesk.view_tagcCrO)z4
    This method is used to show Help desk tags
    zbase/tags/helpdesk_tags.html�tags)r�r�rr!)r�r]r�r�r��helpdesk_tag_view�r\r^zhelpdesk.add_tagcCrR)�E
    This method renders form and template to create Ticket type
    r��"Tag has been created successfully!r��base/tags/tags_form.htmlr�)
r_r�r�r	rrr�r�rr!rTr�r�r��
tag_create��

��rbzhelpdesk.change_tagcC�ptjj|d�}t|d�}|jdkr/t|j|d�}|��r/|��t�}t�	|t
d��td�St|d||d��S)r_r.rr��"Tag has been updated successfully!r�ra�r��tag_id)
r�r�r�r_r�r�r	rrr�r�rr!�r�rg�tagr�r�r�r��
tag_update��

�rjzhorilla_audit.add_audittagcCrR)r_r�r`r��"base/audit_tag/audit_tag_form.htmlr�)
r<r�r�r	rrr�r�rr!rTr�r�r��audit_tag_create�rcrmzhorilla_audit.change_audittagcCrd)r_r.rr�rer�rlrf)
r�r�r�r<r�r�r	rrr�r�rr!rhr�r�r��audit_tag_updaterkrnz#base.view_multipleapprovalconditioncCslt�}|j�d�}|dkrtjj|d��d�ddd�}n
tj���d�ddd�}d}t|d|||d��S)	Nrr�rrrTz'multi_approval_condition/condition.html)r��
conditionsr:)	rOrr�r�r�r�r�rr!)r�r�rrpr:r�r�r��multiple_approval_conditions"���
�rqcCs^|j�d�}|dkrtjj|d��d�ddd�}n
tj���d�ddd�}t|dd|i�S)Nrrrorrz-multi_approval_condition/condition_table.htmlrp)rr�r�r�r�r�rr!)r�rrpr�r�r��hx_multiple_approval_condition/s����rrz"base.add_multipleapprovalconditioncCsB|j�d�}t�}|r|dkrdnd}||d�}td|�}t|�S)N�condition_operator�rangeTF)r�rtz4multi_approval_condition/condition_value_fields.html)r#r�rOr"r)r��operatorr��is_rangerwrr�r�r��get_condition_value_fieldsCs
�rwc
Cs6|j�d�}|�d�}d�|dtt|d�d�g�}t�}|j�d�}||d�}|rkt|�d}d|��}d	td
�fgdd�t	j
��D�}tj
|tjd
|d|��d�d�dd�|j|<||d<||��|d<n'|jdjj�dtt|d�d���dtt|d�d���d��||d<td|�}	t|	�S)Nrr�rrr��managers_count)r�currnet_hx_target�multi_approval_manager_r��Reporting ManagercS�g|]	}|jt|�f�qSr��rdr�r�r�r�r�r�b��z.add_more_approval_managers.<locals>.<listcomp>rrrr
F)�choicesrr
r�multi_approval_manager�id_multi_approval_manager_)r�r/r�z7multi_approval_condition/add_more_approval_manager.html)rIr�rr�r�rrOr#r�r�r�rr	�ChoiceFieldrr0rrr�updater"r)
r�ry�hx_target_splitrr�rxrwr�rrr�r�r��add_more_approval_managersQsH
"�
�������r�cCst�Src)rr�r�r�r��remove_approval_manager�sr�cCsXt�}d}|jdkr�t|j�}|j�d�}|j�d�}|j�d�}|j�d�}|j�d�}|j�d�}|j�d	�}	|j�d
�}
tjj|	d�}tjj|d�}t�}
|�	�r�||
_
||
_||
_||
_
|dkrh||
_n||
_||
_|
��d
}|
D]!}|d7}d}zt|�}Wnd}|}Ytjj|
|||d�qvt�}t�|td��t|d||d��S)NTr�r�condition_fieldrs�condition_value�condition_start_value�condition_end_valuerr�r.rtrr���condition_id�sequencer��reporting_managerz0Multiple approval condition created successfullyz3multi_approval_condition/condition_create_form.html)r�r:)rOr�r�r�r�ryr�r|r�r	rr�rsrr�r�r�rrr�r:rr�r�r!)r�r�r:�dept_idr�rsr�r�r�r�condition_approval_managersr
rr�r�r�r�r�r�r�r��multiple_level_approval_create�sb

���r�cCs�t|�D]B\}}|dkr|j|jd<qd|��}dtd�fgdd�tj��D�}tj|td��	|�tj
d	d
id�dd
�|j|<|j|j|<q|S)Nrr�rzr�r{cSr|r�r}r�r�r�r�r��r~z*edit_approval_managers.<locals>.<listcomp>zApproval Manager {}r	rr
F)r�labelrr
)�	enumerater�r�r�r�r�rr	r�r�rr0)r��managers�ir�r�rr�r�r��edit_approval_managers�s
��r�z%base.change_multipleapprovalconditionc	CsNd}tjj|d�}tjj|d��d�}t|d�}t||�|jdkrrt|j	|d�}|�
�rr|��}t�
|td��d}tjj|d���|j	��D](\}}	|�d	�rq|d
7}d}
zt|	�}Wnd}|	}
Ytjj||||
d�qI|j�d�}|d
kr�tjj|d��d�ddd�}
n
tj���d�ddd�}
t|d||
||t|�d��S)NFr.)r�r�rr�z0Multiple approval condition updated successfullyrr�r�r�rrrorrz1multi_approval_condition/condition_edit_form.html)r�rpr:�	conditionrx)r�r�r�r�r�r�rOr�r�r�r	rrr�r�r�r��
startswithrr:rrr!r�)r�r�r:r�r�r�r�r�r�r�r�r�rrpr�r�r��multiple_level_approval_edit�sh�


�
�������r�z%base.delete_multipleapprovalconditioncCs.tjj|d�}|��t�|td��tt�S)Nr.z0Multiple approval condition deleted successfully)	r�r�r�r�rr�r�r rr)r�r�r�r�r�r��multiple_level_approval_deletesr�c	Cspt�|�}|jj}t|j|d�d�}|jdk�r.t|j�}|���r.||j	_
||j	_|��t
jj|d��d�}d}|��s@d}t|j|d�d�}t�|td��tjj|j
d	�}|���r#|j
jjd
u�r|jjj|j
jkr�|j
jjj}tj|jj||j
�d�d|j
�d
�|j
�d�d|j
�d�d|j
�d�td�d|j��dd�	n~|jjj|j
jjjkr�|j
j}tj|jj|dddddtd�d|j��dd�	nV|j
j|j
jjjg}tj|jj||j
�d�d|j
�d
�|j
�d�d|j
�d�d|j
�d�td�d|j��dd�	n|j
j}tj|jj|dddddtd�d|j��dd�	t|d||||d��St|d|||d��S)zP
    This method renders form and template to create shift request comments
    �r��
request_idr�r��r��-created_atFT�Comment added successfully!r�Nz('s shift request has received a comment.uتلقت طلب تحويل � تعليقًا.z-s Schichtantrag hat einen Kommentar erhalten.zLa solicitud de turno de � ha recibido un comentario.z%La demande de changement de poste de � a reçu un commentaire.r�r\�chatbox-ellipsesrhz*Your shift request has received a comment.u.تلقت طلبك للتحول تعليقًا.z/Ihr Schichtantrag hat einen Kommentar erhalten.z0Tu solicitud de turno ha recibido un comentario.u<Votre demande de changement de poste a reçu un commentaire.�%shift_request/htmx/shift_comment.html��comments�no_commentsr�r�)r�r�r�)r�rr�r�r]r/r�r�r	r�r�r�rr�r�r�r�r�rr�r�r�r�r�r�r�r,r#r!)	r�r�rr�r�r�r�rl�recr�r�r��create_shiftrequest_comments�

�

�
��
�
�

�
��
�

����

�r�cC�t�|�}tjj|d��d�}d}|��sd}|jrH|j�d�}|j	d}tjj
|d�}g}|D]}	t�}
|	|
_|
�
�|�|
�q0|jj|�t|d||||d	��S)
�E
    This method is used to render all the notes of the employee
    r�r�FT�files�
comment_idr.r�r�)r�rr�r�r�r�r�rr�r#r�rwr�rr�r�r�r!)r�r�r�r�r�r�r��comment�attachmentsr��
file_instancer�r�r��view_shift_comment��6
�
��r�cC�|j�d�}|jd}|jd}t�|�}d}|jj|jks(|j�d�s(t|�r=t	j
j|d���t
�|td��t|�St
�|td��d	|�d
�}t|�S)�#
    Used to delete attachment
    r7r�r�r9�base.delete_baserequestfiler8�File deleted successfullyrf�"<span hx-get="/view-shift-comment/�Y/" hx-trigger="load" hx-target="#commentContainer" data-target="#activitySidebar"></span>)r#r�r�rr�r�r�rHrnrwr�r�r�rr�r�r�r)r�r7r�r�r�r�r�r�r��delete_shift_comment_file�� 



���r�cCr�)
r�r�r�FTr�r�r.�-work_type_request/htmx/work_type_comment.html�r�r�r�r^)r�rr�r�r�r�r�rr�r#r�rwr�rr�r�r�r!)r�r{r^r�r�r�r�r�r�r�r�r�r�r��view_work_type_comment�r�r�cCr�)r�r7r�r�r9r�r8r�rf�&<span hx-get="/view-work-type-comment/r�)r#r�r�rr�r�r�rHrnrwr�r�r�rr�r�r�r)r�r7r�r�r�r�r�r�r��delete_work_type_comment_file�r�r�cCs|t�|�}|jj}d}|jj|jks|j�d�st|�r,|�	�t
�|td��t|�St
�
|td��d|�d�}t|�S)z>
    This method is used to delete shift request comments
    r9r��Comment deleted successfully!rfr�r�)r�rr�r/r�r�r�rHrnr�rr�r�r�r)r�r�r�r�r�r�r�r��delete_shiftrequest_comments

���r�c	Csxtjj|d���}|jj}t|j|d�d�}|jdk�r2t|j	�}|�
��r2||j_||j_
|��tjj|d��d�}d}|��sDd}t|j|d�d�}t�|td	��tjj|jd
�}|���r'|jjjdu�r|jjj|jjkr�|jjjj}tj|jj||j�d�d
|j�d�|j�d�d|j�d�d|j�d�td�d|j��dd�	n~|jjj|jjjjkr�|jj}tj|jj|dddddtd�d|j��dd�	nV|jj|jjjjg}tj|jj||j�d�d
|j�d�|j�d�d|j�d�d|j�d�td�d|j��dd�	n|jj}tj|jj|dddddtd�d|j��dd�	t|d||||d��St|d|||d��S) zT
    This method renders form and template to create Work type request comments
    r.r�r�r�r�r�FTr�r�Nz,'s work type request has received a comment.u"تلقت طلب نوع العمل r�z1s Arbeitsart-Antrag hat einen Kommentar erhalten.z#La solicitud de tipo de trabajo de r�z!La demande de type de travail de r�r[r\r�rhz.Your work type request has received a comment.uAتلقى طلب نوع العمل الخاص بك تعليقًا.z3Ihr Arbeitsart-Antrag hat einen Kommentar erhalten.z:Tu solicitud de tipo de trabajo ha recibido un comentario.u8Votre demande de type de travail a reçu un commentaire.r�r�)r�r�r^)r�r�r�r�r�r�rcr/r�r�r	r�r�r�rr�r�r�rr�r�r�r�r�r�r�r,r#r!)	r��worktype_idrmr�r�r�r�rlr�r�r�r��create_worktyperequest_comments�
�

��
��
�
�


��
�
��
�


��

����

�r�cCs|d}t�|�}|jj}|jj|jks|j�d�st|�r,|�	�t
�|td��t|�St
�
|td��d|�d�}t|�S)zB
    This method is used to delete Work type request comments
    r9r�r�rfr�r�)r�rr�r/r�r�r�rHrnr�rr�r�r�r)r�r�r�r�r�r�r�r��delete_worktyperequest_comment�s

���r�cCs�tjj|jd���r6tjj|jd���}t|d�}|jdkr5t|j|d�}|�	�r5|�
�t�|t
d��nt�}|jdkrSt|j�}|�	�rS|�
�t�|t
d��|j�d�r\t�St|j�dd��S)Nrrr�zDefault pagination updated.r�rDr�)r~r�r�r�r�r�rDr�r�r	rrr�r�rIr�rr)r�rrr�r�r��pagination_settings_view�s(

�
�r�zemployee.view_actiontypecCrO)z1
    This method is used to show Action Type
    z!base/action_type/action_type.html�action_types)r�r�rr!)r�r�r�r�r��action_type_view�s

�r�zemployee.add_actiontypecCs�t�}|j��}|j�d�}|jdkrTt|j�}|��rT|��t�}t�	|t
d��|dkrTtd�}tj
���d���}|j��}t|j�|d<t|�d|�����St|d	||d
��S)zE
    This method renders form and template to create Action Type
    r[r�z%Action has been created successfully!�Nonezcreate-actionsr|�actionr!�&base/action_type/action_type_form.html�r�r�)r�r#rr�r�r�r	rrr�r�r#r�r�rr�r�r�r�r/r r!)r�r�r�r[r�r��mutable_getr�r�r��action_type_create�s,



��r�zemployee.change_actiontypecCs�tjj|d�}t|d�}|jdkr$tj��r$tj��jr$t�	�|j
d_|jdkrPt|j
|d�}|��rP|jd}|dkrAd|j_|��t�}t�|td��t|d	||d
��S)zE
    This method renders form and template to update Action type
    r.rr��block_optionr��action_typeFz%Action has been updated successfully!r�)r��act_id)r�r�r�r�r�r�r�rr	�HiddenInputr0rr�r�r	rr�r�rrr�r�r!)r�r�r�r��act_typer�r�r��action_type_update�s,

�
�

�r�zemployee.delete_actiontypecCsRtjj|d���rt�|td��td�Stjj|d��	�t�
|td��t�S)z8
    This method is used to delete the action type.
    )r�zIThis action type is in use in disciplinary actions and cannot be deleted.r�r.z%Action has been deleted successfully!)r�r�r�r�rr�r�rr�r�r�)r�r�r�r�r��action_type_delete	s��r�cCs"t|j�}|��r
|��td�S)z<
    This method is used to update driver viewed status
    r9)rAr#r	rrrTr�r�r��driver_viewed_status s
r�cCsXtjj|jjd�d}|jpg}|j�d�}|r(||vr(|�|�||_|�	�t
d�S)zU
    This function is used to create personalized dashboard charts for employees
    rgr�chart_idr9)r{r�rnr�r�rjr#r�r�rr)r�rvrjr�r�r�r�rv+s��

rvc
Cs�ddlm}t�d�rddlm}gd�}idd�dd�d	d
�dd�dd
�dd�dd�dd�dd�dd�dd�dd�dd�dd�dd�dd
�dd
�ddddd��}idd�dd�d	d �dd!�dd!�dd"�dd#�dd#�dd$�dd%�dd&�dd'�dd(�dd)�dd)�dd*�dd+�d,d-i�}g}gd.�}|D]a}	t�|�|	d��r�|	d|��vs�|	d|vs�t�d�r�|	d|vr�|j�	||	d�r�|�
|	�q�|	d|vr�||j�r�|�
|	�q�t�d�r�|	d|vr�||j�r�|�
|	�q�|�
|	�q�|S)/zr
    This function is used to check the permissions for the charts
    Args:
        charts: dashboard charts
    r)rnr�)�is_stagemanager)�hired_candidates�onboarding_candidates�recruitment_analytics�offline_employeesr��online_employees�overall_leave_chartr�r�r�r�r��attendance_analytic�hours_chart�objective_statusr��key_result_status�feedback_statusr�r3rz�overtime_approve�attendance_validate�leave_request_approve�leave_allocation_approver�r)�asset_request_approve�employees_chart�gender_chart�department_chartzemployee.view_employeezleave.view_leaverequestzrecruitment.view_candidatezrecruitment.view_recruitmentzattendance.view_attendancezpms.view_employeeobjectivezpms.view_employeekeyresultzpms.view_feedbackr�rnzattendance.change_attendancezleave.change_leaverequestz#leave.change_leaveallocationrequestr�zasset.change_assetrequest)r�r�r�r�r�r�r�r�rzr�r�r�r�r�)�base.templatetags.basefiltersrnr
r��+recruitment.templatetags.recruitmentfiltersr�r��keysr�rHr�)
r�rjrnr��need_stage_manager�
chart_appsr��
chart_list�need_reporting_manager�chartr�r�r��check_chart_permission<s�
��������	�
���
��������������	�
���
�������

��

�
�r�cCs�tjj|jjd�d}dtd�fdtd�fdtd�fd	td
�fdtd�fd
td�fdtd�fdtd�fdtd�fdtd�fdtd�fdtd�fdtd�fdtd�fdtd �fd!td"�fd#td$�fd%td&�fd'td(�fd)td*�fd+td,�fd-td.�fg}t||�}|jd/kr�g|_|�	�|j
}|D]3}|d|��vr�|d|jvr�|j�|d�q�|d|��vr�|d|jvr�|j�
|d�q�	q�|�	�td0�S||jd1�}t|d2|�S)3zN
    This function is used to choose which chart to show in the dashboard
    rgrr�zOffline Employeesr�zOnline Employeesr�zOverall Leave Chartr�zHired Candidatesr�zOnboarding Candidatesr�zRecruitment Analyticsr�zAttendance analyticsr�zHours Chartr�zEmployees Chartr�zDepartment Chartr�zGender Chartr�zObjective Statusr�zKey Result Statusr�zFeedback Statusr�zShift Request to ApproverzzWork Type Request to Approver�zOvertime to Approver�zAttendance to Validater�zLeave Request to Approver�zLeave Allocation to Approve�feedback_answerzFeedbacks to Answerr�zAsset Request to Approver�r�)�dashboard_charts�employee_chartzdashboard_chart_form.html)r{r�rnr�r�r�r�r�rjrr�r�r�r�rr!)r�rvrjr�r�rwr�r�r��employee_chart_show�sV��





















�

r�zbase.view_biometricattendancecCrO)Nz&base/install_biometric_attendance.html�	biometric)rxr�r�r!)r�r�r�r�r�� enable_biometric_attendance_view�s
�r�zbase.add_biometricattendancecCsx|jdkr6|j�d�}tj��}|stj��}|dkr'd|_t�	|t
d��nd|_t�|t
d��|��t
dd	i�S)
Nr#r�r�TzAThe biometric attendance feature has been activated successfully.FzCThe biometric attendance feature has been deactivated successfully.r�r�)r�r#r�rxr�r�r:r�rr�r�rJrr)r�r�r�r�r�r��activate_biometric_attendance�s(


���r�cCstj}td|i�S)Nr=)rr:r)r�r=r�r�r��get_horilla_installed_apps�sr�cs<|D]}|��D]\}}||vr|�||�q|�d�qqdd�|��D�}|D]}||=q*tj||��d�}|jjdd�tjdd�dd�fd�}tdd��d	|�d
��d<tj	�dd
�}	|j
|	ddd�|	jd}
|
�dd�|	�
���fdd�}ddlm}m}
dt�����|
�|�|�d��t����S)NcSs&g|]\}}tdd�|D��r|�qS)css�|]}|duVqdSrcr�)r��vr�r�r�r�s�z3generate_error_report.<locals>.<listcomp>.<genexpr>)r)r�r�r�r�r�r�r�s
��z)generate_error_report.<locals>.<listcomp>��columnscSsdS)Nztext-align: centerr�r�r�r�r�r�sz'generate_error_report.<locals>.<lambda>)�subset�application/ms-excel��content_typezattachment; filename="�"�Content-Disposition�
xlsxwriter)�engineF�Sheet1)�index�
sheet_namezA:Z�cst���Src)r�r���	path_infor_r�r��get_error_sheetsz.generate_error_report.<locals>.get_error_sheetr)r�urlpatternszerror-sheet-)r�)r�r�r��	DataFramer��style�applymap�
IndexSlicer�ExcelWriter�to_excel�sheets�
set_columnrg�	base.urlsrr�uuid�uuid4r�)�
error_list�
error_datar��itemr�r��keys_to_remove�
data_frame�styled_data_frame�writer�	worksheetr
rrr�rr��generate_error_report�s8���


r"cCsht�}|j}|j}tj�t||d�t|d�@�}tt|��}t	|�D]	\}}|||_
q"t|dd|i�S)zZ
    Retrieve and display a list of upcoming holidays for the current month and year.
    )�start_date__month�start_date__year)�start_date__gtezholiday/upcoming_holidays.html�holidays)r'rr�yearr�r�r�rrkr�r��background_colorr!)r�rl�
current_month�current_yearr&�colorsr��holidayr�r�r��get_upcoming_holidays(s
��r-zbase.add_holidayscCsv|j��}t�}|jdkr2t|j�}|��r2|��t�}t�|t	d��t
j���
�dkr2td�St|d||d��S)z�
    function used to create holidays.

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

    Returns:
    GET : return holiday creation form template
    POST : return holiday view template
    r�z"New holiday created successfully..r�r�zholiday/holiday_form.htmlr�)r#rrIr�r�r	rrr�r�r�r�r�r<rr!)r�r�r�r�r�r��holiday_creation;s


�r.c
Cshzgd�}tj|d�}tdd�}d|d<|j|dd�|WSty3}z
t|�WYd}~Sd}~ww)	N��Holiday Name�
Start Date�End Date�	Recurringr�rrz3attachment; filename="assign_leave_type_excel.xlsx"rF)r)r�rrrr�)r�r�rr_�	exceptionr�r�r��holidays_excel_templateYs
���r5cCs�gg}}t�dt|����}t�|�}t|dd���}d}t�|�}t|�t	|dd�D]�\}}	zc|	\}
}}}
|
|||
d�}zt
|�}Wnd}td	�|d
<|�|�Yzt
|�}Wnd}td�|d<|�|�Y|
�
�d
vr�d}td�|d<|�|�|r�|�t|
|||
�
�dkd��Wq,ty�}zt|�|d<|�|�WYd}~q,d}~wwWd�n1s�wY|r�tj�|�tj�|�r�t�|�||fS)a*
    Imports holiday data from a CSV file.

    This function reads a CSV file containing holiday information, validates the data,
    and saves valid holiday records to the database using bulk creation for efficiency.

    The expected format for the CSV file is:
    - "Holiday Name": Name of the holiday (string)
    - "Start Date": Start date of the holiday (date string in a recognized format)
    - "End Date": End date of the holiday (date string in a recognized format)
    - "Recurring": Indicates whether the holiday recurs ("yes" or "no")
    zholiday_import.csv�ignore)�errorsTr�)�startr/FzInvalid start date format.�Start Date ErrorzInvalid end date format.�End Date Error��yes�nozRecurring must be yes or no.�Recurring Field Errorr<�r��
start_date�end_date�	recurring�Other ErrorsN)r�rrr)rr(�csv�readerr r�rjr�r�r"r�r�r�r��bulk_create�osr�r�)r��holiday_listrr��holiday_file�csv_filerrE�
total_rows�rowr�r@rArB�holiday_dictrYr�r�r��csv_holiday_importlsn



��

���	����2
rNcCsxg}g}t�|�}|�d�}|D]�}d}z||d}zt�|d���}Wnty:d}td��|d�|d<Ynwzt�|d���}	Wnty\d}td	��|d�|d
<Ynw|�dd��	�}
|
d
vrn|
dk}nd}td��dd�|d<|r�t
|||	|d�}|�|�n|�|�Wqty�}
zt|
�|d<|�|�WYd}
~
qd}
~
ww|r�t
j
�|�|t|�fS)a2
    Imports holiday data from an Excel file.

    This function reads an Excel file containing holiday information, validates the data,
    and saves valid holiday records to the database using bulk creation for efficiency

    The expected format for the Excel file is:
    - "Holiday Name": Name of the holiday (string)
    - "Start Date": Start date of the holiday (date string in a recognized format)
    - "End Date": End date of the holiday (date string in a recognized format)
    - "Recurring": Indicates whether the holiday recurs ("yes" or "no")

    �recordsTr0r1FzInvalid start date format {}r9r2zInvalid end date format {}r:r3r9r;r<zRecurring must be {} or {}r=r>r?zOther errorsN)r��
read_excel�to_dict�to_datetimerpr�r�r�r�r"r�r�r�r�rFr�)r�r�valid_holidaysr�
holiday_dictsr,rr�r@rA�
recurring_strrB�holiday_instancerYr�r�r��excel_holiday_import�sf

����
���
���rWzbase.add_holidayc	Cs�d}d}d}ggggggggd�}|jdkri|j�d�}|ri|j}|dkr4t|�\}}|r3t|||�}n|dkrGt|�\}}|rFt|||�}nt�|t	d��t
d�S|t|�}	|	t|�t	d	�|d
�}
td|
�}t
|�S)NzHolidaysImportError.xlsx)r0r1r2r3r9r:r>rCr��holidays_importztext/csvzAapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheetz/The file you attempted to import is unsupportedr�r�)�
created_count�error_countr�rzimport_popup.html)
r�rr�rrNr"rWrr�r�rr�r")r�rJr�rrr�rrrD�created_holidays_countrwr�r�r��holidays_info_import�sP�
�����
r\cCsB|j�d�rt�}t�}||d�}t|d|d�St|tttdd�S)Nr�)r��
export_columnz'holiday/holiday_export_filter_form.htmlr��Holidays_exportr�)rIr�r/rJr!rgr�)r�r�r]r^r�r�r��holiday_info_export0s ���r_cCsPtj��ddd�}|j��}|j�d�}t||�}t�}t|d||j	|d��S)z�
    function used to view holidays.

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

    Returns:
    GET : return holiday view  template
    Nrr�zholiday/holiday_view.html)r&r�r�)
r�r�rr#rr�ror/r!r�)r�r1r�rH�page_obj�holiday_filterr�r�r��holiday_viewEs

��rbcCs�tj��}|j��}t|j|�j}|j�d�rt||d�}|j�d�}t	|ddd�|�}t
|�}tt|�t|d|||d��S)z�
    function used to filter holidays.

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

    Returns:
    GET : return holiday view template
    rqr�Nrzholiday/holiday.html)r&r�r�)
r�r�rr#rr/r�r�rqrorrlr!)r�r1r�rarHr`r�r�r�r�raas



�razbase.change_holidayscCs�|j��}|�d�rt|td�d��}nt|�}tjj|d�}t|d�}|j	dkrAt|j
|d�}|��rA|��t
�|td��t|d|||d��S)	z�
    function used to update holiday.

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

    Returns:
    GET : return holiday update form template
    POST : return holiday view template
    rVNr.rr�zHolidays updated successfully..z holiday/holiday_update_form.html)r�r/r�)r#rr�rr�r�r�r�rIr�r�r	rrr�r�r!)r�r�query_stringr�r,r�r�r�r��holiday_update}s 




�rdzbase.delete_holidayscC�|j��}ztjj|d���t�|td��Wn"tj	y*t�
|td��Ynty:t�
|td��Ynwtj��sDt
d�Std|���S)z�
    function used to delete holiday.

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

    Returns:
    GET : return holiday view template
    r.zHolidays deleted successfully..zHolidays not found.�Related entries existsr�z/holiday-filter?)r#rr�r�r�r�rr�r�r�r�rr�rr )r�rrcr�r�r��holiday_delete��
�
rgzbase.delete_holidaycCs@|j�d�}tjj|d���d}t�|td�	|���t
d�S)zL
    Deletes multiple holidays based on IDs passed in the POST request.
    r7r8rz+{} Holidays have been successfully deleted.zholiday-filter)r�r�r�r�r�r�rr�r�r�r )r�r7�
deleted_countr�r�r��bulk_holiday_delete�s�rjcCsJ|j�d�}|dkrtj��}dd�|D�}|��}||d�}t|dd�S)Nr�rcSr?r�r@rAr�r�r�r��rBz"holiday_select.<locals>.<listcomp>rCFrE)r#r�r�r�rr<rrGr�r�r��holiday_select�s

rkc	CrJ)Nr�r�rr{cSr?r�r@rAr�r�r�r��rBz)holiday_select_filter.<locals>.<listcomp>rC)r#r�r�r�r/r�r�rr�r<rrKr�r�r��holiday_select_filter�s
�rlzbase.add_companyleavescCsdt�}|jdkr*t|j�}|��r*|��t�|td��tj	�
���dkr*td�St
|dd|i�S)��
    function used to create company leave.

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

    Returns:
    GET : return company leave creation form template
    POST : return company leave view template
    r�z(New company leave created successfully..r�r�z.company_leave/company_leave_creation_form.htmlr�)r?r�r�r	rrr�r�rzr�r�r<rr!rTr�r�r��company_leave_creation�s


�rnc	CsJtj��}|j��}|j�d�}t||�}t�}t|d|t	t
|j|d��S)z�
    function used to view company leave.

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

    Returns:
    GET : return company leave view template
    r�z%company_leave/company_leave_view.html)�company_leaves�weeks�	week_daysr�r�)rzr�rr#rr�ror.r!rsrrr�)r�r1r�rHr`�company_leave_filterr�r�r��company_leave_views


��rsc	Csbtj��}|j��}|j�d�}t|j|�j}t||�}t	|�}t
t|�t|d|tt
||d��S)z�
    function used to filter company leave.

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

    Returns:
    GET : return company leave view template
    r�z company_leave/company_leave.html)rorprqr�r�)rzr�rr#rr�r.r�rorrlr!rsrr)r�r1r�rHrrr`r�r�r�r�rr$s"



��rrzbase.change_companyleavescCsbtjj|d�}t|d�}|jdkr(t|j|d�}|��r(|��t�	|t
d��t|d||d��S)z�
    function used to update company leave.

    Parameters:
    request (HttpRequest): The HTTP request object.
    id : company leave id

    Returns:
    GET : return company leave update form template
    POST : return company leave view template
    r.rr�z$Company leave updated successfully..z,company_leave/company_leave_update_form.html)r�r/)rzr�r�r?r�r�r	rrr�r�r!)r�r/�
company_leaver�r�r�r��company_leave_updateEs

�ruzbase.delete_companyleavescCre)rmr.z$Company leave deleted successfully..zCompany leave not found.rfr�z/company-leave-filter?)r#rrzr�r�r�rr�r�r�r�rr�rr )r�r/rcr�r�r��company_leave_deletebrhrvcCst|j�j}t|dd|i�S)z=
    This method is used to filter or view the penalties
    zpenalty/penalty_view.htmlrO)r0r#r�r!)r�rOr�r�r��view_penalties}srw)NN(�rTrDr�rGrrr�email.mime.imagerr�urllib.parserrr�pandasr��djangor	�django.appsr
�django.confr�django.contribr�django.contrib.authr
rr�django.contrib.auth.modelsrrr�django.contrib.auth.viewsrr�django.core.files.baser�django.core.mailr�django.core.managementr�django.core.paginatorr�django.db.modelsrr�django.httprrrr�django.shortcutsrr r!�django.template.loaderr"�django.urlsr#r$�django.utilsr%�django.utils.htmlr&�django.utils.timezoner'�django.utils.translationr(r��django.views.decorators.csrfr)�django.views.decorators.httpr*�
base.backendsr+�base.decoratorsr,r-�base.filtersr.r/r0r1r2r3r4r5r6r7r8�
base.formsr9r:r;r<r=r>r?r@rArBrCrDrErFrGrHrIrJrKrLrMrNrOrPrQrRrSrTrUrVrWrXrYrZr[r\r]r^r_r`rarbrcrd�base.methodsrerfrgrhrirjrkrlrmrnrorprq�base.modelsrrrsrtrurvrwrxryrzr{r|r}r~rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��employee.filtersr��employee.formsr�r��employee.modelsr�r�r�r�r��horilla.decoratorsr�r�r�r�r�r��horilla.group_byr�r�r�r�r�r�r��horilla.methodsr�r��horilla_audit.formsr��horilla_audit.modelsr�r�r��notifications.modelsr��notifications.signalsr�r�r�r�r�r�r�rrrrrrrr,r2r3r4rX�setattrr]r`rar�r�r�r�r�r�r�r�r�r�r�r�r�rrr r6r>rBrCrGrHrIrKrNrPrQrUrVrXrr_rarerfrgrkrlrnrrrtrxr�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr	rr
rrrrrrrrr r#r'r(r)r�r>rArCrDrJrNrUrYr^rcrmrorzr{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�rrr*r,r.r/r6r;rIrPrRrSrUrWrXrYr[r^rbrjrmrnrqrrrwr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rvr�r�r�r�r�r"r-r.r5rNrWr\r_rbrardrgrjrkrlrnrsrrrurvrwr�r�r�r��<module>s24�
<.�" (
.


%

!
'
2..
!
"K
# #


B3DP
"	
%/8!&)/1!%+;$&08?".',) 6*;FGl$BH%9D"/#+
	M**.67o""t

c3	*LF0

Youez - 2016 - github.com/yon3zu
LinuXploit