
    si"                        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
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lmZ ddlmZmZmZ ddlmZ ddl m!Z!m"Z"m#Z#m$Z$m%Z%  eed       G d de%             Z& eed       G d de#             Z' eed       G d de$             Z( eed       G d de%             Z) eed       G d de!             Z* eed       e ed      d       G d de"                    Z+y) z
Hour account page
    )Any)messages)HttpResponse)render)reversereverse_lazy)method_decorator)gettext_lazy)AttendanceOverTimeFilter)AttendanceOverTimeExportFormAttendanceOverTimeForm)AttendanceOverTime)manager_can_enter)choosesubordinatesfiltersubordinatesis_reportingmanager)login_required)HorillaDetailedViewHorillaFormViewHorillaListViewHorillaNavViewTemplateViewdispatch)namec                       e Zd ZdZdZy)HourAccountz
    Hour Account
    z"cbv/hour_account/hour_account.htmlN)__name__
__module____qualname____doc__template_name     ?/var/www/python-projects/worksol/attendance/cbv/hour_account.pyr   r      s     9Mr#   r   c            
            e Zd ZdZeZeZdeddf fdZ	 f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 ed      df ed      dfgZddddZdZg dZdZ xZS )HourAccountListz
    List view
    kwargsreturnNc                     t        |   di | t        d      | _        d| _        | j
                  j                  j                  d      rd| _        y y )Nattendance-ot-searchzot-table!attendance.add_attendanceovertimehour_actionsr"   )	super__init__r   
search_urlview_idrequestuserhas_permaction_method)selfr'   	__class__s     r$   r.   zHourAccountList.__init__/   sN    "6"!"89!<<%%&IJ!/D Kr#   c                     t         |          }|}|j                  | j                  j                        }t        | j                  |d      }||z  S )N)employee_id__employee_user_idz"attendance.view_attendanceovertime)r-   get_querysetfilterr1   r2   r   )r5   querysetdataaccountsr6   s       r$   r9   zHourAccountList.get_queryset7   sR    7')??ARAR?S%LL$ D
 (""r#   Employeeemployee_idemployee_id__get_avatarMonthget_month_capitalizedYearyearWorked Hoursworked_hourszHours to Validatenot_validated_hrsPending Hourspending_hoursOvertime HoursovertimezNot Approved OT Hoursnot_approved_ot_hrszL
                      style='width:200px !important'
                      zL
                      style='width:180px !important'
                      zF
                   style="width:160px !important"
                   )r?   rL   actionz
                hx-get='{hour_account_detail}?instance_ids={ordered_ids}'
                hx-target="#genericModalBody"
                data-target="#genericModal"
                data-toggle="oh-modal-toggle"
                ))r>   employee_id__get_full_namer@   )rA   rB   )rC   rD   )rE   rF   )rJ   rK      )r   r   r   r    r   modelr   filter_classr   r.   r9   _columnsheader_attrs	row_attrssortby_mappingrecords_per_page__classcell__r6   s   @r$   r&   r&   &   s     E+L0 0 0# 
:'@A	
7,-	
6F	
>	N+	
	!45	
?	_-	
	j)	
"	#%:;	G 
LIN r#   r&   c                   $    e Zd ZdZdZdeddf fdZ ed      Z e	       Z
dZd	Zd
Zd ed      fd ed      fd ed      fd ed      fd ed      fd ed      fd ed      fd ed      fd ed      fd ed      fd ed       fgZ xZS )!HourAccountNavz
    Nav bar
    z&cbv/hour_account/nav_hour_account.htmlr'   r(   Nc                 2   t        |   di | t        d      | _        | j                  j
                  j                  d      st        | j                        sd | _        ndt        d       d| _        t        d      dt        d       d	d
g}| j                  j
                  j                  d      r|j                  t        d      dd
       | j                  j
                  j                  d      st        | j                        sd }|| _        y )Nr*   r+   z
                data-toggle="oh-modal-toggle"
                data-target="#genericModal"
                hx-target="#genericModalBody"
                hx-get="zattendance-overtime-createz"
            Exportzx
                data-toggle="oh-modal-toggle"
                data-target="#hourAccountExport"
                hx-get="zhour-account-exportzs"
                hx-target="#hourAccountExportModalBody"
                style="cursor: pointer;"
                )rM   attrsDeletez
                    onclick="
                    hourAccountbulkDelete();
                    "
                    data-action = "delete"
                    style="cursor: pointer; color:red !important"
                    r"   )r-   r.   r   r/   r1   r2   r3   r   create_attrsr   rR   appendactions)r5   r'   rb   r6   s      r$   r.   zHourAccountNav.__init__o   s   "6"!"89||  ))/
