o
    h                     @   s   d dl 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dS )    )models)ValidationError)timezonec                   @   s    e Zd ZejddZdd ZdS )
Departmentd   
max_lengthc                 C   s   | j S N)nameself r   /var/www/html/pos/hr/models.py__str__	   s   zDepartment.__str__N)__name__
__module____qualname__r   	CharFieldr
   r   r   r   r   r   r      s    r   c                       s  e Zd Zg dZg dZg dZejddddZejdd	Z	ejdd	Z
e Zejd
d	Zejdd	ZejdddZejddddZejd
dddZejdejdddZejddddZejdeddZejdeddZejdeddZe ZejdddZejddZejddddZejddddZ ejddddZ!ej"ddddZ#ej"ddddZ$ej"ddddZ%ej&ddddZ' fddZ(dd Z)  Z*S ) Employee))	full_timez	Full Time)	part_timez	Part Time)contractContract)internIntern)
consultant
Consultant))
management
Management)senior_staffzSenior Staff)junior_staffzJunior Staff)support_staffzSupport Staff)	temporary	Temporary))activeActive)on_leavezOn Leave)	suspended	Suspended)
terminated
Terminated
   TF)r   uniqueeditabler   r         )r   r,   )r   nullblankr   )	on_deleter0   r1   r   )r   choicesdefaultr    r$      
max_digitsdecimal_placesr4   2   zemployee_photos/)	upload_tor0   r1   z	id_scans/zemployee_documents/c                    sR   | j stjjtddd }|r|d nd}d|d| _ t j|i | d S )Nid)max_idr=      HKL03d)employee_idr   objects	aggregater   Maxsupersave)r   argskwargsr=   new_id	__class__r   r   rF   E   s
   zEmployee.savec                 C   s   | j  d| j S )N )
first_name	last_namer   r   r   r   r   M   s   zEmployee.__str__)+r   r   r   EMPLOYMENT_TYPE_CHOICESEMPLOYEE_CATEGORY_CHOICESEMPLOYMENT_STATUS_CHOICESr   r   rA   rM   rN   
EmailFieldemailphoneaddressnational_idemergency_contact_nameemergency_contact_phone
ForeignKeySET_NULL
department	job_titleemployment_typeemployee_categoryemployment_status	DateField	hire_dateDecimalFieldsalaryBooleanField	is_activebankbranchaccount_number
ImageFieldprofile_photoid_scan_frontid_scan_back	FileFieldadditional_documentsrF   r   __classcell__r   r   rJ   r   r      s<    r   c                   @   sP   e Zd ZejeejdZe Z	ej
dddZG dd dZdd Zd	d
 ZdS )
Attendancer2   r+   ))Presentrr   )Absentrs   )Latert   )r   r3   c                   @      e Zd ZdZdS )zAttendance.MetaemployeedateNr   r   r   unique_togetherr   r   r   r   MetaV       r{   c                 C   s6   t jj| j| jd rtd| j d| j dd S )Nrv   zAttendance for  on z has already been recorded.)rp   rB   filterrw   rx   existsr   r   r   r   r   cleanY   s   zAttendance.cleanc                 C   s&   | j j d| j j d| j d| j S NrL    - )rw   rM   rN   rx   statusr   r   r   r   r   ^      &zAttendance.__str__N)r   r   r   r   rY   r   CASCADErw   r`   rx   r   r   r{   r   r   r   r   r   r   rp   Q   s    rp   c                   @   sH   e Zd ZejeejdZe Z	e Z
e ZejddZdd ZdS )Leaverq   Fr9   c                 C   s&   | j j d| j j d| j d| j S )NrL   r   z to )rw   rM   rN   
start_dateend_dater   r   r   r   r   i   r   zLeave.__str__N)r   r   r   r   rY   r   r   rw   r`   r   r   	TextFieldreasonrd   approvedr   r   r   r   r   r   b   s    r   c                   @   sL   e Zd ZejeejddZejddZ	ej
dddZejdd	Zd
d ZdS )	Deduction
deductionsr2   related_name   r   r+   r5   r6   T)auto_now_addc                 C   s   | j j d| j j d| j S r   )rw   rM   rN   r   r   r   r   r   r   s   s   zDeduction.__str__N)r   r   r   r   rY   r   r   rw   r   r   rb   amountr`   rx   r   r   r   r   r   r   m   s    r   c                       s   e Zd ZejeejddZe Z	ej
dddZej
ddddZejeddd	Zej
ddd
dZdd Z fddZdd ZG dd dZ  ZS )Payrollpayrollsr   r+   r5   r6   r   )r7   r8   r4   T)r1   r   F)r7   r8   r-   c                 C   s<   | j rtdd | j D }nd}| j| j | | _| jS )Nc                 s   s    | ]}|j V  qd S r	   )r   ).0	deductionr   r   r   	<genexpr>   s    z/Payroll.calculate_net_salary.<locals>.<genexpr>r   )pksumr   allbasic_salarybonus
net_salary)r   total_deductionsr   r   r   calculate_net_salary   s
   zPayroll.calculate_net_salaryc                    s4   | j s| j| j | _n|   t j|i | d S r	   )r   r   r   r   r   rE   rF   )r   rG   rH   rJ   r   r   rF      s   zPayroll.savec                 C   s    d| j j d| j j d| j S )NzPayroll for rL   r}   )rw   rM   rN   rx   r   r   r   r   r      s    zPayroll.__str__c                   @   ru   )zPayroll.Metarv   Nry   r   r   r   r   r{      r|   r{   )r   r   r   r   rY   r   r   rw   r`   rx   rb   r   r   ManyToManyFieldr   r   r   r   rF   r   r{   ro   r   r   rJ   r   r   w   s    		r   N)	django.dbr   django.core.exceptionsr   django.utilsr   Modelr   r   rp   r   r   r   r   r   r   r   <module>   s    D
