new employee_leave_balance_report

This commit is contained in:
Rushabh Mehta
2013-02-22 17:54:50 +05:30
parent ff20067a6f
commit 90098d2ebd
23 changed files with 166 additions and 231 deletions

View File

@@ -165,7 +165,6 @@ class DocType(DocListController):
# for post in messages
"message": _get_message(url=True),
"message_to": employee.user_id,
"subject": _get_message(),
})
@@ -208,7 +207,7 @@ def get_leave_balance(employee, leave_type, fiscal_year):
leave_app = webnotes.conn.sql("""select SUM(total_leave_days)
from `tabLeave Application`
where employee = %s and leave_type = %s and fiscal_year = %s
and docstatus = 1""", (employee, leave_type, fiscal_year))
and status="Approved" and docstatus = 1""", (employee, leave_type, fiscal_year))
leave_app = leave_app and flt(leave_app[0][0]) or 0
ret = {'leave_balance': leave_all - leave_app}
@@ -234,7 +233,7 @@ def get_events(start, end):
company = webnotes.conn.get_default("company", webnotes.session.user)
from webnotes.widgets.reportview import build_match_conditions
match_conditions = build_match_conditions({"doctype": "Leave Application"})
match_conditions = build_match_conditions("Leave Application")
# show department leaves for employee
show_department_leaves = match_conditions and \

View File

@@ -159,6 +159,17 @@ wn.module_page["HR"] = [
doctype: "Grade"
},
]
},
{
title: wn._("Reports"),
right: true,
icon: "icon-list",
items: [
{
"label":wn._("Employee Leave Balance"),
route: "query-report/Employee Leave Balance"
},
]
}
];

0
hr/report/__init__.py Normal file
View File

View File

@@ -0,0 +1,46 @@
from __future__ import unicode_literals
import webnotes
from webnotes.widgets.reportview import execute as runreport
def execute():
employees = runreport(doctype="Employee", fields=["name", "employee_name", "department"])
leave_types = webnotes.conn.sql_list("select name from `tabLeave Type`")
fiscal_years = webnotes.conn.sql_list("select name from `tabFiscal Year` order by name desc")
employee_in = '", "'.join([e.name for e in employees])
allocations = webnotes.conn.sql("""select employee, fiscal_year, leave_type, total_leaves_allocated
from `tabLeave Allocation`
where docstatus=1 and employee in ("%s")""" % employee_in, as_dict=True)
applications = webnotes.conn.sql("""select employee, fiscal_year, leave_type, SUM(total_leave_days) as leaves
from `tabLeave Application`
where status="Approved" and docstatus = 1 and employee in ("%s")
group by employee, fiscal_year, leave_type""" % employee_in, as_dict=True)
columns = [
"Fiscal Year", "Employee:Link/Employee:150", "Employee Name::200", "Department::150"
]
for leave_type in leave_types:
columns.append(leave_type + " Allocated:Float")
columns.append(leave_type + " Taken:Float")
data = {}
for d in allocations:
data.setdefault((d.fiscal_year, d.employee,
d.leave_type), webnotes._dict()).allocation = d.total_leaves_allocated
for d in applications:
data.setdefault((d.fiscal_year, d.employee,
d.leave_type), webnotes._dict()).leaves = d.leaves
result = []
for fiscal_year in fiscal_years:
for employee in employees:
row = [fiscal_year, employee.name, employee.employee_name, employee.department]
result.append(row)
for leave_type in leave_types:
tmp = data.get((fiscal_year, employee.name, leave_type), webnotes._dict())
row.append(tmp.allocation or 0)
row.append(tmp.leaves or 0)
return columns, result

View File

@@ -0,0 +1,21 @@
[
{
"creation": "2013-02-22 15:29:34",
"docstatus": 0,
"modified": "2013-02-22 15:53:01",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "Report",
"is_standard": "Yes",
"name": "__common__",
"ref_doctype": "Employee",
"report_name": "Employee Leave Balance",
"report_type": "Script Report"
},
{
"doctype": "Report",
"name": "Employee Leave Balance"
}
]

View File

@@ -1 +0,0 @@
from __future__ import unicode_literals

View File

@@ -1,41 +0,0 @@
// ERPNext - web based ERP (http://erpnext.com)
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
this.mytabs.items['Select Columns'].hide();
this.mytabs.tabs['More Filters'].hide();
report.customize_filters = function() {
this.add_filter({
fieldname:'fiscal_year',
label:'Fiscal Year',
fieldtype:'Link',
ignore : 1,
options: 'Fiscal Year',
parent:'Leave Allocation',
in_first_page:1,
report_default: sys_defaults.fiscal_year
});
this.add_filter({
fieldname:'employee_name',
label:'Employee Name',
fieldtype:'Data',
ignore : 1,
options: '',
parent:'Leave Allocation',
in_first_page:1
});
}

View File

@@ -1,73 +0,0 @@
# ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
leave_types = sql("""
SELECT name FROM `tabLeave Type`
WHERE
docstatus!=2 AND
name NOT IN ('Compensatory Off', 'Leave Without Pay')""")
col=[]
col.append(['Employee ID', 'Data', '150px', ''])
col.append(['Employee Name', 'Data', '150px', ''])
col.append(['Fiscal Year', 'Data', '150px', ''])
for e in leave_types:
l = (len(e[0])*9)
if l < 150 : col_width = '150px'
else: col_width = '%spx'%(l)
col.append([e[0],'Currency',col_width,''])
col.append(['Total Balance','Currency','150px',''])
for c in col:
colnames.append(c[0])
coltypes.append(c[1])
colwidths.append(c[2])
coloptions.append(c[3])
col_idx[c[0]] = len(colnames)
data = res
res = []
try:
for d in data:
exists = 0
ind = None
# Check if the employee record exists in list 'res'
for r in res:
if r[0] == d[0] and r[1] == d[1]:
exists = 1
ind = res.index(r)
break
if d[3] in colnames:
# If exists, then append the leave type data
if exists:
res[ind][colnames.index(d[3])] = flt(d[4]) - flt(d[5])
res[ind][len(colnames)-1] = sum(res[ind][3:-1])
# Else create a new row in res
else:
new_row = [0.0 for c in colnames]
new_row[0] = d[0]
new_row[1] = d[1]
new_row[2] = d[2]
new_row[colnames.index(d[3])] = flt(d[4]) - flt(d[5])
new_row[len(colnames)-1] = sum(new_row[3:-1])
res.append(new_row)
except Exception, e:
msgprint(e)

View File

@@ -1,25 +0,0 @@
SELECT
leave_alloc.employee AS 'employee',
leave_alloc.employee_name AS 'employee_name',
leave_alloc.fiscal_year AS 'fiscal_year',
leave_alloc.leave_type AS 'leave_type',
leave_alloc.total_leaves_allocated AS 'total_leaves_allocated',
SUM(leave_app.total_leave_days) AS 'total_leaves_applied'
FROM
`tabLeave Allocation` AS leave_alloc LEFT JOIN `tabLeave Application` AS leave_app
ON leave_alloc.employee=leave_app.employee AND
leave_alloc.leave_type=leave_app.leave_type AND
leave_alloc.fiscal_year=leave_app.fiscal_year AND
leave_app.docstatus=1
WHERE
leave_alloc.docstatus=1 AND
leave_alloc.fiscal_year LIKE '%(fiscal_year)s%%' AND
leave_alloc.employee_name LIKE '%(employee_name)s%%'
GROUP BY
employee,
fiscal_year,
leave_type
ORDER BY
employee,
fiscal_year,
leave_type

View File

@@ -1,27 +0,0 @@
[
{
"owner": "harshada@webnotestech.com",
"docstatus": 0,
"creation": "2010-12-14 10:33:09",
"modified_by": "Administrator",
"modified": "2011-10-31 15:42:36"
},
{
"description": "Employeewise Balance Leave Report",
"module": "HR",
"standard": "Yes",
"sort_order": "ASC",
"filters": "{'Employee\u0001Saved':1,'Employee\u0001Submitted':1,'Employee\u0001Gender':'','Employee\u0001Month of Birth':'','Employee\u0001Status':'Active'}",
"doc_type": "Employee",
"name": "__common__",
"doctype": "Search Criteria",
"sort_by": "`tabEmployee`.`name`",
"page_len": 100,
"criteria_name": "Employee Leave Balance Report",
"columns": "Employee\u0001ID"
},
{
"name": "employeewise_balance_leave_report",
"doctype": "Search Criteria"
}
]