réglages des créneaux de collecte
This commit is contained in:
parent
76deb33629
commit
021d98b09b
10 changed files with 261 additions and 125 deletions
|
|
@ -3,6 +3,8 @@
|
|||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\TimeslotSetting;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CreneauxController extends Controller
|
||||
|
|
@ -10,41 +12,33 @@ class CreneauxController extends Controller
|
|||
public function settings(Request $request)
|
||||
{
|
||||
|
||||
$plage = array(
|
||||
0 => array(),
|
||||
1 => array(
|
||||
'start' => '09:00',
|
||||
'end' => '16:50',
|
||||
),
|
||||
2 => array(
|
||||
'start' => '09:00',
|
||||
'end' => '17:00',
|
||||
),
|
||||
3 => array(
|
||||
'start' => '09:00',
|
||||
'end' => '17:00',
|
||||
),
|
||||
4 => array(
|
||||
'start' => '09:00',
|
||||
'end' => '17:00',
|
||||
),
|
||||
5 => array(
|
||||
'start' => '09:00',
|
||||
'end' => '17:00',
|
||||
),
|
||||
6 => array(
|
||||
'start' => '10:00',
|
||||
'end' => '12:00',
|
||||
),
|
||||
);
|
||||
$plage_interval = "00:15";
|
||||
$plage_days = 14;
|
||||
$timeslotSettings = TimeslotSetting::all();
|
||||
$plage_days = Setting::where('key','order_withdrawal_period')->firstOrFail()->value;
|
||||
|
||||
return view('bo.creneaux.settings', compact('plage', 'plage_interval', 'plage_days'));
|
||||
return view('bo.creneaux.settings', compact('timeslotSettings', 'plage_days'));
|
||||
}
|
||||
|
||||
public function updateSettings(Request $request)
|
||||
{
|
||||
dd($request);
|
||||
$plage = $request->plage;
|
||||
$plage_days = $request->plage_days;
|
||||
|
||||
foreach($plage as $index => $day) {
|
||||
$setting = TimeslotSetting::where('day_index', ''.$index)->firstOrFail();
|
||||
$setting->morning_start = $day['morning_start'];
|
||||
$setting->morning_end = $day['morning_end'];
|
||||
$setting->afternoon_start = $day['afternoon_start'];
|
||||
$setting->afternoon_end = $day['afternoon_end'];
|
||||
$setting->interval = $day['interval'];
|
||||
$setting->max_orders_per_interval = $day['max_orders_per_interval'];
|
||||
$setting->min_order_preparation = $day['min_order_preparation'];
|
||||
$setting->save();
|
||||
}
|
||||
|
||||
$order_withdrawal_period = Setting::where('key','order_withdrawal_period')->firstOrFail();
|
||||
$order_withdrawal_period->value = $plage_days;
|
||||
$order_withdrawal_period->save();
|
||||
|
||||
return redirect()->route('bo.creneaux.settings')->with('success', 'Modifications enregistrées !');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ use Illuminate\Support\Facades\Mail;
|
|||
use App\Mail\OrderStatusMail;
|
||||
use App\Mail\OrderConfirmMail;
|
||||
use App\Models\Customers;
|
||||
use App\Models\TimeslotSetting;
|
||||
use Carbon\Carbon;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Carbon\CarbonInterval;
|
||||
|
|
@ -166,39 +167,25 @@ class OrdersController extends Controller
|
|||
{
|
||||
$activestep = 3;
|
||||
|
||||
//settings à stocker
|
||||
//get available timeslots
|
||||
//days 0 = sunday => 6 = saturday
|
||||
$plage = array(
|
||||
0 => array(),
|
||||
1 => array(
|
||||
'start' => '09:00',
|
||||
'end' => '16:50',
|
||||
),
|
||||
2 => array(
|
||||
'start' => '09:00',
|
||||
'end' => '17:00',
|
||||
),
|
||||
3 => array(
|
||||
'start' => '09:00',
|
||||
'end' => '17:00',
|
||||
),
|
||||
4 => array(
|
||||
'start' => '09:00',
|
||||
'end' => '17:00',
|
||||
),
|
||||
5 => array(
|
||||
'start' => '09:00',
|
||||
'end' => '17:00',
|
||||
),
|
||||
6 => array(
|
||||
'start' => '10:00',
|
||||
'end' => '12:00',
|
||||
),
|
||||
);
|
||||
$plage_interval = "0:15";
|
||||
//setting à stocker et réutiliser
|
||||
$plage_days = 14;
|
||||
|
||||
$timeslotSettings = TimeslotSetting::all();
|
||||
//fabriquons un tableau recap
|
||||
$plage = array();
|
||||
foreach($timeslotSettings as $day) {
|
||||
|
||||
$plage[$day->day_index] = array(
|
||||
'morning_start' => $day->morning_start,
|
||||
'morning_end' => $day->morning_end,
|
||||
'afternoon_start' => $day->afternoon_start,
|
||||
'afternoon_end' => $day->afternoon_end,
|
||||
'interval' => $day->interval,
|
||||
'min_order_preparation' => $day->min_order_preparation
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//génération des plages
|
||||
//start today
|
||||
$today = CarbonImmutable::now()->startOfDay();
|
||||
|
|
@ -206,25 +193,40 @@ class OrdersController extends Controller
|
|||
|
||||
$availCreneaux = array();
|
||||
|
||||
$interval = CarbonInterval::createFromFormat('h:i', $plage_interval);
|
||||
|
||||
for ($i = 0; $i < $plage_days; $i++) {
|
||||
/** @var Carbon */
|
||||
$current = $today->add($i, 'day');
|
||||
$weekDay = $current->weekday();
|
||||
if (isset($plage[$weekDay]['start'])) {
|
||||
$currentTime = Carbon::createFromTimeString($plage[$weekDay]['start']);
|
||||
$endTime = Carbon::createFromTimeString($plage[$weekDay]['end']);
|
||||
$interval = CarbonInterval::createFromFormat('h:i', $plage[$weekDay]['interval'] ?? '00:15');
|
||||
$delaiPrepa = CarbonInterval::createFromFormat('h:i', $plage[$weekDay]['min_order_preparation'] ?? '01:00');
|
||||
//matinée
|
||||
if (!empty($plage[$weekDay]['morning_start'])) {
|
||||
$currentTime = Carbon::createFromTimeString($plage[$weekDay]['morning_start']);
|
||||
$endTime = Carbon::createFromTimeString($plage[$weekDay]['morning_end']);
|
||||
do {
|
||||
$creneau = $currentTime->format('H:i');
|
||||
//attention si la date est passée (today mai avant maintenant) : pas de créneau
|
||||
if ($current > $today || $currentTime >= $now) {
|
||||
if ($current > $today || $currentTime >= $now->add($delaiPrepa)) {
|
||||
$availCreneaux[$current->format('d/m/Y')][] = $creneau;
|
||||
}
|
||||
$currentTime->add($interval);
|
||||
} while ($currentTime <= $endTime);
|
||||
}
|
||||
//aprem
|
||||
if (!empty($plage[$weekDay]['afternoon_start'])) {
|
||||
$currentTime = Carbon::createFromTimeString($plage[$weekDay]['afternoon_start']);
|
||||
$endTime = Carbon::createFromTimeString($plage[$weekDay]['afternoon_end']);
|
||||
do {
|
||||
$creneau = $currentTime->format('H:i');
|
||||
//attention si la date est passée (today mais avant maintenant) : pas de créneau
|
||||
if ($current > $today || $currentTime >= $now->add($delaiPrepa)) {
|
||||
$availCreneaux[$current->format('d/m/Y')][] = $creneau;
|
||||
}
|
||||
$currentTime->add($interval);
|
||||
} while ($currentTime <= $endTime);
|
||||
}
|
||||
}
|
||||
|
||||
$order = Order::where('reference', '=', $reference)->firstOrFail();
|
||||
return view('sales.pick-slot', compact('activestep', 'availCreneaux', 'order'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ class ProductsController extends Controller
|
|||
/**
|
||||
* store a new product
|
||||
* @todo : manage tags and associated products
|
||||
* @todo : enregistrer unité de vente, poids et unité de poids
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
|
|
@ -198,6 +199,7 @@ class ProductsController extends Controller
|
|||
|
||||
/**
|
||||
* update an existing product
|
||||
* @todo : enregistrer unité de vente, poids et unité de poids
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,7 +8,9 @@ use Illuminate\Database\Eloquent\Model;
|
|||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Gloudemans\Shoppingcart\Contracts\Buyable;
|
||||
use Gloudemans\Shoppingcart\CanBeBought;
|
||||
|
||||
/**
|
||||
* @todo : unité de vente/unité de poids devrait être des énums (via table liée ou package enum)
|
||||
*/
|
||||
class Product extends Model implements Buyable
|
||||
{
|
||||
use HasFactory;
|
||||
|
|
|
|||
11
app/Models/TimeslotSetting.php
Normal file
11
app/Models/TimeslotSetting.php
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class TimeslotSetting extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
use Database\Seeders\TimeslotSettingsSeeder;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateTimeslotSettingsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('timeslot_settings', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->enum('day_index', [0,1,2,3,4,5,6])->nullable()->unique();
|
||||
$table->string('morning_start')->nullable();
|
||||
$table->string('morning_end')->nullable();
|
||||
$table->string('afternoon_start')->nullable();
|
||||
$table->string('afternoon_end')->nullable();
|
||||
$table->string('interval')->nullable();
|
||||
$table->unsignedInteger('max_orders_per_interval')->nullable();
|
||||
$table->string('min_order_preparation')->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
$seeder = new TimeslotSettingsSeeder;
|
||||
$seeder->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('timeslot_settings');
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,9 @@
|
|||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
class ThemeSettings extends Seeder
|
||||
{
|
||||
/**
|
||||
|
|
|
|||
86
database/seeders/TimeslotSettingsSeeder.php
Normal file
86
database/seeders/TimeslotSettingsSeeder.php
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\TimeslotSetting;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class TimeslotSettingsSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$mondays = new TimeslotSetting();
|
||||
$mondays->day_index = '0';
|
||||
$mondays->morning_start = "09:01";
|
||||
$mondays->morning_end = "12:00";
|
||||
$mondays->afternoon_start = "13:00";
|
||||
$mondays->afternoon_end = "17:00";
|
||||
$mondays->interval = "00:15";
|
||||
$mondays->max_orders_per_interval = 4;
|
||||
$mondays->min_order_preparation = "01:00";
|
||||
$mondays->save();
|
||||
|
||||
$tuesdays = new TimeslotSetting();
|
||||
$tuesdays->day_index = '1';
|
||||
$tuesdays->morning_start = "09:02";
|
||||
$tuesdays->morning_end = "12:00";
|
||||
$tuesdays->afternoon_start = "13:00";
|
||||
$tuesdays->afternoon_end = "17:00";
|
||||
$tuesdays->interval = "00:15";
|
||||
$tuesdays->max_orders_per_interval = 4;
|
||||
$tuesdays->min_order_preparation = "01:00";
|
||||
$tuesdays->save();
|
||||
|
||||
$wednesdays = new TimeslotSetting();
|
||||
$wednesdays->day_index = '2';
|
||||
$wednesdays->morning_start = "09:03";
|
||||
$wednesdays->morning_end = "12:00";
|
||||
$wednesdays->afternoon_start = "13:00";
|
||||
$wednesdays->afternoon_end = "17:00";
|
||||
$wednesdays->interval = "00:15";
|
||||
$wednesdays->max_orders_per_interval = 4;
|
||||
$wednesdays->min_order_preparation = "01:00";
|
||||
$wednesdays->save();
|
||||
|
||||
$thursdays = new TimeslotSetting();
|
||||
$thursdays->day_index = '3';
|
||||
$thursdays->morning_start = "09:04";
|
||||
$thursdays->morning_end = "12:00";
|
||||
$thursdays->afternoon_start = "13:00";
|
||||
$thursdays->afternoon_end = "17:00";
|
||||
$thursdays->interval = "00:15";
|
||||
$thursdays->max_orders_per_interval = 4;
|
||||
$thursdays->min_order_preparation = "01:00";
|
||||
$thursdays->save();
|
||||
|
||||
$fridays = new TimeslotSetting();
|
||||
$fridays->day_index = '4';
|
||||
$fridays->morning_start = "09:05";
|
||||
$fridays->morning_end = "12:00";
|
||||
$fridays->afternoon_start = "13:00";
|
||||
$fridays->afternoon_end = "17:00";
|
||||
$fridays->interval = "00:15";
|
||||
$fridays->max_orders_per_interval = 4;
|
||||
$fridays->min_order_preparation = "01:00";
|
||||
$fridays->save();
|
||||
|
||||
$saturdays = new TimeslotSetting();
|
||||
$saturdays->day_index = '5';
|
||||
$saturdays->morning_start = "09:06";
|
||||
$saturdays->morning_end = "12:00";
|
||||
$saturdays->interval = "00:15";
|
||||
$saturdays->max_orders_per_interval = 4;
|
||||
$saturdays->min_order_preparation = "01:00";
|
||||
$saturdays->save();
|
||||
|
||||
$sundays = new TimeslotSetting();
|
||||
$sundays->day_index = '6';
|
||||
$sundays->save();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -49,81 +49,73 @@
|
|||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group col">
|
||||
Début
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
<input type="time" id="start_time_1" name="plage[1][start]" class="form-control" value="{{ old('plage[1][start]', $plage[1]["start"] ?? '') }}">
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
<input type="time" id="start_time_2" name="plage[2][start]" class="form-control" value="{{ old('plage[2][start]', $plage[2]["start"] ?? '') }}">
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
<input type="time" id="start_time_3" name="plage[3][start]" class="form-control" value="{{ old('plage[3][start]', $plage[3]["start"] ?? '') }}">
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
<input type="time" id="start_time_4" name="plage[4][start]" class="form-control" value="{{ old('plage[4][start]', $plage[4]["start"] ?? '') }}">
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
<input type="time" id="start_time_5" name="plage[5][start]" class="form-control" value="{{ old('plage[5][start]', $plage[5]["start"] ?? '') }}">
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
<input type="time" id="start_time_6" name="plage[6][start]" class="form-control" value="{{ old('plage[6][start]', $plage[6]["start"] ?? '') }}">
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
<input type="time" id="start_time_0" name="plage[0][start]" class="form-control" value="{{ old('plage[0][start]', $plage[0]["start"] ?? '') }}">
|
||||
Matinée Début
|
||||
</div>
|
||||
@foreach ($timeslotSettings as $zeDay)
|
||||
<div class="form-group col">
|
||||
<input type="time" id="morning_start_time_{{$zeDay->day_index}}" name="plage[{{$zeDay->day_index}}][morning_start]" class="form-control" value="{{ old('plage['.$zeDay->day_index.'][morning_start]', $zeDay->morning_start ?? '') }}">
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group col">
|
||||
Fin
|
||||
Matinée Fin
|
||||
</div>
|
||||
@foreach ($timeslotSettings as $zeDay)
|
||||
<div class="form-group col">
|
||||
<input type="time" id="end_time_1" name="plage[1][end]" class="form-control" value="{{ old('plage[1][end]', $plage[1]["end"] ?? '') }}">
|
||||
<input type="time" id="morning_end_time_{{$zeDay->day_index}}" name="plage[{{$zeDay->day_index}}][morning_end]" class="form-control" value="{{ old('plage['.$zeDay->day_index.'][morning_end]', $zeDay->morning_end ?? '') }}">
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group col">
|
||||
<input type="time" id="end_time_2" name="plage[2][end]" class="form-control" value="{{ old('plage[2][end]', $plage[2]["end"] ?? '') }}">
|
||||
Après-midi Début
|
||||
</div>
|
||||
@foreach ($timeslotSettings as $zeDay)
|
||||
<div class="form-group col">
|
||||
<input type="time" id="afternoon_start_time_{{$zeDay->day_index}}" name="plage[{{$zeDay->day_index}}][afternoon_start]" class="form-control" value="{{ old('plage['.$zeDay->day_index.'][afternoon_start]', $zeDay->afternoon_start ?? '') }}">
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group col">
|
||||
<input type="time" id="end_time_3" name="plage[3][end]" class="form-control" value="{{ old('plage[3][end]', $plage[3]["end"] ?? '') }}">
|
||||
Après-midi Fin
|
||||
</div>
|
||||
@foreach ($timeslotSettings as $zeDay)
|
||||
<div class="form-group col">
|
||||
<input type="time" id="end_time_4" name="plage[4][end]" class="form-control" value="{{ old('plage[4][end]', $plage[4]["end"] ?? '') }}">
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
<input type="time" id="end_time_5" name="plage[5][end]" class="form-control" value="{{ old('plage[5][end]', $plage[5]["end"] ?? '') }}">
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
<input type="time" id="end_time_6" name="plage[6][end]" class="form-control" value="{{ old('plage[6][end]', $plage[6]["end"] ?? '') }}">
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
<input type="time" id="end_time_0" name="plage[0][end]" class="form-control" value="{{ old('plage[0][end]', $plage[0]["end"] ?? '') }}">
|
||||
<input type="time" id="afternoon_end_time_{{$zeDay->day_index}}" name="plage[{{$zeDay->day_index}}][afternoon_end]" class="form-control" value="{{ old('plage['.$zeDay->day_index.'][afternoon_end]', $zeDay->afternoon_end ?? '') }}">
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group col">
|
||||
Durée d'un crénaux
|
||||
</div>
|
||||
@foreach ($timeslotSettings as $zeDay)
|
||||
<div class="form-group col">
|
||||
<input type="time" id="interval_{{$zeDay->day_index}}" name="plage[{{$zeDay->day_index}}][interval]" class="form-control" value="{{ old('plage['.$zeDay->day_index.'][interval]', $zeDay->interval ?? '') }}">
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group col">
|
||||
<input type="time" id="plage_interval" name="plage_interval" class="form-control" value="{{ old('plage_interval', $plage_interval) }}">
|
||||
Nb de réservations maximum par crénau
|
||||
</div>
|
||||
@foreach ($timeslotSettings as $zeDay)
|
||||
<div class="form-group col">
|
||||
<input type="number" id="max_orders_per_interval_{{$zeDay->day_index}}" name="plage[{{$zeDay->day_index}}][max_orders_per_interval]" class="form-control" value="{{ old('plage['.$zeDay->day_index.'][max_orders_per_interval]', $zeDay->max_orders_per_interval ?? '') }}">
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group col">
|
||||
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
|
||||
Delai de préparation de commande
|
||||
</div>
|
||||
@foreach ($timeslotSettings as $zeDay)
|
||||
<div class="form-group col">
|
||||
<input type="time" id="min_order_preparation_{{$zeDay->day_index}}" name="plage[{{$zeDay->day_index}}][min_order_preparation]" class="form-control" value="{{ old('plage['.$zeDay->day_index.'][min_order_preparation]', $zeDay->min_order_preparation ?? '') }}">
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group col">
|
||||
|
|
|
|||
|
|
@ -46,12 +46,12 @@
|
|||
Gestion des QR codes
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
{{--<div class="form-group">
|
||||
<label class="col-form-label">
|
||||
Délai de retrait de la commance
|
||||
<input type="number" name="order_withdrawal_period" class="form-control" value="{{$settingsToPrint['order_withdrawal_period']}}">
|
||||
</label>
|
||||
</div>
|
||||
</div>--}}
|
||||
<div class="form-group">
|
||||
<label class="col-form-label">
|
||||
Adresse de reception des messages "contactez nous"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue