
    si2E                    "   d Z ddl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 dd
l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$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 ddl6m7Z7m8Z8 ddl9m:Z:  ejv                  e<      Z=d Z>d Z? G d de4      Z@ G d de4      ZA G d dej                        ZC e
j                  d       rdd!lEmFZF  e
j                  d"      rdd#lGmHZH  G d$ d%eH      ZId& ZJd' ed(      fd) ed*      fd+ ed,      fd- ed.      fd/ ed0      fd1 ed2      fd3 ed4      fgZKd' ed(      fd) ed*      fd+ ed,      fd- ed.      fd/ ed0      fd1 ed2      fd5 ed6      fgZLd7 ed8      fd9 ed:      fd; ed<      fd= ed>      fd? ed@      fdA edB      fdC edD      fdE edF      fdG edH      fdI edJ      fg
ZM G dK dLej                        ZN G dM dNe4      ZO G dO dPe4      ZP G dQ dRe4      ZQ G dS dTe4      ZR G dU dVej                        ZS G dW dXe4      ZT G dY dZej                        ZU G d[ d\e4      ZV G d] d^ej                        ZW G d_ d`ej                        ZXg da edb      fdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~dddZY G d dej                        ZZy)z#
models.py
Used to register models
    N)datedatetime	timedelta)forms)apps)messages)ValidationError)models)	QueryDict)reversereverse_lazy)timezone)format_html)gettext_lazy)HorillaCompanyManager)get_next_month_same_date)Company
DepartmentEmployeeShiftJobPositionJobRoleWorkTypevalidate_time_format)strtime_seconds)
BonusPointEmployeeEmployeeWorkInformation)horilla_middlewares)_thread_locals)HorillaModelupload_path)HorillaAuditInfoHorillaAuditLogrender_templatec                 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    9/var/www/python-projects/worksol/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)ranger0   r   append)
start_dateend_date	date_listdeltaicurrent_dates         r+   get_date_ranger9   7   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d Zd Z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)rC   choicesnullrD   defaultrE   zPython Code)rE   rI   TrH   Description)rD   rE   rC   rH   editable	on_deletereturnc                 ,    t        | j                        S N)strfiling_statusselfs    r+   __str__zFilingStatus.__str__t   s    4%%&&r-   c                 4    t        dd| j                  i      S )J
        Returns the URL for updating the filing status instance.
        zfiling-status-updatepkkwargsr   rY   rT   s    r+   get_update_urlzFilingStatus.get_update_urlw   s     -tTWWoFFr-   c                 4    t        dd| j                  i      S )rX   ztax-bracket-createfiling_status_idrZ   r\   rT   s    r+   get_create_urlzFilingStatus.get_create_url}   s     +5G4QRRr-   c                 6    t        d       d| j                   S )rX   generic-deletez?model=payroll.FilingStatus&pk=r\   rT   s    r+   get_delete_urlzFilingStatus.get_delete_url   s!     *+,,KDGG9UUr-   c                   2    e Zd ZdgZ ed      Z ed      Zy)FilingStatus.Meta-idFiling StatuszFiling StatusesN)__name__
__module____qualname__orderingr(   rE   verbose_name_plural r-   r+   Metare      s    7) 12r-   rn   N)rh   ri   rj   __doc__r(   based_on_choicer
   	CharFieldrS   based_onBooleanFielduse_py	TextFieldpython_codedescription
ForeignKeyr   PROTECT
company_idr   objectsrR   rV   r]   r`   rc   rn   rm   r-   r+   r;   r;   Q   s   
 
an%	an%	a 345O
 %F$$'M
  v#z]H !V  mUKF"&""-K"&""}%K
 #""dUfnnJ $%G' 'GSV3 3r-   r;   c            
       n    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\                  e/d%d%>      Z0 ejb                  d% ed?       ed@      A      Z2 ejb                  d% edB       edC      A      Z3 ej:                  d%d%d. edD      E      Z4 ejj                  d%d%dFG      Z6 e7dHe8gI      Z9 e:dJ      ZdK Z;dL Z<dM Z=dN Z>dO Z?dP Z@dQ ZAdR ZBdS ZCdT ZDdU ZEdV ZFdWeGfdXZHdY ZI fdZZJ G d[ d\      ZK xZLS #  Y xY w)]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idrS      zContract Title.)rC   	help_textrE   contract_setr   )rN   related_namerE   z
Start DaterE   TzEnd Date)rH   rD   rE   	Wage Type)rG   rC   rI   rE      Pay Frequency)rC   rH   rG   rI   rE   zBasic Salaryr   )rE   rH   rI   	contractsrg   )rN   r   rH   rD   rE   Statusr   )rN   rH   rD   r   rE   zJob PositionzJob RoleShift	Work TyperB   zNotice period in total days.zNotice Period)rI   r   
validatorsrE   )	upload_torH   rD   zDeduct From Basic Payz'Deduct the leave amount from basic pay.rI   rE   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)rH   rD   rI   rE   rF   )rH   rD   rC   history_setr   bases+employee_id__employee_work_info__company_idc                 ^    t        | j                        j                  | j                        S )z#
        Display wage type
        )dictWAGE_CHOICESget	wage_typerT   s    r+   get_wage_type_displayzContract.get_wage_type_display*  s$     D%%&**4>>::r-   c                 ^    t        | j                        j                  | j                        S )z'
        Display pay frequency
        )r   PAY_FREQUENCY_CHOICESr   pay_frequencyrT   s    r+   get_pay_frequency_displayz"Contract.get_pay_frequency_display0  s&     D../33D4F4FGGr-   c                 ^    t        | j                        j                  | j                        S z 
        Display status
        )r   CONTRACT_STATUS_CHOICESr   contract_statusrT   s    r+   get_status_displayzContract.get_status_display6  s&     D00155d6J6JKKr-   c                      t        dd| i      S )z
        status column
        zcbv/contracts/status.htmlinstancepathcontextr$   rT   s    r+   
