
    vgі              
          d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZmZmZmZmZ d	 Zej(                  ej*                  ej,                  ej.                  ej0                  ej2                  ej4                  ed
Zdd idd idd idd idZi ddddddddddddddddddddd d!d"d#dgd$d%d&d'd(d)d*d+d,d-d.d.d/id0g d1g d2dd3dd4d5d6d7d8dd9d:d6gd;d d<d"d=d>d6d?d@d"ddAd6dBdCd"d:d:d6gdDdEdFddGdHdIgdJdKdLd"dMdNd6gdOdPdQdRddSdTdUdVZdW ZdX ZdY Z dZ Z!d[ Z"d\ Z#d] Z$d^ Z%d_ Z&d` Z'da Z(db Z)dc Z*dd Z+de Z,df Z-dg Z.dh Z/e'e(e)e*e+e,e-e.e/di	Z0y)jz
This module contains various functions for calculating payroll-related information for employees.
It includes functions for calculating gross pay, taxable gross pay, allowances, tax deductions,
pre-tax deductions, and post-tax deductions.

    N)apps)get_horilla_model_classupdate_compensation_deduction)compute_limit)models)	AllowanceContract	DeductionLoanAccountMultipleConditionc                      y N )abs     0/var/www/horilla/payroll/methods/payslip_calc.pyreturn_noner      s        )equalnotequalltgtlege	icontainsrangefilterc                 <    | |j                   j                  ||fddS )NT)employee_idwork_type_id__idattendance_date__rangeattendance_validated)work_type_ididemployee	allowance
start_dateend_dates       r   <lambda>r+   +   s'    # ) 6 6 9 9'18&<$(	E
 r   c                 <    | |j                   j                  ||fddS )NT)r    shift_id__idr"   r#   )shift_idr%   r&   s       r   r+   r+   3   s'    #%..11'18&<$(	E
 r   c                     | ||fdddS )NT)r    r"   attendance_overtime_approver#   r   r&   s       r   r+   r+   ;   s    #'18&<+/$(	E
 r   c                     | ||fddS )NTr    r"   r#   r   r&   s       r   r+   r+   C   s    #'18&<$(E
 r   )r$   r.   overtime
attendancenet_payg](@r'      
allowances   zLow Basic Pay AssistanceTallowance_idtitle
is_taxableamount   z!Bonus point Redeem for Adam Luis g     R@   
Motorcycleg     @   zMeal AllowanceFg      @	gross_payg..@contract_wageg     @	basic_payg."P@	paid_daysg      5@unpaid_daysg      ?taxable_gross_payg]tE@basic_pay_deductionsgross_pay_deductionspretax_deductionszSocial Security (FICA)g颋.:@g@deduction_idr;   	is_pretaxr=   employer_contribution_rate>   zLate Come penaltyg      i@g        post_tax_deductionszMedicare taxg.F~@g333333?7   ESIg      
@I   Testtax_deductionsK   ztest tax netpaygE]t@g      @rL   r;   is_taxr=   rN   net_deductionsJ   zTest Netpayg2iV/v@g       @total_deductionsgE]t@loss_of_payg.ۘ@z
2024-02-01z
2024-02-29zFeb 01 2024 - Feb 29 2024)federal_taxr)   r*   r   c                 2   |j                  d      }|D ]t  }t        j                  t              5  t	        | j                         t              r | j                  d      j                         } ddd       t        | |d      } | s | S  | S # 1 sw Y   xY w)a  
    Retrieves the value of a nested attribute from a related object dynamically.

    Args:
        obj: The base object from which to start accessing attributes.
        attribute_path (str): The path of the nested attribute to retrieve, using
        double underscores ('__') to indicate relationship traversal.

    Returns:
        The value of the nested attribute if it exists, or None if it doesn't exist.
    __T)	is_activeN)	split
contextlibsuppress	Exception
isinstancefirstr
   r   getattr)objattribute_path
