
    vg                    :   d Z ddlZddlZddl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 ddlmZ dd	l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 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'm(Z( ddl)m*Z* ddl+m,Z,m-Z-m.Z. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5  ejl                  e7      Z8d Z9d Z: G d de2      Z; G d de2      Z< G d dejz                        Z> e	j~                  d      r!ddl@mAZA  G d  d!eA      ZB eeeA"      d#        ZC e	j~                  d$      rdd%lDmEZE  G d& d'eE      ZF eee."      d(        ZGd) ZHd* ed+      fd, ed-      fd. ed/      fd0 ed1      fd2 ed3      fd4 ed5      fd6 ed7      fgZId* ed+      fd, ed-      fd. ed/      fd0 ed1      fd2 ed3      fd4 ed5      fd8 ed9      fgZJd: ed;      fd< ed=      fd> ed?      fd@ edA      fdB edC      fdD edE      fdF edG      fdH edI      fdJ edK      fdL edM      fg
ZK G dN dOejz                        ZL G dP dQe2      ZM G dR dSe2      ZN G dT dUe2      ZO G dV dWe2      ZPdX ZQ eeeP"      dY        ZR G dZ d[ejz                        ZS G d\ d]e2      ZT	 eTj                  j                  d^_      j                         r,eTj                  j                  d^_      j                  d`_        G da dbejz                        ZY G dc dde2      ZZ G de dfejz                        Z[ G dg dhejz                        Z\g di edj      fdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~dddddddddddZ] G d dejz                        Z^y#  Y xY w)z#
models.py
Used to register models
    N)datedatetime	timedelta)forms)apps)messages)ValidationError)models)	post_save
pre_deletepre_save)receiver)	QueryDict)timezone)gettext_lazy)HorillaCompanyManager)get_next_month_same_date)Company
DepartmentEmployeeShiftJobPositionJobRoleWorkTypevalidate_time_format)strtime_seconds)
BonusPointEmployeeEmployeeWorkInformation)horilla_middlewares)HorillaModel)HorillaAuditInfoHorillaAuditLogc                 6    | dk  rt        t        d            y)z2
    The minimum value zero validation method
    r   zValue must be greater than zeroNr	   _values    )/var/www/horilla/payroll/models/models.pymin_zeror)   ,   s!     qya ABCC     c                     g }|| z
  }t        |j                  dz         D ]"  }| t        |      z   }|j                  |       $ |S )a  
    Returns a list of all dates within a given date range.

    Args:
        start_date (date): The start date of the range.
        end_date (date): The end date of the range.

    Returns:
        list: A list of date objects representing all dates within the range.

    Example:
        start_date = date(2023, 1, 1)
        end_date = date(2023, 1, 10)
        date_range = get_date_range(start_date, end_date)
       )days)ranger-   r   append)
start_dateend_date	date_listdeltaicurrent_dates         r(   get_date_ranger6   4   sT      Iz!E5::>" '!I1$55&' r*   c            
          e Zd ZdZd ed      fd ed      fd ed      fgZ ej                  dd	 ed
            Z ej                  ded	d	d ed            Z	 ej                  dd	      Z ej                  d      Z ej                  d ed      d      Z ej                  edd	ej"                        Z e       ZdefdZ G d d      Zy)FilingStatusz
    FilingStatus model
    	basic_pay	Basic Pay	gross_pay	Gross Paytaxable_gross_payTaxable Gross Pay   FzFiling status)
max_lengthblankverbose_name   zBased on)r@   choicesnullrA   defaultrB   zPython Code)rB   rF   TrE   Description)rA   rB   r@   rE   editable	on_deletereturnc                 ,    t        | j                        S N)strfiling_statusselfs    r(   __str__zFilingStatus.__str__q   s    4%%&&r*   c                       e Zd ZdgZy)FilingStatus.Meta-idN__name__
__module____qualname__ordering r*   r(   MetarU   t   	    7r*   r]   N)rX   rY   rZ   __doc__r%   based_on_choicer
   	CharFieldrP   based_onBooleanFielduse_py	TextFieldpython_codedescription
