Skip to content

Commit

Permalink
ability to add registered customer on reservation form.
Browse files Browse the repository at this point in the history
  • Loading branch information
obinnaelviso committed Jul 13, 2024
1 parent 9632a95 commit c7ac441
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
2 changes: 2 additions & 0 deletions resources/lang/en/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
'text_filter_date' => 'View all reservation dates',
'text_filter_time' => 'View all reservation times',
'text_filter_search' => 'Search by id, location, guest number, status, customer or table name.',
'text_guest' => 'Guest',
'text_no_booking' => 'No Bookings',
'text_no_table' => 'No Table',
'text_restaurant' => 'Location',
'text_unassigned' => 'Yet to be Assigned',
'text_assigned_to_self' => 'Assigned To Me',
'text_assigned_to_others' => 'Assigned To Other User',
'text_customer' => 'Customer',
'text_view_calendar' => 'Calendar View',
'text_view_list' => 'List View',
'text_view_floor_plan' => 'Floor Plan View',
Expand Down
27 changes: 27 additions & 0 deletions resources/models/reservation.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,25 +221,52 @@
'mode' => 'time',
'span' => 'right',
],
'registered_customer_id' => [
'label' => 'lang:igniter.reservation::default.text_customer',
'type' => 'select',
'options' => [Igniter\User\Models\Customer::class, 'getDropdownOptions'],
'span' => 'left',
'placeholder' => 'lang:igniter.reservation::default.text_guest',
],
'first_name' => [
'label' => 'lang:igniter.reservation::default.label_first_name',
'type' => 'text',
'span' => 'left',
'trigger' => [
'action' => 'show',
'field' => 'registered_customer_id',
'condition' => 'value[]',
],
],
'last_name' => [
'label' => 'lang:igniter.reservation::default.label_last_name',
'type' => 'text',
'span' => 'right',
'trigger' => [
'action' => 'show',
'field' => 'registered_customer_id',
'condition' => 'value[]',
],
],
'email' => [
'label' => 'lang:igniter::admin.label_email',
'type' => 'text',
'span' => 'left',
'trigger' => [
'action' => 'show',
'field' => 'registered_customer_id',
'condition' => 'value[]',
],
],
'telephone' => [
'label' => 'lang:igniter.reservation::default.label_customer_telephone',
'type' => 'text',
'span' => 'right',
'trigger' => [
'action' => 'show',
'field' => 'registered_customer_id',
'condition' => 'value[]',
],
],
'location_id' => [
'label' => 'lang:igniter.reservation::default.text_tab_restaurant',
Expand Down
13 changes: 13 additions & 0 deletions src/Http/Controllers/Reservations.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Igniter\Local\Facades\Location as LocationFacade;
use Igniter\Reservation\Models\DiningArea;
use Igniter\Reservation\Models\Reservation;
use Igniter\User\Models\Customer;

class Reservations extends \Igniter\Admin\Classes\AdminController
{
Expand Down Expand Up @@ -228,4 +229,16 @@ protected function getReserveTimeOptions($date = null)

return $items;
}

public function formBeforeSave($model)
{
$registeredCustomerId = post('Reservation.registered_customer_id');
if ($registeredCustomerId) {
$registeredCustomer = Customer::findOrFail($registeredCustomerId);
$model->first_name = $registeredCustomer->first_name;
$model->last_name = $registeredCustomer->last_name;
$model->email = $registeredCustomer->email;
$model->telephone = $registeredCustomer->telephone;
}
}
}
5 changes: 3 additions & 2 deletions src/Http/Requests/ReservationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public function rules()
{
return [
'location_id' => ['sometimes', 'required', 'integer'],
'first_name' => ['required', 'string', 'between:1,48'],
'last_name' => ['required', 'string', 'between:1,48'],
'registered_customer_id' => ['nullable', 'integer'],
'first_name' => ['required_without:registered_customer_id', 'string', 'between:1,48'],
'last_name' => ['required_without:registered_customer_id', 'string', 'between:1,48'],
'email' => ['email:filter', 'max:96'],
'telephone' => ['sometimes', 'string'],
'reserve_date' => ['required', 'date_format:Y-m-d'],
Expand Down

0 comments on commit c7ac441

Please sign in to comment.