blob: 3554fe76dd30cd5f01fcde62d1b4d8f286257f83 [file] [log] [blame]
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +05301# -*- coding: utf-8 -*-
2# Copyright (c) 2015, Frappe Technologies and contributors
3# For license information, please see license.txt
4
5from __future__ import unicode_literals
6import frappe
7import json
8from frappe import _
9from frappe.model.mapper import get_mapped_doc
10from frappe.utils import flt
11
12@frappe.whitelist()
13def enroll_student(source_name):
14 """Creates a Student Record and returns a Program Enrollment.
15
16 :param source_name: Student Applicant.
17 """
18 student = get_mapped_doc("Student Applicant", source_name,
19 {"Student Applicant": {
20 "doctype": "Student",
21 "field_map": {
22 "name": "student_applicant"
23 }
Neil Trini Lasrado06724592016-08-22 12:57:09 +053024 }}, ignore_permissions=True)
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +053025 student.save()
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +053026 program_enrollment = frappe.new_doc("Program Enrollment")
27 program_enrollment.student = student.name
28 program_enrollment.student_name = student.title
29 program_enrollment.program = frappe.db.get_value("Student Applicant", source_name, "program")
30 return program_enrollment
31
32@frappe.whitelist()
33def check_attendance_records_exist(course_schedule):
34 """Check if Attendance Records are made against the specified Course Schedule.
35
36 :param course_schedule: Course Schedule.
37 """
38 return frappe.get_list("Student Attendance", filters={"course_schedule": course_schedule})
39
40@frappe.whitelist()
41def mark_attendance(students_present, students_absent, course_schedule):
42 """Creates Multiple Attendance Records.
43
44 :param students_present: Students Present JSON.
45 :param students_absent: Students Absent JSON.
46 :param course_schedule: Course Schedule.
47 """
48 present = json.loads(students_present)
49 absent = json.loads(students_absent)
50
51 for d in present:
52 make_attendance_records(d["student"], d["student_name"], course_schedule, "Present")
53
54 for d in absent:
55 make_attendance_records(d["student"], d["student_name"], course_schedule, "Absent")
56
57 frappe.msgprint(_("Attendance has been marked successfully."))
58
59def make_attendance_records(student, student_name, course_schedule, status):
60 """Creates Attendance Record.
61
62 :param student: Student.
63 :param student_name: Student Name.
64 :param course_schedule: Course Schedule.
65 :param status: Status (Present/Absent)
66 """
67 student_attendance = frappe.new_doc("Student Attendance")
68 student_attendance.student = student
69 student_attendance.student_name = student_name
70 student_attendance.course_schedule = course_schedule
71 student_attendance.status = status
72 student_attendance.submit()
73 frappe.db.commit()
74
75@frappe.whitelist()
76def get_student_group_students(student_group):
77 """Returns List of student, student_name in Student Group.
78
79 :param student_group: Student Group.
80 """
81 students = frappe.get_list("Student Group Student", fields=["student", "student_name"] , filters={"parent": student_group}, order_by= "idx")
82 return students
83
84@frappe.whitelist()
85def get_fee_structure(program, academic_term=None):
86 """Returns Fee Structure.
87
88 :param program: Program.
89 :param academic_term: Academic Term.
90 """
91 fee_structure = frappe.db.get_values("Fee Structure", {"program": program,
92 "academic_term": academic_term}, 'name', as_dict=True)
93 return fee_structure[0].name if fee_structure else None
94
95@frappe.whitelist()
Neil Trini Lasradof02a0d42016-08-05 15:50:52 +053096def get_fee_components(fee_structure):
97 """Returns Fee Components.
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +053098
99 :param fee_structure: Fee Structure.
100 """
101 if fee_structure:
Neil Trini Lasradof02a0d42016-08-05 15:50:52 +0530102 fs = frappe.get_list("Fee Component", fields=["fees_category", "amount"] , filters={"parent": fee_structure}, order_by= "idx")
Neil Trini Lasrado3f0a5812016-07-19 14:17:33 +0530103 return fs
104
105@frappe.whitelist()
106def get_fee_schedule(program):
107 """Returns Fee Schedule.
108
109 :param program: Program.
110 """
111 fs = frappe.get_list("Program Fee", fields=["academic_term", "fee_structure", "due_date", "amount"] ,
112 filters={"parent": program}, order_by= "idx")
113 return fs
114
115@frappe.whitelist()
116def collect_fees(fees, amt):
117 paid_amount = flt(amt) + flt(frappe.db.get_value("Fees", fees, "paid_amount"))
118 total_amount = flt(frappe.db.get_value("Fees", fees, "total_amount"))
119 frappe.db.set_value("Fees", fees, "paid_amount", paid_amount)
120 frappe.db.set_value("Fees", fees, "outstanding_amount", (total_amount - paid_amount))
121 return paid_amount
122
123@frappe.whitelist()
124def get_course_schedule_events(start, end, filters=None):
125 """Returns events for Course Schedule Calendar view rendering.
126
127 :param start: Start date-time.
128 :param end: End date-time.
129 :param filters: Filters (JSON).
130 """
131 from frappe.desk.calendar import get_event_conditions
132 conditions = get_event_conditions("Course Schedule", filters)
133
134 data = frappe.db.sql("""select name, course,
135 timestamp(schedule_date, from_time) as from_datetime,
136 timestamp(schedule_date, to_time) as to_datetime,
137 room, student_group, 0 as 'allDay'
138 from `tabCourse Schedule`
139 where ( schedule_date between %(start)s and %(end)s )
140 {conditions}""".format(conditions=conditions), {
141 "start": start,
142 "end": end
143 }, as_dict=True, update={"allDay": 0})
144
145 return data