
    vg[                        d Z ddl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 ddlZdd	lmZmZ dd
lmZ ddlmZ ddlmZmZ ddlmZ ddlm Z  ddl!m"Z"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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 ddl6m7Z8  ejr                  e:      Z; G d dej*                        Z< G d dej*                        Z= G d de      Z> G d de"      Z? G d de      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d0 ed1      fd2 ed3      fd4 ed5      fd6 ed7      fd8 ed9      fd: ed;      fd< ed=      fd> ed?      fd@ edA      fdB edC      fgZA G dD dEej(                        ZBg dFZC G dG dHej(                        ZDddIlEmFZF dJ ZG G dK dLe      ZH G dM dNeH      ZI G dO dPe      ZJ G dQ dRe      ZK G dS dTeK      ZL G dU dVej                        ZN G dW dXej                        ZP G dY dZe      ZQ G d[ d\e      ZR G d] d^e      ZSy)_z
These forms provide a convenient way to handle data input, validation, and customization
of form fields and widgets for the corresponding models in the payroll management system.
    N)Any)forms)appsrender_to_string)timezone)gettext_lazy)Form	ModelForm)reload_queryset)EmployeeFilter)
BonusPointEmployee)horilla_middlewares)get_horilla_model_class)HorillaFormorginal_template_name)HorillaMultiSelectField)HorillaMultiSelectWidget)notify)
tax_models)		AllowanceContract	DeductionLoanAccountMultipleConditionPayslipPayslipAutoGenerateReimbursementReimbursementMultipleAttachment)component_widgetsc                        e Zd ZdZ ej
                  ej                  d      Z ej
                  d      Z	 e
d      Z G d d      Z fdZd	 Z fd
Zddedef fdZ xZS )AllowanceFormz"
    Form for Allowance model
    Fwidgetrequiredr&   r   c                       e Zd ZdZej
                  j
                  j                  ZdZdgZ	d e
j                  ddi      iZy)	AllowanceForm.Meta3
        Meta class for additional options
        __all__	is_activeone_time_datetypedateattrsN)__name__
__module____qualname____doc__payrollmodelsr   modelfieldsexcluder   DateTimeInputwidgets     1/var/www/horilla/payroll/forms/component_forms.pyMetar)   6   I    	 %%//-0U007GH
r>   r@   c           
      2   |j                  d      x}r0i }|j                  d|j                  j                  d      i}||d<   t        |   |i | t        t        j                  j                         t        dt        dd| j                        d	
      | j                  d<   | j                  d   j                  j                  j                  ddi       t!        | j                         t        j"                  |       | j                  d   _        y Ninstancer-   z%Y-%m-%dinitialemployee-widget-filterfemployee_filters.html)filter_route_namefilter_classfilter_instance_contex_namefilter_template_pathrD   zSpecific Employees)querysetr%   labelspecific_employeesif_conditiononchangezrangeToggle($(this)))formstyle)getr-   strftimesuper__init__r   r   objectsallr   r   rD   r9   r%   r1   updater   StyleWidget)selfargskwargsrD   rE   	__class__s        r?   rW   zAllowanceForm.__init__B   s   zz*--8- G%%1#X%;%;%D%DZ%P !(F9$)&),C%%))++":+,/%< '
-
() 	N#**00772	

 	$&,&8&8d&CG#r>   c                 &    d| i}t        d|      }|S S
        Render the form fields as HTML table rows with Bootstrap styling.
        rR   zcommon_form.htmlr   r\   context
table_htmls      r?   as_pzAllowanceForm.as_pa         4.%&8'B
r>   c                    t        |   |i |}| j                  j                  d      }| j                  j	                  d      }| j                  j	                  d      }| j
                  j                         D ]  \  }}t        |t              s| j                  j                  |d        |s||st        j                  |di      t         |          }| j
                  |   j                  j                  | j                  j                  |            }	|	||<    t         |          }|j	                  d      dk(  rd|d	<   |j	                  d
      }
|j	                  d      }|
r|r||
k  rt        j                  ddi      |
s|st        j                  ddd      |
st        j                  d
di      |st        j                  ddi      y d |d
<   d |d<   y )NrO   include_active_employeesis_condition_basedThis field is requiredid__inrP   ranger   	if_amountstart_range	end_range*End range cannot be less than start range.1This field is required when condition is "range".rp   rq   )rV   cleandatagetlistrT   r9   items
isinstancer   errorspopr   ValidationErrorrM   filterr\   r]   r^   cleaned_datarO   include_allcondition_based
field_namefield_instancerv   rp   rq   r_   s               r?   ru   zAllowanceForm.cleani   s   w}d5f5!YY../CDiimm$>?))--(<=*.++*;*;*= 	0&J.*AB
D1*#++//=U0VWW$w}{{:.77>>99,,Z8 ?  ,0Z(	0 w}N+w6()L%&**=9K$((5IyY+-E++ "NO  y++'Z%X  !++"$WX  ++ "UV  
 +/L'(,L%r>   commitreturnc                    t         
|   |       | j                  j                  d      }| j                  j                  d      }| j                  j                  d      }g }	 | j                  j
                  r2| j                  j                  j                         j                          | j                  j                  rHt        |      D ]:  \  }}t        |||   ||         }|j                          |j                  |       < |r# | j                  j                  j                  |  |S # t        $ r}	t        |	       Y d }	~	@d }	~	ww xY wNother_conditionsother_fieldsother_valuesfield	conditionvalue)rV   saverv   rw   rD   pkr   rY   deleterj   	enumerater   append	Exceptionloggeraddr\   r   r   r   r   multiple_conditionsindexr   r   er_   s             r?   r   zAllowanceForm.save   s!   V99,,-?@yy((8yy((8 	}}..224;;=}}//$-l$; :LE5 1#"25"9*51!I
 NN$'..y9: .DMM**..0CD""	  	1II	   %B&D2 2	E;EE.)r2   r3   r4   r5   r   	CharFieldr%   AllowanceConditionalVisibilityloadrS   _verbose_namer@   rW   rf   ru   boolr   r   __classcell__r_   s   @r?   r#   r#   -   so     5??&"G"GRWXDEOOU+E[>L

 

D>0-d#4 ## # #r>   r#   c                        e Zd ZdZ ej
                  ej                  d      Z ej
                  d      Z	 e
d      Z G d d      Z fdZ fd	Zd
 Zddedef fdZ xZS )DeductionFormz"
    Form for Deduction model
    Fr$   r'   r   c                       e Zd ZdZej
                  j
                  j                  ZdZdgZ	d e
j                  ddi      iZy)	DeductionForm.Metar*   r+   r,   r-   r.   r/   r0   N)r2   r3   r4   r5   r6   r7   r   r8   r9   r:   r   r;   r<   r=   r>   r?   r@   r      rA   r>   r@   c           
         |j                  d      x}r0i }|j                  d|j                  j                  d      i}||d<   t        |   |i | t        t        j                  j                         t        dt        dd| j                        d	
      | j                  d<   | j                  d   j                  j                  j                  ddi       t!        | j                         t        j"                  |       | j                  d   _        | j                  j%                         D ]?  \  }}t'        |j                  t(        j*                        s+t,        |j                  _        A y rC   )rT   r-   rU   rV   rW   r   r   rX   rY   r   r   rD   r9   r%   r1   rZ   r   r[   rx   ry   r   Selectr   option_template_name)r\   r]   r^   rD   rE   r   r   r_   s          r?   rW   zDeductionForm.__init__   sF   zz*--8- G%%1#X%;%;%D%DZ%P !(F9$)&),C%%))++":+,/%< '
-
() 	N#**00772	

 	$&,&8&8d&CG#!%!2!2!4 	JJ%,,54I1	Jr>   c                    t        |   |i |}| j                  j                  d      }| j                  j	                  d      }| j                  j	                  d      }| j
                  j                         D ]  \  }}t        |t              s| j                  j                  |d        |s||st        j                  |di      t         |          }| j
                  |   j                  j                  | j                  j                  |            }	|	||<    t         |          }|j	                  d      dk(  rd|d	<   |j	                  d
      }
|j	                  d      }|
r0|r.t        |      t        |
      k  rt        j                  ddi      |
