tri de la liste des commandes
commande à retirer aujourd'hui
This commit is contained in:
parent
31683e2648
commit
c5ee8af6ef
6 changed files with 176 additions and 13 deletions
|
|
@ -6,16 +6,14 @@ use App\Http\Controllers\Controller;
|
|||
use App\Models\Order;
|
||||
use App\Models\OrderLine;
|
||||
use App\Models\OrdersProducts;
|
||||
use App\Models\OrdersStatus;
|
||||
use App\Models\Product;
|
||||
use App\Models\Timeslot;
|
||||
use App\Models\Magasin;
|
||||
use App\Http\Requests\SortOrders;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Mail\OrderStatusMail;
|
||||
use App\Mail\OrderConfirmMail;
|
||||
use App\Models\CollecteException;
|
||||
use App\Models\Customers;
|
||||
use App\Models\TimeslotSetting;
|
||||
use App\Models\Setting;
|
||||
use Carbon\Carbon;
|
||||
use Carbon\CarbonImmutable;
|
||||
|
|
@ -31,12 +29,124 @@ class OrdersController extends Controller
|
|||
/**
|
||||
* index of orders (Bo)
|
||||
*/
|
||||
public function index()
|
||||
public function index(SortOrders $request)
|
||||
{
|
||||
$orders = Order::orderBy('date', 'DESC')->get();
|
||||
//$orders = Order::orderBy('date', 'DESC')->get();
|
||||
|
||||
$orders = Order::query();
|
||||
|
||||
|
||||
if ($request->rst) {
|
||||
Session::remove('orders.sort_col');
|
||||
Session::remove('orders.sort_way');
|
||||
}
|
||||
if ($request->sort_col) {
|
||||
Session::put('orders.sort_col', $request->sort_col);
|
||||
Session::save();
|
||||
}
|
||||
if ($request->sort_way) {
|
||||
Session::put('orders.sort_way', $request->sort_way);
|
||||
Session::save();
|
||||
}
|
||||
|
||||
if (Session::has('orders.sort_col') and Session::has('orders.sort_way')) {
|
||||
switch (Session::get('orders.sort_col')) {
|
||||
case 'date':
|
||||
$orders = $orders->orderBy('date', Session::get('orders.sort_way'));
|
||||
break;
|
||||
case 'status_id':
|
||||
$orders = $orders->orderBy('status_id', Session::get('orders.sort_way'));
|
||||
break;
|
||||
case 'magasin_id':
|
||||
$orders = $orders->select('orders.*');
|
||||
$orders = $orders->leftJoin('timeslots', 'timeslots.order_id', '=', 'orders.id');
|
||||
$orders = $orders->leftJoin('magasins', 'timeslots.magasin_id', '=', 'magasins.id');
|
||||
$orders = $orders->orderBy('magasins.id', Session::get('orders.sort_way'));
|
||||
break;
|
||||
case 'date_retrait':
|
||||
$orders = $orders->select('orders.*');
|
||||
$orders = $orders->leftJoin('timeslots', 'timeslots.order_id', '=', 'orders.id');
|
||||
$orders = $orders->orderBy('timeslots.day', Session::get('orders.sort_way'));
|
||||
$orders = $orders->orderBy('timeslots.time', Session::get('orders.sort_way'));
|
||||
break;
|
||||
case 'customer_id':
|
||||
$orders = $orders->orderBy('customer_id', Session::get('orders.sort_way'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->today) {
|
||||
//filter
|
||||
$today = CarbonImmutable::now()->startOfDay();
|
||||
$orders = $orders->whereHas('timeslot', function($q) use($today) {
|
||||
$q->where('day', '=', $today->format('d/m/Y'));
|
||||
});
|
||||
}
|
||||
|
||||
$orders = $orders->paginate(10);
|
||||
|
||||
return view('bo.orders.index', compact('orders'));
|
||||
}
|
||||
|
||||
public function today(SortOrders $request)
|
||||
{
|
||||
//$orders = Order::orderBy('date', 'DESC')->get();
|
||||
|
||||
$orders = Order::query();
|
||||
|
||||
|
||||
if ($request->rst) {
|
||||
Session::remove('orders.sort_col');
|
||||
Session::remove('orders.sort_way');
|
||||
}
|
||||
if ($request->sort_col) {
|
||||
Session::put('orders.sort_col', $request->sort_col);
|
||||
Session::save();
|
||||
}
|
||||
if ($request->sort_way) {
|
||||
Session::put('orders.sort_way', $request->sort_way);
|
||||
Session::save();
|
||||
}
|
||||
|
||||
if (Session::has('orders.sort_col') and Session::has('orders.sort_way')) {
|
||||
switch (Session::get('orders.sort_col')) {
|
||||
case 'date':
|
||||
$orders = $orders->orderBy('date', Session::get('orders.sort_way'));
|
||||
break;
|
||||
case 'status_id':
|
||||
$orders = $orders->orderBy('status_id', Session::get('orders.sort_way'));
|
||||
break;
|
||||
case 'magasin_id':
|
||||
$orders = $orders->select('orders.*');
|
||||
$orders = $orders->leftJoin('timeslots', 'timeslots.order_id', '=', 'orders.id');
|
||||
$orders = $orders->leftJoin('magasins', 'timeslots.magasin_id', '=', 'magasins.id');
|
||||
$orders = $orders->orderBy('magasins.id', Session::get('orders.sort_way'));
|
||||
break;
|
||||
case 'date_retrait':
|
||||
$orders = $orders->select('orders.*');
|
||||
$orders = $orders->leftJoin('timeslots', 'timeslots.order_id', '=', 'orders.id');
|
||||
$orders = $orders->orderBy('timeslots.day', Session::get('orders.sort_way'));
|
||||
$orders = $orders->orderBy('timeslots.time', Session::get('orders.sort_way'));
|
||||
break;
|
||||
case 'customer_id':
|
||||
$orders = $orders->orderBy('customer_id', Session::get('orders.sort_way'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//filter
|
||||
$today = CarbonImmutable::now()->startOfDay();
|
||||
$orders = $orders->whereHas('timeslot', function($q) use($today) {
|
||||
$q->where('day', '=', $today->format('d/m/Y'));
|
||||
});
|
||||
|
||||
|
||||
$orders = $orders->get(); //paginate(20);
|
||||
|
||||
return view('bo.orders.index', compact('orders','today'));
|
||||
}
|
||||
|
||||
/**
|
||||
* action de changement de statut vers l'avant
|
||||
* envoi de mails transctionnels
|
||||
|
|
|
|||
30
app/Http/Requests/SortOrders.php
Normal file
30
app/Http/Requests/SortOrders.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class SortOrders extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'sort_way' => 'sometimes|in:asc,desc',
|
||||
];
|
||||
}
|
||||
}
|
||||
6
resources/views/bo/modules/sorter.blade.php
Normal file
6
resources/views/bo/modules/sorter.blade.php
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
@if(!session($list.'.sort_way') or session($list.'.sort_col') !== $colname or (session($list.'.sort_way') === 'desc' and session($list.'.sort_col') === $colname))
|
||||
<a class="col_sort text-secondary lead asc" href="{{ route('bo.orders', ['sort_col' => $colname, 'sort_way' => 'asc']) }}"> ↓ </a>
|
||||
@endif
|
||||
@if(!session($list.'.sort_way') or session($list.'.sort_col') !== $colname or (session($list.'.sort_way') === 'asc' and session($list.'.sort_col') === $colname))
|
||||
<a class="col_sort text-secondary lead desc" href="{{ route('bo.orders', ['sort_col' => $colname, 'sort_way' => 'desc']) }}"> ↑ </a>
|
||||
@endif
|
||||
|
|
@ -2,21 +2,34 @@
|
|||
|
||||
@section('content')
|
||||
<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">Commandes</h1>
|
||||
<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>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<th scope="col">Utilisateur</th>
|
||||
<th scope="col">Client
|
||||
@include('bo.modules.sorter', ['colname' => 'customer_id', 'list' => 'orders'])
|
||||
</th>
|
||||
<th scope="col">Référence</th>
|
||||
<th scope="col">Date</th>
|
||||
<th scope="col">
|
||||
Date
|
||||
@include('bo.modules.sorter', ['colname' => 'date', 'list' => 'orders'])
|
||||
</th>
|
||||
<th scope="col">Total en €</th>
|
||||
<th scope="col">Date de retrait</th>
|
||||
<th scope="col">Point de retrait</th>
|
||||
<th scope="col">Status</th>
|
||||
<th></th>
|
||||
<th scope="col">Date de retrait
|
||||
@include('bo.modules.sorter', ['colname' => 'date_retrait', 'list' => 'orders'])
|
||||
</th>
|
||||
<th scope="col">
|
||||
Point de retrait
|
||||
@include('bo.modules.sorter', ['colname' => 'magasin_id', 'list' => 'orders'])
|
||||
</th>
|
||||
<th scope="col">
|
||||
Statut
|
||||
@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)
|
||||
|
|
@ -58,7 +71,9 @@
|
|||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@if($orders instanceof \Illuminate\Pagination\LengthAwarePaginator )
|
||||
{{ $orders->appends($_GET)->links() }}
|
||||
@endif
|
||||
@endsection
|
||||
|
||||
@section('scripts')
|
||||
|
|
|
|||
|
|
@ -162,6 +162,7 @@
|
|||
<ul class="nav flex-column mb-2">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{route('bo.orders')}}">Commandes</a>
|
||||
<a class="nav-link" href="{{route('bo.orders.today')}}">Commandes à retirer aujourd'hui</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ Route::namespace('App\Http\Controllers\Bo')
|
|||
|
||||
// Commandes
|
||||
Route::get('/orders', [OrdersController::class, 'index'])->name('orders');
|
||||
Route::get('/orders/today', [OrdersController::class, 'today'])->name('orders.today');
|
||||
Route::get('/orders/{reference}', [OrdersController::class, 'orderDetail'])->name('order-detail');
|
||||
Route::get('/orders/{reference}/advance', [OrdersController::class, 'changeStatus'])->name('change-order-status');
|
||||
Route::get('/orders/{reference}/cancel', [OrdersController::class, 'cancelOrder'])->name('cancel-order');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue