diff --git a/app/Datatables/Shop/ArticleNaturesDataTable.php b/app/Datatables/Shop/ArticleNaturesDataTable.php index 5ce9a1ca..6c78778b 100644 --- a/app/Datatables/Shop/ArticleNaturesDataTable.php +++ b/app/Datatables/Shop/ArticleNaturesDataTable.php @@ -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(), ]; } diff --git a/app/Datatables/Shop/ArticlesDataTable.php b/app/Datatables/Shop/ArticlesDataTable.php index fcede020..8b8f6405 100644 --- a/app/Datatables/Shop/ArticlesDataTable.php +++ b/app/Datatables/Shop/ArticlesDataTable.php @@ -38,7 +38,7 @@ class ArticlesDataTable extends DataTable ->editColumn('tags2', function (Article $article) { $html = ''; foreach ($article->tags as $tag) { - $html .= '' . $tag->slug . ' '; + $html .= '' . $tag->slug . ' '; } return $html; }) diff --git a/app/Datatables/Shop/CategoriesDataTable.php b/app/Datatables/Shop/CategoriesDataTable.php index f126ef7b..5301fd10 100644 --- a/app/Datatables/Shop/CategoriesDataTable.php +++ b/app/Datatables/Shop/CategoriesDataTable.php @@ -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(), ]; } diff --git a/app/Datatables/Shop/CustomerDeliveriesDataTable.php b/app/Datatables/Shop/CustomerDeliveriesDataTable.php new file mode 100644 index 00000000..76be9e86 --- /dev/null +++ b/app/Datatables/Shop/CustomerDeliveriesDataTable.php @@ -0,0 +1,28 @@ +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(), + ]; + } +} diff --git a/app/Datatables/Shop/CustomersDataTable.php b/app/Datatables/Shop/CustomersDataTable.php index 194722c0..4f947401 100644 --- a/app/Datatables/Shop/CustomersDataTable.php +++ b/app/Datatables/Shop/CustomersDataTable.php @@ -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(), ]; } diff --git a/app/Datatables/Shop/OffersDataTable.php b/app/Datatables/Shop/OffersDataTable.php index 2bfaf3db..43898477 100644 --- a/app/Datatables/Shop/OffersDataTable.php +++ b/app/Datatables/Shop/OffersDataTable.php @@ -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'), diff --git a/app/Datatables/Shop/PriceListsDataTable.php b/app/Datatables/Shop/PriceListsDataTable.php index a9777db9..0a1fd854 100644 --- a/app/Datatables/Shop/PriceListsDataTable.php +++ b/app/Datatables/Shop/PriceListsDataTable.php @@ -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); } diff --git a/app/Datatables/Shop/TagGroupsDataTable.php b/app/Datatables/Shop/TagGroupsDataTable.php index a92edfb3..51a7c196 100644 --- a/app/Datatables/Shop/TagGroupsDataTable.php +++ b/app/Datatables/Shop/TagGroupsDataTable.php @@ -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(), ]; } diff --git a/app/Datatables/Shop/TagsDataTable.php b/app/Datatables/Shop/TagsDataTable.php index 0f94b18e..72d2a2ef 100644 --- a/app/Datatables/Shop/TagsDataTable.php +++ b/app/Datatables/Shop/TagsDataTable.php @@ -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(), ]; } diff --git a/app/Datatables/Shop/TariffsDataTable.php b/app/Datatables/Shop/TariffsDataTable.php index 662949a3..249201ba 100644 --- a/app/Datatables/Shop/TariffsDataTable.php +++ b/app/Datatables/Shop/TariffsDataTable.php @@ -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() { diff --git a/app/Datatables/Shop/VariationsDataTable.php b/app/Datatables/Shop/VariationsDataTable.php index 7271e298..fe179df7 100644 --- a/app/Datatables/Shop/VariationsDataTable.php +++ b/app/Datatables/Shop/VariationsDataTable.php @@ -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() { diff --git a/app/Http/Controllers/Admin/Shop/CategoryController.php b/app/Http/Controllers/Admin/Shop/CategoryController.php index 5b69c151..bcecf84e 100644 --- a/app/Http/Controllers/Admin/Shop/CategoryController.php +++ b/app/Http/Controllers/Admin/Shop/CategoryController.php @@ -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]); + } + } diff --git a/app/Http/Controllers/Admin/Shop/CustomerController.php b/app/Http/Controllers/Admin/Shop/CustomerController.php index f8431c54..f42fcb4d 100644 --- a/app/Http/Controllers/Admin/Shop/CustomerController.php +++ b/app/Http/Controllers/Admin/Shop/CustomerController.php @@ -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); } diff --git a/app/Models/Shop/Category.php b/app/Models/Shop/Category.php index 0a2a2647..b0c535c9 100644 --- a/app/Models/Shop/Category.php +++ b/app/Models/Shop/Category.php @@ -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'); diff --git a/app/Models/Shop/Customer.php b/app/Models/Shop/Customer.php index 72d9431d..b8096fa4 100644 --- a/app/Models/Shop/Customer.php +++ b/app/Models/Shop/Customer.php @@ -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() diff --git a/app/Models/Shop/CustomerDelivery.php b/app/Models/Shop/CustomerDelivery.php new file mode 100644 index 00000000..dcf52b19 --- /dev/null +++ b/app/Models/Shop/CustomerDelivery.php @@ -0,0 +1,31 @@ +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); + } +} diff --git a/app/Models/Shop/Tag.php b/app/Models/Shop/Tag.php index b847938e..f01bde00 100644 --- a/app/Models/Shop/Tag.php +++ b/app/Models/Shop/Tag.php @@ -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'); diff --git a/app/Repositories/Core/Tag.php b/app/Repositories/Core/Tag.php index 65f48b60..c031e159 100644 --- a/app/Repositories/Core/Tag.php +++ b/app/Repositories/Core/Tag.php @@ -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; } } diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php index 4d2c725b..5ee88df5 100644 --- a/app/Repositories/Shop/Articles.php +++ b/app/Repositories/Shop/Articles.php @@ -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; } diff --git a/app/Repositories/Shop/Categories.php b/app/Repositories/Shop/Categories.php index 1865a500..1ddfa263 100644 --- a/app/Repositories/Shop/Categories.php +++ b/app/Repositories/Shop/Categories.php @@ -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); diff --git a/build/css/main.css b/build/css/main.css index dad31c7b..1245da50 100644 --- a/build/css/main.css +++ b/build/css/main.css @@ -53,3 +53,7 @@ ul .jqtree_common { .yellow { color: #F2B90F!important; } + +body { + font-size: 0.8rem; +} \ No newline at end of file diff --git a/composer.json b/composer.json index 6e5dc615..2836c0fc 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/config/laravel-erd.php b/config/laravel-erd.php new file mode 100644 index 00000000..3b6a775c --- /dev/null +++ b/config/laravel-erd.php @@ -0,0 +1,40 @@ + '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" => "", + ], +]; diff --git a/config/rinvex.tags.php b/config/rinvex.tags.php index 80966324..e97720bc 100644 --- a/config/rinvex.tags.php +++ b/config/rinvex.tags.php @@ -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, ], ]; diff --git a/resources/lang/fr/shop.php b/resources/lang/fr/shop.php index a2e5c351..2ecb492f 100644 --- a/resources/lang/fr/shop.php +++ b/resources/lang/fr/shop.php @@ -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', diff --git a/resources/views/Admin/Shop/Articles/partials/filters.blade.php b/resources/views/Admin/Shop/Articles/partials/filters.blade.php index 5555bcb0..ff7966da 100644 --- a/resources/views/Admin/Shop/Articles/partials/filters.blade.php +++ b/resources/views/Admin/Shop/Articles/partials/filters.blade.php @@ -1,6 +1,6 @@