[fix] [hr] letter head in salary slip email

This commit is contained in:
Nabin Hait 2013-07-11 11:11:34 +05:30
parent d96bfaf6af
commit 76cacdbb78

View File

@ -33,16 +33,12 @@ class DocType(TransactionBase):
self.doc = doc self.doc = doc
self.doclist = doclist self.doclist = doclist
def autoname(self): def autoname(self):
self.doc.name = make_autoname('Sal Slip/' +self.doc.employee + '/.#####') self.doc.name = make_autoname('Sal Slip/' +self.doc.employee + '/.#####')
def get_emp_and_leave_details(self): def get_emp_and_leave_details(self):
if self.doc.employee: if self.doc.employee:
self.get_leave_details() self.get_leave_details()
# check sal structure
struct = self.check_sal_struct() struct = self.check_sal_struct()
if struct: if struct:
self.pull_sal_struct(struct) self.pull_sal_struct(struct)
@ -91,16 +87,18 @@ class DocType(TransactionBase):
where name = %s", self.doc.employee, as_dict=1)[0] where name = %s", self.doc.employee, as_dict=1)[0]
if emp['relieving_date']: if emp['relieving_date']:
if getdate(emp['relieving_date']) > m['month_start_date'] and getdate(emp['relieving_date']) < m['month_end_date']: if getdate(emp['relieving_date']) > m['month_start_date'] and \
payment_days = getdate(emp['relieving_date']).day getdate(emp['relieving_date']) < m['month_end_date']:
payment_days = getdate(emp['relieving_date']).day
elif getdate(emp['relieving_date']) < m['month_start_date']: elif getdate(emp['relieving_date']) < m['month_start_date']:
webnotes.msgprint(_("Relieving Date of employee is ") + cstr(emp['relieving_date'] webnotes.msgprint(_("Relieving Date of employee is ") + cstr(emp['relieving_date']
+ _(". Please set status of the employee as 'Left'")), raise_exception=1) + _(". Please set status of the employee as 'Left'")), raise_exception=1)
if emp['date_of_joining']: if emp['date_of_joining']:
if getdate(emp['date_of_joining']) > m['month_start_date'] and getdate(emp['date_of_joining']) < m['month_end_date']: if getdate(emp['date_of_joining']) > m['month_start_date'] and \
payment_days = payment_days - getdate(emp['date_of_joining']).day + 1 getdate(emp['date_of_joining']) < m['month_end_date']:
payment_days = payment_days - getdate(emp['date_of_joining']).day + 1
elif getdate(emp['date_of_joining']) > m['month_end_date']: elif getdate(emp['date_of_joining']) > m['month_end_date']:
payment_days = 0 payment_days = 0
@ -110,9 +108,16 @@ class DocType(TransactionBase):
def calculate_lwp(self, m): def calculate_lwp(self, m):
holidays = sql("select t1.holiday_date from `tabHoliday` t1, tabEmployee t2 where t1.parent = t2.holiday_list and t2.name = '%s' and t1.holiday_date between '%s' and '%s'" % (self.doc.employee, m['month_start_date'], m['month_end_date'])) holidays = sql("""select t1.holiday_date
from `tabHoliday` t1, tabEmployee t2
where t1.parent = t2.holiday_list and t2.name = %s
and t1.holiday_date between %s and %s""",
(self.doc.employee, m['month_start_date'], m['month_end_date']))
if not holidays: if not holidays:
holidays = sql("select t1.holiday_date from `tabHoliday` t1, `tabHoliday List` t2 where t1.parent = t2.name and ifnull(t2.is_default, 0) = 1 and t2.fiscal_year = '%s'" % self.doc.fiscal_year) holidays = sql("""select t1.holiday_date
from `tabHoliday` t1, `tabHoliday List` t2
where t1.parent = t2.name and ifnull(t2.is_default, 0) = 1
and t2.fiscal_year = %s""", self.doc.fiscal_year)
holidays = [cstr(i[0]) for i in holidays] holidays = [cstr(i[0]) for i in holidays]
lwp = 0 lwp = 0
for d in range(m['month_days']): for d in range(m['month_days']):
@ -124,20 +129,22 @@ class DocType(TransactionBase):
where t2.name = t1.leave_type where t2.name = t1.leave_type
and ifnull(t2.is_lwp, 0) = 1 and ifnull(t2.is_lwp, 0) = 1
and t1.docstatus = 1 and t1.docstatus = 1
and t1.employee = '%s' and t1.employee = %s
and '%s' between from_date and to_date and %s between from_date and to_date
"""%(self.doc.employee, dt)) """, (self.doc.employee, dt))
if leave: if leave:
lwp = cint(leave[0][1]) and lwp + 0.5 or lwp + 1 lwp = cint(leave[0][1]) and lwp + 0.5 or lwp + 1
return lwp return lwp
def check_existing(self): def check_existing(self):
ret_exist = sql("select name from `tabSalary Slip` where month = '%s' and fiscal_year = '%s' and docstatus != 2 and employee = '%s' and name !='%s'" % (self.doc.month,self.doc.fiscal_year,self.doc.employee,self.doc.name)) ret_exist = sql("""select name from `tabSalary Slip`
where month = %s and fiscal_year = %s and docstatus != 2
and employee = %s and name != %s""",
(self.doc.month, self.doc.fiscal_year, self.doc.employee, self.doc.name))
if ret_exist: if ret_exist:
msgprint("Salary Slip of employee '%s' already created for this month" % self.doc.employee)
self.doc.employee = '' self.doc.employee = ''
raise Exception msgprint("Salary Slip of employee '%s' already created for this month"
% self.doc.employee, raise_exception=1)
def validate(self): def validate(self):
@ -146,41 +153,32 @@ class DocType(TransactionBase):
company_currency = get_company_currency(self.doc.company) company_currency = get_company_currency(self.doc.company)
self.doc.total_in_words = money_in_words(self.doc.rounded_total, company_currency) self.doc.total_in_words = money_in_words(self.doc.rounded_total, company_currency)
def calculate_earning_total(self): def calculate_earning_total(self):
"""
Calculates total earnings considering lwp
"""
self.doc.gross_pay = flt(self.doc.arrear_amount) + flt(self.doc.leave_encashment_amount) self.doc.gross_pay = flt(self.doc.arrear_amount) + flt(self.doc.leave_encashment_amount)
for d in getlist(self.doclist, 'earning_details'): for d in getlist(self.doclist, 'earning_details'):
if cint(d.e_depends_on_lwp) == 1: if cint(d.e_depends_on_lwp) == 1:
d.e_modified_amount = round(flt(d.e_amount)*flt(self.doc.payment_days)/cint(self.doc.total_days_in_month), 2) d.e_modified_amount = round(flt(d.e_amount) * flt(self.doc.payment_days)
/ cint(self.doc.total_days_in_month), 2)
elif not self.doc.payment_days: elif not self.doc.payment_days:
d.e_modified_amount = 0 d.e_modified_amount = 0
self.doc.gross_pay += flt(d.e_modified_amount) self.doc.gross_pay += flt(d.e_modified_amount)
def calculate_ded_total(self): def calculate_ded_total(self):
"""
Calculates total deduction considering lwp
"""
self.doc.total_deduction = 0 self.doc.total_deduction = 0
for d in getlist(self.doclist, 'deduction_details'): for d in getlist(self.doclist, 'deduction_details'):
if cint(d.d_depends_on_lwp) == 1: if cint(d.d_depends_on_lwp) == 1:
d.d_modified_amount = round(flt(d.d_amount)*flt(self.doc.payment_days)/cint(self.doc.total_days_in_month), 2) d.d_modified_amount = round(flt(d.d_amount) * flt(self.doc.payment_days)
/ cint(self.doc.total_days_in_month), 2)
elif not self.doc.payment_days: elif not self.doc.payment_days:
d.d_modified_amount = 0 d.d_modified_amount = 0
self.doc.total_deduction += flt(d.d_modified_amount) self.doc.total_deduction += flt(d.d_modified_amount)
def calculate_net_pay(self): def calculate_net_pay(self):
"""
Calculate net payment
"""
self.calculate_earning_total() self.calculate_earning_total()
self.calculate_ded_total() self.calculate_ded_total()
self.doc.net_pay = flt(self.doc.gross_pay) - flt(self.doc.total_deduction) self.doc.net_pay = flt(self.doc.gross_pay) - flt(self.doc.total_deduction)
self.doc.rounded_total = round(self.doc.net_pay) self.doc.rounded_total = round(self.doc.net_pay)
def on_submit(self): def on_submit(self):
if(self.doc.email_check == 1): if(self.doc.email_check == 1):
@ -189,12 +187,13 @@ class DocType(TransactionBase):
def send_mail_funct(self): def send_mail_funct(self):
from webnotes.utils.email_lib import sendmail from webnotes.utils.email_lib import sendmail
emailid_ret=sql("select company_email from `tabEmployee` where name = '%s'"%self.doc.employee) receiver = webnotes.conn.get_value("Employee", self.doc.employee, "company_email")
if emailid_ret: if receiver:
receiver = cstr(emailid_ret[0][0])
subj = 'Salary Slip - ' + cstr(self.doc.month) +'/'+cstr(self.doc.fiscal_year) subj = 'Salary Slip - ' + cstr(self.doc.month) +'/'+cstr(self.doc.fiscal_year)
earn_ret=sql("select e_type,e_modified_amount from `tabSalary Slip Earning` where parent = '%s'"%self.doc.name) earn_ret=sql("""select e_type, e_modified_amount from `tabSalary Slip Earning`
ded_ret=sql("select d_type,d_modified_amount from `tabSalary Slip Deduction` where parent = '%s'"%self.doc.name) where parent = %s""", self.doc.name)
ded_ret=sql("""select d_type, d_modified_amount from `tabSalary Slip Deduction`
where parent = %s""", self.doc.name)
earn_table = '' earn_table = ''
ded_table = '' ded_table = ''
@ -203,9 +202,10 @@ class DocType(TransactionBase):
for e in earn_ret: for e in earn_ret:
if not e[1]: if not e[1]:
earn_table +='<tr><td>%s</td><td align="right">0.00</td></tr>'%(cstr(e[0])) earn_table += '<tr><td>%s</td><td align="right">0.00</td></tr>' % cstr(e[0])
else: else:
earn_table +='<tr><td>%s</td><td align="right">%s</td></tr>'%(cstr(e[0]),cstr(e[1])) earn_table += '<tr><td>%s</td><td align="right">%s</td></tr>' \
% (cstr(e[0]), cstr(e[1]))
earn_table += '</table>' earn_table += '</table>'
if ded_ret: if ded_ret:
@ -214,15 +214,14 @@ class DocType(TransactionBase):
for d in ded_ret: for d in ded_ret:
if not d[1]: if not d[1]:
ded_table +='<tr><td">%s</td><td align="right">0.00</td></tr>'%(cstr(d[0])) ded_table +='<tr><td">%s</td><td align="right">0.00</td></tr>' % cstr(d[0])
else: else:
ded_table +='<tr><td>%s</td><td align="right">%s</td></tr>'%(cstr(d[0]),cstr(d[1])) ded_table +='<tr><td>%s</td><td align="right">%s</td></tr>' \
% (cstr(d[0]), cstr(d[1]))
ded_table += '</table>' ded_table += '</table>'
letter_head = sql("select value from `tabSingles` where field = 'letter_head' and doctype = 'Control Panel'") letter_head = webnotes.conn.get_value("Letter Head", {"is_default": 1, "disabled": 0},
"content")
if not letter_head:
letter_head = ''
msg = '''<div> %s <br> msg = '''<div> %s <br>
<table cellspacing= "5" cellpadding="5" width = "100%%"> <table cellspacing= "5" cellpadding="5" width = "100%%">
@ -258,8 +257,10 @@ class DocType(TransactionBase):
</table> </table>
<table border="1px solid #CCC" width="100%%" cellpadding="0px" cellspacing="0px"> <table border="1px solid #CCC" width="100%%" cellpadding="0px" cellspacing="0px">
<tr> <tr>
<td colspan = 2 width = "50%%" bgcolor="#CCC" align="center"><b>Earnings</b></td> <td colspan = 2 width = "50%%" bgcolor="#CCC" align="center">
<td colspan = 2 width = "50%%" bgcolor="#CCC" align="center"><b>Deductions</b></td> <b>Earnings</b></td>
<td colspan = 2 width = "50%%" bgcolor="#CCC" align="center">
<b>Deductions</b></td>
</tr> </tr>
<tr> <tr>
<td colspan = 2 width = "50%%" valign= "top">%s</td> <td colspan = 2 width = "50%%" valign= "top">%s</td>
@ -268,17 +269,28 @@ class DocType(TransactionBase):
</table> </table>
<table cellspacing= "5" cellpadding="5" width = '100%%'> <table cellspacing= "5" cellpadding="5" width = '100%%'>
<tr> <tr>
<td width = '25%%'><b>Gross Pay :</b> </td><td width = '25%%' align='right'>%s</td> <td width = '25%%'><b>Gross Pay :</b> </td>
<td width = '25%%'><b>Total Deduction :</b></td><td width = '25%%' align='right'> %s</td> <td width = '25%%' align='right'>%s</td>
<td width = '25%%'><b>Total Deduction :</b></td>
<td width = '25%%' align='right'> %s</td>
</tr> </tr>
<tr> <tr>
<tdwidth='25%%'><b>Net Pay : </b></td><td width = '25%%' align='right'><b>%s</b></td> <tdwidth='25%%'><b>Net Pay : </b></td>
<td width = '25%%' align='right'><b>%s</b></td>
<td colspan = '2' width = '50%%'></td> <td colspan = '2' width = '50%%'></td>
</tr> </tr>
<tr> <tr>
<td width='25%%'><b>Net Pay(in words) : </td><td colspan = '3' width = '50%%'>%s</b></td> <td width='25%%'><b>Net Pay(in words) : </td>
<td colspan = '3' width = '50%%'>%s</b></td>
</tr> </tr>
</table></div>'''%(cstr(letter_head[0][0]),cstr(self.doc.employee), cstr(self.doc.employee_name), cstr(self.doc.month), cstr(self.doc.fiscal_year), cstr(self.doc.department), cstr(self.doc.branch), cstr(self.doc.designation), cstr(self.doc.grade), cstr(self.doc.bank_account_no), cstr(self.doc.bank_name), cstr(self.doc.arrear_amount), cstr(self.doc.payment_days), earn_table, ded_table, cstr(flt(self.doc.gross_pay)), cstr(flt(self.doc.total_deduction)), cstr(flt(self.doc.net_pay)), cstr(self.doc.total_in_words)) </table></div>''' % (cstr(letter_head), cstr(self.doc.employee),
cstr(self.doc.employee_name), cstr(self.doc.month), cstr(self.doc.fiscal_year),
cstr(self.doc.department), cstr(self.doc.branch), cstr(self.doc.designation),
cstr(self.doc.grade), cstr(self.doc.bank_account_no), cstr(self.doc.bank_name),
cstr(self.doc.arrear_amount), cstr(self.doc.payment_days), earn_table, ded_table,
cstr(flt(self.doc.gross_pay)), cstr(flt(self.doc.total_deduction)),
cstr(flt(self.doc.net_pay)), cstr(self.doc.total_in_words))
sendmail([receiver], subject=subj, msg = msg) sendmail([receiver], subject=subj, msg = msg)
else: else:
msgprint("Company Email ID not found, hence mail not sent") msgprint("Company Email ID not found, hence mail not sent")