diff --git a/app/admin/models/Reservations_model.php b/app/admin/models/Reservations_model.php index ea7e6079de..9959b41810 100644 --- a/app/admin/models/Reservations_model.php +++ b/app/admin/models/Reservations_model.php @@ -64,6 +64,7 @@ class Reservations_model extends Model public $relation = [ 'belongsTo' => [ + 'customer' => 'Admin\Models\Customers_model', 'related_table' => ['Admin\Models\Tables_model', 'foreignKey' => 'table_id'], 'location' => 'Admin\Models\Locations_model', ], @@ -100,6 +101,10 @@ protected function afterSave() if (array_key_exists('tables', $this->attributes)) { $this->addReservationTables((array)$this->attributes['tables']); } + + if ($this->location->getOption('auto_allocate_table', 1) && !$this->tables()->count()) { + $this->addReservationTables($this->getNextBookableTable()->pluck('table_id')->all()); + } } // @@ -395,6 +400,34 @@ public function addReservationTables(array $tableIds = []) $this->tables()->sync($tableIds); } + /** + * @return \Illuminate\Support\Collection|null + */ + public function getNextBookableTable() + { + $tables = $this->location->tables->where('table_status', 1); + + $reserved = static::findReservedTables($this->location, $this->reservation_datetime); + + $tables = $tables->diff($reserved)->sortBy('priority'); + + $result = collect(); + $unseatedGuests = $this->guest_num; + foreach ($tables as $table) { + if ($table->min_capacity <= $this->guest_num && $table->max_capacity >= $this->guest_num) + return collect([$table]); + + if ($table->is_joinable && $unseatedGuests >= $table->min_capacity) { + $result->push($table); + $unseatedGuests -= $table->max_capacity; + if ($unseatedGuests <= 0) + break; + } + } + + return $unseatedGuests > 0 ? collect() : $result; + } + // // Mail // diff --git a/app/admin/models/config/menus_model.php b/app/admin/models/config/menus_model.php index 7936832a42..7fdc5bfb5d 100644 --- a/app/admin/models/config/menus_model.php +++ b/app/admin/models/config/menus_model.php @@ -261,7 +261,7 @@ 'modelClass' => 'Admin\Models\Menu_options_model', 'placeholder' => 'lang:admin::lang.menus.help_menu_option', 'formName' => 'lang:admin::lang.menu_options.text_option', - 'popupSize' => 'modal-lg', + 'popupSize' => 'modal-xl', 'addonRight' => [ 'label' => ' Add to Menu', 'tag' => 'button',