s|st        j                  ddd      |
st        j                  d
di      |s!t        j                  ddi      d |d
<   d |d<   | j                  j	                  d      3| j                  j	                  d      dk7  r| j                  j                  d      Gt!        | j                  j                  d            dk(  r t        j                  dt#        d      i      | j                  j	                  d      >| j                  j	                  d      dk(  r t        j                  dt#        d      i      | j                  j	                  d      >| j                  j	                  d      dk(  r t        j                  dt#        d      i      |S )NrO   ri   rj   rk   rl   rP   rn   r   ro   rp   rq   rr   rs   rt   update_compensation z You need to choose the employee.r-   zThis field is required.amount)rV   ru   rv   rw   rT   r9   rx   ry   r   rz   r{   r   r|   rM   r}   intlenr   r~   s               r?   ru   zDeductionForm.clean   s   w}d5f5!YY../CDiimm$>?))--(<=*.++*;*;*= 	0&J.*AB
D1*#++//=U0VWW$w}{{:.77>>99,,Z8 ?  ,0Z(	0 w}N+w6()L%&**=9K$((5IyS^s;?O-O++ "NO  y++'Z%X  !++"$WX  ++ "UV  +/L'(,L% IIMM/0<		34: 		!!"67?		))*>?@AE++)1-O+PQ 
 		o.6IIMM/2b8++$a(A&BC  yy}}X&.499==3Jb3P++Xq9R7S,TUUr>   c                 &    d| i}t        d|      }|S ra   r   rc   s      r?   rf   zDeductionForm.as_p5  rg   r>   r   r   c                    t         
|   |       | j                  j                  d      }| j                  j                  d      }| j                  j                  d      }g }	 | j                  j
                  r2| j                  j                  j                         j                          | j                  j                  rHt        |      D ]:  \  }}t        |||   ||         }|j                          |j                  |       < |r# | j                  j                  j                  |  |S # t        $ r}	t        |	       Y d }	~	@d }	~	ww xY wr   )rV   r   rv   rw   rD   r   r   rY   r   rj   r   r   r   r   printr   r   s             r?   r   zDeductionForm.save=  s!   V99,,-?@yy((8yy((8 	}}..224;;=}}//$-l$; :LE5 1#"25"9*51!I
 NN$'..y9: .DMM**..0CD""	  	!HH	r   r   )r2   r3   r4   r5   r   r   r%   DeductionConditionalVisibilityr   rS   r   r   r@   rW   ru   rf   r   r   r   r   r   s   @r?   r   r      sq     5??&"G"GRWXDEOOU+E[>L

 

 JDHT#4 ## # #r>   r   c                   6     e Zd ZdZ fdZ G d d      Z xZS )PayslipForm
    Form for Payslip
    c                    t        |   |i | t        j                  j	                  d      }|D cg c]:  }|j
                  j                  r"|j
                  j                  |j
                  f< c}| j                  d   _	        | j                  d   j                  j                  j                  ddddd       | j                  j                  gt        j                   j#                         j%                  d	
      | j&                  d<   t        j                   j#                         | j&                  d<   y y c c}w )Nactive)contract_statusemployee_id"/payroll/check-contract-start-date#contractStartDateDiv#payslipCreateFormchange delay:300ms)hx-get	hx-target
hx-include
hx-trigger   day
start_dateend_date)rV   rW   r   rX   r}   r   r,   idr9   choicesr%   r1   rZ   rD   r   datetimer/   todayreplacerE   )r\   r]   r^   active_contractscontractr_   s        r?   rW   zPayslipForm.__init__[  s   $)&)#++2282L -.
##-- !!$$h&:&:;.
M"*
 	M"))//66>422		
 ==#)1)<)<)>)F)F1)F)MDLL&'/}}':':'<DLL$ $.
s   ?D>c                       e Zd ZdZej
                  j
                  j                  Zg dZdgZ	 e
j                  dddddd	
       e
j                  ddi
      dZy)PayslipForm.Metar*   )r   r   r   r,   r/   r   r   r   r   )r.   r   r   r   r   r0   r.   r   r   N)r2   r3   r4   r5   r6   r7   r   r8   r9   r:   r   	DateInputr<   r=   r>   r?   r@   r   o  sq    	 %%--

 -)%//"B!8"6"6 (F
r>   r@   )r2   r3   r4   r5   rW   r@   r   r   s   @r?   r   r   V  s    =(
 
r>   r   c            	       \    e Zd ZdZ ej
                  dd      Z eej                  j                          ededd      d	d
      Z ej                   ej                  ddi            Z ej                   ej                  ddi            Z fdZ fdZ G d d      Z xZS )GeneratePayslipFormr   z
