
    siB                     f   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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 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/  eed       e e#d      d       G d de!                    Z0 eed       e e#d      d       G d de                     Z1 eed       e e#d      d       G d de                    Z2 eed       e e#d      d       G d de2                    Z3 eed       e e#d      d       G d  d!e                    Z4 eed       e e#d      d       G d" d#e                    Z5 eed       e e#d      d       G d$ d%e                    Z6y&)'z
CBV of time sheet page
    )Any)forms)messages)Q)HttpResponse)render)resolvereverse)method_decorator)cached_property)gettext_lazy)Employee)login_required)HorillaCardViewHorillaDetailedViewHorillaFormViewHorillaListViewHorillaNavViewTemplateView)$is_projectmanager_or_member_or_perms)DynamicProjectCreationFormView)DynamicTaskCreateFormView)TimeSheetFilter)TimeSheetForm)ProjectTask	TimeSheetdispatch)nameproject.view_timesheetc                       e Zd ZdZdZy)TimeSheetViewz
    for time sheet page
    zcbv/timesheet/timesheet.htmlN)__name__
__module____qualname____doc__template_name     9/var/www/python-projects/worksol/project/cbv/timesheet.pyr"   r"   #   s    
 3Mr)   r"   c                   R     e Zd ZdZdZ e       ZdZdZdZ	g dZ
dedd	f fd
Z xZS )TimeSheetNavViewz
    Nav bar
    formz#listContainerz cbv/timesheet/timesheet_nav.htmlzcbv/timesheet/filter.html)	employee_id
