fix: 🐛 user->id null on SalarieExportJob + add public holiday with cron + condition on public holiday's calendar
This commit is contained in:
parent
b14f3ec15e
commit
79d9061bc9
14 changed files with 382 additions and 119 deletions
35
app/Console/Commands/GetPublicHolidayNextYear.php
Normal file
35
app/Console/Commands/GetPublicHolidayNextYear.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\GetPublicHolidayForNextYear;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class GetPublicHolidayNextYear extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'uwil:get-public-holiday {year?}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'fetch the public holiday for a specific year or by default for the next year';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$year = $this->argument('year');
|
||||
(new GetPublicHolidayForNextYear($year))->handle();
|
||||
$this->info("Les jours fériés de l'année " . ($year ?? (now()->year + 1)) . " ont été récupéré.");
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Console;
|
||||
|
||||
use App\Jobs\GetPublicHolidayForNextYear;
|
||||
use App\Jobs\SendReminderMail;
|
||||
use App\Jobs\XmlIncoReader as JobsXmlIncoReader;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
|
|
@ -26,6 +27,7 @@ class Kernel extends ConsoleKernel
|
|||
{
|
||||
$schedule->job(JobsXmlIncoReader::class)->name('xml-inco-reader')->onOneServer()->dailyAt('15:00');
|
||||
$schedule->job(SendReminderMail::class)->onOneServer()->dailyAt('7:00');
|
||||
$schedule->job(GetPublicHolidayForNextYear::class)->onOneServer()->yearlyOn(11, 1, '7:30');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
42
app/Enums/ExceptionDayType.php
Normal file
42
app/Enums/ExceptionDayType.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use Kwaadpepper\Enum\BaseEnumRoutable;
|
||||
|
||||
/**
|
||||
* This is an enumeration class,
|
||||
* the following methods are its possible values
|
||||
*
|
||||
* @method static self ferie()
|
||||
* @method static self other()
|
||||
*
|
||||
*/
|
||||
class ExceptionDayType extends BaseEnumRoutable
|
||||
{
|
||||
/**
|
||||
* Enum values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
'ferie' => 'Jour férié',
|
||||
'other' => 'Autre',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum labels
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
'ferie' => __('Jour férié'),
|
||||
'other' => __('Autre'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -147,6 +147,7 @@ class MagasinsController extends Controller
|
|||
$ce = CollecteException::findOrFail($collecteException[$i]["id"]);
|
||||
$ce->date = $collecteException[$i]["date"];
|
||||
$ce->comment = $collecteException[$i]["comment"];
|
||||
$ce->type = $collecteException[$i]["type"];
|
||||
$ce->magasin_id = $collecteException[$i]["magasin_id"];
|
||||
$ce->save();
|
||||
} else {
|
||||
|
|
@ -154,15 +155,16 @@ class MagasinsController extends Controller
|
|||
$ce = CollecteException::updateOrCreate([
|
||||
'date' => $collecteException[$i]["date"],
|
||||
'comment' => $collecteException[$i]["comment"],
|
||||
'type' => $collecteException[$i]["type"],
|
||||
'magasin_id' => $collecteException[$i]["magasin_id"]
|
||||
]);
|
||||
]);
|
||||
$collecteException[$i]["id"] = $ce->id;
|
||||
} else {
|
||||
unset($collecteException[$i]);
|
||||
$i--;
|
||||
}
|
||||
}
|
||||
}//end for
|
||||
} //end for
|
||||
|
||||
// Remet dans l'ordre avant de renvoyer.
|
||||
$this->arraySortByColumn($collecteException, "date");
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
|||
use App\Http\Requests\Bo\ImportRequest;
|
||||
use App\Imports\SalariesImport;
|
||||
use App\Jobs\SalariesExportJob;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class SalariesController extends Controller
|
||||
|
|
@ -47,7 +48,7 @@ class SalariesController extends Controller
|
|||
*/
|
||||
public function export(array $salariesImport)
|
||||
{
|
||||
$this->dispatch(new SalariesExportJob($salariesImport));
|
||||
$this->dispatch(new SalariesExportJob($salariesImport, Auth::user()));
|
||||
return redirect()->route('bo.salaries.index')->with('success', 'Export terminé.');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\ExceptionDayType;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Order;
|
||||
use App\Models\OrderLine;
|
||||
|
|
@ -166,7 +167,6 @@ class OrderTunnelController extends Controller
|
|||
if (Auth::user()->salarie->magasin) {
|
||||
$magasin = Auth::user()->salarie->magasin;
|
||||
}
|
||||
|
||||
$availCreneaux = array();
|
||||
$order = Order::where('reference', '=', $reference)->firstOrFail();
|
||||
|
||||
|
|
@ -198,7 +198,9 @@ class OrderTunnelController extends Controller
|
|||
CarbonInterval $delaiPrepa,
|
||||
CarbonInterval $interval,
|
||||
Carbon $currentTime,
|
||||
Carbon $endTime
|
||||
Carbon $endTime,
|
||||
bool $hasPublicHolidayNextWeekButNoFriday,
|
||||
bool $afterThursdayNight
|
||||
) {
|
||||
$retArray = array();
|
||||
do {
|
||||
|
|
@ -225,6 +227,11 @@ class OrderTunnelController extends Controller
|
|||
}
|
||||
// Attention si la date est passée (today mais avant maintenant) : pas de créneau.
|
||||
if ($current > $today || $currentTime >= $now) {
|
||||
// Si un jour de la semaine prochaine est férié et qu'on passe commande un jeudi après 23h59...alors le vendredi de la semaine suivante n'est pas dispo.
|
||||
$nextFriday = $now->addWeek()->startOfWeek(Carbon::MONDAY)->addDays(4);
|
||||
if ($hasPublicHolidayNextWeekButNoFriday && $afterThursdayNight && $current->isSameDay($nextFriday)) {
|
||||
$isDispo = false;
|
||||
}
|
||||
$retArray[] = array($creneau, $isDispo);
|
||||
}
|
||||
$currentTime->add($interval);
|
||||
|
|
@ -242,7 +249,6 @@ class OrderTunnelController extends Controller
|
|||
{
|
||||
// Setting à stocker et réutiliser.
|
||||
$plage_days = Setting::where('key', 'order_withdrawal_period')->firstOrFail()->value;
|
||||
|
||||
$magasin = Magasin::findOrFail($id);
|
||||
$timeslotSettings = $magasin->timeslotSettings;
|
||||
// $timeslotSettings = TimeslotSetting::all();
|
||||
|
|
@ -267,12 +273,30 @@ class OrderTunnelController extends Controller
|
|||
// Final boundary (permet de limiter la liste des jours d'exception).
|
||||
$finalday = $today->add($plage_days, 'day');
|
||||
$now = CarbonImmutable::now();
|
||||
|
||||
// Jours exceptions.
|
||||
$noCollectDays = $magasin->collecteExceptions()
|
||||
->whereDate('date', '>', $now)
|
||||
->whereDate('date', '<=', $finalday)
|
||||
->orderBy('date')->get();
|
||||
|
||||
|
||||
// On effectue des vérifications pour récupérer des jours de la semaine suivante
|
||||
// =/= de vendredi qui seraient fériés.
|
||||
$thursdayNight = $now->startOfWeek(Carbon::MONDAY)->addDays(3)->setTime(23, 59);
|
||||
$afterThursdayNight = $now->greaterThanOrEqualTo($thursdayNight);
|
||||
$currentweekStartDate = $now->startOfWeek();
|
||||
$currentweekEndDate = $now->endOfWeek();
|
||||
$nextWeekStartDate = $currentweekStartDate->addWeek();
|
||||
$nextWeekEndDate = $currentweekEndDate->addWeek();
|
||||
|
||||
$hasPublicHolidayNextWeekButNoFriday = $magasin->collecteExceptions()
|
||||
->whereDate('date', '>=', $nextWeekStartDate)
|
||||
->whereDate('date', '<=', $nextWeekEndDate)
|
||||
->where('type', '=', ExceptionDayType::ferie())
|
||||
->whereRaw('DAYOFWEEK(date) != ?', 6)
|
||||
->count() > 0;
|
||||
|
||||
$delaiPrepa = CarbonInterval::createFromFormat('h:i', $plage[$weekDay]['min_order_preparation'] ?? '01:00');
|
||||
|
||||
$availCreneaux = array();
|
||||
|
|
@ -288,6 +312,7 @@ class OrderTunnelController extends Controller
|
|||
$interval = CarbonInterval::createFromFormat('h:i', $plage[$weekDay]['interval'] ?? '00:15');
|
||||
|
||||
// Si c'est un jour exception skip.
|
||||
// ah ? mais on skip quoi et ou ? et pourquoi ?
|
||||
$skip = false;
|
||||
foreach ($noCollectDays as $not_today) {
|
||||
if ($current->isSameDay($not_today->date)) {
|
||||
|
|
@ -297,7 +322,9 @@ class OrderTunnelController extends Controller
|
|||
if ($skip) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$availCreneaux[$current->format('d/m/Y')] = array();
|
||||
|
||||
// Matinée.
|
||||
if (!empty($plage[$weekDay]['morning_start'])) {
|
||||
$currentTime = Carbon::createFromTimeString($plage[$weekDay]['morning_start']);
|
||||
|
|
@ -313,7 +340,9 @@ class OrderTunnelController extends Controller
|
|||
$delaiPrepa,
|
||||
$interval,
|
||||
$currentTime,
|
||||
$endTime
|
||||
$endTime,
|
||||
$hasPublicHolidayNextWeekButNoFriday,
|
||||
$afterThursdayNight,
|
||||
);
|
||||
// Cela sert à rien d'afficher un jour avec des créneaux sur lesquels le conso ne peut pas cliquer...
|
||||
if ($this->hasCreneauAvailableTime($morningCreneaux)) {
|
||||
|
|
@ -338,7 +367,9 @@ class OrderTunnelController extends Controller
|
|||
$delaiPrepa,
|
||||
$interval,
|
||||
$currentTime,
|
||||
$endTime
|
||||
$endTime,
|
||||
$hasPublicHolidayNextWeekButNoFriday,
|
||||
$afterThursdayNight,
|
||||
);
|
||||
// Cela sert à rien d'afficher un jour avec des créneaux sur lesquels le conso ne peut pas cliquer...
|
||||
if ($this->hasCreneauAvailableTime($afternoonCreneaux)) {
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ class SalariesImport implements ToModel, WithCustomCsvSettings, WithHeadingRow,
|
|||
$salarie->site = Arr::get($row, 'site');
|
||||
$salarie->service = Arr::get($row, 'service');
|
||||
$salarie->code = $salarie->code ?? Salarie::generateRandomString(8, Salarie::query());
|
||||
Salarie::setSalarieMagasin($salarie);
|
||||
$salarie->setMagasin();
|
||||
$salarie->saveOrFail();
|
||||
$this->salariesImport = array_merge($this->salariesImport, [$matricule]);
|
||||
return $salarie;
|
||||
|
|
|
|||
64
app/Jobs/GetPublicHolidayForNextYear.php
Normal file
64
app/Jobs/GetPublicHolidayForNextYear.php
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Enums\ExceptionDayType;
|
||||
use App\Models\Magasin;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class GetPublicHolidayForNextYear implements ShouldQueue
|
||||
{
|
||||
use Dispatchable;
|
||||
use InteractsWithQueue;
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Chose a specific year to fetch data
|
||||
* @var integer $year
|
||||
*/
|
||||
protected $year;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param integer|null $year
|
||||
*/
|
||||
public function __construct($year = null)
|
||||
{
|
||||
$this->year = is_numeric($year) ? (int)$year : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$targetYear = $this->year ?? now()->year + 1;
|
||||
$url = "https://calendrier.api.gouv.fr/jours-feries/metropole/{$targetYear}.json";
|
||||
$response = Http::get($url);
|
||||
if ($response->successful()) {
|
||||
$publicHolidays = $response->json();
|
||||
$magasins = Magasin::with('collecteExceptions')->get();
|
||||
foreach ($magasins as $magasin) {
|
||||
foreach ($publicHolidays as $date => $holidayName) {
|
||||
$existingException = $magasin->collecteExceptions()->where('date', $date)->first();
|
||||
if (!$existingException) {
|
||||
$magasin->collecteExceptions()->create([
|
||||
'date' => $date,
|
||||
'comment' => $holidayName,
|
||||
'type' => ExceptionDayType::ferie()
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,9 +4,9 @@ namespace App\Jobs;
|
|||
|
||||
use App\Exports\SalariesExport;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Mail\SendSalariesCSVMail;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
|
@ -19,15 +19,23 @@ class SalariesExportJob implements ShouldQueue
|
|||
*/
|
||||
public $salariesImport = null;
|
||||
|
||||
/**
|
||||
* Auth user
|
||||
* @var User|null
|
||||
*/
|
||||
public $user = null;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param array $salariesImport
|
||||
* @param array $salariesImport
|
||||
* @param \Illuminate\Auth\Authenticatable $user
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $salariesImport)
|
||||
public function __construct(array $salariesImport, User $user)
|
||||
{
|
||||
$this->salariesImport = $salariesImport;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -37,14 +45,12 @@ class SalariesExportJob implements ShouldQueue
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
/** @var \App\Models\User */
|
||||
$user = Auth::user();
|
||||
$disk = Storage::disk('salaries');
|
||||
$csv_file = Carbon::now()->format('d_m_Y-H_i_s') . '-' . $user->id . '-export_salaries.csv';
|
||||
$csv_file = Carbon::now()->format('d_m_Y-H_i_s') . '-' . $this->user->id . '-export_salaries.csv';
|
||||
|
||||
Excel::store(new SalariesExport($this->salariesImport), $csv_file, 'salaries');
|
||||
|
||||
Mail::to($user->email)->send(new SendSalariesCSVMail($user, $csv_file));
|
||||
Mail::to($this->user->email)->send(new SendSalariesCSVMail($this->user, $csv_file));
|
||||
|
||||
if ($disk->exists($csv_file)) {
|
||||
$disk->delete($csv_file);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class CollecteException extends Model
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['date', 'comment', 'magasin_id'];
|
||||
protected $fillable = ['date', 'comment', 'magasin_id', 'type'];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
|
|
|
|||
|
|
@ -18,31 +18,24 @@ class Salarie extends Model
|
|||
*/
|
||||
protected $fillable = [
|
||||
'matricule',
|
||||
'nom', 'prenom',
|
||||
'nom',
|
||||
'prenom',
|
||||
'code',
|
||||
'start_date', 'end_date', 'etablissement', 'site', 'service'
|
||||
'start_date',
|
||||
'end_date',
|
||||
'etablissement',
|
||||
'site',
|
||||
'service'
|
||||
];
|
||||
|
||||
/**
|
||||
* Setter magasin for a salarie.
|
||||
*
|
||||
* @param \App\Models\Salarie $salarie
|
||||
* @return void
|
||||
*/
|
||||
public static function setSalarieMagasin(Salarie $salarie)
|
||||
{
|
||||
Salarie::setMagasin($salarie);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the fixed collection point for a salarie.
|
||||
*
|
||||
* @param \App\Models\Salarie $salarie
|
||||
* @return void
|
||||
*/
|
||||
private function setMagasin(Salarie $salarie)
|
||||
public function setMagasin()
|
||||
{
|
||||
switch ($salarie->site) {
|
||||
switch ($this->site) {
|
||||
case SalarieSite::ldccav():
|
||||
// Cavol.
|
||||
$magasin = Magasin::find(3);
|
||||
|
|
@ -56,10 +49,10 @@ class Salarie extends Model
|
|||
$magasin = Magasin::find(9);
|
||||
break;
|
||||
case SalarieSite::cepacpe():
|
||||
if (in_array($salarie->service, ["CEPACP060", "CEPACP070", "CEPACP072"])) {
|
||||
if (in_array($this->service, ["CEPACP060", "CEPACP070", "CEPACP072"])) {
|
||||
// CPE.
|
||||
$magasin = Magasin::find(6);
|
||||
} elseif (in_array($salarie->service, ["CEPACP065", "CEPACP066"])) {
|
||||
} elseif (in_array($this->service, ["CEPACP065", "CEPACP066"])) {
|
||||
// PLB.
|
||||
$magasin = Magasin::find(11);
|
||||
} else {
|
||||
|
|
@ -83,8 +76,7 @@ class Salarie extends Model
|
|||
$magasin = Magasin::find(1);
|
||||
} //end switch
|
||||
|
||||
$salarie->magasin()->associate($magasin);
|
||||
$salarie->save();
|
||||
$this->magasin()->associate($magasin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
use App\Enums\ExceptionDayType;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class AddTypeToExceptionsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$ferie = ExceptionDayType::ferie()->label;
|
||||
$other = ExceptionDayType::other()->label;
|
||||
|
||||
Schema::table('collecte_exceptions', function (Blueprint $table) {
|
||||
$table->string('type')
|
||||
->default(ExceptionDayType::ferie()->label)
|
||||
->after('comment')
|
||||
->comment('Type of exception day.');
|
||||
});
|
||||
|
||||
|
||||
|
||||
DB::table('collecte_exceptions')
|
||||
->where('comment', 'Jour férié')
|
||||
->update(['type' => $ferie]);
|
||||
|
||||
DB::table('collecte_exceptions')
|
||||
->where('comment', '<>', 'Jour férié')
|
||||
->update(['type' => $other]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('collecte_exceptions', function (Blueprint $table) {
|
||||
$table->dropColumn('type');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
<template>
|
||||
<div>
|
||||
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||
<div
|
||||
class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||
<h1 class="h2">Jours Exception - <small class="text-muted">Fermetures exceptionnelles</small></h1>
|
||||
<transition name="fade">
|
||||
<span class="float-right text-success" v-show="processing">{{ response }}</span>
|
||||
|
|
@ -14,16 +15,24 @@
|
|||
</div>
|
||||
<table class="table table-bordered text-center">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Jour</th>
|
||||
<th scope="col">Commentaire</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="col">Jour</th>
|
||||
<th scope="col">Commentaire</th>
|
||||
<th scope="col">Type</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(item, index) in datas" v-bind:key="item.id">
|
||||
<td><input class="form-control form-control-sm" v-model="item.date" type="date" required></td>
|
||||
<td><input class="form-control form-control-sm" v-model="item.comment" type="text"></td>
|
||||
<td>
|
||||
<select class="form-control form-control-sm" v-model="item.type">
|
||||
<option v-for="(option, index) in exceptionType" :key="index" :value="option.value">
|
||||
{{ option.label }}
|
||||
</option>
|
||||
</select>
|
||||
</td>
|
||||
<td><button @click="removeItem(index)" class="btn btn-danger btn-sm">Supprimer</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
@ -35,79 +44,85 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
mounted() {
|
||||
console.log('CreneauxExceptions Component mounted.');
|
||||
this.datas = JSON.parse(this.dbdatas);
|
||||
},
|
||||
props: [
|
||||
'name',
|
||||
'dbdatas',
|
||||
'magasinId'
|
||||
],
|
||||
data() {
|
||||
return {
|
||||
datas: [],
|
||||
response: null,
|
||||
processing: false
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
export default {
|
||||
mounted() {
|
||||
console.log('CreneauxExceptions Component mounted.');
|
||||
this.datas = JSON.parse(this.dbdatas);
|
||||
this.exceptionType = JSON.parse(this.exceptionTypeData);
|
||||
},
|
||||
props: [
|
||||
'name',
|
||||
'dbdatas',
|
||||
'magasinId',
|
||||
'exceptionTypeData'
|
||||
],
|
||||
data() {
|
||||
return {
|
||||
datas: [],
|
||||
exceptionType: [],
|
||||
response: null,
|
||||
processing: false
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
||||
},
|
||||
methods: {
|
||||
newItem() {
|
||||
this.datas.push({ date: '', comment: '', type: this.exceptionType.length > 0 ? this.exceptionType[0].value : '', magasin_id: this.magasinId });
|
||||
},
|
||||
methods: {
|
||||
newItem() {
|
||||
this.datas.push({date: '', comment: '', magasin_id: this.magasinId});
|
||||
},
|
||||
removeItem(index) {
|
||||
if (this.datas[index]['id'] !== undefined) {
|
||||
this.processing = true;
|
||||
axios.post('/bo/ajax/delete-creneaux-exception', {
|
||||
id: this.datas[index]['id'],
|
||||
}).then(
|
||||
(response) => {
|
||||
this.response = response.data;
|
||||
this.processing = false;
|
||||
}
|
||||
)
|
||||
removeItem(index) {
|
||||
if (this.datas[index]['id'] !== undefined) {
|
||||
this.processing = true;
|
||||
axios.post('/bo/ajax/delete-creneaux-exception', {
|
||||
id: this.datas[index]['id'],
|
||||
}).then(
|
||||
(response) => {
|
||||
this.response = response.data;
|
||||
this.processing = false;
|
||||
}
|
||||
)
|
||||
.catch(function (error) {
|
||||
console.log(error);
|
||||
alert('Erreur lors de la suppression.');
|
||||
this.processing = false;
|
||||
});
|
||||
this.datas.splice(index, 1);
|
||||
} else {
|
||||
this.datas.splice(index, 1);
|
||||
this.datas.splice(index, 1);
|
||||
} else {
|
||||
this.datas.splice(index, 1);
|
||||
}
|
||||
},
|
||||
saveData() {
|
||||
this.processing = true;
|
||||
this.response = "En cours de sauvegarde..."
|
||||
axios.post('/bo/ajax/save-creneaux-exception', {
|
||||
collecte_exception: this.datas,
|
||||
}).then(
|
||||
(response) => {
|
||||
this.datas = response.data;
|
||||
this.response = "Sauvegarde terminée !";
|
||||
this.processing = false;
|
||||
}
|
||||
},
|
||||
saveData() {
|
||||
this.processing = true;
|
||||
this.response = "En cours de sauvegarde..."
|
||||
axios.post('/bo/ajax/save-creneaux-exception', {
|
||||
collecte_exception: this.datas,
|
||||
}).then(
|
||||
(response) => {
|
||||
this.datas = response.data;
|
||||
this.response = "Sauvegarde terminée !";
|
||||
this.processing = false;
|
||||
}
|
||||
)
|
||||
)
|
||||
.catch(function (error) {
|
||||
console.log(error);
|
||||
this.response = "Erreur lors de la sauvegarde.";
|
||||
this.processing = false;
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.fade-enter-active, .fade-leave-active {
|
||||
transition: opacity .5s;
|
||||
}
|
||||
.fade-enter, .fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
.fade-enter-active,
|
||||
.fade-leave-active {
|
||||
transition: opacity .5s;
|
||||
}
|
||||
|
||||
.fade-enter,
|
||||
.fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -1,16 +1,17 @@
|
|||
@extends('layouts.bo-layout')
|
||||
|
||||
@section('content')
|
||||
<form action="{{route('bo.magasins.update', $magasin->id)}}" method="POST" enctype="multipart/form-data">
|
||||
<form action="{{ route('bo.magasins.update', $magasin->id) }}" method="POST" enctype="multipart/form-data">
|
||||
@method('PUT')
|
||||
@csrf
|
||||
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||
<h1 class="h2"><a href="{{route('bo.magasins.index')}}" class="h2 text-decoration-none"><</a> Magasin <small class="text-muted">Modification</small></h1>
|
||||
<div class="d-flex justify-content-between flex-md-nowrap align-items-center border-bottom mb-3 flex-wrap pb-2 pt-3">
|
||||
<h1 class="h2"><a class="h2 text-decoration-none" href="{{ route('bo.magasins.index') }}">
|
||||
Magasin </a> <small class="text-muted">Modification</small></h1>
|
||||
@if (session('success'))
|
||||
<span class="float-center text-success">{{ session('success') }}</span>
|
||||
@endif
|
||||
<div class="btn-toolbar mb-2 mb-md-0">
|
||||
<button type="submit" class="btn btn-sm btn-primary">Enregistrer</a>
|
||||
<div class="btn-toolbar mb-md-0 mb-2">
|
||||
<button class="btn btn-sm btn-primary" type="submit">Enregistrer</a>
|
||||
</div>
|
||||
</div>
|
||||
@if ($errors->any())
|
||||
|
|
@ -25,66 +26,88 @@
|
|||
<div class="row">
|
||||
<div class="form-group col">
|
||||
<label for="name">Nom *</label>
|
||||
<input type="text" id="name" name="name" class="form-control" placeholder="Nom *" value="{{ old('name',$magasin->name) }}" required>
|
||||
<input class="form-control" id="name" name="name" type="text" value="{{ old('name', $magasin->name) }}"
|
||||
placeholder="Nom *" required>
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
<a class="btn btn-sm btn-primary" href="{{route('bo.creneaux.settings', $magasin->id)}}">Editer Créneaux de collecte</a>
|
||||
<a class="btn btn-sm btn-primary" href="{{ route('bo.creneaux.settings', $magasin->id) }}">Editer Créneaux de collecte</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Adresse *</label>
|
||||
<input type="text" id="address" name="address" class="form-control" placeholder="Adresse *" value="{{ old('address',$magasin->address) }}" required>
|
||||
<input class="form-control" id="address" name="address" type="text" value="{{ old('address', $magasin->address) }}"
|
||||
placeholder="Adresse *" required>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="form-group col">
|
||||
<label>Code postal *</label>
|
||||
<input type="text" id="postcode" name="postcode" class="form-control" placeholder="Code postal *" value="{{ old('postcode',$magasin->postcode) }}" required>
|
||||
<input class="form-control" id="postcode" name="postcode" type="text" value="{{ old('postcode', $magasin->postcode) }}"
|
||||
placeholder="Code postal *" required>
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
<label>Ville *</label>
|
||||
<input type="text" id="city" name="city" class="form-control" placeholder="Ville *" value="{{ old('city',$magasin->city) }}" required>
|
||||
<input class="form-control" id="city" name="city" type="text" value="{{ old('city', $magasin->city) }}"
|
||||
placeholder="Ville *" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Téléphone</label>
|
||||
<input type="text" id="phone" name="phone" class="form-control" placeholder="Téléphone" value="{{ old('phone',$magasin->phone) }}">
|
||||
<input class="form-control" id="phone" name="phone" type="text" value="{{ old('phone', $magasin->phone) }}"
|
||||
placeholder="Téléphone">
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="form-group col">
|
||||
<label>Latitude</label>
|
||||
<input type="text" id="latitude" name="latitude" class="form-control" placeholder="Latitude" value="{{ old('latitude',$magasin->latitude) }}">
|
||||
<input class="form-control" id="latitude" name="latitude" type="text" value="{{ old('latitude', $magasin->latitude) }}"
|
||||
placeholder="Latitude">
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
<label>Longitude</label>
|
||||
<input type="text" id="longitude" name="longitude" class="form-control" placeholder="Longitude" value="{{ old('longitude',$magasin->longitude) }}">
|
||||
<input class="form-control" id="longitude" name="longitude" type="text" value="{{ old('longitude', $magasin->longitude) }}"
|
||||
placeholder="Longitude">
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||
<div class="d-flex justify-content-between flex-md-nowrap align-items-center border-bottom mb-3 flex-wrap pb-2 pt-3">
|
||||
<h2><small class="text-muted">Google Maps</small></h2>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Embed href</label>
|
||||
<input type="text" id="gmaps_embed_href" name="gmaps_embed_href" class="form-control" placeholder="url cible pour les iframes" value="{{ old('gmaps_embed_href',$magasin->gmaps_embed_href) }}">
|
||||
<input class="form-control" id="gmaps_embed_href" name="gmaps_embed_href" type="text"
|
||||
value="{{ old('gmaps_embed_href', $magasin->gmaps_embed_href) }}" placeholder="url cible pour les iframes">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Lien direct</label>
|
||||
<input type="text" id="gmaps_link_href" name="gmaps_link_href" class="form-control" placeholder="url vers google maps" value="{{ old('gmaps_link_href',$magasin->gmaps_link_href) }}">
|
||||
<input class="form-control" id="gmaps_link_href" name="gmaps_link_href" type="text"
|
||||
value="{{ old('gmaps_link_href', $magasin->gmaps_link_href) }}" placeholder="url vers google maps">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>placeID</label>
|
||||
<input type="text" id="gmaps_placeid" name="gmaps_placeid" class="form-control" placeholder="placeID google maps (necessite une clé d'API)" value="{{ old('gmaps_placeid',$magasin->gmaps_placeid) }}">
|
||||
<input class="form-control" id="gmaps_placeid" name="gmaps_placeid" type="text"
|
||||
value="{{ old('gmaps_placeid', $magasin->gmaps_placeid) }}" placeholder="placeID google maps (necessite une clé d'API)">
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="form-group col"></div>
|
||||
<div class="form-group col text-center">
|
||||
<button type="submit" class="btn btn-sm btn-primary">Enregistrer les règlages</button>
|
||||
<button class="btn btn-sm btn-primary" type="submit">Enregistrer les règlages</button>
|
||||
</div>
|
||||
<div class="form-group col"></div>
|
||||
</div>
|
||||
</form>
|
||||
<creneaux-exceptions dbdatas='@json($exceptionsCollecte)' magasin-id='{{$magasin->id}}'></creneaux-exceptions>
|
||||
|
||||
@php
|
||||
$exceptionType = collect(\App\Enums\ExceptionDayType::toLabels())
|
||||
->map(function ($label, $key) {
|
||||
return [
|
||||
'label' => $label,
|
||||
'value' => \App\Enums\ExceptionDayType::toValues()[$key],
|
||||
];
|
||||
})
|
||||
->values();
|
||||
@endphp
|
||||
|
||||
<creneaux-exceptions exception-type-data='@json($exceptionType)' dbdatas='@json($exceptionsCollecte)'
|
||||
magasin-id='{{ $magasin->id }}'></creneaux-exceptions>
|
||||
@endsection
|
||||
|
||||
@section('scripts')
|
||||
|
||||
@endsection
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue