
    siF                        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 dd	lmZmZmZmZmZmZmZmZ dd
lmZ  G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z  G d de      Z! G d de      Z" G d de      Z# G d d      Z$ G d d      Z% G d d e      Z&y)!a  
Module containing filter set classes for payroll models.

This module defines the filter set classes used for filtering data in the payroll app.
Each filter set class corresponds to a specific model and contains filter fields and methods
to customize the filtering behavior.

    N)forms)Q)gettext_lazy)	FilterSet)Employee)HorillaFilterSetfilter_by_name)	AllowanceContract	DeductionFilingStatusLoanAccountPayslipPayslipAutoGenerateReimbursement)
TaxBracketc                       e Zd ZdZ ej
                  d      Z ej                  d ej                  ddi            Z
 ej                  d	 ej                  ddi            Z ej                   ej                  ddi      dd
      Z ej                   ej                  ddi      dd      Z ej                   ej                  ddi      d	d
      Z ej                   ej                  ddi      d	d      Z ej                   dd      Z ej                   dd
      Z G d d      Zdddd fdZd Z xZS )ContractFilterz|
    Filter set class for Contract model

    Args:
        FilterSet (class): custom filter set class to apply styling
    filter_by_contractmethodcontract_start_datetypedateattrs)
field_namewidgetcontract_end_dategter   r   lookup_exprltewager   r"   c                       e Zd ZdZeZg dZy)ContractFilter.Meta6
        Meta class to add additional options
        )employee_idcontract_namer   r   	wage_typefiling_status+employee_id__employee_work_info__company_id
departmentjob_positionjob_roleshift	work_typepay_frequencycontract_statusr$   N)__name__
__module____qualname____doc__r   modelfields     3/var/www/python-projects/worksol/payroll/filters.pyMetar'   I   s    	 
r<   r>   Nrequestprefixc                   t         |   ||||       | j                  j                  j	                         D ]E  }t        j                          | j                  j                  |   j                  j                  d<   G y N)dataquerysetr@   rA   id	super__init__formr:   keysuuiduuid4r   r   selfrD   rE   r@   rA   field	__class__s         r=   rI   zContractFilter.__init__a   j    dXwvVYY%%**, 	KE<@JJL>DIIU#**006	Kr<   c                 (   |j                         }|d   }|}t        |      dkD  rdj                  |dd       nd}|r|r|j                  ||      }n)|r|j                  |      }n|r|j                  |      }||j                  |	      z  }|S )
=
        Filter queryset by first name or last name.
        r       N )+employee_id__employee_first_name__icontains*employee_id__employee_last_name__icontainsrX   rY   )contract_name__icontains)splitlenjoinfilterrO   rE   _valueparts
first_nameog_queryset	last_names           r=   r   z!ContractFilter.filter_by_contractf   s    
 1X
+.u:>CHHU12Y'r	)<F;D ' H <F ' H ;D ' H k00%0PPr<   NN)r5   r6   r7   r8   django_filters
CharFiltersearch
DateFilterr   	DateInputr   r   contract_start_date_fromcontract_start_date_tillcontract_end_date_fromcontract_end_date_tillNumberFilterbasic_pay__ltebasic_pay__gter>   rI   r   __classcell__rQ   s   @r=   r   r   !   st    '^&&.BCF3.33(uff%56 211&uff%56  9~88uff%56( 
  9~88uff%56( 
 7^66uff%56&
 7^66uff%56&
 1^00FPUVN0^00FPUVN
 
0KD K
r<   r   c                   P    e Zd ZdZ ej
                  d      Z G d d      Zd Zy)AllowanceFilterz/
    Filter set class for Allowance model.
    filter_by_employeer   c                       e Zd ZdZeZg dZy)AllowanceFilter.Metar(   )title
