B
    5be                 @   s  d dl Z d dl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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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'm(Z( G dd dej)Z*G dd deZ+G dd dej,eZ-dS )    N)MaxMinWhenCaseQ	CharField)	TruncDate)gettext_lazyactivate)	FilterSet)mixinsserializers)Response)NoneSerializer)ReportUtilGenericViewSetReportGenericFilter)short_date_formatshort_time_formatvalue_formatweekday_format)Transaction)CHOICE_GENDER)
C_ATT_RULE)STATUS_VALIDSTATUS_RESIGN_PENDINGc               @   sH  e Zd ZejedddZejeddddZejedd	ddZejed
dddZ	ej
eddZejeddddZejeddddZejeddddZejeddddZej
eddZej
eddZej
eddZej
eddZej
eddZdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& ZG d'd( d(Zd)S )*FirstInLastOutReportSerializerZreport_column_empCodeemp__emp_code)labelsourceZreport_column_firstNameemp__first_nameT)r   r   Z
allow_nullZreport_column_lastNameemp__last_nameZreport_column_nickNameemp__nicknameZreport_column_gender)r   Zreport_column_departmentCodeemp__department__dept_codeZreport_column_departmentNameemp__department__dept_nameZreport_column_positionCodeemp__position__position_codeZreport_column_positionNameemp__position__position_nameZreport_column_attendanceDateZreport_column_attendanceWeekdayZreport_column_firstInZreport_column_lastOutZreport_column_totalDurationc             C   s   t t|d |d S )Nemp__gender)dictr   get)selfobj r+   HG:\easytimepro\master/mysite/att\api\views\view_report_firstinlastout.py
get_gender-   s    z)FirstInLastOutReportSerializer.get_genderc             C   s   | dd }|sdS t|S )Ndate )r(   r   )r)   r*   att_dater+   r+   r,   get_att_date0   s    z+FirstInLastOutReportSerializer.get_att_datec             C   s    | dd }|sdS t| S )Nr.   r/   )r(   r   weekday)r)   r*   r0   r+   r+   r,   get_weekday6   s    z*FirstInLastOutReportSerializer.get_weekdayc             C   s   | dd }|sdS t|S )Nfirst_inr/   )r(   r   )r)   r*   r4   r+   r+   r,   get_check_in<   s    z+FirstInLastOutReportSerializer.get_check_inc             C   s   | dd }|sdS t|S )Nlast_outr/   )r(   r   )r)   r*   r6   r+   r+   r,   get_check_outB   s    z,FirstInLastOutReportSerializer.get_check_outc             C   s8   d}|d r4|d r4|d |d  j }t|dddS |S )Nr/   r6   r4   ZdurationiQ g      ?)Zsecondsr   )r)   r*   totalr+   r+   r,   get_total_timeH   s
    z-FirstInLastOutReportSerializer.get_total_timec               @   s   e Zd ZeZdZdS )z#FirstInLastOutReportSerializer.Meta)emp_code
first_name	last_name	nick_namegender	dept_code	dept_nameposition_codeposition_namer0   r2   check_in	check_out
total_timeN)__name__
__module____qualname__r   modelfieldsr+   r+   r+   r,   MetaO   s   rK   N)rF   rG   rH   r   r   _r:   r;   r<   r=   ZSerializerMethodFieldr>   r?   r@   rA   rB   r0   r2   rC   rD   rE   r-   r1   r3   r5   r7   r9   rK   r+   r+   r+   r,   r      s2   r   c               @   sZ   e Zd Zejr,ejdddZejdddZnejdddZejdddZG dd dZ	dS )	FirstInLastOutReportFilterr.   Zgte)Z
field_namelookup_exprZlte)namerN   c               @   s   e Zd ZeZdddddgZdS )zFirstInLastOutReportFilter.MetaZ	employeesZdepartmentsZareas
start_dateend_dateN)rF   rG   rH   r   rI   rJ   r+   r+   r+   r,   rK   ^   s   rK   N)
rF   rG   rH   sixZPY3django_filtersZ
DateFilterrP   rQ   rK   r+   r+   r+   r,   rM   V   s   rM   c                   sR   e Zd ZeZej ZeZ	dgZ
eedZdZ fddZdd Zdd	 Z  ZS )
FirstInLastOutReportViewSetr:   )listZexport)rE   c       	         sZ  | j jj}d|i}| j jj}| j jj}| j jj}tt|  j	f |}| j jj
si }| rh| |d< | r|| |d< | r| |d< |r|j	f |}| }tt|d}|dkr|	ttdtd dB ttdB }|jtdd	}|d
dddddddddd}|jtttdddt dtttdddt ddd}|S )NZemp__company_idZemp__department__inZemp__area__inZemp__position__in
resign_emp0)Zemp__statusZ
punch_time)r.   Zemp_idr   r   r    r!   r&   r"   r#   r$   r%   r.   r   )Zpunch_stateZthen)Zoutput_field   )r4   r6   )ZrequestuserZcurrent_companyZget_auth_deptZget_auth_areaZget_auth_possuperrT   get_querysetfilterZis_superuserexistsallZdistinctstrr   r(   r   r   r   Zannotater   valuesr   r   r   r   r   Zorder_by)	r)   Z
company_idZbase_filterZ	auth_deptZ	auth_areaZauth_posquerysetfiltersrV   )	__class__r+   r,   r[   p   sL    




 



z(FirstInLastOutReportViewSet.get_querysetc             C   s   | j | jtS )N)serializer_dictr(   actionr   )r)   r+   r+   r,   get_serializer_class   s    z0FirstInLastOutReportViewSet.get_serializer_classc             C   s   t d tdS )NZenzFirst In Last Out Report)r
   rL   )r)   r+   r+   r,   get_file_title   s    z*FirstInLastOutReportViewSet.get_file_title)rF   rG   rH   r   rI   Zobjectsr[   ra   rM   Zfilter_classZorderingr   rd   Zsummary_fieldsrf   rg   __classcell__r+   r+   )rc   r,   rT   c   s   
.rT   ).rR   rS   Zdjango.db.modelsr   r   r   r   r   r   Zdjango.db.models.functionsr   Zdjango.utils.translationr	   rL   r
   Zdjango_filters.rest_frameworkr   Zrest_frameworkr   r   Zrest_framework.responser   Zmysite.att.api.serializersr   Zmysite.att.api.utils_classr   r   Zmysite.att.utilsr   r   r   r   Zmysite.iclock.modelsr   Zmysite.personnel.db_constr   Zmysite.att.global_cacher   Zmysite.admin.modelsr   r   ZModelSerializerr   rM   ZListModelMixinrT   r+   r+   r+   r,   <module>   s"    >