ldc-boutique-cnc/resources/views/bo/orders/index.blade.php
Olivier Legat 4873cd7fc2 fix todays orders
localise sorting to current route
2022-12-13 13:55:42 +01:00

270 lines
12 KiB
PHP

@extends('layouts.bo-layout')
@section('content')
<div class="d-flex flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2 pe-5">{{ __('Commandes') }} @if (isset($today)) <br>{{ __('à retirer aujourd\'hui') }} @endif</h1>
@if (!isset($today))
<form method="GET">
<div class="row">
<div class="col-6">
<label for="filter_status_order" class="col-form-label">Etat de commande</label>
<div class="col">
<select class="form-control" id="filter_status_order" name="filter_status_order">
<option value="" @if ($filter_status_order == '') selected @endif>Tous</option>
@foreach($status_orders as $status_order)
<option value="{{$status_order->id}}" @if ($status_order->id == $filter_status_order) selected @endif>{{$status_order->label}}</option>
@endforeach
</select>
</div>
</div>
<div class="col-6">
<label for="filter_magasin" class="col-form-label">Lieu de retrait</label>
<div class="col">
<select class="form-control" id="filter_magasin" name="filter_magasin">
<option value="" @if ($filter_magasin == '') selected @endif>Tous</option>
@foreach($magasins as $magasin)
<option value="{{$magasin->id}}" @if ($magasin->id == $filter_magasin) selected @endif>{{$magasin->name}}</option>
@endforeach
</select>
</div>
</div>
<div class="col-12">
<div class="row align-items-end">
<div class="col-6">
<label for="filter_reference" class="col-form-label">Référence commande</label>
<div class="col">
<input class="form-control" type="text"
placeholder="Référence commande"
id="filter_reference" name="filter_reference"
value="{{ $filter_reference ?? ''}}">
</div>
</div>
<div class="col-6">
<button class="btn btn-primary">Filtrer</button>
<a class="btn btn-info" href="{{ route('bo.orders') }}">Effacer le filtre</a>
</div>
</div>
</div>
</div>
</form>
@endif
@if (session('success'))
<span class="float-center text-success ms-3">{{ session('success') }}</span>
@endif
</div>
<table class="table">
<thead>
<th scope="col">Client&nbsp;
@include('bo.modules.sorter', ['colname' => 'customer_id', 'list' => 'orders'])
</th>
<th scope="col">Référence</th>
<th scope="col">
Date&nbsp;
@include('bo.modules.sorter', ['colname' => 'date', 'list' => 'orders'])
</th>
<th scope="col">Total en €</th>
<th scope="col">Date de retrait&nbsp;
@include('bo.modules.sorter', ['colname' => 'date_retrait', 'list' => 'orders'])
</th>
<th scope="col">
Point de retrait&nbsp;
@include('bo.modules.sorter', ['colname' => 'magasin_id', 'list' => 'orders'])
</th>
<th scope="col">
Statut&nbsp;
@include('bo.modules.sorter', ['colname' => 'status_id', 'list' => 'orders'])
</th>
<th><a href="{{ route(Route::currentRouteName(), ['rst' => 1]) }}" class="float-right btn btn-sm btn-dark mr-2">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))
{{$order->timeslot->day}} {{$order->timeslot->time}}
@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 href="{{route('bo.order-detail', $order->reference)}}" class="btn btn-sm btn-primary"><i class="fas fa-info"></i></a>
@if ($order->status_id < 6 && $order->status_id >=3 )
<a href="{{route('bo.change-order-status', $order->reference)}}" class="btn btn-sm btn-primary"><i class="fas fa-forward"></i></a>
@endif
@if ($order->status_id < 6)
<a href="{{route('bo.cancel-order', $order->reference)}}" class="btn btn-sm btn-danger" onclick="return confirm('Êtes-vous sûr(e) ?')"><i class="fas fa-times"></i></a>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
@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