279 lines
14 KiB
PHP
279 lines
14 KiB
PHP
@extends('bo.layouts.layout')
|
|
|
|
@section('title', sprintf('%s - %s %s %s', Str::ucfirst(__('crud.actions.edit')), Str::ucfirst(trans_choice('models.classes.shops', 1)),
|
|
Str::ucfirst(trans_choice('models.classes.pickup-exceptions', \INF)), $shop->name))
|
|
|
|
@section('breadcrumb', request()->route()->getName())
|
|
@php view()->share('brParam', $shop) @endphp
|
|
|
|
@section('content')
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<div class="row">
|
|
<div class="col">
|
|
<h1 class="h3">
|
|
<a class="btn btn-sm btn-primary" href="{{ route('bo.shops.index') }}"><i class="fas fa-arrow-left"></i></a>
|
|
{{ sprintf(
|
|
'%s - %s %s %s',
|
|
Str::ucfirst(__('crud.actions.edit')),
|
|
Str::ucfirst(trans_choice('models.classes.shops', 1)),
|
|
Str::ucfirst(trans_choice('models.classes.pickup-exceptions', \INF)),
|
|
$shop->name,
|
|
) }}
|
|
</h1>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="card-body">
|
|
<form action="{{ route('bo.shops.pickup-exceptions.update', $shop) }}" method="POST">
|
|
@csrf
|
|
{{ method_field('PUT') }}
|
|
|
|
<div class="row">
|
|
<div class="col">
|
|
<fieldset class="mb-3 border p-3">
|
|
<legend>
|
|
<i class="fas fa-calendar-xmark text-primary me-2"></i>
|
|
{{ Str::ucfirst(trans_choice('models.classes.pickup-exceptions', \INF)) }}
|
|
</legend>
|
|
|
|
<div class="row mb-3">
|
|
<div class="col">
|
|
<span class="h6 text-info text-decoration-underline">
|
|
{!! clean(
|
|
__('The usual pickup day is :date', [
|
|
'date' => '<strong>' . $pickupPeriod->getEndDate()->copy()->setTimezone('Europe/Paris')->translatedFormat('l') . '</strong>',
|
|
]),
|
|
) !!}
|
|
</span><br>
|
|
<span class="h6 text-info text-decoration-underline">
|
|
{!! clean(
|
|
__('The usual limit to pass an order is :date', [
|
|
'date' => '<strong>' . $pickupPeriod->getStartDate()->copy()->setTimezone('Europe/Paris')->translatedFormat('l H\h:i') . '</strong>',
|
|
]),
|
|
) !!}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row mb-3">
|
|
<div class="col-12 form-group">
|
|
<span class="col-form-label mb-2">
|
|
<b>{{ __('Select') . ' ' . Str::ucfirst(trans_choice('models.classes.pickup-exceptions', 1)) }}*</b>
|
|
</span><br>
|
|
|
|
@include('bo.modules.input-error', [
|
|
'inputName' => 'pickup-exceptions',
|
|
'helper' => __(
|
|
'Check all collection exceptions that concern this store. Use the options button to configure postponements if necessary.'),
|
|
])
|
|
|
|
<div class="row g-3 mt-2">
|
|
@forelse($pickupExceptions as $dto)
|
|
@php
|
|
$exception = $dto->pickupException;
|
|
$associatedException = $shop->pickupExceptions->firstWhere('id', $exception->id);
|
|
|
|
$isChecked = in_array($exception->id, old('pickup-exceptions', $shop->pickupExceptions->pluck('id')->toArray()));
|
|
|
|
$replacement_date = old(
|
|
"replacement_date.{$exception->id}",
|
|
$associatedException?->pivot?->replacement_date?->format('Y-m-d'),
|
|
);
|
|
$order_deadline_at = old(
|
|
"order_deadline_at.{$exception->id}",
|
|
Date::toLocalInput($associatedException?->pivot?->order_deadline_at),
|
|
);
|
|
|
|
$noReplacement = $isChecked && empty($associatedException?->pivot?->replacement_date);
|
|
|
|
$isCritical = $dto->missingSubsitute || $dto->passedDeadline;
|
|
|
|
$criticalReason = $dto->missingSubsitute
|
|
? __('No substitute days have been set up. No time slots will be generated for this week.')
|
|
: __('The order deadline has passed. This item will no longer be available for purchase.');
|
|
@endphp
|
|
|
|
<div class="col-12 col-md-6 col-lg-4">
|
|
<div
|
|
class="bg-light d-flex flex-column justify-content-between {{ $isCritical ? 'border-danger border-2' : '' }} rounded border p-3 shadow-sm">
|
|
|
|
<div class="d-flex justify-content-between align-items-start w-100">
|
|
<label class="form-check w-100 m-0 cursor-pointer" for="exception-{{ $exception->id }}">
|
|
<input class="form-check-input exception-checkbox me-2" id="exception-{{ $exception->id }}"
|
|
name="pickup-exceptions[]" data-target="fields-{{ $exception->id }}"
|
|
data-btn="btn-toggle-{{ $exception->id }}" type="checkbox" value="{{ $exception->id }}"
|
|
@checked($isChecked)>
|
|
|
|
<span class="form-check-label d-block text-wrap">
|
|
<strong>{{ $exception->label }}</strong>
|
|
|
|
<small class="d-block text-muted mt-1">
|
|
<i class="fas fa-calendar-day me-1"></i>
|
|
{{ Date::forHumansDate($exception->date) }}
|
|
@if ($dto->isPickupDay)
|
|
<small class="badge bg-secondary-subtle text-secondary-emphasis ms-1">
|
|
{{ __('Pickup day') }}
|
|
</small>
|
|
@endif
|
|
</small>
|
|
|
|
@if ($isCritical)
|
|
<span class="d-block text-danger small fw-bold mt-2" data-bs-toggle="tooltip"
|
|
title="{{ $criticalReason }}">
|
|
<i class="fa-solid fa-triangle-exclamation text-danger me-1"></i> {{ __('Blocked week') }}
|
|
</span>
|
|
@elseif ($noReplacement)
|
|
<span class="d-block text-info small fw-bold mt-2">
|
|
<i class="fa-solid fa-circle-info text-info me-1"></i> {{ __('No replacement date configured') }}
|
|
</span>
|
|
@elseif($associatedException?->pivot?->replacement_date)
|
|
<span class="d-block text-primary small fw-bold mt-2">
|
|
<i class="fa-solid fa-circle-info me-1"></i>
|
|
<span>{{ __('Replacement date :date', [
|
|
'date' => Date::forHumansDate($associatedException?->pivot?->replacement_date),
|
|
]) }}</span>
|
|
</span>
|
|
@endif
|
|
</label>
|
|
|
|
<button
|
|
class="btn btn-sm {{ $isCritical ? 'btn-danger' : 'btn-outline-secondary' }} {{ $isChecked ? '' : 'disabled opacity-25' }} ms-2"
|
|
id="btn-toggle-{{ $exception->id }}" data-bs-toggle="collapse" data-bs-target="#fields-{{ $exception->id }}"
|
|
type="button">
|
|
<i class="fas fa-cog"></i>
|
|
</button>
|
|
</div>
|
|
<!-- COLLAPSIBLE -->
|
|
<div class="{{ $isChecked && $isCritical ? 'show' : '' }} border-top collapse mt-3 pt-3"
|
|
id="fields-{{ $exception->id }}">
|
|
|
|
@if ($isCritical)
|
|
<div class="alert alert-danger rounded-1 small mb-2 px-2 py-1">
|
|
<i class="fas fa-circle-exclamation me-1"></i>
|
|
<small>{{ $criticalReason }}</small>
|
|
</div>
|
|
@else
|
|
<div class="alert alert-info rounded-1 mb-2 px-2 py-1">
|
|
<i class="fas fa-circle-info me-1"></i>
|
|
<small>{{ __('Please note: The scheduled postponement is a one-time event and will not repeat automatically.') }}</small>
|
|
</div>
|
|
@endif
|
|
|
|
<!-- REPLACEMENT_DATE -->
|
|
<div class="mb-2">
|
|
<label class="form-label small fw-bold text-secondary mb-1" for="{{ "replacement-date-{$exception->id}" }}">
|
|
<i class="fas fa-calendar-plus me-1"></i>
|
|
<span>{{ Str::ucfirst(__('validation.custom.attributes.replacement_date')) }}</span>
|
|
</label>
|
|
<div class="input-group input-group-sm">
|
|
<input class="form-control {{ $isCritical && empty($replacement_date) ? 'is-invalid' : '' }}"
|
|
id="{{ "replacement-date-{$exception->id}" }}" name="replacement_date[{{ $exception->id }}]"
|
|
type="date" value="{{ $replacement_date }}">
|
|
<button class="btn btn-outline-secondary btn-clean-input" type="button" title="{{ __('Clear') }}">
|
|
<i class="fas fa-eraser"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ORDER_DEADLINE_AT -->
|
|
<div>
|
|
<label class="form-label small fw-bold text-secondary mb-1" for="{{ "order-deadline-at-{$exception->id}" }}">
|
|
<i class="fas fa-hourglass-end me-1"></i>
|
|
<span>{{ Str::ucfirst(__('validation.custom.attributes.order_deadline_at')) }}</span>
|
|
</label>
|
|
<div class="input-group input-group-sm">
|
|
<input class="form-control" id="{{ "order-deadline-at-{$exception->id}" }}"
|
|
name="order_deadline_at[{{ $exception->id }}]" type="datetime-local"
|
|
value="{{ $order_deadline_at }}">
|
|
<button class="btn btn-outline-secondary btn-clean-input" type="button" title="{{ __('Clear') }}">
|
|
<i class="fas fa-eraser"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
@empty
|
|
<div class="col-12 py-4 text-center">
|
|
<p class="text-muted mb-0">{{ __('No pickup exception has been created for now.') }}</p>
|
|
</div>
|
|
@endforelse
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</fieldset>
|
|
</div>
|
|
</div>
|
|
|
|
<input id="client-timezone" name="client_timezone" type="hidden">
|
|
|
|
<div class="text-center">
|
|
<span class="d-block mb-3">
|
|
<span class="badge text-bg-info">{{ __('crud.helpers.required_fields_with_aster') }}</span>
|
|
</span>
|
|
<button class="btn btn-primary" id="submit-btn" type="submit"><i class="fa fa-floppy-disk"></i>
|
|
<span class="d-none d-sm-inline" data-bs-toggle="tooltip"
|
|
title="{{ Str::ucfirst(__('crud.actions.save')) }}">{{ Str::ucfirst(__('crud.actions.save')) }}</span></button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
@endsection
|
|
|
|
@push('scripts')
|
|
<script nonce="{{ Vite::cspNonce() }}">
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
document.getElementById('client-timezone').value = tz;
|
|
});
|
|
</script>
|
|
@endpush
|
|
|
|
@push('scripts')
|
|
<script nonce="{{ Vite::cspNonce() }}">
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const checkboxes = document.querySelectorAll('.exception-checkbox');
|
|
const cleanButtons = document.querySelectorAll('.btn-clean-input');
|
|
|
|
checkboxes.forEach(checkbox => {
|
|
const targetId = checkbox.getAttribute('data-target');
|
|
const buttonId = checkbox.getAttribute('data-btn');
|
|
|
|
const targetDiv = document.getElementById(targetId);
|
|
const toggleBtn = document.getElementById(buttonId);
|
|
|
|
const bsCollapse = new bootstrap.Collapse(targetDiv, {
|
|
toggle: false
|
|
});
|
|
|
|
checkbox.addEventListener('change', function() {
|
|
if (this.checked) {
|
|
toggleBtn.classList.remove('disabled', 'opacity-25');
|
|
} else {
|
|
toggleBtn.classList.add('disabled', 'opacity-25');
|
|
toggleBtn.setAttribute('aria-expanded', 'false');
|
|
|
|
bsCollapse.hide();
|
|
|
|
targetDiv.addEventListener('hidden.bs.collapse', function onHidden() {
|
|
targetDiv.querySelectorAll('input').forEach(input => input.value = '');
|
|
targetDiv.removeEventListener('hidden.bs.collapse', onHidden);
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
cleanButtons.forEach(button => {
|
|
button.addEventListener('click', function() {
|
|
const inputField = this.closest('.input-group').querySelector('input');
|
|
if (inputField) {
|
|
inputField.value = '';
|
|
inputField.dispatchEvent(new Event('change'));
|
|
}
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
@endpush
|