From 988096e82d6888544a4703a3f2ff65b4f790a08c Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 7 Oct 2013 18:06:52 +0530 Subject: [PATCH] [feature] Sales Funnel visualization. Go to Selling > Analytics > Sales Funnel --- .../{crm_funnel => sales_funnel}/__init__.py | 0 .../sales_funnel.css} | 0 .../sales_funnel.js} | 29 ++++++++++++++----- .../sales_funnel.py} | 0 .../sales_funnel.txt} | 8 ++--- selling/page/selling_home/selling_home.js | 4 +++ 6 files changed, 29 insertions(+), 12 deletions(-) rename selling/page/{crm_funnel => sales_funnel}/__init__.py (100%) rename selling/page/{crm_funnel/crm_funnel.css => sales_funnel/sales_funnel.css} (100%) rename selling/page/{crm_funnel/crm_funnel.js => sales_funnel/sales_funnel.js} (83%) rename selling/page/{crm_funnel/crm_funnel.py => sales_funnel/sales_funnel.py} (100%) rename selling/page/{crm_funnel/crm_funnel.txt => sales_funnel/sales_funnel.txt} (81%) diff --git a/selling/page/crm_funnel/__init__.py b/selling/page/sales_funnel/__init__.py similarity index 100% rename from selling/page/crm_funnel/__init__.py rename to selling/page/sales_funnel/__init__.py diff --git a/selling/page/crm_funnel/crm_funnel.css b/selling/page/sales_funnel/sales_funnel.css similarity index 100% rename from selling/page/crm_funnel/crm_funnel.css rename to selling/page/sales_funnel/sales_funnel.css diff --git a/selling/page/crm_funnel/crm_funnel.js b/selling/page/sales_funnel/sales_funnel.js similarity index 83% rename from selling/page/crm_funnel/crm_funnel.js rename to selling/page/sales_funnel/sales_funnel.js index a2d2b93479..e2c3a98bf5 100644 --- a/selling/page/crm_funnel/crm_funnel.js +++ b/selling/page/sales_funnel/sales_funnel.js @@ -1,14 +1,18 @@ // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. // License: GNU General Public License v3. See license.txt -wn.pages['crm-funnel'].onload = function(wrapper) { +wn.pages['sales-funnel'].onload = function(wrapper) { wn.ui.make_app_page({ parent: wrapper, - title: 'CRM Funnel', + title: 'Sales Funnel', single_column: true }); wrapper.crm_funnel = new erpnext.CRMFunnel(wrapper); + + wrapper.appframe.add_module_icon("Selling", "sales-funnel", function() { + wn.set_route("selling-home"); + }); } erpnext.CRMFunnel = Class.extend({ @@ -40,8 +44,8 @@ erpnext.CRMFunnel = Class.extend({ .appendTo(this.elements.layout); this.options = { - from_date: wn.datetime.get_today(), - to_date: wn.datetime.add_months(wn.datetime.get_today(), -1) + from_date: wn.datetime.add_months(wn.datetime.get_today(), -1), + to_date: wn.datetime.get_today() }; // set defaults and bind on change @@ -108,7 +112,7 @@ erpnext.CRMFunnel = Class.extend({ y_old = y; // new y - y = y + (me.options.height * d.value / me.options.total_value); + y = y + d.height; // new x var half_side = (me.options.height - y) / Math.sqrt(3); @@ -122,15 +126,24 @@ erpnext.CRMFunnel = Class.extend({ }, prepare: function() { + var me = this; + this.elements.no_data.toggle(false); // calculate width and height options this.options.width = $(this.elements.funnel_wrapper).width() * 2.0 / 3.0; this.options.height = (Math.sqrt(3) * this.options.width) / 2.0; - // calculate total value - this.options.total_value = this.options.data.reduce( - function(prev, curr) { return prev + curr.value; }, 0.0); + // calculate total weightage + // as height decreases, area decreases by the square of the reduction + // hence, compensating by squaring the index value + this.options.total_weightage = this.options.data.reduce( + function(prev, curr, i) { return prev + Math.pow(i+1, 2) * curr.value; }, 0.0); + + // calculate height for each data + $.each(this.options.data, function(i, d) { + d.height = me.options.height * d.value * Math.pow(i+1, 2) / me.options.total_weightage; + }); this.elements.canvas = $('') .appendTo(this.elements.funnel_wrapper.empty()) diff --git a/selling/page/crm_funnel/crm_funnel.py b/selling/page/sales_funnel/sales_funnel.py similarity index 100% rename from selling/page/crm_funnel/crm_funnel.py rename to selling/page/sales_funnel/sales_funnel.py diff --git a/selling/page/crm_funnel/crm_funnel.txt b/selling/page/sales_funnel/sales_funnel.txt similarity index 81% rename from selling/page/crm_funnel/crm_funnel.txt rename to selling/page/sales_funnel/sales_funnel.txt index 29cf566053..b841f20fdc 100644 --- a/selling/page/crm_funnel/crm_funnel.txt +++ b/selling/page/sales_funnel/sales_funnel.txt @@ -11,21 +11,21 @@ "icon": "icon-filter", "module": "Selling", "name": "__common__", - "page_name": "crm-funnel", + "page_name": "sales-funnel", "standard": "Yes", - "title": "CRM Funnel" + "title": "Sales Funnel" }, { "doctype": "Page Role", "name": "__common__", - "parent": "crm-funnel", + "parent": "sales-funnel", "parentfield": "roles", "parenttype": "Page", "role": "Sales Manager" }, { "doctype": "Page", - "name": "crm-funnel" + "name": "sales-funnel" }, { "doctype": "Page Role" diff --git a/selling/page/selling_home/selling_home.js b/selling/page/selling_home/selling_home.js index 9697ccf985..5dd33e640f 100644 --- a/selling/page/selling_home/selling_home.js +++ b/selling/page/selling_home/selling_home.js @@ -155,6 +155,10 @@ wn.module_page["Selling"] = [ "label":wn._("Sales Analytics"), page: "sales-analytics" }, + { + "label":wn._("Sales Funnel"), + page: "sales-funnel" + }, ] }, {