[feature] Sales Funnel visualization. Go to Selling > Analytics > Sales Funnel
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 a2d2b93..e2c3a98 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 @@
.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 @@
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 @@
},
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 = $('<canvas></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 29cf566..b841f20 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 9697ccf..5dd33e6 100644
--- a/selling/page/selling_home/selling_home.js
+++ b/selling/page/selling_home/selling_home.js
@@ -155,6 +155,10 @@
"label":wn._("Sales Analytics"),
page: "sales-analytics"
},
+ {
+ "label":wn._("Sales Funnel"),
+ page: "sales-funnel"
+ },
]
},
{