attributesattrs       r   dynamic_attrrl      s      %%d+J   + 	9#))+x0jj4j0668	9 c4&;J J	9 	9s   ?BB	c                  v    d   }d   }||z   }fddD        \  }}}t        ||d||      }|d   ||d   dS )	a  
    Calculate the gross pay for an employee within a given date range.

    Args:
        employee: The employee object for whom to calculate the gross pay.
        start_date: The start date of the period for which to calculate the gross pay.
        end_date: The end date of the period for which to calculate the gross pay.

    Returns:
        A dictionary containing the gross pay as the "gross_pay" key.

    rD   total_allowancec              3   (   K   | ]	  }|     y wr   r   ).0keykwargss     r   	<genexpr>z&calculate_gross_pay.<locals>.<genexpr>   s      &s&s   )r'   r)   r*   rB   compensation_amount
deductions)rB   rD   ru   r   )	_argsrr   rD   rn   rB   r'   r)   r*   updated_gross_pay_datas	    `       r   calculate_gross_payrx      sr     {#I./O)+I&E&"Hj( ;)[*h ,,AB,\: r   c                      |d   }t        di |}|d   }t        di |}t        d |d   D              }t        d |d   D              }||z
  |z
  }d|iS )a  
    Calculate the taxable gross pay for an employee within a given date range.

    Args:
        employee: The employee object for whom to calculate the taxable gross pay.
        start_date: The start date of the period for which to calculate the taxable gross pay.
        end_date: The end date of the period for which to calculate the taxable gross pay.

    Returns:
        A dictionary containing the taxable gross pay as the "taxable_gross_pay" key.

    r7   rB   c              3   0   K   | ]  }|d    s|d     yw)r<   r=   Nr   )rp   r(   s     r   rs   z.calculate_taxable_gross_pay.<locals>.<genexpr>   s%      && 	(&   c              3   0   K   | ]  }|d    r|d     yw)rM   r=   Nr   )rp   	deductions     r   rs   z.calculate_taxable_gross_pay.<locals>.<genexpr>  s%      ![! 	(!r{   rJ   rG   r   )rx   calculate_pre_tax_deductionsum)rv   rr   r7   rB   pre_tax_deductionsnon_taxable_allowance_totalpretax_deduction_totalrG   s           r   calculate_taxable_gross_payr      s     %J#-f-I+&I4>v>"% &#L1& #
 ! !+,?@! 
 "$??BXX. r   c                     | d   }| d   }| d   }| d   }| d   }t         j                  j                  |      }t         j                  j                  d      j                  |	      }t         j                  j                  d
      j                  |	      }||z  |z  }	|	j                  |      j                  |      j	                         }	g }
g }g }g }g }|	D ]  }|j
                  rt        |j                  j                  ddd            }|j                  }|j                  }|j                  j                         j                  dd      }|j                  |||f       d}|D ]U  }t        ||d         }|?t         j#                  |d         } t%        |      |d         } |||      r|dz  }Od} nd} n |s|
