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/payroll/models/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/erp/payroll/models/__pycache__/models.cpython-310.pyc
o

hͦh��@s�dZddlZddlZddlmZmZmZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZdd	lmZmZmZdd
lmZddlmZddlmZdd
lmZddlmZddlm Z ddl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(ddl)m*Z*ddl+m,Z,m-Z-m.Z.ddl/m0Z0ddl1m2Z2ddl3m4Z4m5Z5e�6e7�Z8dd�Z9dd�Z:Gdd�de2�Z;Gdd�de2�Z<Gdd�dej=�Z>e	�?d �r�dd!l@mAZAGd"d#�d#eA�ZBeeeAd$�d%d&��ZCe	�?d'�r�dd(lDmEZEGd)d*�d*eE�ZFeee.d$�d+d,��ZGd-d.�ZHd/ed0�fd1ed2�fd3ed4�fd5ed6�fd7ed8�fd9ed:�fd;ed<�fgZId/ed0�fd1ed2�fd3ed4�fd5ed6�fd7ed8�fd9ed:�fd=ed>�fgZJd?ed@�fdAedB�fdCedD�fdEedF�fdGedH�fdIedJ�fdKedL�fdMedN�fdOedP�fdQedR�fg
ZKGdSdT�dTej=�ZLGdUdV�dVe2�ZMGdWdX�dXe2�ZNGdYdZ�dZe2�ZOGd[d\�d\e2�ZPd]d^�ZQeeePd$�d_d`��ZRGdadb�dbej=�ZSGdcdd�dde2�ZTzeTjUjVdedf��W��r�eTjUjVdedf�jXdgdf�WnYGdhdi�diej=�ZYGdjdk�dke2�ZZGdldm�dmej=�Z[Gdndo�doej=�Z\gdpedq�f�dr�ds�dt�du�dv�dw�dx�dy�dz�d{�d|�d}�d~�d�d��d��d��d��d��d��d��d��d��d��d��d��d��d��d��d��d��Z]Gd�d��d�ej=�Z^dS)�z#
models.py
Used to register models
�N)�date�datetime�	timedelta)�forms)�apps)�messages)�ValidationError)�models)�	post_save�
pre_delete�pre_save)�receiver)�	QueryDict)�timezone)�gettext_lazy)�HorillaCompanyManager)�get_next_month_same_date)�Company�
Department�
EmployeeShift�JobPosition�JobRole�WorkType�validate_time_format)�strtime_seconds)�
BonusPoint�Employee�EmployeeWorkInformation)�horilla_middlewares)�HorillaModel)�HorillaAuditInfo�HorillaAuditLogcCs|dkr
ttd���dS)z2
    The minimum value zero validation method
    rzValue must be greater than zeroN�r�_��value�r&�%/var/www/erp/payroll/models/models.py�min_zero,s�r(cCs<g}||}t|jd�D]}|t|d�}|�|�q
|S)a�
    Returns a list of all dates within a given date range.

    Args:
        start_date (date): The start date of the range.
        end_date (date): The end date of the range.

    Returns:
        list: A list of date objects representing all dates within the range.

    Example:
        start_date = date(2023, 1, 1)
        end_date = date(2023, 1, 10)
        date_range = get_date_range(start_date, end_date)
    �)�days)�ranger*r�append)�
start_date�end_date�	date_list�delta�i�current_dater&r&r'�get_date_range4sr3c@s�eZdZdZded�fded�fded�fgZejdd	ed
�d�Zejded	d	ded
�d�Z	ej
dd	d�Zejdd�Z
ejded�dd�Zejedd	ejd�Ze�Zdefdd�ZGdd�d�ZdS)�FilingStatusz
    FilingStatus model
    �	basic_pay�	Basic Pay�	gross_pay�	Gross Pay�taxable_gross_pay�Taxable Gross Pay�Fz
Filing status)�
max_length�blank�verbose_name�zBased on)r<�choices�nullr=�defaultr>zPython Code)r>rBT�rA�Description)r=r>r<�rA�editable�	on_delete�returncC�
t|j�S�N)�str�
filing_status��selfr&r&r'�__str__q�
zFilingStatus.__str__c@�eZdZdgZdS)zFilingStatus.Meta�-idN��__name__�
__module__�__qualname__�orderingr&r&r&r'�Metat�
rXN)rTrUrV�__doc__r#�based_on_choicer	�	CharFieldrL�based_on�BooleanField�use_py�	TextField�python_code�description�
ForeignKeyr�PROTECT�
company_idr�objectsrKrOrXr&r&r&r'r4Ns@


����
�r4cseZdZdZded�fded�fded�ffZded	�fd
ed�fded
�ffZded�fd
ed�fgZe�	d�rBe�
ded�f�ded�fded�fded�fded�ffZzded�fgee
j�dd��ZWnYejded�ed�d�Zejeejd ed!�d"�Zejed#�d$�Zejd%d%ed&�d'�Zejedd
ed(�d)�Zejd*d%ed
ed+�d,�Zejed-�d%d.d/�Zeje
ejd0d%d%ed1�d2�Zejedded3�d)�Z eje!ejd%d%d0ed4�d5�Z"eje#ejd%d%d0ed6�d5�Z$eje%ejd%d%d0ed7�d5�Z&eje'ejd%d%d0ed8�d5�Z(eje)ejd%d%d0ed9�d5�Z*ej+d:ed;�e,ged<�d=�Z-ej.d>d%d%d?�Z/ej0d%ed@�edA�dB�Z1ej0d%edC�edD�dB�Z2ejd%d%d.edE�dF�Z3ej4d%d%dGdH�Z5e6dIe7gdJ�Z8e9dK�ZdLe:fdMdN�Z;dOdP�Z<�fdQdR�Z=GdSdT�dT�Z>�Z?S)U�Contractz
    Contract Model
    �salary�Salary�hourly�Hourly�
commission�
Commission�weekly�Weekly�monthly�Monthly�semi_monthlyzSemi-Monthly�daily�Daily�
attendance�draft�Draft�active�Active�expired�Expired�
terminated�
Terminated��None�idrL�zContract Title.)r<�	help_textr>�contract_setr)rG�related_namer>z
Start Date�r>TzEnd Date)rAr=r>�	Wage Type)r@r<rBr>��
Pay Frequency)r<rAr@rBr>zBasic Salaryr)r>rArB�	contractsz
Filing Status)rGr�rAr=r>�Statusr)rGrAr=r�r>zJob PositionzJob Role�Shift�	Work Typer;zNotice period in total days.z
Notice Period)rBr��
validatorsr>zuploads/)�	upload_torAr=zDeduct From Basic Payz'Deduct the leave amount from basic pay.�rBr>r�zCalculate Daily Leave AmountzTLeave amount will be calculated by dividing the basic pay by number of working days.zDeduction For One Leave Amount)rAr=rBr>r?)rAr=r<�history_set�r��bases�+employee_id__employee_work_info__company_idrHcCs|j�d|j�d|j��S)Nz -� - )�
contract_name�contract_start_date�contract_end_daterMr&r&r'rOszContract.__str__cCs�|jdur|j|jkrtdtd�i��|jdkr1tjj|jdd�j	|j
d���dkr1t�td���|jdkrOtjj|jdd�j	|j
d���dkrOt�td	���|j
d
vrd|jsf|jdurhtdtd�i��dSdSdS)
Nr�z(End date must be greater than start daterx��employee_id�contract_status�r�r)�4An active contract already exists for this employee.rv�2A draft contract already exists for this employee.)rsrp�deduction_for_one_leave_amount�This field is required)r�r�rr#r�rgrf�filterr��exclude�pk�countr�	wage_type�calculate_daily_leave_amountr�rMr&r&r'�cleansL

�
����
����


��zContract.cleanc
s�tjj|jd���rA|jdur|jjj|_|jdur |jjj	|_|j
dur+|jjj|_
|jdur6|jjj
|_|jdurA|jjj|_|jdurP|jt��krPd|_|jdkrntjj|jdd�j|jd���dkrnt�td���|jdkr�tjj|jdd�j|jd���dkr�t�td	���t�j|i|��|jdkr�|jdur�zt|j�}|jj}||_ |��W|St!y�t"�#d
|j�d��Y|St$y�}zt"�#d|���WYd}~|Sd}~ww|S)
N�r�rzrxr�r�r)r�rvr�zFailed to convert wage 'z' to an integer.zAn unexpected error occurred: )%rrfr�r��exists�
department�employee_work_info�
department_id�job_position�job_position_id�job_role�job_role_id�	work_type�work_type_id�shift�shift_idr�r�todayr�rgr�r�r�rrr#r��super�save�wage�int�basic_salary�
ValueError�logger�error�	Exception)rN�args�kwargs�wage_int�	work_info�e��	__class__r&r'r�<st��





����
����

����z
Contract.savec@seZdZdZgd�ZdS)z
Contract.Metaz6
        Meta class to add additional options
        )r�r�r�N)rTrUrVrZ�unique_togetherr&r&r&r'rXvsrX)@rTrUrVrZr#�COMPENSATION_CHOICES�PAY_FREQUENCY_CHOICES�WAGE_CHOICESr�is_installedr,�CONTRACT_STATUS_CHOICES�listr4rf�values_list�FILING_STATUS_CHOICESr	r\r�rcrrdr��	DateFieldr�r�r��
pay_frequency�
FloatFieldr�rLr�rr�rr�rr�rr�rr��IntegerFieldr(�notice_period_in_days�	FileField�contract_documentr^�deduct_leave_from_basic_payr�r�r`�noter!r �historyrrKrOr�r�rX�
__classcell__r&r&r�r'rgxs


