1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-04-10 00:53:51 +02:00

fix bug: statistic service cant run

This commit is contained in:
Du Peng 2021-07-19 17:28:06 +02:00
parent 47cfa1077c
commit 524b2c97bb

View File

@ -130,7 +130,7 @@ class StatisticService
.eager_load(invoice: [:coupon], subscription: [:plan, statistic_profile: [:group]]).each do |i| .eager_load(invoice: [:coupon], subscription: [:plan, statistic_profile: [:group]]).each do |i|
next if i.invoice.is_a?(Avoir) next if i.invoice.is_a?(Avoir)
sub = i.invoice_items.find(&:subscription) sub = i.subscription
next unless sub next unless sub
@ -162,7 +162,7 @@ class StatisticService
Reservation Reservation
.where("reservable_type = 'Machine' AND slots.canceled_at IS NULL AND " \ .where("reservable_type = 'Machine' AND slots.canceled_at IS NULL AND " \
'reservations.created_at >= :start_date AND reservations.created_at <= :end_date', options) 'reservations.created_at >= :start_date AND reservations.created_at <= :end_date', options)
.eager_load(:slots, statistic_profile: [:group], invoice: [:invoice_items]) .eager_load(:slots, :invoice_items, statistic_profile: [:group])
.each do |r| .each do |r|
next unless r.reservable next unless r.reservable
@ -174,7 +174,7 @@ class StatisticService
machine_type: r.reservable.friendly_id, machine_type: r.reservable.friendly_id,
machine_name: r.reservable.name, machine_name: r.reservable.name,
nb_hours: r.slots.size, nb_hours: r.slots.size,
ca: calcul_ca(r.invoice) ca: calcul_ca(r.original_invoice)
}.merge(user_info(profile))) }.merge(user_info(profile)))
end end
result result
@ -185,7 +185,7 @@ class StatisticService
Reservation Reservation
.where("reservable_type = 'Space' AND slots.canceled_at IS NULL AND " \ .where("reservable_type = 'Space' AND slots.canceled_at IS NULL AND " \
'reservations.created_at >= :start_date AND reservations.created_at <= :end_date', options) 'reservations.created_at >= :start_date AND reservations.created_at <= :end_date', options)
.eager_load(:slots, statistic_profile: [:group], invoice: [:invoice_items]) .eager_load(:slots, :invoice_items, statistic_profile: [:group])
.each do |r| .each do |r|
next unless r.reservable next unless r.reservable
@ -197,7 +197,7 @@ class StatisticService
space_name: r.reservable.name, space_name: r.reservable.name,
space_type: r.reservable.slug, space_type: r.reservable.slug,
nb_hours: r.slots.size, nb_hours: r.slots.size,
ca: calcul_ca(r.invoice) ca: calcul_ca(r.original_invoice)
}.merge(user_info(profile))) }.merge(user_info(profile)))
end end
result result
@ -208,7 +208,7 @@ class StatisticService
Reservation Reservation
.where("reservable_type = 'Training' AND slots.canceled_at IS NULL AND " \ .where("reservable_type = 'Training' AND slots.canceled_at IS NULL AND " \
'reservations.created_at >= :start_date AND reservations.created_at <= :end_date', options) 'reservations.created_at >= :start_date AND reservations.created_at <= :end_date', options)
.eager_load(:slots, statistic_profile: [:group], invoice: [:invoice_items]) .eager_load(:slots, :invoice_items, statistic_profile: [:group])
.each do |r| .each do |r|
next unless r.reservable next unless r.reservable
@ -222,7 +222,7 @@ class StatisticService
training_name: r.reservable.name, training_name: r.reservable.name,
training_date: slot.start_at.to_date, training_date: slot.start_at.to_date,
nb_hours: difference_in_hours(slot.start_at, slot.end_at), nb_hours: difference_in_hours(slot.start_at, slot.end_at),
ca: calcul_ca(r.invoice) ca: calcul_ca(r.original_invoice)
}.merge(user_info(profile))) }.merge(user_info(profile)))
end end
result result
@ -233,7 +233,7 @@ class StatisticService
Reservation Reservation
.where("reservable_type = 'Event' AND slots.canceled_at IS NULL AND " \ .where("reservable_type = 'Event' AND slots.canceled_at IS NULL AND " \
'reservations.created_at >= :start_date AND reservations.created_at <= :end_date', options) 'reservations.created_at >= :start_date AND reservations.created_at <= :end_date', options)
.eager_load(:slots, statistic_profile: [:group], invoice: [:invoice_items]) .eager_load(:slots, :invoice_items, statistic_profile: [:group])
.each do |r| .each do |r|
next unless r.reservable next unless r.reservable
@ -250,7 +250,7 @@ class StatisticService
age_range: (r.reservable.age_range_id ? r.reservable.age_range.name : ''), age_range: (r.reservable.age_range_id ? r.reservable.age_range.name : ''),
nb_places: r.total_booked_seats, nb_places: r.total_booked_seats,
nb_hours: difference_in_hours(slot.start_at, slot.end_at), nb_hours: difference_in_hours(slot.start_at, slot.end_at),
ca: calcul_ca(r.invoice) ca: calcul_ca(r.original_invoice)
}.merge(user_info(profile))) }.merge(user_info(profile)))
end end
result result
@ -262,13 +262,13 @@ class StatisticService
avoirs_ca_list = [] avoirs_ca_list = []
result = [] result = []
Reservation.where('reservations.created_at >= :start_date AND reservations.created_at <= :end_date', options) Reservation.where('reservations.created_at >= :start_date AND reservations.created_at <= :end_date', options)
.eager_load(:slots, statistic_profile: [:group], invoice: [:invoice_items]) .eager_load(:slots, :invoice_items, statistic_profile: [:group])
.each do |r| .each do |r|
next unless r.reservable next unless r.reservable
reservations_ca_list.push OpenStruct.new({ reservations_ca_list.push OpenStruct.new({
date: options[:start_date].to_date, date: options[:start_date].to_date,
ca: calcul_ca(r.invoice) ca: calcul_ca(r.original_invoice)
}.merge(user_info(r.statistic_profile))) }.merge(user_info(r.statistic_profile)))
end end
Avoir.where('invoices.created_at >= :start_date AND invoices.created_at <= :end_date', options) Avoir.where('invoices.created_at >= :start_date AND invoices.created_at <= :end_date', options)