B
    5FcW                 @   s  d dl Z d dl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mZmZmZ d dlmZmZ d dlmZ d dl m!Z! G dd dej"Z#G dd dej$Z%G dd dej"Z&G dd dej$Z'G dd dej"Z(G dd dej$Z)G dd dej"Z*G dd dej$Z+G dd dej"Z,G d d! d!ej"Z-G d"d# d#ej"Z.G d$d% d%ej$Z/G d&d' d'ej"Z0G d(d) d)ej$Z1G d*d+ d+ej"Z2G d,d- d-ej$Z3G d.d/ d/ej"Z4G d0d1 d1ej$Z5G d2d3 d3ej"Z6G d4d5 d5ej$Z7G d6d7 d7ej"Z8G d8d9 d9ej$Z9G d:d; d;ej"Z:G d<d= d=ej$Z;G d>d? d?ej"Z<G d@dA dAej$Z=G dBdC dCej"Z>dS )D    N)HttpResponse)render)gettext_lazy)cache)forms)admin)STATUS_VALID)BOOLEANS)
DepartmentAreaPositionLocationResign)db_constwidgets)get_software_type_without_load)EASYWDMSc               @   s8   e Zd ZdZedZedZedZedZdd Z	dS )ResynchronizeDeviceTZ$employee_action_resynchronize2DeviceZ0employee_action_resynchronize2DeviceConfirmationc             O   s   ddl m} ddlm} ddlm} ddlm} xl| jD ]b}g }|jj	|j
 d}	x6|	D ].}
