diff --git a/lms/lms/doctype/batch_student/batch_student.json b/lms/lms/doctype/batch_student/batch_student.json index 699050df..313c79c4 100644 --- a/lms/lms/doctype/batch_student/batch_student.json +++ b/lms/lms/doctype/batch_student/batch_student.json @@ -10,6 +10,7 @@ "student_details_section", "student", "payment", + "confirmation_email_sent", "column_break_oduu", "student_name", "username" @@ -52,12 +53,18 @@ "fieldtype": "Link", "label": "Payment", "options": "LMS Payment" + }, + { + "default": "0", + "fieldname": "confirmation_email_sent", + "fieldtype": "Check", + "label": "Confirmation Email Sent" } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2023-09-12 16:46:41.042810", + "modified": "2023-10-09 17:09:50.481794", "modified_by": "Administrator", "module": "LMS", "name": "Batch Student", diff --git a/lms/lms/doctype/lms_batch/lms_batch.py b/lms/lms/doctype/lms_batch/lms_batch.py index b21f24ab..68ac25a7 100644 --- a/lms/lms/doctype/lms_batch/lms_batch.py +++ b/lms/lms/doctype/lms_batch/lms_batch.py @@ -8,9 +8,17 @@ import json from frappe import _ from datetime import timedelta from frappe.model.document import Document -from frappe.utils import cint, format_date, format_datetime +from frappe.utils import ( + cint, + format_date, + format_datetime, + add_to_date, + getdate, + get_datetime, +) from lms.lms.utils import get_lessons, get_lesson_index, get_lesson_url from lms.www.utils import get_quiz_details, get_assignment_details +from frappe.email.doctype.email_template.email_template import get_email_template class LMSBatch(Document): @@ -22,6 +30,7 @@ class LMSBatch(Document): self.validate_duplicate_assessments() self.validate_membership() self.validate_timetable() + self.send_confirmation_mail() def validate_duplicate_students(self): students = [row.student for row in self.students] @@ -55,6 +64,43 @@ class LMSBatch(Document): ) ) + def send_confirmation_mail(self): + for student in self.students: + + if not student.confirmation_email_sent: + self.send_mail(student) + student.confirmation_email_sent = 1 + + def send_mail(self, student): + subject = _("Enrollment Confirmation for the Next Training Batch") + template = "batch_confirmation" + custom_template = frappe.db.get_single_value( + "LMS Settings", "batch_confirmation_template" + ) + + args = { + "student_name": student.student_name, + "start_time": self.start_time, + "start_date": self.start_date, + "medium": self.medium, + "name": self.name, + } + + if custom_template: + email_template = get_email_template(custom_template, args) + subject = email_template.get("subject") + content = email_template.get("message") + + frappe.sendmail( + recipients=student.student, + subject=subject, + template=template if not custom_template else None, + content=content if custom_template else None, + args=args, + header=[subject, "green"], + retry=3, + ) + def validate_membership(self): for course in self.courses: for student in self.students: diff --git a/lms/lms/doctype/lms_settings/lms_settings.json b/lms/lms/doctype/lms_settings/lms_settings.json index 36741a4b..13b98a9f 100644 --- a/lms/lms/doctype/lms_settings/lms_settings.json +++ b/lms/lms/doctype/lms_settings/lms_settings.json @@ -16,6 +16,7 @@ "portal_course_creation", "section_break_szgq", "send_calendar_invite_for_evaluations", + "batch_confirmation_template", "column_break_2", "allow_student_progress", "payment_section", @@ -176,7 +177,7 @@ { "fieldname": "section_break_szgq", "fieldtype": "Section Break", - "label": "Class Settings" + "label": "Batch Settings" }, { "fieldname": "signup_settings_tab", @@ -186,6 +187,7 @@ { "fieldname": "mentor_request_tab", "fieldtype": "Tab Break", + "hidden": 1, "label": "Mentor Request" }, { @@ -253,12 +255,18 @@ "fieldname": "apply_rounding", "fieldtype": "Check", "label": "Apply Rounding on Equivalent" + }, + { + "fieldname": "batch_confirmation_template", + "fieldtype": "Link", + "label": "Batch Confirmation Template", + "options": "Email Template" } ], "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2023-09-11 21:56:39.996898", + "modified": "2023-10-09 17:27:28.615355", "modified_by": "Administrator", "module": "LMS", "name": "LMS Settings", diff --git a/lms/templates/emails/batch_confirmation.html b/lms/templates/emails/batch_confirmation.html new file mode 100644 index 00000000..4e9ad30a --- /dev/null +++ b/lms/templates/emails/batch_confirmation.html @@ -0,0 +1,38 @@ +

+ {{ _("Dear ") }} {{ student_name }}, +

+
+

+ {{ _("I am pleased to inform you that your enrollment for the upcoming training batch has been successfully processed. Congratulations!") }} +

+
+

+ + {{ _("Important Details:") }} + +

+ +

+ {{ _("Batch Start Date:") }} {{ frappe.utils.format_date(start_date, "medium") }} +

+ +

+ {{ _("Medium:") }} {{ medium }} +

+ +

+ {{ _("Timings:") }} {{ frappe.utils.format_time(start_time, "hh:mm a") }} +

+
+

+ {{ _("Visit the following link to view your ") }} + {{ _("Batch Details") }} +

+

+ {{ _("If you have any questions or require assistance, feel free to contact us.") }} +

+
+

+ {{ _("Best Regards") }} +

+