ForeignKeyr   PROTECT
company_idr   objectsrO   rS   r]   r\   r*   r(   r8   r8   N   s   
 
an%	an%	a 345O
 %F$$'M
  v#z]H !V  mUKF"&""-K"&""}%K
 #""dUfnnJ $%G' ' r*   r8   c            
       &    e Zd ZdZd ed      fd ed      fd ed      ffZd ed	      fd
 ed      fd ed      ffZd ed      fd
 ed      fgZ ej                  d      rej                  d ed      f       d ed      fd ed      fd ed      fd ed      ffZ	 d ed      fg eej                  j                  dd            z   Z ej$                  d ed       ed             Z ej(                  eej,                  d  ed!      "      Z ej0                   ed#      $      Z ej0                  d%d% ed&      '      Z ej$                  edd
 ed(      )      Z ej$                  d*d%ed
 ed+      ,      Z ej:                   ed-      d%d./      Z ej(                  eej,                  d0d%d% ed1      2      Z ej$                  edd ed3      )      Z  ej(                  e!ej,                  d%d%d0 ed4      5      Z" ej(                  e#ej,                  d%d%d0 ed6      5      Z$ ej(                  e%ej,                  d%d%d0 ed7      5      Z& ej(                  e'ej,                  d%d%d0 ed8      5      Z( ej(                  e)ej,                  d%d%d0 ed9      5      Z* ejV                  d: ed;      e,g ed<      =      Z- ej\                  d>d%d%?      Z/ ej`                  d% ed@       edA      B      Z1 ej`                  d% edC       edD      B      Z2 ej:                  d%d%d. edE      F      Z3 ejh                  d%d%dGH      Z5 e6dIe7gJ      Z8 e9dK      ZdLe:fdMZ;dN Z< fdOZ= G dP dQ      Z> xZ?S #  Y xY w)RContractz
    Contract Model
    salarySalaryhourlyHourly
commission
CommissionweeklyWeeklymonthlyMonthlysemi_monthlyzSemi-MonthlydailyDaily
attendancedraftDraftactiveActiveexpiredExpired
terminated
Terminated NoneidrP      zContract Title.)r@   	help_textrB   contract_setr   )rK   related_namerB   z
Start DaterB   TzEnd Date)rE   rA   rB   	Wage Type)rD   r@   rF   rB      Pay Frequency)r@   rE   rD   rF   rB   zBasic Salaryr   )rB   rE   rF   	contractszFiling Status)rK   r   rE   rA   rB   Statusr   )rK   rE   rA   r   rB   zJob PositionzJob RoleShift	Work Typer?   zNotice period in total days.zNotice Period)rF   r   
validatorsrB   zuploads/)	upload_torE   rA   zDeduct From Basic Payz'Deduct the leave amount from basic pay.rF   rB   r   zCalculate Daily Leave AmountzTLeave amount will be calculated by dividing the basic pay by number of working days.zDeduction For One Leave Amount)rE   rA   rF   rB   rC   )rE   rA   r@   history_setr   bases+employee_id__employee_work_info__company_idrL   c                 R    | j                    d| j                   d| j                   S )Nz - - )contract_namecontract_start_datecontract_end_daterQ   s    r(   rS   zContract.__str__  s.    $$%R(@(@'ATE[E[D\]]r*   c                    | j                   /| j                   | j                  k  rt        dt        d      i      | j                  dk(  rtt
        j                  j                  | j                  d      j                  | j                        j                         dk\  rt        j                  t        d            | j                  dk(  rtt
        j                  j                  | j                  d      j                  | j                        j                         dk\  rt        j                  t        d	            | j                  d
v r0| j                  s#| j                  t        dt        d      i      y y y )Nr   z(End date must be greater than start dater~   employee_idcontract_statusr   r,   4An active contract already exists for this employee.r|   2A draft contract already exists for this employee.)ry   rv   deduction_for_one_leave_amountThis field is required)r   r   r	   r%   r   rm   rk   filterr   excludepkcountr   	wage_typecalculate_daily_leave_amountr   rQ   s    r(   cleanzContract.clean  sq   !!-%%(@(@@%(!,V*WX    H,  '' ,,h (  WW UW ''HI    G+  '' ,,g (  WW UW ''FG  >>114466>)91=U;VW  ? 5 2r*   c                 n   t         j                  j                  | j                        j	                         r| j
                  %| j                  j                  j                  | _        | j                  %| j                  j                  j                  | _        | j                  %| j                  j                  j                  | _
        | j                  %| j                  j                  j                  | _        | j                  %| j                  j                  j                  | _        | j                   (| j                   t#        j$                         k  rd| _        | j&                  dk(  rtt(        j                  j                  | j                  d      j+                  | j,                        j/                         dk\  rt1        j2                  t5        d            | j&                  dk(  rtt(        j                  j                  | j                  d      j+                  | j6                        j/                         dk\  rt1        j2                  t5        d	            t9        | t  |i | | j&                  dk(  rQ| j<                  E	 t?        | j<                        }| j                  j                  }||_         |j;                          | S | S # tB        $ r' tD        jG                  d
| j<                   d       Y | S tH        $ r#}tD        jG                  d|        Y d }~| S d }~ww xY w)Nr   r   r~   r   r   r,   r   r|   r   zFailed to convert wage 'z' to an integer.zAn unexpected error occurred: )%r   rk   r   r   exists
departmentemployee_work_infodepartment_idjob_positionjob_position_idjob_rolejob_role_id	work_typework_type_idshiftshift_idr   r   todayr   rm   r   r   r   r   r	   r%   r   supersavewageintbasic_salary
ValueErrorloggererror	Exception)rR   argskwargswage_int	work_infoe	__class__s         r(   r   zContract.save<  s   "**11(( 2 

&( &"&"2"2"E"E"S"S  ($($4$4$G$G$W$W!}}$ $ 0 0 C C O O~~%!%!1!1!D!D!Q!Qzz!!--@@II
!!-$2H2H4::<2W#,D   H,  '' ,,h (  WW UW ''HI 
   G+  '' ,,g (  WW UW ''FG  	d%f%8+		0ECtyy> ,,??	)1	& 
 t	  W 8CSTV   C=aSABBCs   AK ,L4	L4L//L4c                       e Zd ZdZg dZy)Contract.Metaz6
        Meta class to add additional options
        )r   r   r   N)rX   rY   rZ   r_   unique_togetherr\   r*   r(   r]   r   v  s    	 Vr*   r]   )@rX   rY   rZ   r_   r%   COMPENSATION_CHOICESPAY_FREQUENCY_CHOICESWAGE_CHOICESr   is_installedr/   CONTRACT_STATUS_CHOICESlistr8   rk   values_listFILING_STATUS_CHOICESr
   ra   r   rh   r   ri   r   	DateFieldr   r   r   pay_frequency
FloatFieldr   rP   r   r   r   r   r   r   r   r   r   r   r   IntegerFieldr)   notice_period_in_days	FileFieldcontract_documentrc   deduct_leave_from_basic_payr   r   re   noter"   r!   historyr   rO   rS   r   r   r]   __classcell__r   s   @r(   rm   rm   x   su   
 
1X;	1X;	q' 
1X;	AiL!	>*+ 
!G*	AiL!L
 t&Xq{34 
!G*	1X;	AiL!	q'	"$ai 1D  ,,T?C5
 !
 %F$$!$5"6Qz]M $&##..#z]	K +&**,H(((AjM !  {^	I %F$$%'M 6!N*;$PQRD%F%%.. 'M 'f&&'x[	O #"".. |_J %6$$.. ~&L !v  .. z]H F.. wZE "!!.. {^I 0F//23:'	 )((:DPTU"5&"5"5./=>#
 $76#6#656b
$  &7V%6%678	&" 6TcBD"
G $$QRG^ ^$L8tV Vws   (.N Nrm   c            	           e Zd ZdZd ed      fd ed      fd ed      fd ed	      fd
 ed      fd ed      fgZ ej                  ddd      Z ej                  dde      Z	 ej                  eej                   ed            Z ej                  dd      Z ej                  ddegdd      Z ej                  ddegdd      Z ej&                  ddd      Z ej&                  ddd      Z ej,                  d      Z ej                  ddd      Z ej2                  d      Z ej2                  d      Z ej8                  d      Z ej<                  dd      Z e d      Z! fd Z" fd!Z#d" Z$ xZ%S )#
WorkRecordz
    WorkRecord Model
    FDPPresentHDPzHalf Day PresentABSAbsentHDzHoliday/Company LeaveCONFConflictDFTr}   r   T)r@   rE   rA      )r@   rE   rD   r   rK   rB   )rE   rA   z00:00)rE   rA   r   rF   r@   r   )rE   rA   rF   rC   r@   r?   FrF   r   c                 V    t        j                         | _        t        |   |i | y rN   )r   nowlast_updater   r   rR   r   r   r   s      r(   r   zWorkRecord.save  s"    #<<>d%f%r*   c                 x    t         |           d| j                  cxk  rdk  sn t        t	        d            y )N              ?z*Day percentage must be between 0.0 and 1.0)r   r   day_percentager	   r%   rR   r   s    r(   r   zWorkRecord.clean  s5    d))0S0!!$P"QRR 1r*   c                 h    | j                   | j                   S | j                   d| j                   S )N-)record_namework_record_typer   rQ   s    r(   rS   zWorkRecord.__str__  s@     + 	
 ))*!DII;7	
r*   )&rX   rY   rZ   r_   r%   rD   r
   ra   r   r   rh   r   ri   r   r   r   r   at_workmin_hourr   at_work_secondmin_hour_secondre   r   messagerc   is_attendance_recordis_leave_recordr   r   DateTimeFieldr   r   rk   r   r   rS   r   r   s   @r(   r   r   ~  s   
 
)	$%&	(	q()*	:	'
G #&""cDIK'v''14Q#&##FNN:K 6T2Df 
 G  v 
 H )V((d$JN)f))t4KO6s+Df"4tDG.6..u=)f))%8O&V&&q1N&&&&D=K#$QRG&
S

r*   r   r{   )
Attendancec                   0    e Zd ZdZ eee      d        Zy)OverrideAttendance@
        Class to override Attendance model save method
        senderc                    |j                   rnt        |j                        }t        |j                        }|j                  |k\  rdnd}|j
                  du rdn|}|dk(  rt        d      n
t        d      }|dk(  r||kD  rt        d      n|}t        j                  j                  |j                  d|j                  	      }t        j                  j                  |j                  |j                  
      j                         s
