Files
opensem/app/Repositories/Shop/PriceListValues.php
2021-11-01 00:50:10 +01:00

70 lines
1.5 KiB
PHP

<?php
namespace App\Repositories\Shop;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Yajra\DataTables\DataTables;
use App\Models\Shop\PriceListValue;
class PriceListValues
{
public static function getByPriceListValue($id)
{
return PriceListValue::byPriceListValue($id)->get();
}
public static function getDatatable()
{
$model = PriceListValue::orderBy('name');
return Datatables::of($model)->make(true);
}
public static function getAll()
{
return PriceListValue::orderBy('name', 'asc')->get();
}
public static function get($id)
{
return PriceListValue::find($id);
}
public static function storePrices($price_list_id, $values)
{
foreach ($values as $value) {
$value['price_list_id'] = $price_list_id;
if ($value['price']) {
self::store($value);
}
}
}
public static function store($data)
{
$id = isset($data['id']) ? $data['id'] : false;
$price = $id ? self::update($data) : self::create($data);
return $price;
}
public static function create($data)
{
return PriceListValue::create($data);
}
public static function update($data, $id = false)
{
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}
public static function destroy($id)
{
return PriceListValue::destroy($id);
}
}