
    ~nh5                     l   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
mZmZmZmZ d dlmZmZ d dlmZ d dl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 G d de	e      Z G d de	e      Zy)    N)renderredirect)View)messages)LoginRequiredMixin)
AttendanceTeamVendorsTeam_Projects)User_Departments
User_Types)Projectsc                       e Zd Zd Zd Zy)TeamRegistrationViewc                     t         j                  j                         }t        j                  j                         }t        j                  j                         }t        |d|||d      S )Nzteam-registration.html)departmentsdesignationsprojects)r   objectsallr   r   r   )selfrequestr   r   r   s        L/mnt/ACDE16A4DE16673C/PROJECTS/MIS_PORTALS/MIS_PORTAL/hr_department/views.pygetzTeamRegistrationView.get   sd    &..224!))--/##'')g7+ht  DL  :M  N  	N    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                          |jV                  rtY        |j                  j[                  d'            r[t\        j^                  ja                  |j                  j[                  d'      D cg c]  }t]        |jV                  |(       c}       tc        jd                  |d)       tg        d*      S c c}w )+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declarationr   	member_id
project_id$Team member registered successfully.TeamView)4r	   POSTr   r   joinrangeemployee_idr,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   designation_iddepartment_idr<   r=   r>   r?   r@   rA   FILESrB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   saveidlengetlistr   r   bulk_creater   successr   )r   r   teamprojects       r   postzTeamRegistrationView.post   s   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		777<<''
34%%11ZaZfZfZnZnoyZz3OVMDGG'J3  	"HI
##	3s   UN__name__
__module____qualname__r   rb    r   r   r   r      s    N.$r   r   c                       e Zd Zd Zd Zy)rR   c                 \    t         j                  j                         }t        |dd|i      S )Nz	team.htmlmembers)r	   r   r   r   )r   r   rj   s      r   r   zTeamView.getJ   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)Nr[   r[   z!Team member deleted successfully.rR   zTeam member not found.)
rS   r   r	   r   deleter   r_   r   DoesNotExisterror)r   r   r[   r`   s       r   rb   zTeamView.postO   s    	(!!$'B<<##r#*DKKMW&IJJ''   	(NN7$<=J''	(   A+A. .4B%$B%Nrc   rg   r   r   rR   rR   H   s    C
	(r   rR   c                       e Zd Zd Zd Zy)
MemberViewc           
         t         j                  j                  |      }t        t        j                  j                  |      j                  dd            }t        j                  j                         }t        j                  j                         }t        j                  j                         }t        |d|||||d      S )Nrl   rO   rP   Tflatzedit-team.html)r`   r   r   r   project_list)r	   r   r   listr   filtervalues_listr   r   r   r   r   )r   r   r[   r`   rw   r   r   r   s           r   r   zMemberView.get\   s    ||R(M1188R8HTTUahlTmn&..224!))--/##'')g/4Q\o{  KS  fr  2s  t  	tr   c           	         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                          tX        j                  j[                  |j\                  (      j_                          ta        |j                  jc                  d)            r[tX        j                  je                  |j                  jc                  d)      D cg c]  }tY        |j\                  |*       c}       tg        jh                  |d+       tk        d,      S c c}w )-Nrl   r   r   c              3   F   K   | ]  }t        j                  d         ywr    r"   r%   s     r   r(   z"MemberView.post.<locals>.<genexpr>h   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rG   rH   rI   rJ   rK   rL   rB   rC   rD   rE   rF   rM   rt   r   rN   rQ   rR   )6r	   r   r   rS   r   rT   rU   rV   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   rW   rX   r<   r=   r>   r?   r@   rA   rG   rY   rH   rI   rJ   rK   rL   rB   rC   rD   rE   rF   rM   rZ   r   ry   r[   rm   r\   r]   r^   r   r_   r   )r   r   r[   r`   ra   s        r   rb   zMemberView.poste   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		$$$9@@Bw||##J/0!!--V]VbVbVjVjkuVv/KRgF/  	"HI
##	/s   W#Nrc   rg   r   r   rr   rr   [   s    t3$r   rr   c                       e Zd Zd Zd Zy)AttendanceViewc                    t         j                  j                         }t        j                  j	                  dd      j                         j                  d      }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 ]=  }	t        j                  |	j                  j                         }
|
d   j#                         j%                         }|j'                  d	d
      }|j'                  dd
      }|j'                  dd
      }|j'                  dd
      }|
