B
    ?c*                 @   st   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
mZmZmZ d dlmZ d dlmZ G dd deZd	S )
    )gettext_lazyactivate)datetime)Transaction)temperature_updateget_real_colorget_temp_statusget_mask_valueSHORT_DATE_FORMATget_current_company_id)BaseTemperatureReportViewSet)
C_ATT_RULEc               @   sj   e Zd ZddddgZededededd	Zd
d ZdddZdd Zdd Z	dddZ
dd ZdS )BodyTemperatureReportViewSetin_tempout_tempstatusdisplayed_maskZreport_column_in_tempZreport_column_out_tempZreport_column_displayed_maskZreport_column_status)r   r   r   r   c             C   s  t  }t|}|dd}tt| }x|D ]}|d r|d dd }|d dd }|d dd	 }	tjj|d
 d|||	dd}
|
	 r|
d }|j
}|j}|j}t||}t||}t||}||d< ||d< t|||d< ||d< |d r|d dd }|d dd }|d dd	 }	tjj|d
 d|||	dd}|	 r|d }|j
}|j}|j}t||}t||}t||}||d< ||d< |dd}t||}||kr|n||d< |dd dkrd|d< n|dkr||d< |d
 }|d }t|| }d}tjj|d|ddd}|	 rx|D ].}|d dkrfd}P n|d dkrLd}qLW n`tjj|d|ddd}|	 rx6|D ].}|d dkrd}P n|d dkrd}qW ||d< q0W |S )N
short_date   Zclock_inr               
   emp_id)r   punch_stateZpunch_time__yearZpunch_time__monthZpunch_time__dayZ
punch_timer   in_temp_colorr   r   Z	clock_outz-punch_timer   out_temp_colorz-1ZNoZYesatt_date )r   r   Zpunch_time__date	mask_flag)r   r   getr
   strr   ZobjectsfilterZorder_byexists
company_idZtemperaturer    r	   r   r   r   r   strptimedateZvalues_list)selfZ	base_datar%   Zreport_settingr   Z_formatdataZyearZmonthZdayZtrans_inZtran_inZ
celsius_inr    r   r   Zin_time_colorZ	trans_outZtran_outZcelsius_outr   Zout_time_colorZ	in_statusZ
out_statusr   r   Zmask_flag_in_outZ	check_outiZcheck_in r+   IG:\easytimepro\master/mysite/att\api\views\view_report_bodytemperature.pyupdate_td_md_data   s    
















z.BodyTemperatureReportViewSet.update_td_md_dataNc             C   s  xt |D ]\}}y| jd}W n   d}Y nX |rPd||  d ||< y| jd}W n   d}Y nX |r|| rd|| d  d t||  d ||< y| jd	}W n   d}Y nX |r|| rd|| d
  d t||  d ||< y| jd}	W n   d}	Y nX |	rz||	 rz||	 }
|
dkrJd||	< n0|
dkr^d||	< n|
dkrrd||	< nd||	< t|tr|d|d  qt|}|dd |||< qW |S )z"only use for att report pdf reportr   Nz<span class="att_date">z</span>r   z<span style="color:r   z;">r   r   r   0z+<span style="color: #00CD66;">Normal</span>1z,<span style="color: #fb8e00;">Warning</span>2z)<span style="color: #ff0000;">High</span>r   r   r   )	enumerateexport_headersindexr"   
isinstancelistinsert)r(   datasr2   
extra_datar*   r)   att_date_indexin_temp_indexout_temp_indexstatus_indexr   r+   r+   r,   update_data_listf   sL    

(
(






z-BodyTemperatureReportViewSet.update_data_listc             C   s   |r| d | d |S )Nr   r   )append)r(   r2   group_by_fieldr+   r+   r,   update_header_before_export   s    

z8BodyTemperatureReportViewSet.update_header_before_exportc             C   s$   |dkr| dd |d= |d= |S )N	dept_coder   zNo.)r6   )r(   Zheadersr?   r+   r+   r,   update_group_export_headers   s
    z8BodyTemperatureReportViewSet.update_group_export_headersc             C   s  x |D ]}xt |D ]\}}y| jd}W n   d}Y nX |rht|trhd||  d ||< y| jd}| jd}	W n   d }}	Y nX |r|| rd||	  d t||  d ||< y| jd	}
| jd
}W n   d }
}Y nX |
r0||
 r0d||  d t||
  d ||
< y| jd}W n   d}Y nX |r|| r|| }|dkr~d||< n0|dkrd||< n|dkrd||< nd||< |d= |d= |dkrt|tr|d|d  qt|}|dd |||< qW qW |S )z"only use for att report pdf reportr   Nz<span class="att_date">z</span>r   r   z<span style="color:z;">r   r   r   r.   z+<span style="color: #00CD66;">Normal</span>r/   z,<span style="color: #fb8e00;">Warning</span>r0   z)<span style="color: #ff0000;">High</span>r   rB   rA   r   r   )r1   r2   r3   r4   r5   r"   r6   )r(   r7   r?   r8   r)   r*   vr9   r:   Zin_temp_color_indexr;   Zout_temp_color_indexr<   r   r+   r+   r,   update_group_data_list   sX    
$$






z3BodyTemperatureReportViewSet.update_group_data_listc             C   s   t d tdS )NZenzBody Temperature Report)r   _)r(   r+   r+   r,   get_file_title   s    z+BodyTemperatureReportViewSet.get_file_title)N)N)__name__
__module____qualname__Zexport_headers_prorF   Zextra_headers_translation_dictr-   r=   r@   rC   rE   rG   r+   r+   r+   r,   r      s   P
4	
=r   N)Zdjango.utils.translationr   rF   r   r   Zmysite.iclock.modelsr   Zmysite.att.utilsr   r   r   r	   r
   r   Zmysite.att.api.viewsr   Zmysite.att.global_cacher   r   r+   r+   r+   r,   <module>   s    