�


�

�




�
���
�����������������&:rgcsZeZdZdZded�fded�fded�fded	�fd
ed�fded
�fgZejdddd�Zejdded�Z	ej
eejed�d�Z
ejddd�Zejddegddd�Zejddegddd�Zejdddd�Zejdddd�Zejdd�Zejdddd�Zejdd�Zejdd�Zejdd�Zejddd�Ze d�Z!�fd d!�Z"�fd"d#�Z#d$d%�Z$�Z%S)&�
WorkRecordz
    WorkRecord Model
    �FDP�Present�HDPzHalf Day Present�ABS�Absent�HDzHoliday/Company Leave�CONF�Conflict�DFTrwr�T)r<rAr=�)r<rAr@r�rGr>)rAr=z00:00)rAr=r�rBr<r)rAr=rBr?�r<r;F�rBr�cs t��|_t�j|i|��dSrJ)r�now�last_updater�r��rNr�r�r�r&r'r��s
zWorkRecord.savecs2t���d|jkrdksnttd���dS)N���?z*Day percentage must be between 0.0 and 1.0)r�r��day_percentagerr#rMr�r&r'r��s
�zWorkRecord.cleancCs"|jdur|jS|j�d|j��S)N�-)�record_name�work_record_typerrMr&r&r'rO�s

