Added from date and to date to student leave application
diff --git a/erpnext/schools/doctype/student_leave_application/student_leave_application.json b/erpnext/schools/doctype/student_leave_application/student_leave_application.json
index 2a8dfb2..ad6d498 100644
--- a/erpnext/schools/doctype/student_leave_application/student_leave_application.json
+++ b/erpnext/schools/doctype/student_leave_application/student_leave_application.json
@@ -103,7 +103,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "date", 
+   "fieldname": "from_date", 
    "fieldtype": "Date", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
@@ -111,7 +111,7 @@
    "in_filter": 0, 
    "in_list_view": 1, 
    "in_standard_filter": 1, 
-   "label": "Date", 
+   "label": "From Date", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -131,6 +131,35 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "to_date", 
+   "fieldtype": "Date", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "in_standard_filter": 0, 
+   "label": "To Date", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "description": "Will show the student as Present in Student Monthly Attendance Report", 
    "fieldname": "mark_as_present", 
    "fieldtype": "Check", 
    "hidden": 0, 
@@ -248,7 +277,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-12-20 15:08:40.750278", 
+ "modified": "2016-12-21 18:58:00.256114", 
  "modified_by": "Administrator", 
  "module": "Schools", 
  "name": "Student Leave Application", 
diff --git a/erpnext/schools/report/absent_student_report/absent_student_report.py b/erpnext/schools/report/absent_student_report/absent_student_report.py
index 82a20aa..32026c9 100644
--- a/erpnext/schools/report/absent_student_report/absent_student_report.py
+++ b/erpnext/schools/report/absent_student_report/absent_student_report.py
@@ -55,6 +55,6 @@
 def get_leave_applications(date):
 	leave_applicants = []
 	for student in frappe.db.sql("""select student from `tabStudent Leave Application` 
-		where docstatus = 1 and date = %s""", date):
+	where docstatus = 1 and from_date <= %s and to_date >= %s""", (date, date)):
 		leave_applicants.append(student[0])
 	return leave_applicants
\ No newline at end of file
diff --git a/erpnext/schools/report/student_monthly_attendance_sheet/student_monthly_attendance_sheet.js b/erpnext/schools/report/student_monthly_attendance_sheet/student_monthly_attendance_sheet.js
index 32c0551..8d914cb 100644
--- a/erpnext/schools/report/student_monthly_attendance_sheet/student_monthly_attendance_sheet.js
+++ b/erpnext/schools/report/student_monthly_attendance_sheet/student_monthly_attendance_sheet.js
@@ -3,40 +3,40 @@
 
 
 frappe.query_reports["Student Monthly Attendance Sheet"] = {
-	"filters": [
-		{
-			"fieldname":"month",
-			"label": __("Month"),
-			"fieldtype": "Select",
-			"options": "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug\nSep\nOct\nNov\nDec",
-			"default": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov",
-				"Dec"][frappe.datetime.str_to_obj(frappe.datetime.get_today()).getMonth()],
-		},
-		{
-			"fieldname":"year",
-			"label": __("Year"),
-			"fieldtype": "Select",
-			"reqd": 1
-		},
-		{
-			"fieldname":"student_batch",
-			"label": __("Student Batch"),
-			"fieldtype": "Link",
-			"options": "Student Batch",
-			"reqd": 1
-		}
-	],
+    "filters": [{
+            "fieldname": "month",
+            "label": __("Month"),
+            "fieldtype": "Select",
+            "options": "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug\nSep\nOct\nNov\nDec",
+            "default": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov",
+                "Dec"
+            ][frappe.datetime.str_to_obj(frappe.datetime.get_today()).getMonth()],
+        },
+        {
+            "fieldname": "year",
+            "label": __("Year"),
+            "fieldtype": "Select",
+            "reqd": 1
+        },
+        {
+            "fieldname": "student_batch",
+            "label": __("Student Batch"),
+            "fieldtype": "Link",
+            "options": "Student Batch",
+            "reqd": 1
+        }
+    ],
 
-	"onload": function() {
-		return  frappe.call({
-			method: "erpnext.schools.report.student_monthly_attendance_sheet.student_monthly_attendance_sheet.get_attendance_years",
-			callback: function(r) {
-				var year_filter = frappe.query_report_filters_by_name.year;
-				year_filter.df.options = r.message;
-				year_filter.df.default = r.message.split("\n")[0];
-				year_filter.refresh();
-				year_filter.set_input(year_filter.df.default);
-			}
-		});
-	}
-}
+    "onload": function() {
+        return frappe.call({
+            method: "erpnext.schools.report.student_monthly_attendance_sheet.student_monthly_attendance_sheet.get_attendance_years",
+            callback: function(r) {
+                var year_filter = frappe.query_report_filters_by_name.year;
+                year_filter.df.options = r.message;
+                year_filter.df.default = r.message.split("\n")[0];
+                year_filter.refresh();
+                year_filter.set_input(year_filter.df.default);
+            }
+        });
+    }
+}
\ No newline at end of file
diff --git a/erpnext/schools/report/student_monthly_attendance_sheet/student_monthly_attendance_sheet.py b/erpnext/schools/report/student_monthly_attendance_sheet/student_monthly_attendance_sheet.py
index 025e078..1599a89 100644
--- a/erpnext/schools/report/student_monthly_attendance_sheet/student_monthly_attendance_sheet.py
+++ b/erpnext/schools/report/student_monthly_attendance_sheet/student_monthly_attendance_sheet.py
@@ -3,7 +3,7 @@
 
 from __future__ import unicode_literals
 import frappe
-from frappe.utils import cstr, cint, getdate
+from frappe.utils import cstr, cint, getdate, get_first_day, get_last_day, date_diff, add_days
 from frappe import msgprint, _
 from calendar import monthrange
 from erpnext.schools.api import get_student_batch_students
@@ -11,86 +11,69 @@
 def execute(filters=None):
 	if not filters: filters = {}
 
-	conditions, filters = get_conditions(filters)
-	columns = get_columns(filters)
-	att_map = get_attendance_list(conditions, filters)
+	from_date = get_first_day(filters["month"] + '-' + filters["year"])
+	to_date = get_last_day(filters["month"] + '-' + filters["year"])
+	total_days_in_month = date_diff(to_date, from_date) +1
+	columns = get_columns(total_days_in_month)
+	att_map = get_attendance_list(from_date, to_date, filters.get("student_batch"))
 	students = get_student_batch_students(filters.get("student_batch"))
 	data = []
 	for stud in students:
 		row = [stud.student, stud.student_name]
-
+		date = from_date
 		total_p = total_a = 0.0
-		for day in range(filters["total_days_in_month"]):
+		for day in range(total_days_in_month):
 			status="None"
 			if att_map.get(stud.student):
-				status = att_map.get(stud.student).get(day + 1, "None")
+				status = att_map.get(stud.student).get(date, "None")
 			status_map = {"Present": "P", "Absent": "A", "None": ""}
 			row.append(status_map[status])
-
 			if status == "Present":
 				total_p += 1
 			elif status == "Absent":
 				total_a += 1
-
+			date = add_days(date, 1)
 		row += [total_p, total_a]
 		data.append(row)
-
 	return columns, data
 
-def get_columns(filters):
+def get_columns(days_in_month):
 	columns = [ _("Student") + ":Link/Student:90", _("Student Name") + "::150"]
-
-	for day in range(filters["total_days_in_month"]):
+	for day in range(days_in_month):
 		columns.append(cstr(day+1) +"::20")
-
 	columns += [_("Total Present") + ":Int:95", _("Total Absent") + ":Int:90"]
 	return columns
 
-def get_attendance_list(conditions, filters):
-	attendance_list = frappe.db.sql("""select student, day(date) as day_of_month,
-		status from `tabStudent Attendance` where docstatus = 1 %s order by student, date""" %
-		conditions, filters, as_dict=1)
-
-	students_with_leave_application = get_students_with_leave_application(filters)
-
+def get_attendance_list(from_date, to_date, student_batch):
+	attendance_list = frappe.db.sql("""select student, date, status 
+		from `tabStudent Attendance` where docstatus = 1 and student_batch = %s 
+		and date between %s and %s
+		order by student, date""",
+		(student_batch, from_date, to_date), as_dict=1)
 	att_map = {}
 	for d in attendance_list:
-		att_map.setdefault(d.student, frappe._dict()).setdefault(d.day_of_month, "")
-		for stud in students_with_leave_application:
-			if stud.student== d.student and stud.day_of_month== d.day_of_month:
-				att_map[d.student][d.day_of_month] = "Present"
-				break
-			else:		
-				att_map[d.student][d.day_of_month] = d.status
-
+		att_map.setdefault(d.student, frappe._dict()).setdefault(d.date, "")
+		students_with_leave_application = get_students_with_leave_application(d.date)
+		if students_with_leave_application:
+			for stud in students_with_leave_application:
+				if stud.student== d.student:
+					att_map[d.student][d.date] = "Present"
+					break
+				else:		
+					att_map[d.student][d.date] = d.status
+		else:
+			att_map[d.student][d.date] = d.status
 	return att_map
 
-def get_students_with_leave_application(filters):
-	students_with_leave_application = frappe.db.sql("""select student, day(date) as day_of_month
-		from `tabStudent Leave Application` where mark_as_present and docstatus = 1 
-		and month(date) = %(month)s and year(date) = %(year)s
-		order by student, date""", filters, as_dict=1)
-	return students_with_leave_application 
-
-def get_conditions(filters):
-	if not (filters.get("month") and filters.get("year")):
-		msgprint(_("Please select month and year"), raise_exception=1)
-	
-	filters["month"] = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov",
-		"Dec"].index(filters.month) + 1
-
-	filters["total_days_in_month"] = monthrange(cint(filters.year), filters.month)[1]
-	
-	conditions = " and month(date) = %(month)s and year(date) = %(year)s"
-
-	if filters.get("student_batch"): conditions += " and student_batch = %(student_batch)s"
-	
-	return conditions, filters
+def get_students_with_leave_application(date):
+	students_with_leave_application = frappe.db.sql("""select student from 
+		`tabStudent Leave Application` where mark_as_present and docstatus = 1 and 
+		%s between from_date and to_date""", date, as_dict=1)	
+	return students_with_leave_application
 
 @frappe.whitelist()
 def get_attendance_years():
 	year_list = frappe.db.sql_list("""select distinct YEAR(date) from `tabStudent Attendance` ORDER BY YEAR(date) DESC""")
 	if not year_list:
 		year_list = [getdate().year]
-
 	return "\n".join(str(year) for year in year_list)