mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-21 15:54:22 +01:00
(feat) add adds coupon in statistic export
This commit is contained in:
parent
581e08ea1e
commit
be69befb6b
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
- Fix a bug: unable to cancel a payment schedule
|
- Fix a bug: unable to cancel a payment schedule
|
||||||
- adds reservation context feature (for machine, training, space)
|
- adds reservation context feature (for machine, training, space)
|
||||||
|
- adds coupon in statistic export (for subscription, machine, training, space, event, order)
|
||||||
- [TODO DEPLOY] `rails db:seed`
|
- [TODO DEPLOY] `rails db:seed`
|
||||||
- [TODO DEPLOY] `rails fablab:es:build_stats`
|
- [TODO DEPLOY] `rails fablab:es:build_stats`
|
||||||
- [TODO DEPLOY] `rails fablab:maintenance:regenerate_statistics[2014,1]`
|
- [TODO DEPLOY] `rails fablab:maintenance:regenerate_statistics[2014,1]`
|
||||||
|
@ -70,6 +70,14 @@ module ExcelHelper
|
|||||||
types.push :float
|
types.push :float
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_coupon_cell(index, hit, data, styles, types)
|
||||||
|
return unless index.show_coupon?
|
||||||
|
|
||||||
|
data.push hit['_source']['coupon']
|
||||||
|
styles.push nil
|
||||||
|
types.push :text
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Retrieve an item in the given array of items
|
# Retrieve an item in the given array of items
|
||||||
# by default, the "id" is expected to match the given parameter but
|
# by default, the "id" is expected to match the given parameter but
|
||||||
|
@ -9,5 +9,6 @@ module StatReservationConcern
|
|||||||
attribute :reservationContextId, Integer
|
attribute :reservationContextId, Integer
|
||||||
attribute :ca, Float
|
attribute :ca, Float
|
||||||
attribute :name, String
|
attribute :name, String
|
||||||
|
attribute :coupon, String
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -9,4 +9,8 @@ class StatisticIndex < ApplicationRecord
|
|||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def show_coupon?
|
||||||
|
es_type_key.in? %w[subscription machine training event space order]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -10,4 +10,5 @@ class Stats::Order
|
|||||||
attribute :products, Array
|
attribute :products, Array
|
||||||
attribute :categories, Array
|
attribute :categories, Array
|
||||||
attribute :ca, Float
|
attribute :ca, Float
|
||||||
|
attribute :coupon, String
|
||||||
end
|
end
|
||||||
|
@ -10,4 +10,5 @@ class Stats::Subscription
|
|||||||
attribute :subscriptionId, Integer
|
attribute :subscriptionId, Integer
|
||||||
attribute :invoiceItemId, Integer
|
attribute :invoiceItemId, Integer
|
||||||
attribute :groupName, String
|
attribute :groupName, String
|
||||||
|
attribute :coupon, String
|
||||||
end
|
end
|
||||||
|
@ -17,7 +17,7 @@ class Statistics::BuilderService
|
|||||||
private
|
private
|
||||||
|
|
||||||
def default_options
|
def default_options
|
||||||
yesterday = 1.day.ago
|
yesterday = Time.current
|
||||||
{
|
{
|
||||||
start_date: yesterday.beginning_of_day,
|
start_date: yesterday.beginning_of_day,
|
||||||
end_date: yesterday.end_of_day
|
end_date: yesterday.end_of_day
|
||||||
|
@ -18,7 +18,8 @@ class Statistics::Builders::ReservationsBuilderService
|
|||||||
ca: r[:ca],
|
ca: r[:ca],
|
||||||
name: r["#{category}_name".to_sym],
|
name: r["#{category}_name".to_sym],
|
||||||
reservationId: r[:reservation_id],
|
reservationId: r[:reservation_id],
|
||||||
reservationContextId: r[:reservation_context_id]
|
reservationContextId: r[:reservation_context_id],
|
||||||
|
coupon: r[:coupon]
|
||||||
}.merge(user_info_stat(r)))
|
}.merge(user_info_stat(r)))
|
||||||
stat[:stat] = (type == 'booking' ? 1 : r[:nb_hours])
|
stat[:stat] = (type == 'booking' ? 1 : r[:nb_hours])
|
||||||
stat["#{category}Id".to_sym] = r["#{category}_id".to_sym]
|
stat["#{category}Id".to_sym] = r["#{category}_id".to_sym]
|
||||||
|
@ -22,6 +22,7 @@ class Statistics::Builders::StoreOrdersBuilderService
|
|||||||
categories: o[:order_categories],
|
categories: o[:order_categories],
|
||||||
orderId: o[:order_id],
|
orderId: o[:order_id],
|
||||||
state: o[:order_state],
|
state: o[:order_state],
|
||||||
|
coupon: o[:coupon],
|
||||||
stat: 1 }.merge(user_info_stat(o)))
|
stat: 1 }.merge(user_info_stat(o)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -16,6 +16,7 @@ class Statistics::Builders::SubscriptionsBuilderService
|
|||||||
planId: s[:plan_id],
|
planId: s[:plan_id],
|
||||||
subscriptionId: s[:subscription_id],
|
subscriptionId: s[:subscription_id],
|
||||||
invoiceItemId: s[:invoice_item_id],
|
invoiceItemId: s[:invoice_item_id],
|
||||||
|
coupon: s[:coupon],
|
||||||
groupName: s[:plan_group_name] }.merge(user_info_stat(s)))
|
groupName: s[:plan_group_name] }.merge(user_info_stat(s)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -34,6 +34,7 @@ class Statistics::FetcherService
|
|||||||
duration: p.find_statistic_type.key,
|
duration: p.find_statistic_type.key,
|
||||||
subscription_id: sub.id,
|
subscription_id: sub.id,
|
||||||
invoice_item_id: i.id,
|
invoice_item_id: i.id,
|
||||||
|
coupon: i.invoice.coupon&.code,
|
||||||
ca: ca }.merge(user_info(profile)))
|
ca: ca }.merge(user_info(profile)))
|
||||||
end
|
end
|
||||||
result
|
result
|
||||||
@ -59,7 +60,8 @@ class Statistics::FetcherService
|
|||||||
slot_dates: r.slots.map(&:start_at).map(&:to_date),
|
slot_dates: r.slots.map(&:start_at).map(&:to_date),
|
||||||
nb_hours: (r.slots.map(&:duration).map(&:to_i).reduce(:+) / 3600.0).to_f,
|
nb_hours: (r.slots.map(&:duration).map(&:to_i).reduce(:+) / 3600.0).to_f,
|
||||||
ca: calcul_ca(r.original_invoice),
|
ca: calcul_ca(r.original_invoice),
|
||||||
reservation_context_id: r.reservation_context_id
|
reservation_context_id: r.reservation_context_id,
|
||||||
|
coupon: r.original_invoice.coupon&.code
|
||||||
}.merge(user_info(profile))
|
}.merge(user_info(profile))
|
||||||
yield result
|
yield result
|
||||||
end
|
end
|
||||||
@ -85,7 +87,8 @@ class Statistics::FetcherService
|
|||||||
slot_dates: r.slots.map(&:start_at).map(&:to_date),
|
slot_dates: r.slots.map(&:start_at).map(&:to_date),
|
||||||
nb_hours: (r.slots.map(&:duration).map(&:to_i).reduce(:+) / 3600.0).to_f,
|
nb_hours: (r.slots.map(&:duration).map(&:to_i).reduce(:+) / 3600.0).to_f,
|
||||||
ca: calcul_ca(r.original_invoice),
|
ca: calcul_ca(r.original_invoice),
|
||||||
reservation_context_id: r.reservation_context_id
|
reservation_context_id: r.reservation_context_id,
|
||||||
|
coupon: r.original_invoice.coupon&.code
|
||||||
}.merge(user_info(profile))
|
}.merge(user_info(profile))
|
||||||
yield result
|
yield result
|
||||||
end
|
end
|
||||||
@ -112,7 +115,8 @@ class Statistics::FetcherService
|
|||||||
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.original_invoice),
|
ca: calcul_ca(r.original_invoice),
|
||||||
reservation_context_id: r.reservation_context_id
|
reservation_context_id: r.reservation_context_id,
|
||||||
|
coupon: r.original_invoice&.coupon&.code
|
||||||
}.merge(user_info(profile))
|
}.merge(user_info(profile))
|
||||||
yield result
|
yield result
|
||||||
end
|
end
|
||||||
@ -128,6 +132,7 @@ class Statistics::FetcherService
|
|||||||
.eager_load(:slots, :slots_reservations, :invoice_items, statistic_profile: [:group])
|
.eager_load(:slots, :slots_reservations, :invoice_items, statistic_profile: [:group])
|
||||||
.find_each do |r|
|
.find_each do |r|
|
||||||
next unless r.reservable
|
next unless r.reservable
|
||||||
|
next unless r.original_invoice
|
||||||
|
|
||||||
profile = r.statistic_profile
|
profile = r.statistic_profile
|
||||||
slot = r.slots.first
|
slot = r.slots.first
|
||||||
@ -141,6 +146,7 @@ class Statistics::FetcherService
|
|||||||
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),
|
||||||
|
coupon: r.original_invoice.coupon&.code,
|
||||||
ca: calcul_ca(r.original_invoice) }.merge(user_info(profile))
|
ca: calcul_ca(r.original_invoice) }.merge(user_info(profile))
|
||||||
yield result
|
yield result
|
||||||
end
|
end
|
||||||
@ -215,7 +221,7 @@ class Statistics::FetcherService
|
|||||||
.where('order_activities.created_at >= :start_date AND order_activities.created_at <= :end_date', options)
|
.where('order_activities.created_at >= :start_date AND order_activities.created_at <= :end_date', options)
|
||||||
.group('orders.id')
|
.group('orders.id')
|
||||||
.find_each do |o|
|
.find_each do |o|
|
||||||
result = { date: o.created_at.to_date, ca: calcul_ca(o.invoice) }
|
result = { date: o.created_at.to_date, ca: calcul_ca(o.invoice), coupon: o.invoice.coupon&.code }
|
||||||
.merge(user_info(o.statistic_profile))
|
.merge(user_info(o.statistic_profile))
|
||||||
.merge(store_order_info(o))
|
.merge(store_order_info(o))
|
||||||
yield result
|
yield result
|
||||||
|
@ -28,6 +28,7 @@ wb.add_worksheet(name: ExcelService.name_safe(index.label)) do |sheet|
|
|||||||
end
|
end
|
||||||
columns.push t('export.reservation_context') if index.concerned_by_reservation_context?
|
columns.push t('export.reservation_context') if index.concerned_by_reservation_context?
|
||||||
columns.push t('export.revenue') if index.ca
|
columns.push t('export.revenue') if index.ca
|
||||||
|
columns.push t('export.coupon') if index.show_coupon?
|
||||||
|
|
||||||
sheet.add_row columns, style: header
|
sheet.add_row columns, style: header
|
||||||
|
|
||||||
@ -41,6 +42,7 @@ wb.add_worksheet(name: ExcelService.name_safe(index.label)) do |sheet|
|
|||||||
end
|
end
|
||||||
add_hardcoded_cells(index, hit, data, styles, types)
|
add_hardcoded_cells(index, hit, data, styles, types)
|
||||||
add_ca_cell(index, hit, data, styles, types)
|
add_ca_cell(index, hit, data, styles, types)
|
||||||
|
add_coupon_cell(index, hit, data, styles, types)
|
||||||
|
|
||||||
sheet.add_row data, style: styles, types: types
|
sheet.add_row data, style: styles, types: types
|
||||||
end
|
end
|
||||||
|
@ -20,6 +20,7 @@ indices.each do |index|
|
|||||||
end
|
end
|
||||||
columns.push t('export.reservation_context') if index.concerned_by_reservation_context?
|
columns.push t('export.reservation_context') if index.concerned_by_reservation_context?
|
||||||
columns.push t('export.revenue') if index.ca
|
columns.push t('export.revenue') if index.ca
|
||||||
|
columns.push t('export.coupon') if index.show_coupon?
|
||||||
sheet.add_row columns, style: header
|
sheet.add_row columns, style: header
|
||||||
|
|
||||||
# data rows
|
# data rows
|
||||||
@ -39,6 +40,7 @@ indices.each do |index|
|
|||||||
add_hardcoded_cells(index, hit, data, styles, types)
|
add_hardcoded_cells(index, hit, data, styles, types)
|
||||||
# proceed the 'ca' field if requested
|
# proceed the 'ca' field if requested
|
||||||
add_ca_cell(index, hit, data, styles, types)
|
add_ca_cell(index, hit, data, styles, types)
|
||||||
|
add_coupon_cell(index, hit, data, styles, types)
|
||||||
|
|
||||||
# finally, add the data row to the workbook's sheet
|
# finally, add the data row to the workbook's sheet
|
||||||
sheet.add_row data, style: styles, types: types
|
sheet.add_row data, style: styles, types: types
|
||||||
|
@ -506,6 +506,7 @@ en:
|
|||||||
female: "Woman"
|
female: "Woman"
|
||||||
deleted_user: "Deleted user"
|
deleted_user: "Deleted user"
|
||||||
reservation_context: "Reservation context"
|
reservation_context: "Reservation context"
|
||||||
|
coupon: "Coupon"
|
||||||
#initial price's category for events, created to replace the old "reduced amount" property
|
#initial price's category for events, created to replace the old "reduced amount" property
|
||||||
price_category:
|
price_category:
|
||||||
reduced_fare: "Reduced fare"
|
reduced_fare: "Reduced fare"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user