listOfTablesFromLayouts(); if (empty($tables)) { return []; } // Tengo que preparar el listado como [ table-1 => [..], table-2 => [], ...] $listTables = []; foreach($tables as $table) { unset($table['canvas']); $table['mode'] = 'single'; $table['booking_id'] = null; $listTables['table-'.$table['id']] = $table; } $listTables = $this->fillTablesWithBookings($listTables, $date_string, $time, $guests, $exclude_booking_id); //ray($listTables); // Tables free $listTablesFree = []; $check_tables_allowed_guests = true; foreach ($listTables as $key => $table) { // Solo ni no tiene reserva if ($table['booking_id'] === null) { if (!$check_tables_allowed_guests) { $listTablesFree[$key] = $table; } else if ($guests >= $table['min_seats'] && $guests <= $table['max_seats']) { $listTablesFree[$key] = $table; } } } if ($return_all_free_tables) { return $listTablesFree; } // Busco la mejor mesa if (!empty($listTablesFree)) { return [ $this->selectBestSingleTable($listTablesFree, $guests) ]; } return $listTablesFree; } public function getLayouts() { $layouts_id = $this->custom_layouts; if ( ! is_array( $layouts_id ) ) { return []; } $layouts = []; foreach ( $layouts_id as $layout_id ) { $layouts[] = Layout::find( $layout_id )->toArray(); } return $layouts; } public function listOfTablesFromLayouts() { $layouts_id = $this->custom_layouts; if ( ! is_array( $layouts_id ) ) { return []; } $tables = []; foreach ( $layouts_id as $layout_id ) { $layout = Layout::find( $layout_id ); if ($layout && $layout->tables) { $tables = array_merge( $tables, $layout->tables ); } } return $tables; } public function getLayoutsWithTablesFreeAndPricing($date_string, $time, $guests) { // Obtener el layout con el config de los hotspots // Extraer los hotspots // Asignar a cada hotspot los datos de la mesa y que lleve las etiquetas // Calcular el precio de la mesa con base en los tags // Indicar las mesas libres $layouts_id = $this->custom_layouts; if ( ! is_array( $layouts_id ) ) { return []; } $free_tables = $this->isAvailableByTablesFromLayouts($date_string, $time, $guests, null, true); //ray($free_tables); $restaurant = $this->restaurant; $currency = strtolower($restaurant->currency); $currency_symbol = \Alexr\Enums\CurrencyType::symbolFor($restaurant->currency); $layouts = []; foreach ( $layouts_id as $layout_id ) { $layout_model = Layout::find( $layout_id ); $pricing = $layout_model->pricing; $hotspots = $layout_model->hotspots; $hotspots_rich = []; foreach($hotspots as $hotspot) { $table = Table::find($hotspot['id']); if ($table){ $table_arr = $table->toArray(); unset($table_arr['canvas']); $hotspot['table'] = $table_arr; $hotspot['area'] = $table->area->toArray(); $hotspot['name'] = $table->name; $hotspot['price'] = $this->calculatePriceForTable($table_arr, $pricing); $key = 'table-'.$hotspot['id']; $hotspot['free'] = isset($free_tables[$key]) ? true : false; $hotspot['currency'] = $currency; $hotspot['currency_symbol'] = $currency_symbol; $hotspots_rich[] = $hotspot; } } $layout = [ 'name' => $layout_model->name, 'description' => $layout_model->description, 'image' => $layout_model->image, 'uploaded_image' => $layout_model->uploaded_image, 'config' => $layout_model->config, 'hotspots' => $hotspots_rich, 'pricing' => $pricing, ]; $layouts[] = $layout; } //ray($layouts); return $layouts; } public function calculatePriceForTable($table, $pricing) { $tagsList = $table['tagsList']; $price = 0; // Calculate price based on tags foreach ($tagsList as $tag) { if (isset($pricing[$tag])) { $price += (float) $pricing[$tag]; } } return $price; } }