status_colzContract.status_col<  s     ,&
 	
r-   c                      t        dd| i      S )z 
        Detail actions
        z cbv/contracts/detail_action.htmlr   r   r$   rT   s    r+   detail_actionzContract.detail_actionE  s     3&
 	
r-   c                      t        dd| i      S )z
        Note column
        zcbv/contracts/note.htmlr   r   r$   rT   s    r+   note_colzContract.note_colN  s     *&
 	
r-   c                      t        dd| i      S )z!
        Document column
        zcbv/contracts/document.htmlr   r   r$   rT   s    r+   document_colzContract.document_colW  s     .&
 	
r-   c                      t        dd| i      S )z 
        actions column
        zcbv/contracts/actions.htmlr   r   r$   rT   s    r+   actions_colzContract.actions_col`  s     -&
 	
r-   c                      t        dd| i      S )z:
        Action column for Calculate Leave Amount
        z#cbv/contracts/cal_leave_amount.htmlr   r   r$   rT   s    r+   cal_leave_amountzContract.cal_leave_amounti  s     6&
 	
r-   c                     | j                   j                  j                   d| j                   j                  j                   S )z&
        Detail view subtitle
        z /
          employee_idemployee_work_infodepartment_idjob_position_idrT   s    r+   conract_subtitlezContract.conract_subtitler  sF    
 $$77EEG H//??
@D 	Dr-   c                 8    t        dd| j                  i      }|S )
        detail view
        zcontracts-detail-viewrY   rZ   r\   rU   urls     r+   contracts_detailzContract.contracts_detailz      
 -tTWWoF
r-   c                     | j                   ryy)z4
        Deduct leave from basic pay column
        YesNo)deduct_leave_from_basic_payrT   s    r+   deduct_leave_from_basic_pay_colz(Contract.deduct_leave_from_basic_pay_col  s     ++r-   rO   c                 R    | j                    d| j                   d| j                   S )Nz - - )contract_namecontract_start_datecontract_end_daterT   s    r+   rV   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   r   r   r   r/   4An active contract already exists for this employee.r   2A draft contract already exists for this employee.)r   r   deduction_for_one_leave_amountThis field is required)r   r   r	   r(   r   r}   r{   filterr   excluderY   countr   r   calculate_daily_leave_amountr   rT   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   r{   r   r   exists
departmentr   r   job_positionr   job_rolejob_role_id	work_typework_type_idshiftshift_idr   r   todayr   r}   r   r   r   r   r	   r(   rY   supersavewageintbasic_salary
ValueErrorloggererror	Exception)rU   argsr[   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)rh   ri   rj   ro   unique_togetherrm   r-   r+   rn   r    s    	 Vr-   rn   )Mrh   ri   rj   ro   r(   COMPENSATION_CHOICESr   r   r   is_installedr2   r   listr;   r{   values_listFILING_STATUS_CHOICESr
   rq   r   rx   r   ry   r   	DateFieldr   r   r   r   
FloatFieldr   rS   r   r   r   r   r   r   r   r   r   r   r   IntegerFieldr,   notice_period_in_days	FileFieldr!   contract_documentrs   r   r   r   ru   noter#   r"   historyr   r   r   r   r   r   r   r   r   r   r   r   r   rR   rV   r   r   rn   __classcell__r  s   @r+   r}   r}      s   
 
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:'	 )((;TQUV"5&"5"5./=>#
 $76#6#656b
$  &7V%6%678	&" 6TcBD"
G $$QRG;HL





D^ ^$L8tV V{	s   (.N/ /N4r}   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)rC   rH   rD      )rC   rH   rG   r   rN   rE   )rH   rD   z00:00)rH   rD   r   rI   rC   r   )rH   rD   rI   rF   rC   rB   FrI   r   c                 V    t        j                         | _        t        |   |i | y rQ   )r   nowlast_updater   r   rU   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        g      ?z*Day percentage must be between 0.0 and 1.0)r   r   day_percentager	   r(   rU   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   rT   s    r+   rV   zWorkRecord.__str__1  s@     + 	
 ))*!DII;7	
r-   )&rh   ri   rj   ro   r(   rG   r
   rq   r1  r2  rx   r   ry   r   r  r   r   at_workmin_hourr  at_work_secondmin_hour_secondru   r  messagers   is_attendance_recordis_leave_recordr  r-  DateTimeFieldr)  r   r{   r   r   rV   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   )
Attendanceleave)LeaveRequestc                       e Zd ZdZy)OverrideLeaveRequestz@
        Class to override Attendance model save method
        N)rh   ri   rj   ro   rm   r-   r+   r?  r?    s    	 	r-   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_validatorrB    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Containsr1   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
    rF   r%  TrC   rG   rH   rD   6The value must be like the data stored in the databaserC   rH   rD   r   N)rh   ri   rj   ro   r
   rq   fieldCONDITION_CHOICE	conditionr(   r*   rm   r-   r+   r\  r\  "  sb     FE !   0t4I FLM	Er-   r\  c            
       8	    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 ZAdQ ZBdR ZCdS ZDdT ZEdU ZFdV ZGdW ZHdX ZIdY ZJdZ ZKd[ ZLd\ ZMd] ZNd^ ZOd_ ZPd` ZQda ZRdb ZSdc ZTdd ZUde ZV fdfZWdg ZXdheYfdiZZ fdjZ[ xZ\S )k	Allowancez
    Allowance model
    ignorezExclude the allowance
