
    si                     `   d Z ddl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
 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 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( ddl)m*Z* ddl+m,Z,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z< d ed      fd ed      fgZ=dZ> G d d ej.                        Z? G d! d"e?      Z@ G d# d$e?      ZA G d% d&e      ZB G d' d(e      ZC G d) d*e      ZD G d+ d,e-      ZE G d- d.e      ZF G d/ d0e      ZG G d1 d2e      ZHg d3ZI G d4 d5ej                        ZK G d6 d7ej                        ZL G d8 d9e      ZM G d: d;e      ZN G d< d=ej                        ZO G d> d?ej                        ZP G d@ dAe,      ZQ G dB dCe      ZR G dD dEe      ZS G dF dGe      ZT G dH dIe      ZU G dJ dKe      ZV e
j                  dL      r4dMdNlXmYZYmZZZ  G dO dPe      Z[ G dQ dRej                        Z\ G dS dTe      Z]yy)Uz
This module provides Worksol ModelForms for creating and managing leave-related data,
including leave type, leave request, leave allocation request, holidays and company leaves.
    N)datedatetime)Any)forms)apps)ValidationError)Q)	TextInputrender_to_string)gettext_lazy)	ModelForm)filtersubordinatesemployeemodelreload_queryset)CompanyLeavesHolidays)EmployeeFilter)MultipleFileField)Employee)horilla_middlewares)_thread_locals)HorillaFormView)HorillaFormHorillaModelForm)HorillaMultiSelectField)HorillaMultiSelectWidget)get_leave_day_attendance)AvailableLeaveLeaveAllocationRequestLeaveallocationrequestCommentLeaveRequestLeaverequestCommentLeaverequestFile	LeaveTypeRestrictLeaveyesYesnoNog     j@c                        e Zd Z fdZ xZS )ConditionFormc                    t        |   |i | t        t        j                  dd       }t        | j                         | j                  j                         D ]  \  }}|j                  }t        |t        j                  f      rd|j                  j                  d<   Ht        |t        j                        rA|j                  j                  j                  ddi       t        j                          |_        t        |t        j$                  t        j&                  t        j(                  f      r4|j                  j                  j                  d|j*                  d       t        |t        j,                        r6|j                  j                  j                  d|j*                  ddd	       `t        |t        j.                  t        j0                  f      s|j                  j                  j                  dd
i        	 |j2                  j4                  | j                  d   _        	 |j2                  j4                  j6                  | j                  d   _        y #  Y 8xY w#  Y y xY w)Nrequestzjwidth:100%; height:50px;border: 1px solid hsl(213deg,22%,84%);border-radius: 0rem;padding: 0.8rem 1.25rem;styleclassoh-input w-100)r/   placeholder   (   )r/   r1   rowscolszoh-switch__checkboxemployee_id
company_id)super__init__getattrr   r   r   fieldsitemswidget
isinstancer   Selectattrs	DateInputupdater   todayinitialNumberInput
EmailInputr
   labelTextareaCheckboxInputCheckboxSelectMultipleuseremployee_getget_company)selfargskwargsr-   
field_namefieldr=   	__class__s          //var/www/python-projects/worksol/leave/forms.pyr9   zConditionForm.__init__0   s   $)&)-<<iN$!%!2!2!4  	LJ\\F&5<</2 A ""7+ FU__6""))74D*EF $

**E,<,<eooN "")).u{{K FU^^5""))!1',{{ ! "	 ''00 ""))74I*JKA 	LB	181J1JDKK&.	070I0I0U0UDKK%-			s   (I. ;2I5 .I25I9)__name__
__module____qualname__r9   __classcell__rS   s   @rT   r+   r+   /   s    - -    r+   c            
            e Zd Z eej
                  j                          ededdd       e	d            Z
 G d d	      Z fd
