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

@@ -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()