max_amountProvide max amountr<   r=   rL  rM  r   overtimeOvertimer   r   r   r   r;  rF   FzTitle of the allowancer_  Tz{The one-time allowance in which the allowance will apply to the payslips             if the date between the payslip periodrH   rD   r   Include all active employeesz7Target allowance to all active employees in the companyr   Employees Specificallowance_specificz*Target allowance to the specific employees)rE   rD   r   r   Exclude Employeesallowance_excludedzqTo ignore the allowance to the employees when target them by all employees             or through condition-basedrE   r   rD   r   z6This field is used to calculate the taxable allowancesrI   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rC   rG   rH   rD   r   r]  r^  z)To specify, the allowance is fixed or notzFixed amount for this allowancerH   rD   r   r   zGIf the allowance is not fixed then specifies how the allowance provided)rC   rI   rG   rH   rD   r   The percentage of based onr,  z8The attendance fixed amount for one validated attendance)rH   rD   rI   r   r   zThe fixed amount per childrenrN   rH   rD   rE   z=The fixed amount for one validated attendance with that shift)rH   rI   rD   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 ?rC   rH   rI   rG   r   
   !The pay head for the if conditionrC   rG   rI   r   rF  3Apply for those, if the pay-head conditions satisfyThe amount of the pay-head&The start amount of the pay-head rangerD   rH   r   $The end amount of the pay-head rangerL   rI   rM   rD   rM   c                        e Zd ZdZ ed      Zy)Allowance.Meta3
        Meta class for additional options
        rd  N)rh   ri   rj   ro   r(   rE   rm   r-   r+   rn   r    s    	 ~r-   rn   c                     | j                   j                         }dj                  |D cg c]  }t        |       c}      }|S c c}w )A
        Get all specific employees separated by commas.
        <br>specific_employeesalljoinrR   rU   	employeesemployeeemployee_names_strings       r+   get_specific_employeesz Allowance.get_specific_employees$  sB    
 ++//1	 &9,UxS],U V$$ -V   Ac                     dj                  | j                  j                         D cg c]  }t        |       c}      S c c}w )r  z, )r  exclude_employeesr  rR   )rU   r  s     r+   get_exclude_employeeszAllowance.get_exclude_employees-  s4    
 yy8N8N8R8R8TUH#h-UVVUs   Ac                 "    | j                   rdS dS )z4
        method to return is taxable or not
        r   r   )
is_taxablerT   s    r+   get_is_taxable_displayz Allowance.get_is_taxable_display4  s     u1T1r-   c                 "    | j                   rdS dS )z<
        method to return is condition based or not
        r   r   is_condition_basedrT   s    r+   get_is_condition_basedz Allowance.get_is_condition_based:  s     //u9T9r-   c                 "    | j                   rdS dS )z+
        method to return is fixed
        r   r   is_fixedrT   s    r+   get_is_fixedzAllowance.get_is_fixed@  s     u/4/r-   c                 ^    t        | j                        j                  | j                        S )z5
        method to return get based on field
        r   rp   r   rr   rT   s    r+   get_based_on_displayzAllowance.get_based_on_displayF  $     D(()--dmm<<r-   c                 8    t        dd| j                  i      }|S )r   zallowance-detail-viewrY   rZ   r\   r   s     r+   allowance_detail_viewzAllowance.allowance_detail_viewL  r   r-   c                     t        d      }|S )z>
        to get the delete url for card action delete
        rb   r   r   s     r+   rc   zAllowance.get_delete_urlU      
 +,
r-   c                 8    t        dd| j                  i      }|S )z>
        to get the update url for card action update
        zupdate-allowanceallowance_idrZ   r\   r   s     r+   r]   zAllowance.get_update_url^  s    
 (.$''1JK
r-   c                      t        dd| i      S )z6
        This method to get allowance actions
        z-cbv/allowance_deduction/allowance_action.htmlr   r   r$   rT   s    r+   get_allowance_actionszAllowance.get_allowance_actionsf  s    
 @&
 	
r-   c                 x    t        j                  dd| j                        }|j                  dd      }d| d}|S za
        Method will return the API URL for the avatar or the path to the profile image.
        z[^a-zA-Z0-9\s]r    +z!https://ui-avatars.com/api/?name=z&background=randomresubtitlereplacerU   sanitized_titler   s      r+   
get_avatarzAllowance.get_avatarp  B     &&!2B

