Add filter by sale_channel, add method to get prices by offer, sale_channel and quantity

This commit is contained in:
Ludovic CANDELLIER
2022-01-23 21:37:54 +01:00
parent 94a162deb7
commit fe759565a8
36 changed files with 29 additions and 1165 deletions

View File

@@ -12,7 +12,7 @@ class SaleChannelsDataTable extends DataTable
public function query(SaleChannel $model)
{
$model = $model->withCount('deliveries');
$model = $model->withCount(['deliveries', 'tariffs']);
return $this->buildQuery($model);
}
@@ -21,7 +21,8 @@ class SaleChannelsDataTable extends DataTable
return [
Column::make('code')->title('Code abrégé')->width(100),
Column::make('name')->title('Nom'),
Column::make('deliveries_count')->title(__('shop.deliveries.list'))->searchable(false)->class('text-right'),
Column::make('deliveries_count')->title('#Distrib')->searchable(false)->class('text-right'),
Column::make('tariffs_count')->title('#Tarifs')->searchable(false)->class('text-right'),
$this->makeColumnButtons(),
];
}

View File

@@ -5,7 +5,6 @@ namespace App\Http\Controllers\Admin\Shop;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Repositories\Shop\ArticleNatures;
use App\Repositories\Shop\SaleChannels;
use App\Datatables\Shop\SaleChannelsDataTable;

View File

@@ -21,6 +21,6 @@ class SaleChannel extends Model
public function tariffs()
{
return $this->hasManyThrough(Tariff::class, PriceList::class, 'id1', 'tariff_id', 'id2', 'id3')
return $this->hasManyThrough(Tariff::class, PriceList::class, 'sale_channel_id', 'id', 'id', 'tariff_id');
}
}

View File

@@ -5,21 +5,33 @@ namespace App\Repositories\Shop;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Yajra\DataTables\DataTables;
use App\Models\Shop\PriceListValue;
use App\Models\Shop\PriceList;
use App\Models\Shop\Offer;
class PriceListValues
{
public static function getByPriceListValue($id)
public static function getPriceByOffer($offer_id, $quantity = 1, $sale_channel_id = false)
{
return PriceListValue::byPriceListValue($id)->get();
$prices = self::getPricesByOffer($offer_id, $sale_channel_id);
$price = $prices ? $prices->where('quantity', '<=', $quantity)->sortByDesc('quantity')->first() : false;
return $price ? $price->price_taxed : false;
}
public static function getDatatable()
public static function getPricesByOffer($offer_id, $sale_channel_id = false)
{
$model = PriceListValue::orderBy('name');
return Datatables::of($model)->make(true);
$price_list = Offer::with([
'price_lists' => function ($query) use ($sale_channel_id) {
$sale_channel_id ? $query->bySaleChannel($sale_channel_id) : $query;
},
])->find($offer_id)->price_lists->first();
return $price_list ? $price_list->price_list_values : false;
}
public static function getByPriceList($id)
{
return PriceListValue::byPriceList($id)->get();
}
public static function getAll()

View File

@@ -11,6 +11,11 @@ use App\Models\Shop\PriceList;
class PriceLists
{
public static function getByOfferAndSaleChannel($offer_id, $sale_channel_id)
{
return PriceList::bySaleChannel($sale_channel_id)->byOffer($offer_id)->get();
}
public static function getByOffer($offer_id)
{
return PriceList::byOffer($offer_id)->get();

View File

@@ -16,7 +16,7 @@ class TagGroups
public static function getWithTagsAndCountOffers()
{
$tags = Tag::withCount(['articles'])->get()->toArray();
$tag_groups = TagGroup::pluck('name','id')->toArray();
$tag_groups = TagGroup::pluck('name', 'id')->toArray();
foreach ($tags as $tag) {
$data[$tag['tag_group_id']]['name'] = $tag_groups[$tag['tag_group_id']];
$data[$tag['tag_group_id']]['tags'][] = [