is_taxableis_condition_basedis_fixedbased_onamountN)r5   r6   r7   r8   r
   r9   r:   r;   r<   r=   r>   r{          	 
r<   r>   c                 D   |j                         }|d   }|}t        |      dkD  rdj                  |dd       nd}|r|r|j                  ||      }n)|r|j                  |      }n|r|j                  |      }||j                  |	      z  }|j	                         S 
rT   r   rU   rV   NrW   )2specific_employees__employee_first_name__icontains1specific_employees__employee_last_name__icontains)r   )r   title__icontainsr]   r^   r_   r`   distinctra   s           r=   ry   z"AllowanceFilter.filter_by_employee       
 1X
+.u:>CHHU12Y'r	)CMBK ' H CM ' H BK ' H k00%0HH  ""r<   N	r5   r6   r7   r8   ri   rj   rk   r>   ry   r;   r<   r=   rx   rx      +     '^&&.BCF
 
#r<   rx   c                   P    e Zd ZdZ ej
                  d      Z G d d      Zd Zy)DeductionFilterz/
    Filter set class for Deduction model.
    ry   r   c                       e Zd ZdZeZg dZy)DeductionFilter.Metar(   )r|   	is_pretaxr~   r   r   r   N)r5   r6   r7   r8   r   r9   r:   r;   r<   r=   r>   r      r   r<   r>   c                 D   |j                         }|d   }|}t        |      dkD  rdj                  |dd       nd}|r|r|j                  ||      }n)|r|j                  |      }n|r|j                  |      }||j                  |	      z  }|j	                         S r   r   ra   s           r=   ry   z"DeductionFilter.filter_by_employee   r   r<   Nr   r;   r<   r=   r   r      r   r<   r   c                       e Zd ZdZ ej
                  e      Z ej                  e	j                  j                          ej                               Z ej                   ej                   ddi            Z ej                   ej                   ddi            Z ej                   ej                   ddi      dd	
      Z ej                   ej                   ddi      dd
      Z ej                   ej                   ddi      dd	
      Z ej                   ej                   ddi      dd
      Z ej.                  dd      Z ej.                  dd	      Z ej.                  dd      Z ej.                  dd	      Z ej.                  dd      Z ej.                  dd	      Z ej
                  dd      Z ej
                  dd      Z ej
                  dd      Z  ej
                  dd      Z! ej
                  dd      Z" ej.                  d      Z# ej.                  d      Z$ ej.                  d      Z% ej.                  d      Z& G d d      Z'd Z(d  Z)d! Z*d" Z+d&d#d#d$ fd%Z, xZ-S )'PayslipFilterz-
    Filter set class for payslip model.
    r   )rE   r   r   r   r   )r   
start_dater    r!   r#   end_date	gross_payr%   	deductionnet_pay.employee_id__employee_work_info__department_id	icontains:employee_id__employee_work_info__department_id__departmentmonthyearfilter_by_allowance_titlezAllowance Title)r   labelfilter_by_allowance_amount_gtefilter_by_allowance_amount_ltefilter_by_deduction_amount_gtefilter_by_deduction_amount_ltec                       e Zd ZdZeZg dZy)PayslipFilter.Metar(   )r)   r   r   
group_namestatusgross_pay__ltegross_pay__gtededuction__ltededuction__gtenet_pay__ltenet_pay__gtesent_to_employeeallowance_amount_gteallowance_amount_ltededuction_amount_gtededuction_amount_lteN)r5   r6   r7   r8   r   r9   r:   r;   r<   r=   r>   r   1  s    	 
r<   r>   c                     |j                  |D cg c]@  }t        fd|j                  xs i j                  dg       D              r|j                  B c}      S c c}w )Nc              3   l   K   | ]+  }t        |j                  d d            t              k\   - ywr   r   Nfloatget.0	allowancerc   s     r=   	<genexpr>z?PayslipFilter.filter_by_allowance_amount_gte.<locals>.<genexpr>O  2      ! )--!45uE   14
allowancesid__in)r`   anypay_head_datar   rF   rO   rE   namerc   ps      ` r=   r   z,PayslipFilter.filter_by_allowance_amount_gteJ  e     " &'oo&;%@%@r%R    	
 		
   AAc                     |j                  |D cg c]@  }t        fd|j                  xs i j                  dg       D              r|j                  B c}      S c c}w )Nc              3   l   K   | ]+  }t        |j                  d d            t              k   - ywr   r   r   s     r=   r   z?PayslipFilter.filter_by_allowance_amount_lte.<locals>.<genexpr>[  r   r   r   r   )r`   allr   r   rF   r   s      ` r=   r   z,PayslipFilter.filter_by_allowance_amount_lteV  r   r   c           	          t              g d}|j                  |D cg c]#  t        fd|D              rj                  % c}      S c c}w )Npretax_deductionsgross_pay_deductionsbasic_pay_deductionspost_tax_deductionstax_deductionsnet_deductionsc              3      K   | ]G  }j                   xs i j                  |g       D ]"  }t        |j                  d d            k   $ I ywr   r   r   r   r   keydr   rc   s      r=   r   z?PayslipFilter.filter_by_deduction_amount_lte.<locals>.<genexpr>q  Y      oo388bA  !%%!,-66   AAr   )r   r`   r   rF   rO   rE   r   rc   deduction_keysr   s      ` `r=   r   z,PayslipFilter.filter_by_deduction_amount_lteb  a    e
  " -    

 
	
   (Ac           	          t              g d}|j                  |D cg c]#  t        fd|D              rj                  % c}      S c c}w )Nr   c              3      K   | ]G  }j                   xs i j                  |g       D ]"  }t        |j                  d d            k\   $ I ywr   r   r   s      r=   r   z?PayslipFilter.filter_by_deduction_amount_gte.<locals>.<genexpr>  r   r   r   )r   r`   r   rF   r   s      ` `r=   r   z,PayslipFilter.filter_by_deduction_amount_gtey  r   r   Nr?   c                   t         |   ||||       | j                  j                  j	                         D ]E  }t        j                          | j                  j                  |   j                  j                  d<   G y rC   rG   rN   s         r=   rI   zPayslipFilter.__init__  rR   r<   rh   ).r5   r6   r7   r8   ri   rj   r	   rk   ModelMultipleChoiceFilterr   objectsr   r   SelectMultipler)   rl   rm   r   r   start_date_fromstart_date_tillend_date_fromend_date_tillrr   r   r   r   r   r   r   department_idr.   r   r   allowance_titler   r   r   r   r>   r   r   r   r   rI   ru   rv   s   @r=   r   r      s    '^&&n=F:.::!!%%'#u##%K +**uff%56J )~((uff%56H 0n//uff%56O
 0n//uff%56O
 .N--uff%56M
 .N--uff%56M
 1^00EN 1^00EN 1^00EN 1^00EN />..)QVWL.>..)QVWL-N--CM +**OJ &N%%7SE$>$$&QD/n//*2CO 7>66/ 7>66/ 7>66/ 7>66/
 
2




.
.KD K Kr<   r   c                       e Zd ZdZ ej
                  d      Z ej
                  e      Z ej                   e
j                  ddi      d      Zd	 Z G d
 d      Zy)LoanAccountFilterz
    LoanAccountFilter
    filter_by_searchr   r   r   r   provided_date)r   r   c                 l    |j                  t        |      t        |      z  t        |      z        S )Nr   rZ   r[   )r`   r   )rO   rE   r   rc   s       r=   r   z"LoanAccountFilter.filter_by_search  s7    u%EBC5AB
 	
r<   c                       e Zd ZeZg dZy)LoanAccountFilter.Meta)	rk   search_employeer   settledr   r)   r   0employee_id__employee_work_info__job_position_id5employee_id__employee_work_info__reporting_manager_idN)r5   r6   r7   r   r9   r:   r;   r<   r=   r>   r     s    

r<   r>   N)r5   r6   r7   r8   ri   rj   rk   r	   r   rl   r   rm   r   r   r>   r;   r<   r=   r   r     se    
 '^&&.@AF/n//~FO-N--uff%56"M


 
r<   r   c                   P    e Zd ZdZ ej
                  d      Z G d d      Zd Zy)ReimbursementFilterz
    ReimbursementFilter
    search_methodr   c                       e Zd ZeZg dZy)ReimbursementFilter.Meta)rF   r   r   r)   approved_byr   r   r   N)r5   r6   r7   r   r9   r:   r;   r<   r=   r>   r     s    	
r<   r>   c                 h    |j                  |      |j                  |      z  j                         S )G
        This method is used to search employees and objective
        rZ   r   r`   r   rO   rE   rb   rc   s       r=   r   z!ReimbursementFilter.search_method  s1     ___Ooouo56