C)11#s;1/1BBTU
r-   c                 <    | j                   rd| j                    dS y)z1
        method to return one time field
        z$On <span class="dateformat_changer">z</span>r   one_time_daterT   s    r+   one_time_date_displayzAllowance.one_time_date_displayy  s&     9$:L:L9MWUUr-   c                 R    t        t              j                  | j                        S )z=
        get field choice dict if based on condition
        r   FIELD_CHOICEr   r`  rT   s    r+   get_field_displayzAllowance.get_field_display       L!%%djj11r-   c                 R    t        t              j                  | j                        S )zA
        get condition choice dict if based on condition
        r   ra  r   rb  rT   s    r+   get_condition_displayzAllowance.get_condition_display       $%))$..99r-   c                     | j                   r2| j                         }| j                          d| d| j                   S y)z?
        method to return condition if condition based
        r  r   )r  r  r  r*   )rU   condition_displays     r+   condition_based_displayz!Allowance.condition_based_display  sF     "" $ : : <,,./q1B0C1TZZLQQr-   c                      t        dd| i      S )z6
        custome template for retrieve amount
        z4cbv/allowance_deduction/allowance/custom_amount.htmlr   r   r$   rT   s    r+   based_on_amountzAllowance.based_on_amount       G&
 	
r-   c                      t        dd| i      S )z@
        custom template to retrive allowance max limit
        z4cbv/allowance_deduction/allowance/max_limit_col.htmlr   r   r$   rT   s    r+   cust_allowance_max_limitz"Allowance.cust_allowance_max_limit  r  r-   c                     | j                   r9t        | j                        j                  | j                   | j                         S dS +
        for allowance eligibility
        r   )	if_choicer   if_condition_choicer   rT   s    r+   get_if_choice_displayzAllowance.get_if_choice_display  s?     ~~ ))*..t~~t~~N	
 	
r-   c                     | j                   r3t        t              j                  | j                   | j                         S dS r  )if_conditionr   IF_CONDITION_CHOICEr   rT   s    r+   get_if_condition_displayz"Allowance.get_if_condition_display  s@        $%))$*;*;T=N=NO	
 	
r-   c                 z    t        d       d| j                          d| j                          d| j                   S )r  Ifr  )r(   r  r  	if_amountrT   s    r+   allowance_eligibilityzAllowance.allowance_eligibility  sB     D'!D66894;X;X;Z:[[\]a]k]k\lmmr-   c                      t        dd| i      S )z@
        custom template to retrive detail view actions
        z:cbv/allowance_deduction/allowance/detail_view_actions.htmlr   r   r$   rT   s    r+   allowance_detail_actionsz"Allowance.allowance_detail_actions  s     M&
 	
r-   c                 B    g d}|D ]  }t        | |d        d| _        y)z5Reset the this fields when is_fixed attribute is true)	rr   rateper_attendance_fixed_amountr   shift_per_attendance_amountamount_per_one_hrr   work_type_per_attendance_amountmaximum_amountNF)setattrhas_max_limit)rU   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.r<   z9Rate must be specified for allowances based on basic pay.zHIf condition based, all fields (field, value, condition) must be filled.r   rr   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.rL  z'The amount per children must be filled.r   amountz#Amount should be greater than zero.r  r   )r   r   clean_fixed_attributesr  r`  rb  r*   r  rr   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  rT   s    r+   r  z Allowance.clean_fixed_attributes  sH    }}DK=={{"%x3K1L&MNN! r-   rO   c                 ,    t        | j                        S rQ   rR   r  rT   s    r+   rV   zAllowance.__str__      4::r-   c                     t        t        j                  dd       }|j                  j	                  d      }| j
                  s!|r|dk7  rt        j                  |      | _        t        | )          y Nrequestselected_companyr  getattrr   r   sessionr   r   r   findrz   r   r   rU   r  r  r  s      r+   r   zAllowance.save  Z    -<<iN"??../ABww+0@E0I%ll+;<DOr-   )]rh   ri   rj   ro   r(   exceed_choicerp   r   r
  attendance_choicesr  r
   rq   r  r  r  rs   include_active_employeesManyToManyFieldr   r  r  r  r  r  r`  ra  rb  r*   r  r  r,   r  rr   rB  r  r  r  rx   r   ry   r   r  r  r   r   r  r  r  maximum_unitr  r  r  r  start_range	end_ranger   rz   only_show_under_employeeis_loanr   r{   r\  other_conditionsrn   r  r  r  r  r  r  r  rc   r]   r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  rR   rV   r   r  r  s   @r+   rd  rd  5  sa   
 
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--& &%W2:0=
2:



n
#"2'h"  r-   rd  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 Z7dJ Z8dK Z9dL Z:dM Z;dN Z<dO Z=dP Z>dQ Z?dR Z@dS ZAdT ZBdU ZCdV ZDdW ZEdX ZFdY ZGdZ ZHd[ ZId\ ZJd] ZK fd^ZLd_ ZMd`eNfdaZO fdbZP xZQS )c	Deductionz
    Deduction model
    r<   r=   r>   r?   r@   rA   net_payzNet Payre  zExclude the deductionrf  rg  rF   zTitle of the deduction)rC   r   Tz{The one-time deduction in which the deduction will apply to the payslips             if the date between the payslip periodrj  Frk  z7Target deduction to all active employees in the companyr   rl  deduction_specificz*Target deduction to the specific employees)rE   r   r   rD   rn  deduction_excludezqTo ignore the deduction to the employees when target them by all employees             or through condition-basedrp  z3To specify the deduction is tax or normal deductionrq  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 informationrr  rs  r]  r^  r_  r{  z	Basic payzoUpdate compensation is used to update                    pay-head before any other deduction calculation starts)rH   rD   rC   rG   r   z)To specify, the deduction is fixed or notzFixed amount for this deductionrt  zGIf the deduction is not fixed then specifies how the deduction providedr,  zEmployee rateru  )rH   rD   rI   r   rE   r   )rI   r   zHas max limit for deductionzLimit the deductionz$The maximum amount for the deductionr   rw  rx  ry  rz  r|  r}  rF  r~  r  r  r  r  rL   r  r  c                 b    t         j                  j                  |       j                         }|S )zR
        Method to retrieve the payslip associated with this installment.
        )installment_ids)Payslipr{   r   first)rU   payslips     r+   installment_payslipzDeduction.installment_payslip  s)     //(((>DDFr-   c                 "    | j                   rdS dS Nr   r   )	is_pretaxrT   s    r+   get_is_pretax_displayzDeduction.get_is_pretax_display  s    u0D0r-   c                 "    | j                   rdS dS r  r  rT   s    r+   get_is_condition_based_displayz(Deduction.get_is_condition_based_display  s    //u9T9r-   c                 "    | j                   rdS dS r  r  rT   s    r+   get_is_fixed_displayzDeduction.get_is_fixed_display  s    u/4/r-   c                 ^    t        | j                        j                  | j                        S z#
        Display work type
        r  rT   s    r+   r  zDeduction.get_based_on_display  r  r-   c                 R    t        t              j                  | j                        S )z
        Field column
        r  rT   s    r+   r  zDeduction.get_field_display  r  r-   c                 R    t        t              j                  | j                        S )z*
        condition display column
        r  rT   s    r+   r  zDeduction.get_condition_display	  r  r-   c                 |    | j                   r0| j                          d| j                          d| j                   S y)z(
        Condition based column
        r  r   )r  r  r  r*   rT   s    r+   condition_bsed_colzDeduction.condition_bsed_col  sB     "",,./q1K1K1M0NaPTPZPZ|\\r-   c                      t        dd| i      S )6
        This method for get custom coloumn .
        z:cbv/allowance_deduction/deductions/deductions_actions.htmlr   r   r$   rT   s    r+   deduct_actionszDeduction.deduct_actions  s    
 M&
 	