t               nBt        j                  j                  |j                  |j                  
      j                         }|j                  |_        |j                  |_        |j                  |_        |j                  |_        ||_        ||_        ||_        ||_        d|_        |j
                  r||dz  kD  rdnd|_        |j-                          |dk(  r|j.                  rt        d      }|dk(  rt        d      }||_        |j-                          |j&                  }|j$                  }|j0                  sd}t        d      }||_        ||_        |j-                          yy)zA
            Overriding Attendance model save method
            r   r   Fr   zValidate the attendance	ValidatedzIncomplete minimum hourT)r   r  r   r   r      r         ?zHalf day leaver   zCurrently workingN)
first_saver   minimum_hourattendance_worked_hourr  attendance_validatedr%   r   rk   r   attendance_dater   r   firstr   r   r  r  r   r  r  r   r   r  attendance_clock_out)r  instancer   r  r  statusr  work_records           r(   attendance_post_savez'OverrideAttendance.attendance_post_save  sd   
 """1(2G2G"H!01P1P!Q"*"9"9_"LRW#+#@#@E#Iv4:f4DA/0!K.  ?^+K /0  
 )0077!11)- ( 4 4 8  &--44%55$,$8$8 5  fh L
 $++22%55$,$8$8 3  eg  +3*>*>'#+#;#; &.&E&E#'/'<'<$.=+-;*/5,&-#37000 .11D D$  .   "U?{'B'B 01GU?	lG&-#  "%--$5544"F 34G&-#/5,  " #r*   N)rX   rY   rZ   r_   r   r   r  r  r\   r*   r(   r
  r
    s$    	
 
)J	/C	# 
0C	#r*   r
  r  c                     t         j                  j                  |j                  d|j                        j                          y)z;
        Overriding Attendance model delete method
        T)r   r  r   N)r   rk   r   r   r  delete)r  r  _kwargss      r(   attendance_pre_deleter!    s;     	!! ,,!%)) 	" 	
 &(r*   leave)LeaveRequestc                   <     e Zd ZdZ eee       fd       Z xZS )OverrideLeaveRequestr  r  c                 8   |j                   |j                  k(  r<|j                  |j                  k7  r#|j                  |_        t        t
        |          t        |j                   |j                        }|j                  dk(  rK|D ]D  }	 t        j                  j                  ||j                        j                         r+t        j                  j                  ||j                        n	t               }|j                  |_        d|_        |j                   |k(  r|j                  dk(  s|j                  |k(  r|j                  dk(  rdnd|_        |j                   |k(  r|j                  dk(  s|j                  |k(  r|j                  dk(  rdnd	}||_        ||_        |d	k(  rd
n
t%        d      |_        |j                          G y|D ]<  }t        j                  j                  d||j                        j)                          > y#  Y xY w)zC
            Overriding LeaveRequest model save method
            approvedr  T
first_halfsecond_halfr  r   r   r   r   z$Half day Attendance need to validate)r  r   r   N)r0   r1   end_date_breakdownstart_date_breakdownr   r#  r   r6   r  r   rk   r   r   r   r  r   r   r   r%   r  r  )r  r  r   period_datesr   
work_entryr  r   s          r(   leaverequest_pre_savez*OverrideLeaveRequest.leaverequest_pre_save&  s    ##x'8'88//83P3PP.6.K.K+lH24)(*=*=x?P?PQL*,( *D)  *1188%),4,@,@  9   %fh '	 '..55%),4,@,@ 6  ", # 2:1E1E
.59
2  (22d: ( = = M'00D8 ( ; ;} L	 !
 "& #1  (22d: ( = = M'00D8 ( ; ;} L	 #
 "'  7=
3*.
  & %!"#I!J #*
 #)Q*Z ) D&&--(,!$,$8$8 .  fh	s   E HH)	rX   rY   rZ   r_   r   r   r#  r.  r   r   s   @r(   r%  r%     s#    	
 
(<	0?	 
1?	r*   r%  c                    |j                   j                  dk(  r|j                   nd}||j                  j                         }|s|t	               }| d|_        ||_         |j                  r|j                  nt        j                         |_	        |j                  |j                  nd|_        |j                          yyy)z[
    This method is used to override the save method for EmployeeWorkInformation Model
    TNz's Contractr   )r   	is_activer   r   rm   r   date_joiningr   r   r   r   r   r   )r  r  r   active_employeecontract_existscontracts         r(    employeeworkinformation_pre_saver5  o  s     !) 4 4 > >$ FD  ")66==?zH(7'8%DH"#2H )1)>)>%%HNNDT ( *2)>)>)J%%PQ M MMO  #r*   c                 h    | dk  rt        t        d            | dkD  rt        t        d            y)z
    Percentage validator
    r   zRate must be greater than 0d   zRate must be less than 100Nr$   r&   s    r(   rate_validatorr8    s9     qya =>??s{a <=>> r*   equalz
Equal (==)notequalzNot Equal (!=)ltzLess Than (<)gtzGreater Than (>)lezLess Than or Equal To (<=)gezGreater Than or Equal To (>=)	icontainsContainsr.   RangechildrenChildrenmarital_statuszMarital Status
experience
Experienceemployee_work_info__experiencezCompany ExperiencegenderGendercountryCountrystateStatecontract_set__pay_frequencyr   contract_set__wage_typer   $contract_set__department__departmentzDepartment on Contractc                       e Zd ZdZ ej
                  d      Z ej
                  dedd      Z ej
                  ddd e	d            Z
y)	MultipleConditionz!
    MultipleCondition Model
    rC   r   Tr@   rD   rE   rA   6The value must be like the data stored in the databaser@   rE   rA   r   N)rX   rY   rZ   r_   r
   ra   fieldCONDITION_CHOICE	conditionr%   r'   r\   r*   r(   rR  rR    sb     FE !   0t4I FLM	Er*   rR  c            
           e Zd ZdZd ed      fd ed      fgZd ed      fd ed	      fgZ ej                  d
      r+d ed      fd ed      fd ed      fd
 ed      fgZ	ee	z  Zd ed      fgZ
 ej                  ddd ed            Z ej                  dd ed            Z ej                   d ed       ed            Z ej$                  e ed      dd ed            Z ej$                  e ed       d!d ed"      #      Z ej                   d ed$      %      Z ej                   d ed&      %      Z ej                  dedd ed'      (      Z ej                  dedd)      Z ej                  ddd ed*            Z ej                   d ed+      %      Z ej<                  ddeg ed,      -      Z  ej                  ddedd ed.      /      Z! ej<                  dde"g ed0      -      Z# ej<                  ddd1eg ed2      3      Z$ ej<                  ddd1eg ed4      3      Z% ejL                  e'ejP                  dd ed      5      Z) ej<                  dd1deg ed6      7      Z* ej<                  dd1deg ed8      7      Z+ ejL                  e,ejP                  dd ed      5      Z- ej<                  dd1deg ed9      7      Z. ej                   d ed:       ed;            Z/ ej<                  ddeg ed<      -      Z0 ej                  d=dd>d> ed?      fgd@A      Z1 ej                  dBe
d edC      D      Z2 ej                  dBe3dE edF      D      Z4 ej<                  d1 edG      %      Z5 ej<                  dd edH      I      Z6 ej<                  dd edJ      I      Z7 ejL                  e8ddejP                  K      Z9 ej                   ddL      Z: ej                   ddL      Z; e<       Z= ej$                  e>ddM      Z? G dN dO      Z@dP ZA fdQZBdR ZCdSeDfdTZE fdUZF xZGS )V	Allowancez
    Allowance model
    ignorezExclude the allowance
max_amountProvide max amountr9   r:   rB  rC  r{   overtimeOvertimer   r   r   r   r  rC   FzTitle of the allowancerU  Tz{The one-time allowance in which the allowance will apply to the payslips             if the date between the payslip periodrE   rA   r   Include all active employeesz7Target allowance to all active employees in the companyr   Employees Specificallowance_specificz*Target allowance to the specific employees)rB   rA   r   r   Exclude Employeesallowance_excludedzqTo ignore the allowance to the employees when target them by all employees             or through condition-basedrB   r   rA   r   z6This field is used to calculate the taxable allowancesrF   r   zThis field is used to target allowance         to the specific employees when the condition satisfies with the employee's information"The related field of the employeesr@   rD   rE   rA   r   rS  rT  z)To specify, the allowance is fixed or notzFixed amount for this allowancerE   rA   r   r   zGIf the allowance is not fixed then specifies how the allowance provided)r@   rF   rD   rE   rA   r   The percentage of based onr   z8The attendance fixed amount for one validated attendance)rE   rA   rF   r   r   zThe fixed amount per childrenrK   rE   rA   rB   z=The fixed amount for one validated attendance with that shift)rE   rF   rA   r   r   zjThe fixed amount for one hour overtime that are validated             and approved the overtime attendancezAThe fixed amount for one validated attendance with that work typezHas max limit for allowancezLimit the allowance amountz$The maximum amount for the allowancer   month_working_daysFor working days on monthThe maximum amount for ?r@   rE   rF   rD   r   
   !The pay head for the if conditionr@   rD   rF   r   r<  3Apply for those, if the pay-head conditions satisfyThe amount of the pay-head&The start amount of the pay-head rangerA   rE   r   $The end amount of the pay-head rangerI   rF   rJ   rA   rJ   c                   (    e Zd ZdZg dZ ed      Zy)Allowance.Meta3
        Meta class for additional options
        )title
is_taxableis_condition_basedrV  rX  r'   is_fixedamountrb   rateper_attendance_fixed_amountr   shift_per_attendance_amountamount_per_one_hrr   work_type_per_attendance_amountrZ  N)rX   rY   rZ   r_   r   r%   rB   r\   r*   r(   r]   r|    s    	
$ ~r*   r]   c                 B    g d}|D ]  }t        | |d        d| _        y)z5Reset the this fields when is_fixed attribute is true)	rb   r  r  r   r  r  r   r  maximum_amountNF)setattrhas_max_limit)rR   attributes_to_reset	attributes      r(   reset_based_onzAllowance.reset_based_on  s/    

 - 	+ID)T*	+"r*   c                 T   t         |           | j                          | j                  sd | _        d | _        d | _        | j                  s | j                  st        t        d            | j                  s;| j                  r/| j                  dk(  r | j                  st        t        d            | j                  r8| j                  r| j                  r| j
                  st        t        d            | j                  dk(  r"| j                  st        dt        d      i      | j                  dk(  r | j                  st        t        d	            | j                  d
k(  r | j                  st        t        d            | j                  dk(  r | j                  st        t        d            | j                  r%| j                   dk  rt        dt        d      i      | j"                  r"| j$                  t        dt        d      i      | j"                  sd | _        y y )NFIf the 'Is fixed' field is disabled, the 'Based on' field is required.r9   z9Rate must be specified for allowances based on basic pay.zHIf condition based, all fields (field, value, condition) must be filled.r{   rb   zcIf based on is attendance,                         then per attendance fixed amount must be filled.r   z0If based on is shift, then shift must be filled.r   z8If based on is work type, then work type must be filled.rB  z'The amount per children must be filled.r   r  z#Amount should be greater than zero.r  r   )r   r   clean_fixed_attributesr  rV  rX  r'   r  rb   r	   r%   r  r  r   r   per_children_fixed_amountr  r  r  r   s    r(   r   zAllowance.clean  s   ##%&&DJ!DNDJ}}==%` 
 }}4==K3O99%QR  ""::TZZt~~%b 
 ==L(1Q1Q!J!  ==J&t}}!!$V"WXX==N*43D3D!LM  ==J&t/M/M!!$M"NOO==T[[1_!8Q/T-U"VWW$"5"5"=!#3Q7O5P"QRR!!"&D "r*   c                     | j                   sd| _        | j                   r3| j                  t        dt        d      i      | j	                          yy)zUClean the amount field and trigger the reset_based_on function based on the conditionNr  r   )r  r  r	   r%   r  rQ   s    r(   r  z Allowance.clean_fixed_attributes  sH    }}DK=={{"%x3K1L&MNN! r*   rL   c                 ,    t        | j                        S rN   rO   r~  rQ   s    r(   rS   zAllowance.__str__      4::r*   c                     t         |           | j                  s>| j                  j	                         s#| j
                  sd| _        t         |           y y y y NTr   r   include_active_employeesspecific_employeesr  r  r   s    r(   r   zAllowance.save  P    --++113++,0D)GLN , 4 .r*   )HrX   rY   rZ   r_   r%   exceed_choicer`   r   r   attendance_choicesif_condition_choicer
   ra   r~  r   one_time_daterc   r  ManyToManyFieldr   r  exclude_employeesr  r  FIELD_CHOICErV  rW  rX  r'   r  r   r)   r  rb   r8  r  r  r  rh   r   ri   r   r  r  r   r   r  r  r  maximum_unit	if_choiceIF_CONDITION_CHOICEif_condition	if_amountstart_range	end_ranger   rj   only_show_under_employeeis_loanr   rk   rR  other_conditionsr]   r  r   r  rO   rS   r   r   r   s   @r(   rZ  rZ    s   
 
1,-.	q-./M 
an%	Qz]#O
 t&:'7$Q{^,1\?+	
 	-- 
an% FU%1=U;VE %F$$4
M  3v2256MN 
 0//+,)@A /..*+)(
	 %$$LMJ -,,`
 F89E !   0t4I FLM	E #v"""M NH V:56	F  vU
	H 6
 01D #4&"3"3:NO# !2 1 1:34! !v  ..wZH #4&"3"3:ST# *)):2
	 %6$$..{^L '8f&7&7:O
'# (F''4501M
 'V&&::;	N $6##$ %-.
 -L !  #78	I $6###IJ	L "!!"> ?I $&##+S)TK "!!+Q)RI #""dUfnnJ  3v2255Q!f!!%%@G#%G-v--& &2#"2'h"  r*   rZ  c                   ~    e Zd ZdZd ed      fd ed      fgZd ed      fd ed      fd ed      fd ed	      fgZd
 ed      fd ed      fgZ ej                  d ed            Z
 ej                  dd ed            Z ej                  d ed       ed            Z ej                  e ed      d ed      d      Z ej                  e ed      dd ed            Z ej                  d ed       !      Z ej                  d ed"      !      Z ej                  d ed#      !      Z ej                  dedd ed$      %      Z ej                  dedd&      Z ej                  ddd ed'      (      Z ej                  ddd)d ed*      fd ed      fd ed	      fg ed+      ,      Z ej                  d ed-      !      Z ej:                  ddeg ed.      /      Z ej                  dedd ed0      %      Z  ej:                  ddd1e!g ed2       ed3      4      Z" ej:                  d1e!g5      Z# ej                  d ed6       ed7            Z$ ej:                  ddeg ed8      /      Z% ej                  d9dd:d: ed;      fg ed<      =      Z& ej                  d)ed ed>      ?      Z' ej                  d)e(d@ edA      ?      Z) ej:                  d1 edB      !      Z* ej:                  dd edC      D      Z+ ej:                  dd edE      D      Z, ejZ                  e.ddej^                  F      Z0 ej                  ddG      Z1 e2       Z3 ej                  ddG      Z4 ej                  e5ddH      Z6dI Z7 fdJZ8dK Z9dLe:fdMZ; fdNZ< xZ=S )O	Deductionz
    Deduction model
    r9   r:   r;   r<   r=   r>   net_payzNet Payr[  zExclude the deductionr\  r]  rC   zTitle of the deduction)r@   r   Tz{The one-time deduction in which the deduction will apply to the payslips             if the date between the payslip periodr`  Fra  z7Target deduction to all active employees in the companyr   rb  deduction_specificz*Target deduction to the specific employees)rB   r   r   rA   rd  deduction_excludezqTo ignore the deduction to the employees when target them by all employees             or through condition-basedrf  z3To specify the deduction is tax or normal deductionrg  zfTo find taxable gross,             taxable_gross = (basic_pay + taxable_deduction)-pre_tax_deductions zThis field is used to target deduction         to the specific employees when the condition satisfies with the employee's informationrh  ri  rS  rT  rU  rq  z	Basic payzoUpdate compensation is used to update                    pay-head before any other deduction calculation starts)rE   rA   r@   rD   r   z)To specify, the deduction is fixed or notzFixed amount for this deductionrj  zGIf the deduction is not fixed then specifies how the deduction providedr   zEmployee raterk  )rE   rA   rF   r   rB   r   )rF   r   zHas max limit for deductionzLimit the deductionz$The maximum amount for the deductionr   rm  rn  ro  rp  rr  rs  r<  rt  ru  rv  rw  rx  rI   ry  rz  c                 b    t         j                  j                  |       j                         }|S )zR
        Method to retrieve the payslip associated with this installment.
        installment_ids)Paysliprk   r   r  )rR   payslips     r(   installment_payslipzDeduction.installment_payslip  s)     //(((>DDFr*   c                    t         |           | j                  rd| _        | j                  s,| j
                  s | j                  st        t        d            | j                  s,| j
                  r | j                  st        t        d            | j                  r$| j
                  dv rt        dt        d      i      | j                  r$| j
                  dv rt        dt        d      i      | j                  r$| j
                  dv rt        dt        d	      i      | j                  sd | _
        nd | _        d | _	        | j                          | j                  r"| j                  t        d
t        d      i      | j                  r:| j                  r| j                   r| j"                  st        dt        d      i      | j                  0| j                  r#| j                  t        dt        d      i      y y y )NFr  zHEmployee rate must be specified for deductions that are not fixed amount)r=   rb   z7 Don't choose taxable gross pay when pretax is enabled.)r  z- Don't choose net pay when pretax is enabled.z. Don't choose net pay when the tax is enabled.r  zThis fields requiredr  zdIf condition based, all fields                             (field, value, condition) must be filled.r  r   )r   r   is_tax	is_pretaxr  rb   update_compensationr	   r%   r  r  clean_condition_based_onr  r  r  rV  r'   rX  r   s    r(   r   zDeduction.clean  s   ;;"DN}}==)A)A%` 
 }}tyy!^  >>dmm/DD!Q!  >>dmm{:!QNOP  ;;4==K7!QOPQ  }}DK DMDI%%'""*%'7;Q9R&STT""::TZZt~~%,aG/  ##+}};;&)8Q7O5P*QRR '  ,r*   c                 H    | j                   sd| _        d| _        d| _        yy)z\
        Clean the field, condition, and value attributes when not condition-based.
        N)r  rV  rX  r'   rQ   s    r(   r  z"Deduction.clean_condition_based_on)  s'     &&DJ!DNDJ 'r*   rL   c                 ,    t        | j                        S rN   r  rQ   s    r(   rS   zDeduction.__str__2  r  r*   c                     t         |           | j                  s>| j                  j	                         s#| j
                  sd| _        t         |           y y y y r  r  r   s    r(   r   zDeduction.save5  r  r*   )>rX   rY   rZ   r_   r%   r  r`   r  r
   ra   r~  r   r  rc   r  r  r   r  r  r  r  r  r  rV  rW  rX  r'   r  r  r   r)   r  rb   r8  r  employer_rater  r  r  r  r  r  r  r  r  rh   r   ri   rj   r  r   rk   is_installmentrR  r  r  r   r  rO   rS   r   r   r   s   @r(   r  r    s'   
 
an%	an% 
an%	an%	a 345	AiL!	O 
1,-.	q-./M
 Fq9Q7RSE$F$$4
M  3v2256MN 
 0//+,)@A /..*+((
	 !V  IJF
 $##Q
I -,,`
 F89E !   0t4I FLM	E +&** + !K.))%
 K
