fix: Validate Filters in Sales Funnel. (#21761)

* fix: Validate Filters in Sales Funnel.

* fix: Style fixes
diff --git a/erpnext/selling/page/sales_funnel/sales_funnel.js b/erpnext/selling/page/sales_funnel/sales_funnel.js
index 85c0cd8..e3d0a55 100644
--- a/erpnext/selling/page/sales_funnel/sales_funnel.js
+++ b/erpnext/selling/page/sales_funnel/sales_funnel.js
@@ -90,6 +90,10 @@
 
 	get_data(btn) {
 		var me = this;
+		if (!this.company) {
+			frappe.throw(__("Please Select a Company."));
+		}
+
 		const method_map = {
 			"sales_funnel": "erpnext.selling.page.sales_funnel.sales_funnel.get_funnel_data",
 			"opp_by_lead_source": "erpnext.selling.page.sales_funnel.sales_funnel.get_opp_by_lead_source",
diff --git a/erpnext/selling/page/sales_funnel/sales_funnel.py b/erpnext/selling/page/sales_funnel/sales_funnel.py
index d62e209..dba24ef 100644
--- a/erpnext/selling/page/sales_funnel/sales_funnel.py
+++ b/erpnext/selling/page/sales_funnel/sales_funnel.py
@@ -8,14 +8,23 @@
 from erpnext.accounts.report.utils import convert
 import pandas as pd
 
+def validate_filters(from_date, to_date, company):
+	if from_date and to_date and (from_date >= to_date):
+		frappe.throw(_("To Date must be greater than From Date"))
+
+	if not company:
+		frappe.throw(_("Please Select a Company"))
+
 @frappe.whitelist()
 def get_funnel_data(from_date, to_date, company):
+	validate_filters(from_date, to_date, company)
+
 	active_leads = frappe.db.sql("""select count(*) from `tabLead`
 		where (date(`modified`) between %s and %s)
 		and status != "Do Not Contact" and company=%s""", (from_date, to_date, company))[0][0]
 
 	active_leads += frappe.db.sql("""select count(distinct contact.name) from `tabContact` contact
-		left join `tabDynamic Link` dl on (dl.parent=contact.name) where dl.link_doctype='Customer' 
+		left join `tabDynamic Link` dl on (dl.parent=contact.name) where dl.link_doctype='Customer'
 		and (date(contact.modified) between %s and %s) and status != "Passive" """, (from_date, to_date))[0][0]
 
 	opportunities = frappe.db.sql("""select count(*) from `tabOpportunity`
@@ -38,6 +47,8 @@
 
 @frappe.whitelist()
 def get_opp_by_lead_source(from_date, to_date, company):
+	validate_filters(from_date, to_date, company)
+
 	opportunities = frappe.get_all("Opportunity", filters=[['status', 'in', ['Open', 'Quotation', 'Replied']], ['company', '=', company], ['transaction_date', 'Between', [from_date, to_date]]], fields=['currency', 'sales_stage', 'opportunity_amount', 'probability', 'source'])
 
 	if opportunities:
@@ -68,11 +79,13 @@
 
 @frappe.whitelist()
 def get_pipeline_data(from_date, to_date, company):
+	validate_filters(from_date, to_date, company)
+
 	opportunities = frappe.get_all("Opportunity", filters=[['status', 'in', ['Open', 'Quotation', 'Replied']], ['company', '=', company], ['transaction_date', 'Between', [from_date, to_date]]], fields=['currency', 'sales_stage', 'opportunity_amount', 'probability'])
 
 	if opportunities:
 		default_currency = frappe.get_cached_value('Global Defaults', 'None',  'default_currency')
-		
+
 		cp_opportunities = [dict(x, **{'compound_amount': (convert(x['opportunity_amount'], x['currency'], default_currency, to_date) * x['probability']/100)}) for x in opportunities]
 
 		df = pd.DataFrame(cp_opportunities).groupby(['sales_stage'], as_index=True).agg({'compound_amount': 'sum'}).to_dict()