From da894640f305ea44499f7c30b008f577739e3f7f Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 25 Aug 2011 13:26:54 +0530 Subject: [PATCH] deleted salary slip control panel --- hr/doctype/salary_manager/__init__.py | 4 + hr/doctype/salary_manager/salary_manager.js | 41 +++ hr/doctype/salary_manager/salary_manager.py | 144 ++++++++++ .../salary_manager.txt} | 266 ++++++++---------- .../salary_manager/test_salary_manager.py | 197 +++++++++++++ .../salary_slip_control_panel/__init__.py | 0 .../salary_slip_control_panel.js | 71 ----- .../salary_slip_control_panel.py | 137 --------- 8 files changed, 503 insertions(+), 357 deletions(-) create mode 100644 hr/doctype/salary_manager/__init__.py create mode 100644 hr/doctype/salary_manager/salary_manager.js create mode 100644 hr/doctype/salary_manager/salary_manager.py rename hr/doctype/{salary_slip_control_panel/salary_slip_control_panel.txt => salary_manager/salary_manager.txt} (56%) create mode 100644 hr/doctype/salary_manager/test_salary_manager.py delete mode 100644 hr/doctype/salary_slip_control_panel/__init__.py delete mode 100644 hr/doctype/salary_slip_control_panel/salary_slip_control_panel.js delete mode 100644 hr/doctype/salary_slip_control_panel/salary_slip_control_panel.py diff --git a/hr/doctype/salary_manager/__init__.py b/hr/doctype/salary_manager/__init__.py new file mode 100644 index 0000000000..cb6c600133 --- /dev/null +++ b/hr/doctype/salary_manager/__init__.py @@ -0,0 +1,4 @@ +from webnotes import ValidationError + +class SalarySlipExistsError(ValidationError): pass + diff --git a/hr/doctype/salary_manager/salary_manager.js b/hr/doctype/salary_manager/salary_manager.js new file mode 100644 index 0000000000..0c693f2cfb --- /dev/null +++ b/hr/doctype/salary_manager/salary_manager.js @@ -0,0 +1,41 @@ +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); + if(check){ + $c('runserverobj', args={'method':'submit_salary_slip','docs':compress_doclist(make_doclist (cdt, cdn))},''); + } +} + +// 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); + } +} + + +// Make JV +// -------- +cur_frm.cscript.make_jv = function(doc, dt, dn) { + var call_back = function(r,rt){ + var jv = LocalDB.create('Journal Voucher'); + jv = locals['Journal Voucher'][jv]; + jv.voucher_type = 'Bank Voucher'; + jv.remark = 'Payment of salary for month: ' + doc.month + 'and fiscal year: ' + doc.fiscal_year; + jv.fiscal_year = doc.fiscal_year; + jv.company = doc.company; + jv.posting_date = new Date(); + + // credit to bank + var d1 = LocalDB.add_child(jv, 'Journal Voucher Detail', 'entries'); + d1.account = r.message['default_bank_account']; + d1.credit = r.message['amount'] + + // debit to salary account + var d2 = LocalDB.add_child(jv, 'Journal Voucher Detail', 'entries'); + d2.account = r.message['default_salary_account']; + d2.debit = r.message['amount'] + + loaddoc('Journal Voucher', jv.name); + } + $c_obj(make_doclist(dt,dn),'get_acc_details','',call_back); +} diff --git a/hr/doctype/salary_manager/salary_manager.py b/hr/doctype/salary_manager/salary_manager.py new file mode 100644 index 0000000000..1642ef4eff --- /dev/null +++ b/hr/doctype/salary_manager/salary_manager.py @@ -0,0 +1,144 @@ +# Please edit this list and import only required elements +import webnotes + +from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, generate_hash, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add +from webnotes.model import db_exists +from webnotes.model.doc import Document, addchild, removechild, getchildren, make_autoname, SuperDocType +from webnotes.model.doclist import getlist, copy_doclist +from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax +from webnotes import session, form, is_testing, msgprint, errprint + +set = webnotes.conn.set +sql = webnotes.conn.sql +get_value = webnotes.conn.get_value +in_transaction = webnotes.conn.in_transaction +convert_to_lists = webnotes.conn.convert_to_lists + +# ----------------------------------------------------------------------------------------- + + +class DocType: + def __init__(self, doc, doclist): + self.doc = doc + self.doclist = doclist + + + def get_emp_list(self): + """ + Returns list of active employees based on selected criteria + and for which salary structure exists + """ + + cond = self.get_filter_condition() + + emp_list = sql(""" + select t1.name + from `tabEmployee` t1, `tabSalary Structure` t2 + where t1.docstatus!=2 and t2.docstatus != 2 + and ifnull(t1.status, 'Left') = 'Active' and ifnull(t2.is_active, 'No') = 'Yes' + and t1.name = t2.employee + %s """% cond) + + return emp_list + + + def get_filter_condition(self): + self.check_mandatory() + + cond = '' + for f in ['company', 'branch', 'department', 'designation', 'grade', 'employment_type']: + if self.doc.fields.get(f): + cond += " and t1." + f + " = '" + self.doc.fields.get(f) + "'" + + return cond + + + def check_mandatory(self): + for f in ['company', 'month', 'fiscal_year']: + if not self.doc.fields[f]: + msgprint("Please select %s to proceed" % f, raise_exception=1) + + + def create_sal_slip(self): + """ + Creates salary slip for selected employees if already not created + + """ + emp_list = self.get_emp_list() + 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 + """, (emp[0], self.doc.month, self.doc.fiscal_year, self.doc.company)): + ss = Document('Salary Slip') + ss.fiscal_year = self.doc.fiscal_year + ss.employee = emp[0] + ss.month = self.doc.month + ss.email_check = self.doc.send_email + ss.company = self.doc.company + ss.save(1) + + ss_obj = get_obj('Salary Slip', ss.name, with_children=1) + ss_obj.get_emp_and_leave_details() + ss_obj.calculate_net_pay() + ss_obj.validate() + ss_obj.doc.save() + + for d in getlist(ss_obj.doclist, 'earning_details'): + d.save() + for d in getlist(ss_obj.doclist, 'deduction_details'): + d.save() + + + def get_sal_slip_list(self): + """ + Returns list of salary slips based on selected criteria + which are not submitted + """ + cond = self.get_filter_condition() + ss_list = sql(""" + select t1.name from `tabSalary Slip` t1 + where t1.docstatus = 0 and month = '%s' and fiscal_year = '%s' %s + """ % (self.doc.month, self.doc.fiscal_year, cond)) + return ss_list + + + def submit_salary_slip(self): + """ + Submit all salary slips based on selected criteria + """ + ss_list = self.get_sal_slip_list() + 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() + + + def get_total_salary(self): + """ + Get total salary amount from submitted salary slip based on selected criteria + """ + cond = self.get_filter_condition() + tot = sql(""" + select sum(rounded_total) from `tabSalary Slip` t1 + where t1.docstatus = 0 and month = '%s' and fiscal_year = '%s' %s + """ % (self.doc.month, self.doc.fiscal_year, cond)) + + return flt(tot) + + + def get_acc_details(self): + """ + get default bank account,default salary acount from company + """ + 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.") + + ret = { + 'def_bank_acc' : com and com[0][0] or '', + 'def_sal_acc' : com and com[0][1] or '', + 'amount' : amt + } + return ret diff --git a/hr/doctype/salary_slip_control_panel/salary_slip_control_panel.txt b/hr/doctype/salary_manager/salary_manager.txt similarity index 56% rename from hr/doctype/salary_slip_control_panel/salary_slip_control_panel.txt rename to hr/doctype/salary_manager/salary_manager.txt index b83e0c771b..19f95d11da 100644 --- a/hr/doctype/salary_slip_control_panel/salary_slip_control_panel.txt +++ b/hr/doctype/salary_manager/salary_manager.txt @@ -1,42 +1,37 @@ -# DocType, Salary Slip Control Panel +# DocType, Salary Manager [ # These values are common in all dictionaries { - 'creation': '2010-08-08 17:09:20', + 'creation': '2011-08-11 16:40:04', 'docstatus': 0, - 'modified': '2010-12-29 18:02:38', - 'modified_by': 'umair@iwebnotes.com', + 'modified': '2011-08-12 14:08:33', + 'modified_by': 'Administrator', 'owner': 'Administrator' }, # These values are common for all DocType { - '_last_update': '1294312182', + '_last_update': '1313129645', 'allow_copy': 1, 'allow_email': 1, 'allow_print': 1, 'colour': 'White:FFF', 'doctype': 'DocType', - 'hide_heading': 0, - 'hide_toolbar': 0, - 'in_create': 0, + 'document_type': 'Other', 'issingle': 1, 'module': 'HR', 'name': '__common__', - 'read_only': 1, 'section_style': 'Simple', - 'server_code_error': ' ', - 'show_in_menu': 0, - 'use_template': 0, - 'version': 113 + 'show_in_menu': 1, + 'version': 15 }, # These values are common for all DocField { 'doctype': 'DocField', 'name': '__common__', - 'parent': 'Salary Slip Control Panel', + 'parent': 'Salary Manager', 'parentfield': 'fields', 'parenttype': 'DocType', 'permlevel': 0 @@ -47,7 +42,7 @@ 'create': 1, 'doctype': 'DocPerm', 'name': '__common__', - 'parent': 'Salary Slip Control Panel', + 'parent': 'Salary Manager', 'parentfield': 'permissions', 'parenttype': 'DocType', 'permlevel': 0, @@ -55,10 +50,10 @@ 'write': 1 }, - # DocType, Salary Slip Control Panel + # DocType, Salary Manager { 'doctype': 'DocType', - 'name': 'Salary Slip Control Panel' + 'name': 'Salary Manager' }, # DocPerm @@ -85,21 +80,57 @@ # DocField { 'doctype': 'DocField', - 'fieldtype': 'Section Break', + 'fieldtype': 'Column Break', 'idx': 1, - 'label': 'Salary Slip Control Panel' + 'width': '50%' }, # DocField { 'doctype': 'DocField', - 'fieldname': 'employee_type', + 'fieldname': 'company', 'fieldtype': 'Select', 'idx': 2, - 'label': 'Employment Type', - 'oldfieldname': 'employee_type', - 'oldfieldtype': 'Select', - 'options': 'link:Employment Type' + 'label': 'Company', + 'options': 'link:Company' + }, + + # DocField + { + 'doctype': 'DocField', + 'fieldname': 'branch', + 'fieldtype': 'Link', + 'idx': 3, + 'label': 'Branch', + 'options': 'Branch' + }, + + # DocField + { + 'doctype': 'DocField', + 'fieldname': 'department', + 'fieldtype': 'Link', + 'idx': 4, + 'label': 'Department', + 'options': 'Department' + }, + + # DocField + { + 'doctype': 'DocField', + 'fieldname': 'designation', + 'fieldtype': 'Link', + 'idx': 5, + 'label': 'Designation', + 'options': 'Designation' + }, + + # DocField + { + 'doctype': 'DocField', + 'fieldtype': 'Column Break', + 'idx': 6, + 'width': '50%' }, # DocField @@ -107,180 +138,117 @@ 'doctype': 'DocField', 'fieldname': 'grade', 'fieldtype': 'Select', - 'idx': 3, + 'idx': 7, 'label': 'Grade', - 'oldfieldname': 'grade', - 'oldfieldtype': 'Select', 'options': 'link:Grade' }, # DocField { 'doctype': 'DocField', - 'fieldname': 'branch', + 'fieldname': 'employment_type', 'fieldtype': 'Select', - 'idx': 4, - 'label': 'Branch', - 'oldfieldname': 'branch', - 'oldfieldtype': 'Select', - 'options': 'link:Branch' - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'department', - 'fieldtype': 'Select', - 'idx': 5, - 'label': 'Department', - 'oldfieldname': 'department', - 'oldfieldtype': 'Select', - 'options': 'link:Department' - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'designation', - 'fieldtype': 'Select', - 'idx': 6, - 'label': 'Designation', - 'oldfieldname': 'designation', - 'oldfieldtype': 'Select', - 'options': 'link:Designation' + 'idx': 8, + 'label': 'Employment Type', + 'options': 'link:Employment Type' }, # DocField { 'colour': 'White:FFF', - 'doctype': 'DocField', - 'fieldtype': 'Column Break', - 'idx': 7, - 'oldfieldtype': 'Column Break' - }, - - # DocField - { 'doctype': 'DocField', 'fieldname': 'fiscal_year', 'fieldtype': 'Select', - 'idx': 8, - 'in_filter': 1, - 'label': 'Fiscal Year', - 'oldfieldname': 'fiscal_year', - 'oldfieldtype': 'Select', - 'options': 'link:Fiscal Year' - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'month', - 'fieldtype': 'Select', 'idx': 9, - 'label': 'Month', - 'oldfieldname': 'month', - 'oldfieldtype': 'Select', - 'options': '\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12' - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'year', - 'fieldtype': 'Select', - 'idx': 10, - 'label': 'Year', - 'oldfieldname': 'year', - 'oldfieldtype': 'Select', - 'options': '\n2009\n2010\n2011\n2012' - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'week_off', - 'fieldtype': 'Currency', - 'idx': 11, - 'label': 'Week Off', - 'oldfieldname': 'week_off', - 'oldfieldtype': 'Currency' - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'arrear_amount', - 'fieldtype': 'Currency', - 'idx': 12, - 'label': 'Arrear Amount', - 'oldfieldname': 'arrear_amount', - 'oldfieldtype': 'Currency' + 'label': 'Fiscal Year', + 'options': 'link:Fiscal Year', + 'reqd': 1 }, # DocField { 'colour': 'White:FFF', 'doctype': 'DocField', - 'fieldname': 'email_check', + 'fieldname': 'month', + 'fieldtype': 'Select', + 'idx': 10, + 'label': 'Month', + 'options': '\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12', + 'reqd': 1 + }, + + # DocField + { + 'colour': 'White:FFF', + 'description': 'Check if you want to send salary slip in mail to each employee while submitting salary slip', + 'doctype': 'DocField', + 'fieldname': 'send_email', 'fieldtype': 'Check', - 'idx': 13, - 'label': 'Email', - 'oldfieldname': 'email_check', - 'oldfieldtype': 'Check' + 'idx': 11, + 'label': 'Send Email' }, # DocField { 'doctype': 'DocField', 'fieldtype': 'Section Break', - 'idx': 14, - 'oldfieldtype': 'Section Break' - }, - - # DocField - { - 'colour': 'White:FFF', - 'doctype': 'DocField', - 'fieldtype': 'Button', - 'idx': 15, - 'label': 'Process Payroll', - 'oldfieldtype': 'Button', - 'trigger': 'Client' - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldtype': 'HTML', - 'idx': 16, - 'label': 'Salary Slip HTML' + 'idx': 12 }, # DocField { 'doctype': 'DocField', 'fieldtype': 'Column Break', - 'idx': 17 + 'idx': 13, + 'width': '50%' }, # DocField { 'colour': 'White:FFF', + 'description': 'Creates salary slip for above mentioned criteria.', 'doctype': 'DocField', 'fieldtype': 'Button', - 'idx': 18, - 'label': 'Submit Salary Slip', - 'oldfieldtype': 'Button', - 'trigger': 'Client' + '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': 19, + 'idx': 16, + 'label': 'Submit Salary Slip', + 'options': 'submit_salary_slip' + }, + + # DocField + { + 'doctype': 'DocField', + 'fieldtype': 'Column Break', + 'idx': 17, + 'width': '25%' + }, + + # DocField + { + 'colour': 'White:FFF', + 'description': 'Create Bank Voucher for the total salary paid in the particular month and year', + 'doctype': 'DocField', + 'fieldtype': 'Button', + 'idx': 18, 'label': 'Make Bank Voucher', - 'trigger': 'Client' + 'options': 'make_bank_voucher' } ] \ No newline at end of file diff --git a/hr/doctype/salary_manager/test_salary_manager.py b/hr/doctype/salary_manager/test_salary_manager.py new file mode 100644 index 0000000000..1a0b48a18e --- /dev/null +++ b/hr/doctype/salary_manager/test_salary_manager.py @@ -0,0 +1,197 @@ +import unittest +import webnotes + +from webnotes.model.doc import Document +from webnotes.model.code import get_obj +sql = webnotes.conn.sql + +class TestSalarySlip(unittest.TestCase): + def setUp(self): + webnotes.conn.begin() + for rec in [des1, dep1, branch1, grade1, comp1, emp1, emp2]: + rec.save(1) + + ss1[0].employee = emp1.name + for s in ss1: s.save(1) + for s in ss1[1:]: + sql("update `tabEarning Detail` set parent = '%s' where name = '%s'" % (ss1[0].name, s.name)) + sql("update `tabDeduction Detail` set parent = '%s' where name = '%s'" % (ss1[0].name, s.name)) + + + ss2[0].employee = emp2.name + for s in ss2: s.save(1) + for s in ss2[1:]: + sql("update `tabEarning Detail` set parent = '%s' where name = '%s'" % (ss2[0].name, s.name)) + sql("update `tabDeduction Detail` set parent = '%s' where name = '%s'" % (ss2[0].name, s.name)) + + sman.save() + self.sm = get_obj('Salary Manager') + leave.save(1) + self.sm.create_sal_slip() + + def test_creation(self): + ssid = sql(""" + select name, department + from `tabSalary Slip` + where month = '08' and fiscal_year='2011-2012'""") + + self.assertTrue(len(ssid)==1) + self.assertTrue(ssid[0][1] == 'dep1') + + + def test_lwp_calc(self): + ss = sql(""" + select payment_days + from `tabSalary Slip` + where month = '08' and fiscal_year='2011-2012' and employee = '%s' + """ % emp1.name) + + self.assertTrue(ss[0][0]==27) + + def test_net_pay(self): + ss = webnotes.conn.sql(""" + select rounded_total + from `tabSalary Slip` + where month = '08' + and fiscal_year='2011-2012' and employee = '%s'""" % emp1.name) + self.assertTrue(ss[0][0]==67) + + def test_submit(self): + self.sm.submit_sal_slip() + ss = webnotes.conn.sql(""" + select docstatus + from `tabSalary Slip` + where month = '08' + and fiscal_year='2011-2012' and employee = '%s'""" % emp1.name) + self.assertTrue(ss[0][0]==1) + + def tearDown(self): + webnotes.conn.rollback() + +#-------------------------------------------- +# test data +#-------------------------------------------- +des1 = Document(fielddata={ + 'name':'des1', + 'doctype':'Designation', + 'designation_name':'des1' +}) + +dep1 = Document(fielddata={ + 'name':'dep1', + 'doctype':'Department', + 'department_name' : 'dep1' +}) + +branch1 = Document(fielddata={ + 'name':'branch1', + 'doctype':'Branch', + 'branch' : 'branch1' +}) + +comp1 = Document(fielddata={ + 'name':'comp1', + 'doctype':'Company', + 'abbr':'c1', + 'company_name' : 'comp1' +}) + +grade1 = Document(fielddata={ + 'name':'grade1', + 'doctype':'Grade', + 'grade_name' : 'grade1' +}) + +emp1 = Document(fielddata={ + 'doctype':'Employee', + 'employee_number':'emp1', + 'department':'dep1', + 'designation':'des1', + 'branch' : 'branch1', + 'company':'comp1', + 'grade':'grade1', + 'naming_series':'EMP/', + 'status':'Active', + 'docstatus':0 +}) + +emp2 = Document(fielddata={ + 'doctype':'Employee', + 'employee_number':'emp2', + 'department':'dep1', + 'designation':'des2', + 'branch' : 'branch1', + 'company':'comp1', + 'naming_series':'EMP/', + 'grade':'grade1', + 'status':'Active', + +}) + +ss1 = [ + Document(fielddata={ + 'doctype':'Salary Structure', + 'docstatus':0, + 'employee':'emp1', + 'is_active':'Yes', + 'department': 'dep1', + 'designation' : 'des1' + }), + Document(fielddata={ + 'parenttype':'Salary Structure', + 'parentfield':'earning_details', + 'doctype':'Earning Detail', + 'e_type' : 'Basic', + 'depend_on_lwp':1, + 'modified_value':100 + }), + Document(fielddata={ + 'parenttype':'Salary Structure', + 'parentfield':'earning_details', + 'doctype':'Deduction Detail', + 'd_type':'TDS', + 'd_modified_amt':20 + }) +] + +ss2 = [ + Document(fielddata={ + 'doctype':'Salary Structure', + 'is_active':'Yes', + 'docstatus':0, + }), + Document(fielddata={ + 'parenttype':'Salary Structure', + 'parentfield':'deduction_details', + 'doctype':'Earning Detail', + 'e_type' : 'Basic', + 'modified_value':100 + }), + Document(fielddata={ + 'parenttype':'Salary Structure', + 'parentfield':'deduction_details', + 'doctype':'Deduction Detail', + 'd_type':'TDS', + 'd_modified_amt':20 + }) +] + +sman = Document(fielddata={ + 'name':'Salary Manager', + 'doctype':'Salary Manager', + 'company': 'comp1', + 'department':'dep1', + 'designation':'des1', + 'month': '08', + 'fiscal_year':'2011-2012' + }) + +leave = Document(fielddata = { + 'doctype':'Leave Application', + 'employee':'emp1', + 'from_date':'2011-08-12', + 'to_date':'2011-08-15', + 'total_leave_days':'4', + 'leave_type':'Leave Without Pay', + 'docstatus':1 + }) diff --git a/hr/doctype/salary_slip_control_panel/__init__.py b/hr/doctype/salary_slip_control_panel/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/hr/doctype/salary_slip_control_panel/salary_slip_control_panel.js b/hr/doctype/salary_slip_control_panel/salary_slip_control_panel.js deleted file mode 100644 index 5fd80cbd95..0000000000 --- a/hr/doctype/salary_slip_control_panel/salary_slip_control_panel.js +++ /dev/null @@ -1,71 +0,0 @@ -cur_frm.cscript.onload = function(doc, cdt, cdn) { - alert("Salary Slip Control Panel is currently under re-development. It will take around a week time."); - hide_field(['Process Payroll', 'Submit Salary Slip', 'Make Bank Voucher']); -} - -cur_frm.cscript['Process Payroll'] = function(doc,cdt,cdn){ - $c('runserverobj', args={'method':'process_payroll','docs':compress_doclist (make_doclist (doc.doctype,doc.name))},function(r,rt){ - - if(!pscript.ss_html) - pscript.ss_html = $a(cur_frm.fields_dict['Salary Slip HTML'].wrapper,'span','',{border:'1px solid #CCC', backgroundColor:'#DDD'}); - pscript.ss_html.innerHTML = ''; - pscript.ss_html.innerHTML = r.message; - - - }); - -} - -cur_frm.cscript['Submit Salary Slip'] = function(doc,cdt,cdn){ - if(doc.month && doc.fiscal_year && doc.year){ - var check = confirm("DO you really want to Submit all Salary Slip for month : " + doc.month+" and year : "+doc.year); - if(check){ - $c('runserverobj', args={'method':'submit_sal_slip','docs':compress_doclist (make_doclist (doc.doctype,doc.name))},function(r,rt){ - - if(!pscript.ss_html) - pscript.ss_html = $a(cur_frm.fields_dict['Salary Slip HTML'].wrapper,'span','',{border:'1px solid #CCC', backgroundColor:'#DDD'}); - pscript.ss_html.innerHTML = ''; - pscript.ss_html.innerHTML = r.message; - - - }); - } - } - else - alert("Please select month, fiscal year and year"); -} - -// Make JV -// -------- -cur_frm.cscript.make_jv = function(doc, dt, dn) { - var call_back = function(r,rt){ - var jv = LocalDB.create('Journal Voucher'); - jv = locals['Journal Voucher'][jv]; - jv.voucher_type = 'Bank Voucher'; - jv.remark = 'Salary - Bank Voucher'; - jv.fiscal_year = doc.fiscal_year; - jv.company = doc.company; - - // credit to bank - var d1 = LocalDB.add_child(jv, 'Journal Voucher Detail', 'entries'); - d1.account = r.message['default_bank_account']; - - // debit to salary account - var d1 = LocalDB.add_child(jv, 'Journal Voucher Detail', 'entries'); - d1.account = r.message['default_salary_account']; - if(!r.message['default_salary_account'] && !r.message['default_bank_account']) alert("To debit salary amount in salary head and credit amount from bank, you need to specify default salary account and default bank account in Global Defaults.\nGo to Setup, click on Company. Select a company.\nSelect Default Salary Account, Default Bank Account from Accounting tab."); - else if(!r.message['default_salary_account']) alert("To debit salary amount you need to specify default salary account in Global Defaults.\nGo to Setup, click on Company. Select a company.\nSelect Default Salary Account from Accounting tab."); - else if(!r.message['default_bank_account']) alert("To credit salary amount you need to specify default bank account in Global Defaults.\nGo to Setup, click on Company. Select a company.\nSelect Default Bank Account from Accounting tab."); - loaddoc('Journal Voucher', jv.name); - } - $c_obj(make_doclist(dt,dn),'get_acct_dtl','',call_back); - -} - - - -// Make Journal Voucher -// -------------------- -cur_frm.cscript['Make Bank Voucher'] = function(doc, dt, dn) { - cur_frm.cscript.make_jv(doc,dt,dn); -} diff --git a/hr/doctype/salary_slip_control_panel/salary_slip_control_panel.py b/hr/doctype/salary_slip_control_panel/salary_slip_control_panel.py deleted file mode 100644 index 3a4fadf4cf..0000000000 --- a/hr/doctype/salary_slip_control_panel/salary_slip_control_panel.py +++ /dev/null @@ -1,137 +0,0 @@ -# Please edit this list and import only required elements -import webnotes - -from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, generate_hash, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add -from webnotes.model import db_exists -from webnotes.model.doc import Document, addchild, removechild, getchildren, make_autoname, SuperDocType -from webnotes.model.doclist import getlist, copy_doclist -from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax -from webnotes import session, form, is_testing, msgprint, errprint - -set = webnotes.conn.set -sql = webnotes.conn.sql -get_value = webnotes.conn.get_value -in_transaction = webnotes.conn.in_transaction -convert_to_lists = webnotes.conn.convert_to_lists - -# ----------------------------------------------------------------------------------------- - - -class DocType: - def __init__(self, doc, doclist): - self.doc = doc - self.doclist = doclist - - # Get Employees - # ********************************************************************** - def get_employee(self): - e1 = self.emp_fr_memp() #get employee list from employee where employee is active - e2 = self.emp_fr_salstr(e1) #get employee list from salary structure whose salary structure is created and is active - e3 = self.emp_fr_salslip(e2) #get employee list from salary slip whose salary slip not yet created for this month and year - return e3 - - # ********************************************************************** - def emp_fr_memp(self): - lst1 = [[self.doc.employee_type,"employment_type"],[self.doc.branch,"branch"],[self.doc.designation,"designation"],[self.doc.department, "department"],[self.doc.grade,"grade"]] - - condition = "" - #flag = 0 - for l in lst1: - - if(l[0]): - #if flag == 0: - # condition += l[1] + "= '" + l[0] +"'" - #else: - condition += " and " + l[1]+ "= '" +l[0] +"'" - #flag = 1 - - emp_query = "select name from `tabEmployee` where status = 'Active'" - #if flag == 1: - emp_query += condition - - e = sql(emp_query) - return e - - # ********************************************************************** - def emp_fr_salstr(self,e1): - lst = [] - for r in e1: - lst.append(r[0]) - - - e_lst = "%s"%lst - e_lst=e_lst.replace("[","(") - e_lst=e_lst.replace("]",")") - cond = '' - - if e1: - cond = " and employee in %s"%e_lst - - el=sql("select employee from `tabSalary Structure` where is_active = 'Yes'"+cond) - - return el - - # ********************************************************************** - def emp_fr_salslip(self,e2): - e3 = [] - for i in e2: - ret = sql("select name from `tabSalary Slip` where month = '%s' and year = '%s' and employee = '%s' and docstatus !=2 "%(self.doc.month,self.doc.year,i[0])) - - if not ret: - e3.append(i[0]) - return e3 - - # ********************************************************************** - def process_payroll(self): - sal_slip_str = '' - if self.doc.month and self.doc.fiscal_year and self.doc.year: - e = self.get_employee() - if e: - self.doc.emp_lst=e - sal_slip_str += 'Sucessfully created following salary slips:' - for i in e: - ss = Document('Salary Slip') - ss.fiscal_year = self.doc.fiscal_year - ss.employee = i - ss.month = self.doc.month - ss.year= self.doc.year - ss.arrear_amount = self.doc.arrear_amount - ss.email_check = self.doc.email_check - ss.save(1) - salary_obj=get_obj("Salary Slip",ss.name,with_children=1) - salary_obj.process_payroll_all() - sal_slip_str += "
"+ss.name - - else: - - msgprint("For Process Payroll Fiscal Year, Month, Year fields are mandatory.") - if not sal_slip_str: - - sal_slip_str = "No record found." - return cstr(sal_slip_str) - - # ********************************************************************** - def submit_sal_slip(self): - - sal_slip_str = '' - r = sql("select name from `tabSalary Slip` where month='%s' and year = '%s' and fiscal_year = '%s' and docstatus = 0"%(self.doc.month,self.doc.year,self.doc.fiscal_year)) - - - ret = sql("update `tabSalary Slip` set docstatus = 1 where month='%s' and year = '%s' and fiscal_year = '%s' and docstatus = 0"%(self.doc.month,self.doc.year,self.doc.fiscal_year)) - if r: - sal_slip_str += 'Sucessfully updated following salary slips:' - for i in r: - - salary_obj=get_obj("Salary Slip",i[0],with_children=1) - salary_obj.on_submit() - sal_slip_str += "
"+cstr(i[0]) - if not sal_slip_str: - - sal_slip_str = "No record found." - return cstr(sal_slip_str) - - # ********************************************************************** - #get default bank account,default salary acount from company. - def get_acct_dtl(self): - res = sql("select default_bank_account,default_salary_acount from `tabCompany` where name = '%s'"%get_defaults()['company'], as_dict=1) - return res[0]