
    si'.              	          d 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 dd	lmZ dd
lmZ ddlmZmZmZ ddlmZ ddlmZ ddlmZ ddlmZmZ ej@                  ejB                  ejD                  ejF                  ejH                  ejJ                  ejL                  ed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,y)z\
This page is handling the cbv methods of allowance and deduction in employee profile page.
    N)Any)apps)reverse)method_decorator)gettext_lazy)Employee)return_none)login_required)HorillaDetailedViewHorillaListViewHorillaTabView)AllowanceListView)DeductionListView)dynamic_attr)	Allowance	Deduction)equalnotequalltgtlege	icontainsrangec                   "     e Zd ZdZ fdZ xZS )AllowanceDeductionTabViewz6
    generic tab view for allowance and deduction
    c                     t        |   di |}| j                  j                  d      }t	        d      t        dd|i       ddt        d       d| d	d
gdt	        d      t        dd|i       dg|d<   |S )zj
        Adds tab information for allowances and deductions, including actions for adding bonuses
        pk
Allowancesallowance-tab-listkwargsz	Add Bonusz)
                                hx-get="z	add-bonusz?employee_id=z",
								hx-target="#addBonusModalBody"
								data-toggle="oh-modal-toggle"
								data-target="#addBonusModal"
                      )actionattrs)titleurlactions
Deductionsdeduction-tab-list)r%   r&   tabs )superget_context_datar"   get_r   )selfr"   contextr   	__class__s       C/var/www/python-projects/worksol/payroll/cbv/allowance_deduction.pyr-   z*AllowanceDeductionTabView.get_context_data+   s    
 '*4V4[[__T" <!"6tRjIJ #.&))0)=(>mB4 P"
  <!"6tRkJK!
*     )__name__
__module____qualname____doc__r-   __classcell__)r2   s   @r3   r   r   &   s     r4   r   c                       e Zd ZdZdZdZdeddffdZej                  D  cg c]  }|d   d	vr| c}} Z	dZ
 eed
      fd       ZdeffdZd ZxZS c c}} w )AllowanceTabListz%
    list view for allowance tab
    0cbv/allowance_deduction/allowance_deduction.html   r"   returnNc                     t        |   di | d| _        | j                  j                  j
                  j                  d      }t        dd|i      | _        y )Nallowance_tab_idr   r    r!   r+   )	r,   __init__view_idrequestresolver_matchr"   r.   r   
search_urlr0   r"   r   r2   s      r3   rA   zAllowanceTabList.__init__R   sM    "6")\\((//33D9!"6bzJr4      )get_specific_employeesget_exclude_employeescondition_based_displayratedispatchnamec                 *    t        t        | 
  |i |S N)r,   r   rL   r0   argsr"   r2   s      r3   rL   zAllowanceTabList.dispatchg       &6GGGr4   c                    t        |   d
i |}| j                  j                  d      }|| j                  _        d| j                  _        d| j                  _        t        j                  j                  |      }t        j                  d      r*|j                  j                  d      j                         nd}|r|j                  nd}||d<   ||d	<   |S )zl
        Adds active contract details and basic pay for a specified employee
        to the context
        r   Nr@   idpayrollactivecontract_statusactive_contracts	basic_payr+   )r,   r-   r"   r.   rC   emp_idallowance_divr@   r   objectsr   is_installedcontract_setfilterfirstwager0   r"   r1   r   employeer[   r\   r2   s          r3   r-   z!AllowanceTabList.get_context_datak   s     '*4V4[[__T" %)"(:%##''2'.   + !!(((BHHJ 	
 .>$))4	&6"#(r4   c                    t        j                  |       }| j                  j                  d      }t        j
                  j                  |      }t        j                  d      r*|j                  j                  d      j                         nd}|r|j                  nd}g }|r|j                  |      }|j                  d	      j                  |
      }|j                  d      j                  |
      }	||z  |	z  }
|
j                         }
|
D ]  }|j                  r|j                  }|j                   }|j"                  j%                         j'                  dd      }t)        ||      }t*        j                  |      }|u t-        |      |      } |||      s|j/                  |       |j/                  |        g }|D ]Y  }t*        j                  |j0                        }|j2                  dk(  r|nd} |||j4                        sI|j/                  |       [ |j                  |D cg c]  }|j6                   c}      }|S |j9                         }|S c c}w )z
        Returns a filtered queryset of allowance based on
        the employee's active contract and specific conditions
        r   rU   rW   rX   rY   N)specific_employeesT)is_condition_basedexclude_employees)include_active_employees r/   r\   r   id__in)r   get_querysetr"   r.   r   r_   r   r`   ra   rb   rc   rd   excludedistinctri   field	conditionvaluelowerreplacer   operator_mappingtypeappendif_condition	if_choice	if_amountrV   none)r0   querysetr   rf   r[   r\   employee_allowancesspecific_allowancesconditional_allowancesactive_employeescombined_allowances	allowancecondition_fieldcondition_operatorcondition_valueemployee_valueoperator_funcfiltered_allowancess                     r3   rp   zAllowanceTabList.get_queryset   sd    #//5[[__T"##''2'.   + !!(((BHHJ 	
 .>$))4	 "*//X/"N%-___%M%U%U"* &V &"  (MUU"*  V  
 $&<<?OO   #6">">"@0 :	//&/ooO)2)<)<&&/oo&;&;&=&E&Ec3&OO%1(O%LN$4$8$89K$LM%1*>$~*>*O(I/66yA'..y9: #%0 :	 0 4 4Y5K5K L/8/B/Bk/Q)WX )2E2EF'..y9	:  6IJ	J ' H   }}H Ks   ;I*)r5   r6   r7   r8   template_namerecords_per_pager   rA   r   columnsrow_status_indicationsr   r
   rL   r-   rp   r9   .0colr2   s   00@r3   r;   r;   J   s     GMK K K %,,
q6

 	
G "n:6H 7H ,;S
s   Ar;   c                       e Zd ZdZ eed      fd       ZdeddffdZe	j                  D  cg c]  }|d	   d
vr| c}} Z
dZdeffdZfdZxZS c c}} w )DeductionTabz%
    list view for deduction tab
    rL   rM   c                 *    t        t        | 
  |i |S rP   )r,   r   rL   rQ   s      r3   rL   zDeductionTab.dispatch   rS   r4   r"   r>   Nc                     t        |   di | d| _        | j                  j                  j
                  j                  d      }t        dd|i      | _        d | _	        y )Nz
