
    vg                     z    d Z ddlZddlZddlmZmZ ddlmZmZ ddl	m
Z
 ddlmZ  ej                  e      Zd Zy)z
Module: payroll.tax_calc

This module contains a function for calculating the taxable amount for an employee
based on their contract details and income information.
    N)compute_yearly_taxable_amountconvert_year_tax_to_period)calculate_gross_paycalculate_taxable_gross_pay)Contract)
TaxBracketc            	         | d   }| d   }| d   }| d   }t         j                  j                  |d      j                         }|j                  }|syd}t
        j                  j                  |      j                  d	      }||z
  j                  d
z   }	t        t        d}
|j                  }||
v r|
|   } |d"i | }t        ||         }nt        |      }|j                  }t        j                  |d
d
      }t        j                  |dd      }||z
  j                  d
z   }||	z  |z  }t        ||      }t!        d       t!        |       t#        |d      }d}||j$                  s|j'                  dd	d      D cg c]  }|d   |d	   t)        |d   |      d }}g }|D ]?  }|d   |d   kD  r1|d   |d   z
  |d<   |d   dz  |d   z  |d<   |j+                  |       ? n t-        d |D              }n^|j$                  rR|j.                  }|j1                  dd      }d}||z   }|j1                  dd      }i }t3        |i |       	  |d    |      }d}|r&|j;                         s|j$                  r
||z  }||	z  }t=        |||||!      }|S c c}w # t4        $ r}t6        j9                  |       Y d}~dd}~ww xY w)#af  Calculate the taxable amount for a given employee within a specific period.

    Args:
        employee (int): The ID of the employee.
        start_date (datetime.date): The start date of the period.
        end_date (datetime.date): The end date of the period.
        allowances (int): The number of allowances claimed by the employee.
        total_allowance (float): The total allowance amount.
        basic_pay (float): The basic pay amount.
        day_dict (dict): A dictionary containing specific day-related information.

    Returns:
        float: The federal tax amount for the specified period.
    employee
start_dateend_date	basic_payactive)employee_idcontract_statusr   )filing_status_id
min_income   )taxable_gross_pay	gross_pay      z!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.   Ntax_rate
max_income)rateminmaxr   r   diffr   d   calculated_ratec              3   &   K   | ]	  }|d      yw)r    N ).0brackets     ,/var/www/horilla/payroll/methods/tax_calc.py	<genexpr>z+calculate_taxable_amount.<locals>.<genexpr>^   s     U'"34Us   zprint(zpass_print(z2
def pass_print(*args, **kwargs):
    return None
z  formated_result(z#  formated_result(calcluate_federal_tax)federal_tax_for_period
yearly_tax
total_daysr   r   r"   )r   objectsfilterfirstfiling_statusr   order_bydaysr   r   based_onfloatyeardatetimedater   printrounduse_pyvaluesr   appendsumpython_codereplaceexec	Exceptionloggererrorexistsr   )kwargsr
   r   r   r   contractfilingr(   tax_bracketsnum_dayscalculation_functionsbasedcalculation_functionincomer3   check_start_datecheck_end_dater*   yearly_incomefederal_taxitembracketsfilterd_bracketsr$   code
pass_print
local_varsedaily_federal_taxs                                r%   calculate_taxable_amountrX      sF    j!H%Jj!H{#I&&h ' eg  ##F%%,,f,ENNL :%++a/H8( OOE%%4U;%//ve}%y!==D}}T1a0]]4R0N #3399A=JX%
2M1&-HM	
-.	--+MK&-- %++JlS
 	 Z(L)4-}=
 
  	Gu~.")%.75>"A.5fo.Cwv-V)* ''0	 UDTUU	!!||Hm4
 D ||02GH
T2z"	=*%<=mLK ++-'*4!2X!=75 "!]
>  	LLOO	s    JJ 	K$J>>K)__doc__r4   loggingpayroll.methods.methodsr   r   payroll.methods.payslip_calcr   r   payroll.models.modelsr   payroll.models.tax_modelsr   	getLogger__name__r@   rX   r"       r%   <module>rb      s<      + 0			8	$c"ra   