project_iddatestatus5employee_id__employee_work_info__reporting_manager_id.employee_id__employee_work_info__department_id0employee_id__employee_work_info__job_position_id1employee_id__employee_work_info__employee_type_id+employee_id__employee_work_info__company_idkwargsreturnNc                 `   t        |   di | t        d      | _        t        dd| j                  j
                  j                  j                  i       }t        d      ddg| _	        dd	t        d      d
dddt        d      ddddd| ddg| _
        dt        d       d| _        y )Ntime-sheet-listzpersonal-time-sheet-viewemp_id)r7   Deletez
                    class="oh-dropdown__link--danger"
                    data-action ="delete"
                    onclick="deleteTimeSheet();"
                    style="cursor: pointer; color:red !important"
                    actionattrslistzlist-outlinez?
                        title ='List'
                        )typeiconurlr?   cardzgrid-outlinetime-sheet-cardzC
                          title ='Card'
                          graphz	bar-chartzm
                          onclick="event.stopPropagation();
                          window.location.href='zF'"
                          title ='Graph'
                          )rA   rB   r?   a&  
                                onclick = "event.stopPropagation();"
                                data-toggle="oh-modal-toggle"
                                data-target="#genericModal"
                                hx-target="#genericModalBody"
                                hx-get="zcreate-time-sheetz""
                                r(   )super__init__r
   
search_urlrequestuseremployee_getid_actions
view_typescreate_attrs)selfr7   rC   	__class__s      r*   rH   zTimeSheetNavView.__init__I   s    "6"!"343HdllFWFWFdFdFgFg;hij H+

 &01	 &01	  #114 6#
8!)
 *11D)E(F G!$r)   )r#   r$   r%   r&   filter_form_context_namer   filter_instancesearch_swap_targetr'   filter_body_templategroup_by_fieldsr   rH   __classcell__rS   s   @r*   r,   r,   /   sH    
  &%'O)6M6
O1$ 1$ 1$ 1$r)   r,   c            	            e Zd ZdZeZeZ fdZde	ddf fdZ
 ed      dd	fd
dddd ed      dfgZed        Zd ed      dfd ed      dfgZdZdZ xZS )TimeSheetListz
    Time sheet list view
    c                 4   t         |          }| j                  j                  j	                  d      sc| j                  j                  j
                  }|j                  t        |      t        |      z  t        |      z        j                         }|S Nr    )task_id__task_managers)project_id__managersr.   	rG   get_querysetrJ   rK   has_permrL   filterr   distinctrR   querysetemployeerS   s      r*   rc   zTimeSheetList.get_queryset       7')||  ))*BC||((55H223)* hj	 
 r)   r7   r8   Nc                 R    t        |   di | t        d      | _        d| _        y )Nr:   rO   r(   )rG   rH   r
   rI   action_methodrR   r7   rS   s     r*   rH   zTimeSheetList.__init__   s(    "6"!"34&r)   r   r.   employee_id__get_avatarr/   task_idr0   
time_spentr1   Descriptionget_description_colc                    | j                         j                  j                  } |d      j                  ddf |d      j                  df |d      j                  df |d      j                  df |d	      j                  d	fgS )
Nr.    employee_id__employee_first_namern   r/   project_id__titlero   task_id__titlerp   r0   model_meta	get_fieldverbose_namerR   rz   s     r*   sortby_mappingzTimeSheetList.sortby_mapping   s    JJL&&00	 -(552)
 |$113FGy!..0@A|$11<@v++V4

 
	
r)   in-progress--dotIn progress
            onclick="
                $('#applyFilter').closest('form').find('[name=status]').val('in_Progress');
                $('#applyFilter').click();

            "
            completed--dot	Completed
            onclick="
                $('#applyFilter').closest('form').find('[name=status]').val('completed');
                $('#applyFilter').click();

            "
            
                hx-get='{detail_view}?instance_ids={ordered_ids}'
                hx-target="#genericModalBody"
                data-target="#genericModal"
                data-toggle="oh-modal-toggle"
                status-{status})r#   r$   r%   r&   r   rx   r   filter_classrc   r   rH   rN   columnsr   r}   row_status_indications	row_attrsrow_status_classrY   rZ   s   @r*   r\   r\   }   s    
 E"L	' ' ' 
:'@A	
=	01G 
 
  m
	
 kN
	
0I )r)   r\   c                   N     e Zd ZdZdZdZdeddf fdZdef fdZdZ	d	 Z
 xZS )
TaskTimeSheet Fr7   r8   Nc                 "   t        |   di | d| _        t        | j                  j
                        j                  j                  d      }|| j                  _        | j                  j                  j                  d      }|rd| _
        y y )Nztask-timesheet-containerro   r.   rO   r(   )rG   rH   view_idr	   rJ   	path_infor7   getro   GETrl   )rR   r7   ro   r.   rS   s       r*   rH   zTaskTimeSheet.__init__   su    "6"1$,,00188<<YG&ll&&**=9!*D r)   c                     t        |   di |}| j                  j                  d      }t        j
                  j                  |      }|j                  }||d<   ||d<   ||d<   |S )Nro   rM   projecttaskr(   )rG   get_context_datar7   r   r   objectsr   )rR   r7   contextro   r   r   rS   s         r*   r   zTaskTimeSheet.get_context_data   si    '*4V4++//),||7+,,$	$	r)   z!cbv/timesheet/task_timesheet.htmlc                    t        j                  |       }| j                  j                  d      }t        j
                  j                  |      j                         }t        j
                  j                  |      }|j                  |      }| j                  j                  j                  d      }|rt        j
                  j                  |      j                         }|rj||j                  j                         vrN||j                  j                  j                         vr(|j                   j"                  s|j                  |      }|S )Nro   r   )ro   r.   ra   )r   rc   r7   r   r   r   re   firstr   rJ   r   r   task_managersallr   managersemployee_user_idis_superuser)rR   rh   ro   r   r.   ri   s         r*   rc   zTaskTimeSheet.get_queryset   s   "//5++//),||""g".446$$++G+<??7?3ll&&**=9''..+.>DDFH D$6$6$:$:$<< DLL$9$9$=$=$?? 11>>#??{?Cr)   )r#   r$   r%   r   r   bulk_select_optionr   rH   r   r'   rc   rY   rZ   s   @r*   r   r      sA     I"+ + +  8Mr)   r   c                        e Zd ZdZeZeZ ed      dz   ej                  j                  z   Zdeddf fdZeZeZ ed      dz   ej                  j                  z   Zdef fdZ fd	Zd
edef fdZ xZS )TimeSheetFormViewz&
    form view for create project
    Create r7   r8   Nc                     t        |   di | dt        fg| _        | j                  j
                  j                  d      r"| j                  j                  dt        f       y y )Nro   project.add_projectr/   r(   )	rG   rH   r   dynamic_create_fieldsrJ   rK   rd   appendr   rm   s     r*   rH   zTimeSheetFormView.__init__  sc    "6"12&
" <<%%&;<&&--=> =r)   c                     t         |          }| j                  j                  d      }|rJt        j
                  j                  |      }|j                  }|j                  |d<   |j                  |d<   |S )Nro   r   r/   )rG   get_initialr7   r   r   r   r   rM   )rR   initialro   r   r/   rS   s        r*   r   zTimeSheetFormView.get_initial$  sf    '%'++//),<<##w#/DJ$.MMGL!!%GIr)   c                    t        |   di |}| j                  j                  d      }| j                  j
                  j                  j                  }d }|rLt        j                  j                  |      }|j                  }t        j                  j                  |      }| j                  j                  j                  r{| j                  j                  j                   j                  }| j                  j                  j"                  }t        j                  j                  |      }t        j                  j                  |      }t        j                  j                  |      }|| j                  j$                  d   _        |D 	cg c]  }	|	j                  |	j(                  f c}	| j                  j$                  d   _        | j                  j$                  d   j*                  j-                  d       | j                  j.                  j                  d      }t1        d      | j2                  _        |r%| j                  j
                  j6                  s%| j                  j
                  j9                  d      rz|j:                  j=                         |j>                  j=                         z  j@                  j=                         z  |jB                  j=                         z  jE                         }
njG                         |j:                  j=                         v rb||j>                  j=                         z  j@                  j=                         z  |jB                  j=                         z  jE                         }
nX|jG                         jB                  j=                         v r,||j@                  j=                         z  jE                         }
n|}
|r`tI        jJ                         | j                  j$                  d   _&        tI        jJ                         | j                  j$                  d   _&        |
| j                  j$                  d   _        |S | j                  j
                  j                  }| j                  j
                  j9                  d	      rtN        j                  j=                         }ntN        j                  j                  |
      tN        j                  j                  |      z  tN        j                  j                  t        j                  j                  |      jQ                  dd            z  tN        j                  j                  t        j                  j                  |      jQ                  dd            z  jE                         }|| j                  j$                  d   _        |S c c}	w )Nro   r   )r   )dynamic_createzDynamic createzUpdate Time Sheetr   r/   r.   zproject.add_timesheet)r   )members)r   r   T)flat)id__in)task_membersr(   ))rG   r   r7   r   rJ   rK   rL   rM   r   r   r   r   re   r-   instancepkro   r/   fieldsrh   titlechoicesr   r   rN   
