
    h8-                     ,   d dl 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
Zd dlmZmZmZ d dlmZmZ  G d d	e	e      Z G d
 de	e      Z G d de	e      Z G d de	e      Z G d de	e      Z G d de	e      Z G d de	e      Z G d de	e      Zy)    N)renderredirect)View)messages)LoginRequiredMixin)
AttendanceTeamVendors)User_Departments
User_Typesc                       e Zd Zd Zd Zy)TeamRegistrationViewc                     t         j                  j                         }t        j                  j                         }t	        |d||d      S )Nzteam-registration.html)departmentsdesignations)r   objectsallr   r   )selfrequestr   r   s       F/mnt/ACDE16A4DE16673C/PROJECTS/MIS_PORTALS/KUNJ/hr_department/views.pygetzTeamRegistrationView.get   s@    &..224!))--/g7+ht9uvv    c                 	   t               }|j                  j                  d      |_        dj	                  d t        d      D              |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_	        |j                  j                  d      |_
        |j                  j                  d	      |_        |j                  j                  d
      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j:                  j                  d      |_        |j:                  j                  d      |_        |j:                  j                  d      |_         |j:                  j                  d      |_!        |j:                  j                  d      |_"        |j                  j                  d       |_#        |j:                  j                  d!      |_$        |j                  j                  d"      |_%        |j                  j                  d#      |_&        |j                  j                  d$      |_'        |j                  j                  d%      |_(        d&|j:                  v r |j:                  j                  d"      |_)        |jU                          tW        jX                  |d'       t[        d(      S ))Nemployment_type c              3   F   K   | ]  }t        j                  d         yw$1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZNrandomchoice.0is     r   	<genexpr>z,TeamRegistrationView.post.<locals>.<genexpr>        #l^_FMM2X$Y#l   !   positionnamefather_namemother_nameemailmobiledate_of_birthgenderqualification
university
experiencemarital_statusemergency_contact_nojoining_datedesignation
departmentpayment_typebasic_amount
ctc_amountepfesicpan_nophotoresumeaadharpan_card	marksheetaddressmessageassets	condition
issue_datereturn_datedeclaration$Team member registered successfully.TeamView).r	   POSTr   r   joinrangeemployee_idr)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   designation_iddepartment_idr9   r:   r;   r<   r=   r>   FILESr?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   saver   successr   )r   r   teams      r   postzTeamRegistrationView.post   sk   v&||//0AB77#lchijck#lm((4LL$$V,	"<<++M:"<<++M:\\%%g.
ll&&x0$\\--o>ll&&x0$\\--o>!,,**<8!,,**<8%ll../?@$+LL$4$45K$L!#LL,,^<%ll..}=$\\--l;#LL,,^<#LL,,^<!,,**<8<<##E*LL$$V,	ll&&x0]]&&w/
mm''1mm''1))*5 **;7||''	2}}((3ll&&x0 ))+6!,,**<8"<<++M:GMM)&}}00:D		"HI
##r   N__name__
__module____qualname__r   rW    r   r   r   r      s    w)$r   r   c                       e Zd Zd Zd Zy)rL   c                 \    t         j                  j                         }t        |dd|i      S )Nz	team.htmlmembers)r	   r   r   r   )r   r   r_   s      r   r   zTeamView.getD   s(    ,,""$g{Y,ABBr   c                 P   	 |j                   j                  d      }t        j                  j                  |      }|j	                          t        j                  |d       t        d      S # t        j                  $ r$ t        j                  |d       t        d      cY S w xY w)Nidra   z!Team member deleted successfully.rL   zTeam member not found.)
rM   r   r	   r   deleter   rU   r   DoesNotExisterrorr   r   ra   rV   s       r   rW   zTeamView.postJ   s    	(!!$'B<<##r#*DKKMW&IJJ''   	(NN7$<=J''	(   A+A. .4B%$B%NrX   r\   r   r   rL   rL   B   s    C	(r   rL   c                       e Zd Zd Zd Zy)
MemberViewc                     t         j                  j                  |      }t        j                  j	                         }t
        j                  j	                         }t        |d|||d      S )Nrb   zedit-team.html)rV   r   r   )r	   r   r   r   r   r   r   )r   r   ra   rV   r   r   s         r   r   zMemberView.getW   sZ    ||R(&..224!))--/g/4Q\o{1|}}r   c                 X
   t         j                  j                  |      }|j                  j                  d      |_        dj                  d t        d      D              |_        |j                  j                  d      |_        |j                  j                  d      |_	        |j                  j                  d      |_
        |j                  j                  d	      |_        |j                  j                  d
      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j>                  j                  d      |_         |j                  j                  d      |_!        |j                  j                  d      |_"        |j                  j                  d       |_#        |j                  j                  d!      |_$        d"|j>                  v r |j>                  j                  d"      |_%        d#|j>                  v r |j>                  j                  d#      |_&        d$|j>                  v r |j>                  j                  d$      |_'        d%|j>                  v r |j>                  j                  d%      |_(        d&|j>                  v r |j>                  j                  d&      |_)        d'|j>                  v r |j>                  j                  d      |_*        |jW                          tY        jZ                  |d(       t]        d)      S )*Nrb   r   r   c              3   F   K   | ]  }t        j                  d         ywr   r   r"   s     r   r%   z"MemberView.post.<locals>.<genexpr>a   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   rD   rE   rF   rG   rH   rI   r?   r@   rA   rB   rC   rJ   rK   rL   )/r	   r   r   rM   r   rN   rO   rP   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   rQ   rR   r9   r:   r;   r<   r=   r>   rD   rS   rE   rF   rG   rH   rI   r?   r@   rA   rB   rC   rJ   rT   r   rU   r   rf   s       r   rW   zMemberView.post^   s   ||R(&||//0AB77#lchijck#lm((4LL$$V,	"<<++M:"<<++M:\\%%g.
