Add categories for generic prices

This commit is contained in:
Ludovic CANDELLIER
2020-08-31 00:44:29 +02:00
parent 3b6108b449
commit c9198de890
26 changed files with 471 additions and 242 deletions

View File

@@ -0,0 +1,61 @@
<?php
namespace App\Repositories\Shop;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Yajra\DataTables\DataTables;
use App\Models\Shop\PriceGenericCategory;
class PriceGenericCategories
{
public static function getDatatable()
{
$model = PriceGenericCategory::orderBy('name');
return Datatables::of($model)->make(true);
}
public static function getAll()
{
return PriceGenericCategory::orderBy('name','asc')->get();
}
public static function get($id)
{
return PriceGenericCategory::find($id);
}
public static function getOptions()
{
return PriceGenericCategory::get()->pluck('name','id')->toArray();
}
public static function store($data)
{
$id = isset($data['id']) ? $data['id'] : false;
$category = $id ? self::update($data) : self::create($data);
return $category->id;
}
public static function create($data)
{
return PriceGenericCategory::create($data);
}
public static function update($data, $id = false)
{
$id = isset($data['id']) ? $data['id'] : false;
$category = PriceGenericCategory::find($id);
$category->update($data);
return $category;
}
public static function destroy($id)
{
return PriceGenericCategory::destroy($id);
}
}

View File

@@ -33,6 +33,15 @@ class PriceGenericValues
return PriceGenericValue::find($id);
}
public static function storePrices($generic_id, $values)
{
foreach ($values as $value)
{
$value['price_generic_id'] = $generic_id;
self::store($value);
}
}
public static function store($data)
{
$id = isset($data['id']) ? $data['id'] : false;

View File

@@ -36,14 +36,17 @@ class PriceGenerics
public static function get($id)
{
return PriceGeneric::find($id);
return PriceGeneric::with("values")->find($id);
}
public static function store($data)
{
$id = isset($data['id']) ? $data['id'] : false;
$price = $id ? self::update($data) : self::create($data);
return $price->id;
$prices = isset($data['prices']) ? $data['prices'] : false;
unset($data['prices']);
$generic = $id ? self::update($data) : self::create($data);
PriceGenericValues::storePrices($generic->id, $prices);
return $generic->id;
}
public static function create($data)
@@ -54,9 +57,9 @@ class PriceGenerics
public static function update($data, $id = false)
{
$id = isset($data['id']) ? $data['id'] : false;
$article = PriceGeneric::find($id);
$article->update($data);
return $article;
$generic = PriceGeneric::find($id);
$generic->update($data);
return $generic;
}
public static function destroy($id)