r-   c                      t        dd| i      S )r%  z;cbv/allowance_deduction/deductions/detail_view_actions.htmlr   r   r$   rT   s    r+   deduct_detail_actionszDeduction.deduct_detail_actions"  s    
 N&
 	
r-   c                 b    | j                          d| j                          d| j                   S )z.
        Deduction eligibility column
        r  )r  r  r  rT   s    r+   deduction_eligibilityzDeduction.deduction_eligibility,  s8     ,,./q1N1N1P0QQRSWSaSaRbccr-   c                      t        dd| i      S )r%  z9cbv/allowance_deduction/deductions/has_maximum_limit.htmlr   r   r$   rT   s    r+   has_maximum_limit_colzDeduction.has_maximum_limit_col2  s    
 L&
 	
r-   c                      t        dd| i      S )zA
        This method for get custom coloumn for amount .
        z.cbv/allowance_deduction/deductions/amount.htmlr   r   r$   rT   s    r+   
amount_colzDeduction.amount_col<  s    
 A&
 	
r-   c                 x    t        j                  dd| j                        }|j                  dd      }d| d}|S r  r  r  s      r+   r  zDeduction.get_avatarF  r  r-   c                 8    t        dd| j                  i      }|S )r   zdeduction-detail-viewrY   rZ   r\   r   s     r+   deduction_detail_viewzDeduction.deduction_detail_viewO  s     -tTWWoF
r-   c                     t        d      }|S )r   rb   r  r   s     r+   rc   zDeduction.get_delete_urlV  r  r-   c                 8    t        dd| j                  i      }|S )/
        This method to get update url
        zupdate-deductiondeduction_idrZ   r   rY   r   s     r+   r]   zDeduction.get_update_url_  s     -~tww6OP
