
    vgR                     L   d 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 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  G d dej@                        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

forms.py
    )date)Any)forms)widgetsrender_to_string)gettext_lazy)Form)reload_queryset)MultipleFileField)Employee)horilla_middlewares)get_active_employees)ContractEncashmentGeneralSettingsPayrollGeneralSettingReimbursementFileReimbursementrequestCommentc                   "     e Zd ZdZ fdZ xZS )	ModelFormz1
    ModelForm override for additional style
    c                 p   t        |   |i | t        | j                         t	        t
        j                  dd       }| j                  j                         D ]I  \  }}|j                  }t        |t        j                        rt        j                         |_        t        |t        j                        r)|j                  j                  j!                  ddi       net        |t        j"                  t        j$                  t        j&                  f      r>t)        |j*                        }|j                  j                  j!                  d|d       nt        |t        j,                  f      r(|j                  j                  j!                  ddi       nt        |t        j.                        r@t)        |j*                        }|j                  j                  j!                  d|ddd	       nQt        |t        j0                  t        j2                  f      r'|j                  j                  j!                  dd
i       	 |j4                  j6                  | j                  d   _        	 |j4                  j6                  j8                  | j                  d   _        L y #  Y ;xY w#  Y ZxY w)Nrequestclassz oh-input oh-calendar-input w-100oh-input w-100)r   placeholderz/oh-select oh-select-2 select2-hidden-accessible   (   )r   r   rowscolszoh-switch__checkboxemployee_id
company_id)super__init__r   fieldsgetattrr   _thread_localsitemswidget
isinstancer   	DateInputr   todayinitialattrsupdateNumberInput
EmailInput	TextInputtranslabelSelectTextareaCheckboxInputCheckboxSelectMultipleuseremployee_getget_company)	selfargskwargsr   _fieldr(   r3   	__class__s	           '/var/www/horilla/payroll/forms/forms.pyr#   zModelForm.__init__!   s   $)&)$-<<iN))+ 0	HAu\\F&5??4 $

&5??4""))74V*WX**E,<,<eooN ekk*"")).uE FU\\O4""))OP FU^^5ekk*""))!1', ! "	 ''00 ""))74I*JK5<\\5N5NM*2LL--99 L)1Y0	Ps   
(J)32J0)J-0J5)__name__
__module____qualname____doc__r#   __classcell__r@   s   @rA   r   r      s    4 4    r   c                        e Zd ZdZ ed      Z ej                         Z ej                  d      Z	 G d d      Z
 fdZd Zd	 Z xZS )
ContractFormz
    ContactForm
    r   F)requiredc                       e Zd ZdZdZdgZeZy)ContractForm.Meta3
        Meta class for additional options
        __all__	is_activeN)rB   rC   rD   rE   r$   excluder   model rH   rA   MetarM   a   s    	 
 rH   rT   c                 t   t        |   |i | | j                  d   j                  j                  j                  ddi       t        j                  dddd      | j                  d	   _        t        j                  dddd      | j                  d
   _        | j                  d   j                  j                  j                  ddi       | j                  rg| j                  j                  rQ| j                  | j                        }| j                  d   j                  j                  j                  d|dd       t        j                  j                         }|r/| j                  j                  |j                  | j                  d<   d| j                  d   j                  j                  d<   y )Nr    onchangezcontractInitial(this)r   r   zSelect a date)typer   r   r-   contract_start_datecontract_end_datecontract_statusr   z	oh-selectthisbeforebegin)z	hx-targetzhx-postzhx-swapnotice_period_in_days.jpg, .jpeg, .png, .pdfcontract_documentaccept)r"   r#   r$   r(   r-   r.   r   r*   instancepkget_dynamic_hx_post_urlr   objectsfirstnotice_periodr,   )r;   r<   r=   dynamic_urlrf   r@   s        rA   r#   zContractForm.__init__l   s   $)&)M"))//6601	
 5<4E4E).5
)*1 3:2C2C).3
'(/ 	%&--33::	

 ==T]]--66t}}EKKK)*1177>>!'*, &--335T]]%%-494G4GDLL01 & 	'(//55	
rH   c                 &    d| i}t        d|      }|S )S
        Render the form fields as HTML table rows with Bootstrap styling.
        formzcontract_form.htmlr   r;   context