form_classr{   r   rd   r   r   r   r   r   rf   r   r   HiddenInputwidgetr   values_list)rR   r7   r   ro   user_employee_idr   r   ri   tasksitemr   projectsrS   s               r*   r   z"TimeSheetFormView.get_context_data.  s   '*4V4++//),<<,,99<<<<##w#/DllG''..2B.CH99  ii((0033Gii((33GLL'''8E''..2B.CH<<##w#/D38DIIY'0273*.$**%3DIIY'/ IIY'//664 ll&&**95G+,-@+ADOO(||  --1B1B1K1K%2 $$((*oo))+,''++-. ((,,./ (*  !W%5%5%9%9%;;oo))+,''++-. ((,,./ (*  !T%7%7%;%;%==#d&7&7&;&;&==GGI"8=8I8I8K		  .55:5F5F5H		  +27>DII]+4. ' ||((55H||  ))*AB"??..0 OO**H*=oo,,X,>?oo,,#||222JVV%D  W   -  oo,,#||222IUU%D  V   -  (*  7?DII\*3q3s   Wr-   c                 \   |j                         r|j                  j                  r#t        | j                  j                   d      }nt        d      }|j                          t        j                  | j                  t        |             | j                         S t        | -  |      S )Nz UpdatedzNew time sheet created)is_validr   r   rN   r-   saver   successrJ   r   rG   
form_valid)rR   r-   messagerS   s      r*   r   zTimeSheetFormView.form_validy  s    ==?}}tyy112(;<45IIKT\\1W:6$$&&w!$''r)   )r#   r$   r%   r&   r   r   r   rx   rN   ry   r{   new_display_titler   rH   dictr   r   r   r   rY   rZ   s   @r*   r   r     s    
 JE(c)EKK,D,DD   JE(c)EKK,D,DDT IV	(} 	( 	( 	(r)   r   c                   ~     e Zd ZdZeZeZ fdZde	ddf fdZ
ddd	d
ZdZd ed      dfd ed      dfgZdZ xZS )TimeSheetCardViewz
    For card view
    c                 4   t         |          }| j                  j                  j	                  d      sc| j                  j                  j
                  }|j                  t        |      t        |      z  t        |      z        j                         }|S r^   rb   rg   s      r*   rc   zTimeSheetCardView.get_queryset  rj   r)   r7   r8   Nc                 b    t        |   di | t        d      | _        ddddddg| _        y )NrE   Edita#  
                         hx-get='{get_update_url}'
                         hx-target='#genericModalBody'
                         data-toggle="oh-modal-toggle"
                         data-target="#genericModal"
                         class="oh-dropdown__link"
                         r=   r<   a  
                onclick="
                            event.stopPropagation()
                            deleteItem({get_delete_url});
                            "
                            class="oh-dropdown__link oh-dropdown__link--danger"
                r(   )rG   rH   r
   rI   rO   rm   s     r*   rH   zTimeSheetCardView.__init__  sG    "6"!"34 !	 #	
