
    vgZ-                        d dl mZ d dlmZmZ d dlmZ d dlmZm	Z	m
Z
mZmZmZmZmZ d dlmZ  G d dej$                        Z G d d	ej$                        Z G d
 dej$                        Z G d dej$                        Z G d dej$                        Z G d dej$                        Z G d dej$                        Z G d dej$                        Zy)    )serializers)
BonusPointEmployee)	LeaveType)	AllowanceContract	DeductionLoanAccountMultipleConditionPayslipReimbursementReimbursementMultipleAttachment)
TaxBracketc                   <   e Zd Z ej                  dd      Z ej                  dd      Z ej                  dd      Z ej                  dd      Z ej                  d      Z
 ej                  dd      Z ej                  d	d      Z G d
 d      Zd Zy)PayslipSerializeremployee_id.employee_first_nameTsource	read_onlyemployee_id.employee_last_nameshift_id.employee_shiftemployee_id.badge_idr   z7employee_id.employee_work_info.department_id.departmentz0employee_id.employee_bank_details.account_numberc                       e Zd ZeZdZy)PayslipSerializer.Meta__all__N)__name__
__module____qualname__r   modelfields     C/var/www/horilla/horilla_api/api_serializers/payroll/serializers.pyMetar   #   s    r#   r%   c                 V    	 |j                   j                  }|j                  S #  Y y xY wNemployee_idemployee_profileurlselfobjr*   s      r$   get_employee_profile_urlz*PayslipSerializer.get_employee_profile_url*   -    	"??#'''	   !$ (N)r   r   r   r   	CharFieldemployee_first_nameemployee_last_name
shift_namebadge_idSerializerMethodFieldemployee_profile_urldepartment_namebank_account_check_numberr%   r/   r"   r#   r$   r   r      s    /+//0D /../4 '&&.GSWXJ${$$,BdSH<;<<tL+k++HTXO !6 5 5AT! r#   r   c                      e Zd Z ej                  dd      Z ej                  dd      Z ej                  dd      Z ej                  dd      Z ej                  d      Z
 ej                  dd      Z ej                  d	d      Z ej                  d