" #v""?@H
 V:56	F  vU
H 6
 '01	D &F%%
M (F''45)*M
 'V&&::;	N $6##$!1%@#AB
 ./	L !  #78	I $6###IJ	L "!!"> ?I $&##+S)TK "!!+Q)RI #""dUfnnJ  3v2255Q#%G(V((GN-v--:Sx  r*   r  c                   .    e Zd ZdZd ed      fd ed      fd ed      fd ed	      fgZ ej                  d
dd ed            Z ej                  dddd      Z	 ej                  eej                   ed            Z ej                         Z ej                         Z ej"                         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 ej                  ddde      Z ej4                  dd      Z ed      Z ej<                  ed      Z  e!de"g      Z#de$fdZ% fdZ& fdZ'd Z(d  Z)d! Z*d" Z+ G d# d$      Z, xZ-S )%r  z
    Payslip model
    r|   r}   review_ongoingzReview Ongoing	confirmed	ConfirmedpaidPaid2   Tz
Batch name)r@   rE   rA   rB   rC   F)r@   uniquerE   rA   r   r   r   )rE   rF   r   )r@   rE   rF   rD   r   rJ   r   r   rL   c                 T    d| j                    d| j                   d| j                   S )NPayslip for z - Period:  to r   r0   r1   rQ   s    r(   rS   zPayslip.__str__g  s.    d../{4??:K4PTP]P]__r*   c                 4   t         |           t        j                         }| j                  | j
                  k  rt        dt        d      i      | j                  |kD  rt        t        d            | j
                  |kD  rt        t        d            y )Nr1   z<The end date must be greater than or equal to the start datez%The end date cannot be in the future.z'The start date cannot be in the future.)r   r   r   r   r1   r0   r	   r%   )rR   r   r   s     r(   r   zPayslip.cleanj  s    

