34 lines
1.4 KiB
Python
Raw Normal View History

# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2013-10-04 21:19:30 +05:30
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
2014-02-14 15:47:51 +05:30
import frappe
2013-10-04 21:19:30 +05:30
2014-02-14 15:47:51 +05:30
@frappe.whitelist()
2013-10-04 21:19:30 +05:30
def get_funnel_data(from_date, to_date):
2014-02-26 12:35:33 +05:30
active_leads = frappe.db.sql("""select count(*) from `tabLead`
2013-10-31 19:06:11 +05:30
where (date(`modified`) between %s and %s)
2013-10-04 21:19:30 +05:30
and status != "Do Not Contact" """, (from_date, to_date))[0][0]
2014-04-28 15:43:32 +05:30
2014-02-26 12:35:33 +05:30
active_leads += frappe.db.sql("""select count(distinct customer) from `tabContact`
2013-10-31 19:06:11 +05:30
where (date(`modified`) between %s and %s)
2013-10-04 21:19:30 +05:30
and status != "Passive" """, (from_date, to_date))[0][0]
2014-04-28 15:43:32 +05:30
2014-02-26 12:35:33 +05:30
opportunities = frappe.db.sql("""select count(*) from `tabOpportunity`
2013-10-31 19:06:11 +05:30
where docstatus = 1 and (date(`creation`) between %s and %s)
2013-10-04 21:19:30 +05:30
and status != "Lost" """, (from_date, to_date))[0][0]
2014-04-28 15:43:32 +05:30
2014-02-26 12:35:33 +05:30
quotations = frappe.db.sql("""select count(*) from `tabQuotation`
2013-10-31 19:06:11 +05:30
where docstatus = 1 and (date(`creation`) between %s and %s)
2013-10-04 21:19:30 +05:30
and status != "Lost" """, (from_date, to_date))[0][0]
2014-04-28 15:43:32 +05:30
sales_orders = frappe.db.sql("""select count(*) from `tabSales Order`
2013-10-31 19:06:11 +05:30
where docstatus = 1 and (date(`creation`) between %s and %s)""", (from_date, to_date))[0][0]
2014-04-28 15:43:32 +05:30
2013-10-04 21:19:30 +05:30
return [
{ "title": "Active Leads / Customers", "value": active_leads, "color": "#B03B46" },
{ "title": "Opportunities", "value": opportunities, "color": "#F09C00" },
{ "title": "Quotations", "value": quotations, "color": "#006685" },
{ "title": "Sales Orders", "value": sales_orders, "color": "#00AD65" }
2014-04-28 15:43:32 +05:30
]