if @zones
  json.array! @zones do |zone|
    if zone.is_active
      json.id zone.id
      json.name zone.name
      #List all tables
      json.tables zone.tables do |table|
        if table.is_active
          current_booking = table.get_current_booking
          json.id table.id
          json.name table.name
          json.status table.status
          json.zone_id table.zone_id #Add this zone_id to keep data structure consistance
          if !current_booking.nil?
            json.current_booking current_booking.booking_id
            json.checkin_at Time.parse(current_booking.checkin_at.strftime("%Y-%m-%d %H:%M:%S")).utc.getlocal.strftime("%Y-%m-%d %H:%M:%S")
            json.checkout_at current_booking.checkout_at ? Time.parse(current_booking.checkout_at.strftime("%Y-%m-%d %H:%M:%S")).utc.getlocal.strftime("%Y-%m-%d %H:%M:%S") : ""
          else
            json.current_booking ""
            json.checkin_at ""
            json.checkout_at ""
          end
        end
      end

      json.rooms zone.rooms do |room|
        if room.is_active
          current_booking = room.get_current_booking
          json.id room.id
          json.name room.name
          json.status room.status
          json.zone_id room.zone_id #Add this zone_id to keep data structure consistance
          if !current_booking.nil?
            json.current_booking current_booking.booking_id
            json.checkin_at Time.parse(current_booking.checkin_at.strftime("%Y-%m-%d %H:%M:%S")).utc.getlocal.strftime("%Y-%m-%d %H:%M:%S")
            json.checkout_at current_booking.checkout_at ? Time.parse(current_booking.checkout_at.strftime("%Y-%m-%d %H:%M:%S")).utc.getlocal.strftime("%Y-%m-%d %H:%M:%S") : ""
          else
            json.current_booking ""
            json.checkin_at ""
            json.checkout_at ""
          end
        end
      end
    end
  end
else #list all tables and rooms with out zones
  json.tables @all_tables do |table|
    if table.is_active
      current_booking = table.get_current_booking
      json.id table.id
      json.name table.name
      json.status table.status
      json.zone_id table.zone_id #Add this zone_id to keep data structure consistance
      if !current_booking.nil?
        json.current_booking current_booking.booking_id
        json.checkin_at Time.parse(current_booking.checkin_at.strftime("%Y-%m-%d %H:%M:%S")).utc.getlocal.strftime("%Y-%m-%d %H:%M:%S")
        json.checkout_at current_booking.checkout_at ? Time.parse(current_booking.checkout_at.strftime("%Y-%m-%d %H:%M:%S")).utc.getlocal.strftime("%Y-%m-%d %H:%M:%S") : ""
      else
        json.current_booking ""
        json.checkin_at ""
        json.checkout_at ""
      end
    end
  end

  json.rooms @all_rooms do |room|
    if room.is_active
      current_booking = room.get_current_booking
      json.id room.id
      json.name room.name
      json.status room.status
      json.zone_id room.zone_id #Add this zone_id to keep data structure consistance
      if !current_booking.nil?
        json.current_booking current_booking.booking_id
        json.checkin_at Time.parse(current_booking.checkin_at.strftime("%Y-%m-%d %H:%M:%S")).utc.getlocal.strftime("%Y-%m-%d %H:%M:%S")
        json.checkout_at current_booking.checkout_at ? Time.parse(current_booking.checkout_at.strftime("%Y-%m-%d %H:%M:%S")).utc.getlocal.strftime("%Y-%m-%d %H:%M:%S") : ""
      else
        json.current_booking ""
        json.checkin_at ""
        json.checkout_at ""
      end
    end
  end
end
