Salary Manager rewriten for multiple sal slip generation.

Test case included.
This commit is contained in:
Nabin Hait 2011-08-25 13:30:02 +05:30
parent da894640f3
commit 781b3eeb81
6 changed files with 225 additions and 170 deletions

View File

@ -1,11 +1,37 @@
var display_activity_log = function(msg) {
if(!pscript.ss_html)
pscript.ss_html = $a(cur_frm.fields_dict['Activity Log'].wrapper,'div','',{border:'1px solid #CCC', backgroundColor:'#CCC'});
pscript.ss_html.innerHTML = '<div style="color:#EEE; background-color:#555;"><b><i>Activity Log:</i><br></b></div>';
pscript.ss_html.innerHTML += '<div style="color:#666; padding: 5px">'+ msg + '</div>';
}
//Create salary slip
//-----------------------
cur_frm.cscript['Create Salary Slip'] = function(doc, cdt, cdn) {
var callback = function(r, rt){
if (r.message)
display_activity_log(r.message);
}
$c('runserverobj', args={'method':'create_sal_slip','docs':compress_doclist(make_doclist (cdt, cdn))},callback);
}
//Submit salary slip
//-----------------------
cur_frm.cscript['Submit Salary Slip'] = function(doc, cdt, cdn) { cur_frm.cscript['Submit Salary Slip'] = function(doc, cdt, cdn) {
var check = confirm("DO you really want to Submit all Salary Slip for month : " + doc.month+" and fiscal year : "+doc.fiscal_year); var check = confirm("Do you really want to Submit all Salary Slip for month : " + doc.month+" and fiscal year : "+doc.fiscal_year);
if(check){ if(check){
$c('runserverobj', args={'method':'submit_salary_slip','docs':compress_doclist(make_doclist (cdt, cdn))},''); var callback = function(r, rt){
if (r.message)
display_activity_log(r.message);
}
$c('runserverobj', args={'method':'submit_salary_slip','docs':compress_doclist(make_doclist (cdt, cdn))},callback);
} }
} }
// Make Bank Voucher // Make Bank Voucher
//-----------------------
cur_frm.cscript['Make Bank Voucher'] = function(doc,cdt,cdn){ cur_frm.cscript['Make Bank Voucher'] = function(doc,cdt,cdn){
if(doc.month && doc.fiscal_year){ if(doc.month && doc.fiscal_year){
cur_frm.cscript.make_jv(doc, cdt, cdn); cur_frm.cscript.make_jv(doc, cdt, cdn);
@ -14,7 +40,7 @@ cur_frm.cscript['Make Bank Voucher'] = function(doc,cdt,cdn){
// Make JV // Make JV
// -------- //-----------------------
cur_frm.cscript.make_jv = function(doc, dt, dn) { cur_frm.cscript.make_jv = function(doc, dt, dn) {
var call_back = function(r,rt){ var call_back = function(r,rt){
var jv = LocalDB.create('Journal Voucher'); var jv = LocalDB.create('Journal Voucher');

View File

@ -64,7 +64,14 @@ class DocType:
Creates salary slip for selected employees if already not created Creates salary slip for selected employees if already not created
""" """
emp_list = self.get_emp_list() emp_list = self.get_emp_list()
log = ""
if emp_list:
log = "<table><tr><td>Following Salary Slip has been created: </td></tr><tr><td><u>SAL SLIP ID</u></td><td><u>EMPLOYEE NAME</u></td></tr>"
else:
log = "<table><tr><td>No employee found for the above selected criteria</td></tr>"
for emp in emp_list: for emp in emp_list:
if not sql("""select name from `tabSalary Slip` if not sql("""select name from `tabSalary Slip`
where docstatus!= 2 and employee = %s and month = %s and fiscal_year = %s and company = %s where docstatus!= 2 and employee = %s and month = %s and fiscal_year = %s and company = %s
@ -88,6 +95,9 @@ class DocType:
for d in getlist(ss_obj.doclist, 'deduction_details'): for d in getlist(ss_obj.doclist, 'deduction_details'):
d.save() d.save()
log += '<tr><td>' + ss.name + '</td><td>' + ss_obj.doc.employee_name + '</td></tr>'
log += '</table>'
return log
def get_sal_slip_list(self): def get_sal_slip_list(self):
""" """
@ -107,11 +117,21 @@ class DocType:
Submit all salary slips based on selected criteria Submit all salary slips based on selected criteria
""" """
ss_list = self.get_sal_slip_list() ss_list = self.get_sal_slip_list()
log = ""
if ss_list:
log = "<table><tr><td>Following Salary Slip has been submitted: </td></tr><tr><td><u>SAL SLIP ID</u></td><td><u>EMPLOYEE NAME</u></td></tr>"
else:
log = "<table><tr><td>No salary slip found to submit for the above selected criteria</td></tr>"
for ss in ss_list: for ss in ss_list:
ss_obj = get_obj("Salary Slip",ss[0],with_children=1) ss_obj = get_obj("Salary Slip",ss[0],with_children=1)
set(ss_obj.doc, 'docstatus', 1) set(ss_obj.doc, 'docstatus', 1)
ss_obj.on_submit() ss_obj.on_submit()
log += '<tr><td>' + ss[0] + '</td><td>' + ss_obj.doc.employee_name + '</td></tr>'
log += '</table>'
return log
def get_total_salary(self): def get_total_salary(self):
""" """
@ -133,8 +153,8 @@ class DocType:
amt = self.get_total_salary() amt = self.get_total_salary()
com = sql("select default_bank_account,default_salary_acount from `tabCompany` where name = '%s'" % self.doc.company) com = sql("select default_bank_account,default_salary_acount from `tabCompany` where name = '%s'" % self.doc.company)
#if not com[0][0] or not com[0][1]: if not com[0][0] or not com[0][1]:
#msgprint("You can set Default Salary Head and Default Bank Account in Setup --> Global Defaults.") msgprint("You can set Default Salary Head and Default Bank Account in Setup --> Global Defaults.")
ret = { ret = {
'def_bank_acc' : com and com[0][0] or '', 'def_bank_acc' : com and com[0][0] or '',

View File

@ -5,14 +5,14 @@
{ {
'creation': '2011-08-11 16:40:04', 'creation': '2011-08-11 16:40:04',
'docstatus': 0, 'docstatus': 0,
'modified': '2011-08-12 14:08:33', 'modified': '2011-08-25 12:02:57',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'owner': 'Administrator' 'owner': 'Administrator'
}, },
# These values are common for all DocType # These values are common for all DocType
{ {
'_last_update': '1313129645', '_last_update': '1314179318',
'allow_copy': 1, 'allow_copy': 1,
'allow_email': 1, 'allow_email': 1,
'allow_print': 1, 'allow_print': 1,
@ -24,7 +24,7 @@
'name': '__common__', 'name': '__common__',
'section_style': 'Simple', 'section_style': 'Simple',
'show_in_menu': 1, 'show_in_menu': 1,
'version': 15 'version': 29
}, },
# These values are common for all DocField # These values are common for all DocField
@ -77,11 +77,28 @@
'role': 'HR Manager' 'role': 'HR Manager'
}, },
# DocField
{
'colour': 'White:FFF',
'doctype': 'DocField',
'fieldtype': 'HTML',
'idx': 1,
'label': 'Document Description',
'options': '<div class="field_description">You can generate multiple salary slips based on the selected criteria, submit and mail those to the employee directly from here</div>'
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Section Break',
'idx': 2
},
# DocField # DocField
{ {
'doctype': 'DocField', 'doctype': 'DocField',
'fieldtype': 'Column Break', 'fieldtype': 'Column Break',
'idx': 1, 'idx': 3,
'width': '50%' 'width': '50%'
}, },
@ -90,9 +107,10 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'company', 'fieldname': 'company',
'fieldtype': 'Select', 'fieldtype': 'Select',
'idx': 2, 'idx': 4,
'label': 'Company', 'label': 'Company',
'options': 'link:Company' 'options': 'link:Company',
'reqd': 1
}, },
# DocField # DocField
@ -100,7 +118,7 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'branch', 'fieldname': 'branch',
'fieldtype': 'Link', 'fieldtype': 'Link',
'idx': 3, 'idx': 5,
'label': 'Branch', 'label': 'Branch',
'options': 'Branch' 'options': 'Branch'
}, },
@ -110,7 +128,7 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'department', 'fieldname': 'department',
'fieldtype': 'Link', 'fieldtype': 'Link',
'idx': 4, 'idx': 6,
'label': 'Department', 'label': 'Department',
'options': 'Department' 'options': 'Department'
}, },
@ -120,7 +138,7 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'designation', 'fieldname': 'designation',
'fieldtype': 'Link', 'fieldtype': 'Link',
'idx': 5, 'idx': 7,
'label': 'Designation', 'label': 'Designation',
'options': 'Designation' 'options': 'Designation'
}, },
@ -129,7 +147,7 @@
{ {
'doctype': 'DocField', 'doctype': 'DocField',
'fieldtype': 'Column Break', 'fieldtype': 'Column Break',
'idx': 6, 'idx': 8,
'width': '50%' 'width': '50%'
}, },
@ -138,7 +156,7 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'grade', 'fieldname': 'grade',
'fieldtype': 'Select', 'fieldtype': 'Select',
'idx': 7, 'idx': 9,
'label': 'Grade', 'label': 'Grade',
'options': 'link:Grade' 'options': 'link:Grade'
}, },
@ -148,7 +166,7 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'employment_type', 'fieldname': 'employment_type',
'fieldtype': 'Select', 'fieldtype': 'Select',
'idx': 8, 'idx': 10,
'label': 'Employment Type', 'label': 'Employment Type',
'options': 'link:Employment Type' 'options': 'link:Employment Type'
}, },
@ -159,7 +177,7 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'fiscal_year', 'fieldname': 'fiscal_year',
'fieldtype': 'Select', 'fieldtype': 'Select',
'idx': 9, 'idx': 11,
'label': 'Fiscal Year', 'label': 'Fiscal Year',
'options': 'link:Fiscal Year', 'options': 'link:Fiscal Year',
'reqd': 1 'reqd': 1
@ -171,7 +189,7 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'month', 'fieldname': 'month',
'fieldtype': 'Select', 'fieldtype': 'Select',
'idx': 10, 'idx': 12,
'label': 'Month', 'label': 'Month',
'options': '\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12', 'options': '\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12',
'reqd': 1 'reqd': 1
@ -184,7 +202,7 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'send_email', 'fieldname': 'send_email',
'fieldtype': 'Check', 'fieldtype': 'Check',
'idx': 11, 'idx': 13,
'label': 'Send Email' 'label': 'Send Email'
}, },
@ -192,14 +210,14 @@
{ {
'doctype': 'DocField', 'doctype': 'DocField',
'fieldtype': 'Section Break', 'fieldtype': 'Section Break',
'idx': 12 'idx': 14
}, },
# DocField # DocField
{ {
'doctype': 'DocField', 'doctype': 'DocField',
'fieldtype': 'Column Break', 'fieldtype': 'Column Break',
'idx': 13, 'idx': 15,
'width': '50%' 'width': '50%'
}, },
@ -209,28 +227,9 @@
'description': 'Creates salary slip for above mentioned criteria.', 'description': 'Creates salary slip for above mentioned criteria.',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldtype': 'Button', 'fieldtype': 'Button',
'idx': 14,
'label': 'Create Salary Slip',
'options': 'create_sal_slip'
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Column Break',
'idx': 15,
'width': '25%'
},
# DocField
{
'colour': 'White:FFF',
'description': 'Submit all salary slips for the particular year and month',
'doctype': 'DocField',
'fieldtype': 'Button',
'idx': 16, 'idx': 16,
'label': 'Submit Salary Slip', 'label': 'Create Salary Slip',
'options': 'submit_salary_slip' 'trigger': 'Client'
}, },
# DocField # DocField
@ -244,11 +243,45 @@
# DocField # DocField
{ {
'colour': 'White:FFF', 'colour': 'White:FFF',
'description': 'Create Bank Voucher for the total salary paid in the particular month and year', 'description': 'Submit all salary slips for the above selected criteria',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldtype': 'Button', 'fieldtype': 'Button',
'idx': 18, 'idx': 18,
'label': 'Submit Salary Slip',
'trigger': 'Client'
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Column Break',
'idx': 19,
'width': '25%'
},
# DocField
{
'colour': 'White:FFF',
'description': 'Create Bank Voucher for the total salary paid for the above selected criteria',
'doctype': 'DocField',
'fieldtype': 'Button',
'idx': 20,
'label': 'Make Bank Voucher', 'label': 'Make Bank Voucher',
'options': 'make_bank_voucher' 'trigger': 'Client'
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Section Break',
'idx': 21
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'HTML',
'idx': 22,
'label': 'Activity Log'
} }
] ]