Z fdZ fdZ xZS )LeaveTypeFormemployee-widget-filterfemployee_filters.htmlFfilter_route_namefilter_classfilter_instance_contex_namefilter_template_pathrequiredr   querysetr=   rG   c                       e Zd ZeZdZdgZd ed      iZ e	ddd       e
j                          e
j                          e
j                  d	d
i      dZy)LeaveTypeForm.Meta__all__	is_activenameNamecolorheight:40px;typer.   r@   rq   r   rn   	period_in
total_dayscarryforward_expire_dateN)rU   rV   rW   r$   modelr;   exclude_labelsr
   r   HiddenInputrA   widgets rZ   rT   Metari   n   sh    -AfI
 g%OP***,+%++-(7vv>N(O	
rZ   r~   c                     t         |          }d| j                  v r| j                  d= d| j                  v r| j                  d= |d   st        |d<   d|d<   d|d<   d	|d
<   d	|d<   |S )Nr6   exceed_dayslimit_leaveru   Tresetyearlyreset_based1reset_month	reset_dayr8   cleanerrorsLEAVE_MAX_LIMITrN   cleaned_datarS   s     rT   r   zLeaveTypeForm.clean|   s~    w}DKK'M*DKK'M*M*)8L&$(L!*2L'*-L'(+L%rZ   c                     t        |   |i |}| j                  j                  d      x}rN|D ]H  }t        j
                  j                  |      }t        |||j                        j                          J y y )Nr6   id)leave_type_idr6   available_days)	r8   savedatagetlistr   objectsgetr   ru   )rN   rO   rP   
leave_type	employeesr6   employeerS   s          rT   r   zLeaveTypeForm.save   s}    W\4262
		))-8898( #++//;/?", (#-#8#8 $& 9rZ   c                 $    t        |   |i | y N)r8   r9   rN   rO   rP   rS   s      rT   r9   zLeaveTypeForm.__init__   s    $)&)rZ   )rU   rV   rW   r   r   r   allr   r   ry   r6   r~   r   r   r9   rX   rY   s   @rT   r\   r\   `   s]    )!!%%''6'(+!8
 
m
K
 
	* *rZ   r\   c                   F     e Zd Z fdZ G d d      Z fdZ fdZ xZS )UpdateLeaveTypeFormc                    t        t        | 
  |i | g }| j                  j                  j                         D ]W  \  }}||dk(  s|j                  d      r(t        j                  dd|      }|j                  |       |j                  |       Y t        | j                               D ]t  \  }}t        | j                  j                               |   |v s/d|j                  j                   j"                  d<   d|j                  j                   j"                  d<   v | j                  j$                  x}	r|	| j                  d<   y y )	N _idz_id$zwdisplay:none;width:100%; height:50px;border: 1px solid hsl(213deg,22%,84%);border-radius: 0rem;padding: 0.8rem 1.25rem;r.   Tzdata-hiddenrv   )r8   r   r9   instance__dict__r<   endswithresubappend	enumeratevisible_fieldslistr;   keysrR   r=   r@   rv   )rN   rO   rP   empty_fieldsrQ   field_valueforeign_key_field_nameindexvisibleexpire_daterS   s             rT   r9   zUpdateLeaveTypeForm.__init__   s<   !414B6B'+}}'='='C'C'E 	0#J"kR&7&&u--/VVFB
-K* ''(>?##J/	0 ((;(;(=> 	ANE7DKK$$&'.,> N $$**73 =A$$**=9	A --@@@;@6ADKK23 ArZ   c                       e Zd ZeZdZdgZ eddd       ej                          ej                          ej                  ddi      d	Zy
)UpdateLeaveTypeForm.Metarj   rk   rn   ro   rp   rr   rq   r   rs   N)rU   rV   rW   r$   rw   r;   rx   r
   r   r{   rA   r|   r}   rZ   rT   r~   r      sV    -g%OP***,+%++-(7vv>N(O	
rZ   r~   c                     t         |          }d| j                  v r| j                  d= |d   st        |d<   d|d<   d|d<   d|d	<   d|d
<   |S )Nr   r   ru   Tr   r   r   r   r   r   r   r   s     rT   r   zUpdateLeaveTypeForm.clean   sf    w}DKK'M*M*)8L&$(L!*2L'*-L'(+L%rZ   c                 $    t        |   |i |}y r   )r8   r   )rN   rO   rP   r   rS   s       rT   r   zUpdateLeaveTypeForm.save   s    W\4262
rZ   )rU   rV   rW   r9   r~   r   r   rX   rY   s   @rT   r   r      s"    B*	
 	
3 3rZ   r   c                        e Zd ZddiZ ej
                   ej                  ddi            Z ej
                   ej                  ddi            Z fdZ	d Z
 G d	 d
      Z xZS )LeaveRequestCreationFormdescription   rq   r   rr   r=   c                    t        |   |i | d| j                  d   j                  j                  d<   t        t        d      }| j                  d   j                  j                  j                  dddd	d