(*	r<   N	r5   r6   r7   r8   ri   rj   rk   r>   r   r;   r<   r=   r   r     s*    
 '^&&o>F
 
r<   r   c                   P    e Zd ZdZ ej
                  d      Z G d d      Zd Zy)TaxBracketFilter0
    Filter set class for TaxBracket model.
    r   r   c                       e Zd ZeZdZy)TaxBracketFilter.Meta__all__N)r5   r6   r7   r   r9   r:   r;   r<   r=   r>   r    s    r<   r>   c                 B    |j                  |      j                         S )r   )*filing_status_id__filing_status__icontainsr   r  s       r=   r   zTaxBracketFilter.search_method  s     OOuOM
(*	r<   Nr  r;   r<   r=   r  r    s*     '^&&o>F r<   r  c                   P    e Zd ZdZ ej
                  d      Z G d d      Zd Zy)FilingStatusFilterr  r   r   c                       e Zd ZeZdZy)FilingStatusFilter.Metar  N)r5   r6   r7   r   r9   r:   r;   r<   r=   r>   r    s    r<   r>   c                 B    |j                  |      j                         S )r   )filing_status__icontainsr   r  s       r=   r   z FilingStatusFilter.search_method  s    
 ?IIKKr<   Nr  r;   r<   r=   r  r    s+     '^&&o>F Lr<   r  c                       e Zd ZdZd ed      fd ed      fd ed      fd ed	      fd
 ed      fd ed      fd ed      fd ed      fd ed      fd ed      fg
Zy)ContractReGroup:
    Class to keep the field name for group by option
    rW   Selectr)   r   r   Job Positionr   
Departmentr4   Status)employee_id__employee_work_info__shift_idShift-employee_id__employee_work_info__work_type_idz	Work Type,employee_id__employee_work_info__job_role_idJob Roler   zReporting Managerr-   CompanyNr5   r6   r7   r8   rb   r:   r;   r<   r=   r  r    s    
 
Qx[	*&	;Q~=NO	91\?K	AhK(	4ajA	8!K.I	7:GC!"	
 
7)EFr<   r  c                       e Zd ZdZd ed      fd ed      fd ed      fd ed	      fd
 ed      fd ed      fd ed      fd ed      fd ed      fd ed      fd ed      fd ed      fd ed      fgZy)PayslipReGroupr  rW   r  r)   r   r   zPayslip Batchr   z
Start Dater   zEnd Date	basic_payz	Basic Payr   z	Gross Payr   zNet Payr   r  r   r  r   r  r  r  r-   r  Nr  r;   r<   r=   r   r     s    
 
Qx[	*&	q)*	q'	Qz]#	an%	an%	AiL!	1X;	91\?K	;Q~=NO	7:G	6)EFr<   r   c                   L    e Zd Z ej                  d      Z G d d      Zd Zy)PayslipAutoGenerateFilterr   r   c                       e Zd ZeZdgZy)PayslipAutoGenerateFilter.Meta
company_idN)r5   r6   r7   r   r9   r:   r;   r<   r=   r>   r%  1  s    #r<   r>   c                 B    |j                  |      j                         S )r   )company_id__company__icontainsr   r  s       r=   r   z'PayslipAutoGenerateFilter.search_method5  s    
 FQQSSr<   N)r5   r6   r7   ri   rj   rk   r>   r   r;   r<   r=   r#  r#  -  s$    &^&&o>F   Tr<   r#  )'r8   rL   ri   djangor   django.db.modelsr   django.utils.translationr   rb   base.filtersr   employee.modelsr   horilla.filtersr   r	   payroll.models.modelsr
   r   r   r   r   r   r   r   payroll.models.tax_modelsr   r   rx   r   r   r   r   r  r  r  r   r#  r;   r<   r=   <module>r1     s        6 " $ <	 	 	 1]% ]@.#& .#b.#& .#bpK$ pKf 
(  
F* @' *L) L& , ,T 0 Tr<   