From b7d03fc5c4ba0bb90dbd0124f9116b68bbf49d8a Mon Sep 17 00:00:00 2001 From: Ludovic CANDELLIER Date: Mon, 3 Aug 2020 23:09:26 +0200 Subject: [PATCH] Add exports & fix on edition --- app/DataTables/Botanic/FamiliesDataTable.php | 2 +- app/DataTables/Botanic/GenresDataTable.php | 2 +- app/DataTables/Botanic/SpeciesDataTable.php | 2 +- app/DataTables/Botanic/VarietiesDataTable.php | 2 +- app/DataTables/Shop/CustomersDataTable.php | 5 +- app/DataTables/Shop/InvoicesDataTable.php | 4 +- .../Botanic/Admin/FamilyController.php | 6 + .../Botanic/Admin/GenreController.php | 6 + .../Botanic/Admin/SpecieController.php | 4 + .../Botanic/Admin/VarietyController.php | 4 + app/Repositories/Botanic/Families.php | 7 + app/Repositories/Botanic/Genres.php | 6 + app/Repositories/Botanic/Species.php | 6 + app/Repositories/Botanic/Varieties.php | 217 +++++++++--------- app/Repositories/Shop/ArticleAttributes.php | 6 +- app/Repositories/Shop/ArticlePrices.php | 8 +- app/Repositories/Shop/Articles.php | 2 +- .../Botanic/Admin/Families/list.blade.php | 2 +- .../views/Botanic/Admin/Genres/list.blade.php | 2 +- .../Botanic/Admin/Species/list.blade.php | 2 +- .../Botanic/Admin/Varieties/list.blade.php | 2 +- .../views/Shop/Admin/Articles/edit.blade.php | 12 - .../partials/prices/block_price.blade.php | 4 +- .../partials/prices/block_price_new.blade.php | 4 +- routes/Botanic/Admin/Families.php | 2 + routes/Botanic/Admin/Genres.php | 2 + routes/Botanic/Admin/Species.php | 2 + routes/Botanic/Admin/Varieties.php | 3 + 28 files changed, 190 insertions(+), 136 deletions(-) diff --git a/app/DataTables/Botanic/FamiliesDataTable.php b/app/DataTables/Botanic/FamiliesDataTable.php index 1238b51a..05ab3138 100644 --- a/app/DataTables/Botanic/FamiliesDataTable.php +++ b/app/DataTables/Botanic/FamiliesDataTable.php @@ -8,7 +8,7 @@ use App\Models\Botanic\Family; class FamiliesDataTable extends DataTable { - public $model_name = 'Families'; + public $model_name = 'families'; public function query(Family $model) { diff --git a/app/DataTables/Botanic/GenresDataTable.php b/app/DataTables/Botanic/GenresDataTable.php index 70cc6264..c083061a 100644 --- a/app/DataTables/Botanic/GenresDataTable.php +++ b/app/DataTables/Botanic/GenresDataTable.php @@ -8,7 +8,7 @@ use App\Models\Botanic\Genre; class GenresDataTable extends DataTable { - public $model_name = 'Genres'; + public $model_name = 'genres'; public function query(Genre $model) { diff --git a/app/DataTables/Botanic/SpeciesDataTable.php b/app/DataTables/Botanic/SpeciesDataTable.php index da8c75d5..df3aaeba 100644 --- a/app/DataTables/Botanic/SpeciesDataTable.php +++ b/app/DataTables/Botanic/SpeciesDataTable.php @@ -8,7 +8,7 @@ use App\Models\Botanic\Specie; class SpeciesDataTable extends DataTable { - public $model_name = 'Species'; + public $model_name = 'species'; public function query(Specie $model) { diff --git a/app/DataTables/Botanic/VarietiesDataTable.php b/app/DataTables/Botanic/VarietiesDataTable.php index 859bb722..df19157d 100644 --- a/app/DataTables/Botanic/VarietiesDataTable.php +++ b/app/DataTables/Botanic/VarietiesDataTable.php @@ -8,7 +8,7 @@ use App\Models\Botanic\Variety; class VarietiesDataTable extends DataTable { - public $model_name = 'Varieties'; + public $model_name = 'varieties'; public function query(Variety $model) { diff --git a/app/DataTables/Shop/CustomersDataTable.php b/app/DataTables/Shop/CustomersDataTable.php index 3cba740f..9739a066 100644 --- a/app/DataTables/Shop/CustomersDataTable.php +++ b/app/DataTables/Shop/CustomersDataTable.php @@ -18,7 +18,10 @@ class CustomersDataTable extends DataTable protected function getColumns() { return [ - Column::make('name'), + Column::make('name')->title('Nom'), + Column::make('address')->title('Adresse'), + Column::make('zipcode')->title('Code postal'), + Column::make('city')->title('Ville'), self::makeColumnButtons(), ]; } diff --git a/app/DataTables/Shop/InvoicesDataTable.php b/app/DataTables/Shop/InvoicesDataTable.php index 7d258abc..5586accd 100644 --- a/app/DataTables/Shop/InvoicesDataTable.php +++ b/app/DataTables/Shop/InvoicesDataTable.php @@ -18,7 +18,9 @@ class InvoicesDataTable extends DataTable protected function getColumns() { return [ - Column::make('name'), + Column::make('status.name'), + Column::make('customer.name'), + Column::make('total'), self::makeColumnButtons(), ]; } diff --git a/app/Http/Controllers/Botanic/Admin/FamilyController.php b/app/Http/Controllers/Botanic/Admin/FamilyController.php index 0caf4590..3f4b4fc6 100644 --- a/app/Http/Controllers/Botanic/Admin/FamilyController.php +++ b/app/Http/Controllers/Botanic/Admin/FamilyController.php @@ -49,4 +49,10 @@ class FamilyController extends Controller { return Families::destroy($id); } + + public function exportExcel() + { + return Families::exportExcel(); + } + } diff --git a/app/Http/Controllers/Botanic/Admin/GenreController.php b/app/Http/Controllers/Botanic/Admin/GenreController.php index a935c1cd..79236ccf 100644 --- a/app/Http/Controllers/Botanic/Admin/GenreController.php +++ b/app/Http/Controllers/Botanic/Admin/GenreController.php @@ -49,4 +49,10 @@ class GenreController extends Controller { return Genres::destroy($id); } + + public function exportExcel() + { + return Genres::exportExcel(); + } + } diff --git a/app/Http/Controllers/Botanic/Admin/SpecieController.php b/app/Http/Controllers/Botanic/Admin/SpecieController.php index 7b85d33a..412e8a7c 100644 --- a/app/Http/Controllers/Botanic/Admin/SpecieController.php +++ b/app/Http/Controllers/Botanic/Admin/SpecieController.php @@ -50,4 +50,8 @@ class SpecieController extends Controller return Species::destroy($id); } + public function exportExcel() + { + return Species::exportExcel(); + } } diff --git a/app/Http/Controllers/Botanic/Admin/VarietyController.php b/app/Http/Controllers/Botanic/Admin/VarietyController.php index 9abfc282..823ace72 100644 --- a/app/Http/Controllers/Botanic/Admin/VarietyController.php +++ b/app/Http/Controllers/Botanic/Admin/VarietyController.php @@ -74,4 +74,8 @@ class VarietyController extends Controller return Varieties::deleteImage($id, $index); } + public function exportExcel() + { + return Varieties::exportExcel(); + } } diff --git a/app/Repositories/Botanic/Families.php b/app/Repositories/Botanic/Families.php index 04c462d4..37c677d3 100644 --- a/app/Repositories/Botanic/Families.php +++ b/app/Repositories/Botanic/Families.php @@ -7,8 +7,10 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; use Yajra\DataTables\DataTables; +use Maatwebsite\Excel\Facades\Excel; use App\Models\Botanic\Family; +use App\Exports\Botanic\FamiliesExport; class Families { @@ -56,4 +58,9 @@ class Families return Family::destroy($id); } + public static function exportExcel() + { + return Excel::download(new FamiliesExport, 'families.xlsx'); + } + } diff --git a/app/Repositories/Botanic/Genres.php b/app/Repositories/Botanic/Genres.php index f6715f9e..93ffdb4c 100644 --- a/app/Repositories/Botanic/Genres.php +++ b/app/Repositories/Botanic/Genres.php @@ -7,8 +7,10 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; use Yajra\DataTables\DataTables; +use Maatwebsite\Excel\Facades\Excel; use App\Models\Botanic\Genre; +use App\Exports\Botanic\GenresExport; class Genres { @@ -56,4 +58,8 @@ class Genres return Genre::destroy($id); } + public static function exportExcel() + { + return Excel::download(new GenresExport, 'genres.xlsx'); + } } diff --git a/app/Repositories/Botanic/Species.php b/app/Repositories/Botanic/Species.php index b50f184a..f90f1c31 100644 --- a/app/Repositories/Botanic/Species.php +++ b/app/Repositories/Botanic/Species.php @@ -7,8 +7,10 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; use Yajra\DataTables\DataTables; +use Maatwebsite\Excel\Facades\Excel; use App\Models\Botanic\Specie; +use App\Exports\Botanic\SpeciesExport; class Species { @@ -56,4 +58,8 @@ class Species return Specie::destroy($id); } + 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 261ea93f..598fc0a4 100644 --- a/app/Repositories/Botanic/Varieties.php +++ b/app/Repositories/Botanic/Varieties.php @@ -7,133 +7,140 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; use Yajra\DataTables\DataTables; +use Maatwebsite\Excel\Facades\Excel; use App\Models\Botanic\Variety; +use App\Exports\Botanic\VarietiesExport; class Varieties { - public static function getDatatable() - { - $model = Variety::with('specie'); - return Datatables::of($model)->make(true); - } + public static function getDatatable() + { + $model = Variety::with('specie'); + return Datatables::of($model)->make(true); + } - public static function getOptions() - { - return Variety::orderBy('name')->get()->pluck('name','id')->toArray(); - } + public static function getOptions() + { + return Variety::orderBy('name')->get()->pluck('name','id')->toArray(); + } - public static function getOptionsWithSpecie() - { - $varieties = Variety::with('specie')->get(); - $data = []; - foreach ($varieties as $variety) - { - $data[] = ['id' => $variety->id, 'text' => (isset($variety->specie->name) ? $variety->specie->name . ' ' : '') . $variety->name]; - } - return collect($data)->sortBy('text')->values()->all(); - } + public static function getOptionsWithSpecie() + { + $varieties = Variety::with('specie')->get(); + $data = []; + foreach ($varieties as $variety) + { + $data[] = ['id' => $variety->id, 'text' => (isset($variety->specie->name) ? $variety->specie->name . ' ' : '') . $variety->name]; + } + return collect($data)->sortBy('text')->values()->all(); + } - public static function getAll() - { - return Variety::orderBy('name','asc')->get(); - } + public static function getAll() + { + return Variety::orderBy('name','asc')->get(); + } - public static function get($id) - { - return Variety::find($id); - } + public static function get($id) + { + return Variety::find($id); + } - public static function getFull($id) - { - $variety = self::get($id); - $data = $variety->toArray(); - $data['tags'] = self::getTagsByVariety($variety); - return $data; - } + public static function getFull($id) + { + $variety = self::get($id); + $data = $variety->toArray(); + $data['tags'] = self::getTagsByVariety($variety); + return $data; + } - public static function getTagsByVariety($variety) - { - return $variety->tags->pluck('id')->toArray(); - } + public static function getTagsByVariety($variety) + { + return $variety->tags->pluck('id')->toArray(); + } - public static function storeFull($data) - { - $images = isset($data['images']) ? $data['images'] : false; - $tags = isset($data['tags']) ? $data['tags'] : false; - unset($data['images']); - unset($data['tags']); - $variety = self::store($data); - self::storeImages($variety, $images); - self::storeTags($variety, $tags); - return $variety; - } + public static function storeFull($data) + { + $images = isset($data['images']) ? $data['images'] : false; + $tags = isset($data['tags']) ? $data['tags'] : false; + unset($data['images']); + unset($data['tags']); + $variety = self::store($data); + self::storeImages($variety, $images); + self::storeTags($variety, $tags); + return $variety; + } - public static function store($data) - { - return isset($data['id']) ? self::update($data) : self::create($data); - } + public static function store($data) + { + return isset($data['id']) ? self::update($data) : self::create($data); + } - public static function create($data) - { - return Variety::create($data); - } + public static function create($data) + { + return Variety::create($data); + } - public static function update($data, $id = false) - { - $id = $id ? $id : $data['id']; - $variety = Variety::find($id); - $ret = $variety->update($data); - return $variety; - } + public static function update($data, $id = false) + { + $id = $id ? $id : $data['id']; + $variety = Variety::find($id); + $ret = $variety->update($data); + return $variety; + } - public static function destroy($id) - { - return Variety::destroy($id); - } + public static function destroy($id) + { + return Variety::destroy($id); + } - public static function storeTags($variety, $tags) - { - if ($tags) { - $tags = collect($tags)->transform(function ($item, $key) { - return (int) $item; - })->toArray(); - return $variety->syncTags($tags, true); - } else return false; - } + public static function storeTags($variety, $tags) + { + if ($tags) { + $tags = collect($tags)->transform(function ($item, $key) { + return (int) $item; + })->toArray(); + return $variety->syncTags($tags, true); + } else return false; + } - public static function storeImages($variety, $files) - { - if ($files) { - foreach ($files as $file) { - $variety->addMedia($file)->withResponsiveImages()->toMediaCollection('images'); - } - } - } + public static function storeImages($variety, $files) + { + if ($files) { + foreach ($files as $file) { + $variety->addMedia($file)->withResponsiveImages()->toMediaCollection('images'); + } + } + } - public static function getImages($id) - { - $variety = self::get($id); - if ($variety) { - $variety->getMedia(); - foreach ($variety->media as $key => $media) { - $variety->media[$key]['url'] = $media->getUrl(); - } - return $variety->media; - } else { - return false; - } - } + public static function getImages($id) + { + $variety = self::get($id); + if ($variety) { + $variety->getMedia(); + foreach ($variety->media as $key => $media) { + $variety->media[$key]['url'] = $media->getUrl(); + } + return $variety->media; + } else { + return false; + } + } - public static function deleteImage($id, $index) - { - $variety = self::get($id); - $variety->getMedia(); - $ret = $variety->media[$index]->delete(); - return "1"; - } + public static function deleteImage($id, $index) + { + $variety = self::get($id); + $variety->getMedia(); + $ret = $variety->media[$index]->delete(); + return "1"; + } + + public static function exportExcel() + { + return Excel::download(new VarietiesExport, 'varieties.xlsx'); + } } diff --git a/app/Repositories/Shop/ArticleAttributes.php b/app/Repositories/Shop/ArticleAttributes.php index 7045a191..51952bc5 100644 --- a/app/Repositories/Shop/ArticleAttributes.php +++ b/app/Repositories/Shop/ArticleAttributes.php @@ -64,8 +64,10 @@ class ArticleAttributes public static function update($data, $id = false) { - $id = isset($data['id']) ? $id : $data['id']; - return ArticleAttribute::find($id)->update($data); + $id = isset($data['id']) ? $data['id'] : $id; + $item = ArticleAttribute::find($id); + $item->update($data); + return $item; } public static function destroy($id) diff --git a/app/Repositories/Shop/ArticlePrices.php b/app/Repositories/Shop/ArticlePrices.php index cebc2eae..1c3b6d02 100644 --- a/app/Repositories/Shop/ArticlePrices.php +++ b/app/Repositories/Shop/ArticlePrices.php @@ -39,11 +39,15 @@ class ArticlePrices return ArticlePrice::find($id); } - public static function storePrices($article_attribute_id, $prices) + public static function storePrices($article_id, $prices) { if ($prices) { foreach ($prices as $key => $price) { - $prices[$key]['article_attribute_id'] = $article_attribute_id; + $price['article_attribute']['article_attribute_value_id'] = $price['attribute']['attribute_value_id']; + $prices[$key]['article_attribute_id'] = ArticleAttributes::storeAttribute($article_id, $price['article_attribute']); + + unset($prices[$key]['article_attribute']); + unset($prices[$key]['attribute']); self::store($prices[$key]); } } else { diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php index 528d1abf..78529c2a 100644 --- a/app/Repositories/Shop/Articles.php +++ b/app/Repositories/Shop/Articles.php @@ -87,7 +87,7 @@ class Articles self::storeCategories($article, $categories); self::storeTags($article, $tags); self::storePrices($article, $prices); - return $article; + return $article_id; } public static function store($data) diff --git a/resources/views/Botanic/Admin/Families/list.blade.php b/resources/views/Botanic/Admin/Families/list.blade.php index 2361800f..dfdeb3a5 100644 --- a/resources/views/Botanic/Admin/Families/list.blade.php +++ b/resources/views/Botanic/Admin/Families/list.blade.php @@ -6,6 +6,6 @@ @section('content') @component('components.card') - @include('components.datatable', ['route' => route('Botanic.Admin.Families.index'), 'model' => 'Families']) + @include('components.datatable', ['route' => route('Botanic.Admin.Families.index'), 'model' => 'families']) @endcomponent @endsection \ No newline at end of file diff --git a/resources/views/Botanic/Admin/Genres/list.blade.php b/resources/views/Botanic/Admin/Genres/list.blade.php index d0c8068b..85fd8a58 100644 --- a/resources/views/Botanic/Admin/Genres/list.blade.php +++ b/resources/views/Botanic/Admin/Genres/list.blade.php @@ -6,7 +6,7 @@ @section('content') @component('components.card') - @include('components.datatable', ['route' => route('Botanic.Admin.Genres.index'), 'model' => 'BotanicGenres']) + @include('components.datatable', ['route' => route('Botanic.Admin.Genres.index'), 'model' => 'genres']) @endcomponent @endsection diff --git a/resources/views/Botanic/Admin/Species/list.blade.php b/resources/views/Botanic/Admin/Species/list.blade.php index 8ee15dfc..33faae64 100644 --- a/resources/views/Botanic/Admin/Species/list.blade.php +++ b/resources/views/Botanic/Admin/Species/list.blade.php @@ -6,7 +6,7 @@ @section('content') @component('components.card') - @include('components.datatable', ['route' => route('Botanic.Admin.Species.index'), 'model' => 'BotanicSpecies']) + @include('components.datatable', ['route' => route('Botanic.Admin.Species.index'), 'model' => 'species']) @endcomponent @endsection diff --git a/resources/views/Botanic/Admin/Varieties/list.blade.php b/resources/views/Botanic/Admin/Varieties/list.blade.php index 526468c0..8582eb20 100644 --- a/resources/views/Botanic/Admin/Varieties/list.blade.php +++ b/resources/views/Botanic/Admin/Varieties/list.blade.php @@ -6,7 +6,7 @@ @section('content') @component('components.card') - @include('components.datatable', ['route' => route('Botanic.Admin.Varieties.index'), 'model' => 'BotanicVarieties']) + @include('components.datatable', ['route' => route('Botanic.Admin.Varieties.index'), 'model' => 'varieties']) @endcomponent @endsection diff --git a/resources/views/Shop/Admin/Articles/edit.blade.php b/resources/views/Shop/Admin/Articles/edit.blade.php index 043e42dd..4f22fb06 100644 --- a/resources/views/Shop/Admin/Articles/edit.blade.php +++ b/resources/views/Shop/Admin/Articles/edit.blade.php @@ -11,18 +11,6 @@ {{ Form::open(['route' => 'Shop.Admin.Articles.store', 'id' => 'article-form', 'autocomplete' => 'off', 'files' => true]) }} -
-
- - {{ __('Shop.articles.title') }} - - - - @include('components.button-save') - -
-
- @include('Shop.Admin.Articles.form') diff --git a/resources/views/Shop/Admin/Articles/partials/prices/block_price.blade.php b/resources/views/Shop/Admin/Articles/partials/prices/block_price.blade.php index c1402fae..2abcf0f5 100644 --- a/resources/views/Shop/Admin/Articles/partials/prices/block_price.blade.php +++ b/resources/views/Shop/Admin/Articles/partials/prices/block_price.blade.php @@ -24,8 +24,8 @@
- {{ Form::label('generic_price_id', 'Générique') }}
- @include('components.select', ['name' => "prices[$key][article_generic_price_id]", 'value' => $price['article_generic_price_id'] ?? null, 'list' => ['Tarif barquette','Tarif semences'], 'required' => false, 'class' => 'form-control-sm']) + {{ Form::label('price_generic_id', 'Générique') }}
+ @include('components.select', ['name' => "prices[$key][article_price_generic_id]", 'value' => $price['article_price_generic_id'] ?? null, 'list' => $price_generics ?? null, 'required' => false, 'class' => 'form-control-sm'])
diff --git a/resources/views/Shop/Admin/Articles/partials/prices/block_price_new.blade.php b/resources/views/Shop/Admin/Articles/partials/prices/block_price_new.blade.php index b8b58ac8..bd75d2e8 100644 --- a/resources/views/Shop/Admin/Articles/partials/prices/block_price_new.blade.php +++ b/resources/views/Shop/Admin/Articles/partials/prices/block_price_new.blade.php @@ -24,8 +24,8 @@
- {{ Form::label('generic_price_id', 'Générique') }}
- @include('components.select', ['name' => "prices[0][article_generic_price_id]", 'value' => $price['article_generic_price_id'] ?? null, 'list' => ['Tarif barquette','Tarif semences'], 'required' => false, 'class' => 'form-control-sm']) + {{ Form::label('price_generic_id', 'Générique') }}
+ @include('components.select', ['name' => "prices[0][article_price_generic_id]", 'value' => $price['article_price_generic_id'] ?? null, 'list' => $price_generics ?? null, 'required' => false, 'class' => 'form-control-sm'])
diff --git a/routes/Botanic/Admin/Families.php b/routes/Botanic/Admin/Families.php index 7067facc..d191fb18 100644 --- a/routes/Botanic/Admin/Families.php +++ b/routes/Botanic/Admin/Families.php @@ -8,5 +8,7 @@ Route::prefix('Families')->name('Families.')->group(function () { Route::post('store', 'FamilyController@store')->name('store'); Route::get('edit/{id}', 'FamilyController@edit')->name('edit'); + Route::any('exportExcel', 'FamilyController@exportExcel')->name('exportExcel'); + }); diff --git a/routes/Botanic/Admin/Genres.php b/routes/Botanic/Admin/Genres.php index 214af0ad..b180b5d4 100644 --- a/routes/Botanic/Admin/Genres.php +++ b/routes/Botanic/Admin/Genres.php @@ -8,5 +8,7 @@ Route::prefix('Genres')->name('Genres.')->group(function () { Route::post('store', 'GenreController@store')->name('store'); Route::get('edit/{id}', 'GenreController@edit')->name('edit'); + Route::any('exportExcel', 'GenreController@exportExcel')->name('exportExcel'); + }); diff --git a/routes/Botanic/Admin/Species.php b/routes/Botanic/Admin/Species.php index af6c0d2e..14632b88 100644 --- a/routes/Botanic/Admin/Species.php +++ b/routes/Botanic/Admin/Species.php @@ -8,5 +8,7 @@ Route::prefix('Species')->name('Species.')->group(function () { Route::post('store', 'SpecieController@store')->name('store'); Route::get('edit/{id}', 'SpecieController@edit')->name('edit'); + Route::any('exportExcel', 'SpecieController@exportExcel')->name('exportExcel'); + }); diff --git a/routes/Botanic/Admin/Varieties.php b/routes/Botanic/Admin/Varieties.php index 633e7426..b0c576ec 100644 --- a/routes/Botanic/Admin/Varieties.php +++ b/routes/Botanic/Admin/Varieties.php @@ -11,5 +11,8 @@ Route::prefix('Varieties')->name('Varieties.')->group(function () { Route::post('getSelect', 'VarietyController@getOptionsWithSpecie')->name('getSelect'); Route::post('deleteImage', 'VarietyController@deleteImage')->name('deleteImage'); Route::any('getImages/{id?}', 'VarietyController@getImages')->name('getImages'); + + Route::any('exportExcel', 'VarietyController@exportExcel')->name('exportExcel'); + });