Module: InventoryTrait

Extended by:
ActiveSupport::Concern
Included in:
Inventory, InventoryBistrochat, InventoryMyMenu, InventorySevenRooms, InventoryTablecheck, InventoryTakeAway
Defined in:
app/models/concerns/inventory_trait.rb

Constant Summary collapse

QUANTITY_AVAILABLE_DEFAULT =
1000

Instance Method Summary collapse

Instance Method Details

#calc_total_booked_seatObject



51
52
53
# File 'app/models/concerns/inventory_trait.rb', line 51

def calc_total_booked_seat
  self.total_booked_seat = inventory_reservations.where(inventory_type: self.class).sum(:booked_seat)
end

#date_formatObject



79
80
81
# File 'app/models/concerns/inventory_trait.rb', line 79

def date_format
  date.strftime('%m/%d/%Y') if date.present?
end

#date_format_extObject



83
84
85
# File 'app/models/concerns/inventory_trait.rb', line 83

def date_format_ext
  date.strftime("#{date.day.ordinalize} %B %Y") if date.present? # 20th December 2013
end

#end_time_formatObject



71
72
73
# File 'app/models/concerns/inventory_trait.rb', line 71

def end_time_format
  end_time.strftime('%H:%M') if end_time.present?
end

#end_time_sqlObject



75
76
77
# File 'app/models/concerns/inventory_trait.rb', line 75

def end_time_sql
  end_time.strftime('%H:%M:00') if end_time.present?
end

#log_and_update_attributes(attributes) ⇒ Object



87
88
89
90
91
92
93
# File 'app/models/concerns/inventory_trait.rb', line 87

def log_and_update_attributes(attributes)
  if update(attributes)
    UpdatedInventory.dup_inventory(self)
  else
    false
  end
end

#overbooked?Boolean

Returns:

  • (Boolean)


45
46
47
48
49
# File 'app/models/concerns/inventory_trait.rb', line 45

def overbooked?
  return false if total_booked_seat.nil? || quantity_available.nil?

  total_booked_seat > quantity_available
end

#seat_leftObject



55
56
57
# File 'app/models/concerns/inventory_trait.rb', line 55

def seat_left
  quantity_available - total_booked_seat
end

#start_time_formatObject



63
64
65
# File 'app/models/concerns/inventory_trait.rb', line 63

def start_time_format
  start_time.strftime('%H:%M') if start_time.present?
end

#start_time_hourObject



59
60
61
# File 'app/models/concerns/inventory_trait.rb', line 59

def start_time_hour
  start_time.strftime('%H').to_i
end

#start_time_sqlObject



67
68
69
# File 'app/models/concerns/inventory_trait.rb', line 67

def start_time_sql
  start_time.strftime('%H:%M:00') if start_time.present?
end