r)   rn   z{employee_id}zi <b>{date}</b> <br>Project : <b>{project_id}</b> <br><b>{task_id}</b> |  Time Spent : <b>{time_spent}</b>)	image_srcr   subtitler   r~   r   r   r   r   r   r   )r#   r$   r%   r&   r   rx   r   r   rc   r   rH   detailscard_status_classrN   card_status_indications
card_attrsrY   rZ   s   @r*   r   r     s    
 E"L	
 
 
6 / G * m
	
 kN
	
2Jr)   r   c                   D    e Zd ZdZeZ ed      ZddddZdZ	e
d        Zy	)
TimeSheetDetailViewz!
    detail view of the page
    Detailsr.   r/   rn   )r   r   avatardetail_actionsc                    | j                         j                  j                  } |d      j                  df |d      j                  df |d      j                  df |d      j                  df |d      j                  dfgS )Nro   r0   rp   r1   get_status_displaydescriptionrw   r|   s     r*   bodyzTimeSheetDetailView.body  s    JJL&&00	y!..	:v++V4|$11<@x --/CD}%22MB
 	
r)   N)r#   r$   r%   r&   r   rx   rN   r   headerrl   r   r   r(   r)   r*   r   r     s@    
 EiLE +F
 %M
 
r)   r   N)7r&   typingr   djangor   django.contribr   django.db.modelsr   django.httpr   django.shortcutsr   django.urlsr	   r
   django.utils.decoratorsr   django.utils.functionalr   django.utils.translationr   rN   employee.modelsr   horilla_views.cbv_methodsr   horilla_views.generic.cbv.viewsr   r   r   r   r   r   project.cbv.cbv_decoratorsr   project.cbv.projectsr   project.cbv.tasksr   project.filtersr   project.formsr   project.modelsr   r   r   r"   r,   r\   r   r   r   r   r(   r)   r*   <module>r      s     #  $ # ( 4 3 6 $ 4  L ? 7 + ' 3 3 .z2()AB3L 3 33 .z2()ABG$~ G$ 3G$T .z2()ABQ)O Q) 3Q)h .z2()AB,M , 3,^ .z2()ABv( v( 3v(r .z2()ABS S 3Sl .z2()AB
- 
 3
r)   