���zWorkRecord.__str__)&rTrUrVrZr#r@r	r\r�r�rcrrdr�r�rr�at_work�min_hourr��at_work_second�min_hour_secondr`r��messager^�is_attendance_record�is_leave_recordr�r��
DateTimeFieldr�rrfr�r�rOr�r&r&r�r'r�~sV





�	���	��	r�ru)�
Attendancec@s$eZdZdZeeed�dd��ZdS)�OverrideAttendance�@
        Class to override Attendance model save method
        ��sendercKs�|jr�t|j�}t|j�}|j|krdnd}|jdurdn|}|dkr'td�ntd�}|dkr7||kr7td�n|}tjj	|j
d|jd	�}tjj	|j
|jd
���sSt�ntjj	|j
|jd
��
�}|j|_|j
|_|j|_|j|_||_||_||_||_d|_|jr�||dkr�dnd
|_|��|dkr�|jr�td�}|dkr�td�}||_|��|j}|j}|js�d}td�}||_||_|��dSdS)zA
            Overriding Attendance model save method
            r�r�Fr�zValidate the attendance�	ValidatedzIncomplete minimum hourT)rr�r��rr��r���?zHalf day leaver�zCurrently workingN)�
first_saver�minimum_hour�attendance_worked_hourr��attendance_validatedr#r�rfr��attendance_dater�r��firstrr�r�r�r�r�r�r�r�r��attendance_clock_out)r��instancer�r�r��statusr��work_recordr&r&r'�attendance_post_save�sp

����������z'OverrideAttendance.attendance_post_saveN)rTrUrVrZr
r
r�rr&r&r&r'r��s
r�r�cKstjj|jd|jd���dS)z;
        Overriding Attendance model delete method
        T)r�r�rN)r�rfr�r�r�delete)r�r�_kwargsr&r&r'�attendance_pre_deletes�
r�leave)�LeaveRequestcs,eZdZdZeeed��fdd��Z�ZS)�OverrideLeaveRequestr�r�csP|j|jkr|j|jkr|j|_tt|���t|j|j�}|jdkr�|D]m}zft	j
j||jd��
�r<t	j
j||jd�nt	�}|j|_d|_|j|krP|jdksZ|j|kr\|jdkr\dnd|_|j|kri|jdkss|j|kru|jdkrudnd	}||_||_|d	kr�d
ntd�|_|��Wq%Yq%d
S|D]}t	j
jd||jd���q�d
S)zC
            Overriding LeaveRequest model save method
            �approvedr�T�
first_half�second_halfrr�r�r�r�z$Half day Attendance need to validate)r�rr�N)r-r.�end_date_breakdown�start_date_breakdownr�rr�r3r	r�rfr�r�r�r�r�r�rr#r�r)r�rr
�period_datesr�
work_entryr	r�r&r'�leaverequest_pre_save&sj
����



��



�����-��z*OverrideLeaveRequest.leaverequest_pre_save)	rTrUrVrZr
rrrr�r&r&r�r'r s
rcKs�|jjdkr	|jnd}|dur>|j��}|s@t�}|�d�|_||_|jr(|jnt��|_	|j
dur5|j
nd|_|��dSdSdS)z[
    This method is used to override the save method for EmployeeWorkInformation Model
    TNz's Contractr)
r��	is_activer�r�rgr��date_joiningrr�r�r�r�r�)r�rr
�active_employee�contract_exists�contractr&r&r'� employeeworkinformation_pre_saveos�
���rcCs,|dkr
ttd���|dkrttd���dS)z
    Percentage validator
    rzRate must be greater than 0�dzRate must be less than 100Nr"r$r&r&r'�rate_validator�s
�r!�equalz
Equal (==)�notequalzNot Equal (!=)�ltz
Less Than (<)�gtzGreater Than (>)�lezLess Than or Equal To (<=)�gezGreater Than or Equal To (>=)�	icontains�Containsr+�Range�children�Children�marital_statuszMarital Status�
experience�
Experience�employee_work_info__experiencezCompany Experience�gender�Gender�country�Country�state�State�contract_set__pay_frequencyr��contract_set__wage_typer��$contract_set__department__departmentzDepartment on Contractc@sDeZdZdZejdd�Zejdeddd�Zejddde	d�d�Z
dS)	�MultipleConditionz!
    MultipleCondition Model
    r?r�T�r<r@rAr=�6The value must be like the data stored in the database�r<rAr=r�N)rTrUrVrZr	r\�field�CONDITION_CHOICE�	conditionr#r%r&r&r&r'r:�s��
