Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Healthcare Package #526

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions healthcare/healthcare/custom_doctype/payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@


@frappe.whitelist()
def set_paid_amount_in_treatment_counselling(doc, method):
if doc.treatment_counselling and doc.paid_amount:
def set_paid_amount_in_healthcare_docs(doc, method):
if doc.paid_amount:
on_cancel = True if method == "on_cancel" else False
validate_treatment_counselling(doc, on_cancel)
if doc.treatment_counselling:
validate_doc("Treatment Counselling", doc.treatment_counselling, doc.paid_amount, on_cancel)
if doc.package_subscription:
validate_doc("Package Subscription", doc.package_subscription, doc.paid_amount, on_cancel)


def validate_treatment_counselling(doc, on_cancel=False):
treatment_counselling_doc = frappe.get_doc("Treatment Counselling", doc.treatment_counselling)
def validate_doc(doctype, docname, paid_amount, on_cancel=False):
doc = frappe.get_doc(doctype, docname)

paid_amount = treatment_counselling_doc.paid_amount + doc.paid_amount
if on_cancel:
paid_amount = treatment_counselling_doc.paid_amount - doc.paid_amount
paid_amount = doc.paid_amount - paid_amount
else:
paid_amount = doc.paid_amount + paid_amount

treatment_counselling_doc.paid_amount = paid_amount
treatment_counselling_doc.outstanding_amount = (
treatment_counselling_doc.amount - treatment_counselling_doc.paid_amount
)
treatment_counselling_doc.save()
doc.paid_amount = paid_amount
amount = doc.total_package_amount if doctype == "Package Subscription" else doc.amount

doc.outstanding_amount = amount - doc.paid_amount
doc.save()
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
// Copyright (c) 2024, earthians Health Informatics Pvt. Ltd. and contributors
// For license information, please see license.txt

let package_docs_filter = ["Item", "Clinical Procedure Template", "Observation Template", "Therapy Type"]

frappe.ui.form.on("Healthcare Package", {
refresh: function (frm) {
frm.set_query("price_list", function() {
return {
filters: {
"selling": 1,
}
};
});

frm.set_query("package_item_type", "package_items", function() {
return {
filters: {
"name": ["in", package_docs_filter],
}
};
});

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

onload: function (frm) {
if (frm.doc.is_billable) {
let read_only = frm.doc.item ? 1 : 0;
frm.set_df_property("item_code", "read_only", read_only);
frm.set_df_property("item_group", "read_only", read_only);
}
},

total_amount: function (frm) {
calculate_total_payable(frm);
},

apply_discount_on: function (frm) {
if(frm.doc.discount_percentage) {
frm.trigger("discount_percentage");
}
},

discount_percentage: function (frm) {
frm.via_discount_percentage = true;

if(frm.doc.discount_percentage && frm.doc.discount_amount) {
frm.set_value("discount_amount", 0);
}

let discount_field = frm.doc.apply_discount_on == "Total" ? "total_amount" : "net_total";
var total = flt(frm.doc[discount_field]);

var discount_amount = flt(total * flt(frm.doc.discount_percentage) / 100,
precision("discount_amount"));

frm.set_value("discount_amount", discount_amount)
.then(() => delete frm.via_discount_percentage);
calculate_total_payable(frm);
},

discount_amount: function (frm) {
if (!frm.via_discount_percentage) {
frm.set_value("discount_percentage", 0);
let discount_field = frm.doc.apply_discount_on == "Total" ? "total_amount" : "net_total";
var total = flt(frm.doc[discount_field]);
var discount_percentage = (flt(frm.doc.discount_amount) / total) * 100;

frm.set_value("discount_percentage", discount_percentage)
calculate_total_payable(frm);
}
},

package_name: function (frm) {
if (frm.doc.package_name && !frm.doc.item_code) {
frm.set_value("item_code", frm.doc.package_name);
}
}
});

frappe.ui.form.on("Healthcare Package Item", {
package_item: async function(frm, cdt, cdn) {
let row = locals[cdt][cdn];
if (frm.doc.price_list && row.package_item_type && row.package_item) {
if (row.package_item_type == "Item") {
frappe.model.set_value(cdt, cdn, "item_code", row.package_item)
set_item_rate(frm, row, row.package_item);
} else {
let item = (await frappe.db.get_value(row.package_item_type, row.package_item, "item")).message.item;
if (item) {
console.log()
frappe.model.set_value(cdt, cdn, "item_code", item)
set_item_rate(frm, row, item);
}
}
}
},

rate: function (frm, cdt, cdn) {
set_amount(frm, cdt, cdn);
},

no_of_sessions: function (frm, cdt, cdn) {
set_amount(frm, cdt, cdn);
},

amount: function (frm, cdt, cdn) {
let row = locals[cdt][cdn];
set_child_discounted_amount(row);
},

amount_with_discount: function (frm, cdt, cdn) {
set_totals(frm);
},

discount_percentage: function (frm, cdt, cdn) {
let row = locals[cdt][cdn];
frm.via_child_discount_percentage = true;

if(row.discount_percentage && row.discount_amount) {
row.discount_amount = 0;
}

var discount_amount = flt(row.amount * flt(row.discount_percentage) / 100,
precision("discount_amount"));

frappe.model.set_value(cdt, cdn, "discount_amount", discount_amount)
.then(() => delete frm.via_child_discount_percentage);
set_child_discounted_amount(row);
},

discount_amount: function (frm, cdt, cdn) {
let row = locals[cdt][cdn];
if (!frm.via_child_discount_percentage) {
row.discount_percentage = 0;
var discount_percentage = (flt(row.discount_amount) / row.amount) * 100;

frappe.model.set_value(cdt, cdn, "discount_percentage", discount_percentage)
set_child_discounted_amount(row);
}
}
});

var set_totals = function (frm) {
let total = 0;
let net_total = 0;
frm.doc.package_items.forEach((item) => {
total += item.amount_with_discount;
net_total += item.amount;
});
frm.set_value("total_amount", total);
frm.set_value("net_total", net_total);
};

var set_amount = function (frm, cdt, cdn) {
row = locals[cdt][cdn];
if (row.rate && row.no_of_sessions) {
frappe.model.set_value(cdt, cdn, "amount", (row.rate * row.no_of_sessions) - row.discount_amount);
}
};

var calculate_total_payable = function (frm) {
if (frm.doc.discount_amount) {
let discount_field = frm.doc.apply_discount_on == "Total" ? "total_amount" : "net_total";
var total = flt(frm.doc[discount_field]);
frm.set_value("discount_amount", flt(total * flt(frm.doc.discount_percentage) / 100));
frm.set_value("total_package_amount", total - flt(total * flt(frm.doc.discount_percentage) / 100));
} else {
frm.set_value("total_package_amount", frm.doc.total_amount);
}
};

var set_child_discounted_amount = function (row) {
frappe.model.set_value(row.doctype, row.name, "amount_with_discount", row.amount - row.discount_amount)
};

var set_item_rate = function (frm, row, item) {
frappe.db.get_value("Item Price", {
"item_code": item,
"price_list": frm.doc.price_list
}, "price_list_rate")
.then(r => {
let price_list_rate = r.message.price_list_rate ? r.message.price_list_rate : 0;
frappe.model.set_value(row.doctype, row.name, "rate", price_list_rate);
});
};
Loading
Loading