Batch nameTrN   r&   rF   rG   rH   )rI   rJ   rK   rL   r   )rM   r%   rN   r&   r.   r/   r0   )r%   c                 L   t         |          }|j                  d      }|j                  d      }t        j                  j                         }||k  rt        j                  ddi      ||kD  rt        j                  ddi      ||kD  rt        j                  ddi      |S )Nr   r   z=The end date must be greater than or equal to the start date.z'The start date cannot be in the future.z%The end date cannot be in the future.)rV   ru   rT   r   r/   r   r   r|   )r\   r   r   r   r   r_   s        r?   ru   zGeneratePayslipForm.clean  s    w}!%%l3
##J/##%j '' _ 
 ''FG  e''DE  r>   c                    t        |   |i | t        j                  j	                  ddd      | j
                  d   _        | j
                  d   j                  j                  j                  dt        j                         d       | j
                  d   j                  j                  j                  d	d
i       | j
                  d   j                  j                  j                  d	d
i       | j
                  d   j                  j                  j                  d	d
i       t        j                  j                         j                  d      | j                   d<   t        j                  j                         | j                   d<   y )NTFr   )r,   contract_set__isnullcontract_set__contract_statusr   zoh-select oh-select-2)classr   r   r   oh-input w-100
group_namer   r   r   )rV   rW   r   rX   r}   r9   rM   r%   r1   rZ   uuiduuid4r   r/   r   r   rE   r\   r]   r^   r_   s      r?   rW   zGeneratePayslipForm.__init__  s:   $)&).6.>.>.E.E!&*2 /F /
M"+
 	M"))//66-TZZ\B	
 	L!((..55w@P6QRL!((..55w@P6QRJ&&,,33W>N4OP%-]]%8%8%:%B%Bq%B%I\"#+==#6#6#8Z r>   c                   f    e Zd ZdZ ej
                  ddi       ej
                  ddi      dZy)GeneratePayslipForm.Metar*   r.   r/   r0   r   N)r2   r3   r4   r5   r   r   r<   r=   r>   r?   r@   r     s6    	
 *%//0@A'vv.>?
r>   r@   )r2   r3   r4   r5   r   r   r   r   r   rX   noner   r   r   	DateFieldr   r   r   ru   rW   r@   r   r   s   @r?   r   r     s     !J
 *!!&&('6'(+!8	
 
K !vv>N(OPJuoeooVV<L&MNH.9 
 
r>   r   c                   $    e Zd ZdZ G d d      Zy)PayrollSettingsFormz(
    Form for PayrollSettings model
    c                   ,    e Zd ZdZej
                  ZdZy)PayrollSettingsForm.Metar*   r+   N)r2   r3   r4   r5   r7   PayrollSettingsr8   r9   r=   r>   r?   r@   r     s    	 &&r>   r@   Nr2   r3   r4   r5   r@   r=   r>   r?   r   r     s     r>   r   r   r   r   Batchr   z
Start Dater   zEnd Datecontract_wagezContract Wage	basic_pay	Basic Pay	gross_payz	Gross Pay	deductionr   net_payzNet PaystatusStatus-employee_id__employee_bank_details__bank_namez	Bank Name*employee_id__employee_bank_details__branchBranch2employee_id__employee_bank_details__account_numberzAccount Number3employee_id__employee_bank_details__any_other_code1zBank Code #13employee_id__employee_bank_details__any_other_code2zBank Code #2+employee_id__employee_bank_details__countryCountry)employee_id__employee_bank_details__stateState(employee_id__employee_bank_details__cityCityc                   N    e Zd Z ej                  eej                  g d      Zy)PayslipExportColumnForm)r   r   r   r   r   r   r   r   r   r%   rE   N)r2   r3   r4   r   MultipleChoiceFieldexcel_columnsCheckboxSelectMultipleselected_fieldsr=   r>   r?   r  r    s%    /e//++	
Or>   r  )r   contract_documentr,   noter	  
created_atc            
       &   e Zd Zej                  j                         ZeD  cg c]8  }t        |d      r*|j                  t        vr|j                  |j                  f: c}}}} Z ej                  eej                  g d      Zyc c}}}} w )ContractExportFieldFormr   )contract_namer   contract_start_datecontract_end_date	wage_typewagefiling_statusr   r  N)r2   r3   r4   r   _meta
get_fieldsmodel_fieldshasattrnameexclude_fieldsr   field_choicesr   r  r  r  ).0r   r  r  s   0000r?   r  r    s    >>,,.L " 5.)ejj.N 
U''(M
 0e//++	
Os   =B
r  )r|   c                 h    | dk  rt        t        d            | dkD  rt        t        d            y)z
    Percentage validator
    r   zRate must be greater than 0d   zRate must be less than 100N)r|   r   )r   s    r?   rate_validatorr  )  s9     qya =>??s{a <=>> r>   c                       e Zd ZdZ ej
                  d      Z ej                   ej                         d      Z	 ej                  d ej                               Z ej                  dd	d ej                         
      Z ej                   dd      Z ej$                  dgd      Z ej(                  egdd      ZddZ fdZ xZS )	BonusForm
    Bonus Creating Form
    r  )
