57 lines
1.9 KiB
PHP
57 lines
1.9 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
|
|
{
|
|
public function settings(Request $request,$id)
|
|
{
|
|
|
|
$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'));
|
|
}
|
|
|
|
public function makeCreneauxSettings($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;
|
|
}
|
|
|
|
public function updateSettings(Request $request,$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 !');
|
|
}
|
|
}
|