Skip to content

Commit

Permalink
Merge branch '3.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
sampoyigi committed Jun 30, 2022
2 parents 3b95b83 + 5e84a71 commit ee29b34
Show file tree
Hide file tree
Showing 20 changed files with 340 additions and 51 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/split.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
with:
branch: ${GITHUB_REF#refs/heads/}

package-directory: 'app/${{ matrix.package.path }}'
split-repository-organization: 'tastyigniter'
split-repository-name: '${{ matrix.package.repository }}'
Expand Down
4 changes: 4 additions & 0 deletions app/admin/actions/ListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ public function makeList($alias)
$this->controller->listExtendQuery($query, $alias);
});

$widget->bindEvent('list.extendRecords', function ($records) use ($alias) {
return $this->controller->listExtendRecords($records, $alias);
});

$widget->bindEvent('list.overrideColumnValue', function ($record, $column, $value) use ($alias) {
return $this->controller->listOverrideColumnValue($record, $column, $alias);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,25 @@ public function up()
{
Schema::disableForeignKeyConstraints();

foreach ($this->getForeignConstraints() as $tableName => $constraints) {
foreach ($constraints as $options) {
$this->addForeignKey($tableName, $options);
}
}
// Commented out so foreign keys are not added on new installations.
// For existing installations, another migration has been added to drop all foreign keys.

// foreach ($this->getForeignConstraints() as $tableName => $constraints) {
// foreach ($constraints as $options) {
// $this->addForeignKey($tableName, $options);
// }
// }

Schema::enableForeignKeyConstraints();
}

public function down()
{
foreach ($this->getForeignConstraints() as $tableName => $constraints) {
foreach ($constraints as $options) {
$this->dropForeignKey($tableName, $options);
}
}
// foreach ($this->getForeignConstraints() as $tableName => $constraints) {
// foreach ($constraints as $options) {
// $this->dropForeignKey($tableName, $options);
// }
// }
}

protected function addForeignKey($tableName, $options)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?php

namespace Admin\Database\Migrations;

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Schema;

class DropForeignKeyConstraintsOnAllTables extends Migration
{
public function up()
{
Schema::disableForeignKeyConstraints();

foreach ($this->getForeignConstraints() as $tableName => $constraints) {
foreach ($constraints as $options) {
$this->dropForeignKey($tableName, $options);
}
}

Schema::enableForeignKeyConstraints();
}

public function down()
{
}

protected function dropForeignKey($tableName, $options)
{
try {
Schema::table($tableName, function (Blueprint $table) use ($tableName, $options) {
$keys = (array)$options[1];
$foreignKey = $keys[0];

$table->dropForeign([$foreignKey]);
$table->dropIndex(sprintf('%s%s_%s_foreign', DB::getTablePrefix(), $tableName, $foreignKey));
});
}
catch (\Exception $ex) {
Log::error($ex);
}
}

protected function getForeignConstraints(): array
{
return [
'addresses' => [
['customers', 'customer_id', 'nullOnDelete' => true],
['countries', 'country_id', 'nullOnDelete' => true],
],
'allergenables' => [
['allergens', 'allergen_id', 'nullable' => false, 'cascadeOnDelete' => true],
],
'assignable_logs' => [
['staffs', ['assignee_id', 'staff_id'], 'nullable' => false, 'nullOnDelete' => true],
['staff_groups', ['assignee_group_id', 'staff_group_id'], 'nullable' => false, 'nullOnDelete' => true],
['statuses', ['status_id', 'status_id'], 'nullable' => false, 'nullOnDelete' => true],
],
'categories' => [
['categories', ['parent_id', 'category_id'], 'nullOnDelete' => true],
],
'customers' => [
['addresses', 'address_id', 'nullOnDelete' => true],
['customer_groups', 'customer_group_id', 'nullOnDelete' => true],
],
'location_areas' => [
['locations', 'location_id', 'nullable' => false, 'cascadeOnDelete' => true],
],
'locationables' => [
['locations', 'location_id', 'nullable' => false, 'cascadeOnDelete' => true],
],
'locations' => [
['countries', ['location_country_id', 'country_id'], 'cascadeOnDelete' => true],
],
'menu_categories' => [
['menus', 'menu_id', 'nullable' => false, 'cascadeOnDelete' => true],
['categories', 'category_id', 'nullable' => false, 'cascadeOnDelete' => true],
],
'menu_item_option_values' => [
['menu_item_options', 'menu_option_id', 'nullable' => false, 'cascadeOnDelete' => true],
['menu_option_values', 'option_value_id', 'nullable' => false, 'cascadeOnDelete' => true],
],
'menu_item_options' => [
['menus', 'menu_id', 'nullable' => false, 'cascadeOnDelete' => true],
['menu_options', 'option_id', 'nullable' => false, 'cascadeOnDelete' => true],
],
'menu_mealtimes' => [
['menus', 'menu_id', 'nullable' => false, 'cascadeOnDelete' => true],
['mealtimes', 'mealtime_id', 'nullable' => false, 'cascadeOnDelete' => true],
],
'menu_option_values' => [
['menu_options', 'option_id', 'nullable' => false, 'cascadeOnDelete' => true],
],
'menus_specials' => [
['menus', 'menu_id', 'cascadeOnDelete' => true],
],
'order_menu_options' => [
['orders', 'order_id', 'nullable' => false, 'cascadeOnDelete' => true],
['order_menus', 'order_menu_id', 'nullable' => false, 'cascadeOnDelete' => true],
],
'order_menus' => [
['orders', 'order_id', 'nullable' => false, 'cascadeOnDelete' => true],
['menus', 'menu_id', 'nullable' => false, 'cascadeOnDelete' => true],
],
'order_totals' => [
['orders', 'order_id', 'nullable' => false, 'cascadeOnDelete' => true],
],
'orders' => [
['customers', 'customer_id', 'nullOnDelete' => true],
['locations', 'location_id', 'nullOnDelete' => true],
['addresses', 'address_id', 'nullOnDelete' => true],
['statuses', 'status_id', 'nullOnDelete' => true],
['staffs', ['assignee_id', 'staff_id'], 'nullOnDelete' => true],
['staff_groups', ['assignee_group_id', 'staff_group_id'], 'nullOnDelete' => true],
],
'payment_logs' => [
['orders', 'order_id', 'nullable' => false, 'cascadeOnDelete' => true],
],
'payment_profiles' => [
['customers', 'customer_id', 'cascadeOnDelete' => true],
['payments', 'payment_id', 'cascadeOnDelete' => true],
],
'reservation_tables' => [
['reservations', 'reservation_id', 'nullable' => false, 'cascadeOnDelete' => true],
['tables', 'table_id', 'nullable' => false, 'cascadeOnDelete' => true],
],
'reservations' => [
['tables', 'table_id', 'nullOnDelete' => true],
['customers', 'customer_id', 'nullOnDelete' => true],
['locations', 'location_id', 'nullOnDelete' => true],
['statuses', 'status_id', 'nullOnDelete' => true],
['staffs', ['assignee_id', 'staff_id'], 'nullOnDelete' => true],
['staff_groups', ['assignee_group_id', 'staff_group_id'], 'nullOnDelete' => true],
],
'staffs' => [
['staff_roles', 'staff_role_id', 'nullOnDelete' => true],
['languages', 'language_id', 'nullOnDelete' => true],
],
'staffs_groups' => [
['staffs', 'staff_id', 'nullable' => false, 'cascadeOnDelete' => true],
['staff_groups', 'staff_group_id', 'nullable' => false, 'cascadeOnDelete' => true],
],
'status_history' => [
['staffs', 'staff_id', 'nullOnDelete' => true],
['statuses', 'status_id', 'nullOnDelete' => true],
],
'user_preferences' => [
['users', 'user_id', 'nullable' => false, 'cascadeOnDelete' => true],
],
'users' => [
['staffs', 'staff_id', 'nullable' => false, 'cascadeOnDelete' => true],
],
'working_hours' => [
['locations', 'location_id', 'nullable' => false, 'cascadeOnDelete' => true],
],
];
}
}
18 changes: 7 additions & 11 deletions app/admin/models/LocationOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,16 @@ protected function updateOptions()
if (!$location = $this->locationContext)
return false;

$records = $this->getAll();

collect($this->itemsToSaveCache)
->filter(function ($value, $key) use ($records) {
return $value != array_get($records, $key);
})
->each(function ($value, $key) use ($location) {
self::updateOrCreate([
self::upsert(collect($this->itemsToSaveCache)
->map(function ($value, $key) use ($location) {
return [
'location_id' => $location->location_id,
'item' => $key,
], ['value' => $value]);
});
'value' => json_encode($value),
];
})->values()->all(), ['location_id', 'item'], ['value']);

static::$cache[$location->location_id] = null;
unset(static::$cache[$location->location_id]);

return true;
}
Expand Down
13 changes: 6 additions & 7 deletions app/admin/models/Orders_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,17 +361,15 @@ public function mailGetData()
$data['order_comment'] = $model->comment;

$data['order_type'] = $model->order_type_name;
$data['order_time'] = Carbon::createFromTimeString($model->order_time)->format(lang('system::lang.php.time_format'));
$data['order_date'] = $model->order_date->format(lang('system::lang.php.date_format'));
$data['order_added'] = $model->created_at->format(lang('system::lang.php.date_time_format'));
$data['order_time'] = Carbon::createFromTimeString($model->order_time)->isoFormat(lang('system::lang.moment.time_format'));
$data['order_date'] = $model->order_date->isoFormat(lang('system::lang.moment.date_format'));
$data['order_added'] = $model->created_at->isoFormat(lang('system::lang.moment.date_time_format'));

$data['invoice_id'] = $model->invoice_number;
$data['invoice_number'] = $model->invoice_number;
$data['invoice_date'] = $model->invoice_date ? $model->invoice_date->format(lang('system::lang.php.date_format')) : null;
$data['invoice_date'] = $model->invoice_date ? $model->invoice_date->isoFormat(lang('system::lang.moment.date_format')) : null;

$data['order_payment'] = ($model->payment_method)
? $model->payment_method->name
: lang('admin::lang.orders.text_no_payment');
$data['order_payment'] = $model->payment_method->name ?? lang('admin::lang.orders.text_no_payment');

$data['order_menus'] = [];
$menus = $model->getOrderMenusWithOptions();
Expand Down Expand Up @@ -413,6 +411,7 @@ public function mailGetData()
$data['order_address'] = format_address($model->address->toArray(), false);

if ($model->location) {
$data['location_logo'] = $model->location->thumb;
$data['location_name'] = $model->location->location_name;
$data['location_email'] = $model->location->location_email;
$data['location_telephone'] = $model->location->location_telephone;
Expand Down
38 changes: 36 additions & 2 deletions app/admin/models/Reservations_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
Expand Down Expand Up @@ -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());
}
}

