Skip to content

Commit

Permalink
fix: add so/si support in fee schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
RitvikSardana committed Mar 26, 2024
1 parent 0d37b24 commit 63f8d3e
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 166 deletions.
310 changes: 163 additions & 147 deletions education/education/doctype/fee_schedule/fee_schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,162 +3,178 @@

frappe.provide("erpnext.accounts.dimensions");
frappe.ui.form.on("Fee Schedule", {
company: function (frm) {
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
},
company: function (frm) {
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
},

onload: function (frm) {
frm.set_query("receivable_account", function (doc) {
return {
filters: {
account_type: "Receivable",
is_group: 0,
company: doc.company,
},
};
});
onload: function (frm) {
frm.set_query("receivable_account", function (doc) {
return {
filters: {
account_type: "Receivable",
is_group: 0,
company: doc.company,
},
};
});

frm.set_query("income_account", function (doc) {
return {
filters: {
account_type: "Income Account",
is_group: 0,
company: doc.company,
},
};
});
frm.set_query("income_account", function (doc) {
return {
filters: {
account_type: "Income Account",
is_group: 0,
company: doc.company,
},
};
});

frm.set_query("academic_term", function (doc) {
return {
filters: {
academic_year: doc.academic_year,
},
};
});
frm.set_query("academic_term", function (doc) {
return {
filters: {
academic_year: doc.academic_year,
},
};
});

frm.set_query("student_group", "student_groups", function () {
return {
filters: {
program: frm.doc.program,
academic_term: frm.doc.academic_term,
academic_year: frm.doc.academic_year,
disabled: 0,
},
};
});
frm.set_query("student_group", "student_groups", function () {
return {
filters: {
program: frm.doc.program,
academic_term: frm.doc.academic_term,
academic_year: frm.doc.academic_year,
disabled: 0,
},
};
});

frappe.realtime.on("fee_schedule_progress", function (data) {
if (data.reload && data.reload === 1) {
frm.reload_doc();
}
if (data.progress) {
let progress_bar = $(cur_frm.dashboard.progress_area.body).find(
".progress-bar"
);
if (progress_bar) {
$(progress_bar)
.removeClass("progress-bar-danger")
.addClass("progress-bar-success progress-bar-striped");
$(progress_bar).css("width", data.progress + "%");
}
}
});
frappe.realtime.on("fee_schedule_progress", function (data) {
if (data.reload && data.reload === 1) {
frm.reload_doc();
}
if (data.progress) {
let progress_bar = $(cur_frm.dashboard.progress_area.body).find(
".progress-bar"
);
if (progress_bar) {
$(progress_bar)
.removeClass("progress-bar-danger")
.addClass("progress-bar-success progress-bar-striped");
$(progress_bar).css("width", data.progress + "%");
}
}
});

erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
},
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
},

refresh: function (frm) {
if (
!frm.doc.__islocal &&
frm.doc.__onload &&
frm.doc.__onload.dashboard_info &&
frm.doc.fee_creation_status === "Successful"
) {
var info = frm.doc.__onload.dashboard_info;
frm.dashboard.add_indicator(
__("Total Collected: {0}", [
format_currency(info.total_paid, info.currency),
]),
"blue"
);
frm.dashboard.add_indicator(
__("Total Outstanding: {0}", [
format_currency(info.total_unpaid, info.currency),
]),
info.total_unpaid ? "orange" : "green"
);
}
if (frm.doc.fee_creation_status === "In Process") {
frm.dashboard.add_progress("Fee Creation Status", "0");
}
if (
(frm.doc.docstatus === 1 && !frm.doc.fee_creation_status) ||
frm.doc.fee_creation_status === "Failed"
) {
let button_label = "Create Sales Invoice";
// frappe.db.get_value get only create_so field from Education Settings
frappe.db.get_value("Education Settings", {}, "create_so", (r) => {
if (+r.create_so) {
button_label = "Create Sales Order";
}
frm.add_custom_button(__(button_label), function () {
frappe.call({
method: "create_fees",
doc: frm.doc,
callback: function () {
frm.refresh();
},
});
});
});
}
if (frm.doc.fee_creation_status === "Successful") {
frm.add_custom_button(__("View Sales Invoice Records"), function () {
frappe.route_options = {
fee_schedule: frm.doc.name,
};
frappe.set_route("List", "Sales Invoice");
});
}
},
refresh: function (frm) {
if (
!frm.doc.__islocal &&
frm.doc.__onload &&
frm.doc.__onload.dashboard_info &&
frm.doc.fee_creation_status === "Successful"
) {
var info = frm.doc.__onload.dashboard_info;
frm.dashboard.add_indicator(
__("Total Collected: {0}", [
format_currency(info.total_paid, info.currency),
]),
"blue"
);
frm.dashboard.add_indicator(
__("Total Outstanding: {0}", [
format_currency(info.total_unpaid, info.currency),
]),
info.total_unpaid ? "orange" : "green"
);
}
if (frm.doc.fee_creation_status === "In Process") {
frm.dashboard.add_progress("Fee Creation Status", "0");
}
if (
(frm.doc.docstatus === 1 && !frm.doc.fee_creation_status) ||
frm.doc.fee_creation_status === "Failed"
) {
let button_label = "Create Sales Invoice";

fee_structure: function (frm) {
if (frm.doc.fee_structure) {
frappe.call({
method:
"education.education.doctype.fee_schedule.fee_schedule.get_fee_structure",
args: {
target_doc: frm.doc.name,
source_name: frm.doc.fee_structure,
},
callback: function (r) {
var doc = frappe.model.sync(r.message);
frappe.set_route("Form", doc[0].doctype, doc[0].name);
},
});
}
},
frappe.db.get_value("Education Settings", {}, "create_so", (r) => {
// convert r.create_so to number
if (+r.create_so) {
button_label = "Create Sales Order";
// set indicator in the frm
}
frm.add_custom_button(__(button_label), function () {
frappe.call({
method: "create_fees",
doc: frm.doc,
callback: function () {
frm.refresh();
},
});
});
});
}
if (frm.doc.fee_creation_status === "Successful") {
frm.add_custom_button(
__("View Sales Order"),
function () {
frappe.route_options = {
fee_schedule: frm.doc.name,
};
frappe.set_route("List", "Sales Order");
},
__("View Records")
);
frm.add_custom_button(
__("View Sales Invoice"),
function () {
frappe.route_options = {
fee_schedule: frm.doc.name,
};
frappe.set_route("List", "Sales Invoice");
},
__("View Records")
);
}
},

fee_structure: function (frm) {
if (frm.doc.fee_structure) {
frappe.call({
method:
"education.education.doctype.fee_schedule.fee_schedule.get_fee_structure",
args: {
target_doc: frm.doc.name,
source_name: frm.doc.fee_structure,
},
callback: function (r) {
var doc = frappe.model.sync(r.message);
frappe.set_route("Form", doc[0].doctype, doc[0].name);
},
});
}
},
});