max_lengthFr$   r   )rN   r%   zIs FixedT)rN   rE   r&   r%   Amountr   )	BASIC_PAYr   )r   r&   Rate)
validatorsrN   r&   c                    | j                   d   }| j                   d   }| j                   d   }| j                   d   }| j                   d   }| j                   d   }t               }||_        ||_        d|_        ||_        ||_        ||_        |j                          d|_	        |j                  j                  |g       |j                          |S )	Ntitler/   r   r   is_fixedrateTF)r   r   r'  r-   only_show_under_employeer   r(  r)  r   ri   rO   set)	r\   r   r'  r/   r   r   r(  r)  bonuss	            r?   r   zBonusForm.saveK  s    !!'*  (''6""8,$$Z0  (")-&!


).&  $$k]3

r>   c                 t   t        |   |i | | j                  j                         D ],  \  }}|j                  j
                  j                  ddi       . t        j                  ddd      | j                  d   _        | j                  d   j                  j
                  j                  ddi       y )Nr   r   r/   r.   r   r0   r(  zoh-switch__checkbox)	rV   rW   r9   rx   r%   r1   rZ   r   r   )r\   r]   r^   r   r   r_   s        r?   rW   zBonusForm.__init__a  s    $)&)!%!2!2!4 	CJLL%%w0@&AB	C%*__!,<=&
F" 	J&&,,33W>S4TUr>   )T)r2   r3   r4   r5   r   r   r'  r   r   r/   IntegerFieldHiddenInputr   BooleanFieldCheckboxInputr(  DecimalFieldr   ChoiceFieldbased_on
FloatFieldr  r)  r   rW   r   r   s   @r?   r  r  3  s     EOOs+E5??/%//"3eDD$%$$:>Oe>O>O>QRK!u!!$?Ru?R?R?TH  UF !u  *D)EPUVH5
 D,V Vr>   r  c                        e Zd Z fdZ xZS )PayslipAllowanceFormc                 p    t        |   |i | t        j                         | j                  d   _        y )Nr/   )rV   rW   r   r0  r9   r%   r   s      r?   rW   zPayslipAllowanceForm.__init__l  s/    $)&)%*%6%6%8F"r>   )r2   r3   r4   rW   r   r   s   @r?   r8  r8  k  s    9 9r>   r8  c                   :    e Zd ZdZ ed      Z G d d      Zd Zy)PayslipDeductionFormr   r   c                   >    e Zd ZeZg dZd ej                         iZy)PayslipDeductionForm.Meta)r'  r-   r   is_tax	is_pretaxr(  r   r5  r)  employer_ratehas_max_limitmaximum_amountr-   N)	r2   r3   r4   r   r8   r9   r   r0  r<   r=   r>   r?   r@   r=  x  s(    
 .U..0
r>   r@   c                 &    d| i}t        d|      }|S )rb   rR   zone_time_deduction.htmlr   rc   s      r?   rf   zPayslipDeductionForm.as_p  s      4.%&?I
r>   N)r2   r3   r4   r5   r   r   r@   rf   r=   r>   r?   r;  r;  q  s!     [>L
 
,r>   r;  c                   J     e Zd ZdZdZ G d d      Zd Z fdZ fdZ xZ	S )LoanAccountFormz
    LoanAccountForm
    zLoan / Advanced Sarlaryc                   r    e Zd ZeZdZddgZ ej                  ddi       ej                  ddi      dZ	y)	LoanAccountForm.Metar+   r,   settled_dater.   r/   r0   )provided_dateinstallment_start_dateN)
