Class: Trackers::InventoryService
- Inherits:
-
Object
- Object
- Trackers::InventoryService
- Defined in:
- app/services/partner_service/trackers/inventory_service.rb
Overview
The InventoryService class provides methods to track inventory updates and allotment blocks for a specific restaurant. It helps capture changes in seating availability and blocked allotments.
Instance Attribute Summary collapse
-
#changes ⇒ Object
Returns the value of attribute changes.
-
#footer_text ⇒ Object
Returns the value of attribute footer_text.
-
#navigation ⇒ Object
Returns the value of attribute navigation.
Instance Method Summary collapse
-
#track_block_inventory(valid_params, _restaurant_id) ⇒ void
Tracks allotment blocks, capturing the reason and the blocked date-time range.
-
#track_update_inventory(params, restaurant_id) ⇒ void
Tracks changes in the inventory, including seating availability updates within a specified date-time range.
Instance Attribute Details
#changes ⇒ Object
Returns the value of attribute changes.
5 6 7 |
# File 'app/services/partner_service/trackers/inventory_service.rb', line 5 def changes @changes end |
#footer_text ⇒ Object
Returns the value of attribute footer_text.
5 6 7 |
# File 'app/services/partner_service/trackers/inventory_service.rb', line 5 def @footer_text end |
#navigation ⇒ Object
Returns the value of attribute navigation.
5 6 7 |
# File 'app/services/partner_service/trackers/inventory_service.rb', line 5 def @navigation end |
Instance Method Details
#track_block_inventory(valid_params, _restaurant_id) ⇒ void
This method returns an undefined value.
Tracks allotment blocks, capturing the reason and the blocked date-time range.
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/services/partner_service/trackers/inventory_service.rb', line 72 def track_block_inventory(valid_params, _restaurant_id) blocked_datetime = "#{valid_params[:start_date].to_date.strftime('%d %b %Y')}, #{valid_params[:start_time].to_datetime.strftime('%H:%M')} - #{valid_params[:end_date].to_date.strftime('%d %b %Y')}, #{valid_params[:end_time].to_datetime.strftime('%H:%M')}" @navigation = 'allotment' @footer_text = Time.zone.now.strftime('%d %B %Y, %H:%M') @changes = { inv: { type: 'block_inv', label: 'Allotment has been blocked', blocked_reason: valid_params[:reason], blocked_datetime: blocked_datetime, }, } end |
#track_update_inventory(params, restaurant_id) ⇒ void
This method returns an undefined value.
Tracks changes in the inventory, including seating availability updates within a specified date-time range.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/services/partner_service/trackers/inventory_service.rb', line 12 def track_update_inventory(params, restaurant_id) start_date = params[:inventory][:start_date] end_date = params[:inventory][:end_date] start_time = params[:inventory][:start_time] end_time = params[:inventory][:end_time] # Parse the date and time to create a DateTime range start_datetime = DateTime.parse("#{start_date} #{start_time}") end_datetime = DateTime.parse("#{end_date} #{end_time}") # Fetch inventory records within the specified date and time range records = Inventory.where(restaurant_id: restaurant_id). where(date: start_date..end_date). where('start_time >= ? AND end_time <= ?', start_datetime, end_datetime) if records.blank? @navigation = 'allotment' @footer_text = Time.zone.now.strftime('%d %B %Y, %H:%M') @changes = { inv: { type: 'update_inv', label: 'Seat Has been changed', from_datetime: start_datetime.strftime('%d %b %Y, %H:%M'), to_datetime: end_datetime.strftime('%d %b %Y, %H:%M'), seats_from: 0, seats_to: params[:inventory][:quantity_available], }, } return end # Find the minimum date with its start_time and maximum date with its end_time min_record = records.order(:date, :start_time).first max_record = records.order(date: :desc, end_time: :desc).first return if min_record.quantity_available == params[:inventory][:quantity_available].to_i # Combine date and time fields to get from_datetime and to_datetime from_datetime = "#{min_record.date.strftime('%d %b %Y')}, #{min_record.start_time.strftime('%H:%M')}" if min_record to_datetime = "#{max_record.date.strftime('%d %b %Y')}, #{max_record.end_time.strftime('%H:%M')}" if max_record @navigation = 'allotment' @footer_text = Time.zone.now.strftime('%d %B %Y, %H:%M') @changes = { inv: { type: 'update_inv', label: 'Seat Has been changed', from_datetime: from_datetime, to_datetime: to_datetime, seats_from: min_record.quantity_available, seats_to: params[:inventory][:quantity_available], }, } end |