r-   c                     | j                   j                         }dj                  |D cg c]  }t        |       c}      }|S c c}w )z$
        Specific Employees
        r  r  r  s       r+   specific_employees_colz Deduction.specific_employees_colf  sB     ++//1	 &9,UxS],U V$$ -Vr  c                     | j                   j                         }dj                  |D cg c]  }t        |       c}      }|S c c}w )z$
        Excluded employees
        r  )r  r  r  rR   r  s       r+   excluded_employees_colz Deduction.excluded_employees_coln  sB     **..0	 &9,UxS],U V$$ -Vr  c                     | j                   rt        d      }| j                   rdnd}nt        d      }| j                  rdnd}|j                         }d| d| dS )NTaxr   r   Pretaxze
        <div class="oh-timeoff-modal__stat">
            <span class="oh-timeoff-modal__stat-title">z?</span>
            <span class="oh-timeoff-modal__stat-count">z</span>
        </div>
        )is_taxr(   r  
capitalize)rU   r  r   s      r+   tax_colzDeduction.tax_colv  sf    ;;eHE![[EdEhKE!^^EE  "88=w ?88=w ?	 	r-   c                 <    | j                   rd| j                    dS y)z+
        One time deduction column
        z%On <span class='dateformat_changer'> z</span> r   r  rT   s    r+   get_one_time_deductionz Deduction.get_one_time_deduction  s&     :4;M;M:NhWW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@   rr   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   r>  r  r  rr   update_compensationr	   r(   r  r  clean_condition_based_onr  r  r  r`  r*   rb  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  r`  rb  r*   rT   s    r+   rE  z"Deduction.clean_condition_based_on  s'     &&DJ!DNDJ 'r-   rO   c                 ,    t        | j                        S rQ   r  rT   s    r+   rV   zDeduction.__str__  r  r-   c                     t        t        j                  dd       }|j                  j	                  d      }| j
                  s!|r|dk7  rt        j                  |      | _        t        | )          y r  r  r  s      r+   r   zDeduction.save  r   r-   )Rrh   ri   rj   ro   r(   r  rp   r  r
   rq   r  r  r  rs   r  r  r   r  r  r>  r  r  r  r`  ra  rb  r*   rD  r  r  r,   r  rr   rB  r  employer_rater  r  r  r  r  r  r  r  r  rx   r   ry   rz   r  r   r{   is_installmentr\  r
  r  r  r  r  r  r  r  r#  r&  r(  r*  r,  r.  r  r1  rc   r]   r8  r:  r@  rB  r   rE  rR   rV   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--1:0=2:

d

%% :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%d Z&d Z'd Z(d  Z)d! Z*d" Z+d# Z,d$ Z- fd%Z. fd&Z/d' Z0d( Z1d) Z2d* Z3 G d+ d,      Z4 xZ5S )-r  z
    Payslip model
    r   r   review_ongoingzReview Ongoing	confirmed	ConfirmedpaidPaid2   Tz
Batch name)rC   rH   rD   rE   rF   F)rC   uniquerH   rD   r   r$  r   )rH   rI   r   )rC   rH   rI   rG   r   rM   r   r   rO   c                 T    d| j                    d| j                   d| j                   S )NPayslip for z - Period:  to r   r3   r4   rT   s    r+   rV   zPayslip.__str__  s.    d../{4??:K4PTP]P]__r-   c                 ^    t        | j                        j                  | j                        S r   )r   status_choicesr   statusrT   s    r+   
get_statuszPayslip.get_status	  s$     D''(,,T[[99r-   c                      t        dd| i      S )z1
        This method to get download url
        z%cbv/payslip/payslip_download_tab.htmlr   r   r$   rT   s    r+   get_download_urlzPayslip.get_download_url  s     8&
 	
r-   c                 8    | j                   }t        dd|i      S )z
        gross pay
        cbv/payslip/pay_display.htmlr  r   )r>   r%   )rU   r>   s     r+   gross_pay_displayzPayslip.gross_pay_display  %     NN	/y)
 	
r-   c                 8    | j                   }t        dd|i      S )z
        deduction
        r_  r  r   )	deductionr%   )rU   rc  s     r+   deduction_displayzPayslip.deduction_display#  ra  r-   c                 8    | j                   }t        dd|i      S )z
        net pay
        r_  r  r   )r  r%   )rU   r  s     r+   net_pay_displayzPayslip.net_pay_display.  s%     ,,/w'
 	
r-   c                      t        dd| i      S )z'
        custom status coloumn
        z#cbv/payslip/payslip_status_col.htmlr   r   r$   rT   s    r+   custom_status_colzPayslip.custom_status_col9      
 6&
 	
r-   c                      t        dd| i      S )z(
        custom actions coloumn
        z cbv/payslip/payslip_actions.htmlr   r   r$   rT   s    r+   custom_actions_colzPayslip.custom_actions_colC  s    
 3&
 	
r-   c                 8    t        dd| j                  i      }|S )z7
        This method to get individual payslip
        zview-created-payslip
payslip_idrZ   r6  r   s     r+   get_individual_payslipzPayslip.get_individual_payslipM  s    
 1<:QR
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 )Nr4   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   r4   r3   r	   r(   )rU   r   r  s     r+   r   zPayslip.cleanU  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 )NrW  r/   z+Employee ,start and end date must be uniquez0The data must be in dictionary or querydict type)r  r{   r   r   r3   r4   r   r	   r(   
isinstancepay_head_datar   r   r   r   r*  s      r+   r   zPayslip.savee  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_namerT   s    r+   get_namezPayslip.get_nameu  s     --//r-   c                 ^    t        t        t        t        | dd      dd      dd      dd      S )rt  r   Nr   rz   company)r  rT   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                   d| j                   S d| j                   d| j                   S )zz
        Method to generate the title for a payslip.
        Returns:
            str: The title for the payslip.
        zPayslip rV  z for rU  )
group_namer3   r4   r   rT   s    r+   get_payslip_titlezPayslip.get_payslip_title  sw     ????" $--/ t'tDMM?%@P@P?QR	
  0d6F6F5GH	
r-   c                     | j                   j                  }| j                   j                  }t        j                  ||      d   S )Nr/   )r3   yearmonthcalendar
monthrange)rU   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)rh   ri   rj   ro   rk   rm   r-   r+   rn   r    s    	
 
r-   rn   )6rh   ri   rj   ro   r(   rY  r
   rq   r{  	referencerx   r   ry   r   r  r3   r4   	JSONFieldrr  r  contract_wager<   r>   rc  r  rZ  rs   sent_to_employeer   r{   r  r  r  r#   r"   r  rR   rV   r[  r]  r`  rd  rf  rh  rk  rn  r   r   rv  ry  r|  r  rn   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+d( Z,d) Z-d* Z.d+ Z/d, Z0d- Z1d. Z2d/ Z3 fd0Z4d1 Z5 fd2Z6 xZ7S )3LoanAccountz>
    This modal is used to store the loan Account details
    loanLoanadvanced_salaryzAdvanced SalaryfinezPenalty / Fine   )rI   rG   rC   r   r%  r   r$  r   Amount)rI   rE   FT)rN   rM   rH   rF   rH   rC   rS  r  zinstallment Amount)rE   rD   rH   zTotal installmentsr   z(From the start date deduction will apply)r   end_of_month)rI   rC   rM   r&  rJ   assetzasset.Asset)rN   rD   rH   rM   r   c                 8    | j                    d| j                   S )Nr   )r  r   rT   s    r+   rV   zLoanAccount.__str__  s    **S!1!1 233r-   c                     t         j                  j                  | j                  j	                               j                         }|S )Ninstallment_ids__in)r  r{   r   deduction_idsr  r   )rU   installment_paids     r+   r  zLoanAccount.installment_paid  s?    "??11 $ 2 2 6 6 8 2 

%' 	  r-   c                     | j                   S rQ   )installmentsrT   s    r+   total_installmentszLoanAccount.total_installments  s       r-   c                      t        dd| i      S )z3
        This method for get loan actions.
        zcbv/loan/loan_actions.htmlr   r   r$   rT   s    r+   loan_actionszLoanAccount.loan_actions  s    
 -&
 	
r-   c                 b    t        d      }d}| j                  }| d| }d| ddz   d| dz   S )/
        This method to get delete url
        zdelete-loanz"Do you want to delete this record?z?ids=',r6  )rU   base_urlr7  loan_idr   s        r+   rc   zLoanAccount.get_delete_url  sL      .6''
%y)3%qzCAgYa.00r-   c                 4    t        dd| j                  i      S )z
        Edit url
        zloan-edit-formrY   rZ   r\   rT   s    r+   edit_urlzLoanAccount.edit_url  s     'tww@@r-   c                 L    t        d| | j                  | j                  d      S )z7
        This method for get progress bar col.
        zcbv/loan/loan_card.html)r   r  r  r   )r%   r  r  rT   s    r+   progress_bar_colzLoanAccount.progress_bar_col   s.    
 * &*&=&=$($9$9
 	
r-   c                 8    t        dd| j                  i      }|S )z)
        for detail view of page
        zloan-detail-viewrY   rZ   r\   r   s     r+   loan_detail_viewzLoanAccount.loan_detail_view  s     ($A
r-   c                     | j                   j                  j                   d| j                   j                  j                   S )zZ
        Return subtitle containing both department and job position information.
        z / r   rT   s    r+   detail_subtitlezLoanAccount.detail_subtitle  s;     ""55CCDCHXHXHkHkH{H{G|}}r-   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_amountr  installment_start_dater1   rR   r   )rU   r  r  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)flatr  )r  r  deleter  r  r{   r   r  r  r   r   r*  s      r+   r  zLoanAccount.delete2  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   rA  )r  r  r{   r   r  r  r   )rU   r  r  ratios       r+   installment_ratiozLoanAccount.installment_ratio?  sb     ".."??11 $ 2 2 6 6 8 2 