table_htmls      rA   as_pzContractForm.as_p   s      4.%&:GD
rH   c                      d|j                    S )Nz /payroll/update-contract-status/)rc   )r;   rb   s     rA   rd   z$ContractForm.get_dynamic_hx_post_url   s    1(++??rH   )rB   rC   rD   rE   r2   verbose_namer   	DateFieldrY   rZ   rT   r#   ro   rd   rF   rG   s   @rA   rJ   rJ   X   sO     $L)%//+'7	 	&&P@rH   rJ   c                   $    e Zd ZdZ G d d      Zy)ReimbursementRequestCommentFormz.
    ReimbursementRequestCommentForm form
    c                       e Zd ZdZeZdZy)$ReimbursementRequestCommentForm.MetarN   )commentN)rB   rC   rD   rE   r   rR   r$   rS   rH   rA   rT   rv      s    	 ,rH   rT   N)rB   rC   rD   rE   rT   rS   rH   rA   rt   rt      s     rH   rt   c                   V     e Zd ZdZdZ G d d      Z fdZd Zd
dede	f fd	Z
 xZS )reimbursementCommentFormz2
    Reimbursement request comment model form
    zAdd Commentc                       e Zd ZeZdZy)reimbursementCommentForm.MetarO   N)rB   rC   rD   r   rR   r$   rS   rH   rA   rT   r{      s    +rH   rT   c                     t        |   |i | t        d      | j                  d<   d| j                  d   _        d| j                  d   j
                  j                  d<   y )Nfiles)r3   Fr_   ra   )r"   r#   r   r$   rK   r(   r-   )r;   r<   r=   r@   s      rA   r#   z!reimbursementCommentForm.__init__   sX    $)&)0w?G(-G%6OG##))(3rH   c                 &    d| i}t        d|      }|S )rj   rk   zcommon_form.htmlr   rl   s      rA   ro   zreimbursementCommentForm.as_p   s      4.%&8'B
rH   commitreturnc                    g }d }| j                   j                  d      rt| j                   j                  d      }|d   | j                  _        g }|D ]>  }t	               }||_        |j                          |j                  |j                         @ t        |   |      }|r |j                   j                  |  ||fS )Nr}   r   )r}   getlistrb   
attachemntr   filesaveappendrc   r"   add)r;   r   multiple_files_idsr}   r   file_instancerb   r@   s          rA   r   zreimbursementCommentForm.save   s    ::g&JJ&&w/E',QxDMM$!## <
 1 3%/"""$"))-*:*:;	<
 7<'HNN 23rH   ).)rB   rC   rD   rE   rq   rT   r#   ro   boolr   r   rF   rG   s   @rA   ry   ry      s<     !L P4 #  rH   ry   c                        e Zd Z G d d      Zy)EncashmentGeneralSettingsFormc                       e Zd ZeZdZy)"EncashmentGeneralSettingsForm.MetarO   N)rB   rC   rD   r   rR   r$   rS   rH   rA   rT   r      s    )rH   rT   N)rB   rC   rD   rT   rS   rH   rA   r   r      s     rH   r   c            
       Z   e Zd Zg dZ ej
                  d ej                  ddd            Z ej
                  d ej                  ddd            Z ej                  de
j                  j                         D  cg c]  }|j                  |j                         f  c}} ej                        Z ej                  de	      Z ej                  d ed
      d   D  cg c]  }|j                  |j                         f  c}} ej                        Zy
c c}} w c c}} w )DashboardExport)) r   )draftDraft)review_ongoingzReview Ongoing)	confirmed	Confirmed)paidPaidFr   r   )rW   r   rX   )rK   r(   )rK   choicesr(   )rK   r   Nr   )rB   rC   rD   status_choicesr   rr   r*   
start_dateend_dateChoiceFieldr   re   allidget_full_nameSelectMultiple	employeesstatusr   contributions).0emps   00rA   r   r      s    N !uf?O%PQJ uuf?O%PQH "!!:B:J:J:N:N:PQ3#&&#++-.Q##I
 U~FF%E%% ,D12HI
 VVS&&()
 ##M	 R
s   #D!)#D'r   N)&rE   datetimer   typingr   djangor   django.formsr   django.template.loaderr   django.utils.translationr	   r2   
base.formsr
   base.methodsr   employee.formsr   employee.modelsr   horillar   payroll.context_processorsr   payroll.models.modelsr   r   r   r   r   r   rJ   rt   ry   r   r   rS   rH   rA   <module>r      s         3 :  ( , $ ' ; 9 9xE@9 E@Pi (y (VI d rH   