d      Z ej                  dd      Z ej                  dd      Zd Z G d d      Zy)ContractSerializerr   Tr   r   r   r   r   zjob_position_id.job_positionzjob_role_id.job_rolezdepartment_id.departmentzwork_type_id.work_typec                 V    	 |j                   j                  }|j                  S #  Y y xY wr'   r(   r,   s      r$   r/   z+ContractSerializer.get_employee_profile_urlI   r0   r1   c                       e Zd ZeZdZy)ContractSerializer.Metar   N)r   r   r   r   r    r!   r"   r#   r$   r%   r?   P   s    r#   r%   N)r   r   r   r   r2   r3   r4   r5   r6   r7   r8   job_position_namejob_role_namer9   work_type_namer/   r%   r"   r#   r$   r<   r<   2   s    /+//0D /../4 '&&.GSWXJ${$$,BdSH<;<<tL---- *K))1GSWXM+k++)TO '&&.GSWXJ*[**'4N r#   r<   c                        e Zd Z G d d      Zy)MultipleConditionSerializerc                       e Zd ZeZdZy) MultipleConditionSerializer.Metar   N)r   r   r   r   r    r!   r"   r#   r$   r%   rF   V   s    !r#   r%   Nr   r   r   r%   r"   r#   r$   rD   rD   U        r#   rD   c                   :   e Zd Z ej                  ej                  j                         dd      Z ej                  ej                  j                         dd      Z	 ej                  e
j                  j                         dd      Z G d d      Zd Zd Zy)	AllowanceSerializerTF)querysetmanyrequiredc                       e Zd ZeZdZg dZy)AllowanceSerializer.Metar   )id
company_idonly_show_under_employeeis_loanN)r   r   r   r   r    r!   read_only_fieldsr"   r#   r$   r%   rO   f   s    Vr#   r%   c                 R   |j                  dg       }|j                  dg       }|j                  dg       }t        j                  j                  di |}|j                  j                  |       |j                  j                  |       |j                  j                  |       |S )Nspecific_employeesexclude_employeesother_conditionsr"   )popr   objectscreaterV   setrW   rX   )r-   validated_datarV   rW   rX   	allowances         r$   r[   zAllowanceSerializer.createk   s    +//0DbI*../BBG)--.@"E%%,,>~>	 	$$(();<##''(9:""&&'78r#   c                     |j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }	|j                  d	      }
|j                  d
      }|j                  d      }|j                  d      }|r||dk  rt        j                  d      |s|st        j                  d      |dk(  r|st        j                  d      |dk(  r|st        j                  d      |dk(  r|st        j                  d      |r|	r|r|
st        j                  d      |r|t        j                  d      |S )Nis_fixedamountbased_onper_attendance_fixed_amountshift_idwork_type_idis_condition_basedfield	conditionvaluehas_max_limitmaximum_amountr   z:If 'is_fixed' is True, 'amount' must be a positive number.z/If 'is_fixed' is False, 'based_on' is required.
attendancezIIf 'based_on' is 'attendance', 'per_attendance_fixed_amount' is required.z4If 'based_on' is 'shift_id', 'shift_id' is required.z<If 'based_on' is 'work_type_id', 'work_type_id' is required.zPIf 'is_condition_based' is True, 'field', 'value', and 'condition' are required.z9If 'has_max_limit' is True, 'maximum_amount' is required.)getr   ValidationError)r-   datar`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   s                 r$   validatezAllowanceSerializer.validatey   s   88J'(#88J'&*hh/L&M#88J'xx/!XX&:;!HH[)	!1"236A:--L  --A  |#,G--[  z!(--F  ~%l--N  uE--b  ^3--K  r#   N)r   r   r   r   PrimaryKeyRelatedFieldr   rZ   allrV   rW   r   rX   r%   r[   rp   r"   r#   r$   rJ   rJ   [   s    ;;;!!%%'dU ;::!!%%'dU :{99"**..0teW W
1r#   rJ   c                        e Zd Z G d d      Zy)DeductionSerializerc                       e Zd ZeZdZy)DeductionSerializer.Metar   N)r   r   r   r	   r    r!   r"   r#   r$   r%   rv      s    r#   r%   NrG   r"   r#   r$   rt   rt      rH   r#   rt   c                       e Zd Z ej                  d      Z ej                  dd      Z ej                  dd      Z ej                  dd      Z	 G d d      Z
d	 Zy
)LoanAccountSerializerTr   employee_id.get_full_namer   r   zemployee_id.get_job_positionc                       e Zd ZeZdZy)LoanAccountSerializer.Metar   N)r   r   r   r
   r    r!   r"   r#   r$   r%   r{      s    r#   r%   c                 V    	 |j                   j                  }|j                  S #  Y y xY wr'   r(   r,   s      r$   r/   z.LoanAccountSerializer.get_employee_profile_url   r0   r1   N)r   r   r   r   r7   r8   r2   employee_full_namer6   r@   r%   r/   r"   r#   r$   rx   rx      sk    <;<<tL...*d %{$$,BdSH---- r#   rx   c                       e Zd Z ej                         Z ej                  dd      Z ej                  d      Z ej                  d      Z	 ej                  d      Z
d Z G d	 d
      Zd Z fdZd Zd Z fdZ xZS )ReimbursementSerializerzleave_type_id.nameTr   r   r   )r   ry   c                 V    	 |j                   j                  }|j                  S #  Y y xY wr'   r(   r,   s      r$   r/   z0ReimbursementSerializer.get_employee_profile_url   r0   r1   c                       e Zd ZeZdZy)ReimbursementSerializer.Metar   N)r   r   r   r   r    r!   r"   r#   r$   r%   r      s    r#   r%   c                     g }|j                   j                         D ](  }	 |j                  |j                  j                         * |S #  Y 1xY wr'   )other_attachmentsrr   append
attachmentr+   )r-   r.   attachmentsr   s       r$   get_other_attachementsz.ReimbursementSerializer.get_other_attachements   sV    //335 	J"":#8#8#<#<=	
 s   %A

Ac                 0   t        |   |i | g }t        | j                  dd       }|dk(  r|j	                  g d       n1|dk(  r|j	                  g d       n|dk(  r|j	                  g d       |D ]  }| j
                  j                  |d          y )Ntypereimbursement)leave_type_idcfd_to_encashad_to_encashbonus_to_encashleave_encashment)r   ra   r   bonus_encashment)r   ra   r   r   r   )super__init__getattrinstanceextendr!   rY   )r-   argskwargsexclude_fieldsinstance_typerg   	__class__s         r$   r   z ReimbursementSerializer.__init__   s    $)&)vt<O+!!U 00!!"MN00!! $ 	)EKKOOE4(	)r#   c                 J    t         j                  j                  |dd      }|S )N   T)%employee_available_leave__employee_id/employee_available_leave__total_leave_days__gteis_encashable)r   rZ   filter)r-   employeeleavess      r$   get_encashable_leavesz-ReimbursementSerializer.get_encashable_leaves   s-    ""))2:<= * 

 r#   c                 z   	 | j                   j                  }| j                   j                  }| j                   j                  }t
        j                  j                  |      j                         }|dk(  rY	 | j                   j                  }|j                  |k  rt        j                  ddi      |dk  rt        j                  dd	i      |d
k(  r0|}| j                  |      }|||vrt        j                  ddi      |S #  |d   }|d   }|j	                  dd       r|d   nd }Y xY w#  |d   }Y xY w)Nr)   r   r   )r)   r   r   z!Not enough bonus points to redeemr   z+Points must be greater than zero to redeem.r   z!This leave type is not encashable)r   r)   r   r   rm   r   rZ   r   firstr   pointsr   rn   r   )r-   ro   r)   r   r   available_pointsr   encashable_leavess           r$   rp   z ReimbursementSerializer.validate  sa   		--33K==%%D MM77M &--444MSSU%%:"&--"?"?  &&8!11&(KL  !#!11&(UV  %%)M $ : :; G%=@Q+Q!11$&IJ  =	}-K<D)-/4)H_%d :"&'8"9s   AD 8D1 %D.1D:c                 R   g }| j                   d   j                  }|j                  d      }|rC|D ]>  }t               }||_        |j                          |j                  |j                         @ t        |          } |j                  j                  |  t        |   di |S )Nrequestr   r"   )contextFILESgetlistr   r   saver   pkr   r   add)	r-   r   multiple_attachment_idsrequest_filesr   r   file_instancer   r   s	           r$   r   zReimbursementSerializer.save,  s    "$Y/55#++L9) A
 ? A+5(""$'..}/?/?@	A 7<>&""&&(?@w|%f%%r#   )r   r   r   r   r7   other_attachementsr2   leave_type_namer8   r6   r}   r/   r%   r   r   r   rp   r   __classcell__)r   s   @r$   r   r      s    :::<+k++3GSWXO<;<<tL${$$,BCH...6QR )6#J& &r#   r   c                        e Zd Z G d d      Zy)TaxBracketSerializerc                       e Zd ZdZeZy)TaxBracketSerializer.Metar   N)r   r   r   r!   r   r    r"   r#   r$   r%   r   >  s    r#   r%   NrG   r"   r#   r$   r   r   =  rH   r#   r   N)rest_frameworkr   employee.modelsr   r   leave.modelsr   payroll.models.modelsr   r   r	   r
   r   r   r   r   payroll.models.tax_modelsr   ModelSerializerr   r<   rD   rJ   rt   rx   r   r   r"   r#   r$   <module>r      s    & 0 "	 	 	 133 @ 44  F+"="= O+55 Od+55 K77 ,q&k99 q&h;66 r#   