==4??*!V!  ==5 !!$K"LMM??U"!!$M"NOO #r*   c                 V   t         j                  j                  | j                  | j                  | j
                        j                         dkD  rt        t        d            t        | j                  t        t        f      st        t        d            t        | 8  |i | y )Nr  r,   z+Employee ,start and end date must be uniquez0The data must be in dictionary or querydict type)r  rk   r   r   r0   r1   r   r	   r%   
isinstancepay_head_datar   dictr   r   r   s      r(   r   zPayslip.savez  s    OO"" ,,?? #  eg "!$Q"RSS$,,y$.?@!!$V"WXXd%f%r*   c                 6    | j                   j                         S )B
        Method is used to get the full name of the owner
        )r   get_full_namerQ   s    r(   get_namezPayslip.get_name  s     --//r*   c                 ^    t        t        t        t        | dd      dd      dd      dd      S )r  r   Nr   rj   company)getattrrQ   s    r(   get_companyzPayslip.get_company  s>     mT:<PRVW
 
 	
r*   c                     | j                   r| j                   S | j                  | j                  k7  rd| j                   d| j                   S d| j                   S )zz
        Method to generate the title for a payslip.
        Returns:
            str: The title for the payslip.
        zPayslip r  r  )
group_namer0   r1   rQ   s    r(   get_payslip_titlezPayslip.get_payslip_title  s]     ????" $--/ t'tDMM?;	
  01	
