bug solved (not correct form) and show 6 months by default

This commit is contained in:
Patri
2014-05-30 01:06:09 +02:00
parent 6d01b111c7
commit 79ccbe2e4c
3 changed files with 95 additions and 79 deletions

View File

@ -1,6 +1,20 @@
$ ->
$("input.datepicker").each (i) ->
$(this).datepicker
altFormat: "yy-mm-dd"
dateFormat: "mm/dd/yy"
altFormat: "dd-mm-yy"
dateFormat: "dd/mm/yy"
altField: $(this).next()
$("#datepicker_from, #datepicker_to").datepicker
changeMonth: true
changeYear: true
showButtonPanel: true
dateFormat: "MM yy"
onClose: ->
month = $("#ui-datepicker-div .ui-datepicker-month :selected").val()
year = $("#ui-datepicker-div .ui-datepicker-year :selected").val()
$(this).datepicker "setDate", new Date(year, month, 1)
return
$("#datepicker_from, #datepicker_to").focus ->
$(".ui-datepicker-calendar").hide()
return

View File

@ -23,12 +23,13 @@ class ReportsController < ApplicationController
@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]
# periodo a mostrar actividades globales, por defecto 6 meses
ini = params[:ini]? params[:ini].to_date : DateTime.now.to_date - 5.month
fin = params[:fin]? params[:fin].to_date : DateTime.now.to_date
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
num_months = (fin.year * 12 + fin.month) - (ini.year * 12 + ini.month) + 1
date = ini
# vector para los meses de la gráfica ["Enero", "Febrero",...]
@months_names = []
# y vectores con los datos para la gráfica

View File

@ -1,78 +1,79 @@
%h1
= t ".statistics"
.panel.panel-default
.panel-heading
.panel-title
= t ".global_activity"
.panel-body
%ul.nav.nav-pills.statistics
%li
= t ".users_reg"
.badge
= @members.count
%li
= t ".num_swaps"
.badge
= @num_swaps
%li
= 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
%div{"ng-controller" => ""}
%h1
= t ".statistics"
.panel.panel-default
.panel-heading
.panel-title
= t ".global_activity"
.panel-body
%ul.nav.nav-pills.statistics
%li
= t ".users_reg"
.badge
= @members.count
%li
= t ".num_swaps"
.badge
= @num_swaps
%li
= t ".total_hours"
.badge
= seconds_to_hm @total_hours
%form.navbar-form.navbar-right
.form-group
%input.form-control{id: "datepicker_from", placeholder: "mm/aaaa inicial", name: "ini", value: params[:ini]}
%input.form-control{id: "datepicker_to", placeholder: "mm/aaaa final", name: "fin", value: params[:fin]}
%button.btn.btn-default{type: "submit"}= "Mostrar"
#chart
.panel.panel-default
.panel-heading
.panel-title
= t ".inactive_users"
.panel-body
%table.table.table-hover.table-condensed
%thead
%tr
%th ID
%th= User.human_attribute_name(:username)
%th= t ".days_without_swaps"
%th= t ".last_movement"
%tbody
/ Por días sin movimientos
- @members.includes(:account).sort_by(&:days_without_swaps).reverse.map{|a| a unless a.days_without_swaps.zero?}.compact.each do |mem|
%tr
%td= mem.member_uid
%td= link_to mem.user.username, mem.user
%td= (DateTime.now.to_date - mem.account.updated_at.to_date).to_i
%td= (mem.account.balance.blank? || mem.account.balance.zero?) ? t(".no_movements") : l(mem.account.updated_at, format: :short)
.panel.panel-default
.panel-heading
.panel-title
= t ".inactive_users"
.panel-body
%table.table.table-hover.table-condensed
%thead
%tr
%th ID
%th= User.human_attribute_name(:username)
%th= t ".days_without_swaps"
%th= t ".last_movement"
%tbody
/ Por días sin movimientos
- @members.includes(:account).sort_by(&:days_without_swaps).reverse.map{|a| a unless a.days_without_swaps.zero?}.compact.each do |mem|
%tr
%td= mem.member_uid
%td= link_to mem.user.username, mem.user
%td= (DateTime.now.to_date - mem.account.updated_at.to_date).to_i
%td= (mem.account.balance.blank? || mem.account.balance.zero?) ? t(".no_movements") : l(mem.account.updated_at, format: :short)
.panel.panel-default
.panel-heading
.panel-title
= t ".demographics"
.panel-body
- age = 0
- @date = { 'Desconocida' => 0, '-17' => 0, '18-24' => 0, '25-34' => 0, '35-44' => 0, '45-54' => 0, '55-64' => 0, '65+' => 0 }
- @members.each do |m|
- age = (m.user.date_of_birth.present?)? age(m.user.date_of_birth) : -1
- case age
- when 0 .. 17
- @date['-17']+= 1
- when 18 .. 24
- @date['18-24']+= 1
- when 25 .. 34
- @date['25-34']+= 1
- when 35 .. 44
- @date['35-44']+= 1
- when 45 .. 54
- @date['45-54']+= 1
- when 55 .. 64
- @date['55-64']+= 1
- when 65 .. 100
- @date['65+']+= 1
- else
- @date['Desconocida']+= 1
#pie
.panel.panel-default
.panel-heading
.panel-title
= t ".demographics"
.panel-body
- age = 0
- @date = { 'Desconocida' => 0, '-17' => 0, '18-24' => 0, '25-34' => 0, '35-44' => 0, '45-54' => 0, '55-64' => 0, '65+' => 0 }
- @members.each do |m|
- age = (m.user.date_of_birth.present?)? age(m.user.date_of_birth) : -1
- case age
- when 0 .. 17
- @date['-17']+= 1
- when 18 .. 24
- @date['18-24']+= 1
- when 25 .. 34
- @date['25-34']+= 1
- when 35 .. 44
- @date['35-44']+= 1
- when 45 .. 54
- @date['45-54']+= 1
- when 55 .. 64
- @date['55-64']+= 1
- when 65 .. 100
- @date['65+']+= 1
- else
- @date['Desconocida']+= 1
#pie
:javascript
window.onload = function () {