Fixes for deliveries vs sale_channels

This commit is contained in:
Ludovic CANDELLIER
2021-11-23 23:37:47 +01:00
parent f6668a6dd3
commit 6dce60d227
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,8 +30,7 @@ class TariffsDataTable extends DataTable
}
return $html;
})
->rawColumns(['sale_channels2', 'action'])
;
->rawColumns(['sale_channels2', 'action']);
return parent::modifier($datatables);
}

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,8 +22,7 @@ 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);
}

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(
$tags = $tags ? collect($tags)->transform(
function ($item, $key) {
return (int) $item;
}
)->toArray();
return $model->syncTags($tags, true);
} else {
return false;
}
)->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);

View File

@@ -53,3 +53,7 @@ ul .jqtree_common {
.yellow {
color: #F2B90F!important;
}
body {
font-size: 0.8rem;
}

View File

@@ -62,6 +62,7 @@
"olssonm/laravel-backup-shield": "^3.1",
"orangehill/iseed": "^3.0",
"php-console/php-console": "^3.1",
"proengsoft/laravel-jsvalidation": "^4.5",
"qoraiche/laravel-mail-editor": "^3.2",
"respect/validation": "^2.2",
"rinvex/laravel-categories": "^5.0",
@@ -97,6 +98,7 @@
"fakerphp/faker": "^1.13",
"fossbarrow/laravel-phpcs": "dev-main",
"imanghafoori/laravel-microscope": "^1.0",
"kevincobain2000/laravel-erd": "^1.3",
"mockery/mockery": "^1.4.2",
"nunomaduro/collision": "^5.4",
"nunomaduro/larastan": "^0.7",

40
config/laravel-erd.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
return [
'url' => 'erd',
'middlewares' => [
//Example
//\App\Http\Middleware\NotFoundWhenProduction::class,
],
'models_path' => base_path('app/Models'),
'docs_path' => base_path('docs/erd/'),
"display" => [
"show_data_type" => false,
],
"from_text" => [
"BelongsTo" => "1..1\nBelongs To",
"BelongsToMany" => "1..*\nBelongs To Many",
"HasMany" => "1..*\nHas Many",
"HasOne" => "1..1\nHas One",
"ManyToMany" => "*..*\nMany To Many",
"ManyToOne" => "*..1\nMany To One",
"OneToMany" => "1..*\nOne To Many",
"OneToOne" => "1..1\nOne To One",
"MorphTo" => "1..1\n",
"MorphToMany" => "1..*\n",
],
"to_text" => [
"BelongsTo" => "",
"BelongsToMany" => "",
"HasMany" => "",
"HasOne" => "",
"ManyToMany" => "",
"ManyToOne" => "",
"OneToMany" => "",
"OneToOne" => "",
"MorphTo" => "",
"MorphToMany" => "",
],
];

View File

@@ -17,7 +17,8 @@ return [
// Tags Models
'models' => [
'tag' => \Rinvex\Tags\Models\Tag::class,
// 'tag' => \Rinvex\Tags\Models\Tag::class,
'tag' => \App\Models\Shop\Tag::class,
],
];

View File

@@ -182,6 +182,19 @@ return [
'successdel' => 'Le tag a été correctement effacé',
'confirmdelete' => 'Confirmez-vous la suppression du tag ?',
],
'tag_families' => [
'title' => 'Familles de tags',
'name' => 'Famille de tag',
'description' => 'Gérer les familles de tags',
'add' => 'Ajouter une famille de tag',
'edit' => 'Editer une famille de tag',
'del' => 'Effacer une famille de tag',
'list' => 'Liste des familles de tags',
'successadd' => 'La famille de tag été correctement ajoutée',
'successmod' => 'La famille de tag a été correctement modifiée',
'successdel' => 'La famille de tag a été correctement effacée',
'confirmdelete' => 'Confirmez-vous la suppression de la famille de tag ?',
],
'tariffs' => [
'title' => 'Tarifs',
'name' => 'Tarif',

View File

@@ -1,6 +1,6 @@
<form id="{{ $model }}-filters">
<div class="row">
<label class="col-4">{{ __('article_natures.title') }}</label>
<label class="col-4">{{ __('shop.article_natures.title') }}</label>
<div class="col-8">
@include('components.form.select', ['name' => 'article_nature_id', 'list' => $article_natures ?? [], 'value' => $filters['article_nature_id'] ?? null, 'class' => 'form-control-sm select2', 'with_empty' => ' '])
</div>

View File

@@ -7,7 +7,7 @@
@if ($inherited['tags'])
<h6> Tags</h6>
@foreach ($inherited['tags'] as $tag)
<button type="button" class="btn btn-secondary btn-xs">{{ $tag['group']['name'] }}-{{ $tag['name'] }}</button>
<button type="button" class="btn btn-secondary btn-xs">{{ $tag['group']['name'] }}-{{ $tag['name']['fr'] }}</button>
@endforeach
@endif
@endcomponent

View File

@@ -6,7 +6,7 @@
@section('content')
{{ Form::open(['route' => 'Admin.Shop.Categories.store', 'id' => 'form', 'autocomplete' => 'off', 'files' => true]) }}
{{ Form::open(['route' => 'Admin.Shop.Categories.store', 'id' => 'category-form', 'autocomplete' => 'off', 'files' => true]) }}
@include('Admin.Shop.Categories.form')
</form>

View File

@@ -6,7 +6,7 @@
@section('content')
{{ Form::open(['route' => 'Admin.Shop.Categories.store', 'id' => 'form', 'autocomplete' => 'off']) }}
{{ Form::open(['route' => 'Admin.Shop.Categories.store', 'id' => 'category-form', 'autocomplete' => 'off']) }}
<input type="hidden" name="id" value="{{ $category['id'] }}">
@include('Admin.Shop.Categories.form')
</form>

View File

@@ -39,10 +39,12 @@
@include('load.form.select2')
@include('load.form.editor')
@include('load.form.save')
@push('js')
<script>
$(function() {
initSaveForm('#category-form');
initSelect2();
initEditor();
});

View File

@@ -5,17 +5,29 @@
])
@section('content')
<div class="row">
<div class="col-8">
@component('components.card')
@include('components.datatable', ['route' => route('Admin.Shop.Categories.index'), 'model' => 'categories'])
@include('components.datatable', ['route' => route('Admin.Shop.Categories.index'), 'model' => 'categories', 'callback' => 'handleCategory();'])
@endcomponent
</div>
<div class="col-4">
@include('Admin.Shop.Categories.partials.tree')
</div>
</div>
@endsection
@include('load.form.select2')
@include('load.form.toggle')
@push('js')
<script>
function handleCategory() {
initToggle("{{ route('Admin.Shop.Categories.toggleVisible') }}");
}
$(document).ready(function () {
initSelect2();
});
</script>
@endpush

