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) {
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){
$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
//-----------------------
cur_frm.cscript['Make Bank Voucher'] = function(doc,cdt,cdn){
if(doc.month && doc.fiscal_year){
cur_frm.cscript.make_jv(doc, cdt, cdn);
@ -14,7 +40,7 @@ cur_frm.cscript['Make Bank Voucher'] = function(doc,cdt,cdn){
// Make JV
// --------
//-----------------------
cur_frm.cscript.make_jv = function(doc, dt, dn) {
var call_back = function(r,rt){
var jv = LocalDB.create('Journal Voucher');

View File

@ -64,7 +64,14 @@ class DocType:
Creates salary slip for selected employees if already not created
"""
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:
if not sql("""select name from `tabSalary Slip`
where docstatus!= 2 and employee = %s and month = %s and fiscal_year = %s and company = %s
@ -87,7 +94,10 @@ class DocType:
d.save()
for d in getlist(ss_obj.doclist, 'deduction_details'):
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):
"""
@ -107,11 +117,21 @@ class DocType:
Submit all salary slips based on selected criteria
"""
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:
ss_obj = get_obj("Salary Slip",ss[0],with_children=1)
set(ss_obj.doc, 'docstatus', 1)
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):
"""
@ -133,8 +153,8 @@ class DocType:
amt = self.get_total_salary()
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]:
#msgprint("You can set Default Salary Head and Default Bank Account in Setup --> Global Defaults.")
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.")
ret = {
'def_bank_acc' : com and com[0][0] or '',

View File

@ -5,14 +5,14 @@
{
'creation': '2011-08-11 16:40:04',
'docstatus': 0,
'modified': '2011-08-12 14:08:33',
'modified': '2011-08-25 12:02:57',
'modified_by': 'Administrator',
'owner': 'Administrator'
},
# These values are common for all DocType
{
'_last_update': '1313129645',
'_last_update': '1314179318',
'allow_copy': 1,
'allow_email': 1,
'allow_print': 1,
@ -24,7 +24,7 @@
'name': '__common__',
'section_style': 'Simple',
'show_in_menu': 1,
'version': 15
'version': 29
},
# These values are common for all DocField
@ -77,11 +77,28 @@
'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
{
'doctype': 'DocField',
'fieldtype': 'Column Break',
'idx': 1,
'idx': 3,
'width': '50%'
},
@ -90,9 +107,10 @@
'doctype': 'DocField',
'fieldname': 'company',
'fieldtype': 'Select',
'idx': 2,
'idx': 4,
'label': 'Company',
'options': 'link:Company'
'options': 'link:Company',
'reqd': 1
},
# DocField
@ -100,7 +118,7 @@
'doctype': 'DocField',
'fieldname': 'branch',
'fieldtype': 'Link',
'idx': 3,
'idx': 5,
'label': 'Branch',
'options': 'Branch'
},
@ -110,7 +128,7 @@
'doctype': 'DocField',
'fieldname': 'department',
'fieldtype': 'Link',
'idx': 4,
'idx': 6,
'label': 'Department',
'options': 'Department'
},
@ -120,7 +138,7 @@
'doctype': 'DocField',
'fieldname': 'designation',
'fieldtype': 'Link',
'idx': 5,
'idx': 7,
'label': 'Designation',
'options': 'Designation'
},
@ -129,7 +147,7 @@
{
'doctype': 'DocField',
'fieldtype': 'Column Break',
'idx': 6,
'idx': 8,
'width': '50%'
},
@ -138,7 +156,7 @@
'doctype': 'DocField',
'fieldname': 'grade',
'fieldtype': 'Select',
'idx': 7,
'idx': 9,
'label': 'Grade',
'options': 'link:Grade'
},
@ -148,7 +166,7 @@
'doctype': 'DocField',
'fieldname': 'employment_type',
'fieldtype': 'Select',
'idx': 8,
'idx': 10,
'label': 'Employment Type',
'options': 'link:Employment Type'
},
@ -159,7 +177,7 @@
'doctype': 'DocField',
'fieldname': 'fiscal_year',
'fieldtype': 'Select',
'idx': 9,
'idx': 11,
'label': 'Fiscal Year',
'options': 'link:Fiscal Year',
'reqd': 1
@ -171,7 +189,7 @@
'doctype': 'DocField',
'fieldname': 'month',
'fieldtype': 'Select',
'idx': 10,
'idx': 12,
'label': 'Month',
'options': '\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12',
'reqd': 1
@ -184,7 +202,7 @@
'doctype': 'DocField',
'fieldname': 'send_email',
'fieldtype': 'Check',
'idx': 11,
'idx': 13,
'label': 'Send Email'
},
@ -192,14 +210,14 @@
{
'doctype': 'DocField',
'fieldtype': 'Section Break',
'idx': 12
'idx': 14
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Column Break',
'idx': 13,
'idx': 15,
'width': '50%'
},
@ -209,28 +227,9 @@
'description': 'Creates salary slip for above mentioned criteria.',
'doctype': 'DocField',
'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,
'label': 'Submit Salary Slip',
'options': 'submit_salary_slip'
'label': 'Create Salary Slip',
'trigger': 'Client'
},
# DocField
@ -244,11 +243,45 @@
# DocField
{
'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',
'fieldtype': 'Button',
'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',
'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

@ -3,25 +3,25 @@ cur_frm.add_fetch('employee', 'company', 'company');
// On load
// -------------------------------------------------------------------
cur_frm.cscript.onload = function(doc,dt,dn){
if((cint(doc.__islocal) == 1) && !doc.amended_from){
var today=new Date();
month = (today.getMonth()+01).toString();
if(month.length>1) doc.month = month;
else doc.month = '0'+month;
if((cint(doc.__islocal) == 1) && !doc.amended_from){
var today=new Date();
month = (today.getMonth()+01).toString();
if(month.length>1) doc.month = month;
else doc.month = '0'+month;
doc.fiscal_year = sys_defaults['fiscal_year'];
refresh_many(['month', 'fiscal_year']);
cur_frm.cscript.fiscal_year(doc, dt, dn);
}
refresh_many(['month', 'fiscal_year']);
cur_frm.cscript.fiscal_year(doc, dt, dn);
}
}
// Get leave details
//---------------------------------------------------------------------
cur_frm.cscript.fiscal_year = function(doc,dt,dn){
$c_obj(make_doclist(doc.doctype,doc.name), 'get_emp_and_leave_details','',function(r, rt) {
var doc = locals[dt][dn];
cur_frm.refresh();
calculate_all(doc, dt, dn);
});
$c_obj(make_doclist(doc.doctype,doc.name), 'get_emp_and_leave_details','',function(r, rt) {
var doc = locals[dt][dn];
cur_frm.refresh();
calculate_all(doc, dt, dn);
});
}
cur_frm.cscript.month = cur_frm.cscript.employee = cur_frm.cscript.fiscal_year;
@ -29,24 +29,24 @@ cur_frm.cscript.month = cur_frm.cscript.employee = cur_frm.cscript.fiscal_year;
// Calculate total if lwp exists
// ------------------------------------------------------------------------
cur_frm.cscript.leave_without_pay = function(doc,dt,dn){
doc.payment_days = flt(doc.total_days_in_month) - flt(doc.leave_without_pay);
refresh_field('payment_days');
calculate_all(doc, dt, dn);
doc.payment_days = flt(doc.total_days_in_month) - flt(doc.leave_without_pay);
refresh_field('payment_days');
calculate_all(doc, dt, dn);
}
// Calculate all
// ------------------------------------------------------------------------
var calculate_all = function(doc, dt, dn) {
calculate_earning_total(doc, dt, dn);
calculate_ded_total(doc, dt, dn);
calculate_net_pay(doc, dt, dn);
calculate_earning_total(doc, dt, dn);
calculate_ded_total(doc, dt, dn);
calculate_net_pay(doc, dt, dn);
}
// Trigger on earning modified amount and depends on lwp
// ------------------------------------------------------------------------
cur_frm.cscript.e_modified_amount = function(doc,dt,dn){
calculate_earning_total(doc, dt, dn);
calculate_net_pay(doc, dt, dn);
calculate_earning_total(doc, dt, dn);
calculate_net_pay(doc, dt, dn);
}
cur_frm.cscript.e_depends_on_lwp = cur_frm.cscript.e_modified_amount;
@ -54,8 +54,8 @@ cur_frm.cscript.e_depends_on_lwp = cur_frm.cscript.e_modified_amount;
// Trigger on earning modified amount and depends on lwp
// ------------------------------------------------------------------------
cur_frm.cscript.d_modified_amount = function(doc,dt,dn){
calculate_ded_total(doc, dt, dn);
calculate_net_pay(doc, dt, dn);
calculate_ded_total(doc, dt, dn);
calculate_net_pay(doc, dt, dn);
}
cur_frm.cscript.d_depends_on_lwp = cur_frm.cscript.d_modified_amount;
@ -63,50 +63,50 @@ cur_frm.cscript.d_depends_on_lwp = cur_frm.cscript.d_modified_amount;
// Calculate earning total
// ------------------------------------------------------------------------
var calculate_earning_total = function(doc, dt, dn) {
var tbl = getchildren('SS Earning Detail', doc.name, 'earning_details', doc.doctype);
var tbl = getchildren('SS Earning Detail', doc.name, 'earning_details', doc.doctype);
var total_earn = 0;
for(var i = 0; i < tbl.length; i++){
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));
refresh_field('e_modified_amount', tbl[i].name, 'earning_details');
}
total_earn += flt(tbl[i].e_modified_amount);
}
doc.gross_pay = total_earn + flt(doc.arrear_amount) + flt(doc.leave_encashment_amount);
refresh_many(['e_modified_amount', 'gross_pay']);
var total_earn = 0;
for(var i = 0; i < tbl.length; i++){
if(cint(tbl[i].e_depends_on_lwp) == 1) {
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');
}
total_earn += flt(tbl[i].e_modified_amount);
}
doc.gross_pay = total_earn + flt(doc.arrear_amount) + flt(doc.leave_encashment_amount);
refresh_many(['e_modified_amount', 'gross_pay']);
}
// Calculate deduction total
// ------------------------------------------------------------------------
var calculate_ded_total = function(doc, dt, dn) {
var tbl = getchildren('SS Deduction Detail', doc.name, 'deduction_details', doc.doctype);
var tbl = getchildren('SS Deduction Detail', doc.name, 'deduction_details', doc.doctype);
var total_ded = 0;
for(var i = 0; i < tbl.length; i++){
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));
var total_ded = 0;
for(var i = 0; i < tbl.length; i++){
if(cint(tbl[i].d_depends_on_lwp) == 1) {
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');
}
total_ded += flt(tbl[i].d_modified_amount);
}
doc.total_deduction = total_ded;
refresh_field('total_deduction');
}
total_ded += flt(tbl[i].d_modified_amount);
}
doc.total_deduction = total_ded;
refresh_field('total_deduction');
}
// Calculate net payable amount
// ------------------------------------------------------------------------
var calculate_net_pay = function(doc, dt, dn) {
doc.net_pay = flt(doc.gross_pay) - flt(doc.total_deduction);
doc.net_pay = flt(doc.gross_pay) - flt(doc.total_deduction);
doc.rounded_total = Math.round(doc.net_pay);
refresh_many(['net_pay', 'rounded_total']);
refresh_many(['net_pay', 'rounded_total']);
}
// trigger on arrear
// ------------------------------------------------------------------------
cur_frm.cscript.arrear_amount = function(doc,dt,dn){
calculate_earning_total(doc, dt, dn);
calculate_net_pay(doc, dt, dn);
calculate_earning_total(doc, dt, dn);
calculate_net_pay(doc, dt, dn);
}
// trigger on encashed amount
@ -116,5 +116,5 @@ cur_frm.cscript.leave_encashment_amount = cur_frm.cscript.arrear_amount;
// validate
// ------------------------------------------------------------------------
cur_frm.cscript.validate = function(doc, dt, dn) {
calculate_all(doc, dt, dn);
calculate_all(doc, dt, dn);
}

View File

@ -68,7 +68,7 @@ class DocType(TransactionBase):
# Get leave details
#=======================================================
def get_leave_details(self):
m = self.get_month_details()
m = self.get_month_details()
lwp = self.calculate_lwp(m)
self.doc.total_days_in_month = m[3]
self.doc.leave_without_pay = lwp
@ -129,12 +129,45 @@ class DocType(TransactionBase):
self.check_existing()
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)
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
#=======================================================
def on_submit(self):
if(self.doc.email_check == 1):
self.send_mail_funct()
# Send mail
#=======================================================
@ -148,8 +181,7 @@ class DocType(TransactionBase):
earn_table = ''
ded_table = ''
if earn_ret:
if earn_ret:
earn_table += "<table cellspacing= '5' cellpadding='5' >"
for e in earn_ret:

View File

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