||
j}
||
|gfd ddddddd qZW ||j |S W d S )	Nr   )r   )Terminal)zk_set_user_data)	getDevice)area__in   )ZcmdTimeZ	is_fingerZis_faceZis_picZis_pvZis_fvZis_biophoto)django.core.cacher   mysite.iclock.modelsr   Zmysite.core.zkcmdprocr   Zmysite.iclock.utilsr   objectsfilterareaallsnappendemp_code)selfargskwargsr   r   r   r   empobjZdevicesdev r(   CG:\easytimepro\master/mysite/personnel\actions\personnel_actions.pyaction!   s    


zResynchronizeDevice.actionN)
__name__
__module____qualname__batch_select_verbose_namehelp_txtshort_descriptionconfirmationr*   r(   r(   r(   r)   r      s   r   c               @   sR   e Zd ZejeddddedfdedffdZejedd	d
deddZdS )ReUploadFromDeviceFormZreUploadFromDevice_field_deviceTr   ZdataRange_option_allr   ZdataRange_option_specified)labelrequiredinitialchoicesZ!reUploadFromDevice_field_deviceSN FZ'eUploadFromDevice_field_deviceSNHelpTxt)r5   empty_valuer6   Zdisabled	help_textN)	r+   r,   r-   r   ChoiceFieldr/   r'   	TextFieldr   r(   r(   r(   r)   r4   8   s
   
r4   c               @   s8   e Zd ZdZdZedZedZedZe	Z
dd ZdS )ReUploadFromDevicez6
    Re upload user from device under user's area
    TZ"employee_action_reUploadFromDevicec             C   s   ddl m} ddlm} ddlm} g }|jj|d }|dkrR|sR|t	dx| jD ]}dj
|jd	}	|rt|r|jj|j d
jddd}
n2td |d}|jjdd |D djddd}
x|
D ]}|||	 qW ||j qZW |S )Nr   )r   )saveCmd)ActionHandleError)r   0Z please_enter_valid_serial_numberzDATA QUERY USERINFO PIN={pin})pin)r   idT)flat,c             S   s   g | ]}|  qS r(   )strip).0xr(   r(   r)   
<listcomp>Y   s    z-ReUploadFromDevice.action.<locals>.<listcomp>)Zsn__in)r   r   mysite.utilsr?   mysite.admin.actionr@   r   r   existsr/   formatr!   intr   r   values_listsplitr    )r"   r'   r   r   r?   r@   r   Zserial_numberr%   cmdZdevsr(   r(   r)   r*   K   s"     "
zReUploadFromDevice.actionN)r+   r,   r-   __doc__r.   r/   r0   r1   r2   r4   action_formr*   r(   r(   r(   r)   r>   A   s   r>   c               @   s|   e Zd ZejedejjdZej	ede
jddZejedejjdZej	edde
jd	Zejed
dde
jdZdS )ResignationFormZemployeeResign_field_date)r5   r7   ZemployeeResign_field_leaveTyper   )r5   r8   r7   Z$resign_field_reportGenerationEndDateZ.employeeResign_field_disableAttendanceFunctionT)r5   r7   r8   ZemployeeResign_field_reasonr9   F)r5   r:   r6   Z
max_lengthN)r+   r,   r-   r   Z	DateFieldr/   datetimenowresign_dater<   r   Z	LEAVETYPEresign_typereport_generation_end_dateZDISABLE_ATTdisable_attr=   MAX_RESIGN_REASONreasonr(   r(   r(   r)   rT   `   s   
rT   c               @   s8   e Zd ZdZedZedZedZeZ	dZ
dd ZdS )ResignationTZemployee_action_resignationimportc       
   	   O   s   g }t | jj}| r|j}tj  }|d }|d |k rDd}xP| jD ]F}t	||d |d |d |d d t
j |d}	|	  ||	j qLW |S d S )NrZ   rW   TrY   rX   r\   )ZemployeerW   rY   rX   r\   Z
disableatt)rT   requestPOSTZis_validcleaned_datarU   rV   dater   r   r   r[   saver    r!   )
r"   r#   r$   r   Zformra   rV   rZ   r%   r&   r(   r(   r)   r*   t   s"    zResignation.actionN)r+   r,   r-   r.   r/   r0   r1   r2   rT   rS   Zurlr*   r(   r(   r(   r)   r]   l   s   r]   c               @   s<   e Zd Zejedej e	j
dZejeddddZdS )AdjustDepartmentFormZemployee_field_department)r5   querysetwidgetZ transferDepartment_field_remarksr9   F)r5   r:   r6   N)r+   r,   r-   django_formsModelChoiceFieldr/   r
   r   get_querysetr   ZDepartmentRadioSelect
departmentr   r=   remarksr(   r(   r(   r)   rd      s   
rd   c               @   s4   e Zd ZdZedZedZedZeZ	dd Z
dS )AdjustDepartmentTZ"employee_action_transferDepartmentc             O   s6   g }x,| j D ]"}|d |_|  ||j qW |S )Nrj   )r   Zdepartment_idrc   r    r!   )r"   r#   r$   r   r&   r(   r(   r)   r*      s    
zAdjustDepartment.actionN)r+   r,   r-   r.   r/   r0   r1   r2   rd   rS   r*   r(   r(   r(   r)   rl      s   rl   c               @   s<   e Zd Zejedej e	j
dZejeddddZdS )AdjustAreaFormZemp_field_area)r5   re   rf   ZtransferArea_field_remarksr9   F)r5   r:   r6   N)r+   r,   r-   rg   ZModelMultipleChoiceFieldr/   r   r   ri   r   ZAreaSelectMultipler   r   r=   rk   r(   r(   r(   r)   rm      s   rm   c               @   s4   e Zd ZdZedZedZedZeZ	dd Z
dS )
AdjustAreaTZemployee_action_transferAreac             O   sl   | j jdg }|s(tdjtddg }x:| jD ]0}|j| t	j	
 |_|  ||j q4W |S )Nr   z{error}#employee_actionError_areaIsRequired)error)r_   r`   getlist	ExceptionrM   r/   r   r   setrU   rV   update_timerc   r    r!   )r"   r#   r$   areasr   r&   r(   r(   r)   r*      s    zAdjustArea.actionN)r+   r,   r-   r.   r/   r0   r1   r2   rm   rS   r*   r(   r(   r(   r)   rn      s   rn   c               @   s4   e Zd ZdZedZedZedZeZ	dd Z
dS )CopyAreaTZemployee_action_addAreac       	      O   s   | j jdg }|s(tdjtddg }ttt|}xx| j	D ]n}t|j
jddd}t|t|}|srqBt|t|}|j
| tj |_|  ||j qBW |d d S )	Nr   z{error}ro   )rp   rC   T)rD      )r_   r`   rq   rr   rM   r/   listmaprN   r   r   rO   rs   
differenceunionrU   rV   rt   rc   r    r!   )	r"   r#   r$   ru   r   r&   Zcurrent_areasZ	new_areasZ	all_areasr(   r(   r)   r*      s     zCopyArea.actionN)r+   r,   r-   r.   r/   r0   r1   r2   rm   rS   r*   r(   r(   r(   r)   rv      s   rv   c               @   s8   e Zd ZdZedZedZedZedZdd Z	dS )PassProbationTZemployee_action_passProbationZ)employee_action_passProbationConfirmationc             O   s"   x| j D ]}d|_|  qW d S )Nr   )r   Zemp_typerc   )r"   r#   r$   	objects_ir(   r(   r)   r*      s    zPassProbation.actionN)
r+   r,   r-   r.   r/   r0   r1   r2   r3   r*   r(   r(   r(   r)   r|      s   r|   c               @   s<   e Zd Zejedej e	j
dZejeddddZdS )PositionTransferFormZemployee_field_position)r5   re   rf   ZtransferPosition_field_remarksr9   F)r5   r:   r6   N)r+   r,   r-   rg   rh   r/   r   r   ri   r   ZPositionRadioSelectpositionr   r=   rk   r(   r(   r(   r)   r~      s   
r~   c               @   s4   e Zd ZedZedZedZeZdZ	dd Z
dS )PositionTransferZ employee_action_transferPositionTc             O   sZ   g }xP| j D ]F}dtjjj|d gi}tj jf | |_|	  |
|j qW |S )Nz{}__inr   )r   rM   r   _metapknamer   firstr   rc   r    r!   )r"   r#   r$   r   r}   filter_paramr(   r(   r)   r*      s    zPositionTransfer.actionN)r+   r,   r-   r/   r0   r1   r2   r~   rS   r.   r*   r(   r(   r(   r)   r      s   r   c               @   s<   e Zd Zejedej e	j
dZejeddddZdS )LocationTransferFormZemployee_field_location)r5   re   rf   ZtransferLocation_field_remarksr9   F)r5   r:   r6   N)r+   r,   r-   rg   rh   r/   r   r   ri   r   ZLocationRadioSelectlocationr   r=   rk   r(   r(   r(   r)   r      s   
r   c               @   s4   e Zd ZedZedZedZeZdZ	dd Z
dS )LocationTransferZ employee_action_transferLocationTc             O   sZ   g }xP| j D ]F}dtjjj|d gi}tj jf | |_|	  |
|j qW |S )Nz{}__inr   )r   rM   r   r   r   r   r   r   r   rc   r    r!   )r"   r#   r$   r   r}   r   r(   r(   r)   r*     s    zLocationTransfer.actionN)r+   r,   r-   r/   r0   r1   r2   r   rS   r.   r*   r(   r(   r(   r)   r     s   r   c               @   sf   e Zd ZejededZejededZejededZ	ejededZ
ejededZdS )DeleteBiometricTemplatesFormZbio_templateType_fingerprint)r5   r8   Zbio_templateType_faceZbio_templateType_fingerVeinZbio_templateType_palmZbio_templateType_vlfaceN)r+   r,   r-   r   r<   r/   r	   fpfacefvpvvlr(   r(   r(   r)   r     s
   r   c               @   s4   e Zd ZdZedZedZedZeZ	dd Z
dS )DeleteBiometricTemplatesTZdelete_biometric_templatesc       
      O   s   g }|rt |r|d |r0t |r0|d |rFt |rF|d |r\t |r\|d |rrt |rr|d |rx2| jD ](}	|	| |	| d|kr~|	  q~W dd | jD S )N12689c             S   s   g | ]
}|j qS r(   )r!   )rG   r&   r(   r(   r)   rI   :  s    z3DeleteBiometricTemplates.action.<locals>.<listcomp>)rN   r    r   Zdelete_emp_devZdelete_db_biodataZdelete_biophoto)
r"   r   r   r   r   r   r#   r$   Z	bio_typesr&   r(   r(   r)   r*   '  s$    






zDeleteBiometricTemplates.actionN)r+   r,   r-   r.   r/   r0   r1   r2   r   rS   r*   r(   r(   r(   r)   r      s   r   c               @   sf   e Zd ZejedddZejedddZejedddZejedddZ	ejedddZ
dS )	
EnableAppszMobile App StatusF)r5   r6   zMobile Att PunchzMobile Outdoor Status zWhatsApp Statusz
SMS StatusN)r+   r,   r-   r   BooleanFieldr/   mobileapp_statusmobileapp_punch_statusmobileapp_outdoor_statuswhatsapp_statussmspush_statusr(   r(   r(   r)   r   =  s
   r   c               @   s4   e Zd ZdZedZedZedZeZ	dd Z
dS )	EnableAppTZenable_mobile_applicationc       	      O   s   |dkr&x| j D ]}d|_|  qW |dkrLx| j D ]}d|_|  q6W |dkrrx| j D ]}d|_|  q\W |dkrx| j D ]}d|_|  qW |dkrx| j D ]}d|_|  qW d S )Nonr   True)r   
app_statusrc   app_punch_statusenable_outdoor_managementenable_whatsapp
enable_sms)	r"   r   r   r   r   r   r#   r$   r}   r(   r(   r)   r*   M  s(    zEnableApp.actionN)r+   r,   r-   r.   r/   r0   r1   r2   r   rS   r*   r(   r(   r(   r)   r   E  s   r   c               @   sf   e Zd ZejedddZejedddZejedddZejedddZ	ejedddZ
dS )	DisableAppszMobile App StatusF)r5   r6   zMobile Att PunchzMobile Outdoor StatuszWhatsApp Statusz
SMS StatusN)r+   r,   r-   r   r   r/   r   r   r   r   r   r(   r(   r(   r)   r   h  s
   r   c               @   s<   e Zd ZdZedZedZedZeZ	edZ
dd ZdS )
DisableAppTZdisable_mobile_applicationz*are_you_sure_to_disable_app_status {0} {1}c       	      O   s   |dkr&x| j D ]}d|_|  qW |dkrLx| j D ]}d|_|  q6W |dkrrx| j D ]}d|_|  q\W |dkrx| j D ]}d|_|  qW |dkrx| j D ]}d|_|  qW d S )Nr   r   False)r   r   rc   r   r   r   r   )	r"   r   r   r   r   r   r#   r$   r}   r(   r(   r)   r*   x  s(    zDisableApp.actionN)r+   r,   r-   r.   r/   r0   r1   r2   r   rS   r3   r*   r(   r(   r(   r)   r   p  s   r   c               @   s6   e Zd ZejededdZejedej	dZ
dS )ImportEmployeeFormdataImport_field_filedata_import_fileHelpTxt)r5   r;   dataImport_field_type)r5   r8   N)r+   r,   r-   r   	FileFieldr/   import_filer<   r   IMPORT_TYPEimport_typer(   r(   r(   r)   r     s   r   c               @   s4   e Zd ZedZedZedZeZdZ	dd Z
dS )ImportEmployeeZ dataImport_action_importEmployeeZ'dataImport_action_importEmployeeHelpTxtZ+dataImport_action_importEmployeeDescriptionTc             O   s@   | j jdkr<| j| j  x t| jdg D ]}t| q*W d S )Nr`   Z
cache_keys)r_   methodr   Z
dataimportgetattrr   delete)r"   r#   r$   kr(   r(   r)   r*     s    zImportEmployee.actionN)r+   r,   r-   r/   r0   r1   r2   r   rS   Zkeep_page_openr*   r(   r(   r(   r)   r     s   r   c               @   s6   e Zd ZejededdZejedej	dZ
dS )ImportDocumentFormr   r   )r5   r;   r   )r5   r8   N)r+   r,   r-   r   r   r/   r   r<   r   r   r   r(   r(   r(   r)   r     s   r   c               @   s0   e Zd ZedZedZedZeZdd Z	dS )ImportDocumentZ dataImport_action_importDocumentZ'dataImport_action_importDocumentHelpTxtZ+dataImport_action_importDocumentDescriptionc             O   sZ   ddl m} ddlm} | jjdkrV|| jdddd}|  |j}|rV|d	|d S )
Nr   )r@   )ImportEmployeecertificationDatar`   Zimport_dataZ	personnelZEmployeeCertification)ZreqZ
input_nameZ	app_labelZ
model_name;)	rK   r@   Z2mysite.personnel.admin.employeecertification_adminr   r_   r   Zexe_import_dataZ
error_infojoin)r"   r#   r$   r@   r   Z
obj_importZ	ret_errorr(   r(   r)   r*     s    zImportDocument.actionN)
r+   r,   r-   r/   r0   r1   r2   r   rS   r*   r(   r(   r(   r)   r     s
   r   c               @   sX   e Zd ZejededddZejeddedZ	ejeddedZ
ejdd	Zd
S )ImportPhotoFormr   r   F)r5   r;   r6   ZdataImport_field_overwriter   )r5   r7   r8   ZdataImport_field_ignoreError)r6   N)r+   r,   r-   r   r   r/   	bio_photor<   r	   	overwriteignore_errorr=   delete_filesr(   r(   r(   r)   r     s   r   c               @   s0   e Zd ZedZedZedZeZdd Z	dS )ImportPhotoZdataImport_action_importPhotoZ$dataImport_action_importPhotoHelpTxtZ(dataImport_action_importPhotoDescriptionc          
      s  dd l }ddlm} ddlm} ddlm} ddlm  ddl	m
} ddlm} | jjdkr|jj| jjjd	}	| jjd
}
x0|
D ](}|jdd }|dkr|tdqW | jjd }|r||}|
s|tdt|dd}t|dd}dd |D } fdd|
D }x"|D ]}||kr"|| q"W |jj|| jjjdjddd}t|dkrz|tdt|tt | }|s|r|tdj!d"|dt#j$"d|	j%}||}x|
D ]}t&||kr҈ |jddd }||krqt#j$"|dj!|d}|s6t#j$'|r6q|( }|st&|)dd |kr|rt|d krtd!}||j!|dt*|d"}|+| W d Q R X qW d S )#Nr   )get_or_create_folder)r@   )Employee)	devicePIN)Company)AdminRuntimeWarningr`   )rC   r   .r   )ZjpgZjpegZempPhoto_format_errorr   ZempPhotoImport_error_noPhotor   r   c             S   s   g | ]}| d d qS )r   r   )rP   )rG   Zimager(   r(   r)   rI     s    z&ImportPhoto.action.<locals>.<listcomp>c                s*   g | ]"} |j d dd ddqS )r   r   r    r9   )r   rsplitreplace)rG   photo)r   r(   r)   rI     s    )Zemp_code__inZ
company_idr!   T)rD   Z$bioPhotoImport_error_noPhotoSelectedz"empPhotoImport_error_{pin}NotFoundrE   )rB   r   z	{pin}.jpgi x  z(empPhotoImport_error_{pin}SizeExceed25KBwb),jsonrJ   r   rK   r@   mysite.personnel.modelsr   Zmysite.personnel.utilsr   Zmysite.cloud.modelsr   Zmysite.admin.exceptionsr   r_   r   r   getuserZcurrent_companyZFILESrq   r   r   r/   r`   loadsrN   remover   rO   lenrs   rx   rM   r   ospathZhex_idstrrL   readrP   openwrite)r"   r#   r$   r   r   r@   r   r   r   Zcompanyphotosr   Zfile_extensionZdeleted_imagesr   r   Zdeleted_image_namesZpinsZimagesZexists_pinsZ
extra_pinsr   Z	store_dirrB   	file_pathZimgmsgfr(   )r   r)   r*     sd    





2zImportPhoto.actionN)
r+   r,   r-   r/   r0   r1   r2   r   rS   r*   r(   r(   r(   r)   r     s
   r   )?rU   r   Zdjango.httpr   Zdjango.shortcutsr   Zdjango.utils.translationr   r/   r   r   Zdjangor   rg   mysiter   Zmysite.adminZmysite.admin.modelsr   Zmysite.base_choicesr	   r   r
   r   r   r   r   Zmysite.personnelr   r   Zmysite.admin.utilsr   Zmysite.admin.constr   ZZKModelActionr   ZZKActionFormr4   r>   rT   r]   rd   rl   rm   rn   rv   r|   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r(   r(   r(   r)   <module>   sR   	##