View File

@@ -4,8 +4,6 @@
'breadcrumb' => [__('shop.customers.title')]
])
@include('boilerplate::load.fileinput')
@section('content')
{{ Form::open(['route' => 'Admin.Shop.Customers.update', 'id' => 'customer-form', 'autocomplete' => 'off']) }}

View File

@@ -17,7 +17,7 @@
</div>
<div class="col-6">
{{ Form::label('sale_delivery_id', __('shop.deliveries.name')) }}
@include('components.form.select', ['name' => 'sale_delivery_id', 'list' => $sale_deliveries ?? [], 'value' => $customer['sale_delivery_id'] ?? null, 'with_empty' => '', 'class' => 'select2'])
@include('components.form.select', ['name' => 'sale_delivery_id', 'list' => $deliveries ?? [], 'values' => $customer['deliveries'] ?? null, 'with_empty' => '', 'class' => 'select2', 'multiple' => true])
</div>
</div>
@include('components.address', ['with_country' => false])

View File

@@ -1,9 +1,9 @@
@if (count($prices ?? []))
<table class="table table-bordered table-hover table-striped w-100 mb-0 dataTable">
<table class="table table-bordered table-hover table-striped w-100 mb-0">
<tr>
@foreach ($prices as $price)
<td>
{{ $price['code'] ?? null }} - {{ $price['quantity'] ?? null }} : {{ $price['price_taxed'] ?? null }}
{{ "{" . ($price['code'] ?? null) . "}" }} - {{ $price['quantity'] ?? null }} : {{ $price['price_taxed'] ?? null }} TTC
</td>
@endforeach
</tr>

View File

@@ -11,10 +11,6 @@
<option value=''>{{ $with_empty }}</option>
@endif
@if (isset($multiple))
@include('components.form.options.options-multiple')
@else
@include('components.form.options')
@endif
</select>

View File

@@ -12,5 +12,5 @@ Route::prefix('Categories')->name('Categories.')->group(function () {
Route::post('deleteImage', 'CategoryController@deleteImage')->name('deleteImage');
Route::post('moveTree', 'CategoryController@moveTree')->name('moveTree');
Route::post('toggleVisible', 'CategoryController@toggleVisible')->name('toggleVisible');
});