frappe.ui.form.on("Fee Schedule Student Group", {
student_group: function (frm, cdt, cdn) {
var row = locals[cdt][cdn];
if (row.student_group && frm.doc.academic_year) {
frappe.call({
method:
"education.education.doctype.fee_schedule.fee_schedule.get_total_students",
args: {
student_group: row.student_group,
academic_year: frm.doc.academic_year,
academic_term: frm.doc.academic_term,
student_category: frm.doc.student_category,
},
callback: function (r) {
if (r.message) {
frappe.model.set_value(cdt, cdn, "total_students", r.message);
}
},
});
}
},
student_group: function (frm, cdt, cdn) {
var row = locals[cdt][cdn];
if (row.student_group && frm.doc.academic_year) {
frappe.call({
method:
"education.education.doctype.fee_schedule.fee_schedule.get_total_students",
args: {
student_group: row.student_group,
academic_year: frm.doc.academic_year,
academic_term: frm.doc.academic_term,
student_category: frm.doc.student_category,
},
callback: function (r) {
if (r.message) {
frappe.model.set_value(cdt, cdn, "total_students", r.message);
}
},
});
}
},
});
6 changes: 5 additions & 1 deletion education/education/doctype/fee_schedule/fee_schedule.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,13 @@
{
"link_doctype": "Sales Invoice",
"link_fieldname": "fee_schedule"
},
{
"link_doctype": "Sales Order",
"link_fieldname": "fee_schedule"
}
],
"modified": "2024-01-23 12:18:14.075608",
"modified": "2024-03-26 14:37:05.652436",
"modified_by": "Administrator",
"module": "Education",
"name": "Fee Schedule",
Expand Down
Loading

0 comments on commit 63f8d3e

Please sign in to comment.