%' 	  !$66#=r-   c                 ~    | j                   rt        j                         | _        nd | _        t	        |   |i | y rQ   )settledr   r(  settled_dater   r   r*  s      r+   r   zLoanAccount.saveM  s1    << (D $Dd%f%r-   )8rh   ri   rj   ro   r(   	loan_typer
   rq   typer  rx   r   ry   r   r  r  r  provided_daterd  SET_NULLr  ru   rw   r  r  r  rs   r  r  r  r  r  r  apply_onr  r:  r  r   r
  asset_idr   r{   rV   r  r  r  rc   r  r  r  r  r  r  r  r   r  r  s   @r+   r  r    s6   
 
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 !
1"A
~$.& &r-   r  c                   X    e Zd ZdZ ej
                  e      Z ej                         Z	y)ReimbursementMultipleAttachmentz0
    ReimbursementMultipleAttachement Model
    r   N)
rh   ri   rj   ro   r
   r  r!   
attachmentManagerr{   rm   r-   r+   r  r  W  s)     "!!K8JfnnGr-   r  c            	           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(                  ed      Z e
j.                  edd      Z ej                  d      r' e
j                  de
j                   dd ed            Z e
j6                  d ed       ed            Z e
j6                  d ed       ed             Z e
j<                  d ed!       ed"            Z e
j6                  d#      Z  e
j                  d$e	dd%      Z! e
j                  ee
jD                  dd&d'      Z# e
jH                  dd()      Z% e
j                  e&e
jD                  dd*      Z' e(d+      Z) G d, d-      Z*d; fd.Z+ fd/Z,d0 Z-d1 Z.d2 Z/d3 Z0d4 Z1d5 Z2d6 Z3d7 Z4d8 Z5d9 Z6d: Z7 xZ8S )<Reimbursementz
    Reimbursement Model
    reimbursementbonus_encashmentzBonus Point Encashmentr<  leave_encashmentzLeave Encashment	requested	RequestedapprovedApprovedrejectedRejectedrQ  r%     )rG   rC   rI   r   r$  T)r   rH   Fr  zleave.LeaveTypez
Leave type)rN   rD   rH   rE   r   zAvailable Days to encashzAvailable days)rI   r   rE   zCarry Forward Days to encashzCarry forward dayszBonus points to encashzBonus pointsr&  r{  )rC   rG   rI   rM   approved_by)rN   rH   r   rM   rF   r  )rN   rH   rM   r   c                       e Zd ZdgZy)Reimbursement.Metarf   N)rh   ri   rj   rk   rm   r-   r+   rn   r    s	    7r-   rn   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 )Nr  r/   zpayroll.change_reimbursementr  r  r   r  leave_type_idr     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 daysr  zleave encashment)/r  r   r   EncashmentGeneralSettingsr{   r  leave_amountbonus_amountuserhas_permemployee_getr   r  r  r	   r  rZ  cfd_to_encashad_to_encashr  maxroundemployee_available_leaver   bonus_to_encashr  r   r   r   r   pointsreasonr   infoavailable_dayscarryforward_daysr(   rd  allowance_onr  r  r  r  r  addr  r  )rU   r  r[   r  amount_for_leaveamount_for_bonusr  assigned_leaveproceedbonus_pointsr  r  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   rZ  r   r  r(   r  r  r  r   success)rU   r  r[   r  r7  r  s        r+   r  zReimbursement.delete	  s    -<<iN;;*$mmzzl #) *G    !!((*//"**74KLr-   c                     | j                    S rQ   )r  rT   s    r+   rV   zReimbursement.__str__0	  s    **r-   c                 ^    t        | j                        j                  | j                        S )z&
        Display status types
        )r   status_typesr   rZ  rT   s    r+   r   z Reimbursement.get_status_display3	  s$     D%%&**4;;77r-   c                      t        dd| i      S )r%  zcbv/reimbursements/comment.htmlr   r   r$   rT   s    r+   comment_colzReimbursement.comment_col9	      
 2&
 	
r-   c                      t        dd| i      S )r%  zcbv/reimbursements/options.htmlr   r   r$   rT   s    r+   options_colzReimbursement.options_colC	  r  r-   c                      t        dd| i      S )r%  zcbv/reimbursements/actions.htmlr   r   r$   rT   s    r+   r   zReimbursement.actions_colM	  r  r-   c                      t        dd| i      S )z@
        This method for get custom column for amount .
        zcbv/reimbursements/amount.htmlr   r   r$   rT   s    r+   r.  zReimbursement.amount_colW	  s    
 1&
 	
r-   c                      t        dd| i      S )zD
        This method for get custom column for attachment .
        z#cbv/reimbursements/attachments.htmlr   r   r$   rT   s    r+   attachments_colzReimbursement.attachments_cola	  ri  r-   c                      t        dd| i      S )zK
        This method for get custom column for actions in detail .
        z&cbv/reimbursements/detail_actions.htmlr   r   r$   rT   s    r+   detail_action_colzReimbursement.detail_action_colk	  s    
 9&
 	