�r:cs�eZdZdZded�fded�fgZded�fded	�fgZe�d
�r=ded�fd
ed�fded�fd
ed�fgZ	ee	7Zded�fgZ
ejddded�d�Z
ejdded�d�Zejded�ed�d�Zejeed�dded�d�Zejeed �d!ded"�d#�Zejded$�d%�Zejded&�d%�Zejdedded'�d(�Zejdeddd)�Zejddded*�d�Zejded+�d%�Zejddeged,�d-�Z ejddedded.�d/�Z!ejdde"ged0�d-�Z#ejddd1eged2�d3�Z$ejddd1eged4�d3�Z%ej&e'ej(dded�d5�Z)ejdd1deged6�d7�Z*ejdd1deged8�d7�Z+ej&e,ej(dded�d5�Z-ejdd1deged9�d7�Z.ejded:�ed;�d�Z/ejddeged<�d-�Z0ejd=dd>d>ed?�fgd@dA�Z1ejdBe
dedC�dD�Z2ejdBe3dEedF�dD�Z4ejd1edG�d%�Z5ejddedH�dI�Z6ejddedJ�dI�Z7ej&e8ddej(dK�Z9ejdddL�Z:ejdddL�Z;e<�Z=eje>dddM�Z?GdNdO�dO�Z@dPdQ�ZA�fdRdS�ZBdTdU�ZCdVeDfdWdX�ZE�fdYdZ�ZF�ZGS)[�	Allowancez
    Allowance model
    �ignorezExclude the allowance�
max_amount�Provide max amountr5r6r+r,ru�overtime�Overtimer�r�r�r�r�r?FzTitle of the allowancer=Tz{The one-time allowance in which the allowance will apply to the payslips             if the date between the payslip period�rAr=r��Include all active employeesz7Target allowance to all active employees in the companyr��Employees Specific�allowance_specificz*Target allowance to the specific employees)r>r=r�r��Exclude Employees�allowance_excludedzqTo ignore the allowance to the employees when target them by all employees             or through condition-based�r>r�r=r�z6This field is used to calculate the taxable allowances�rBr�z�This field is used to target allowance         to the specific employees when the condition satisfies with the employee's information�"The related field of the employees�r<r@rAr=r�r;r<z)To specify, the allowance is fixed or notzFixed amount for this allowance�rAr=r�r�zGIf the allowance is not fixed then specifies how the allowance provided)r<rBr@rAr=r��The percentage of based onr�z8The attendance fixed amount for one validated attendance)rAr=rBr�r�zThe fixed amount per children�rGrAr=r>z=The fixed amount for one validated attendance with that shift)rArBr=r�r�zjThe fixed amount for one hour overtime that are validated             and approved the overtime attendancezAThe fixed amount for one validated attendance with that work typezHas max limit for allowancezLimit the allowance amountz$The maximum amount for the allowancer��month_working_days�For working days on month�The maximum amount for ?�r<rArBr@r��
�!The pay head for the if condition�r<r@rBr�r%�3Apply for those, if the pay-head conditions satisfy�The amount of the pay-head�&The start amount of the pay-head range�r=rAr��$The end amount of the pay-head rangerE�rBrF�r=rFc@s eZdZdZgd�Zed�ZdS)zAllowance.Meta�3
        Meta class for additional options
        )�title�
is_taxable�is_condition_basedr>r@r%�is_fixed�amountr]�rate�per_attendance_fixed_amountr��shift_per_attendance_amount�amount_per_one_hrr��work_type_per_attendance_amountrAN)rTrUrVrZr�r#r>r&r&r&r'rX�srXcCs(gd�}|D]}t||d�qd|_dS)z5Reset the this fields when is_fixed attribute is true)	r]rhrir�rjrkr�rl�maximum_amountNF)�setattr�
has_max_limit)rN�attributes_to_reset�	attributer&r&r'�reset_based_on�s
zAllowance.reset_based_oncsVt���|��|jsd|_d|_d|_|js!|js!t	t
d���|js5|jr5|jdkr5|js5t	t
d���|jrG|jrA|jrA|jsGt	t
d���|jdkrW|jsWt	dt
d�i��|jdkre|j
set	t
d	���|jd
krs|jsst	t
d���|jdkr�|js�t	t
d
���|jr�|jdkr�t	dt
d�i��|jr�|jdur�t	dt
d�i��|js�d|_dSdS)N�FIf the 'Is fixed' field is disabled, the 'Based on' field is required.r5z9Rate must be specified for allowances based on basic pay.zHIf condition based, all fields (field, value, condition) must be filled.rur]zcIf based on is attendance,                         then per attendance fixed amount must be filled.r�z0If based on is shift, then shift must be filled.r�z8If based on is work type, then work type must be filled.r+z'The amount per children must be filled.rrgz#Amount should be greater than zero.rmr�)r�r��clean_fixed_attributesrer>r@r%rfr]rr#rhrir�r��per_children_fixed_amountrgrormrMr�r&r'r��s^
���������
�zAllowance.cleancCs<|jsd|_|jr|jdurtdtd�i��|��dSdS)zUClean the amount field and trigger the reset_based_on function based on the conditionNrgr�)rfrgrr#rrrMr&r&r'rts
�z Allowance.clean_fixed_attributesrHcCrIrJ�rKrcrMr&r&r'rOrPzAllowance.__str__c�@t���|js|j��s|jsd|_t���dSdSdSdS�NT�r�r��include_active_employees�specific_employeesrrerMr�r&r'r��
����zAllowance.save)HrTrUrVrZr#�
exceed_choicer[rr��attendance_choices�if_condition_choicer	r\rcr��
one_time_dater^rz�ManyToManyFieldrr{�exclude_employeesrdre�FIELD_CHOICEr>r?r@r%rfr�r(rgr]r!rhrirurcrrdr�rjrkrr�rlrorm�maximum_unit�	if_choice�IF_CONDITION_CHOICE�if_condition�	if_amount�start_range�	end_rangerre�only_show_under_employee�is_loanrrfr:�other_conditionsrXrrr�rtrKrOr�r�r&r&r�r'rA�s�

�

�




�
��������
����������
��	������
���
�����
���
�
�
��4	rAc	s8eZdZdZded�fded�fgZded�fded�fded�fded	�fgZd
ed�fded
�fgZej	ded�d�Z
ejdded�d�Zej
ded�ed�d�Zejeed�ded�dd�Zejeed�dded�d�Zej
ded �d!�Zej
ded"�d!�Zej
ded#�d!�Zej	dedded$�d%�Zej	deddd&�Zej	ddded'�d(�Zej	ddd)ded*�fded�fded	�fged+�d,�Zej
ded-�d!�Zejddeged.�d/�Zej	dedded0�d%�Z ejddd1e!ged2�ed3�d4�Z"ejd1e!gd5�Z#ej
ded6�ed7�d�Z$ejddeged8�d/�Z%ej	d9dd:d:ed;�fged<�d=�Z&ej	d)eded>�d?�Z'ej	d)e(d@edA�d?�Z)ejd1edB�d!�Z*ejddedC�dD�Z+ejddedE�dD�Z,ej-e.ddej/dF�Z0ej
dddG�Z1e2�Z3ej
dddG�Z4eje5dddH�Z6dIdJ�Z7�fdKdL�Z8dMdN�Z9dOe:fdPdQ�Z;�fdRdS�Z<�Z=S)T�	Deductionz
    Deduction model
    r5r6r7r8r9r:�net_payzNet PayrBzExclude the deductionrCrDr?zTitle of the deduction)r<r�Tz{The one-time deduction in which the deduction will apply to the payslips             if the date between the payslip periodrGFrHz7Target deduction to all active employees in the companyr�rI�deduction_specificz*Target deduction to the specific employees)r>r�r�r=rK�deduction_excludezqTo ignore the deduction to the employees when target them by all employees             or through condition-basedrMz3To specify the deduction is tax or normal deductionrNzfTo find taxable gross,             taxable_gross = (basic_pay + taxable_deduction)-pre_tax_deductions z�This field is used to target deduction         to the specific employees when the condition satisfies with the employee's informationrOrPr;r<r=rXz	Basic payzoUpdate compensation is used to update                    pay-head before any other deduction calculation starts)rAr=r<r@r�z)To specify, the deduction is fixed or notzFixed amount for this deductionrQzGIf the deduction is not fixed then specifies how the deduction providedr�z
Employee raterR)rAr=rBr�r>r�)rBr�zHas max limit for deductionzLimit the deductionz$The maximum amount for the deductionr�rTrUrVrWrYrZr%r[r\r]r^r_rEr`racCstjj|d���}|S)zR
        Method to retrieve the payslip associated with this installment.
        ��installment_ids)�Paysliprfr�r)rN�payslipr&r&r'�installment_payslip�szDeduction.installment_payslipcsRt���|jrd|_|js|js|jsttd���|js)|jr)|j	s)ttd���|jr9|jdvr9tdtd�i��|jrI|jdvrItdtd�i��|jrY|jdvrYtdtd	�i��|js`d|_
nd|_d|_	|��|jrz|j
durztd
td�i��|jr�|jr�|jr�|js�tdtd
�i��|jdur�|jr�|j
dur�tdtd�i��dSdSdS)NFrszHEmployee rate must be specified for deductions that are not fixed amount)r9r]z7 Don't choose taxable gross pay when pretax is enabled.)r�z- Don't choose net pay when pretax is enabled.z. Don't choose net pay when the tax is enabled.rmzThis fields requiredrezdIf condition based, all fields                             (field, value, condition) must be filled.rgr�)r�r��is_tax�	is_pretaxrfr]�update_compensationrr#rhrg�clean_condition_based_onrormrer>r%r@rMr�r&r'r��sl
�������
�
�
���

�zDeduction.cleancCs |jsd|_d|_d|_dSdS)z\
        Clean the field, condition, and value attributes when not condition-based.
        N)rer>r@r%rMr&r&r'r�)s

�z"Deduction.clean_condition_based_onrHcCrIrJrvrMr&r&r'rO2rPzDeduction.__str__crwrxryrMr�r&r'r�5r|zDeduction.save)>rTrUrVrZr#rr[r}r	r\rcr�r�r^rzr�rr{r�r�r�rer�r>r?r@r%r�rfr�r(rgr]r!rh�
employer_raterormr�r�r�r�r�r�r�rcrrdrer�rrf�is_installmentr:r�r�r�r�rKrOr�r�r&r&r�r'r�s^

