chore: Remove raw SQL query
diff --git a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.js b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.js
index febf85c..99cc0a7 100644
--- a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.js
+++ b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.js
@@ -43,20 +43,13 @@
 
 	reference_docname: function(frm) {
 		if (frm.doc.reference_docname && frm.doc.reference_doctype) {
-			let fields_to_fetch = ["grand_total"];
 			let party_field = frm.doc.reference_doctype == "Sales Order" ? "customer" : "supplier";
 
-			if (frm.doc.reference_doctype == "Sales Order") {
-				fields_to_fetch.push("project");
-			}
-
-			fields_to_fetch.push(party_field);
 			frappe.call({
-				method: "erpnext.accounts.doctype.bank_guarantee.bank_guarantee.get_vouchar_detials",
+				method: "erpnext.accounts.doctype.bank_guarantee.bank_guarantee.get_voucher_details",
 				args: {
-					"column_list": fields_to_fetch,
-					"doctype": frm.doc.reference_doctype,
-					"docname": frm.doc.reference_docname
+					"bank_guarantee_type": frm.doc.bg_type,
+					"reference_name": frm.doc.reference_docname
 				},
 				callback: function(r) {
 					if (r.message) {
diff --git a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py
index 9144a29..a57acda 100644
--- a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py
+++ b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py
@@ -2,11 +2,8 @@
 # For license information, please see license.txt
 
 
-import json
-
 import frappe
 from frappe import _
-from frappe.desk.search import sanitize_searchfield
 from frappe.model.document import Document
 
 
@@ -25,14 +22,17 @@
 
 
 @frappe.whitelist()
-def get_vouchar_detials(column_list, doctype, docname):
-	column_list = json.loads(column_list)
-	for col in column_list:
-		sanitize_searchfield(col)
-	return frappe.db.sql(
-		""" select {columns} from `tab{doctype}` where name=%s""".format(
-			columns=", ".join(column_list), doctype=doctype
-		),
-		docname,
-		as_dict=1,
-	)[0]
+def get_voucher_details(bank_guarantee_type, reference_name):
+	fields_to_fetch = ["grand_total"]
+
+	doctype = "Sales Order" if bank_guarantee_type == "Receiving" else "Purchase Order"
+
+	if doctype == "Sales Order":
+		fields_to_fetch.append("customer")
+		fields_to_fetch.append("project")
+	else:
+		fields_to_fetch.append("supplier")
+
+	bg_doctype = frappe.qb.DocType("Bank Guarantee")
+
+	return frappe.db.get_value(doctype, reference_name, fields_to_fetch, as_dict=True)