View File

@ -68,7 +68,7 @@ var calculate_earning_total = function(doc, dt, dn) {
var total_earn = 0; var total_earn = 0;
for(var i = 0; i < tbl.length; i++){ for(var i = 0; i < tbl.length; i++){
if(cint(tbl[i].e_depends_on_lwp) == 1) { if(cint(tbl[i].e_depends_on_lwp) == 1) {
tbl[i].e_modified_amount = flt(tbl[i].e_amount)*(flt(doc.payment_days)/cint(doc.total_days_in_month)); tbl[i].e_modified_amount = Math.round(tbl[i].e_amount)*(flt(doc.payment_days)/cint(doc.total_days_in_month)*100)/100;
refresh_field('e_modified_amount', tbl[i].name, 'earning_details'); refresh_field('e_modified_amount', tbl[i].name, 'earning_details');
} }
total_earn += flt(tbl[i].e_modified_amount); total_earn += flt(tbl[i].e_modified_amount);
@ -85,7 +85,7 @@ var calculate_ded_total = function(doc, dt, dn) {
var total_ded = 0; var total_ded = 0;
for(var i = 0; i < tbl.length; i++){ for(var i = 0; i < tbl.length; i++){
if(cint(tbl[i].d_depends_on_lwp) == 1) { if(cint(tbl[i].d_depends_on_lwp) == 1) {
tbl[i].d_modified_amount = flt(tbl[i].d_amount)*(flt(doc.payment_days)/cint(doc.total_days_in_month)); tbl[i].d_modified_amount = Math.round(tbl[i].d_amount)*(flt(doc.payment_days)/cint(doc.total_days_in_month)*100)/100;
refresh_field('d_modified_amount', tbl[i].name, 'deduction_details'); refresh_field('d_modified_amount', tbl[i].name, 'deduction_details');
} }
total_ded += flt(tbl[i].d_modified_amount); total_ded += flt(tbl[i].d_modified_amount);

View File

@ -130,12 +130,45 @@ class DocType(TransactionBase):
dcc = TransactionBase().get_company_currency(self.doc.company) dcc = TransactionBase().get_company_currency(self.doc.company)
self.doc.total_in_words = get_obj('Sales Common').get_total_in_words(dcc, self.doc.rounded_total) self.doc.total_in_words = get_obj('Sales Common').get_total_in_words(dcc, self.doc.rounded_total)
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)
for d in getlist(self.doclist, 'earning_details'):
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)
self.doc.gross_pay += d.e_modified_amount
def calculate_ded_total(self):
"""
Calculates total deduction considering lwp
"""
self.doc.total_deduction = 0
for d in getlist(self.doclist, 'deduction_details'):
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)
self.doc.total_deduction += d.d_modified_amount
def calculate_net_pay(self):
"""
Calculate net payment
"""
self.calculate_earning_total()
self.calculate_ded_total()
self.doc.net_pay = flt(self.doc.gross_pay) - flt(self.doc.total_deduction)
self.doc.rounded_total = round(self.doc.net_pay)
# ON SUBMIT # ON SUBMIT
#======================================================= #=======================================================
def on_submit(self): def on_submit(self):
if(self.doc.email_check == 1): if(self.doc.email_check == 1):
self.send_mail_funct() self.send_mail_funct()
# Send mail # Send mail
#======================================================= #=======================================================
def send_mail_funct(self): def send_mail_funct(self):
@ -149,7 +182,6 @@ class DocType(TransactionBase):
earn_table = '' earn_table = ''
ded_table = '' ded_table = ''
if earn_ret: if earn_ret:
earn_table += "<table cellspacing= '5' cellpadding='5' >" earn_table += "<table cellspacing= '5' cellpadding='5' >"
for e in earn_ret: for e in earn_ret:

View File

@ -5,14 +5,14 @@
{ {
'creation': '2010-12-14 16:50:05', 'creation': '2010-12-14 16:50:05',
'docstatus': 0, 'docstatus': 0,
'modified': '2011-06-27 14:39:11', 'modified': '2011-08-11 16:56:38',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'owner': 'Administrator' 'owner': 'Administrator'
}, },
# These values are common for all DocType # These values are common for all DocType
{ {
'_last_update': '1308808105', '_last_update': '1311621379',
'colour': 'White:FFF', 'colour': 'White:FFF',
'doctype': 'DocType', 'doctype': 'DocType',
'module': 'HR', 'module': 'HR',
@ -21,7 +21,7 @@
'server_code_error': ' ', 'server_code_error': ' ',
'show_in_menu': 0, 'show_in_menu': 0,
'subject': 'For %(employee_name)s', 'subject': 'For %(employee_name)s',
'version': 586 'version': 587
}, },
# These values are common for all DocField # These values are common for all DocField
@ -39,7 +39,8 @@
'name': '__common__', 'name': '__common__',
'parent': 'Salary Structure', 'parent': 'Salary Structure',
'parentfield': 'permissions', 'parentfield': 'permissions',
'parenttype': 'DocType' 'parenttype': 'DocType',
'read': 1
}, },
# DocType, Salary Structure # DocType, Salary Structure
@ -54,9 +55,9 @@
'cancel': 0, 'cancel': 0,
'create': 0, 'create': 0,
'doctype': 'DocPerm', 'doctype': 'DocPerm',
'match': 'owner', 'idx': 1,
'permlevel': 0, 'permlevel': 0,
'read': 1, 'role': 'Employee',
'submit': 0, 'submit': 0,
'write': 0 'write': 0
}, },
@ -66,97 +67,40 @@
'amend': 0, 'amend': 0,
'cancel': 0, 'cancel': 0,
'create': 0, 'create': 0,
'doctype': 'DocPerm',
'match': 'owner',
'permlevel': 0,
'read': 1,
'submit': 0,
'write': 0
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': 'DocPerm',
'match': 'owner',
'permlevel': 0,
'read': 1,
'submit': 0,
'write': 0
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': 'DocPerm',
'match': 'owner',
'permlevel': 0,
'read': 1,
'submit': 0,
'write': 0
},
# DocPerm
{
'doctype': 'DocPerm',
'permlevel': 0,
'role': 'Sales User'
},
# DocPerm
{
'doctype': 'DocPerm', 'doctype': 'DocPerm',
'idx': 2, 'idx': 2,
'permlevel': 1, 'permlevel': 1,
'read': 1,
'role': 'All', 'role': 'All',
'submit': 0,
'write': 0 'write': 0
}, },
# DocPerm # DocPerm
{ {
'create': 1, 'amend': 0,
'cancel': 0,
'create': 0,
'doctype': 'DocPerm', 'doctype': 'DocPerm',
'idx': 3, 'idx': 3,
'permlevel': 0, 'permlevel': 0,
'read': 1,
'role': 'HR User', 'role': 'HR User',
'write': 1 'submit': 0,
'write': 0
}, },
# DocPerm # DocPerm
{ {
'amend': 1,
'cancel': 1,
'create': 1, 'create': 1,
'doctype': 'DocPerm', 'doctype': 'DocPerm',
'idx': 4, 'idx': 4,
'permlevel': 0, 'permlevel': 0,
'read': 1,
'role': 'HR Manager', 'role': 'HR Manager',
'submit': 1,
'write': 1 'write': 1
}, },
# DocPerm
{
'doctype': 'DocPerm',
'idx': 5,
'permlevel': 1,
'read': 1,
'role': 'HR Manager'
},
# DocPerm
{
'doctype': 'DocPerm',
'idx': 6,
'permlevel': 1,
'read': 1,
'role': 'HR User'
},
# DocField # DocField
{ {
'doctype': 'DocField', 'doctype': 'DocField',