mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
ability to limit extended prices to slots in the same day
This commit is contained in:
parent
2d807e6c94
commit
ffb0f3e19e
@ -2,6 +2,7 @@
|
||||
|
||||
- Updated portuguese translation
|
||||
- Refactored the ReserveButton component to use the same user's data across all the component
|
||||
- [TODO DEPLOY] `rails db:seed`
|
||||
|
||||
## v5.1.13 2021 November 16
|
||||
|
||||
|
@ -111,7 +111,8 @@ export enum SettingName {
|
||||
PublicAgendaModule = 'public_agenda_module',
|
||||
RenewPackThreshold = 'renew_pack_threshold',
|
||||
PackOnlyForSubscription = 'pack_only_for_subscription',
|
||||
OverlappingCategories = 'overlapping_categories'
|
||||
OverlappingCategories = 'overlapping_categories',
|
||||
ExtendedPricesInSameDay = 'extended_prices_in_same_day'
|
||||
}
|
||||
|
||||
export type SettingValue = string|boolean|number;
|
||||
|
@ -1080,7 +1080,7 @@ angular.module('application.router', ['ui.router'])
|
||||
"'reminder_delay', 'visibility_yearly', 'visibility_others', 'wallet_module', 'trainings_module', " +
|
||||
"'display_name_enable', 'machines_sort_by', 'fab_analytics', 'statistics_module', 'address_required', " +
|
||||
"'link_name', 'home_content', 'home_css', 'phone_required', 'upcoming_events_shown', 'public_agenda_module'," +
|
||||
"'renew_pack_threshold', 'pack_only_for_subscription', 'overlapping_categories']"
|
||||
"'renew_pack_threshold', 'pack_only_for_subscription', 'overlapping_categories', 'extended_prices_in_same_day']"
|
||||
}).$promise;
|
||||
}],
|
||||
privacyDraftsPromise: ['Setting', function (Setting) { return Setting.get({ name: 'privacy_draft', history: true }).$promise; }],
|
||||
|
@ -117,6 +117,28 @@
|
||||
required="true">
|
||||
</number-setting>
|
||||
</div>
|
||||
|
||||
<div class="section-separator"></div>
|
||||
<div class="row">
|
||||
<h3 class="m-l" translate>{{ 'app.admin.settings.pack_only_for_subscription_info' }}</h3>
|
||||
<p class="alert alert-warning m-h-md" ng-bind-html="'app.admin.settings.pack_only_for_subscription_info_html' | translate"></p>
|
||||
<boolean-setting name="pack_only_for_subscription"
|
||||
settings="allSettings"
|
||||
label="app.admin.settings.pack_only_for_subscription"
|
||||
classes="m-l">
|
||||
</boolean-setting>
|
||||
</div>
|
||||
|
||||
<div class="section-separator"></div>
|
||||
<div class="row">
|
||||
<h3 class="m-l" translate>{{ 'app.admin.settings.extended_prices' }}</h3>
|
||||
<p class="alert alert-warning m-h-md" ng-bind-html="'app.admin.settings.extended_prices_info_html' | translate"></p>
|
||||
<boolean-setting name="extended_prices_in_same_day"
|
||||
settings="allSettings"
|
||||
label="app.admin.settings.extended_prices_in_same_day"
|
||||
classes="m-l">
|
||||
</boolean-setting>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -170,6 +192,8 @@
|
||||
label="app.admin.settings.show_event"
|
||||
classes="m-l"></boolean-setting>
|
||||
</div>
|
||||
|
||||
<div class="section-separator"></div>
|
||||
<div class="row">
|
||||
<h3 class="m-l" translate>{{ 'app.admin.settings.display_invite_to_renew_pack' }}</h3>
|
||||
<p class="alert alert-warning m-h-md" ng-bind-html="'app.admin.settings.packs_threshold_info_html' | translate"></p>
|
||||
@ -182,14 +206,5 @@
|
||||
step="0.01">
|
||||
</number-setting>
|
||||
</div>
|
||||
<div class="row">
|
||||
<h3 class="m-l" translate>{{ 'app.admin.settings.pack_only_for_subscription_info' }}</h3>
|
||||
<p class="alert alert-warning m-h-md" ng-bind-html="'app.admin.settings.pack_only_for_subscription_info_html' | translate"></p>
|
||||
<boolean-setting name="pack_only_for_subscription"
|
||||
settings="allSettings"
|
||||
label="app.admin.settings.pack_only_for_subscription"
|
||||
classes="m-l">
|
||||
</boolean-setting>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -18,13 +18,14 @@ class CartItem::Reservation < CartItem::BaseItem
|
||||
def price
|
||||
is_privileged = @operator.privileged? && @operator.id != @customer.id
|
||||
prepaid = { minutes: PrepaidPackService.minutes_available(@customer, @reservable) }
|
||||
prices = applicable_prices
|
||||
|
||||
elements = { slots: [] }
|
||||
amount = 0
|
||||
|
||||
hours_available = credits
|
||||
@slots.each_with_index do |slot, index|
|
||||
amount += get_slot_price_from_prices(applicable_prices, slot, is_privileged,
|
||||
amount += get_slot_price_from_prices(prices, slot, is_privileged,
|
||||
elements: elements,
|
||||
has_credits: (index < hours_available),
|
||||
prepaid: prepaid)
|
||||
@ -129,6 +130,8 @@ class CartItem::Reservation < CartItem::BaseItem
|
||||
# and the base price (1 hours), we use the 7 hours price, then 3 hours price, and finally the base price twice (7+3+1+1 = 12).
|
||||
# All these prices are returned to be applied to the reservation.
|
||||
def applicable_prices
|
||||
all_slots_in_same_day = @slots.map { |slot| slot[:start_at].to_date }.uniq.size == 1
|
||||
|
||||
total_duration = @slots.map { |slot| (slot[:end_at].to_time - slot[:start_at].to_time) / SECONDS_PER_MINUTE }.reduce(:+)
|
||||
rates = { prices: [] }
|
||||
|
||||
@ -137,7 +140,7 @@ class CartItem::Reservation < CartItem::BaseItem
|
||||
max_duration = @reservable.prices.where(group_id: @customer.group_id, plan_id: @plan.try(:id))
|
||||
.where(Price.arel_table[:duration].lteq(remaining_duration))
|
||||
.maximum(:duration)
|
||||
max_duration = 60 if max_duration.nil?
|
||||
max_duration = 60 if max_duration.nil? || Setting.get('extended_prices_in_same_day') && !all_slots_in_same_day
|
||||
max_duration_price = @reservable.prices.find_by(group_id: @customer.group_id, plan_id: @plan.try(:id), duration: max_duration)
|
||||
|
||||
current_duration = [remaining_duration, max_duration].min
|
||||
|
@ -121,7 +121,8 @@ class Setting < ApplicationRecord
|
||||
public_agenda_module
|
||||
renew_pack_threshold
|
||||
pack_only_for_subscription
|
||||
overlapping_categories] }
|
||||
overlapping_categories
|
||||
extended_prices_in_same_day] }
|
||||
# WARNING: when adding a new key, you may also want to add it in:
|
||||
# - config/locales/en.yml#settings
|
||||
# - app/frontend/src/javascript/models/setting.ts#SettingName
|
||||
|
@ -1235,6 +1235,9 @@ en:
|
||||
pack_only_for_subscription_info_html: "If this option is activated, the purchase and use of a prepaid pack is only possible for the user with a valid subscription."
|
||||
pack_only_for_subscription: "Subscription valid for purchase and use of a prepaid pack"
|
||||
pack_only_for_subscription_info: "Make subscription mandatory for prepaid packs"
|
||||
extended_prices: "Extended prices"
|
||||
extended_prices_info_html: "Spaces can have different prices depending on the cumulated duration of the booking. You can choose if this apply to all bookings or only to those starting within the same day."
|
||||
extended_prices_in_same_day: "Extended prices in the same day"
|
||||
overlapping_options:
|
||||
training_reservations: "Trainings"
|
||||
machine_reservations: "Machines"
|
||||
|
@ -535,3 +535,4 @@ en:
|
||||
renew_pack_threshold: "Threshold for packs renewal"
|
||||
pack_only_for_subscription: "Restrict packs for subscribers"
|
||||
overlapping_categories: "Categories for overlapping booking prevention"
|
||||
extended_prices_in_same_day: "Extended prices in the same day"
|
||||
|
@ -905,6 +905,8 @@ unless Setting.find_by(name: 'overlapping_categories').try(:value)
|
||||
Setting.set('overlapping_categories', 'training_reservations,machine_reservations,space_reservations,events_reservations')
|
||||
end
|
||||
|
||||
Setting.set('extended_prices_in_same_day', true) unless Setting.find_by(name: 'extended_prices_in_same_day').try(:value)
|
||||
|
||||
if StatisticCustomAggregation.count.zero?
|
||||
# available reservations hours for machines
|
||||
machine_hours = StatisticType.find_by(key: 'hour', statistic_index_id: 2)
|
||||
|
Loading…
x
Reference in New Issue
Block a user