r*   c                     | j                   j                  }| j                   j                  }t        j                  ||      d   S )Nr,   )r0   yearmonthcalendar
monthrange)rR   r  r  s      r(   get_days_in_monthzPayslip.get_days_in_month  s8    ##%%""4/22r*   c                       e Zd ZdZdgZy)Payslip.Metar}  z	-end_dateN)rX   rY   rZ   r_   r[   r\   r*   r(   r]   r    s    	
 
r*   r]   ).rX   rY   rZ   r_   r%   status_choicesr
   ra   r  	referencerh   r   ri   r   r   r0   r1   	JSONFieldr  r   contract_wager9   r;   	deductionr  r  rc   sent_to_employeer   rk   r  r  r  r"   r!   r   rO   rS   r   r   r  r  r  r  r]   r   r   s   @r(   r  r  @  s   
 
!G*	1-./	an%	6	N "!!D1\?J !  CDPTUI#&##FNN:K "!!#Jv!H$F$$&M%F%%4;M!!!tQ7I!!!tQ7I!!!tQ7IfT15GVD'>F +v**eD#$QRG,f,,YGO"
G` `P & 0

3

 
r*   r  c                       e Zd ZdZd ed      fd ed      fd ed      fgZ ej                  ded	      Z ej                  d
      Z	 ej                  eej                   ed            Z ej                  d ed            Z ej                          Z ej                  eej&                  dd      Z ej*                  dd      Z ej.                  ed      Z ej4                  dd      Z ej                  dd      Z ej                   ed      dd      Z ej<                   ed            Z ej                   d      Z  ej                  dd
d      Z! ej4                  d       Z" ejF                  d!      Z$ e%jL                  d"      r! ej                  d#ej                  ddd$      Z' e(d%      Z)d& Z*d' Z+ fd(Z,d) Z- fd*Z. xZ/S )+LoanAccountz>
    This modal is used to store the loan Account details
    loanLoanadvanced_salaryzAdvanced SalaryfinezPenalty / Fine   )rF   rD   r@   r   r   r   r   r   Amount)rF   rB   FT)rK   rJ   rE   rC   rE   r@   r  ry  zinstallment Amount)rB   rA   rE   zTotal installmentsr   z(From the start date deduction will apply)r   end_of_month)rF   r@   rJ   r   rG   assetzasset.Asset)rK   rA   rE   rJ   r   c                 8    | j                    d| j                   S )Nr   )r~  r   rQ   s    r(   rS   zLoanAccount.__str__  s    **S!1!1 233r*   c                     | j                   }| j                  }||z  }| j                  }i }|}i }t        |      D ]  }||t	        |      <   t        |      } |S )z
        Method to calculate installment schedule for the loan.

        Returns:
            dict: A dictionary representing the installment schedule with installment dates as keys
            and corresponding installment amounts as values.
        )loan_amountinstallmentsinstallment_start_dater.   rO   r   )rR   r  total_installmentsinstallment_amountr  installment_scheduleinstallment_dater%   s           r(   get_installmentszLoanAccount.get_installments  s     &&!..(+==!%!<!<!1!)* 	JA:L %5!6778HI	J $#r*   c                 d   | j                   j                         j                          | j                  | j                  j                          t        j
                  j                  t        | j                   j                  dd                  j                         st        |   |i | y)zG
        Method to delete the instance and associated objects.
        Nr   Tflatinstallment_ids__in)deduction_idsallr  allowance_idr  rk   r   r   r   r   r   r   s      r(   r  zLoanAccount.delete  s     	 '')($$&%% $T%7%7%C%CDt%C%T U & 

&( GND+F+r*   c                     | j                   }t        j                  j                  | j                  j                               j                         }|sy||z  dz  S )zk
        Method to calculate the ratio of paid installments to total installments in loan account.
        r  r   r7  )r  r  rk   r   r  r	  r   )rR   r  installment_paids      r(   installment_ratiozLoanAccount.installment_ratio  s^     ".."??11 $ 2 2 6 6 8 2 

%' 	   #55<<r*   c                 ~    | j                   rt        j                         | _        nd | _        t	        |   |i | y rN   )settledr   r   settled_dater   r   r   s      r(   r   zLoanAccount.save  s1    << (D $Dd%f%r*   )0rX   rY   rZ   r_   r%   	loan_typer
   ra   typer~  rh   r   ri   r   r   r  r   provided_daterZ  SET_NULLr
  re   rg   r  r  r  rc   r  r  r  r   r  r  apply_onr  r  r  r   r   asset_idr   rk   rS   r  r  r  r   r   r   s   @r(   r  r    s   
 
6	A/01	#$%I
 6FI"MDF+E#&##FNN:K $&##AAhKHK$F$$&M$6$$V__u4L #&""=K*F**9uEM"v""4%@H6Q7D***+,Dt '6&&A6J4KLL-V--<  v2PUVH!f!!%0G'6''T2Lt!$6$$nn
 $$QRG4$.
=& &r*   r  c                 2   t               }| j                   d| |_        d|_        ||_        d|_        ||_        d|_        d|_        |j                          d|_        |j                  j                  | j                         |j                          |S )Nr   FT)r  r~  r  r  r  r  r  r  r   r  addr   )r  r  r   installments       r(   _create_deductionsr  %  s    +K#>>*#dV4K+0K(KK $K+/K(!%K+0K(""&&x';';<r*   c                    g }d}t        j                  d      r|j                  dnd}|r|r|j                  dk7  rt	               }|j
                  |_        |j                  |_        d|_        |j
                  |_        d|_	        d|_
        |j                  |_        d|_        |j                          d|_        |j                  j!                  |j"                         |j                          ||_        t&        t(        |;          y|j*                  j-                  dd      }t.        j0                  j3                  |      }|D 	cg c]$  }	|j3                  |		      j5                         s|	& }
}	|j7                         }|s|j8                  s~t:        j0                  j3                  |
      j=                          |j?                         D ]#  \  }}tA        |||      }|jC                  |       %  |j*                  j                   |  y|j8                  r/t:        j0                  j3                  |

      j=                          y|
