Fixes for deliveries vs sale_channels

This commit is contained in:
Ludovic CANDELLIER
2021-11-23 23:37:47 +01:00
parent 323330b1a1
commit 5b84ff74e3
36 changed files with 279 additions and 94 deletions

View File

@@ -20,7 +20,7 @@ class ArticleNaturesDataTable extends DataTable
{
return [
Column::make('name')->title('Nom'),
Column::make('articles_count')->title('Nb articles')->addClass('text-right')->searchable(false),
Column::make('articles_count')->title('#Art')->addClass('text-right')->searchable(false)->width(60),
$this->makeColumnButtons(),
];
}

View File

@@ -38,7 +38,7 @@ class ArticlesDataTable extends DataTable
->editColumn('tags2', function (Article $article) {
$html = '';
foreach ($article->tags as $tag) {
$html .= '<span class="btn btn-xs btn-secondary pb-2">' . $tag->slug . '</span> ';
$html .= '<span class="btn btn-xs btn-success pb-2">' . $tag->slug . '</span> ';
}
return $html;
})

View File

@@ -12,15 +12,42 @@ class CategoriesDataTable extends DataTable
public function query(Category $model)
{
$model = $model::withCount('articles');
$model = $model::with(['tags.articles'])->withCount(['articles', 'tags']);
return $this->buildQuery($model);
}
public function modifier($datatables)
{
$datatables
->editColumn('visible', function (Category $category) {
return view("components.form.toggle", [
'value' => $category->visible,
'on' => __('visible'),
'off' => __('invisible'),
'meta' => 'data-id=' . $category->id,
'size' => 'sm',
]);
})
->editColumn('articles_tagged_count', function (Category $category) {
$count = 0;
foreach ($category->tags as $tag) {
$nb = collect($tag->articles)->count();
$count += $nb;
}
return $count;
})
->rawColumns(['visible', 'action']);
return parent::modifier($datatables);
}
protected function getColumns()
{
return [
Column::make('visible')->title('visible')->width(60)->title(''),
Column::make('name')->title('Nom'),
Column::make('articles_count')->title('Nb Articles')->class('text-right')->searchable(false),
Column::make('articles_count')->title('#Art')->class('text-right')->searchable(false)->width(60),
Column::make('tags_count')->title('#Tags')->class('text-right')->searchable(false)->width(60),
Column::make('articles_tagged_count')->title('#ArtTag')->class('text-right')->searchable(false)->width(60),
$this->makeColumnButtons(),
];
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Datatables\Shop;
use Yajra\DataTables\Html\Column;
use App\Datatables\ParentDataTable as DataTable;
use App\Models\Shop\Customer;
class CustomerDeliveriesDataTable extends DataTable
{
public $model_name = 'customer_deliveries';
public function query(Customer $model)
{
return $this->buildQuery($model);
}
protected function getColumns()
{
return [
Column::make('name')->title('Nom'),
Column::make('address')->title('Adresse'),
Column::make('zipcode')->title('Code postal'),
Column::make('city')->title('Ville'),
$this->makeColumnButtons(),
];
}
}

View File

@@ -18,10 +18,7 @@ class CustomersDataTable extends DataTable
protected function getColumns()
{
return [
Column::make('name')->title('Nom'),
Column::make('address')->title('Adresse'),
Column::make('zipcode')->title('Code postal'),
Column::make('city')->title('Ville'),
Column::make('last_name')->title('Nom'),
$this->makeColumnButtons(),
];
}

View File

@@ -54,8 +54,8 @@ class OffersDataTable extends DataTable
{
return [
Column::make('status_id')->title('')->width(40),
Column::make('article.name')->title('Article'),
Column::make('article.article_nature.name')->title('Nature'),
Column::make('article.name')->title('Article'),
Column::make('variation.name')->title('Déclinaison'),
Column::make('tariff.name')->title('Tarif'),
Column::make('stock_current')->title('Appro im'),

View File

@@ -18,7 +18,7 @@ class PriceListsDataTable extends DataTable
public function query(PriceList $model)
{
$model = $model->with(['sale_channel','price_list_values']);
$model = $model->with(['sale_channel', 'price_list_values']);
$model = self::filterByTariff($model);
return $this->buildQuery($model);
}
@@ -38,7 +38,7 @@ class PriceListsDataTable extends DataTable
->editColumn('tariff_id', function (PriceList $price_list) {
return view('Admin.Shop.PriceLists.partials.table-prices', ['prices' => $price_list['price_list_values']]);
})
->rawColumns(['tariff_id','action']);
->rawColumns(['tariff_id', 'action']);
return parent::modifier($datatables);
}

View File

@@ -20,7 +20,7 @@ class TagGroupsDataTable extends DataTable
{
return [
Column::make('name'),
Column::make('tags_count')->title('Nb de tags')->searchable(false)->addClass('text-right'),
Column::make('tags_count')->title('#Tags')->searchable(false)->addClass('text-right')->width(60),
$this->makeColumnButtons(),
];
}

View File

@@ -30,12 +30,12 @@ class TagsDataTable extends DataTable
protected function getColumns()
{
return [
Column::make('group.name')->title('Groupe'),
Column::make('group.name')->title('Groupe')->width(200),
Column::make('name')->title('Nom'),
Column::make('articles_count')->title('#Art')->class('text-right')->searchable(false),
Column::make('species_count')->title('#Esp')->class('text-right')->searchable(false),
Column::make('varieties_count')->title('#Var')->class('text-right')->searchable(false),
Column::make('shelves_count')->title('#Ray')->class('text-right')->searchable(false),
Column::make('articles_count')->title('#Art')->class('text-right')->searchable(false)->width(60),
Column::make('species_count')->title('#Esp')->class('text-right')->searchable(false)->width(60),
Column::make('varieties_count')->title('#Var')->class('text-right')->searchable(false)->width(60),
Column::make('shelves_count')->title('#Ray')->class('text-right')->searchable(false)->width(60),
$this->makeColumnButtons(),
];
}

View File

@@ -30,10 +30,9 @@ class TariffsDataTable extends DataTable
}
return $html;
})
->rawColumns(['sale_channels2', 'action'])
;
->rawColumns(['sale_channels2', 'action']);
return parent::modifier($datatables);
}
}
protected function getColumns()
{

View File

@@ -12,7 +12,7 @@ class VariationsDataTable extends DataTable
public function query(Variation $model)
{
$model = $model->with(['package','unity'])->withCount('offers');
$model = $model->with(['package', 'unity'])->withCount('offers');
return $this->buildQuery($model);
}
@@ -22,10 +22,9 @@ class VariationsDataTable extends DataTable
->editColumn('unity_value', function (Variation $variation) {
return $variation->unity ? $variation->unity->value : '';
})
->rawColumns(['description','action'])
;
->rawColumns(['description', 'action']);
return parent::modifier($datatables);
}
}
protected function getColumns()
{

View File

@@ -17,10 +17,11 @@ class CategoryController extends Controller
public function create()
{
$data = [];
$data['category_id'] = 0;
$data['categories'] = Categories::getOptions();
$data['tags_list'] = TagGroups::getTreeTags();
$data = [
'category_id' => 0,
'categories' => Categories::getOptions(),
'tags_list' => TagGroups::getTreeTags(),
];
return view('Admin.Shop.Categories.create', $data);
}
@@ -38,17 +39,12 @@ class CategoryController extends Controller
public function edit($id)
{
$data['category'] = Categories::get($id)->toArray();
$data['category'] = Categories::getFull($id);
$data['categories'] = Categories::getOptions();
$data['tags_list'] = TagGroups::getTreeTags();
return view('Admin.Shop.Categories.edit', $data);
}
public function update(Request $request)
{
//
}
public function destroy($id)
{
return Categories::destroy($id);
@@ -75,4 +71,11 @@ class CategoryController extends Controller
$type = $request->input('type');
return Categories::moveTree($node_id, $target_id, $type);
}
public function toggleVisible(Request $request)
{
$data = Categories::toggle_visible($request->input('id'), ($request->input('visible') == 'true') ? 1 : 0);
return response()->json(['error' => 0]);
}
}