d       | j                  d   j                  j                  j                  dd	ddd       | j                  d   j                  j                  j                  dddd	d
d       y )N.jpg, .jpeg, .png, .pdf
attachmentacceptr-   r   z#leaverequestForm#createTitleafterendchange%/leave/employee-available-leave-count
hx-include	hx-targethx-swap
hx-triggerhx-getr6   #id_leave_type_id_parent_div	innerHTMLz=/leave/get-employee-leave-types?form=LeaveRequestCreationFormr   r   r   r   
start_date)r8   r9   r;   r=   r@   r:   r   rB   )rN   rO   rP   r-   rS   s       rT   r9   z!LeaveRequestCreationForm.__init__   s    $)&);TL!((..x8.)4 	O$++11881+%&A	
 	M"))//66;&&Y		
 	L!((..551+%&A	
rZ   c                 &    d| i}t        d|      }|S S
        Render the form fields as HTML table rows with Bootstrap styling.
        formhorilla_form.htmlr   rN   rO   rP   context
table_htmls        rT   as_pzLeaveRequestCreationForm.as_p         4.%&97C
rZ   c                       e Zd ZeZg dZy)LeaveRequestCreationForm.Metar6   r   r   start_date_breakdownend_dateend_date_breakdownr   r   NrU   rV   rW   r!   rw   r;   r}   rZ   rT   r~   r         	
rZ   r~   )rU   rV   rW   r5   r   	DateFieldrA   r   r   r9   r   r~   rX   rY   s   @rT   r   r      sb    2D vv>N(OPJuoeooVV<L&MNH'
R
 
rZ   r   c                        e Zd Z ej                   ej
                  ddi            Z ej                   ej
                  ddi            Z fdZd Z	 G d d      Z
 xZS )	LeaveRequestUpdationFormrq   r   rr   r   c                 b   t        |   |i | | j                  }|j                  }|j                  }|r|j
                  j                         }t        j                  j                  |j                  dd            }|rL|j                  |j                  dd      vr-|t        j                  j                  |j                        z  }|| j                  d   _        | j                  d   j                  j                  j!                  ddd	d
