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 @@