j                  |       |j&                  t(        v rst)        |j&                     d   ||||      }t+        j,                  d      sDt/        dd      } |j                  j                  d i |so|
j                  |       |
j                  |        |
D ]1  }|j0                  r|j                  |       !|j                  |       3 |D ]  }|j2                  r3|j4                  }|| d<   || d<   t7        d i | }|j                  |       Bt8        j#                  |j&                        } |d i ||||dd||d}|| d<   || d<   t7        d i | }|j                  |        |D ]  }|j2                  r3|j4                  }|| d<   || d<   t7        d i | }|j                  |       Bt8        j#                  |j&                        } |d i ||||||d}|| d<   || d<   t7        d i | }|j                  |        g }t;        ||      D ];  \  }}|j<                  |j>                  |j0                  |d}|j                  |       = t;        ||      D ];  \  }}|j<                  |j>                  |j0                  |d}|j                  |       = d|iS )!aK  
    Calculate the allowances for an employee within the specified payroll period.

    Args:
        employee (Employee): The employee object for which to calculate the allowances.
        start_date (datetime.date): The start date of the payroll period.
        end_date (datetime.date): The end date of the payroll period.

    r'   r)   r*   rD   day_dict)specific_employeesT)is_condition_basedexclude_employees)include_active_employeesone_time_date__ltone_time_date__gtfield	conditionvalue _r   Nr6   rA   Fr   r4   	app_labelmodelr=   	componentr'   r)   r*   r   r7   rn   rD   r   )r'   r)   r*   r   r   rD   r9   r7   r   ) r	   objectsr   excludedistinctr   listother_conditionsvalues_listr   r   r   lowerreplaceappendrl   operator_mappinggettypebased_onfilter_mappingr   is_installedr   r<   is_fixedr=   if_condition_oncalculation_mappingzipr%   r;   )rr   r'   r)   r*   rD   r   specific_allowancesconditional_allowancesactive_employeesr7   employee_allowancestax_allowancesno_tax_allowancestax_allowances_amtno_tax_allowances_amtr(   
conditionscondition_fieldcondition_operatorcondition_value
applicabler   valoperator_funcfilter_params
Attendancer=   calculation_functionserialized_allowancesserialized_allowances                                 r   calculate_allowancer     s     j!H%Jj!H{#Ij!H#++22h2O&..555NVV" W  !((///NVV" W  %'==@PPJ 	Z8	8	,	  N &6	''**66wWUJ (ooO!*!4!4'oo335==c3GO0BOTUJ' 	"8Yq\:?$4$8$81$FM&/d3i	!&=O$S/:%/$%6
 %*
!&J #**95!!^3 .y/A/A B8 LiX! $$\2!8".l"J 1z))00A=A+229=#**95M&6P ) 0	!!),$$Y/	0 $ .	%%F%F8"+F;$.v.F%%f-#6#:#:9;M;M#N )  (", (!*"&'+!* (	F  &F8"+F;$.v.F%%f-3.6 ' 1	%%F%F8"+F;$.v.F!((0 $7#:#:9;M;M#N ) 	 (", (!* (!*	F  &F8"+F;$.v.F!((0/10  !1CD ;	6%LL__#..	 
 	$$%9:; !!24IJ ;	6%LL__#..	 
 	$$%9:; /00r   c                     |d   }|d   }|d   }t         j                  j                  j                  |dd      }t         j                  j                  j                  ddd      j	                  |      }||z  }|j	                  |	      j	                  |
      j	                  d      }g }g }	|D ]d  }
t
        j                  |
j                        } |di ||||
|d   |d   |d   |d   d}||d<   |
|d<   t        di |}|j                  |       f t        ||      D ]F  \  }
}|
j                  |
j                  |
j                  ||
j                  d}|	j                  |       H d|	iS )a  
    Calculates the tax deductions for the specified employee within the given date range.

    Args:
        employee (Employee): The employee for whom the tax deductions are being calculated.
        start_date (date): The start date of the tax deduction period.
        end_date (date): The end date of the tax deduction period.
        allowances (dict): Dictionary containing the calculated allowances.
        total_allowance (float): The total amount of allowances.
        basic_pay (float): The basic pay amount.
        day_dict (dict): Dictionary containing working day details.

    Returns:
        dict: A dictionary containing the serialized tax deductions.
    r'   r)   r*   FTr   rM   rX   r   rM   rX   r   r   r   update_compensation__isnullr7   rn   rD   r   r   r=   r   rW   rU   r   )r   r   r   r   r   r   r   r   r   r   r   r%   r;   rX   employer_rate)rv   rr   r'   r)   r*   specific_deductionsactive_employee_deductionru   deductions_amtserialized_deductionsr}   r   r=   serialized_deductions                 r   calculate_tax_deductionr     s     j!H%Jj!H **2299#uT :  !' 0 0 8 8 ? ?!%t !@ !gg)  %'@@JZ8	8	,	U	3 
 N &	266y7I7IJ% 
$($&$\2#)*;#<#K0":.	
 "x'{ *6*f%#&$ !^< ;	6%LL__&&*3*A*A 
 	$$%9:; 344r   c                  Z   |d   }|d   }|d   }t         j                  j                  j                  |dd      }t         j                  j                  j                  ddd      j	                  |      }t         j                  j                  j                  ddd	      j	                  |      }||z  |z  }|j	                  |
      j	                  |      j	                  d      }|j                  d      }	g }
