Module: SpreeCmCommissioner::Admin::InventoryLocksHelper

Defined in:
app/helpers/spree_cm_commissioner/admin/inventory_locks_helper.rb

Instance Method Summary collapse

Instance Method Details

#availability_percentage_badge_class(percentage) ⇒ Object

High/medium/low as risk of running out of public stock, not as a grade — a bare number in a dense table doesn't say whether 22% is fine or a problem, so the color carries that instead. Reuses the badge-success/warning/danger classes already styled for this admin (see gems/spree_backend's _badges.scss) rather than introducing new color tokens.



31
32
33
34
35
36
# File 'app/helpers/spree_cm_commissioner/admin/inventory_locks_helper.rb', line 31

def availability_percentage_badge_class(percentage)
  return 'badge-danger' if percentage <= 20
  return 'badge-warning' if percentage <= 50

  'badge-success'
end

#available_capacity_percentage(inventory_item) ⇒ Object

Share of this date's capacity still on public sale.

max_capacity is the right denominator because MoveToLocked only ever moves units BETWEEN quantity_available and quantity_locked — it never touches max_capacity — so this figure falls by exactly what an operator withholds.

nil when there is nothing to divide by, so the caller renders a dash instead of a 0% that would read as "sold out" on a date that simply has no stock configured.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/helpers/spree_cm_commissioner/admin/inventory_locks_helper.rb', line 12

def available_capacity_percentage(inventory_item)
  return nil if inventory_item.nil?

  capacity = inventory_item.max_capacity.to_i
  return nil if capacity.zero?

  percentage = inventory_item.quantity_available.to_f / capacity * 100
  return percentage.round if percentage <= 0 || percentage >= 1

  # A few seats left out of a large capacity is a fraction of a percent but is NOT sold out;
  # rounding it whole would print 0% and read as exactly that. Two decimals, floored at 0.01 so
  # capacities past 10k still show something non-zero.
  [percentage.round(2), 0.01].max
end