Add ``getStatusBadge()`` to ``Orders`` returning Bootstrap badge HTML per status: warning (En attente), info (Préparation), primary (Expédié), success (Livré), danger (Annulé). Applied to all four order DataTables (admin, admin customer, shop, shop customer).
70 lines
1.7 KiB
PHP
70 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Datatables\Admin\Shop;
|
|
|
|
use App\Datatables\ParentDataTable as DataTable;
|
|
use App\Models\Shop\Order;
|
|
use App\Repositories\Shop\Customers;
|
|
use App\Repositories\Shop\Orders;
|
|
use Yajra\DataTables\Html\Column;
|
|
|
|
class CustomerOrdersDataTable extends DataTable
|
|
{
|
|
public $model_name = 'orders';
|
|
|
|
public $sortedColumn = 1;
|
|
|
|
public $sortedOrder = 'desc';
|
|
|
|
public $stateSave = true;
|
|
|
|
public $url = null;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->url = route('Shop.Orders.index');
|
|
}
|
|
|
|
public function query(Order $model)
|
|
{
|
|
$customerId = Customers::getId();
|
|
$model = $model->byCustomer($customerId);
|
|
|
|
return $this->buildQuery($model);
|
|
}
|
|
|
|
public function getHtmlButtons()
|
|
{
|
|
$buttons = '';
|
|
|
|
$buttons .= self::getButtonShow('uuid', 'Voir la facture');
|
|
|
|
return $buttons;
|
|
}
|
|
|
|
public function modifier($datatables)
|
|
{
|
|
$datatables
|
|
->editColumn('status', function (Order $order) {
|
|
return Orders::getStatusBadge($order->status);
|
|
})
|
|
->editColumn('created_at', function (Order $order) {
|
|
return $order->created_at->isoFormat('DD/MM/YY HH:mm');
|
|
})
|
|
->rawColumns(['status', 'action']);
|
|
|
|
return parent::modifier($datatables);
|
|
}
|
|
|
|
protected function getColumns()
|
|
{
|
|
return [
|
|
Column::make('created_at')->title('Date'),
|
|
Column::make('ref')->title('Ref'),
|
|
Column::make('total_shipped')->title('Montant')->class('text-right'),
|
|
Column::make('status')->title('Statut'),
|
|
$this->makeColumnButtons(),
|
|
];
|
|
}
|
|
}
|