s|j?                         D ]i  \  }}t:        j0                  j3                  ||j"                  d|j                        j5                         rLtA        |||      }|jC                  |       k  |j*                  j                   |  yyc c}	w )z+
    Post save method for loan account
    Tr  NFr  r   r  r  r  )id__in)r  r  r  r~  )"r   r   r  r  rZ  r  r  r~  r  r  r  r  r  r  r   r  r  r   r
  r   r  r  r   r  rk   r   r   r  r  r  r  itemsr  r/   )r  r  createdr   r  r  r  
deductionspayslips_with_deductionsdeduction_idbalance_deductioninstallment_dictr  r  r  s                  r(   create_installmentsr$  6  s   
 LE! ))1u5X]]f4{**^^
(-%**(,%%33		(-%##H$8$89		 $k8)+++7747H
#*??#9#9 * $: $
 
 !+
+22 , 3 fh 
 
 $446'0@0@$$J$7>>@ "'')1  "002B ##K01 'H""&&5$$,=$>EEG % &++-9 $&$,,33&6+3+?+?'+&nn	 4 
 fh '9$&8:J' %++K89  +&&**L9# %9
s   )K)c                   X    e Zd ZdZ ej
                  d      Z ej                         Zy)ReimbursementMultipleAttachmentz0
    ReimbursementMultipleAttachement Model
    payroll/reimbursementsr   N)	rX   rY   rZ   r_   r
   r   
attachmentManagerrk   r\   r*   r(   r&  r&    s*     "!!,DEJfnnGr*   r&  c            	       F    e Zd ZdZd ed       fd ed      fgZ ej                  d      rej                  d ed      f       d ed	      fd
 ed      fd ed      fgZ	 e
j                  d      Z e
j                  edd      Z e
j                  ee
j                   d      Z e
j$                         Z e
j(                  dd      Z e
j,                  edd      Z ej                  d      r' e
j                  de
j                   dd ed            Z e
j4                  d ed       ed            Z e
j4                  d ed        ed!            Z e
j:                  d ed"       ed#            Z e
j4                  d$      Z e
j                  d%e	dd&      Z  e
j                  ee
jB                  dd'd(      Z" e
jF                  dd)*      Z$ e
j                  e%e
jB                  dd+      Z& e'd,      Z( G d- d.      Z)d2 fd/Z* fd0Z+d1 Z, xZ-S )3Reimbursementz
    Reimbursement Model
    reimbursementbonus_encashmentzBonus Point Encashmentr"  leave_encashmentzLeave Encashment	requested	Requestedr'  ApprovedrejectedRejectedr  r      )rD   r@   rF   r   r   r'  T)r   rE   Frz  zleave.LeaveTypez
Leave type)rK   rA   rE   rB   r   zAvailable Days to encashzAvailable days)rF   r   rB   zCarry Forward Days to encashzCarry forward dayszBonus points to encashzBonus pointsr   rq  )r@   rD   rF   rJ   approved_by)rK   rE   r   rJ   rC   r  )rK   rE   rJ   r   c                       e Zd ZdgZy)Reimbursement.MetarV   NrW   r\   r*   r(   r]   r8    r^   r*   r]   c                 
   t        t        j                  dd       }t        j                  j                         r(t        j                  j                         j                  nd}t        j                  j                         r(t        j                  j                         j                  nd}|j                  j                  d      }|s|j                  j                  | _        | j                  dk(  r| j                  t        ddi      | j                  dk(  r| j                  t        ddi      | j                  dk(  r| j                   d	k(  r!| j"                  | j$                  z   |z  | _        t)        t+        | j"                  d
z        d
z  d      | _        t)        t+        | j$                  d
z        d
z  d      | _        | j                  j,                  j/                  | j                        j                         }| j                  dk(  r#| j                   d	k(  r| j0                  |z  | _        | j                   dk7  s| j2                   t5        | l  |i | | j                   dk(  rg| j2                  Z| j                  dk(  rd}nr| j                  dk(  rd}t8        j                  j;                  | j                        }	|	j<                  | j0                  k\  r9d}|	xj<                  | j0                  z  c_        d|	_        |	j7                          nt        t        j                  dd       }|rtA        jB                  |d       nd}r|jD                  }
|jF                  }|
| j$                  k\  rJ|| j"                  k\  r;d}|
| j$                  z
  |_"        || j"                  z
  |_#        |j7                          n<t        t        j                  dd       }|rtA        jB                  |tI        d             |rtK               }| jL                  |_'        | jP                  |_(        d|_)        d|_*        | j&                  |_        |j7                          d|_*        |jV                  jY                  | j                         |j7                          || _        |r#|j                  j                  | _-        nd	| _        t5        | l  |i | y | j                   dk(  r| j2                  }| j"                  }| j$                  }
| j                  dk(  rUr8|jD                  |
z   |_"        |jF                  |z   |_#        |j7                          | j2                  j]                          y y y y y )Nrequestr,   zpayroll.change_reimbursementr-  r)  r   r/  leave_type_idr0  r  r   r   r.  r'  TFzbonus points has been redeemed.z9The employee don't have that much bonus points to encash.zrThe employee don't have that much leaves                                         to encash in CFD / Available daysr3  zleave encashment)/r  r   _thread_localsEncashmentGeneralSettingsrk   r  leave_amountbonus_amountuserhas_permemployee_getr   r  r)  r	   r;  r  cfd_to_encashad_to_encashr  maxroundemployee_available_leaver   bonus_to_encashr
  r   r   r   getpointsreasonr   infoavailable_dayscarryforward_daysr%   rZ  allowance_onr  r~  r  r  r  r  r6  r  )rR   r   r   r:  amount_for_leaveamount_for_bonusrA  assigned_leaveproceedbonus_pointsrM  rN  r-  cfd_daysr   s                 r(   r   zReimbursement.save  s   -<<iN )00668 &--335BB 	 )00668 &--335BB 	 <<(()GH&||88D99'DOO,C!<1I"JKK99**t/A/A/I!?4L"MNN99**{{k)&&):)::$% "%eD,>,>,B&Ca&G!!LD #U4+<+<q+@%AA%E JD!//HHOO ,, P eg  99**{{k)#337GG;;*$(9(9(AGL$)&){{j(T->->-F99/"GYY"44#G#-#5#5#9#9dFVFV#9#WL#**d.B.BB"&$++t/C/CC+.O+$))+")/>>	4# #$MM ' [
 $G%)7)F)F,:,L,L)*d.?.?? 1T5G5G G&*G .1B1B B +9 !2D4F4F F +< +//1&- 3 B BIt'G  ' ($+$%)K%&!" $-KM262C2CM/*.**M'=AM:=BM:+/;;M(!&&(=BM:!44889I9IJ!&&((5D%+2<<+D+D("-DKd-f-
