44 lines
1.4 KiB
PHP
44 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Datatables\Shop;
|
|
|
|
use Yajra\DataTables\Html\Column;
|
|
use App\Datatables\ParentDataTable as DataTable;
|
|
use App\Models\Shop\Offer;
|
|
|
|
class OffersDataTable extends DataTable
|
|
{
|
|
public $model_name = 'offers';
|
|
|
|
public function query(Offer $model)
|
|
{
|
|
$model = $model->with(['article.article_nature', 'variation', 'tariff']);
|
|
$model = self::filterByArticleNature($model);
|
|
$model = self::filterByPackage($model);
|
|
return $this->buildQuery($model);
|
|
}
|
|
|
|
public static function filterByArticleNature($model, $article_nature_id = false)
|
|
{
|
|
$article_nature_id = $article_nature_id ? $article_nature_id : self::isFilteredByField('article_nature_id');
|
|
return $article_nature_id ? $model->byArticleNature($article_nature_id) : $model;
|
|
}
|
|
|
|
public static function filterByPackage($model, $package_id = false)
|
|
{
|
|
$package_id = $package_id ? $package_id : self::isFilteredByField('package_id');
|
|
return $package_id ? $model->byPackage($package_id) : $model;
|
|
}
|
|
|
|
protected function getColumns()
|
|
{
|
|
return [
|
|
Column::make('article.name')->title('Article'),
|
|
Column::make('article.article_nature.name')->title('Nature'),
|
|
Column::make('variation.name')->title('Déclinaison'),
|
|
Column::make('tariff.name')->title('Tarif'),
|
|
$this->makeColumnButtons(),
|
|
];
|
|
}
|
|
}
|