80 lines
2.6 KiB
PHP
80 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Magasin;
|
|
use App\Models\TimeslotSetting;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CreneauxController extends Controller
|
|
{
|
|
/**
|
|
* Display creneaux settings form
|
|
*
|
|
* @param Request $request
|
|
* @param integer $id
|
|
* @return \Illuminate\Contracts\View\View
|
|
*
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
*/
|
|
public function settings(Request $request, int $id)
|
|
{
|
|
// @phpcs:enable
|
|
$magasin = Magasin::findOrFail($id);
|
|
$timeslotSettings = $magasin->timeslotSettings;
|
|
if ($timeslotSettings->count() === 0) {
|
|
// Aucun settings pour ce magasin.
|
|
$timeslotSettings = $this->makeCreneauxSettings($id);
|
|
}
|
|
|
|
return view('bo.creneaux.settings', compact('timeslotSettings', 'magasin'));
|
|
}
|
|
|
|
/**
|
|
* Retrieve creneaux settings
|
|
*
|
|
* @param integer $id
|
|
* @return mixed
|
|
*/
|
|
public function makeCreneauxSettings(int $id)
|
|
{
|
|
for ($i = 0; $i < 7; $i++) {
|
|
$dayset = new TimeslotSetting();
|
|
$dayset->magasin_id = $id;
|
|
$dayset->day_index = '' . $i;
|
|
$dayset->save();
|
|
}
|
|
return Magasin::findOrFail($id)->timeslotSettings;
|
|
}
|
|
|
|
/**
|
|
* save settings
|
|
*
|
|
* @param Request $request
|
|
* @param integer $id
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function updateSettings(Request $request, int $id)
|
|
{
|
|
$plage = $request->plage;
|
|
$magasin_id = $id;
|
|
|
|
foreach ($plage as $index => $day) {
|
|
$setting = TimeslotSetting::where('day_index', '' . $index)
|
|
->where('magasin_id', $magasin_id)
|
|
->firstOrFail();
|
|
// $setting->magasin_id = $magasin_id; ne doit pas changer
|
|
$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();
|
|
}
|
|
|
|
return redirect()->route('bo.creneaux.settings', $magasin_id)->with('success', 'Modifications enregistrées !');
|
|
}
|
|
}
|