*t/@/@/L--!%!2!299 22%*99NJ '5 +<<xG '8 '++-%%,,. 3 0M*K )Br*   c                 N   t        t        j                  dd       }| j                  dk(  r.t	        j
                  |t        | j                   d            }|S | j                  r?| j                  j                          t        | $  |i | t	        j                  |d      }S )Nr:  r'  z> is in approved state,                    it cannot be deletedzReimbursement deleted)r  r   r<  r  r   rL  r%   r~  r
  r  r   success)rR   r   r   r:  r  r   s        r(   r  zReimbursement.deleteL  s    -<<iN;;*$mmzzl #) *G    !!((*//"**74KLr*   c                     | j                    S rN   )r~  rQ   s    r(   rS   zReimbursement.__str__^  s    **r*   )rL   N).rX   rY   rZ   r_   r%   reimbursement_typesr   r   r/   status_typesr
   ra   r~  r  rh   r   ri   r   r   rO  r   r)  r  r&  other_attachmentsr;  r   rD  rC  r   rH  r  r  r  r6  re   rg   rZ  r
  r   rk   r]   r   r  rS   r   r   s   @r(   r,  r,    s{   
 
!O,-	Q789
 t!""$6:L8M#NO 
an%	Qz]#	Qz]#L
 F+E6#OD $&##FNNK $6##%L!!!,D4PJ...'te t!)))nn<
 %6$$./'(L
 &F%%23+,M
 *f)),-~&O
 Vq)FV|[5F $&##//"K #&""=K$6$$V__4%L $$QRG s/j$r*   r,  canceled)r  r3  c                   T    e Zd Z ej                  d      Z ej                         Zy)ReimbursementFilezpayroll/request_filesr(  N)rX   rY   rZ   r
   r   filer*  rk   r\   r*   r(   r^  r^  j  s#    6&=>DfnnGr*   r^  c                   (   e Zd ZdZ ej
                  eej                        Z ej
                  e	ej                        Z
 ej                  d ed      d      Z ej                  ed      Z ej"                  d ed      d	      Zd
efdZy)ReimbursementrequestCommentz+
    ReimbursementRequestComment Model
    )rK   TCommentrC   )rE   rB   r@   )rA   z
Created At)auto_now_addrB   rE   rL   c                     | j                    S rN   )commentrQ   s    r(   rS   z#ReimbursementrequestComment.__str__~  s    ,, r*   N)rX   rY   rZ   r_   r
   rh   r,  CASCADE
request_idr   r   re   r%   re  r  r^  filesr  
created_atrO   rS   r\   r*   r(   ra  ra  o  s     #""=FNNKJ#&##HGKfDq|PSTG"F""#4DAE%%%|_J! !r*   ra  c                   z    e Zd ZdZ ej
                  degd      Z ej                  e	ej                  d      Zy)PayrollGeneralSettingz
    PayrollGeneralSetting
    zNotice period in daysr?   )r   r   rF   T)rK   rE   N)rX   rY   rZ   r_   r
   r   r)   notice_periodrh   r   rf  rj   r\   r*   r(   rk  rk    sB     (F''):M
 #""7fnn4PJr*   rk  c                       e Zd ZdZ ej
                  d      Z ej
                  ddd      Z ej                         Z	y)r=  z)
    BonusPointGeneralSettings model
    r,   r   Tr  )rA   rE   rB   N)
rX   rY   rZ   r_   r
   r   r?  r>  r*  rk   r\   r*   r(   r=  r=    s?     '6&&q1L&6&&T8TLfnnGr*   r=  zlast dayzLast Day)11st)22nd)33rd)44th)55th)66th)77th)88th)99th)1010th)1111th)1212th)1313th)1414th)1515th)1616th)1717th)1818th)1919th)2020th)2121th)2222th)2323th)2424th)2525th)2626th)2727th)2828th)2929th)3030th)3131thc                        e Zd ZdZ ej
                  deddd      Z ej                  d      Z	 ej                  eej                  d	d	d
      Zd Z fdZdefdZ xZS )PayslipAutoGeneratez4
    Model for generating payslip automatically
    r?   rn  zPayslip Generate Dayz5On this day of every month,Payslip will auto generate)r@   rD   rF   rB   r   Fr   Tr   rl  c                 V   | j                   st        j                  j                  d       j	                         rn| j
                  st        ddi      t        j                  j                  d       j                         }|j
                  | j
                  k7  rt        ddi      y y y )N)rj   rj   z9Auto payslip generation for all company is already exists)rj   r  rk   r   r   r   r	   r  )rR   all_company_auto_payslips     r(   r   zPayslipAutoGenerate.clean  s     #++22d2CJJL77%$&a 
 (;'B'B'I'I (J (eg % (**dgg5%$&a  6 M  r*   c                 V    ddl m} | j                  r |        t        |   |i | y )Nr   )auto_payslip_generate)payroll.schedulerr  auto_generater   r   )rR   r   r   r  r   s       r(   r   zPayslipAutoGenerate.save  s&    ;!#d%f%r*   rL   c                 :    | j                    d| j                   dS )Nz |  )generate_dayrj   rQ   s    r(   rS   zPayslipAutoGenerate.__str__  s!    ##$C'8::r*   )rX   rY   rZ   r_   r
   ra   DAYSr  rc   r  OneToOneFieldr   rf  rj   r   r   rO   rS   r   r   s   @r(   r  r    sv     $6##+IL (F''6M%%%6>>DyJ,&; ;r*   r  )_r_   r  loggingr   r   r   djangor   django.appsr   django.contribr   django.core.exceptionsr	   	django.dbr
   django.db.models.signalsr   r   r   django.dispatchr   django.httpr   django.utilsr   django.utils.translationr   r%   base.horilla_company_managerr   base.methodsr   base.modelsr   r   r   r   r   r   r   !employee.methods.duration_methodsr   employee.modelsr   r   r   horillar   horilla.modelsr    horilla_audit.modelsr!   r"   	getLoggerrX   r   r)   r6   r8   rm   Modelr   r   attendance.modelsr  r
  r!  leave.modelsr#  r%  r5  r8  rW  r  r  rR  rZ  r  r  r  r  r$  r&  r,  rk   r   r   updater^  ra  rk  r=  r  r  r\   r*   r(   <module>r     s  
   . .   # 2  D D $ ! ! 6 > 1   > I I ' ' B			8	$D4'< 'TCV| CVL?
 ?
D 4\",J#Z J#X j,
 -
 4W)F| F^ 
(23 4.? ao#$%	1_	1 !	1)*+	1,-.!J-   ao#$%	1_	1 !	1)*+	1,-.aj  :q)*+1\?#%q)='>?q{)aj"Ao$67+/+Q/G-HI &X Xv
^ ^B	x
l x
vg&, g&T" 
)K(K: )K:\fll QL Qj	##:#6==?$$J$7>>j>Q
 
!, !&
QFLL 
Q !:!! ! 	!
 ! ! ! ! ! ! ! ! ! ! !  !!" #!$ %!& '!( )!* +!, -!. /!0 1!2 3!4 5!6 7!8 9!: ;!< =!> ?!@ A!H0;&,, 0;o	s   AN N