
    vg                        d Z ddl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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 Z#e! e"d      d               Z$e! e"d      d               Z%e! e"d      dd              Z&e! e"d      dd              Z'e!d        Z(e! e"d      d               Z)y)zX
employee/context_processors.py

This module is used to write context processor methods
    N)date)template)apps)messages)EmailMessage)	Paginator)HttpResponseJsonResponse)render)ConfiguredEmailBackend)export_datagenerate_pdf)HorillaMailTemplate)EmployeeFilter)Employee)settings)login_requiredmanager_can_enterc                 @    t        | d      }|j                  |      } | S )z3
    This method is used to paginate query set
       )r   get_page)qrysetpage_number	paginators      1/var/www/horilla/employee/not_in_out_dashboard.pypaginator_qryr      s%     &"%I,FM    zemployee.view_employeec                 2   | j                   j                  d      }| j                   j                         }t        dt	        j
                         i      j                  j                  d      j                  d      }t        | dt        ||      |d      S )l
    This context processor wil return the employees, if they not marked the attendance
    for the day
    page
not_in_yetTemployee_work_info__isnull	is_activezdashboard/not_in_yet.html)	employeespd)GETget	urlencoder   r   todayqsexcludefilterr   r   )requestr   previous_dataempss       r   r!   r!   $   s     ++//&)KKK))+Mdjjl34	GGtG4	$	 	 #&t[9	
 r   c                     t        dt        j                         i      j                  j	                  d      j                  d      }t        | dd|i      S )r   not_out_yetTr"   r$   zdashboard/not_out_yet.htmlr&   )r   r   r+   r,   r-   r.   r   )r/   r1   s     r   r3   r3   =   sO     	tzz|45	GGtG4	$	 	
 '7+t9LMMr   zemployee.change_employeec                     d}|r t         j                  j                  |      }t         j                  j                         }t        j                  j                         }t        | d|||d      S )5
    This method used send mail to the employees
    Nidzemployee/send_mail.html)employee	templatesr&   )r   objectsr)   allr   r   )r/   emp_idr8   r&   r9   s        r   	send_mailr=   L   sj     H##''6'2  $$&I#++//1I!IIN r   c                    | j                   }|r=|j                  r0|j                  dk(  r d}|r t        j                  j	                  |      }d|i}t        j                  d      r8ddlm} ddl	m
}  |       } |       }|j                  ||j                  d	       t        j                  d
      r>ddlm}	 ddlm}
 ddlm}  |
       } |	       }|j                  ||j                  d       t        j                  d      r5ddlm} ddlm} |j                   |        || j.                        d       t1        | d|      S t3        | 	
d      S )r5   zexport-data-employeeNr6   r8   leaver   )LeaveRequestFilter)LeaveRequestExportForm)leave_excel_columnleave_export_filter
attendance)AttendanceFilters)AttendanceExportForm)
Attendance)attendance_excel_columnattendance_export_filterpayroll)PayslipFilter)PayslipExportColumnForm)payroll_export_columnpayroll_export_filterz"employee/export_data_employee.html)contextAttendance_export)r/   modelfilter_class
form_class	file_name)resolver_matchurl_namer   r:   r)   r   is_installedleave.filtersr@   leave.formsrA   updateformattendance.filtersrE   attendance.formsrF   attendance.modelsrG   payroll.filtersrK   payroll.forms.component_formsrL   r(   r   r   )r/   r<   rU   r8   rO   r@   rA   excel_columnexport_filterrE   rF   rG   rK   rL   s                 r   employee_data_exportrc   _   sE    ++N####'==''++v+6Hx( W%8:13L.0MNN*6+8+=+= \*<=4/1L-/MNN/;0=0B0B Y'5MNN-D-F-:7;;-G gCWUU&'% r   c                    t         j                  j                  |      j                  }| j                  j                  d      }|rrt
        j                  j                  |      }t        j                  |      }t        j                  || j                  j                  d      }|j                  |      }t        d|i      S )z9
    This method is used to return the mail template
    r6   instance_idinstanceselfbody)r   r:   r)   ri   r(   r   r   TemplateContextuseremployee_getr   r
   )r/   r<   ri   re   rg   template_bdyrO   s          r   get_templatero      s    
 &&**f*5::D++//-0K##'';'7((.""!7<<+D+DE
 ""7+''r   zrecruitment.change_employee)permc                    | j                   d   }| j                   j                  d      }| j                   j                  d      }| j                   j                  d      }t        j                  j                  |      }| j                  j                  d      }|D cg c])  }|j                  |j                         |j                  f+ }}|r!t        j                  j                  |      }	nt        j                  j                         }	||	z  j                         }| j                   j                  d      }
|D ]  }t        t        j                  j                  |
      j                  dd	
            }|D ]  }t        j                   |      }t        j"                  || j$                  j&                  d      }|j)                  |      }|j+                  dt-        |i dd      j.                  df        t        j                   |      }t        j"                  || j$                  j&                  d      }|j)                  |      }|j0                  r,|j0                  j2                  r|j0                  j2                  n|j2                  }t5        |||g      }d|_        ||_        	 |j;                          |j0                  j2                  s|j2                  r(t=        j>                  | d|jA                                 n't=        jB                  | d|jA                                  tI        d      S c c}w # tD        $ r!}t=        jF                  | d       Y d}~/d}~ww xY w)zK
    This method is used to send acknowledgement mail to the candidate
    r7   subjectri   r&   )id__inother_attachmentsr6   template_attachmentsT)flatrf   DocumentF)pathtitlezapplication/pdf)rr   ri   tohtmlzMail sent to zEmail not set for zSomething went wrongNz)<script>window.location.reload()</script>)%POSTr)   getlistr   r:   r.   FILESnamereadcontent_typenonedistinctlistr   values_listr   rj   rk   rl   rm   r   appendr   contentemployee_work_infoemailr   content_subtypeattachmentssendr   successget_full_nameinfo	Exceptionerrorr	   )r/   employee_idrr   bdyemployee_idsr&   rt   filer   employee_objtemplate_attachment_idsr8   bodysr{   rn   rO   
render_bdysend_to_mailr   es                       r   send_mail_to_employeer      s    ,,t$Klly)G
,,

6
"C<<''4L  ''|'<I--.AB@Q8<DIIK!2!23K  ''..+.>'',,.\)335I%ll223IJ /<''... / k&tk,

  	D#,,T2L&&%w||/H/HIG &,,W5J Re:NVV%	  ((-""!7<<+D+DE
 "((1
 **x/J/J/P/P ''-- 	 ~

 !''	<JJL**00HNN  M(:P:P:R9S*TUg);H<R<R<T;U'VW[/<` CDDwr  	<NN7$:;;	<s    .M7BM	M5M00M5)N)*__doc__jsondatetimer   djangor   django.appsr   django.contribr   django.core.mailr   django.core.paginatorr   django.httpr	   r
   django.shortcutsr   base.backendsr   base.methodsr   r   base.modelsr   employee.filtersr   employee.modelsr   horillar   horilla.decoratorsr   r   r   r!   r3   r=   rc   ro   r    r   r   <module>r      s       # ) + 2 # 0 2 + + $  @ +, - . +,
N - 
N -. / " -.A / AH ( (" 56GE 7 GEr   