mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-17 06:52:27 +01:00
[to test] space reservations
This commit is contained in:
parent
2419a96010
commit
d450301934
@ -6,7 +6,7 @@ class API::StatisticsController < API::ApiController
|
||||
@statistics = StatisticIndex.all
|
||||
end
|
||||
|
||||
%w(account event machine project subscription training user).each do |path|
|
||||
%w(account event machine project subscription training user space).each do |path|
|
||||
class_eval %{
|
||||
def #{path}
|
||||
authorize :statistic, :#{path}?
|
||||
|
9
app/models/stats/space.rb
Normal file
9
app/models/stats/space.rb
Normal file
@ -0,0 +1,9 @@
|
||||
module Stats
|
||||
class Space
|
||||
include Elasticsearch::Persistence::Model
|
||||
include StatConcern
|
||||
include StatReservationConcern
|
||||
|
||||
attribute :spaceId, Integer
|
||||
end
|
||||
end
|
@ -1,5 +1,5 @@
|
||||
class StatisticPolicy < ApplicationPolicy
|
||||
%w(index account event machine project subscription training user scroll export_subscription export_machine
|
||||
%w(index account event machine project subscription training user space scroll export_subscription export_machine
|
||||
export_training export_event export_account export_project export_global).each do |action|
|
||||
define_method "#{action}?" do
|
||||
user.is_admin?
|
||||
|
@ -39,6 +39,23 @@ class StatisticService
|
||||
end
|
||||
end
|
||||
|
||||
# space list
|
||||
reservations_space_list(options).each do |r|
|
||||
%w(booking hour).each do |type|
|
||||
stat = Stats::Space.new({
|
||||
date: format_date(r.date),
|
||||
type: type,
|
||||
subType: r.space_type,
|
||||
ca: r.ca,
|
||||
spaceId: r.space_id,
|
||||
name: r.space_name,
|
||||
reservationId: r.reservation_id
|
||||
}.merge(user_info_stat(r)))
|
||||
stat.stat = (type == 'booking' ? 1 : r.nb_hours)
|
||||
stat.save
|
||||
end
|
||||
end
|
||||
|
||||
# training list
|
||||
reservations_training_list(options).each do |r|
|
||||
%w(booking hour).each do |type|
|
||||
@ -170,6 +187,27 @@ class StatisticService
|
||||
result
|
||||
end
|
||||
|
||||
|
||||
def reservations_space_list(options = default_options)
|
||||
result = []
|
||||
Reservation
|
||||
.where("reservable_type = 'Space' AND reservations.created_at >= :start_date AND reservations.created_at <= :end_date", options)
|
||||
.eager_load(:slots, user: [:profile, :group], invoice: [:invoice_items])
|
||||
.each do |r|
|
||||
u = r.user
|
||||
result.push OpenStruct.new({
|
||||
date: options[:start_date].to_date,
|
||||
reservation_id: r.id,
|
||||
space_id: r.reservable.id,
|
||||
space_name: r.reservable.name,
|
||||
space_type: r.reservable.slug,
|
||||
nb_hours: r.slots.size,
|
||||
ca: calcul_ca(r.invoice)
|
||||
}.merge(user_info(u))) if r.reservable
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def reservations_training_list(options = default_options)
|
||||
result = []
|
||||
Reservation
|
||||
|
@ -164,7 +164,7 @@ Rails.application.routes.draw do
|
||||
end
|
||||
end
|
||||
|
||||
%w(account event machine project subscription training user).each do |path|
|
||||
%w(account event machine project subscription training user space).each do |path|
|
||||
post "/stats/#{path}/_search", to: "api/statistics##{path}"
|
||||
post "/stats/#{path}/export", to: "api/statistics#export_#{path}"
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user