Commit 271c21c0 authored by aecres's avatar aecres

- Added parameters for enabling Total and "quotes as a proxy for invoices"

parent 079336e4
......@@ -29,7 +29,8 @@
<callbacks>
</callbacks>
<parameters>
<!-- No version parameters -->
<parameter datatype="number" min_n_values="1" max_n_values="1" name="RevenueByDeptWithTotalP" default="0" description="Should we show the Total in the Revenue by Department indicator? The Total will change the scale of the indicator, so it's not that recommended."/>
<parameter datatype="number" min_n_values="1" max_n_values="1" name="RevenueByDeptUseQuotesAsProxyForInvoicesDays" default="0" description="Can we use quoted amounts as a proxy for invoices, while the project is not yet closed? Default is '0' in order to disable this feature. Reasonable values could be 30 or 60, meaning that 30 or 60 days after the end_date of the project the indicator would use the invoiced amount instead of the quoted amount, assuming that it will take so long in order to write invoices."/>
</parameters>
</version>
......
......@@ -19,6 +19,8 @@ if {![info exists diagram_default_interval] || "" eq $diagram_default_interval}
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" }
set enable_total_p [parameter::get_from_package_key -package_key "intranet-reporting-dashboard" -parameter RevenueByDeptWithTotalP -default 1]
set use_quotes_as_proxy_for_invoices_days [parameter::get_from_package_key -package_key "intranet-reporting-dashboard" -parameter RevenueByDeptUseQuotesAsProxyForInvoicesDays -default 0]
# ----------------------------------------------------
# dept_sql - how to determine the department or area?
......@@ -49,6 +51,7 @@ set default_currency [im_parameter -package_id [im_package_cost_id] "DefaultCurr
# Get the list of all departments
set dept_list [db_list dept_list "select dept from (select distinct $diagram_dept_sql as dept from im_projects) t order by lower(dept)"]
if {$enable_total_p} { set dept_list [lappend dept_list "Total"] }
set dept_list_json "\['[join $dept_list "', '"]'\]"
# The header of the Sencha store:
......@@ -76,7 +79,7 @@ foreach dept $dept_list {
}
},
tips: { width: 200, renderer: function(storeItem, item) {
this.setTitle('$dept:<br>Date: '+storeItem.get('Date').toISOString().substring(0,10)+',<br> Revenues: '+storeItem.get('$dept'));
this.setTitle('$dept:<br>Date: '+storeItem.get('Date').toISOString().substring(0,7)+',<br> Revenues: '+storeItem.get('$dept'));
}}
}"
}
......
......@@ -39,7 +39,10 @@ if {![im_permission $current_user_id view_companies_all] || ![im_permission $cur
ad_script_abort
}
set enable_total_p [parameter::get_from_package_key -package_key "intranet-reporting-dashboard" -parameter "RevenueByDeptWithTotalP" -default 1]
set default_currency [im_parameter -package_id [im_package_cost_id] "DefaultCurrency" "" "EUR"]
set use_quotes_as_proxy_for_invoices_days [parameter::get_from_package_key -package_key "intranet-reporting-dashboard" -parameter RevenueByDeptUseQuotesAsProxyForInvoicesDays -default 0]
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} {
......@@ -163,6 +166,7 @@ foreach now $months {
}
# Extract a list of revenues by dept, following the list of depts
set total 0.0
foreach dept $dept_list {
set value 0.0; # current value
if {[info exists hash($dept-$diagram_fact)]} { set value $hash($dept-$diagram_fact) }
......@@ -175,6 +179,12 @@ foreach now $months {
set diff [expr round(1000.0 * ($value - $old_value)) / 1000.0]
lappend rev_line "'$dept': $diff"
set total [expr $total + $diff]
}
if {$enable_total_p} {
set total [expr round(1000.0 * $total) / 1000.0]
lappend rev_line "'Total': $total"
}
# Skip the first row, because it starts with 0
......
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