ll&&x0$\\--o>ll&&x0$\\--o>!,,**<8!,,**<8%ll../?@$+LL$4$45K$L!#LL,,^<%ll..}=$\\--l;#LL,,^<#LL,,^<!,,**<8<<##E*LL$$V,	ll&&x0||''	2}}((3ll&&x0 ))+6!,,**<8"<<++M:gmm# **73DJw}}$!--++H5DKw}}$!--++H5DK&#MM--j9DM'--'$]]..{;DNGMM)&}}00:D		"HI
##r   NrX   r\   r   r   ri   ri   V   s    ~.$r   ri   c                       e Zd Zd Zd Zy)AttendanceViewc                    t         j                  j                         }t        j                  j	                  dd      j                         j                  d      }t        |j                         d|j                  v r|j                  d   dk7  rd|j                  v r~|j                  d   dk7  rlt        j                  j                  t        |j                  d         t        |j                  d               }|j                  d   }|j                  d   }nmt        j                  j                  d      j                         }|r|j                  }|j                  }nd }d }t        j                  j                  ||      }g }|D ]2  }	t        j                  |	j                   j"                        }
|
d   j%                         j'                         }|j)                  d	d
      }|j)                  dd
      }|j)                  dd
      }|j)                  dd
      }|
d   j+                         }|j-                  |	j.                  j0                  |	j.                  j2                  |	j.                  j4                  |	j.                  j6                  |||||	j                   j8                  t;        |d      d
       5 t=        |d|||||d      S )NyearT)flatr   month)rr   rp   z-idStatusPresentr   AbsentLeaveHolidayzWorking Hours   )
rP   r-   r.   r*   presentabsentleaveholidayfiletotal_hourszattendance.html)
attendancer_   yearsrp   rr   )r	   r   r   r   values_listdistinctorder_byprintGETfilterintfirstrp   rr   pd
read_excelr}   pathvalue_countsto_dictr   sumappendmemberrP   r-   r.   r*   urlroundr   )r   r   r_   r   attendancesrp   rr   last_attendanceresultsattdfcountsry   rz   r{   r|   r~   s                    r   r   zAttendanceView.get   sk   ,,""$""..vD.AJJLUUV\]gkkW[[ W[[%8B%>7gkkCY^e^i^ijq^rvx^x$,,33#gkk'>R:SZ]^e^i^ijp^qZr3sK;;v&DKK(E(0099%@FFHO&++'--$,,33%d3KK 	Csxx}}-B\..088:FjjA.GZZ!,FJJw*EjjA.G_-113KNN"zz55))**++

" #$[!4 	( g0'W^joz~  KP  3Q  R  	Rr   c                    	 t         j                  j                  |j                  j                  d      |j                  j                  d      |j                  j                  d            }|j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_	        |j                          t        j                  |d       t        d      S # t         j                  $ r t               }Y w xY w)N	member_idrr   rp   )r   rr   rp   r}   zAttendance saved successfully.rn   )r   r   r   rM   rd   r   rr   rp   rS   r}   rT   r   rU   r   )r   r   r   s      r   rW   zAttendanceView.post   s   	&#++//GLL<L<L[<Ycjcococscst{c|  FM  FR  FR  FV  FV  W]  F^/  _J  '||//<
"<<++G4
!,,**62
!--++F3
"BC()) && 	&#J	&s   A-D   E ?E NrX   r\   r   r   rn   rn      s    'RT*r   rn   c                       e Zd Zd Zy)MemberDetailViewc                     	 t         j                  j                  |      }t        |dd|i      S # t         j                  $ r t        d      cY S w xY w)Nrb   zmember.htmlr   rL   )r	   r   r   r   rd   r   )r   r   ra   r   s       r   r   zMemberDetailView.get   sR    	(\\%%2%.F'=8f2EFF   	(J''	(s   .1 AAN)rY   rZ   r[   r   r\   r   r   r   r      s    (r   r   c                       e Zd Zd Zd Zy)VendorRegistrationViewc                     t        |d      S )Nzvendor-registration.html)r   )r   r   s     r   r   zVendorRegistrationView.get   s    g9::r   c                 8   t               }|j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_	        |j                  j                  d      |_
        |j                          t        j                  |d       t        d	      S )
Nr*   r-   r.   r>   rB   rD   rE   zVendor registered successfully.
VendorView)r
   rM   r   r*   r-   r.   r>   rS   rB   rD   rE   rT   r   rU   r   )r   r   vendors      r   rW   zVendorRegistrationView.post   s    ll&&v.||''0((2((2!--++J7 )))4 **95"CD%%r   NrX   r\   r   r   r   r      s    ;&r   r   c                       e Zd Zd Zd Zy)r   c                 \    t         j                  j                         }t        |dd|i      S )Nzvendors.htmlvendors)r
   r   r   r   )r   r   r   s      r   r   zVendorView.get   s(    //%%'g~	G/DEEr   c                 P   	 |j                   j                  d      }t        j                  j                  |      }|j	                          t        j                  |d       t        d      S # t        j                  $ r$ t        j                  |d       t        d      cY S w xY w)Nra   rb   zVendor deleted successfully.r   zVendor not found.)rM   r   r
   r   rc   r   rU   r   r	   rd   re   r   r   ra   r   s       r   rW   zVendorView.post   s    	*!!$'B__((B(/FMMOW&DEL))   	*NN7$78L))	*rg   NrX   r\   r   r   r   r      s    F
	*r   r   c                       e Zd Zd Zd Zy)VendorMemberViewc                 `    t         j                  j                  |      }t        |dd|i      S )Nrb   zedit-vendor.htmlr   )r
   r   r   r   r   s       r   r   zVendorMemberView.get   s.    $$"$-g1Hv3FGGr   c                    t         j                  j                  |      }|j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d      |_        d|j                  v r |j                  j                  d      |_	        |j                  j                  d      |_
        |j                  j                  d      |_        |j                          t        j                  |d	       t        d
      S )Nrb   r*   r-   r.   r>   rB   rD   rE   zVendor updated successfully.r   )r
   r   r   rM   r*   r-   r.   r>   rS   rB   rD   rE   rT   r   rU   r   r   s       r   rW   zVendorMemberView.post  s    $$"$-ll&&v.||''0((2((2&%mm//
;FO )))4 **95"@A%%r   NrX   r\   r   r   r   r      s    H&r   r   )r    django.shortcutsr   r   django.viewsr   django.contribr   django.contrib.auth.mixinsr   pandasr   hr_department.modelsr   r	   r
   users.modelsr   r   r   rL   ri   rn   r   r   r   r   r\   r   r   <module>r      s     -  # 9  ; ; 51$-t 1$l(!4 ((6$#T 6$r7*' 7*t()4 (&/ &**#T *(&)4 &r   