r-   c                 8    t        dd| j                  i      }|S )z3
        for detail view of reimbursements
        zdetail-view-reimbursementrY   rZ   r\   r   s     r+   reimbursements_detail_viewz(Reimbursement.reimbursements_detail_viewu	  s     14/J
r-   c                 8    t        dd| j                  i      }|S )z7
        for detail view of leave encashments.
        zdetail-view-leave-encashmentrY   rZ   r\   r   s     r+   leave_encash_detail_viewz&Reimbursement.leave_encash_detail_view|	       4dDGG_M
r-   c                 8    t        dd| j                  i      }|S )z7
        for detail view of bonus encashments.
        zdetail-view-bonus-encashmentrY   rZ   r\   r   s     r+   bonus_encash_detail_viewz&Reimbursement.bonus_encash_detail_view	  r  r-   )rO   N)9rh   ri   rj   ro   r(   reimbursement_typesr   r
  r2   r  r
   rq   r  r  rx   r   ry   r   r  r  r  r!   r  r  r  other_attachmentsr  r  r  r  r  r  r  rZ  r  r  ru   rw   rd  r  r   r{   rn   r   r  rV   r   r  r  r   r.  r   r  r  r  r	  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!!!KdCJ...'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$8





r-   r  c                   T    e Zd Z ej                  e      Z ej                         Zy)ReimbursementFiler  N)	rh   ri   rj   r
   r  r!   filer  r{   rm   r-   r+   r  r  	  s"    6k2D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
    )rN   TCommentrF   )rH   rE   rC   )rD   z
Created At)auto_now_addrE   rH   rO   c                     | j                    S rQ   )commentrT   s    r+   rV   z#ReimbursementrequestComment.__str__	  s    ,, r-   N)rh   ri   rj   ro   r
   rx   r  CASCADE
request_idr   r   ru   r(   r  r  r  filesr:  
created_atrR   rV   rm   r-   r+   r  r  	  s     #""=FNNKJ#&##HGKfDq|PSTG"F""#4DAE%%%|_J! !r-   r  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 daysrB   )r   r   rI   T)rN   rH   N)rh   ri   rj   ro   r
   r  r,   notice_periodrx   r   r  rz   rm   r-   r+   r  r  	  sB     (F''):M
 #""7fnn4PJr-   r  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  )rD   rH   rE   N)
rh   ri   rj   ro   r
   r  r  r  r  r{   rm   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d Zd Zd Zd Zd Zd Z fdZdefdZ xZS )PayslipAutoGeneratez4
    Model for generating payslip automatically
    rB   r  zPayslip Generate Dayz5On this day of every month,Payslip will auto generate)rC   rG   rI   rE   r   Fr&  Tr   rv  c                 R    t        t              j                  | j                        S r  )r   DAYSr   generate_dayrT   s    r+   get_generate_day_displayz,PayslipAutoGenerate.get_generate_day_display	  s     Dz~~d//00r-   c                 4    | j                   r| j                   S y)NzAll companyrz   rT   s    r+   ry  zPayslipAutoGenerate.get_company	  s    ????"r-   c                      t        dd| i      S )z"
        is active column
        zcbv/settings/is_active_col.htmlr   r   r$   rT   s    r+   is_active_colz!PayslipAutoGenerate.is_active_col	  s     2Z<N
 	
r-   c                 8    t        dd| j                  i      }|S )r4  zpay-slip-automation-updaterY   rZ   r6  r   s     r+   r]   z"PayslipAutoGenerate.get_update_url
  s     7twwP
r-   c                 8    t        dd| j                  i      }|S )r  zdelete-auto-payslipauto_idrZ   r6  r   s     r+   rc   z"PayslipAutoGenerate.get_delete_url	
  s     0)TWW9MN
r-   c                     | j                   S rQ   r   rT   s    r+   get_instance_idz#PayslipAutoGenerate.get_instance_id
  s    wwr-   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 )Nrb  rz   z9Auto payslip generation for all company is already exists)rz   r\  r{   r   r   r   r	   r  )rU   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.schedulerrm  auto_generater   r   )rU   r  r[   rm  r  s       r+   r   zPayslipAutoGenerate.save)
  s&    ;!#d%f%r-   rO   c                 :    | j                    d| j                   dS )Nz | r  )r_  rz   rT   s    r+   rV   zPayslipAutoGenerate.__str__1
  s!    ##$C'8::r-   )rh   ri   rj   ro   r
   rq   r^  r_  rs   ro  OneToOneFieldr   r  rz   r`  ry  rd  r]   rc   ri  r   r   rR   rV   r  r  s   @r+   r\  r\  	  s     $6##+IL (F''6M%%%6>>DyJ1

,&; ;r-   r\  )[ro   r  loggingr  r   r   r   djangor   django.appsr   django.contribr   django.core.exceptionsr	   	django.dbr
   django.httpr   django.urlsr   r   django.utilsr   django.utils.htmlr   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.horilla_middlewaresr   horilla.modelsr    r!   horilla_audit.modelsr"   r#   horilla_views.cbv_methodsr%   	getLoggerrh   r   r,   r9   r;   r}   Modelr  r
  attendance.modelsr;  leave.modelsr=  r?  rB  ra  r  r  r\  rd  r  r  r  r  r  r  r  r  r  r^  r\  rm   r-   r+   <module>r     sQ  
   	 . .   # 2  ! - ! ) 6 > 1   > I I ' 6 4 B 5			8	$D4;3< ;3|eV| eVP?
 ?
D 4\",h 4W)| N? 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 &n nbv vrD
l D
Nn&, n&bfll hL hV	 
!, !&
QFLL 
Q !:!! ! 	!
 ! ! ! ! ! ! ! ! ! ! !  !!" #!$ %!& '!( )!* +!, -!. /!0 1!2 3!4 5!6 7!8 9!: ;!< =!> ?!@ A!HT;&,, T;r-   