g }g }|D ]%  }|j
                  rt        |j                  j                  ddd            }|j                  }|j                  }|j                  j                         j                  dd      }|j                  |||f       t        j!                  |      }d}|D ]U  }t#        ||d         }|?t        j!                  |d         } t%        |      |d         } |||      r|dz  }Od} nd} n |s|
j                  |       |
j                  |       ( |
D ]  }|j&                  r/|j(                  |d<   ||d<   |j                  t+        di |       >t,        j!                  |j.                        } |di |||||d   |d   |d   |d   d}||d<   ||d<   |j                  t+        di |        t1        |
|      D ]F  \  }}|j2                  |j4                  |j6                  ||j8                  d}|j                  |       H ||	dS ) a  
    This function retrieves pre-tax deductions applicable to the employee and calculates
    their amounts

    Args:
        employee: The employee object for whom to calculate the pre-tax deductions.
        start_date: The start date of the period for which to calculate the pre-tax deductions.
        end_date: The end date of the period for which to calculate the pre-tax deductions.

    Returns:
        A dictionary containing the pre-tax deductions as the "pretax_deductions" key.

    r'   r)   r*   TFr   r   rM   rX   r   r   r   r   r   is_installmentr   r   r   r   r   r   r6   rA   r=   r   r7   rn   rD   r   r   rK   )rJ   installmentsr   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rl   r   r   r=   r   r   r   r   r%   r;   rM   r   )rv   rr   r'   r)   r*   r   conditional_deductionr   ru   r   r   pre_tax_deductions_amtr   r}   r   r   r   r   r   r   r   r   r   r=   r   s                            r   r~   r~     s    j!H%Jj!H **2299#tE :  #,,44;;4 < gg)  !' 0 0 8 8 ? ?!%e !@ !gg)  %'<<?XXJZ8	8	,	U	3  $$D$9L 1	''**66wWUJ (ooO!*!4!4'oo335==c3GO0BOTU,001CDMJ' 	"8Yq\:?$4$8$81$FM&/d3i	!&=O$S/:%/$%6
 %*
!&J ")))4%%i091< ( E	(//F8"+F;"))/*CF*CD#6#:#:9;M;M#N )  (", (!*"("6'-.?'@!'!4 &z 2	F  &F8"+F;"))/*CF*CD+E, !!35KL ;	6%LL__",,*3*A*A 
 	$$%9:; "7UUr   c                     |d   }|d   }|d   }|d   }|d   }|d   }|d   }t         j                  j                  j                  |dd	      }	t         j                  j                  j                  d
dd      j	                  |      }
t         j                  j                  j                  d
dd      j	                  |      }|	|
z  |z  }|j	                  |      j	                  |      j	                  d      }|j                  d
      }g }g }g }g }|D ]  }|j
                  r|j                  }|j                  }|j                  j                         j                  dd      }t        ||      }t        j                  |      }|u t        |      |      } |||      s|j                  |       |j                  |        |D ]  }|j                   r3|j"                  }||d<   ||d<   t%        di |}|j                  |       B|j&                  dk7  sRt(        j                  |j&                        } |di ||||||||d}||d<   ||d<   t%        di |}|j                  |        t+        ||      D ]F  \  }}|j,                  |j.                  |j0                  ||j2                  d}|j                  |       H |D ]'  }|j&                  dk(  sd|i}|j                  |       ) |||dS )a  
    This function retrieves post-tax deductions applicable to the employee and calculates
    their amounts

    Args:
        employee: The employee object for whom to calculate the pre-tax deductions.
        start_date: The start date of the period for which to calculate the pre-tax deductions.
        end_date: The end date of the period for which to calculate the pre-tax deductions.

    Returns:
        A dictionary containing the pre-tax deductions as the "post_tax_deductions" key.

    r'   r)   r*   r7   rn   rD   r   Fr   Tr   r   r   r   r   r   r   r   r   r=   r   r5   r   rK   r}   )rP   net_pay_deductionr   r   )r   r   r   r   r   r   r   r   r   r   r   rl   r   r   r   r   r   r=   r   r   r   r   r%   r;   rM   r   )rv   rr   r'   r)   r*   r7   rn   rD   r   r   r   r   ru   r   rP   post_tax_deductions_amtr   serialized_net_pay_deductionsr}   r   r   r   employee_valuer   r=   r   r   serialized_net_pay_deductions                               r   calculate_post_tax_deductionr   S  s|    j!H%Jj!H%J./O{#Ij!H **2299#uU :  #,,44;;5 < gg)  !' 0 0 8 8 ? ?!%u !@ !gg)  %'<<?XXJZ8	8	,	U	3  $$D$9L $&! 2	'''ooO!*!4!4'oo335==c3GO)(ODN,001CDM)"6$~"6"G A'..y9&&y12 ) 7	%%F%F8"+F;$.v.F#**62!!Y.':'>'>y?Q?Q'R$- $,&0$,%.&0+:%.$,	 $*x &/{#(262'..v6376 !!46MN ;	6%LL__",,*3*A*A 
 	$$%9:; ) O	*,7+C()001MNO
  5:$ r   c                 x   |d   }g }|D cg c]  }|d   	 }}g }|D ]5  }t        || |      }	|	|d<   ||d<   t        di |}	|j                  |	       7 d}
