Fixes on prices & add ArticlePriceGeneric

This commit is contained in:
Ludovic CANDELLIER
2020-07-31 00:21:49 +02:00
parent ef791fbcf2
commit 1e685cfefb
18 changed files with 374 additions and 52 deletions

View File

@@ -0,0 +1,30 @@
<?php
namespace App\DataTables\Shop;
use Yajra\DataTables\Html\Column;
use App\DataTables\ParentDataTable as DataTable;
use App\Models\Shop\ArticlePriceGeneric;
class ArticlePriceGenericsDataTable extends DataTable
{
public $model_name = 'article-price-generics';
public function query(ArticlePriceGeneric $model)
{
$model = $model::withCount('article_prices');
return self::buildQuery($model);
}
protected function getColumns()
{
return [
Column::make('name')->title('Nom'),
Column::make('price')->title('Prix HT')->class('text-right'),
Column::make('price_taxed')->title('Prix TTC')->class('text-right'),
Column::make('article_prices_count')->title('Nb de tarifs')->class('text-right'),
self::makeColumnButtons(),
];
}
}

View File

@@ -1,27 +0,0 @@
<?php
namespace App\DataTables\Shop;
use Yajra\DataTables\Html\Column;
use App\DataTables\ParentDataTable as DataTable;
use App\Models\Shop\ArticlePrice;
class ArticlePricessDataTable extends DataTable
{
public $model_name = 'ArticlePrices';
public function query(ArticlePrice $model)
{
$model = $model::with(['Article', 'ArticleAttributes']);
return self::buildQuery($model);
}
protected function getColumns()
{
return [
Column::make('name'),
self::makeColumnButtons(),
];
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace App\Http\Controllers\Shop\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Shop\ArticlePriceGeneric;
use App\Repositories\Shop\ArticlePriceGenerics;
use App\Repositories\Shop\Taxes;
use App\DataTables\Shop\ArticlePriceGenericsDataTable;
class ArticlePriceGenericController extends Controller
{
public function index(ArticlePriceGenericsDataTable $dataTable)
{
return $dataTable->render('Shop.Admin.ArticlePriceGenerics.list');
}
public function getDatatable(Request $request)
{
return ArticlePriceGenerics::getTables($request->all());
}
public function create()
{
$data['taxes'] = Taxes::getOptions();
return view('Shop.Admin.ArticlePriceGenerics.create',$data);
}
public function store(Request $request)
{
$ret = ArticlePriceGenerics::store($request->all());
return redirect()->route('Shop.Admin.ArticlePriceGenerics.index');
}
public function show($id)
{
$data = ArticlePriceGenerics::get($id);
return view('Shop.Admin.ArticlePriceGenerics.view', $data);
}
public function edit($id)
{
$data['generic'] = ArticlePriceGenerics::get($id);
$data['taxes'] = Taxes::getOptions();
return view('Shop.Admin.ArticlePriceGenerics.edit', $data);
}
public function update(Request $request)
{
//
}
public function destroy($id)
{
return ArticlePriceGenerics::destroy($id);
}
}

View File

@@ -33,6 +33,8 @@ class Shop
->activeIfRoute(['Shop.Admin.ArticleAttributeValues.*'])->order(8);
$menu->addTo('shop', 'Stock', [ 'route' => 'Shop.Admin.ArticleAttributeValues.index', 'permission' => 'backend_access' ])
->activeIfRoute(['Shop.Admin.ArticleAttributeValues.*'])->order(9);
$menu->addTo('shop', 'Prix génériques', [ 'route' => 'Shop.Admin.ArticlePriceGenerics.index', 'permission' => 'backend_access' ])
->activeIfRoute(['Shop.Admin.ArticlePriceGenerics.*'])->order(10);
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use Znck\Eloquent\Traits\BelongsToThrough;
class ArticlePriceGeneric extends Model
{
use BelongsToThrough;
protected $guarded = ['id'];
protected $table = 'shop_article_price_generics';
public function article_prices()
{
return $this->hasMany('App\Models\Shop\ArticlePrice');
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace App\Repositories\Shop;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Yajra\DataTables\DataTables;
use App\Models\Shop\ArticlePriceGeneric;
class ArticlePriceGenerics
{
public static function getByArticle($id)
{
return ArticlePriceGeneric::byArticle($id)->get();
}
public static function getByArticleWithAttribute($id)
{
return ArticlePriceGeneric::with('article_attribute.attribute_value')->byArticle($id)->get();
}
public static function getDatatable()
{
$model = ArticlePriceGeneric::orderBy('name');
return Datatables::of($model)->make(true);
}
public static function getAll()
{
return ArticlePriceGeneric::orderBy('name','asc')->get();
}
public static function get($id)
{
return ArticlePriceGeneric::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;
}
public static function create($data)
{
return ArticlePriceGeneric::create($data);
}
public static function update($data, $id = false)
{
$id = isset($data['id']) ? $data['id'] : false;
$article = ArticlePriceGeneric::find($id);
$article->update($data);
return $article;
}
public static function destroy($id)
{
return ArticlePriceGeneric::destroy($id);
}
}