dd       | j                  d   j                  j                  j!                  dd
dd       d| j                  d   j                  j                  d<   | j                  d   j                  j                  j!                  ddd	d
dd       y )Nr   Tflatid__inr   r   z#leaveRequestUpdateFormz#assinedLeaveAvailableCount	outerHTMLr   r   r   r6   r   z=/leave/get-employee-leave-types?form=LeaveRequestUpdationForm)r   r   r   r   r   r   r   )r8   r9   r   r6   r   available_leaver   r$   r   filtervalues_listr   r;   rg   r=   r@   rB   )	rN   rO   rP   leave_requestr   r   available_leavesassigned_leave_typesrS   s	           rT   r9   z!LeaveRequestUpdationForm.__init__  s   $)&) ,,"00
'77;;=#,#4#4#;#;'33O$3O $< $  jmm3G3S3S4 4T 4  %	(9(9(@(@JMM(@(RR$4HDKK(1O$++11887:&&A	
 	M"))//66;&Y	
 <UL!((..x8L!((..557:&&A	
rZ   c                 &    d| i}t        d|      }|S r   r   r   s        rT   r   zLeaveRequestUpdationForm.as_pE  r   rZ   c                       e Zd ZeZg dZy)LeaveRequestUpdationForm.Meta)r   r6   r   r   r   r   r   r   Nr   r}   rZ   rT   r~   r   M  r   rZ   r~   )rU   rV   rW   r   r   rA   r   r   r9   r   r~   rX   rY   s   @rT   r   r     sX     vv>N(OPJuoeooVV<L&MNH.
`
 
rZ   r   c                       e Zd ZdZ ej
                  ej                  j                         ej                  d      Z
 ej
                  ej                  j                         ej                  d      Z G d d      Zy)AvailableLeaveForma  
    Form for managing available leave data.

    This form allows users to manage available leave data by specifying details such as
    the leave type and employee.

    Attributes:
        - leave_type_id: A ModelChoiceField representing the leave type associated with the available leave.
        - employee_id: A ModelChoiceField representing the employee associated with the available leave.
    N)rg   r=   empty_labelc                       e Zd ZeZg dZy)AvailableLeaveForm.Meta)r   r6   rk   N)rU   rV   rW   r   rw   r;   r}   rZ   rT   r~   r   r  s    >rZ   r~   )rU   rV   rW   __doc__r   ModelChoiceFieldr$   r   r   SelectMultipler   r   r6   r~   r}   rZ   rT   r   r   [  su    	 +E**""&&(##M
 )%((!!%%'##K? ?rZ   r   c            
            e Zd ZdZddiZ eej                  j                          e	de
ddd      d	
      Z G d d      Z fdZ xZS )LeaveOneAssignForma=  
    Form for assigning available leave to employees.

    This form allows administrators to assign available leave to a single employee
    by specifying the employee and setting the is_active flag.

    Attributes:
        - employee_id: A HorillaMultiSelectField representing the employee to assign leave to.
    r6   r   r]   r^   r_   Tr`   r   rf   c                       e Zd ZdZeZddgZy)LeaveOneAssignForm.Meta3
        Meta class for additional options
        r6   rk   NrU   rV   rW   r   r   rw   r;   r}   rZ   rT   r~   r     s    	 -rZ   r~   c                 N    t        |   |i | t        | j                         y r   )r8   r9   r   r;   r   s      rT   r9   zLeaveOneAssignForm.__init__  s!    $)&)$rZ   )rU   rV   rW   r   r5   r   r   r   r   r   r   r6   r~   r9   rX   rY   s   @rT   r   r   w  s`     2D)!!%%''6'(+!8
 
K. .% %rZ   r   c                   $    e Zd ZdZ G d d      Zy)AvailableLeaveUpdateForma  
    Form for updating available leave data.

    This form allows users to update available leave data by modifying fields such as
    available_days, carryforward_days, and is_active.

    Attributes:
        - Meta: Inner class defining metadata options.
            - model: The model associated with the form (AvailableLeave).
            - fields: A list of fields to include in the form.
    c                       e Zd ZdZeZg dZy)AvailableLeaveUpdateForm.Metar   )r   carryforward_daysrk   Nr   r}   rZ   rT   r~   r    s    	 ErZ   r~   NrU   rV   rW   r   r~   r}   rZ   rT   r  r    s    
F FrZ   r  c                   .    e Zd ZdZdddZ G d d      Zy)CompanyLeaveForma  
    Form for managing company leave data.

    This form allows users to manage company leave data by including all fields from
    the CompanyLeaves model except for is_active.

    Attributes:
        - Meta: Inner class defining metadata options.
            - model: The model associated with the form (CompanyLeaves).
            - fields: A special value indicating all fields should be included in the form.
            - exclude: A list of fields to exclude from the form (is_active).
    r   )based_on_weekbased_on_week_dayc                       e Zd ZdZeZdZdgZy)CompanyLeaveForm.Metar   rj   rk   N)rU   rV   rW   r   r   rw   r;   rx   r}   rZ   rT   r~   r    s    	 -rZ   r~   N)rU   rV   rW   r   r5   r~   r}   rZ   rT   r	  r	    s      b9D   rZ   r	  c                       e Zd Z ej                   ej
                  ddi            Z ej                   ej
                  ddi            Z ej                   e	d      ej                        Z fdZd Z G d	 d
      Z xZS )UserLeaveRequestFormrq   r   rr   r   DescriptionrG   r=   c                 p   |j                  dd       }|j                  dd       }t        t        |   |i | d| j                  d   j
                  j                  d<   |r_|j                  j                         }t        j                  j                  |j                  dd      	      }|| j                  d   _        |rut        j                  j                  |d   j                  
      | j                  d   _        |d   j                  | j                  d   _        d | j                  d   _        y y )NrD   r   r   r   r   r   Tr   r   r   )popr8   r  r9   r;   r=   r@   r   r   r$   r   r   r   rg   r   rD   r   )rN   rO   rP   r   r   r   r   rS   s          rT   r9   zUserLeaveRequestForm.__init__  s   ZZ	40
::j$/"D2DCFC;TL!((..x8'77;;=#,#4#4#;#;'33O$3O $< $  5IDKK(14=4E4E4L4Lo.11 5M 5DKK(1 4>o3N3Q3QDKK(07;DKK(4 rZ   c                 &    d| i}t        d|      }|S r   r   r   s        rT   r   zUserLeaveRequestForm.as_p  r   rZ   c                   B    e Zd ZdZeZg dZd ej                         iZ	y)UserLeaveRequestForm.Metar   r   r6   N
rU   rV   rW   r   r!   rw   r;   r   r{   r|   r}   rZ   rT   r~   r    s/    	 	
 ,5,,.
rZ   r~   )rU   rV   rW   r   r   rA   r   r   	CharFieldry   rH   r   r9   r   r~   rX   rY   s   @rT   r  r    sr     vv>N(OPJuoeooVV<L&MNH!%//-(8PK<$
 
rZ   r  )r   approved_available_daysapproved_carryforward_days
created_atr   c            
       *   e Zd 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 )AvailableLeaveColumnExportForma  
    Form for selecting columns to export in available leave data.

    This form allows users to select specific columns from the AvailableLeave model
    for export. The available columns are dynamically generated based on the
    model's meta information, excluding specified excluded_fields.

    Attributes:
        - model_fields: A list of fields in the AvailableLeave model.
        - field_choices: A list of field choices for the form, consisting of field names
          and their verbose names, excluding specified excluded_fields.
        - selected_fields: A MultipleChoiceField representing the selected columns
          to be exported.
    verbose_name)r6   r   r   r  total_leave_dayschoicesr=   rD   N)rU   rV   rW   r   r   _meta
get_fieldsmodel_fieldshasattrrl   excluded_fieldsr  field_choicesr   MultipleChoiceFieldrJ   selected_fields.0rR   r%  r&  s   0000rT   r  r  
  s     "''224L " 5.)ejj.O 
U''(M
 0e//++

O   =B
r  c                       e Zd ZdZ ej
                   ed       ej                  ddd            Z G d d	      Z	y
)
RejectFormz
    Form for rejecting a leave request.

    This form allows administrators to provide a rejection reason when rejecting
    a leave request.

    Attributes:
        - reason: A CharField representing the reason for rejecting the leave request.
    Rejection Reason   p-4 oh-input w-100r4   r/   rr   r  c                       e Zd ZdZeZdgZy)RejectForm.Metar   reject_reasonN)rU   rV   rW   r   r!   rw   r;   r}   rZ   rT   r~   r4  =  s    	 !"rZ   r~   N
rU   rV   rW   r   r   r  ry   rH   reasonr~   r}   rZ   rT   r.  r.  -  s@     U__"#u~~Q9M$NOF
# #rZ   r.  c                        e Zd ZddiZ ej
                   ej                  ddi            Z ej
                   ej                  ddi            Zd Z	 fdZ
 G d	 d
      Z xZS )UserLeaveRequestCreationFormr   r   rq   r   rr   r   c                 &    d| i}t        d|      }|S r   r   r   s        rT   r   z!UserLeaveRequestCreationForm.as_pK  r   rZ   c                    |j                  dd       }t        |   |i | d| j                  d   j                  j
                  d<   |r_|j                  j                         }t        j                  j                  |j                  dd            }|| j                  d   _        | j                  d   j                  j
                  j                  d	d
dddd       || j                  d   _        y )Nr   r   r   r   r   Tr   r   z#myleaverequestFormr   r   r   r   r   r6   )r  r8   r9   r;   r=   r@   r   r   r$   r   r   r   rg   rB   rD   )rN   rO   rP   r   r   r   rS   s         rT   r9   z%UserLeaveRequestCreationForm.__init__S  s    ::j$/$)&);TL!((..x8'77;;=#,#4#4#;#;'33O$3O $< $  5IDKK(1O$++11883+%&A	
 .6M"*rZ   c                   b    e Zd ZdZeZg dZ ej                          ej                         dZ	y)!UserLeaveRequestCreationForm.Metar   )	r   r6   r   r   r   r   r   r   requested_days)r6   r>  Nr  r}   rZ   rT   r~   r=  i  s:    	 

 -5,,./e//1
rZ   r~   )rU   rV   rW   r5   r   r   rA   r   r   r   r9   r~   rX   rY   s   @rT   r9  r9  F  sa    2D vv>N(OPJuoeooVV<L&MNH6,
 
rZ   r9  c                   2    e Zd ZdZddiZd Z G d d      Zy)LeaveAllocationRequestForma=  
    Form for creating a leave allocation request.

    This form allows users to create a leave allocation request by specifying
    details such as leave type, employee, requested days, description, and attachment.

    Methods:
        - as_p: Render the form fields as HTML table rows with Bootstrap styling.
    r   r   c                 &    d| i}t        d|      }|S r   r   r   s        rT   r   zLeaveAllocationRequestForm.as_p  r   rZ   c                       e Zd ZdZeZg dZy)LeaveAllocationRequestForm.Metar   )r   r6   r>  r   r   N)rU   rV   rW   r   r   rw   r;   r}   rZ   rT   r~   rC    s    	 '
rZ   r~   N)rU   rV   rW   r   r5   r   r~   r}   rZ   rT   r@  r@    s"     2D
 
rZ   r@  c                       e Zd ZdZ ej
                   ed       ej                  ddd            Z G d d	      Z	y
) LeaveAllocationRequestRejectForma  
    Form for rejecting a leave allocation request.

    This form allows administrators to provide a rejection reason when rejecting
    a leave allocation request.

    Attributes:
        - reason: A CharField representing the reason for rejecting the leave allocation request.
    r/  r0  r1  r2  rr   r  c                       e Zd ZeZdgZy)%LeaveAllocationRequestRejectForm.Metar5  N)rU   rV   rW   r   rw   r;   r}   rZ   rT   r~   rG    s    &!"rZ   r~   Nr6  r}   rZ   rT   rE  rE    s@     U__"#u~~Q9M$NOF
# #rZ   rE  c            
       *   e Zd 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 )LeaveRequestExportForma  
    Form for selecting fields to export in a leave request export.

    This form allows users to select specific fields from the LeaveRequest model
    for export. The available fields are dynamically generated based on the
    model's meta information, excluding certain fields specified in 'excluded_fields'.

    Attributes:
        - model_fields: A list of fields in the LeaveRequest model.
        - field_choices: A list of field choices for the form, consisting of field names
          and their verbose names, excluding specified excluded_fields.
        - selected_fields: A MultipleChoiceField representing the selected fields
          to be exported.
    r  )	r6   leave_type_Assignidr   r   r   r   r>  r   statusr   N)rU   rV   rW   r   r!   r"  r#  r$  r%  rl   r&  r  r'  r   r(  rJ   r)  r*  s   0000rT   rI  rI    s      %%002L " 5.)ejj.O 
U''(M 0e//++

Or,  rI  c            
           e Zd ZdZ ej
                  ej                  j                          ej                  ddd      ddd	      Z
 eej                  j                          ed
eddd      d      Z fdZ fdZ xZS )AssignLeaveFormz
    Form for Payslip
    zoh-select oh-select-2 mb-2T)r/   re   rr   N
Leave TypeF)rg   r=   r   rG   re   r]   r^   r_   r`   r   rf   c                     t         |          }|j                  d      }|j                  d      }|st        j                  ddi      |st        j                  ddi      |S )Nr6   r   zThis field is required)r8   r   r   r   r   )rN   r   r6   r   rS   s       rT   r   zAssignLeaveForm.clean  sh    w}"&&}5$((9''8P(QRR'':R(STTrZ   c                    t        |   |i | t        | j                         | j                  d   j                  j
                  j                  dt        j                         d      f d| j                  d   _	        y )Nr6   T)re   r   rN  r   )