t        ||      D ]K  \  }}	|j                  |j
                  |j                  |	|j                  d}|	|
z   }
|j                  |       M ||
dS c c}w )	a_  
    Calculates the deductions based on the net pay amount.

    Args:
        net_pay (float): The net pay amount.
        net_pay_deductions (list): List of net pay deductions.
        day_dict (dict): Dictionary containing working day details.

    Returns:
        dict: A dictionary containing the serialized deductions and deduction amount.
    r   r}   r=   r   r   rK   )net_pay_deductionsnet_deductionr   )calculate_based_on_net_payr   r   r   r%   r;   rM   r   )r5   r   rr   r   r   itemru   deduction_amtr}   r=   r   r   s               r   calculate_net_pay_deductionr     s     j!H$&!0BC${#CJCM %	+IwI!x'{ *6*V$% M ]; 	C	6%LL__",,*3*A*A 
 .%,,-AB	C <& ' Ds   B7c                  p   |d   }|d   }|d   }d}t        |      }t        |t              st        di |d   }|j                  dk(  r|n|}|j
                  dk(  r%|j                  |cxk  r|j                  k  sn d}|S t        j                  |j
                        } |||j                        sd}|S )a  
    This method is used to check the allowance or deduction through the the conditions

    Args:
        employee (obj): Employee instance
        amount (float): calculated amount of the component
        component (obj): Allowance or Deduction instance
        start_date (obj): Start date of the period
        end_date (obj): End date of the period

    Returns:
        _type_: _description_
    r   rD   r=   r   rB   r   r   )floatre   r	   rx   	if_choiceif_conditionstart_range	end_ranger   r   	if_amount)rv   rr   r   rD   r=   rB   r   r   s           r   r   r     s     {#I{#IHFI6]Fi+' 


	 $-#6#6+#Ei9O($$N9;N;NNF
 M ),,Y-C-CD_i.A.ABFMr   c                  f    |d   }|d   }|d   }|j                   }||z  dz  }t        |||      }|S )a  
    Calculate the amount of an allowance or deduction based on the employee's
    basic pay with rate provided in the allowance or deduction object

    Args:
        employee (Employee): The employee object for whom to calculate the amount.
        start_date (datetime.date): The start date of the period for which to calculate the amount.
        end_date (datetime.date): The end date of the period for which to calculate the amount.
        component (Component): The allowance or deduction object that defines the rate or percentage
        to apply.

    Returns:
        The calculated allowance or deduction amount based on the employee's basic pay.

    r   rD   r   d   )rater   )rv   rr   r   rD   r   r   r=   s          r   calculate_based_on_basic_payr     sM      {#I{#Ij!H>>D#F9fh7FMr   c                  T    |d   }t        di |}|j                  }|d   |z  dz  }|S )a  
    Calculate the amount of an allowance or deduction based on the employee's gross pay with rate
    provided in the allowance or deduction object

    Args:
        employee (Employee): The employee object for whom to calculate the amount.
        start_date (datetime.date): The start date of the period for which to calculate the amount.
        end_date (datetime.date): The end date of the period for which to calculate the amount.
        component (Component): The allowance or deduction object that defines the rate or percentage
        to apply.

    Returns:+-
        The calculated allowance or deduction amount based on the employee's gross pay.

    r   rB   r   r   )rx   r   )rv   rr   r   rB   r   r=   s         r   calculate_based_on_gross_payr     s=    " {#I#-f-I>>D{#d*S0FMr   c                  X    |d   }t        di |}|d   }|j                  }||z  dz  }|S )a  
    Calculate the amount of an allowance or deduction based on the employee's taxable gross pay with
    rate provided in the allowance or deduction object

    Args:
        employee (Employee): The employee object for whom to calculate the amount.
        start_date (datetime.date): The start date of the period for which to calculate the amount.
        end_date (datetime.date): The end date of the period for which to calculate the amount.
        component (Component): The allowance or deduction object that defines the rate or percentage
        to apply.

    Returns:
        The calculated component amount based on the employee's taxable gross pay.

    r   rG   r   r   )r   r   )rv   rr   r   rG   r   r=   s         r   $calculate_based_on_taxable_gross_payr   6  sE      {#I3=f=)*=>>>D%+FMr   c                 t    t        | j                        }||z  dz  }t        | ||      }t        | ||      }|S )a  
    Calculates the amount of an allowance or deduction based on the net pay of an employee.

    Args:
        component (Allowance or Deduction): The allowance or deduction object.
        net_pay (float): The net pay of the employee.
        day_dict (dict): Dictionary containing working day details.

    Returns:
        float: The calculated amount of the component based on the net pay.
    r   )r   r   r   )r   r5   r   r   r=   s        r   r   r   N  sA      Dt^c!F9fh7F9fh7FMr   c                     t        j                  d      syt        dd      }|d   }|d   }|d   }|d   }|d   }|j                  j	                  |||fd	
      j                         }||j                  z  }	t        ||	|      }	|	S ):  
    Calculates the amount of an allowance or deduction based on the attendance of an employee.

    Args:
        employee (Employee): The employee for whom the attendance is being calculated.
        start_date (date): The start date of the attendance period.
        end_date (date): The end date of the attendance period.
        component (Allowance or Deduction): The allowance or deduction object.
        day_dict (dict): Dictionary containing working day details.

    Returns:
        float: The calculated amount of the component based on the attendance.
    r4   r   r   r'   r)   r*   r   r   Tr2   )r   r   r   r   r   countper_attendance_fixed_amountr   )