r2   r3   r4   r   r8   r9   r:   r   r;   r<   r=   r>   r?   r@   rG    sG    /0U007GH&9e&9&9@P&Q
r>   r@   c                 &    d| i}t        d|      }|S ra   r   rc   s      r?   rf   zLoanAccountForm.as_p  rg   r>   c                    t        |   |i | t        t        j                  j                               | j                  d<   t        t        j                  j                               | j                  d<   | j                  j                  r| j                  j                  | _
        ddg}t        j                  j                  t        | j                  j                  j!                  dd                  j#                         r|g dz   }t        | j                  j$                        | j                  d<   |D ]  }|| j&                  v s| j&                  |=   y y )	NrI  rJ  r   r   T)flat)installment_ids__in)loan_amountinstallmentsinstallment_amount)rV   rW   strr   r/   r   rE   rD   r   r'  r   r   rX   r}   listdeduction_idsvalues_listexistsrI  r9   )r\   r]   r^   fields_to_excluder   r_   s        r?   rW   zLoanAccountForm.__init__  s(   $)&)(+HMM,?,?,A(B_%14X]]5H5H5J1K-.== $ 3 3D!.0H I%%$(MM//;;Dt;L% &  fh	
 %6 9 %!
 -00K0K,LDLL)* +DKK'E*+ r>   c                 <   t        |   |i |}| j                  j                  s8|j	                  d      |j	                  d      k  rt        j                  d      |j	                  d      d k7  r)|j	                  d      dk  rt        j                  d      |S )NrJ  rI  zGInstallment start date should be greater than or equal to provided daterP  r   z+Installments needs to be a positive integer)rV   ru   rD   r   rT   r   r|   )r\   r]   r^   r   r_   s       r?   ru   zLoanAccountForm.clean  s    w}d5f5}}L$4$4$%
_-%. ''Y  N+t3/14++A  r>   )
r2   r3   r4   r5   r   r@   rf   rW   ru   r   r   s   @r?   rE  rE    s-     -L
 
+, r>   rE  c                   .     e Zd Z ed      Z fdZ xZS )AssetFineFormz
Asset Finec                 \   t        |   |i | t        d      | j                  d   _        t        d      | j                  d   _        ddg}|D ]  }|| j                  v s| j                  |=   g d}|D ci c]!  }|| j                  v s|| j                  |   # c}| _        y c c}w )NzFine AmountrO  z	Fine DaterI  r   r.   )r'  rO  rI  descriptionrP  rJ  rQ  settled)rV   rW   r   r9   rN   )r\   r]   r^   rW  r   field_orderr_   s         r?   rW   zAssetFineForm.__init__  s    $)&)+,]+;M"(-.{^O$* 
 ' 	'E#KK&	'	
 4?
*/%4;;BVE4;;u%%
 
s   :B)B))r2   r3   r4   r   r   rW   r   r   s   @r?   rZ  rZ    s    \?L
 
