Commit 7f9fb9c8 authored by aecres's avatar aecres

- revenue-by-dept:

  - Now with external data-source in order to support re-loading
  - Now with interval selector in GUI and data-source
  - Now with "fact" selctore (revenue/profit) in GUI and data-source
  - Now allows to configure custom $dept_sql for custom measures
parent 01672e8a
......@@ -10,8 +10,8 @@ Ext.onReady(function () {
type: 'rest',
url: '/intranet-reporting-dashboard/revenue-by-dept.json',
extraParams: { // Parameters to the data-source
diagram_interval: 'last_year', //
diagram_fact: 'revenue', //
diagram_interval: '@diagram_default_interval@', //
diagram_fact: '@diagram_default_fact@', //
diagram_dept_sql: "@diagram_dept_sql;noquote@" //
},
reader: { type: 'json', root: 'data' }
......@@ -28,6 +28,16 @@ Ext.onReady(function () {
]
});
var revenueByDeptsFactStore = Ext.create('Ext.data.Store', {
fields: ['display', 'value'],
data: [
{"display":"<%=[lang::message::lookup "" intranet-reporting-dashboard.Revenue "Revenue"]%>", "value":"revenue"},
{"display":"<%=[lang::message::lookup "" intranet-reporting-dashboard.Profit "Profit"]%>", "value":"profit"},
{"display":"<%=[lang::message::lookup "" intranet-reporting-dashboard.Internal_Cost "Internal Cost"]%>", "value":"internal_cost"},
{"display":"<%=[lang::message::lookup "" intranet-reporting-dashboard.External_Cost "External Cost"]%>", "value":"external_cost"}
]
});
revenueByDeptsChart = new Ext.chart.Chart({
xtype: 'chart',
animate: false,
......@@ -63,22 +73,43 @@ Ext.onReady(function () {
{
xtype: 'combo',
editable: false,
// fieldLabel: '<%=[lang::message::lookup "" intranet-reporting-dashboard.Interval Interval]%>',
fieldLabel: '<%=[lang::message::lookup "" intranet-reporting-dashboard.Interval Interval]%>',
store: revenueByDeptsIntervalStore,
mode: 'local',
displayField: 'display',
valueField: 'value',
triggerAction: 'all',
width: 150,
width: 250,
forceSelection: true,
value: 'last_year',
value: '@diagram_default_interval@',
listeners:{select:{fn:function(combo, comboValues) {
var value = comboValues[0].data.value;
var extraParams = revenueByDeptsStore.getProxy().extraParams;
extraParams.diagram_interval = value;
revenueByDeptsStore.load();
}}}
}, '->',
{
xtype: 'combo',
editable: false,
fieldLabel: '<%=[lang::message::lookup "" intranet-reporting-dashboard.Fact_Dimension "Fact Dimension"]%>',
store: revenueByDeptsFactStore,
mode: 'local',
displayField: 'display',
valueField: 'value',
triggerAction: 'all',
width: 250,
forceSelection: true,
value: '@diagram_default_fact@',
listeners:{select:{fn:function(combo, comboValues) {
var value = comboValues[0].data.value;
var extraParams = revenueByDeptsStore.getProxy().extraParams;
extraParams.diagram_fact = value;
revenueByDeptsStore.load();
}}}
}
],
items: revenueByDeptsChart
});
......
......@@ -13,10 +13,10 @@
# defined by the calling /tcl/*.tcl libary:
if {![info exists diagram_width]} { set diagram_width 600 }
if {![info exists diagram_height]} { set diagram_height 500 }
if {![info exists diagram_title]} { set diagram_title [lang::message::lookup "" intranet-reporting-dashboard.Revenue_by_Department "Revenue by Department"] }
if {![info exists diagram_title] || "" eq $diagram_title} { set diagram_title [lang::message::lookup "" intranet-reporting-dashboard.Revenue_by_Department "Revenue by Department"] }
if {![info exists diagram_dept_sql]} { set diagram_dept_sql "" }
if {![info exists diagram_intervall]} { set diagram_interval "last_year" }
if {![info exists diagram_fact]} { set diagram_fact "revenue" }
if {![info exists diagram_default_interval] || "" eq $diagram_default_interval} { set diagram_default_interval "last_year" }
if {![info exists diagram_default_fact] || "" eq $diagram_default_fact} { set diagram_default_fact "revenue" }
if {![info exists diagram_min_start_date]} { set diagram_min_start_date "2015-01-01" }
......@@ -24,6 +24,8 @@ if {![info exists diagram_min_start_date]} { set diagram_min_start_date "2015-01
# dept_sql - how to determine the department or area?
# ----------------------------------------------------
# ad_return_complaint 1 $diagram_dept_sql
set default_diagram_dept_sql "coalesce((select cost_center_name from im_cost_centers where cost_center_id = project_cost_center_id), 'none')"
if {"" eq $diagram_dept_sql} {
set diagram_dept_sql $default_diagram_dept_sql
......@@ -32,7 +34,7 @@ if {"" eq $diagram_dept_sql} {
# set dept_sql "coalesce(acs_object__name(project_cost_center_id), 'none')"
# set dept_sql "coalesce(im_category_from_id(aec_area_id), 'none')"
# set dept_sql "coalesce((select cost_center_name from im_cost_centers where cost_center_id = project_cost_center_id), 'none')"
set diagram_dept_sql "coalesce((select category from im_categories where category_id = aec_area_id), 'none')"
# set diagram_dept_sql "coalesce((select category from im_categories where category_id = aec_area_id), 'none')"
# ----------------------------------------------------
......
......@@ -882,6 +882,11 @@ ad_proc -public im_dashboard_project_eva {
ad_proc -public im_dashboard_revenue_by_dept {
{-diagram_width 600}
{-diagram_height 500}
{-diagram_title ""}
{-diagram_dept_sql ""}
{-diagram_default_interval "last_year" }
{-diagram_default_fact "revenue" }
{-diagram_min_start_date "2015-01-01" }
} {
Returns a HTML component with a timeline of a revenues
by department.
......@@ -896,6 +901,11 @@ ad_proc -public im_dashboard_revenue_by_dept {
set params [list \
[list diagram_width $diagram_width] \
[list diagram_height $diagram_height] \
[list diagram_title $diagram_title] \
[list diagram_dept_sql $diagram_dept_sql] \
[list diagram_default_interval $diagram_default_interval] \
[list diagram_default_fact $diagram_default_fact] \
[list diagram_min_start_date $diagram_min_start_date] \
]
set result [ad_parse_template -params $params "/packages/intranet-reporting-dashboard/lib/revenue-by-dept"]
......
......@@ -146,30 +146,30 @@ set months [db_list months "select * from im_month_enumerator(:diagram_start_dat
# ----------------------------------------------------
foreach dept $dept_list { set rev_hash_old($dept) 0.0 }
foreach dept $dept_list { set hash_old($dept-revenue) 0.0 }
set rev_rows {}
set cnt 0
foreach now $months {
set rev_line [list "'Date': new Date(\"$now\")"]
array unset rev_hash
array unset hash
db_foreach rev $revenue_sql {
set rev_hash($department) $revenue
set int_cost_hash($department) $internal_cost
set ext_cost_hash($department) $external_cost
set profit_hash($department) $profit
set hash($department-revenue) $revenue
set hash($department-internal_cost) $internal_cost
set hash($department-external_cost) $external_cost
set hash($department-profit) $profit
}
# Extract a list of revenues by dept, following the list of depts
foreach dept $dept_list {
set value 0.0; # current value
if {[info exists rev_hash($dept)]} { set value $rev_hash($dept) }
if {[info exists hash($dept-$diagram_fact)]} { set value $hash($dept-$diagram_fact) }
set old_value 0.0; # value from last month
if {[info exists rev_hash_old($dept)]} { set old_value $rev_hash_old($dept) }
if {[info exists hash_old($dept-$diagram_fact)]} { set old_value $hash_old($dept-$diagram_fact) }
set rev_hash_old($dept) $value; # update the old value for next iteration
set hash_old($dept-$diagram_fact) $value; # update the old value for next iteration
set diff [expr round(1000.0 * ($value - $old_value)) / 1000.0]
lappend rev_line "'$dept': $diff"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment