brotherton-erpnext/erpnext/selling/page/sales_funnel/sales_funnel.py

36 lines
1.6 KiB
Python
Raw Normal View History

# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2013-10-04 15:49:30 +00:00
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
2014-02-14 10:17:51 +00:00
import frappe
2013-10-04 15:49:30 +00:00
2016-01-04 10:27:01 +00:00
from frappe import _
2014-02-14 10:17:51 +00:00
@frappe.whitelist()
2013-10-04 15:49:30 +00:00
def get_funnel_data(from_date, to_date):
active_leads = frappe.db.sql("""select count(*) from `tabLead`
2013-10-31 13:36:11 +00:00
where (date(`modified`) between %s and %s)
2013-10-04 15:49:30 +00:00
and status != "Do Not Contact" """, (from_date, to_date))[0][0]
2014-04-28 10:13:32 +00:00
2017-01-20 12:56:40 +00:00
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'
and (date(contact.modified) between %s and %s) and status != "Passive" """, (from_date, to_date))[0][0]
2014-04-28 10:13:32 +00:00
opportunities = frappe.db.sql("""select count(*) from `tabOpportunity`
where (date(`creation`) between %s and %s)
2013-10-04 15:49:30 +00:00
and status != "Lost" """, (from_date, to_date))[0][0]
2014-04-28 10:13:32 +00:00
quotations = frappe.db.sql("""select count(*) from `tabQuotation`
2013-10-31 13:36:11 +00:00
where docstatus = 1 and (date(`creation`) between %s and %s)
2013-10-04 15:49:30 +00:00
and status != "Lost" """, (from_date, to_date))[0][0]
2014-04-28 10:13:32 +00:00
sales_orders = frappe.db.sql("""select count(*) from `tabSales Order`
2013-10-31 13:36:11 +00:00
where docstatus = 1 and (date(`creation`) between %s and %s)""", (from_date, to_date))[0][0]
2014-04-28 10:13:32 +00:00
2013-10-04 15:49:30 +00:00
return [
2016-01-04 10:27:01 +00:00
{ "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 10:13:32 +00:00
]