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
- #calc_total_booked_seat ⇒ Object
- #date_format ⇒ Object
- #date_format_ext ⇒ Object
- #end_time_format ⇒ Object
- #end_time_sql ⇒ Object
- #log_and_update_attributes(attributes) ⇒ Object
- #overbooked? ⇒ Boolean
- #seat_left ⇒ Object
- #start_time_format ⇒ Object
- #start_time_hour ⇒ Object
- #start_time_sql ⇒ Object
Instance Method Details
#calc_total_booked_seat ⇒ Object
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_format ⇒ Object
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_ext ⇒ Object
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_format ⇒ Object
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_sql ⇒ Object
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
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_left ⇒ Object
55 56 57 |
# File 'app/models/concerns/inventory_trait.rb', line 55 def seat_left quantity_available - total_booked_seat end |
#start_time_format ⇒ Object
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_hour ⇒ Object
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_sql ⇒ Object
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 |