d   j)                         }|j+                  |	j,                  |	j.                  j0                  |	j.                  j2                  |	j.                  j4                  |	j.                  j6                  |||||	j                  j8                  t;        |d      d       @ t=        |d|||||d      S )NyearTru   r   month)r   r   z-idStatusPresentr   AbsentLeaveHolidayzWorking Hours   )r[   rV   r0   r1   r-   presentabsentleaveholidayfiletotal_hourszattendance.html)
attendancerj   yearsr   r   )r	   r   r   r   rz   distinctorder_byGETry   intfirstr   r   pd
read_excelr   pathvalue_countsto_dictr   sumappendr[   memberrV   r0   r1   r-   urlroundr   )r   r   rj   r   attendancesr   r   last_attendanceresultsattdfcountsr   r   r   r   r   s                    r   r   zAttendanceView.get   sf   ,,""$""..vD.AJJLUUV\]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vv"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)NrO   r   r   )rO   r   r   r   zAttendance saved successfully.r~   )r   r   r   rS   rn   rO   r   r   rY   r   rZ   r   r_   r   )r   r   r   s      r   rb   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 Nrc   rg   r   r   r~   r~      s    'RT*r   r~   c                       e Zd Zd Zy)AttendanceDeleteViewc                 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)Nr[   rl   z Attendance deleted successfully.r~   Vendor not found.)
rS   r   r   r   rm   r   r_   r   rn   ro   )r   r   r[   r   s       r   rb   zAttendanceDeleteView.post   s    	.!!$'B#++//R/8JW&HI,--&& 	.NN7$78,--	.rp   N)rd   re   rf   rb   rg   r   r   r   r      s    	.r   r   c                       e Zd Zd Zy)MemberDetailViewc                 P   	 t         j                  j                  |      }t        t        j                  j                  |      j                  dd            }dj                  d |D              }t        |d||d	      S # t         j                  $ r t        d
      cY S w xY w)Nrl   rt   project__projectTru   z, c              3   2   K   | ]  }t        |        y w)N)str)r&   ra   s     r   r(   z'MemberDetailView.get.<locals>.<genexpr>   s     $NgS\$Ns   zmember.html)r   rw   rR   )r	   r   r   rx   r   ry   rz   rT   r   rn   r   )r   r   r[   r   rw   s        r   r   zMemberDetailView.get   s    	(\\%%2%.F 5 5 < < < L X XYkrv X wxL99$N$NNL'=fWc2dee   	(J''	(s   BB B%$B%Nrd   re   rf   r   rg   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                 T   t               }|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 )
Nr-   r0   r1   rA   rE   rG   rH   zVendor registered successfully.
VendorView)r
   rS   r   r-   r0   r1   rA   rY   rE   rG   rH   rZ   r   r_   r   )r   r   vendors      r   rb   zVendorRegistrationView.post   s    ll&&v.||''0((2((2&%mm//
;FO )))4 **95"CD%%r   Nrc   rg   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)Nr[   rl   zVendor deleted successfully.r   r   )rS   r   r
   r   rm   r   r_   r   r	   rn   ro   r   r   r[   r   s       r   rb   zVendorView.post  s    	*!!$'B__((B(/FMMOW&DEL))   	*NN7$78L))	*rp   Nrc   rg   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 )Nrl   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 )Nrl   r-   r0   r1   rA   rE   rG   rH   zVendor updated successfully.r   )r
   r   r   rS   r-   r0   r1   rA   rY   rE   rG   rH   rZ   r   r_   r   r   s       r   rb   zVendorMemberView.post  s    $$"$-ll&&v.||''0((2((2&%mm//
;FO )))4 **95"@A%%r   Nrc   rg   r   r   r   r     s    H&r   r   c                       e Zd Zd Zy)VendorMemberDetailViewc                     	 t         j                  j                  |      }t        |dd|i      S # t         j                  $ r t        d      cY S w xY w)Nrl   zvendor.htmlr   r   )r
   r   r   r   rn   r   r   s       r   r   zVendorMemberDetailView.get.  sR    	*__((b(1F'=8f2EFF## 	*L))	*s   .1 AANr   rg   r   r   r   r   -  s    *r   r   ) r#   django.shortcutsr   r   django.viewsr   django.contribr   django.contrib.auth.mixinsr   hr_department.modelsr   r	   r
   r   users.modelsr   r   program_department.modelsr   pandasr   r   rR   rr   r~   r   r   r   r   r   r   rg   r   r   <module>r      s     -  # 9 I I 5 . 7$-t 7$x(!4 (&=$#T =$@7*' 7*r.-t .()4 (&/ &,*#T *&&)4 &,*/ *r   