r>   rZ  c                       e Zd ZdZy)MultipleFileInputTN)r2   r3   r4   allow_multiple_selectedr=   r>   r?   r`  r`    s    "r>   r`  c                   *     e Zd Z fdZd fd	Z xZS )MultipleFileFieldc                 X    |j                  dt                      t        |   |i | y )Nr%   )
setdefaultr`  rV   rW   r   s      r?   rW   zMultipleFileField.__init__  s)    ($5$78$)&)r>   c                     t         |   }t        |t        t        f      r|D cg c]  } |||       }}n
 |||      g}|r|d   S d S c c}w )Nr   )rV   ru   ry   rS  tuple)r\   rv   rE   single_file_cleandresultr_   s         r?   ru   zMultipleFileField.clean  s\    !GMdT5M*=AB'73BFB'g67F"vay,, Cs   A)N)r2   r3   r4   rW   ru   r   r   s   @r?   rc  rc    s    *- -r>   rc  c                        e Zd ZdZdZ G d d      Z ej                  d      rd Z fdZ	d Z
 fd	Zdd
edef fdZ xZS )ReimbursementFormz
    ReimbursementForm
    zReimbursement / Encashmentc                       e Zd ZeZdZdgZy)ReimbursementForm.Metar+   r,   N)r2   r3   r4   r   r8   r9   r:   r=   r>   r?   r@   rn    s    -r>   r@   leavec                 \    t        dd      }|j                  j                  |dd      }|S )Nro  	leavetype	app_labelr8   r   T)%employee_available_leave__employee_id/employee_available_leave__total_leave_days__gteis_encashable)r   rX   r}   )r\   employee	LeaveTypeleavess       r?   get_encashable_leavesz'ReimbursementForm.get_encashable_leaves  s9    /'UI&&--6>@A" . F
 Mr>   c                    t        |   |i | g }| j                  j                  s4t	        t
        j                  j                               | j                  d<   t        t        j                  dd       }|rB| j                  j                  |j                  j                  n| j                  j                  }j                  | j                  d<   t!        j"                  d      r|t%        dd      }| j'                  |      }|j(                  j+                  ||      | _        || j.                  d   _        d | j.                  d   _        d | j.                  d   _        | j.                  d	   j4                  j6                  }d
|d<   | j.                  d	   j4                  j6                  j9                  |       | j.                  d   j4                  j6                  }	d|	d<   | j.                  d   j4                  j6                  j9                  |	       t;        j<                  ddd      | j.                  d   _        t?        d      | j.                  d<   d| j.                  d   j4                  j6                  d<   d }
| j@                  r&| j                  j                  s| j@                  d	   }
n"| j                  | j                  jB                  }
|j                  jE                  d      s|jG                  d       |
dk(  r| j                  j                  r|g dz   }n| j                  j                  r|
dk(  s| j@                  jI                  d	      dk(  r|g dz   }n@| j                  j                  r|
dk(  s| j@                  jI                  d	      dk(  r|g dz   }| j                  j                  r|d	dgz   }|D ]  }|| j.                  v s| j.                  |=   y )Nallowance_onrequestr   ro  availableleaverr  )leave_type_id__inr   leave_type_idr.   ztoggleReimbursmentType($(this))rQ   zgetAssignedLeave($(this))r/   r   r.  r0   Attachements)rN   
attachmentz.jpg, .jpeg, .png, .pdfacceptzpayroll.add_reimbursementreimbursement)r  cfd_to_encashad_to_encashbonus_to_encashleave_encashment)r  r   r  bonus_encashment)r  r   r  r  r  )%rV   rW   rD   r   rR  r   r/   r   rE   getattrr   _thread_localsuseremployee_getr   r   r   is_installedr   rz  rX   r}   assigned_leavesr9   rM   empty_labelr%   r1   rZ   r   r   rc  rv   r.   has_permr   rT   )r\   r]   r^   r  r}  rw  AvailableLeaver  	type_attremployee_attrr.   r   r_   s               r?   rW   zReimbursementForm.__init__  sY   $)&)}}+.x}}/B/B/D+EDLL(-<<iN ==##+ ))]].. 
 '/kk]#W%4!)9N #88BO#1#9#9#@#@"1x $A $D  5DDKK(17;DKK(459DKK&2KK'..44	 A	*F""((//	:M299??$?j!M"))//66}E-2__!,<=.
N#* %6N$KL!;TL!((..x8 99T]]--99V$D]]&==%%D||$$%@A!!-0?"t}}'7'7+ / N MM**yy}}V$(::+ / N MM**yy}}V$(::+ / N ==+v}.EEN# 	'E#KK&	'r>   c                 &    d| i}t        d|      }|S ra   r   rc   s      r?   rf   zReimbursementForm.as_pv  rg   r>   c                    t         |          }t        t        j                  dd       }| j
                  j                  r-| j
                  j                  }| j
                  j                  }n|j                  j                  }|d   }t        j                  j                  |      j                         }|dk(  rt| j
                  j                  r| j
                  j                  }n|d   }|j                   |k  rt#        j$                  ddi      |dk  rt#        j$                  ddi      |d	k(  r| j
                  j                  rC| j
                  j&                  }| j
                  j(                  }| j
                  j*                  }	n|d
   }|d   }|d   }	| j-                  |      }
|t#        j$                  d
di      ||
vrt#        j$                  d
di      t/        dd      }|j                  j                  ||      j                         }|dk  r t#        j$                  dt1        d      i      |	dk  r t#        j$                  dt1        d      i      ||j2                  kD  r t#        j$                  dt1        d      i      |	|j4                  kD  r t#        j$                  dt1        d      i      y y )Nr}  r.   )r   r  r  z!Not enough bonus points to redeemr   z+Points must be greater than zero to redeem.r  r  r  r  rk   z!This leave type is not encashablero  r~  rr  )r  r   zValue can't be negative.z&Not enough carryforward days to redeemz#Not enough available days to redeem)rV   ru   r  r   r  rD   r   r   r.   r  r  r   rX   r}   firstr  pointsr   r|   r  r  r  rz  r   r   carryforward_daysavailable_days)r\   r   r}  r   r.   available_pointsr  r  r  r  encashable_leavesr  available_leaver_   s                r?   ru   zReimbursementForm.clean~  s   w}-<<iN==--33K==%%D ",,33K'D%--444MSSU%%}}"&--"?"?"./@"A&&8++&(KL  !#++&(UV  %%}} $ ; ; $ ; ;#}}99 ,_ = ,_ =+N; $ : :; G$++_>V,WXX&77++$&IJ  "9%-=" #1"8"8"?"?"/[ #@ #%'   !1$//(!,F*GH   !#//'+E)FG  !?#D#DD//(!,T*UV   /"@"@@//'+P)QR  AG &r>   r   r   c                     | j                   j                   }g }g }d }| j                  j                  d      rt| j                  j                  d      }|d   | j                   _        g }|D ]>  }t               }||_        |j                          |j                  |j                         @ t        
|   |      } |j                  j                  |  t        j                  j                  | j                  d         }	 |r]t!        j"                  ||j$                  j&                  j(                  d| dd| dd| dd	| dd
| ddd|j*                   	       ||fS # t,        $ r}	Y d }	~	||fS d }	~	ww xY w)Nr  r   r   )r   z4You have a new reimbursement request to approve for .uf   لديك طلب استرداد نفقات جديد يتعين عليك الموافقة عليه لـ uB   Sie haben einen neuen Rückerstattungsantrag zur Genehmigung für z:Tienes una nueva solicitud de reembolso para aprobar para uB   Vous avez une nouvelle demande de remboursement à approuver pour informationz/payroll/view-reimbursement?id=)	recipientverbverb_arverb_deverb_esverb_friconredirect)rD   r   filesrw   
attachemntr    r  r   r   rV   other_attachmentsr   r   rX   rT   rE   r   sendemployee_work_inforeporting_manager_idemployee_user_idr   r   )r\   r   is_newr  multiple_attachment_idsattachemntsfile_instancerD   empr   r_   s             r?   r   zReimbursementForm.save  s   ]]%%%
"$::l+**,,\:K'21~DMM$&(#) A
 ? A+5(""$'..}/?/?@	A
 7<'&""&&(?@""dll=&A"B	..CCTTOPSuTUV E  FI  EJ  JK  L`ad`eefgXY\X]]^_`ad`eefg&>x{{mL  $$  	$$	s   AE' '	E=8E=r   )r2   r3   r4   r5   r   r@   r   r  rz  rW   rf   ru   r   r   r   r   r   s   @r?   rl  rl    s[     0L   
 t!	U'n@D$%4 $%# $% $%r>   rl  c                   $    e Zd ZdZ G d d      Zy)ConditionFormz!
    Multiple condition form
    c                       e Zd ZeZg dZy)ConditionForm.Metar   N)r2   r3   r4   r   r8   r9   r=   r>   r?   r@   r    s    
r>   r@   Nr   r=   r>   r?   r  r    s    
 
r>   r  c                   &    e Zd Z G d d      Zd Zy)PayslipAutoGenerateFormc                       e Zd ZeZg dZy)PayslipAutoGenerateForm.Meta)generate_day
company_idauto_generateN)r2   r3   r4   r   r8   r9   r=   r>   r?   r@   r    s    #@r>   r@   c                 &    d| i}t        d|      }|S ra   r   rc   s      r?   rf   zPayslipAutoGenerateForm.as_p  rg   r>   N)r2   r3   r4   r@   rf   r=   r>   r?   r  r    s    A Ar>   r  )Tr5   r   loggingr   typingr   djangor   django.appsr   django.template.loaderr   django.utilsr   django.utils.translationr	   r   payroll.models.modelsr6   
base.formsr
   r   base.methodsr   employee.filtersr   employee.modelsr   r   horillar   horilla.methodsr   horilla_widgets.formsr   r   2horilla_widgets.widgets.horilla_multi_select_fieldr   &horilla_widgets.widgets.select_widgetsr   notifications.signalsr   payroll.modelsr   r7   r   r   r   r   r   r   r   r   r    payroll.widgetsr!   r%   	getLoggerr2   r   r#   r   r   r   r   r  r  r  r  django.core.exceptionsr|   r  r  r8  r;  rE  rZ  ClearableFileInputr`  	FileFieldrc  rl  r  r  r=   r>   r?   <module>r     sa  
       3 ! 6  & ( + 0 ' 3 D V K ( /
 
 
 8			8	$D#EOO D#N_#EOO _#D4
) 4
nG
+ G
T)  AjM"1W:1\?#:a()!K.!!K.!!K.!)q{4anE11X;?91=M;NO:An<MN:An<MN2AiLA0!G*=/6;%,ejj " Xejj . 3?5V 5Vp99 9#9 #L=i =@
O 
>#00 #- -\%	 \%~
I 
i r>   