
    vgU2                     $   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mZ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      Z G d d      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)gettext_lazy)	FilterSet)Employee)filter_by_name)	AllowanceContract	DeductionFilingStatusLoanAccountPayslipReimbursementc                       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     #/var/www/horilla/payroll/filters.pyMetar#   F   s    	 
r8   r:   Nrequestprefixc                   t         |   ||||       | j                  j                  j	                         D ]E  }t        j                          | j                  j                  |   j                  j                  d<   G y N)dataquerysetr<   r=   id	super__init__formr6   keysuuiduuid4r   r   selfr@   rA   r<   r=   field	__class__s         r9   rE   zContractFilter.__init__^   j    dXwvVYY%%**, 	KE<@JJL>DIIU#**006	Kr8   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)rT   )rU   )contract_name__icontains)splitlenjoinfilterrK   rA   _valueparts
first_nameog_queryset	last_names           r9   r   z!ContractFilter.filter_by_contractc   s    
 1X
+.u:>CHHU12Y'r	)<F;D ' H <F ' H ;D ' H k00%0PPr8   NN)r1   r2   r3   r4   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:   rE   r   __classcell__rM   s   @r9   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
r8   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)r1   r2   r3   r4   r   r5   r6   r7   r8   r9   r:   ru          	 
r8   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 
rP   r   rQ   rR   NrS   )2specific_employees__employee_first_name__icontains1specific_employees__employee_last_name__icontains)r   )r   )title__icontainsrW   rX   rY   rZ   distinctr[   s           r9   rs   z"AllowanceFilter.filter_by_employee       
 1X
+.u:>CHHU12Y'r	)CMBK ' H CM ' H BK ' H k00%0HH  ""r8   N	r1   r2   r3   r4   rc   rd   re   r:   rs   r7   r8   r9   rr   rr   ~   +     '^&&.BCF
 
#r8   rr   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.
    rs   r   c                       e Zd ZdZeZg dZy)DeductionFilter.Metar$   )rv   	is_pretaxrx   ry   rz   r{   N)r1   r2   r3   r4   r
   r5   r6   r7   r8   r9   r:   r      r|   r8   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   r[   s           r9   rs   z"DeductionFilter.filter_by_employee   r   r8   Nr   r7   r8   r9   r   r      r   r8   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  G d d      Z!dddd fdZ" xZ#S )PayslipFilterz-
    Filter set class for payslip model.
    r   )rA   r   r   r   r   )r   
start_dater   r   r   end_date	gross_payr!   	deductionnet_pay:employee_id__employee_work_info__department_id__department	icontainsmonthyearc                       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_employeeN)r1   r2   r3   r4   r   r5   r6   r7   r8   r9   r:   r     s    	 
r8   r:   Nr;   c                   t         |   ||||       | j                  j                  j	                         D ]E  }t        j                          | j                  j                  |   j                  j                  d<   G y r?   rC   rJ   s         r9   rE   zPayslipFilter.__init__/  rN   r8   rb   )$r1   r2   r3   r4   rc   rd   r   re   ModelMultipleChoiceFilterr   objectsallr   SelectMultipler%   rf   rg   r   r   start_date_fromstart_date_tillend_date_fromend_date_tillrl   r   r   r   r   r   r   r*   r   r   r:   rE   ro   rp   s   @r9   r   r      sB    '^&&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***OJ &N%%7SE$>$$&QD
 
*KD K Kr8   r   c                       e Zd ZdZ ej
                  dd      Z ej
                  e      Z ej                   e
j                  ddi      d	
      Z G d d      Zy)LoanAccountFilterz
    LoanAccountFilter
    rv   r   r!   r   r   r   r   provided_date)r   r   c                       e Zd ZeZg dZy)LoanAccountFilter.Meta)	re   search_employeer   settledr   r%   .employee_id__employee_work_info__department_id0employee_id__employee_work_info__job_position_id5employee_id__employee_work_info__reporting_manager_idN)r1   r2   r3   r   r5   r6   r7   r8   r9   r:   r   A  s    

r8   r:   N)r1   r2   r3   r4   rc   rd   re   r   r   rf   r   rg   r   r:   r7   r8   r9   r   r   5  sa     '^&&'{SF/n//~FO-N--uff%56"M

 
r8   r   c                   L    e Zd ZdZ ej
                  dd      Z G d d      Zy)ReimbursementFilterz
    ReimbursementFilter
    rv   r   r!   c                       e Zd ZeZg dZy)ReimbursementFilter.Meta)rB   r   r   r%   approved_byr   r   r   N)r1   r2   r3   r   r5   r6   r7   r8   r9   r:   r   W  s    	
r8   r:   N)r1   r2   r3   r4   rc   rd   re   r:   r7   r8   r9   r   r   P  s'     '^&&'{SF
 
r8   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
    rS   Selectr%   r   r   Job Positionr   
Departmentr0   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r1   r2   r3   r4   r\   r6   r7   r8   r9   r   r   e  s    
 
Qx[	*&	;Q~=NO	91\?K	AhK(	4ajA	8!K.I	7:GC!"	
 
7)EFr8   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   rS   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   r7   r8   r9   r   r   {  s    
 
Qx[	*&	q)*	q'	Qz]#	an%	an%	AiL!	1X;	91\?K	;Q~=NO	7:G	6)EFr8   r   )r4   rH   rc   djangor   django.utils.translationr   r\   base.filtersr   employee.modelsr   horilla.filtersr   payroll.models.modelsr   r	   r
   r   r   r   r   r   rr   r   r   r   r   r   r   r7   r8   r9   <module>r      s       6 " $ *  ]Y ]@.#i .#b.#i .#bRKI RKj
	 
6
) 
* , r8   