�



�

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

�������	������
��
���
�
�
��<	r�csteZdZdZded�fded�fded�fded	�fgZejd
dded�d
�Zejddddd�Z	ej
eejed�d�Z
e��Ze��Ze��Zejddd�Zejddd�Zejddd�Zejddd�Zejddd�Zejddded�Zejddd�Zed�Zejedd�Z e!de"gd�Z#de$fdd�Z%�fdd�Z&�fd d!�Z'd"d#�Z(d$d%�Z)d&d'�Z*d(d)�Z+Gd*d+�d+�Z,�Z-S),r�z
    Payslip model
    rvrw�review_ongoingzReview Ongoing�	confirmed�	Confirmed�paid�Paid�2Tz
Batch name)r<rAr=r>r?F)r<�uniquerAr=rr�r)rArBr�)r<rArBr@r��rFr�r�rHcCsd|j�d|j�d|j��S)N�Payslip for z - Period: � to �r�r-r.rMr&r&r'rOgszPayslip.__str__cs^t���t��}|j|jkrtdtd�i��|j|kr"ttd���|j|kr-ttd���dS)Nr.z<The end date must be greater than or equal to the start datez%The end date cannot be in the future.z'The start date cannot be in the future.)r�r�rr�r.r-rr#)rNr�r�r&r'r�js
���

�z
Payslip.cleancs^tjj|j|j|jd���dkrttd���t	|j
ttf�s$ttd���t
�j|i|��dS)Nr�r)z+Employee ,start and end date must be uniquez0The data must be in dictionary or querydict type)r�rfr�r�r-r.r�rr#�
isinstance�
pay_head_datar�dictr�r�r�r�r&r'r�zs��zPayslip.savecCs
|j��S)�B
        Method is used to get the full name of the owner
        )r��
get_full_namerMr&r&r'�get_name�s
zPayslip.get_namecCs$tttt|dd�dd�dd�dd�S)r�r�Nr�re�company)�getattrrMr&r&r'�get_company�s��zPayslip.get_companycCs8|jr|jS|j|jkrd|j�d|j��Sd|j��S)zz
        Method to generate the title for a payslip.
        Returns:
            str: The title for the payslip.
        zPayslip r�r�)�
group_namer-r.rMr&r&r'�get_payslip_title�s��
�zPayslip.get_payslip_titlecCs |jj}|jj}t�||�dS)Nr))r-�year�month�calendar�
monthrange)rNr�r�r&r&r'�get_days_in_month�szPayslip.get_days_in_monthc@seZdZdZdgZdS)zPayslip.Metarbz	-end_dateN)rTrUrVrZrWr&r&r&r'rX�s�rX).rTrUrVrZr#�status_choicesr	r\r��	referencercrrdr�r�r-r.�	JSONFieldr�r��
contract_wager5r7�	deductionr�r	r^�sent_to_employeerrfr�r�r�r!r r�rKrOr�r�r�r�r�r�rXr�r&r&r�r'r�@sR



������r�cs~eZdZdZded�fded�fded�fgZejdedd	�Zejd
d�Z	ej
eejed�d
�Z
ejded�d�Ze��Zej
eejddd�Zejddd�Zejedd�Zejddd�Zejddd�Zejed�ddd�Zejed�d�Zejdd�Z ejdd
dd�Z!ejdd �Z"ej#dd!�Z$e%�&d"�r�ej
d#ejdddd$�Z'e(d%�Z)d&d'�Z*d(d)�Z+�fd*d+�Z,d,d-�Z-�fd.d/�Z.�Z/S)0�LoanAccountz>
    This modal is used to store the loan Account details
    �loan�Loan�advanced_salaryzAdvanced Salary�finezPenalty / Fine�)rBr@r<r�r�rr�r�Amount)rBr>FT)rGrFrAr?�rAr<r�r`zinstallment Amount)r>r=rAzTotal installmentsr�z(From the start date deduction will apply)r��end_of_month)rBr<rFr�rC�assetzasset.Asset)rGr=rArFr�cCs|j�d|j��S)Nr�)rcr�rMr&r&r'rO�szLoanAccount.__str__cCsL|j}|j}||}|j}i}|}i}t|�D]}||t|�<t|�}q|S)z�
        Method to calculate installment schedule for the loan.

        Returns:
            dict: A dictionary representing the installment schedule with installment dates as keys
            and corresponding installment amounts as values.
        )�loan_amount�installments�installment_start_dater+rKr)rNr��total_installments�installment_amountr��installment_schedule�installment_dater#r&r&r'�get_installments�s
zLoanAccount.get_installmentscsZ|j����|jdur|j��tjjt|jjddd��d��	�s+t
�j|i|��dS)zG
        Method to delete the instance and associated objects.
        Nr�T��flat��installment_ids__in)�
deduction_ids�allr�allowance_idr�rfr�r�r�r�r�r�r�r&r'rs

��zLoanAccount.deletecCs2|j}tjj|j��d���}|sdS||dS)zk
        Method to calculate the ratio of paid installments to total installments in loan account.
        r�rr )r�r�rfr�r�r�r�)rNr��installment_paidr&r&r'�installment_ratios��zLoanAccount.installment_ratiocs.|jr	t��|_nd|_t�j|i|��dSrJ)�settledrr��settled_dater�r�r�r�r&r'r�szLoanAccount.save)0rTrUrVrZr#�	loan_typer	r\�typercrcrrdr�r�r�r��
provided_daterA�SET_NULLr�r`rbr�r�r�r^rfrhr�r�r�r��apply_onr�r�r�rr��asset_idrrfrOr�rr�r�r�r&r&r�r'r��sX