r8   r9   r   r;   r=   r@   rB   uuiduuid4rG   r   s      rT   r9   zAssignLeaveForm.__init__  sj    $)&)$M"))//66TZZ\2	
 	 .:O$*rZ   )rU   rV   rW   r   r   r   r$   r   r   r   r   r   r   r   r   r6   r   r9   rX   rY   s   @rT   rM  rM    s     +E**""&&(#u##8dK
 M *!!%%''6'(+!8
 
K	: :rZ   rM  c                   $    e Zd ZdZ G d d      Zy)LeaverequestcommentFormz"
    LeaverequestComment form
    c                       e Zd ZdZeZdZy)LeaverequestcommentForm.Metar   commentNrU   rV   rW   r   r"   rw   r;   r}   rZ   rT   r~   rV    s    	 $rZ   r~   Nr  r}   rZ   rT   rT  rT         rZ   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 )LeaveCommentForm*
    Leave request comment model form
    Add Commentc                       e Zd ZdZeZdZy)LeaveCommentForm.Metar   rj   NrY  r}   rZ   rT   r~   r`  $  s    	 $rZ   r~   c                     t        |   |i | t        d      | j                  d<   d| j                  d   j                  j
                  d<   d| j                  d   _        y )NfilesrG   r   r   F)r8   r9   r   r;   r=   r@   re   r   s      rT   r9   zLeaveCommentForm.__init__,  sX    $)&)0w?G6OG##))(3(-G%rZ   c                 &    d| i}t        d|      }|S r   r   zcommon_form.htmlr   rN   r   r   s      rT   r   zLeaveCommentForm.as_p3        4.%&8'B
rZ   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 Nrb  r   rb  r   r   
attachemntr#   filer   r   pkr8   addrN   rh  multiple_files_idsrb  rm  file_instancer   rS   s          rT   r   zLeaveCommentForm.save;      ::g&JJ&&w/E',QxDMM$!## <
 0 2%/"""$"))-*:*:;	<
 7<'HNN 23rZ   .rU   rV   rW   r   r  r~   r9   r   boolr   r   rX   rY   s   @rT   r\  r\    s;     !L .4 #  rZ   r\  c                   $    e Zd ZdZ G d d      Zy)!LeaveallocationrequestcommentFormz.
    Leave Allocation Requestcomment form
    c                       e Zd ZdZeZdZy)&LeaveallocationrequestcommentForm.Metar   rW  NrU   rV   rW   r   r    rw   r;   r}   rZ   rT   r~   r{  R  s    	 .rZ   r~   Nr  r}   rZ   rT   ry  ry  M  rZ  rZ   ry  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 )LeaveAllocationCommentFormr]  r^  c                       e Zd ZdZeZdZy)LeaveAllocationCommentForm.Metar   rj   Nr|  r}   rZ   rT   r~   r  b  s    	 .rZ   r~   c                 ~    t        |   |i | t        d      | j                  d<   d| j                  d   _        y )Nrb  rc  F)r8   r9   r   r;   re   r   s      rT   r9   z#LeaveAllocationCommentForm.__init__j  s9    $)&)0w?G(-G%rZ   c                 &    d| i}t        d|      }|S re  r   rf  s      rT   r   zLeaveAllocationCommentForm.as_po  rg  rZ   rh  ri  c                    g }d }| j                   j                  d      rt| j                   j                  d      }|d   | j                  _        g }|D ]>  }t	               }||_        |j                          |j                  |j                         @ t        |   |      }|r |j                   j                  |  ||fS rk  rl  rq  s          rT   r   zLeaveAllocationCommentForm.savew  rt  rZ   ru  rv  rY   s   @rT   r~  r~  [  s;     !L .
4 #  rZ   r~  c                        e Zd ZdddZ ej
                   ej                  ddi            Z ej
                   ej                  ddi            Zd Z	 G d d	      Z
 fd
Z xZS )RestrictLeaveFormr   )titler   rq   r   rr   r   c                     | j                   j                  d      }| j                   j                  d      }|r|r||k  rt        t        d            |S )Nr   r   z3End date should not be earlier than the start date.)r   r   r   ry   )rN   r   r   s      rT   clean_end_datez RestrictLeaveForm.clean_end_date  sW    &&**<8
$$((4(x*'<!GH  rZ   c                       e Zd ZeZdZdgZy)RestrictLeaveForm.Metarj   rk   N)rU   rV   rW   r%   rw   r;   rx   r}   rZ   rT   r~   r    s    -rZ   r~   c                    t        t        | 
  |i | d| j                  d   j                  j
                  d<   t        j                  ddd      | j                  d   _        t        j                  ddd      | j                  d   _        | j                  d	   j                  j
                  j                  d
dddd       y )Nr  autocompleter   r0   )rq   r/   rr   r   r   
departmentz#leaveRestrictFormz#restrictLeaveJobPositionr   z!/leave/get-restrict-job-positions)r   r   r   r   )	r8   r  r9   r;   r=   r@   r   rA   rB   r   s      rT   r9   zRestrictLeaveForm.__init__  s    /@@<CG##)).9+0??!,<=,
L!( */!,<=*
J& 	L!((..5528&=		
rZ   )rU   rV   rW   r5   r   r   rA   r   r   r  r~   r9   rX   rY   s   @rT   r  r    sn    +D uff%56J uuff%56H	   

 
rZ   r  
attendance   )CompensatoryLeaveRequestCompensatoryLeaverequestCommentc                   R     e Zd ZdZddddZ G d d      Z fdZd Z fdZ xZ	S )	CompensatoryLeaveFormaU  
        Form for creating a leave allocation request.

        This form allows users to create a leave allocation request by specifying
        details such as leave type, employee, requested days, description, and attachment.

        Methods:
            - as_p: Render the form fields as HTML table rows with Bootstrap styling.
        r   )attendance_idr   r6   c                   B    e Zd ZdZ ej
                  d      ZeZg dZ	y)CompensatoryLeaveForm.Meta;
            Meta class for additional options
            T)re   )r6   r  r   N)
rU   rV   rW   r   r   r(  r  r  rw   r;   r}   rZ   rT   r~   r    s'     6E55tDM,EFrZ   r~   c                    t        t        | 
  |i | t        t        j
                  dd       }d }| j                  r| j                  j                  }|rtt        |d      rht        |j                  d      rR|j                  j                  }t        ||      }t        |j                  dd            }|| j                  d   _        t!        |t"        j$                  j'                  d	            t"        j$                  j'                  |j                  
      z  j)                         }|| j                  d   _        | j                  d   j,                  j.                  j1                  ddddd       y )Nr-   rK   rL   )comp_idr   attendance_dater  T)rk   )employee_user_idr6   z#dynamic_field_attendance_idr   r   z!/leave/get-leave-attendance-datesr   )r8   r  r9   r:   r   r   r   r   r%  rK   rL   r   r   r   r;   r!  r   r   r   r   distinctrg   r=   r@   rB   )
rN   rO   rP   r-   instance_idr   holiday_attendanceattendance_datesrg   rS   s
            rT   r9   zCompensatoryLeaveForm.__init__  sM   '7HH1@@)TRGK}}"mm..GV,GLL.9"<<44%=k&" $(&2249JK$  8HO,4/X--44t4D ""))7<<)HI hj  3;DKK&/KK&--33::!?"**A	rZ   c                 &    d| i}t        d|      }|S )z[
            Render the form fields as HTML table rows with Bootstrap styling.
            r   r   r   r   s        rT   r   zCompensatoryLeaveForm.as_p  s      tnG)*=wGJrZ   c                    t         |          }|j                  d      }|t        |      dk  r t	        j
                  dt        d      i      |j                  d      }d}d }| j                  r| j                  j                  }|D ][  }t        j                  j                  ||      j                  t        |      t        d	      z        j                         sYd
} n |rt	        j
                  ddi      |S )Nr  r  zThis field is required.r6   F)r6   r  r   rejected)rK  Tz;This attendance is already converted to complimentory leave)r8   r   r   lenr   r   ry   r   r   r  r   r   rx   r	   exists)rN   r   r  r   attendance_repeatr  r  rS   s          rT   r   zCompensatoryLeaveForm.clean  s    7=?L(,,_=M$M(:Q(>++$a(A&BC  $''6H %K}}"mm..+ 	
,44;;$,J <  WQ+.*1EEFVX	 )-%	 !++')f 
  rZ   )
rU   rV   rW   r   r5   r~   r9   r   r   rX   rY   s   @rT   r  r    s9    	  
	 	$	L		  	 rZ   r  c                       e Zd ZdZ ej
                   ed       ej                  ddd            Z G d d	      Z	y
)"CompensatoryLeaveRequestRejectForma<  
        Form for rejecting a compensatory leave request.

        This form allows administrators to provide a rejection reason when rejecting
        a compensatory leave request.

        Attributes:
            - reason: A CharField representing the reason for rejecting the  compensatory leave request.
        r/  r0  r1  r2  rr   r  c                       e Zd ZeZdgZy)'CompensatoryLeaveRequestRejectForm.Metar5  N)rU   rV   rW   r  rw   r;   r}   rZ   rT   r~   r  5  s    ,E%&FrZ   r~   Nr6  r}   rZ   rT   r  r  %  s@    	 !&'!5>>=Q(RS

	' 	'rZ   r  c                   $    e Zd ZdZ G d d      Zy)#CompensatoryLeaveRequestcommentFormz*
        LeaverequestComment form
        c                       e Zd ZdZeZdZy)(CompensatoryLeaveRequestcommentForm.Metar  rW  N)rU   rV   rW   r   r  rw   r;   r}   rZ   rT   r~   r  >  s     4E!FrZ   r~   Nr  r}   rZ   rT   r  r  9  s    		" 	"rZ   r  )^r   r   rQ  r   r   typingr   djangor   django.appsr   django.core.exceptionsr   django.db.modelsr	   django.forms.widgetsr
   django.template.loaderr   django.utils.translationr   ry   
base.formsr   BaseModelFormbase.methodsr   r   base.modelsr   r   employee.filtersr   employee.formsr   employee.modelsr   horillar   horilla.horilla_middlewaresr   horilla_views.generic.cbv.viewsr   horilla_widgets.formsr   r   2horilla_widgets.widgets.horilla_multi_select_fieldr   &horilla_widgets.widgets.select_widgetsr   leave.methodsr   leave.modelsr   r   r    r!   r"   r#   r$   r%   CHOICESr   r+   r\   r   r   r   r   r   r  r	  r  r&  Formr  r.  r9  r@  rE  rI  rM  rT  r\  ry  r~  r  is_installedmodelsr  r  r  r  r  r}   rZ   rT   <module>r     s  
 
  #    2  * 3 6 1 I / + , $ ' 6 ; ? V K 2	 	 	 1U8tQtWo
..EOO .b7*M 7*t03- 03fA
} A
HG
} G
T? ?8#%) #%LF} F, }  41
= 1
h UZZ  F# #27
= 7
t!
 !
H#uzz #*%UZZ %P+:k +:\m -} -` + +\*
 *
Z 4\"Qj  j X'UZZ '("m "G #rZ   