//
Expand Down Expand Up @@ -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
//
Expand Down Expand Up @@ -435,8 +468,8 @@ public function mailGetData()
$data['reservation'] = $model;
$data['reservation_number'] = $model->reservation_id;
$data['reservation_id'] = $model->reservation_id;
$data['reservation_time'] = Carbon::createFromTimeString($model->reserve_time)->format(lang('system::lang.php.time_format'));
$data['reservation_date'] = $model->reserve_date->format(lang('system::lang.php.date_format_long'));
$data['reservation_time'] = Carbon::createFromTimeString($model->reserve_time)->isoFormat(lang('system::lang.moment.time_format'));
$data['reservation_date'] = $model->reserve_date->isoFormat(lang('system::lang.moment.date_format_long'));
$data['reservation_guest_no'] = $model->guest_num;
$data['first_name'] = $model->first_name;
$data['last_name'] = $model->last_name;
Expand All @@ -445,6 +478,7 @@ public function mailGetData()
$data['reservation_comment'] = $model->comment;

if ($model->location) {
$data['location_logo'] = $model->location->thumb;
$data['location_name'] = $model->location->location_name;
$data['location_email'] = $model->location->location_email;
$data['location_telephone'] = $model->location->location_telephone;
Expand Down
5 changes: 3 additions & 2 deletions app/admin/models/config/categories_model.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

$config['list']['filter'] = [
'search' => [
'prompt' => 'lang:admin::lang.categories.text_filter_search',
Expand Down Expand Up @@ -70,13 +71,13 @@
'label' => 'lang:admin::lang.label_name',
'type' => 'text',
],
'parent_cat' => [
'parent' => [
'label' => 'lang:admin::lang.categories.column_parent',
'type' => 'text',
'relation' => 'parent_cat',
'select' => 'name',
],
'locations' => [
'location_name' => [
'label' => 'lang:admin::lang.column_location',
'type' => 'text',
'relation' => 'locations',
Expand Down
3 changes: 2 additions & 1 deletion app/admin/models/config/mealtimes_model.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

$config['list']['filter'] = [
'scopes' => [
'location' => [
Expand Down Expand Up @@ -82,7 +83,7 @@
'label' => 'lang:admin::lang.column_id',
'invisible' => true,
],
'locations' => [
'location_name' => [
'label' => 'lang:admin::lang.column_location',
'type' => 'text',
'relation' => 'locations',
Expand Down
Loading

0 comments on commit ee29b34

Please sign in to comment.