From 9cf96b7d4e98dc425abfb513f3082a70e83367fa Mon Sep 17 00:00:00 2001 From: Ludovic CANDELLIER Date: Thu, 9 Sep 2021 00:03:24 +0200 Subject: [PATCH] fixes --- app/Datatables/Shop/PriceListsDataTable.php | 13 +++++- app/Datatables/Shop/TariffsDataTable.php | 13 ++++++ .../Admin/Botanic/GenreController.php | 3 +- .../Admin/Botanic/SpecieController.php | 20 +++++++- .../Admin/Botanic/VarietyController.php | 2 +- app/Menu/Customers.php | 4 +- app/Models/Botanic/Variety.php | 2 +- app/Models/Shop/Tariff.php | 14 +++++- app/Repositories/Botanic/Species.php | 46 +++++++++++++++---- app/Repositories/Botanic/Varieties.php | 2 - app/Repositories/Shop/PriceLists.php | 11 +++++ app/Repositories/Shop/Tariffs.php | 5 ++ ...0_212813_create_botanic_families_table.php | 2 +- ..._20_212813_create_botanic_genres_table.php | 2 +- resources/lang/fr/customer.php | 30 ++++++++++++ .../views/Admin/Botanic/Genres/form.blade.php | 4 +- .../Admin/Botanic/Species/form.blade.php | 18 ++++++-- .../Admin/Botanic/Varieties/edit.blade.php | 2 +- .../Admin/Botanic/Varieties/form.blade.php | 16 +++---- .../views/Admin/Shop/Tariffs/form.blade.php | 7 ++- resources/views/components/input.blade.php | 2 +- routes/Admin/Botanic/Species.php | 3 ++ 22 files changed, 183 insertions(+), 38 deletions(-) create mode 100644 resources/lang/fr/customer.php diff --git a/app/Datatables/Shop/PriceListsDataTable.php b/app/Datatables/Shop/PriceListsDataTable.php index a82b7c48..4d940708 100644 --- a/app/Datatables/Shop/PriceListsDataTable.php +++ b/app/Datatables/Shop/PriceListsDataTable.php @@ -5,6 +5,7 @@ namespace App\Datatables\Shop; use Yajra\DataTables\Html\Column; use App\Datatables\ParentDataTable as DataTable; use App\Models\Shop\PriceList; +use App\Repositories\Shop\PriceLists; class PriceListsDataTable extends DataTable { @@ -17,7 +18,7 @@ class PriceListsDataTable extends DataTable public function query(PriceList $model) { - $model = $model->with('sale_channel'); + $model = $model->with(['sale_channel','price_list_values']); $model = self::filterByTariff($model); return self::buildQuery($model); } @@ -28,10 +29,20 @@ class PriceListsDataTable extends DataTable return $tariff_id ? $model->byTariff($tariff_id) : $model; } + public function modifier($datatables) + { + $datatables + ->editColumn('status', function (PriceList $price_list) { + return PriceLists::getStatus($price_list['status_id']); + }) + ->rawColumns(['action']); + return parent::modifier($datatables); + } protected function getColumns() { return [ + Column::make('status_id')->data('status')->title('etat'), Column::make('name')->title('Nom'), Column::make('sale_channel.name')->title('Canal de vente'), self::makeColumnButtons(), diff --git a/app/Datatables/Shop/TariffsDataTable.php b/app/Datatables/Shop/TariffsDataTable.php index b0fe3a4e..caa0c6b2 100644 --- a/app/Datatables/Shop/TariffsDataTable.php +++ b/app/Datatables/Shop/TariffsDataTable.php @@ -5,6 +5,7 @@ namespace App\Datatables\Shop; use Yajra\DataTables\Html\Column; use App\Datatables\ParentDataTable as DataTable; use App\Models\Shop\Tariff; +use App\Repositories\Shop\Tariffs; class TariffsDataTable extends DataTable { @@ -16,9 +17,21 @@ class TariffsDataTable extends DataTable return self::buildQuery($model); } + public function modifier($datatables) + { + $datatables + ->editColumn('status', function (Tariff $tariff) { + return Tariffs::getStatus($tariff['status_id']); + }) + ->rawColumns(['action']) + ; + return parent::modifier($datatables); + } + protected function getColumns() { return [ + Column::make('status_id')->data('status')->title('status'), Column::make('name')->title('Nom'), Column::make('sale_channel.name')->title('Canal de vente par défaut'), Column::make('code')->title('Code'), diff --git a/app/Http/Controllers/Admin/Botanic/GenreController.php b/app/Http/Controllers/Admin/Botanic/GenreController.php index f0337ae8..0f94136d 100644 --- a/app/Http/Controllers/Admin/Botanic/GenreController.php +++ b/app/Http/Controllers/Admin/Botanic/GenreController.php @@ -28,7 +28,8 @@ class GenreController extends Controller public function store(Request $request) { - $ret = Genres::store($request); + $data = $request->all(); + $ret = Genres::store($data); return redirect()->route('Admin.Botanic.Genres.index'); } diff --git a/app/Http/Controllers/Admin/Botanic/SpecieController.php b/app/Http/Controllers/Admin/Botanic/SpecieController.php index 88e008d8..1ea4de42 100644 --- a/app/Http/Controllers/Admin/Botanic/SpecieController.php +++ b/app/Http/Controllers/Admin/Botanic/SpecieController.php @@ -6,6 +6,7 @@ use Illuminate\Http\Request; use App\Repositories\Botanic\Species; use App\Repositories\Botanic\Genres; +use App\Repositories\Shop\TagGroups; use App\Datatables\Botanic\SpeciesDataTable; class SpecieController extends Controller @@ -28,13 +29,14 @@ class SpecieController extends Controller public function create() { $data['genres'] = Genres::getOptions(); + $data['tags_list'] = TagGroups::getTreeTags(); return view('Admin.Botanic.Species.create', $data); } public function store(Request $request) { $data = $request->all(); - $ret = Species::store($data); + $ret = Species::storeFull($data); return redirect()->route('Admin.Botanic.Species.index'); } @@ -48,6 +50,7 @@ class SpecieController extends Controller { $data['specie'] = Species::get($id); $data['genres'] = Genres::getOptions(); + $data['tags_list'] = TagGroups::getTreeTags(); return view('Admin.Botanic.Species.edit', $data); } @@ -56,6 +59,21 @@ class SpecieController extends Controller return Species::destroy($id); } + public function getImages(Request $request, $id = false, $can_edit = true) + { + $id = $id ? $id : $request->input('id'); + $data['images'] = Species::getImages($id); + $data['can_edit'] = $can_edit; + return view('components.uploader.mini-gallery-items', $data); + } + + public function deleteImage(Request $request) + { + $id = $request->input('id'); + $index = $request->input('index'); + return Species::deleteImage($id, $index); + } + public function exportExcel() { return Species::exportExcel(); diff --git a/app/Http/Controllers/Admin/Botanic/VarietyController.php b/app/Http/Controllers/Admin/Botanic/VarietyController.php index bee728f2..82880f34 100644 --- a/app/Http/Controllers/Admin/Botanic/VarietyController.php +++ b/app/Http/Controllers/Admin/Botanic/VarietyController.php @@ -44,7 +44,7 @@ class VarietyController extends Controller public function edit($id) { - $data = Varieties::getFull($id); + $data['variety'] = Varieties::getFull($id); $data['species'] = Species::getOptions(); $data['tags_list'] = TagGroups::getTreeTags(); return view('Admin.Botanic.Varieties.edit', $data); diff --git a/app/Menu/Customers.php b/app/Menu/Customers.php index c1c83231..fc41ae83 100644 --- a/app/Menu/Customers.php +++ b/app/Menu/Customers.php @@ -13,10 +13,10 @@ class Customers ->activeIfRoute('customers') ->order(3); - $menu->addTo('customers', 'Clients', [ 'route' => 'Admin.Shop.Customers.index', 'permission' => 'backend_access' ]) + $menu->addTo('customers', __('customer.customers.name'), [ 'route' => 'Admin.Shop.Customers.index', 'permission' => 'backend_access' ]) ->activeIfRoute(['Admin.Shop.Customers.*'])->order(1); - $menu->addTo('customers', 'Canaux de vente', [ 'route' => 'Admin.Shop.SaleChannels.index', 'permission' => 'backend_access' ]) + $menu->addTo('customers', __('customer.sale_channels.name'), [ 'route' => 'Admin.Shop.SaleChannels.index', 'permission' => 'backend_access' ]) ->activeIfRoute(['Admin.Shop.SaleChannels.*'])->order(1); } } diff --git a/app/Models/Botanic/Variety.php b/app/Models/Botanic/Variety.php index 6fdf103c..f5c81fee 100644 --- a/app/Models/Botanic/Variety.php +++ b/app/Models/Botanic/Variety.php @@ -16,7 +16,7 @@ use Kirschbaum\PowerJoins\PowerJoins; use Wildside\Userstamps\Userstamps; class Variety extends Model implements HasMedia { - use InteractsWithMedia, PowerJoins, Taggable, SoftDeletes, UserStamps; + use InteractsWithMedia, PowerJoins, SoftDeletes, Taggable, UserStamps; protected $guarded = ['id']; protected $table = 'botanic_varieties'; diff --git a/app/Models/Shop/Tariff.php b/app/Models/Shop/Tariff.php index 6d263684..19292619 100644 --- a/app/Models/Shop/Tariff.php +++ b/app/Models/Shop/Tariff.php @@ -6,9 +6,11 @@ use Illuminate\Database\Eloquent\Model; use Staudenmeir\EloquentHasManyDeep\HasRelationships; use BeyondCode\Comments\Traits\HasComments; +use Kirschbaum\PowerJoins\PowerJoins; + class Tariff extends Model { - use HasComments, HasRelationships; + use HasComments, HasRelationships, PowerJoins; protected $guarded = ['id']; protected $table = 'shop_tariffs'; @@ -27,4 +29,14 @@ class Tariff extends Model { return $this->hasMany('App\Models\Shop\PriceList'); } + + public function scopeBySaleChanel($query, $id) + { + return $query->where($this->table . '.sale_channel_id', $id); + } + + public function scopeByStatus($query, $id) + { + return $query->where($this->table . '.status_id', $id); + } } diff --git a/app/Repositories/Botanic/Species.php b/app/Repositories/Botanic/Species.php index b24ae7de..3c976aa7 100644 --- a/app/Repositories/Botanic/Species.php +++ b/app/Repositories/Botanic/Species.php @@ -6,19 +6,15 @@ use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; -use Yajra\DataTables\DataTables; use Maatwebsite\Excel\Facades\Excel; +use App\Repositories\Core\Tag; use App\Models\Botanic\Specie; use App\Exports\Botanic\SpeciesExport; + class Species { - public static function getDatatable() - { - $model = Specie::orderBy('name'); - return Datatables::of($model)->make(true); - } public static function getOptions() { @@ -45,11 +41,23 @@ class Species return Specie::findOrFail($id); } + public static function storeFull($data) + { + $images = $data['images'] ?? false; + $tags = $data['tags'] ?? false; + unset($data['images']); + unset($data['tags']); + $specie = self::store($data); + self::storeImages($variety, $images); + self::storeTags($specie, $tags); + return $specie; + } + public static function store($data) { - $id = isset($data['id']) ? $data['id'] : false; - $item = $id ? self::update($data, $id) : self::create($data); - return $item->id; + $id = $data['id'] ?? false; + $specie = $id ? self::update($data, $id) : self::create($data); + return $specie; } public static function create($data) @@ -70,6 +78,26 @@ class Species return Specie::destroy($id); } + public static function storeTags($specie, $tags) + { + return Tag::storeTags($specie, $tags); + } + + public static function storeImages($specie, $files) + { + return Media::storeImages($specie, $files); + } + + public static function getImages($id) + { + return Media::getImages(self::get($id)); + } + + public static function deleteImage($id, $index) + { + return Media::deleteImage(self::get($id), $index); + } + public static function exportExcel() { return Excel::download(new SpeciesExport, 'species.xlsx'); diff --git a/app/Repositories/Botanic/Varieties.php b/app/Repositories/Botanic/Varieties.php index 1916ff8e..82705353 100644 --- a/app/Repositories/Botanic/Varieties.php +++ b/app/Repositories/Botanic/Varieties.php @@ -62,7 +62,6 @@ class Varieties return Tag::getTagsByModel($variety); } - public static function storeFull($data) { $images = isset($data['images']) ? $data['images'] : false; @@ -75,7 +74,6 @@ class Varieties return $variety; } - public static function store($data) { return isset($data['id']) ? self::update($data) : self::create($data); diff --git a/app/Repositories/Shop/PriceLists.php b/app/Repositories/Shop/PriceLists.php index ff458afe..8b00df0c 100644 --- a/app/Repositories/Shop/PriceLists.php +++ b/app/Repositories/Shop/PriceLists.php @@ -10,6 +10,17 @@ use App\Models\Shop\PriceList; class PriceLists { + + public static function getStatus($status_id) + { + return self::getStatuses()[$status_id]; + } + + public static function getStatuses() + { + return ['Actif','Suspendu','Invisible','Obsolete']; + } + public static function getByTariff($id) { return PriceList::byTariff($id)->get(); diff --git a/app/Repositories/Shop/Tariffs.php b/app/Repositories/Shop/Tariffs.php index 9c672eb5..992688dc 100644 --- a/app/Repositories/Shop/Tariffs.php +++ b/app/Repositories/Shop/Tariffs.php @@ -26,6 +26,11 @@ class Tariffs return Tariff::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray(); } + public static function getStatus($status_id) + { + return self::getStatuses()[$status_id]; + } + public static function getStatuses() { return ['Actif','Suspendu','Invisible','Obsolete']; diff --git a/database/migrations/2020_04_20_212813_create_botanic_families_table.php b/database/migrations/2020_04_20_212813_create_botanic_families_table.php index ea241306..c603ffb7 100644 --- a/database/migrations/2020_04_20_212813_create_botanic_families_table.php +++ b/database/migrations/2020_04_20_212813_create_botanic_families_table.php @@ -14,7 +14,7 @@ class CreateBotanicFamiliesTable extends Migration { { Schema::create('botanic_families', function(Blueprint $table) { - $table->integer('id')->nullable(); + $table->increments('id'); $table->string('name', 50)->nullable(); $table->string('alias', 50)->nullable(); $table->string('latin', 50)->nullable(); diff --git a/database/migrations/2020_04_20_212813_create_botanic_genres_table.php b/database/migrations/2020_04_20_212813_create_botanic_genres_table.php index 04f7043b..a40f1974 100644 --- a/database/migrations/2020_04_20_212813_create_botanic_genres_table.php +++ b/database/migrations/2020_04_20_212813_create_botanic_genres_table.php @@ -14,7 +14,7 @@ class CreateBotanicGenresTable extends Migration { { Schema::create('botanic_genres', function(Blueprint $table) { - $table->integer('id', true); + $table->increments('id'); $table->integer('family_id')->nullable(); $table->string('name', 50)->nullable(); $table->string('alias', 50)->nullable(); diff --git a/resources/lang/fr/customer.php b/resources/lang/fr/customer.php new file mode 100644 index 00000000..8887b7d7 --- /dev/null +++ b/resources/lang/fr/customer.php @@ -0,0 +1,30 @@ + [ + 'title' => 'Client', + 'name' => 'Client', + 'description' => 'Gérer les clients', + 'add' => 'Ajouter un client', + 'edit' => 'Editer un client', + 'del' => 'Effacer un client', + 'list' => 'Liste des clients', + 'successadd' => 'Le client été correctement ajouté', + 'successmod' => 'Le client a été correctement modifié', + 'successdel' => 'Le client a été correctement effacé', + 'confirmdelete' => 'Confirmez-vous la suppression du client ?', + ], + 'sale_channels' => [ + 'title' => 'Canal de vente', + 'name' => 'Canal de vente', + 'description' => 'Gérer les clients', + 'add' => 'Ajouter un canal de vente', + 'edit' => 'Editer un canal de vente', + 'del' => 'Effacer un canal de vente', + 'list' => 'Liste des canaux de vente', + 'successadd' => 'Le canal de vente été correctement ajouté', + 'successmod' => 'Le canal de vente a été correctement modifié', + 'successdel' => 'Le canal de vente a été correctement effacé', + 'confirmdelete' => 'Confirmez-vous la suppression du canal de vente ?', + ], +]; diff --git a/resources/views/Admin/Botanic/Genres/form.blade.php b/resources/views/Admin/Botanic/Genres/form.blade.php index 8bafd6f0..278aef05 100644 --- a/resources/views/Admin/Botanic/Genres/form.blade.php +++ b/resources/views/Admin/Botanic/Genres/form.blade.php @@ -11,7 +11,7 @@
{{ Form::label('family', 'Famille') }} - @include('components.select', ['name' => 'family_id', 'list' => $families, 'value' => $genre['family_id'] ?? null, 'required' => false]) + @include('components.select', ['name' => 'family_id', 'list' => $families, 'value' => $genre['family_id'] ?? null, 'required' => false, 'with_empty' => ''])
@@ -19,7 +19,7 @@
{{ Form::label('alias', 'Alias') }} - @include('components.input', ['name' => 'alias', 'value' => $genre['alias'] ?? null, 'required' => false]) + @include('components.input', ['name' => 'alias', 'value' => $genre['alias'] ?? null])
diff --git a/resources/views/Admin/Botanic/Species/form.blade.php b/resources/views/Admin/Botanic/Species/form.blade.php index d8b3fa8f..5e8a29ae 100644 --- a/resources/views/Admin/Botanic/Species/form.blade.php +++ b/resources/views/Admin/Botanic/Species/form.blade.php @@ -26,6 +26,13 @@ +
+
+ {{ Form::label('tags', 'Tags') }} + @include('components.select-tree', ['name' => 'tags[]', 'list' => $tags_list, 'values' => $tags ?? null, 'class' => 'select2 form-control', 'multiple' => true]) +
+
+
{{ Form::label('description', 'Description') }} @@ -36,21 +43,26 @@
- {{ Form::label('photo', 'Photos') }} - @include('components.file', ['name' => 'name', 'value' => $specie['name'] ?? null]) + @include('components.uploader.widget', ['load_url' => route('Admin.Botanic.Species.getImages', ['id' => $specie['id'] ?? false]), 'delete_url' => route('Admin.Botanic.Species.deleteImage'), 'name' => 'images'])
@include('components.save') -@include('load.form.upload.fileinput') +@include('load.form.appender') +@include('load.form.editor') +@include('load.form.save') @include('load.form.select2') +@include('load.form.upload.fileinput') +@include('boilerplate::load.tinymce') + @push('js') @endpush \ No newline at end of file diff --git a/resources/views/Admin/Botanic/Varieties/edit.blade.php b/resources/views/Admin/Botanic/Varieties/edit.blade.php index 9c8d7477..638ecfa6 100644 --- a/resources/views/Admin/Botanic/Varieties/edit.blade.php +++ b/resources/views/Admin/Botanic/Varieties/edit.blade.php @@ -7,7 +7,7 @@ @section('content') {{ Form::open(['route' => 'Admin.Botanic.Varieties.store', 'id' => 'form', 'autocomplete' => 'off', 'files' => true]) }} - + @include('Admin.Botanic.Varieties.form') diff --git a/resources/views/Admin/Botanic/Varieties/form.blade.php b/resources/views/Admin/Botanic/Varieties/form.blade.php index 38808cff..7a9d6dfa 100644 --- a/resources/views/Admin/Botanic/Varieties/form.blade.php +++ b/resources/views/Admin/Botanic/Varieties/form.blade.php @@ -1,34 +1,34 @@
-
+
{{ Form::label('name', 'Nom') }} - @include('components.input', ['name' => 'name', 'value' => $name ?? null, 'required' => true]) + @include('components.input', ['name' => 'name', 'value' => $variety['name'] ?? null, 'required' => true])
{{ Form::label('genre', 'Espèce') }} - @include('components.select', ['name' => 'specie_id', 'list' => $species, 'value' => $specie_id ?? null, 'class' => 'select2 form-control', 'with_empty' => '', 'required' => false]) + @include('components.select', ['name' => 'specie_id', 'list' => $species, 'value' => $variety['specie_id'] ?? null, 'class' => 'select2 form-control', 'with_empty' => '', 'required' => false])
-
+
{{ Form::label('tags', 'Tags') }} - @include('components.select-tree', ['name' => 'tags[]', 'list' => $tags_list, 'values' => $tags ?? null, 'class' => 'select2 form-control', 'multiple' => true]) + @include('components.select-tree', ['name' => 'tags[]', 'list' => $tags_list, 'values' => $variety['tags'] ?? null, 'class' => 'select2 form-control', 'multiple' => true])
-
+
{{ Form::label('description', 'Description') }} - @include('components.textarea', ['name' => 'description', 'value' => $description ?? null, 'class' => 'editor', 'rows' => 5, 'required' => false]) + @include('components.textarea', ['name' => 'description', 'value' => $variety['description'] ?? null, 'class' => 'editor', 'rows' => 5, 'required' => false])
- @include('components.uploader.widget', ['load_url' => route('Admin.Botanic.Varieties.getImages', ['id' => $id ?? false]), 'delete_url' => route('Admin.Botanic.Varieties.deleteImage'), 'name' => 'images']) + @include('components.uploader.widget', ['load_url' => route('Admin.Botanic.Varieties.getImages', ['id' => $variety['id'] ?? false]), 'delete_url' => route('Admin.Botanic.Varieties.deleteImage'), 'name' => 'images'])
diff --git a/resources/views/Admin/Shop/Tariffs/form.blade.php b/resources/views/Admin/Shop/Tariffs/form.blade.php index 66725ec0..ff1bdfa9 100644 --- a/resources/views/Admin/Shop/Tariffs/form.blade.php +++ b/resources/views/Admin/Shop/Tariffs/form.blade.php @@ -1,4 +1,4 @@ -
+
{{ Form::open(['route' => 'Admin.Shop.Tariffs.store', 'id' => 'tariffs-form', 'autocomplete' => 'off']) }} @@ -48,7 +48,10 @@
-
+
+ +
+
@if ($tariff['id'] ?? false) @component('components.card', ['title' => 'Liste de prix']) diff --git a/resources/views/components/input.blade.php b/resources/views/components/input.blade.php index bb776e65..c3b59672 100644 --- a/resources/views/components/input.blade.php +++ b/resources/views/components/input.blade.php @@ -4,7 +4,7 @@ id="@if (isset($id_name)){{ $id_name }}@else{{ $name }}@endif" class="form-control @if (isset($class)){{ $class }}@endif" value="@if (isset($value)){{ $value }}@endif" -@if (isset($required)) +@if ($required ?? false) required="required" @endif @if (isset($mask)) diff --git a/routes/Admin/Botanic/Species.php b/routes/Admin/Botanic/Species.php index 22753ad5..b2391cd3 100644 --- a/routes/Admin/Botanic/Species.php +++ b/routes/Admin/Botanic/Species.php @@ -8,6 +8,9 @@ Route::prefix('Species')->name('Species.')->group(function () { Route::post('store', 'SpecieController@store')->name('store'); Route::get('edit/{id}', 'SpecieController@edit')->name('edit'); Route::any('getSelect', 'SpecieController@getOptions')->name('getSelect'); + Route::post('deleteImage', 'SpecieController@deleteImage')->name('deleteImage'); + Route::any('getImages/{id?}/{can_edit?}', 'SpecieController@getImages')->name('getImages'); + Route::any('exportExcel', 'SpecieController@exportExcel')->name('exportExcel');