ldc-cocotte/resources/views/bo/orders/index.blade.php
Jérémy Munsch 3a3d993d7c
feat: ✨ Closes #46
Add orders filter with: a search bar, date filters
2024-05-15 16:58:17 +02:00

306 lines
15 KiB
PHP

@extends('layouts.bo-layout')
@section('content')
<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">Commandes @if (isset($today))
à retirer aujourd'hui
@endif
</h1>
@if (session('success'))
<span class="float-center text-success">{{ session('success') }}</span>
@endif
</div>
<form class="container-fluid" id="searchForm" action="/{{ request()->path() }}">
@include('bo.modules.search-bar-orders')
@if (request()->routeIs('bo.orders'))
<div class="row mb-1">
<div class="col-xl-6 g-0">
<div class="input-group mb-2">
<span class="input-group-text">{{ __('Date de commande') }}</span>
<div class="input-group-text">
<div class="form-check form-switch">
<input class="form-check-input" id="date-order-switch" name="date-order-switch" type="checkbox" value="1"
role="switch" @if (old('date-order-switch', request()->input('date-order-switch')) ? true : false) checked @endif>
<label class="form-check-label" data-bs-toggle="tooltip" for="date-order-switch"
title="{{ __('Rechercher en utilisant une plage de dates') }}">{{ __('Plage') }}</label>
</div>
</div>
<label class="input-group-text" for="date-order-start">{{ __('Du') }}</label>
<input class="form-control w-md-auto" id="date-order-start" name="date-order-start" type="date"
value="{{ old('date-order-start', request()->input('date-order-start')) }}">
<label class="input-group-text d-none flex-50" data-toggle="date-order-end"
for="date-order-end">{{ __('Jusqu\'au') }}</label>
<input class="form-control d-none w-md-auto" id="date-order-end" name="date-order-end" data-toggle="date-order-end"
type="date" value="{{ old('date-order-end', request()->input('date-order-end')) }}">
</div>
@include('modules.input-error', ['inputName' => 'date-order-start'])
@include('modules.input-error', ['inputName' => 'date-order-end'])
</div>
<div class="col">
<div class="input-group mb-2">
<span class="input-group-text">{{ __('Date de retrait') }}</span>
<div class="input-group-text">
<div class="form-check form-switch">
<input class="form-check-input" id="date-retrait-switch" name="date-retrait-switch" type="checkbox"
value="1" role="switch" @if (old('date-retrait-switch', request()->input('date-retrait-switch')) ? true : false) checked @endif>
<label class="form-check-label" data-bs-toggle="tooltip" for="date-retrait-switch"
title="{{ __('Rechercher en utilisant une plage de dates') }}">{{ __('Plage') }}</label>
</div>
</div>
<label class="input-group-text" for="date-retrait-start">{{ __('Du') }}</label>
<input class="form-control w-md-auto" id="date-retrait-start" name="date-retrait-start" type="date"
value="{{ old('date-retrait-start', request()->input('date-retrait-start')) }}">
<label class="input-group-text d-none flex-50" data-toggle="date-retrait-end"
for="date-retrait-end">{{ __('Jusqu\'au') }}</label>
<input class="form-control d-none w-md-auto" id="date-retrait-end" name="date-retrait-end"
data-toggle="date-retrait-end" type="date"
value="{{ old('date-retrait-end', request()->input('date-retrait-end')) }}">
</div>
@include('modules.input-error', ['inputName' => 'date-retrait-start'])
@include('modules.input-error', ['inputName' => 'date-retrait-end'])
</div>
</div>
@push('scripts')
<script @if (!empty($nonce)) nonce="{{ $nonce }} @endif">
document.getElementById('searchbar-delete').addEventListener('click', function(e) {
e.preventDefault();
window.location = '/{{ request()->path() }}';
});
</script>
@endpush
@endif
</form>
<div class="row mb-3">
<div class="col">
<span class="fw-bold">{{ __('Obligatoire') }}</span>
</div>
</div>
<div class="table-responsive">
<table class="table">
<thead>
<th scope="col"><span>{{ __('Client') }}</span>&nbsp;
@include('bo.modules.sorter', ['colname' => 'customer_id', 'list' => 'orders'])
</th>
<th scope="col">{{ __('Référence') }}</th>
<th scope="col">
<span>{{ __('Date commande') }}</span>&nbsp;
@include('bo.modules.sorter', ['colname' => 'date', 'list' => 'orders'])
</th>
<th scope="col">{{ __('Total en €') }}</th>
<th scope="col"><span>{{ __('Date de retrait') }}</span>&nbsp;
@include('bo.modules.sorter', ['colname' => 'date_retrait', 'list' => 'orders'])
</th>
<th scope="col">
<span>{{ __('Point de retrait') }}</span>&nbsp;
@include('bo.modules.sorter', ['colname' => 'magasin_id', 'list' => 'orders'])
</th>
<th scope="col">
<span>{{ __('Statut') }}</span>&nbsp;
@include('bo.modules.sorter', ['colname' => 'status_id', 'list' => 'orders'])
</th>
<th><a class="btn btn-sm btn-dark float-right mr-2" href="{{ route(Route::currentRouteName(), ['rst' => 1]) }}">Réinitialiser
le
tri</a></th>
</thead>
<tbody>
@foreach ($orders as $order)
<tr>
<td>
{{-- <a data-fancybox data-trigger="customer-info" data-type="ajax" data-src="{{ route('bo.get-customer-info', $order->customer->id) }}" data-src="#customer-info" href="javascript:;">
Infos Client
</a> --}}
<a class="ajax-tippy-cust" id="tippy-{{ $order->customer->id }}" data-custid="{{ $order->customer->id }}"
href="javascript:">Infos Client</a>
</td>
<td>{{ $order->reference }}</td>
<td>{{ \Carbon\Carbon::parse($order->date)->format('d/m/Y') }}</td>
<td>{{ number_format($order->total, 2, ',', ' ') }}€</td>
<td>
@if (!empty($order->timeslot))
{{ optional($order->timeslot->day)->format('d/m/Y') }}
{{ optional($order->timeslot->time)->format('H:i') }}
@endif
</td>
<td>
@if (!empty($order->timeslot))
{{-- <a data-fancybox data-trigger="magasin-info" data-type="ajax" data-src="{{ route('bo.get-magasin-info', $order->timeslot->magasin->id) }}" data-src="#magasin-info" href="javascript:;">
{{$order->timeslot->magasin->name}}
</a> --}}
<a class="ajax-tippy-shop" id="shop-{{ $order->timeslot->magasin->id }}"
data-shopid="{{ $order->timeslot->magasin->id }}"
href="javascript:">{{ $order->timeslot->magasin->name }}</a>
@endif
</td>
<td>{{ $order->status->label }}</td>
<td class="text-center">
{{-- L'id du status 6 est le status "Retirée", la dernière étape d'une commande --}}
<a class="btn btn-sm btn-primary" href="{{ route('bo.order-detail', $order->reference) }}"><i
class="fas fa-info"></i></a>
@if ($order->status_id < 6 && $order->status_id >= 3)
<a class="btn btn-sm btn-primary" href="{{ route('bo.change-order-status', $order->reference) }}"><i
class="fas fa-forward"></i></a>
@endif
@if ($order->status_id < 6)
<a class="btn btn-sm btn-danger" href="{{ route('bo.cancel-order', $order->reference) }}"
onclick="return confirm('Êtes-vous sûr(e) ?')"><i class="fas fa-times"></i></a>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@if ($orders instanceof \Illuminate\Pagination\LengthAwarePaginator)
{{ $orders->appends($_GET)->links() }}
@endif
@endsection
@section('scripts')
<script type="text/javascript">
var tippyCustContents = [];
var tippyShopContents = [];
var customerInfo = [];
//to make sure we fetch only one at a time
var _fetchingCustInfo = false;
function loadCustInfo(element) {
if (!_fetchingCustInfo) {
if (typeof customerInfo[element.dataset.custid] === 'undefined') {
//fetch only if we don't already have the data
_fetchingCustInfo = true;
return fetch('/bo/customer-info/' + element.dataset.custid + '/json')
.then(response => {
return response.json();
})
.then(data => {
customerInfo[element.dataset.custid] = data;
element.innerHTML = data.firstname + ' ' + data.lastname;
_fetchingCustInfo = false;
})
} else {
//put text
element.innerHTML = customerInfo[element.dataset.custid].firstname + ' ' + customerInfo[element.dataset.custid].lastname;
//leave
return;
}
} else {
setTimeout(function() {
loadCustInfo(element)
}, 250);
}
}
clientLinks = $('.ajax-tippy-cust');
clientLinks.each(function(index, element) {
return loadCustInfo(element);
});
tippy('.ajax-tippy-cust', {
content: '<i class="fas fa-circle-notch fa-spin"></i>',
allowHTML: true,
theme: 'light-border',
//trigger: "click",
//hide upon clicking
//hideOnClick: true,
onCreate(instance) {
// Setup our own custom state properties
instance._isFetching = false;
instance._src = null;
instance._error = null;
instance._custID = instance.reference.dataset.custid;
},
onShow(instance) {
if (instance._isFetching || instance._src || instance._error) {
return;
}
if (typeof tippyCustContents[instance._custID] === 'undefined') {
//carry on
} else {
instance.setContent(tippyCustContents[instance._custID]);
return;
}
instance._isFetching = true;
fetch('/bo/customer-info/' + instance._custID + '/tippy')
.then(response => {
return response.text();
})
.then(data => {
instance.setContent(data);
//save for reusability
tippyCustContents[instance._custID] = data;
})
.catch((error) => {
// Fallback if the network request failed
instance.setContent(`Request failed. ${error}`);
})
.finally(() => {
instance._isFetching = false;
});
},
onHidden(instance) {
instance.setContent('<i class="fas fa-circle-notch fa-spin"></i>');
// Unset these properties so new network requests can be initiated
instance._src = null;
instance._error = null;
},
});
tippy('.ajax-tippy-shop', {
content: '<i class="fas fa-circle-notch fa-spin"></i>',
allowHTML: true,
theme: 'light-border',
//trigger: "click",
//hide upon clicking
//hideOnClick: true,
onCreate(instance) {
// Setup our own custom state properties
instance._isFetching = false;
instance._src = null;
instance._error = null;
instance._shopID = instance.reference.dataset.shopid;
},
onShow(instance) {
if (instance._isFetching || instance._src || instance._error) {
return;
}
if (typeof tippyShopContents[instance._shopID] === 'undefined') {
//carry on
} else {
instance.setContent(tippyShopContents[instance._shopID]);
return;
}
instance._isFetching = true;
fetch('/bo/magasin-info/' + instance._shopID + '/tippy')
.then(response => {
return response.text();
})
.then(data => {
instance.setContent(data);
//save for reusability
tippyShopContents[instance._shopID] = data;
})
.catch((error) => {
// Fallback if the network request failed
instance.setContent(`Request failed. ${error}`);
})
.finally(() => {
instance._isFetching = false;
});
},
onHidden(instance) {
instance.setContent('<i class="fas fa-circle-notch fa-spin"></i>');
// Unset these properties so new network requests can be initiated
instance._src = null;
instance._error = null;
},
});
</script>
@endsection