rv   rr   r   r'   r)   r*   r   r   r   r=   s
             r   calculate_based_on_attendancer   b  s     \*(<|TJj!H%Jj!H{#Ij!H%% *H5! &  eg	 

 Y:::F9fh7FMr   c                  @   t        j                  d      syt        dd      }|d   }|d   }|d   }|d   }|d   }|j                  j                  }|j
                  j                  ||||fd	
      j                         }	|	|j                  z  }
t        ||
|      }
|
S )aH  
    Calculates the amount of an allowance or deduction based on the employee's shift attendance.

    Args:
        employee (Employee): The employee for whom the shift attendance is being calculated.
        start_date (date): The start date of the attendance period.
        end_date (date): The end date of the attendance period.
        component (Allowance or Deduction): The allowance or deduction object.
        day_dict (dict): Dictionary containing working day details.

    Returns:
        float: The calculated amount of the component based on the shift attendance.
    r4   r   r   r'   r)   r*   r   r   T)r    r.   r"   r#   )
r   r   r   r.   r%   r   r   r   shift_per_attendance_amountr   )rv   rr   r   r'   r)   r*   r   r   r.   r   r=   s              r   calculate_based_on_shiftr     s     \*(<|TJj!H%Jj!H{#Ij!H!!$$H%% *H5!	 & 
 eg 
 Y:::F9fh7FMr   c                  @   t        j                  d      syt        dd      }|d   }|d   }|d   }|d   }|d   }|j                  j	                  |||fd	
      }t        d |D              }	|j                  }