View File

@@ -5,7 +5,7 @@ namespace App\Http\Controllers\Admin\Shop;
use Illuminate\Http\Request;
use App\Repositories\Shop\Customers;
use App\Repositories\Shop\SaleChannels;
use App\Repositories\Shop\Deliveries;
use App\Datatables\Shop\CustomersDataTable;
class CustomerController extends Controller
@@ -18,7 +18,7 @@ class CustomerController extends Controller
public function create()
{
$data['sale_channels'] = SaleChannels::getOptions();
$data['deliveries'] = Deliveries::getOptions();
return view('Admin.Shop.Customers.create', $data);
}
@@ -37,7 +37,7 @@ class CustomerController extends Controller
public function edit($id)
{
$data['customer'] = Customers::get($id)->toArray();
$data['sale_channels'] = SaleChannels::getOptions();
$data['deliveries'] = Deliveries::getOptions();
return view('Admin.Shop.Customers.edit', $data);
}

View File

@@ -3,6 +3,7 @@
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
@@ -10,12 +11,12 @@ use Spatie\MediaLibrary\MediaCollections\Models\Media;
// use Rinvex\Categories\Traits\Categorizable;
use Rinvex\Tags\Traits\Taggable;
// use Conner\Tagging\Taggable;
use Fico7489\Laravel\EloquentJoin\Traits\EloquentJoin;
use Wildside\Userstamps\Userstamps;
class Category extends Model
{
use InteractsWithMedia, Taggable;
use InteractsWithMedia, SoftDeletes, Taggable, Userstamps;
protected $guarded = ['id'];
protected $table = 'shop_categories';
@@ -25,6 +26,11 @@ class Category extends Model
return $this->morphedByMany(Article::class, 'categorizable');
}
public function ArticlesTagged()
{
return $this->tags->articles;
}
public function Shelves()
{
return $this->morphedByMany(Category::class, 'categorizable');

View File

@@ -19,9 +19,14 @@ class Customer extends Model
return $this->hasMany(Invoice::class);
}
public function Delivery()
public function customer_deliveries()
{
return $this->belongsTo(Delivery::class);
return $this->hasMany(CustomerDelivery::class);
}
public function deliveries()
{
return $this->hasManyThrough(Delivery::class, CustomerDelivery::class);
}
public function Orders()

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
class CustomerDelivery extends Model
{
protected $guarded = ['id'];
protected $table = 'shop_customer_deliveries';
public function customer()
{
return $this->belongsTo(Customer::class);
}
public function delivery()
{
return $this->belongsTo(Delivery::class);
}
public function scopeByCustomer($query, $customer_id)
{
return $query->where($this->table . '.customer_id', $customer_id);
}
public function scopeByDelivery($query, $customer_id)
{
return $query->where($this->table . '.delivery_id', $customer_id);
}
}

View File

@@ -5,10 +5,12 @@ namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
use Rinvex\Tags\Models\Tag as parentTag;
use App\Models\Botanic\Specie;
use App\Models\Botanic\Variety;
class Tag extends Model
class Tag extends parentTag
{
use HasTranslations;
@@ -27,6 +29,11 @@ class Tag extends Model
return $this->morphedByMany(Article::class, 'taggable');
}
public function categories()
{
return $this->morphedByMany(Category::class, 'taggable');
}
public function group()
{
return $this->hasOne(TagGroup::class, 'id', 'tag_group_id');

View File

@@ -12,15 +12,11 @@ class Tag
public static function storeTags($model, $tags)
{
if ($tags) {
$tags = collect($tags)->transform(
function ($item, $key) {
return (int) $item;
}
)->toArray();
return $model->syncTags($tags, true);
} else {
return false;
}
$tags = $tags ? collect($tags)->transform(
function ($item, $key) {
return (int) $item;
}
)->toArray() : false;
return $tags ? $model->syncTags($tags, true) : false;
}
}

View File

@@ -173,8 +173,11 @@ class Articles
case 'App\Models\Botanic\Variety':
$data['products'] = Species::getOptions();
break;
case 'App\Models\Shop\Merchandise':
$data['products'] = Merchandises::getOptions();
break;
default:
$data['products'] = Species::getOptions();
$data['products'] = [];
}
$data['categories_options'] = Categories::getOptions();
@@ -184,6 +187,8 @@ class Articles
$data['models_options'] = [
'App\Models\Botanic\Specie' => 'Espèces',
'App\Models\Botanic\Variety' => 'Variétés',
'App\Models\Shop\Merchandise' => 'Marchandise',
'App\Models\Shop\Merchandise' => 'Autres',
];
return $data;
}

View File

@@ -3,6 +3,7 @@
namespace App\Repositories\Shop;
use App\Models\Shop\Category;
use App\Repositories\Core\Tag;
class Categories
{
@@ -13,7 +14,25 @@ class Categories
public static function get($id)
{
return Category::with('CategoryTree')->find($id);
return Category::findOrFail($id);
}
public static function getFull($id)
{
$category = Category::with('CategoryTree')->find($id);
$data = $category->toArray();
$data['tags'] = self::getTagsByCategory($category);
return $data;
}
public static function getTagsByCategory($category)
{
return $category->tags->pluck('id')->toArray();
}
public static function getTagsNameByCategory($category)
{
return $category->tags->pluck('name', 'id')->toArray();
}
public static function getByCategory($category_id)
@@ -28,7 +47,7 @@ class Categories
public static function getOptions()
{
return Category::get()->pluck('name', 'category_id')->toArray();
return Category::orderBy('name', 'asc')->pluck('name', 'category_id')->toArray();
}
public static function storeFull($data)
@@ -53,17 +72,7 @@ class Categories
public static function storeTags($category, $tags)
{
if ($tags) {
$tags = collect($tags)->transform(
function ($item, $key) {
return (int) $item;
}
)->toArray();
return $category->syncTags($tags, true);
} else {
return false;
}
return Tag::storeTags($category, $tags);
}
public static function storeImages($category, $files)
@@ -131,6 +140,11 @@ class Categories
return Category::destroy($id);
}
public static function toggle_visible($id, $visible)
{
return self::update(['visible' => $visible], $id);
}
public static function getRoot()
{
return app('rinvex.categories.category')->find(1);