��
�
��
�
r�cCsdt�}|j�d|��|_d|_||_d|_||_d|_d|_|��d|_|j	�
|j�|��|S)Nr�FT)r�rcrzrgrfr�r�r�r�r{�addr�)rrgr�installmentr&r&r'�_create_deductions%sr�c
s�g}d}t�d�r|jdurdnd}|rX|rX|jdkrXt�}|j|_|j|_d|_|j|_d|_	d|_
|j|_d|_
|��d|_|j�|j�|��||_tt|���dS|jjddd�}tjj|d���fd	d
�|D�}|��}	�s�|js�tjj|d���|	��D]\}
}t|||
�}|� |�q�|jj|�dS|jr�tjj|d���dS|s�|	��D]\}
}tjj|
|jd|jd��!�s�t|||
�}|� |�q�|jj|�dSdS)
z+
    Post save method for loan account
    Tr�NFr�r�r�r�cs g|]}�j|d���s|�qS)r�)r�r�)�.0�deduction_id��payslips_with_deductionsr&r'�
<listcomp>Us���z'create_installments.<locals>.<listcomp>)�id__in)r�r{r�rc)"rr�r�r�rAr�rgrcrzr�rfr�r�r�r�r{r�r�r�r�r�r�r�r�rfr�r�r�r�r�itemsr�r,r�)
r�r�createdr�r�r�r��
deductions�balance_deduction�installment_dictr�r�r�r&r�r'�create_installments6s|
�
�
������
��r�c@s$eZdZdZejdd�Ze��ZdS)�ReimbursementMultipleAttachmentz0
    ReimbursementMultipleAttachement Model
    �payroll/reimbursements�r�N)	rTrUrVrZr	r��
attachment�Managerrfr&r&r&r'r��sr�cs�eZdZdZded�fded�fgZe�d�r e�ded�f�ded	�fd
ed�fded
�fgZ	e
jdd�Ze
jeddd�Z
e
jee
jdd�Ze
��Ze
jddd�Ze
jeddd�Ze�d�rme
jde
jdded�d�Ze
jded�ed�d�Ze
jded �ed!�d�Ze
jded"�ed#�d�Ze
jdd$�Ze
jd%e	ddd&�Z e
jee
j!dd'dd(�Z"e
j#dd)d*�Z$e
je%e
j!ddd+�Z&e'd,�Z(Gd-d.�d.�Z)d7�fd1d2�Z*�fd3d4�Z+d5d6�Z,�Z-S)8�
Reimbursementz
    Reimbursement Model
    �
reimbursement�bonus_encashmentzBonus Point Encashmentr�leave_encashmentzLeave Encashment�	requested�	Requestedr�Approved�rejected�Rejectedr�r��)r@r<rBrr�r�T)r�rAFrazleave.LeaveTypez
Leave type)rGr=rAr>rzAvailable Days to encashzAvailable days)rBr�r>zCarry Forward Days to encashzCarry forward dayszBonus points to encashzBonus pointsr�rX)r<r@rBrF�approved_by)rGrAr�rFr?r�)rGrArFr�c@rQ)zReimbursement.MetarRNrSr&r&r&r'rX�rYrXrHNcs^ttjdd�}tj��rtj��jnd}tj��rtj��jnd}|j�	d�}|s.|jj
|_|jdkr>|j
dur>tddi��|jdkrN|jdurNtddi��|jdkr�|jd	kra|j|j||_tt|jd
�d
d�|_tt|jd
�d
d�|_|jjj|jd���}|jd
kr�|jd	kr�|j||_|jdks�|jdu�r�t�j|i|��|jdk�ru|jdu�ru|jdkr�d}ns|jd
kr�d}tjj|jd�}	|	j|jkr�d}|	j|j8_d|	_|	��nLttjdd�}|r�t �!|d�n<d}|�r1|j"}
|j#}|
|jk�r||jk�rd}|
|j|_"||j|_#|��nttjdd�}|�r1t �!|t$d��|�rgt%�}|j&|_'|j(|_(d|_)d|_*|j|_|��d|_*|j+�,|j�|��||_|�rf|jj
|_-nd	|_t�j|i|��dS|jdk�r�|jdu�r�|j}
|j}
|jdk�r�|�r�|j"|
|_"|j#|
|_#|��|j�.�dSdSdSdSdS)N�requestr)zpayroll.change_reimbursementr�r�r�r��
leave_type_idr�r�rr�r�rTFzbonus points has been redeemed.z9The employee don't have that much bonus points to encash.zrThe employee don't have that much leaves                                         to encash in CFD / Available daysr�zleave encashment)/r�r�_thread_locals�EncashmentGeneralSettingsrfr�leave_amount�bonus_amount�user�has_perm�employee_getr�r�r�rrr	�
cfd_to_encash�ad_to_encashrg�max�round�employee_available_leaver��bonus_to_encashr�r�r�r�get�points�reasonr�info�available_days�carryforward_daysr#rA�allowance_onr�rcr�rzr{r�r�r)rNr�r�r�amount_for_leave�amount_for_bonusr�assigned_leave�proceed�bonus_pointsrrr��cfd_daysr�r&r'r��s�����



���




�����
���
����EzReimbursement.savecsfttjdd�}|jdkrt�|t|j�d���}|S|jr1|j�	�t
�j	|i|��t�|d�}|S)Nrrz> is in approved state,                    it cannot be deletedzReimbursement deleted)r�rrr	rrr#rcr�rr��success)rNr�r�rr�r�r&r'rLs

��
�
zReimbursement.deletecC�|j�SrJ)rcrMr&r&r'rO^�zReimbursement.__str__)rHN).rTrUrVrZr#�reimbursement_typesrr�r,�status_typesr	r\rcr�rcrrdr�r�rr�r�r�r��other_attachmentsrr�r
r	r�rrgr	r�r�r`rbrAr�rrfrXr�rrOr�r&r&r�r'r��s�

�



����
������
�ur��canceled)r	r�c@s eZdZejdd�Ze��ZdS)�ReimbursementFilezpayroll/request_filesr�N)rTrUrVr	r��filer�rfr&r&r&r'r#jsr#c@steZdZdZejeejd�Zeje	ejd�Z
ejded�dd�Z
ejedd�Zejded�dd	�Zd
efdd�Zd
S)�ReimbursementrequestCommentz+
    ReimbursementRequestComment Model
    )rGT�Commentr?)rAr>r<)r=z
Created At)�auto_now_addr>rArHcCrrJ)�commentrMr&r&r'rO~rz#ReimbursementrequestComment.__str__N)rTrUrVrZr	rcr��CASCADE�
request_idrr�r`r#r(r�r#�filesr��
created_atrKrOr&r&r&r'r%os�r%c@s4eZdZdZejdegdd�Zeje	ej
dd�ZdS)�PayrollGeneralSettingz
    PayrollGeneralSetting
    zNotice period in daysr;)r�r�rBT)rGrAN)rTrUrVrZr	r�r(�
notice_periodrcrr)rer&r&r&r'r-�s�r-c@s4eZdZdZejdd�Zejdddd�Ze��Z	dS)rz)
    BonusPointGeneralSettings model
    r)r�Tr�)r=rAr>N)
rTrUrVrZr	r�rrr�rfr&r&r&r'r�s
rzlast dayzLast Day)�1�1st)�2�2nd)�3�3rd)�4�4th)�5�5th)�6�6th)�7�7th)�8�8th)�9�9th)�10�10th)�11�11th)�12�12th)�13�13th)�14�14th)�15�15th)�16�16th)�17�17th)�18�18th)�19�19th)�20�20th)�21�21th)�22�22th)�23�23th)�24�24th)�25�25th)�26�26th)�27�27th)�28�28th)�29�29th)�30�30th)�31�31thcsleZdZdZejdedddd�Zejdd�Z	ej
eejd	d	d
d�Z
dd
�Z�fdd�Zdefdd�Z�ZS)�PayslipAutoGeneratez4
    Model for generating payslip automatically
    r;r/zPayslip Generate Dayz5On this day of every month,Payslip will auto generate)r<r@rBr>r�Fr�TrrScCs`|js*tjjdd���r,|jstddi��tjjdd���}|j|jkr.tddi��dSdSdS)N)rerez9Auto payslip generation for all company is already exists)rermrfr�r�r�rr)rN�all_company_auto_payslipr&r&r'r��s*���������
zPayslipAutoGenerate.cleancs.ddlm}|jr|�t�j|i|��dS)Nr)�auto_payslip_generate)�payroll.schedulerro�
auto_generater�r�)rNr�r�ror�r&r'r��szPayslipAutoGenerate.saverHcCs|j�d|j�d�S)Nz | � )�generate_dayrerMr&r&r'rO�szPayslipAutoGenerate.__str__)rTrUrVrZr	r\�DAYSrsr^rq�
OneToOneFieldrr)rer�r�rKrOr�r&r&r�r'rm�s ��rm)_rZr��loggingrrr�djangor�django.appsr�django.contribr�django.core.exceptionsr�	django.dbr	�django.db.models.signalsr
rr�django.dispatchr
�django.httpr�django.utilsr�django.utils.translationrr#�base.horilla_company_managerr�base.methodsr�base.modelsrrrrrrr�!employee.methods.duration_methodsr�employee.modelsrrr�horillar�horilla.modelsr�horilla_audit.modelsr r!�	getLoggerrTr�r(r3r4rg�Modelr�r��attendance.modelsr�r�r�leave.modelsrrrr!r?r�r�r:rAr�r�r�r�r�r�r�rfr�r��updater#r%r-rrtrmr&r&r&r'�<module>s>$	
*
B
L



O







�







�










�]#{j

N	V�


��������	�
���
������������������� �$

Youez - 2016 - github.com/yon3zu
LinuXploit