deduct-divr   r)   r!   r+   )
r,   rA   rB   rC   rD   r"   r.   r   rE   r   rF   s      r3   rA   zDeductionTab.__init__   sU    "6"#\\((//33D9!"6bzJ&*#r4   rG   )specific_employees_colexcluded_employees_colcondition_bsed_colrK   r<   c                 t   t        |   d	i |}| j                  j                  d      }|| j                  _        t        j                  j                  |      }t        j                  d      r*|j                  j                  d      j                         nd}|r|j                  nd}||d<   ||d<   |S )
zX
        Adds employee details, active contracts, and basic pay to the context.
        r   rU   rW   rX   rY   Nr[   r\   r+   )r,   r-   r"   r.   rC   my_idr   r_   r   r`   ra   rb   rc   rd   re   s          r3   r-   zDeductionTab.get_context_data   s    
 '*4V4[[__T"##''2'.   + !!(((BHHJ 	
 .>$))4	&6"#( r4   c                 t   t        j                  |       }| j                  j                  d      }t        j
                  j                  |      }t        j                  d      r*|j                  j                  d      j                         nd}|r|j                  nd}|rq|j                  |dd	      j                         }|j                  ddd
      j                  |      j                         }|j                  ddd      j                  |      j                         }||z  |z  }g }	|D ]  }
|
j                  r|
j                  }|
j                   }|
j"                  j%                         j'                  dd      }t)        ||      }t*        j                  |      }|u || t-        |      |            s|	j/                  |
       |	j/                  |
        |j                  |	D 
cg c]  }
|
j0                   c}
      }|S t2        |          j5                         }|S c c}
w )z
        Returns a filtered queryset of deductions based on
        the employee's active contract and specific conditions
        r   rU   rW   rX   rY   NTF)rh   	is_pretaxis_tax)ri   r   r   rj   )rl   r   r   rm   r/   rn   )r   rp   r"   r.   r   r_   r   r`   ra   rb   rc   rd   rr   rq   ri   rs   rt   ru   rv   rw   r   rx   ry   rz   rV   r,   r~   )r0   r   r   rf   r[   r\   specific_deductionsconditional_deductionactive_employee_deductionfiltered_queryset	deductionr   r   r   r   r   r2   s                   r3   rp   zDeductionTab.get_queryset   s)    #//5[[__T"##''2'.   + !!(((BHHJ 	
 .>$))4	"*//#+tE #2 #hj   44PUV84 " -1T%    84 & $&;;>WW  !#% 8	//&/ooO)2)<)<&&/oo&;&;&=&E&Ec3&OO%1(O%LN$4$8$89K$LM%1m&(<^(<_(M7 *00;%,,Y78  6GH	H ' H
  w+-224H	 Is   :H5)r5   r6   r7   r8   r   r
   rL   r   rA   r   r   r   r-   rp   r9   r   s   00@r3   r   r      s     n:6H 7H+ + + %,,
q6

 	
G GM ,7 7M
s   Ar   c                       e Zd ZdZeZ ed      ZddddZ ed      dd	f ed
      df ed      df ed      df ed      df ed      dfgZ	dZ
y)DeductionDetailViewz
    Detail View
    Detailsr%   r   
get_avatarr%   subtitleavatarTaxtax_colTzOne Time deductionget_one_time_deductionCondition Basedr   Amount
amount_colHas Maximum Limithas_maximum_limit_colzDeduction Eligibilitydeduction_eligibilitydeduct_detail_actionsN)r5   r6   r7   r8   r   modelr/   r%   headerbodyaction_methodr+   r4   r3   r   r   /  s     EiLE F 
59d#	
	 ":;	
	34	
8l#	
	!89	
"	#%<=D ,Mr4   r   c                       e Zd ZdZeZ ed      ZddddZ ed      df ed	      d
f ed      df ed      df ed      df ed      dfgZ	dZ
y)AllowanceDetailViewz'
    detail view for allowance tab
    r   r%    r   r   Taxableget_is_taxable_displayzOne Time Allowanceone_time_date_displayr   rJ   r   based_on_amountr   cust_allowance_max_limitzAllowance Eligibilityallowance_eligibilityallowance_detail_actionsN)r5   r6   r7   r8   r   r   r/   r%   r   r   r   r+   r4   r3   r   r   I  s     EiLE F 
9/0	
	 "9:	
	89	
8'(	
	!;<	
"	#%<=D /Mr4   r   )-r8   operatortypingr   django.appsr   django.urlsr   django.utils.decoratorsr   django.utils.translationr   r/   employee.modelsr   employee.viewsr	   horilla_views.cbv_methodsr
   horilla_views.generic.cbv.viewsr   r   r   payroll.cbv.allowancesr   payroll.cbv.deductionr   payroll.methods.payslip_calcr   payroll.models.modelsr   r   eqner   r   r   r   containsrx   r   r;   r   r   r   r+   r4   r3   <module>r      s        4 6 $ & 4 
 5 3 5 6 [[
++
++
++
++""	 ! !Hr( rjm$ m`,- ,4/- /r4   