diff --git a/erpnext/config/schools.py b/erpnext/config/schools.py index 2299305a5e..80e327402d 100644 --- a/erpnext/config/schools.py +++ b/erpnext/config/schools.py @@ -76,6 +76,12 @@ def get_data(): "name": "Absent Student Report", "doctype": "Attendance" }, + { + "type": "report", + "is_query_report": True, + "name": "Student Batch Wise Attendance", + "doctype": "Attendance" + }, { "type": "report", "is_query_report": True, diff --git a/erpnext/schools/report/student_batch_wise_attendance/__init__.py b/erpnext/schools/report/student_batch_wise_attendance/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/schools/report/student_batch_wise_attendance/student_batch_wise_attendance.js b/erpnext/schools/report/student_batch_wise_attendance/student_batch_wise_attendance.js new file mode 100644 index 0000000000..51f7346b89 --- /dev/null +++ b/erpnext/schools/report/student_batch_wise_attendance/student_batch_wise_attendance.js @@ -0,0 +1,12 @@ +// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.query_reports["Student Batch-Wise Attendance"] = { + "filters": [{ + "fieldname": "date", + "label": __("Date"), + "fieldtype": "Date", + "default": get_today(), + "reqd": 1 + }] +} \ No newline at end of file diff --git a/erpnext/schools/report/student_batch_wise_attendance/student_batch_wise_attendance.json b/erpnext/schools/report/student_batch_wise_attendance/student_batch_wise_attendance.json new file mode 100644 index 0000000000..f9c9e55268 --- /dev/null +++ b/erpnext/schools/report/student_batch_wise_attendance/student_batch_wise_attendance.json @@ -0,0 +1,18 @@ +{ + "add_total_row": 0, + "apply_user_permissions": 1, + "creation": "2016-11-28 22:07:03.859124", + "disabled": 0, + "docstatus": 0, + "doctype": "Report", + "idx": 0, + "is_standard": "Yes", + "modified": "2016-12-01 10:48:23.380837", + "modified_by": "Administrator", + "module": "Schools", + "name": "Student Batch-Wise Attendance", + "owner": "Administrator", + "ref_doctype": "Student Attendance", + "report_name": "Student Batch-Wise Attendance", + "report_type": "Script Report" +} \ No newline at end of file diff --git a/erpnext/schools/report/student_batch_wise_attendance/student_batch_wise_attendance.py b/erpnext/schools/report/student_batch_wise_attendance/student_batch_wise_attendance.py new file mode 100644 index 0000000000..eaf090e2ad --- /dev/null +++ b/erpnext/schools/report/student_batch_wise_attendance/student_batch_wise_attendance.py @@ -0,0 +1,64 @@ +# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe +from frappe.utils import cstr, cint, getdate +from frappe import msgprint, _ + +def execute(filters=None): + if not filters: filters = {} + + if not filters.get("date"): + msgprint(_("Please select date"), raise_exception=1) + + columns = get_columns(filters) + + active_student_batch = get_active_student_batch() + + data = [] + for student_batch in active_student_batch: + row = [student_batch.name] + present_students = 0 + absent_students = 0 + student_batch_strength = get_student_batch_strength(student_batch.name) + student_attendance = get_student_attendance(student_batch.name, filters.get("date")) + if student_attendance: + for attendance in student_attendance: + if attendance.status== "Present": + present_students = attendance.count + elif attendance.status== "Absent": + absent_students = attendance.count + + unmarked_students = student_batch_strength - (present_students + absent_students) + row+= [student_batch_strength, present_students, absent_students, unmarked_students] + data.append(row) + + return columns, data + +def get_columns(filters): + columns = [ + _("Student batch") + ":Link/Student Batch:250", + _("Student batch Strength") + "::170", + _("Present") + "::90", + _("Absent") + "::90", + _("Not Marked") + "::90" + ] + return columns + +def get_active_student_batch(): + active_student_batch = frappe.db.sql("""select name from `tabStudent Batch` + where active = 1 order by name""", as_dict=1) + return active_student_batch + +def get_student_batch_strength(student_batch): + student_batch_strength = frappe.db.sql("""select count(*) from `tabStudent Batch Student` + where parent = %s""", student_batch)[0][0] + return student_batch_strength + +def get_student_attendance(student_batch, date): + student_attendance = frappe.db.sql("""select count(*) as count, status from `tabStudent Attendance` where \ + student_batch= %s and date= %s and docstatus=1 and\ + (course_schedule is Null or course_schedule='') group by status""", + (student_batch, date), as_dict=1) + return student_attendance \ No newline at end of file