|
dz  }|	|z  }t        |d      }t        |||      }|S )aA  
    Calculates the amount of an allowance or deduction based on employee's overtime hours.

    Args:
        employee (Employee): The employee for whom the overtime is being calculated.
        start_date (date): The start date of the overtime period.
        end_date (date): The end date of the overtime period.
        component (Allowance or Deduction): The allowance or deduction object.
        day_dict (dict): Dictionary containing working day details.

    Returns:
        float: The calculated amount of the allowance or deduction based on the overtime hours.
    r4   r   r   r'   r)   r*   r   r   T)r    r"   r0   c              3   4   K   | ]  }|j                     y wr   )overtime_second)rp   r4   s     r   rs   z.calculate_based_on_overtime.<locals>.<genexpr>  s     L*:--Ls   i  rA   )	r   r   r   r   r   r   amount_per_one_hrroundr   )rv   rr   r   r'   r)   r*   r   r   attendancesr3   amount_per_houramount_per_secondr=   s                r   calculate_based_on_overtimer    s     \*(<|TJj!H%Jj!H{#Ij!H$$++ *H5$( , K
 LLLH11O'73))F61F9fh7FMr   c                  @   t        j                  d      syt        dd      }|d   }|d   }|d   }|d   }|d   }|j                  j                  }|j
                  j                  ||||fd	
      j                         }	|	|j                  z  }
t        ||
|      }
|
S )a  
    Calculates the amount of an allowance or deduction based on the employee's
    attendance with a specific work type.

    Args:
        employee (Employee): The employee for whom the attendance is being considered.
        start_date (date): The start date of the attendance period.
        end_date (date): The end date of the attendance period.
        component (Allowance or Deduction): The allowance or deduction object.
        day_dict (dict): Dictionary containing working day details.

    Returns:
        float: The calculated amount of the allowance or deduction based on the
               attendance with the specified work type.
    r4   r   r   r'   r)   r*   r   r   T)r    r$   r"   r#   )
r   r   r   r$   r%   r   r   r   work_type_per_attendance_amountr   )rv   rr   r   r'   r)   r*   r   r   r$   r   r=   s              r   calculate_based_on_work_typer    s      \*(<|TJj!H%Jj!H{#Ij!H)),,L%%! *H5!	 & 
 eg 
 Y>>>F9fh7FMr   c                  t    |d   }|d   }|d   }|j                   }||j                  z  }t        |||      }|S )r   r'   r   r   )childrenper_children_fixed_amountr   )rv   rr   r'   r   r   r   r=   s          r   calculate_based_on_childrenr	    sP     j!H{#Ij!HEY888F9fh7FMr   )	rD   rB   rG   r5   r4   r.   r3   r$   r  )1__doc__rb   operatordjango.appsr   horilla.methodsr   payroll.methods.deductionsr   payroll.methods.limitsr   payroll.modelsr   payroll.models.modelsr	   r
   r   r   r   r   eqner   r   r   r   containsr   r   tetsrl   rx   r   r   r   r~   r   r   r   r   r   r   r   r   r   r  r  r	  r   r   r   r   <module>r     sJ      4 D 0 ! 
 [[
++
++
++
++""	  	 
 	 
 	 
 	 
3 Fd!dd /		
 8		
 !		
 %		
'd: ";d< W=d> "?d@ AdB 3CdD -/@AEdF BGdH BIdJ -(*-	
 (*-	
Kdj #(*.	
 *.	
 *-	
kdX &'*-	
Ydj "'*-	
kd| )}d~ $d@ (GdN2@B[1|<5~fVReP$ND400("J"J%P%P0 .-=)/(+0+
 r   