%dll3 $D% &&BCD E	!D H+ !!678 9	
 <<%%&IJNNk	 ||  ))/
%dll3Gr#   Hour Accountz!cbv/hour_account/hour_filter.htmlformz#listContainerr?   r>   monthrA   rD   rC   employee_id__countryCountry5employee_id__employee_work_info__reporting_manager_idzReporting Manager)employee_id__employee_work_info__shift_idShift-employee_id__employee_work_info__work_type_idz	Work Type.employee_id__employee_work_info__department_id
Department0employee_id__employee_work_info__job_position_idzJob Position1employee_id__employee_work_info__employee_type_idzEmployment Type+employee_id__employee_work_info__company_idCompany)r   r   r   r    r!   r   r.   rR   	nav_titler   filter_instancefilter_body_templatefilter_form_context_namesearch_swap_targetgroup_by_fieldsrX   rY   s   @r$   r[   r[   g   s     =M. . .` .!I.0O>%) 
*&	!G*	6	9.C!"	
 
5ajA	8!K.I	91\?K	;Q~=NO	<a@Q>RS	6)EOr#   r[   c                   ,     e Zd ZdZdZdef fdZ xZS )HourExportViewz
    For candidate export
    z!cbv/hour_account/hour_export.htmlr'   c                     t        |   di |}t        j                  j	                         }t
        }t        |      }||d<   ||d<   |S )N)r;   export_fields
export_objr"   )r-   get_context_datar   objectsallr   r   )r5   r'   contextattendancesr{   r|   r6   s         r$   r}   zHourExportView.get_context_data   sQ    '*4V4(004464-{C
#0  *r#   )r   r   r   r    r!   r   r}   rX   rY   s   @r$   ry   ry      s      8M  r#   ry   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gZ	dZ
y)HourAccountDetailViewz
    Detail View
    DetailsrN   hour_account_subtitler@   )titlesubtitleavatarrA   rB   rC   rD   rE   rF   rH   rI   z	Over timerK   hour_detail_actionsN)r   r   r   r    r   rP   rR   r   headerbodyr4   r"   r#   r$   r   r      sx     EiLE .++F 
7,-	
6F	
>	N+	
?	_-	
;$D *Mr#   r   r+   c                   b     e Zd ZdZeZeZ ed      Z	 fdZ
dedef fdZdedef fdZ xZS )HourAccountFormViewz
    Form View
    rc   c                    t        |   di |}| j                  d| j                  j                  j
                  i       | j                  j                  j                  r@t        d      | j                  _
        | j                  | j                  j                         t        | j                  | j                  d      | _        | j                  |d<   |S )Nr?   )initialzHour account update)instancer+   rd   r"   )r-   r}   
form_classr1   r2   employee_getrd   r   pkrR   verbose_namer   )r5   r'   r   r6   s      r$   r}   z$HourAccountFormView.get_context_data   s    '*4V40A0A0N0N OP99  +,-B+CDOO(OOTYY%7%7O8&LL$))%H
	 ))r#   rd   r(   c                     |j                         s>|j                  j                         }t        | j                  | j
                  ||d      S t        |   |      S )N)rd   errors)is_validr   as_datar   r1   r!   r-   form_invalid)r5   rd   r   r6   s      r$   r   z HourAccountFormView.form_invalid   sS    }}[[((*Fd00462R  w#D))r#   c                 .   |j                         rv|j                  j                  rt        d      }nt        d      }|j	                          t        j                  | j                  t        |             | j                         S t        | )  |      S )NzAttendance account updatedzAttendance account added)r   r   r   rR   saver   successr1   r   r-   
form_valid)r5   rd   messager6   s      r$   r   zHourAccountFormView.form_valid  so    ==?}}8967IIKT\\1W:6$$&&w!$''r#   )r   r   r   r    r   rP   r   r   rR   new_display_titler}   r   r   r   r   rX   rY   s   @r$   r   r      sP    
 E'J.)
* * *	(5 	(, 	( 	(r#   r   N),r    typingr   django.contribr   django.httpr   django.shortcutsr   django.urlsr   r   django.utils.decoratorsr	   django.utils.translationr
   rR   attendance.filtersr   attendance.formsr   r   attendance.modelsr   base.decoratorsr   base.methodsr   r   r   horilla_views.cbv_methodsr   horilla_views.generic.cbv.viewsr   r   r   r   r   r   r&   r[   ry   r   r   r"   r#   r$   <module>r      s*    # $ # - 4 6 7 Q 0 - T T 4  .z29, 9 39 .z2=o = 3=@ .z2L^ L 3L^ .z2\  3" .z2*/ * 3*2 .z29:((/ (( 3((r#   