add activity bank by months with chart
This commit is contained in:
@@ -73,7 +73,12 @@ nav.navbar-static-top.navbar-inverse {
|
||||
color: red;
|
||||
}
|
||||
|
||||
// statistics view
|
||||
ul.statistics li{
|
||||
padding-right: 10px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
#chart{
|
||||
clear: both;
|
||||
}
|
||||
@@ -21,6 +21,42 @@ class ReportsController < ApplicationController
|
||||
end
|
||||
# cada intercambio implica dos movimientos
|
||||
@num_swaps = (num_movements + current_organization.account.movements.count)/2
|
||||
# intercambios con el banco
|
||||
@total_hours += current_organization.account.movements.map{ |a| (a.amount > 0)? a.amount : 0 }.inject(0,:+)
|
||||
# periodo a mostrar actividades globales
|
||||
ini, fin = params[:ini], params[:fin]
|
||||
if ini.present?
|
||||
# calculo numero de meses
|
||||
num_months = (fin.to_date.year * 12 + fin.to_date.month) - (ini.to_date.year * 12 + ini.to_date.month) + 1
|
||||
date = ini.to_date
|
||||
# vector para los meses de la gráfica ["Enero", "Febrero",...]
|
||||
@months_names = []
|
||||
# y vectores con los datos para la gráfica
|
||||
@user_reg_months = []
|
||||
@num_swaps_months = []
|
||||
@hours_swaps_months = []
|
||||
# valores por cada mes
|
||||
num_months.times{
|
||||
@months_names.push(date.strftime("%B"))
|
||||
@user_reg_months.push(@members.by_month(date).count)
|
||||
# movimientos de los miembros en dicho mes
|
||||
swaps_members = @members.map{|a| a.account.movements.by_month(date)}
|
||||
# movimimentos del banco
|
||||
swaps_organization = current_organization.account.movements.by_month(date)
|
||||
# numero de movimientos totales
|
||||
sum_swaps = (swaps_members.flatten.count + swaps_organization.count)/2
|
||||
@num_swaps_months.push(sum_swaps)
|
||||
# horas intercambiadas
|
||||
sum_hours = 0
|
||||
swaps_members.flatten.each do |s|
|
||||
sum_hours += (s.amount > 0)? s.amount : 0
|
||||
end
|
||||
sum_hours += swaps_organization.map{ |a| (a.amount > 0)? a.amount : 0 }.inject(0,:+)
|
||||
sum_hours = sum_hours / 3600.0 if sum_hours > 0
|
||||
@hours_swaps_months.push(sum_hours)
|
||||
date = date.next_month
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ class Member < ActiveRecord::Base
|
||||
after_create :create_account
|
||||
before_validation :assign_registration_number, :on => :create
|
||||
|
||||
scope :by_month, ->(month) { where({ created_at: month.beginning_of_month..month.end_of_month})}
|
||||
|
||||
validates :organization_id, presence: true
|
||||
validates :member_uid,
|
||||
presence: true,
|
||||
|
||||
@@ -14,4 +14,6 @@ class Movement < ActiveRecord::Base
|
||||
end
|
||||
|
||||
has_one :other_side, (->(self_) { where ["NOT movements.id = #{self_.id}"] }), through: :transfer, source: :movements
|
||||
|
||||
scope :by_month, ->(month) { where({ created_at: month.beginning_of_month..month.end_of_month})}
|
||||
end
|
||||
|
||||
@@ -18,6 +18,11 @@
|
||||
= t ".total_hours"
|
||||
.badge
|
||||
= seconds_to_hm @total_hours
|
||||
%form.navbar-form.navbar-right
|
||||
.form-group
|
||||
%input.form-control{type: "date", placeholder: "mm/aaaa inicial", name: "ini", value: params[:ini]}
|
||||
%input.form-control{type: "date", placeholder: "mm/aaaa final", name: "fin", value: params[:fin]}
|
||||
%button.btn.btn-default{type: "submit"}= "Mostrar"
|
||||
#chart
|
||||
|
||||
.panel.panel-default
|
||||
@@ -71,6 +76,54 @@
|
||||
|
||||
:javascript
|
||||
window.onload = function () {
|
||||
//globales
|
||||
$('#chart').highcharts({
|
||||
chart: {
|
||||
type: 'column'
|
||||
},
|
||||
title: {
|
||||
text: 'Actividad del banco'
|
||||
},
|
||||
subtitle: {
|
||||
text: 'Por meses'
|
||||
},
|
||||
xAxis: {
|
||||
categories: #{@months_names.to_json}
|
||||
},
|
||||
yAxis: {
|
||||
min: 0,
|
||||
title: {
|
||||
text: ''
|
||||
}
|
||||
},
|
||||
tooltip: {
|
||||
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
|
||||
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
|
||||
'<td style="padding:0"><b>{point.y}</b></td></tr>',
|
||||
footerFormat: '</table>',
|
||||
shared: true,
|
||||
useHTML: true
|
||||
},
|
||||
plotOptions: {
|
||||
column: {
|
||||
pointPadding: 0.2,
|
||||
borderWidth: 0
|
||||
}
|
||||
},
|
||||
series: [{
|
||||
name: "#{t '.users_reg'}",
|
||||
data: #{@user_reg_months.to_json}
|
||||
|
||||
}, {
|
||||
name: "#{t ".num_swaps"}",
|
||||
data: #{@num_swaps_months.to_json}
|
||||
|
||||
}, {
|
||||
name: "#{t ".total_hours"}",
|
||||
data: #{@hours_swaps_months.to_json}
|
||||
|
||||
}]
|
||||
});
|
||||
//demograficos
|
||||
var keys1 = #{@date.keys.to_json};
|
||||
var values1 = #{@date.values.to_json};
|
||||
@@ -109,6 +162,6 @@
|
||||
name: 'Nº personas',
|
||||
data: ages
|
||||
}]
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user