From ae20643879620b0c148f02a4db6dd6fd5ff756fb Mon Sep 17 00:00:00 2001 From: Ludovic CANDELLIER Date: Mon, 1 Nov 2021 16:26:31 +0100 Subject: [PATCH] add offers count, & minor fixes code standards --- .../Admin/Core/CommentsDataTable.php | 4 +- app/Datatables/Botanic/FamiliesDataTable.php | 4 +- app/Datatables/Botanic/GenresDataTable.php | 14 +- app/Datatables/Botanic/SpeciesDataTable.php | 14 +- app/Datatables/Botanic/VarietiesDataTable.php | 20 +-- .../Shop/ArticleNaturesDataTable.php | 6 +- app/Datatables/Shop/ArticlesDataTable.php | 23 ++- app/Datatables/Shop/CategoriesDataTable.php | 4 +- app/Datatables/Shop/CustomersDataTable.php | 4 +- app/Datatables/Shop/DeliveriesDataTable.php | 14 +- app/Datatables/Shop/InvoicesDataTable.php | 4 +- app/Datatables/Shop/OffersDataTable.php | 7 +- app/Datatables/Shop/OrdersDataTable.php | 6 +- app/Datatables/Shop/PackagesDataTable.php | 4 +- .../Shop/PriceGenericCategoriesDataTable.php | 4 +- app/Datatables/Shop/PriceListsDataTable.php | 4 +- app/Datatables/Shop/SaleChannelsDataTable.php | 6 +- app/Datatables/Shop/TagGroupsDataTable.php | 4 +- app/Datatables/Shop/TagsDataTable.php | 12 +- app/Datatables/Shop/TariffsDataTable.php | 4 +- app/Datatables/Shop/UnitiesDataTable.php | 4 +- app/Datatables/Shop/VariationsDataTable.php | 11 +- .../Admin/Botanic/FamilyController.php | 5 - .../Admin/Botanic/SpecieController.php | 7 +- .../Admin/Core/App/ApplicationController.php | 7 +- .../Core/App/ApplicationModuleController.php | 5 - .../Admin/Core/Auth/PermissionController.php | 2 +- .../Admin/Core/Auth/RoleController.php | 2 +- .../Admin/Core/Auth/TeamController.php | 3 +- .../Admin/Shop/ArticleNatureController.php | 5 - .../Admin/Shop/CategoryController.php | 5 - .../Admin/Shop/InvoiceController.php | 2 +- .../Admin/Shop/OrderController.php | 2 +- .../Admin/Shop/PackageController.php | 5 - .../Controllers/Admin/Shop/TagController.php | 5 - .../Admin/Shop/TagGroupController.php | 5 - .../Controllers/Admin/Shop/TaxController.php | 15 +- .../Admin/Shop/UnityController.php | 5 - .../Controllers/Shop/CategoryController.php | 5 - app/Models/Shop/Delivery.php | 2 +- app/Repositories/Core/App/Applications.php | 22 ++- app/Repositories/Core/Auth/NewUser.php | 74 -------- .../Core/Auth/PasswordSecurities.php | 15 +- app/Repositories/Core/Auth/ResetPassword.php | 31 ---- app/Repositories/Core/Auth/UserClients.php | 7 +- app/Repositories/Core/Auth/Users.php | 62 ++++--- app/Repositories/Core/Comments.php | 7 +- app/Repositories/Core/Database.php | 2 +- app/Repositories/Core/DateCalculation.php | 6 +- app/Repositories/Core/Export.php | 10 +- app/Repositories/Core/Stat.php | 38 ++--- app/Repositories/Core/Upload.php | 21 +-- app/Repositories/Core/User/ShopCart.php | 35 +++- .../Core/User/ShopCartStorage.php | 38 +++++ app/Repositories/Shop/ArticleComponents.php | 52 ------ app/Repositories/Shop/ArticlePrices.php | 96 ----------- app/Repositories/Shop/Articles.php | 8 +- app/Repositories/Shop/Categories.php | 4 +- app/Repositories/Shop/Merchandises.php | 73 ++++++++ composer.json | 1 + config/app.php | 2 + phpcs.xml | 161 ++++++++++++++++++ .../views/Admin/Shop/Articles/list.blade.php | 3 +- .../views/Admin/Shop/Packages/index.blade.php | 48 ------ .../views/Admin/Shop/Packages/list.blade.php | 9 +- .../views/components/datatable.blade.php | 11 +- 66 files changed, 526 insertions(+), 574 deletions(-) delete mode 100644 app/Repositories/Core/Auth/NewUser.php delete mode 100644 app/Repositories/Core/Auth/ResetPassword.php create mode 100644 app/Repositories/Core/User/ShopCartStorage.php delete mode 100644 app/Repositories/Shop/ArticleComponents.php delete mode 100644 app/Repositories/Shop/ArticlePrices.php create mode 100644 app/Repositories/Shop/Merchandises.php create mode 100644 phpcs.xml delete mode 100644 resources/views/Admin/Shop/Packages/index.blade.php diff --git a/app/Datatables/Admin/Core/CommentsDataTable.php b/app/Datatables/Admin/Core/CommentsDataTable.php index f9194f06..3a13339b 100644 --- a/app/Datatables/Admin/Core/CommentsDataTable.php +++ b/app/Datatables/Admin/Core/CommentsDataTable.php @@ -20,7 +20,7 @@ class CommentsDataTable extends DataTable public function query(Comment $model) { $model = $model::with(['user'])->select('*'); - return self::buildQuery($model); + return $this->buildQuery($model); } protected function getColumns() @@ -29,7 +29,7 @@ class CommentsDataTable extends DataTable Column::make('updated_at')->title(__('date'))->width('80')->class('text-center')->searchable(false), Column::make('user.name')->title(__('name'))->searchable(false), Column::make('comment')->title(__('comments'))->searchable(false), - self::makeColumnButtons(), + $this->makeColumnButtons(), ]; } } diff --git a/app/Datatables/Botanic/FamiliesDataTable.php b/app/Datatables/Botanic/FamiliesDataTable.php index fd48d551..9b6f280a 100644 --- a/app/Datatables/Botanic/FamiliesDataTable.php +++ b/app/Datatables/Botanic/FamiliesDataTable.php @@ -13,7 +13,7 @@ class FamiliesDataTable extends DataTable public function query(Family $model) { $model = $model::withCount(['genres','species','varieties']); - return self::buildQuery($model); + return $this->buildQuery($model); } protected function getColumns() @@ -25,7 +25,7 @@ class FamiliesDataTable extends DataTable Column::make('genres_count')->title('Nb genres')->searchable(false)->addClass('text-right'), Column::make('species_count')->title('Nb espèces')->searchable(false)->addClass('text-right'), Column::make('varieties_count')->title('Nb variétés')->searchable(false)->addClass('text-right'), - self::makeColumnButtons(), + $this->makeColumnButtons(), ]; } } diff --git a/app/Datatables/Botanic/GenresDataTable.php b/app/Datatables/Botanic/GenresDataTable.php index 64e7d56e..85e41301 100644 --- a/app/Datatables/Botanic/GenresDataTable.php +++ b/app/Datatables/Botanic/GenresDataTable.php @@ -13,19 +13,17 @@ class GenresDataTable extends DataTable public function query(Genre $model) { $model = $model::with('family')->withCount('species')->withCount('varieties'); - return self::buildQuery($model); + return $this->buildQuery($model); } public function modifier($datatables) { $datatables - ->editColumn( - 'family_name', function (Genre $genre) { - return $genre->family ? $genre->family->name : ''; - } - ) + ->editColumn('family_name', function (Genre $genre) { + return $genre->family ? $genre->family->name : ''; + }) ->rawColumns(['genre_name', 'action']); - return Parent::modifier($datatables); + return parent::modifier($datatables); } protected function getColumns() @@ -37,7 +35,7 @@ class GenresDataTable extends DataTable Column::make('family.name')->data('family_name')->title('Famille'), Column::make('species_count')->title('Nb Espèces')->searchable(false)->addClass('text-right'), Column::make('varieties_count')->title('Nb Variétés')->searchable(false)->addClass('text-right'), - self::makeColumnButtons(), + $this->makeColumnButtons(), ]; } } diff --git a/app/Datatables/Botanic/SpeciesDataTable.php b/app/Datatables/Botanic/SpeciesDataTable.php index fde75326..596446dd 100644 --- a/app/Datatables/Botanic/SpeciesDataTable.php +++ b/app/Datatables/Botanic/SpeciesDataTable.php @@ -13,19 +13,17 @@ class SpeciesDataTable extends DataTable public function query(Specie $model) { $model = $model::withCount('varieties')->with('genre'); - return self::buildQuery($model); + return $this->buildQuery($model); } public function modifier($datatables) { $datatables - ->editColumn( - 'genre_name', function (Specie $specie) { - return $specie->genre ? $specie->genre->name : ''; - } - ) + ->editColumn('genre_name', function (Specie $specie) { + return $specie->genre ? $specie->genre->name : ''; + }) ->rawColumns(['genre_name', 'action']); - return Parent::modifier($datatables); + return parent::modifier($datatables); } @@ -37,7 +35,7 @@ class SpeciesDataTable extends DataTable Column::make('genre.name')->data('genre_name')->title('Genre'), Column::make('latin'), Column::make('varieties_count')->title('Nb variétés')->searchable(false)->addClass('text-right'), - self::makeColumnButtons(), + $this->makeColumnButtons(), ]; } } diff --git a/app/Datatables/Botanic/VarietiesDataTable.php b/app/Datatables/Botanic/VarietiesDataTable.php index 0c56587e..c4b857f5 100644 --- a/app/Datatables/Botanic/VarietiesDataTable.php +++ b/app/Datatables/Botanic/VarietiesDataTable.php @@ -14,23 +14,21 @@ class VarietiesDataTable extends DataTable { // $model = $model::with('specie')->withCount('Articles')->select('botanic_varieties.*'); $model = $model::joinRelationship('Specie')->select('botanic_varieties.*', 'botanic_species.name as specie_name')->with('Specie')->withCount('Articles'); - return self::buildQuery($model); + return $this->buildQuery($model); } public function modifier($datatables) { $datatables - ->editColumn( - 'photo', function (Variety $variety) { - $media = $variety->getFirstMedia(); - // dump($media); - // return $media('thumb'); - return ''; - } - ) + ->editColumn('photo', function (Variety $variety) { + $media = $variety->getFirstMedia(); + // dump($media); + // return $media('thumb'); + return ''; + }) ->rawColumns(['photo', 'action']); - return Parent::modifier($datatables); + return parent::modifier($datatables); } @@ -41,7 +39,7 @@ class VarietiesDataTable extends DataTable Column::make('name')->title('Nom'), Column::make('articles_count')->title('Nb articles')->class('text-right')->searchable(false), Column::make('photo')->title('')->searchable(false)->orderable(false), - self::makeColumnButtons(), + $this->makeColumnButtons(), ]; } } diff --git a/app/Datatables/Shop/ArticleNaturesDataTable.php b/app/Datatables/Shop/ArticleNaturesDataTable.php index de9dbed6..5ce9a1ca 100644 --- a/app/Datatables/Shop/ArticleNaturesDataTable.php +++ b/app/Datatables/Shop/ArticleNaturesDataTable.php @@ -13,15 +13,15 @@ class ArticleNaturesDataTable extends DataTable public function query(ArticleNature $model) { $model = $model::withCount('Articles'); - return self::buildQuery($model); + return $this->buildQuery($model); } protected function getColumns() { return [ Column::make('name')->title('Nom'), - Column::make('articles_count')->title('Nb articles')->addClass('text-right'), - self::makeColumnButtons(), + Column::make('articles_count')->title('Nb articles')->addClass('text-right')->searchable(false), + $this->makeColumnButtons(), ]; } } diff --git a/app/Datatables/Shop/ArticlesDataTable.php b/app/Datatables/Shop/ArticlesDataTable.php index 3df522a6..2906ee7f 100644 --- a/app/Datatables/Shop/ArticlesDataTable.php +++ b/app/Datatables/Shop/ArticlesDataTable.php @@ -15,37 +15,36 @@ class ArticlesDataTable extends DataTable public function query(Article $model) { - $model = $model::with(['article_nature','image'])->withCount(['categories', 'tags'])->joinRelationship('article_nature'); - $model = self::filterByArticleNature($model); - return self::buildQuery($model); + $model = $model::with(['article_nature', 'image'])->withCount(['categories', 'tags', 'offers'])->joinRelationship('article_nature'); + $model = self::filterByArticleNature($model); + return $this->buildQuery($model); } public static function filterByArticleNature($model, $article_nature_id = false) { $article_nature_id = $article_nature_id ? $article_nature_id : self::isFilteredByField('article_nature_id'); return $article_nature_id ? $model->byArticleNature($article_nature_id) : $model; - } + } public function modifier($datatables) { - $datatables - ->editColumn('thumb', function (Article $article) { - return ''; - }) - ->rawColumns(['thumb','action']); + $datatables->editColumn('thumb', function (Article $article) { + return ''; + }) + ->rawColumns(['thumb', 'action']); return parent::modifier($datatables); } - protected function getColumns() { return [ Column::make('article_nature.name')->title('Nature'), - Column::make('thumb')->searchable(false)->width(40)->class('text-center'), + Column::make('thumb')->searchable(false)->orderable(false)->width(40)->class('text-center'), Column::make('name')->title('Nom'), Column::make('tags_count')->title('Tags')->class('text-right')->searchable(false), Column::make('categories_count')->title('Rayons')->class('text-right')->searchable(false), - self::makeColumnButtons(), + Column::make('offers_count')->title('Offres')->class('text-right')->searchable(false), + $this->makeColumnButtons(), ]; } } diff --git a/app/Datatables/Shop/CategoriesDataTable.php b/app/Datatables/Shop/CategoriesDataTable.php index 5a631c1e..f126ef7b 100644 --- a/app/Datatables/Shop/CategoriesDataTable.php +++ b/app/Datatables/Shop/CategoriesDataTable.php @@ -13,7 +13,7 @@ class CategoriesDataTable extends DataTable public function query(Category $model) { $model = $model::withCount('articles'); - return self::buildQuery($model); + return $this->buildQuery($model); } protected function getColumns() @@ -21,7 +21,7 @@ class CategoriesDataTable extends DataTable return [ Column::make('name')->title('Nom'), Column::make('articles_count')->title('Nb Articles')->class('text-right')->searchable(false), - self::makeColumnButtons(), + $this->makeColumnButtons(), ]; } } diff --git a/app/Datatables/Shop/CustomersDataTable.php b/app/Datatables/Shop/CustomersDataTable.php index ebc6b70c..194722c0 100644 --- a/app/Datatables/Shop/CustomersDataTable.php +++ b/app/Datatables/Shop/CustomersDataTable.php @@ -12,7 +12,7 @@ class CustomersDataTable extends DataTable public function query(Customer $model) { - return self::buildQuery($model); + return $this->buildQuery($model); } protected function getColumns() @@ -22,7 +22,7 @@ class CustomersDataTable extends DataTable Column::make('address')->title('Adresse'), Column::make('zipcode')->title('Code postal'), Column::make('city')->title('Ville'), - self::makeColumnButtons(), + $this->makeColumnButtons(), ]; } } diff --git a/app/Datatables/Shop/DeliveriesDataTable.php b/app/Datatables/Shop/DeliveriesDataTable.php index bff8d227..07e399b4 100644 --- a/app/Datatables/Shop/DeliveriesDataTable.php +++ b/app/Datatables/Shop/DeliveriesDataTable.php @@ -12,15 +12,21 @@ class DeliveriesDataTable extends DataTable public function query(Delivery $model) { - $model = $model->with('SaleChannel'); - return self::buildQuery($model); + $model = $model->with('sale_channel'); + return $this->buildQuery($model); } public function modifier($datatables) { $datatables ->editColumn('active', function (Delivery $delivery) { - return view("components.form.toggle", ['value' => $delivery->active, 'on' => __('active'), 'off' => __('inactive'), 'meta' => 'data-id='.$delivery->id, 'size' => 'sm']); + return view("components.form.toggle", [ + 'value' => $delivery->active, + 'on' => __('active'), + 'off' => __('inactive'), + 'meta' => 'data-id='.$delivery->id, + 'size' => 'sm', + ]); }) ->rawColumns(['active', 'action']); return parent::modifier($datatables); @@ -35,7 +41,7 @@ class DeliveriesDataTable extends DataTable Column::make('address')->title('Adresse'), Column::make('zipcode')->title('Code postal'), Column::make('city')->title('Ville'), - self::makeColumnButtons(), + $this->makeColumnButtons(), ]; } } diff --git a/app/Datatables/Shop/InvoicesDataTable.php b/app/Datatables/Shop/InvoicesDataTable.php index 57f11fca..85c07b55 100644 --- a/app/Datatables/Shop/InvoicesDataTable.php +++ b/app/Datatables/Shop/InvoicesDataTable.php @@ -12,7 +12,7 @@ class InvoicesDataTable extends DataTable public function query(Invoice $model) { - return self::buildQuery($model); + return $this->buildQuery($model); } protected function getColumns() @@ -21,7 +21,7 @@ class InvoicesDataTable extends DataTable Column::make('status.name'), Column::make('customer.name'), Column::make('total'), - self::makeColumnButtons(), + $this->makeColumnButtons(), ]; } } diff --git a/app/Datatables/Shop/OffersDataTable.php b/app/Datatables/Shop/OffersDataTable.php index 227e1ffe..d5dfc430 100644 --- a/app/Datatables/Shop/OffersDataTable.php +++ b/app/Datatables/Shop/OffersDataTable.php @@ -12,17 +12,18 @@ class OffersDataTable extends DataTable public function query(Offer $model) { - $model = $model->with(['article','variation','tariff'])->select(['shop_offers.*']); - return self::buildQuery($model); + $model = $model->with(['article.article_nature', 'variation', 'tariff']); + return $this->buildQuery($model); } protected function getColumns() { return [ Column::make('article.name')->title('Article'), + Column::make('article.article_nature.name')->title('Nature'), Column::make('variation.name')->title('Déclinaison'), Column::make('tariff.name')->title('Tarif'), - self::makeColumnButtons(), + $this->makeColumnButtons(), ]; } } diff --git a/app/Datatables/Shop/OrdersDataTable.php b/app/Datatables/Shop/OrdersDataTable.php index 09b6cf62..aa10145d 100644 --- a/app/Datatables/Shop/OrdersDataTable.php +++ b/app/Datatables/Shop/OrdersDataTable.php @@ -10,16 +10,16 @@ class OrdersDataTable extends DataTable { public $model_name = 'orders'; - public function query(Product $model) + public function query(Order $model) { - return self::buildQuery($model); + return $this->buildQuery($model); } protected function getColumns() { return [ Column::make('name'), - self::makeColumnButtons(), + $this->makeColumnButtons(), ]; } } diff --git a/app/Datatables/Shop/PackagesDataTable.php b/app/Datatables/Shop/PackagesDataTable.php index e1de4e79..9968e769 100644 --- a/app/Datatables/Shop/PackagesDataTable.php +++ b/app/Datatables/Shop/PackagesDataTable.php @@ -13,7 +13,7 @@ class PackagesDataTable extends DataTable public function query(Package $model) { $model = $model->withCount(['variations','offers']); - return self::buildQuery($model); + return $this->buildQuery($model); } protected function getColumns() @@ -22,7 +22,7 @@ class PackagesDataTable extends DataTable Column::make('value')->title('Valeur'), Column::make('variations_count')->title('nb variations')->searchable(false)->class('text-right'), Column::make('offers_count')->title('nb offres')->searchable(false)->class('text-right'), - self::makeColumnButtons(), + $this->makeColumnButtons(), ]; } } diff --git a/app/Datatables/Shop/PriceGenericCategoriesDataTable.php b/app/Datatables/Shop/PriceGenericCategoriesDataTable.php index 5af74331..a7923cdc 100644 --- a/app/Datatables/Shop/PriceGenericCategoriesDataTable.php +++ b/app/Datatables/Shop/PriceGenericCategoriesDataTable.php @@ -13,7 +13,7 @@ class PriceGenericCategoriesDataTable extends DataTable public function query(PriceGenericCategory $model) { $model = $model->withCount('price_generics'); - return self::buildQuery($model); + return $this->buildQuery($model); } protected function getColumns() @@ -21,7 +21,7 @@ class PriceGenericCategoriesDataTable extends DataTable return [ Column::make('name')->title('Nom'), Column::make('price_generics_count')->title('Nb Tarifs')->class('text-right'), - self::makeColumnButtons(), + $this->makeColumnButtons(), ]; } } diff --git a/app/Datatables/Shop/PriceListsDataTable.php b/app/Datatables/Shop/PriceListsDataTable.php index dbd8f857..a9777db9 100644 --- a/app/Datatables/Shop/PriceListsDataTable.php +++ b/app/Datatables/Shop/PriceListsDataTable.php @@ -20,7 +20,7 @@ class PriceListsDataTable extends DataTable { $model = $model->with(['sale_channel','price_list_values']); $model = self::filterByTariff($model); - return self::buildQuery($model); + return $this->buildQuery($model); } public static function filterByTariff($model, $tariff_id = false) @@ -49,7 +49,7 @@ class PriceListsDataTable extends DataTable Column::make('name')->title('Nom'), Column::make('sale_channel.name')->title('Canal de vente'), Column::make('tariff_id')->title('Liste de prix'), - self::makeColumnButtons(), + $this->makeColumnButtons(), ]; } } diff --git a/app/Datatables/Shop/SaleChannelsDataTable.php b/app/Datatables/Shop/SaleChannelsDataTable.php index 559892f1..7282aea5 100644 --- a/app/Datatables/Shop/SaleChannelsDataTable.php +++ b/app/Datatables/Shop/SaleChannelsDataTable.php @@ -13,7 +13,7 @@ class SaleChannelsDataTable extends DataTable public function query(SaleChannel $model) { $model = $model->withCount('deliveries'); - return self::buildQuery($model); + return $this->buildQuery($model); } protected function getColumns() @@ -21,8 +21,8 @@ class SaleChannelsDataTable extends DataTable return [ Column::make('code')->title('Code abrégé')->width(100), Column::make('name')->title('Nom'), - Column::make('deliveries_count')->title(__('shop.deliveries.list'))->searchable(false), - self::makeColumnButtons(), + Column::make('deliveries_count')->title(__('shop.deliveries.list'))->searchable(false)->class('text-right'), + $this->makeColumnButtons(), ]; } } diff --git a/app/Datatables/Shop/TagGroupsDataTable.php b/app/Datatables/Shop/TagGroupsDataTable.php index 48667349..a92edfb3 100644 --- a/app/Datatables/Shop/TagGroupsDataTable.php +++ b/app/Datatables/Shop/TagGroupsDataTable.php @@ -13,7 +13,7 @@ class TagGroupsDataTable extends DataTable public function query(TagGroup $model) { $model = $model::withCount('tags'); - return self::buildQuery($model); + return $this->buildQuery($model); } protected function getColumns() @@ -21,7 +21,7 @@ class TagGroupsDataTable extends DataTable return [ Column::make('name'), Column::make('tags_count')->title('Nb de tags')->searchable(false)->addClass('text-right'), - self::makeColumnButtons(), + $this->makeColumnButtons(), ]; } } diff --git a/app/Datatables/Shop/TagsDataTable.php b/app/Datatables/Shop/TagsDataTable.php index ed5330e4..95c138b9 100644 --- a/app/Datatables/Shop/TagsDataTable.php +++ b/app/Datatables/Shop/TagsDataTable.php @@ -13,8 +13,8 @@ class TagsDataTable extends DataTable public function query(Tag $model) { - $model = $model::with('group')->withCount(['articles','species','varieties']); - return self::buildQuery($model); + $model = $model::with('group')->withCount(['articles', 'species', 'varieties']); + return $this->buildQuery($model); } protected function getColumns() @@ -22,10 +22,10 @@ class TagsDataTable extends DataTable return [ Column::make('group.name')->title('Groupe'), Column::make('name')->title('Nom'), - Column::make('articles_count')->title('Articles')->class('text-right'), - Column::make('species_count')->title('Espèces')->class('text-right'), - Column::make('varieties_count')->title('Variétés')->class('text-right'), - self::makeColumnButtons(), + Column::make('articles_count')->title('Articles')->class('text-right')->searchable(false), + Column::make('species_count')->title('Espèces')->class('text-right')->searchable(false), + Column::make('varieties_count')->title('Variétés')->class('text-right')->searchable(false), + $this->makeColumnButtons(), ]; } } diff --git a/app/Datatables/Shop/TariffsDataTable.php b/app/Datatables/Shop/TariffsDataTable.php index caa0c6b2..596cd362 100644 --- a/app/Datatables/Shop/TariffsDataTable.php +++ b/app/Datatables/Shop/TariffsDataTable.php @@ -14,7 +14,7 @@ class TariffsDataTable extends DataTable public function query(Tariff $model) { $model = $model->with(['sale_channel'])->select(['shop_tariffs.*']); - return self::buildQuery($model); + return $this->buildQuery($model); } public function modifier($datatables) @@ -36,7 +36,7 @@ class TariffsDataTable extends DataTable Column::make('sale_channel.name')->title('Canal de vente par défaut'), Column::make('code')->title('Code'), Column::make('ref')->title('Référence'), - self::makeColumnButtons(), + $this->makeColumnButtons(), ]; } } diff --git a/app/Datatables/Shop/UnitiesDataTable.php b/app/Datatables/Shop/UnitiesDataTable.php index cda6a972..2295d2b3 100644 --- a/app/Datatables/Shop/UnitiesDataTable.php +++ b/app/Datatables/Shop/UnitiesDataTable.php @@ -12,14 +12,14 @@ class UnitiesDataTable extends DataTable public function query(Unity $model) { - return self::buildQuery($model); + return $this->buildQuery($model); } protected function getColumns() { return [ Column::make('value')->title('Valeur'), - self::makeColumnButtons(), + $this->makeColumnButtons(), ]; } } diff --git a/app/Datatables/Shop/VariationsDataTable.php b/app/Datatables/Shop/VariationsDataTable.php index 758f8bd6..adf3c6c5 100644 --- a/app/Datatables/Shop/VariationsDataTable.php +++ b/app/Datatables/Shop/VariationsDataTable.php @@ -12,18 +12,19 @@ class VariationsDataTable extends DataTable public function query(Variation $model) { - $model = $model->with(['package','unity'])->select($model->table . 'shop_variations.*'); - return self::buildQuery($model); + $model = $model->with(['package','unity'])->withCount('offers'); + return $this->buildQuery($model); } protected function getColumns() { return [ Column::make('package.value')->title('Package'), - Column::make('quantity')->title('Quantité')->class('text-right'), - Column::make('unity.value')->title('Unité'), + Column::make('quantity')->title('Quantité')->class('text-right')->with(80), + Column::make('unity.value')->title('Unité')->searchable(false)->with(80), Column::make('description')->title('Description'), - self::makeColumnButtons(), + Column::make('offers_count')->title('Offres')->searchable(false)->class('text-right'), + $this->makeColumnButtons(), ]; } } diff --git a/app/Http/Controllers/Admin/Botanic/FamilyController.php b/app/Http/Controllers/Admin/Botanic/FamilyController.php index dd2e7e08..297b3167 100644 --- a/app/Http/Controllers/Admin/Botanic/FamilyController.php +++ b/app/Http/Controllers/Admin/Botanic/FamilyController.php @@ -14,11 +14,6 @@ class FamilyController extends Controller return $dataTable->render('Admin.Botanic.Families.list'); } - public function getDatatable(Request $request) - { - return Families::getTables($request->all()); - } - public function create() { return view('Admin.Botanic.Families.create', $data ?? []); diff --git a/app/Http/Controllers/Admin/Botanic/SpecieController.php b/app/Http/Controllers/Admin/Botanic/SpecieController.php index f24eea11..0fbb93ce 100644 --- a/app/Http/Controllers/Admin/Botanic/SpecieController.php +++ b/app/Http/Controllers/Admin/Botanic/SpecieController.php @@ -16,11 +16,6 @@ class SpecieController extends Controller return $dataTable->render('Admin.Botanic.Species.list'); } - public function getDatatable(Request $request) - { - return Species::getDatatable($request->all()); - } - public function getOptions() { return response()->json(['0' => ''] + Species::getOptions()); @@ -72,7 +67,7 @@ class SpecieController extends Controller $id = $request->input('id'); $index = $request->input('index'); return Species::deleteImage($id, $index); - } + } public function exportExcel() { diff --git a/app/Http/Controllers/Admin/Core/App/ApplicationController.php b/app/Http/Controllers/Admin/Core/App/ApplicationController.php index 5016a9d8..912a6f29 100644 --- a/app/Http/Controllers/Admin/Core/App/ApplicationController.php +++ b/app/Http/Controllers/Admin/Core/App/ApplicationController.php @@ -19,16 +19,11 @@ class ApplicationController extends Controller return $dataTable->render('admin.Core.App.Application.index', $data); } - public function getDatatable() - { - return Applications::getDatatable(); - } - public function edit(Request $request, $id = false) { $id = $id ? $id : $request->input('id'); $data = \App\Repositories\Config::init(); - $data = Applications::select_by_id($id); + $data = Applications::get($id); return view('Admin.Core.App.Application.edit', $data); } diff --git a/app/Http/Controllers/Admin/Core/App/ApplicationModuleController.php b/app/Http/Controllers/Admin/Core/App/ApplicationModuleController.php index f3a2a070..62d9df1e 100644 --- a/app/Http/Controllers/Admin/Core/App/ApplicationModuleController.php +++ b/app/Http/Controllers/Admin/Core/App/ApplicationModuleController.php @@ -18,11 +18,6 @@ class ApplicationModuleController extends Controller return $dataTable->render('admin.Core.App.ApplicationModule.index', $data); } - public function getDatatable() - { - return ApplicationModules::getDatatable(); - } - public function create() { $data = \App\Repositories\Config::init(); diff --git a/app/Http/Controllers/Admin/Core/Auth/PermissionController.php b/app/Http/Controllers/Admin/Core/Auth/PermissionController.php index f8af64b0..7d1e1c65 100644 --- a/app/Http/Controllers/Admin/Core/Auth/PermissionController.php +++ b/app/Http/Controllers/Admin/Core/Auth/PermissionController.php @@ -65,7 +65,7 @@ class PermissionController extends Controller public function destroy($id) { - Permissions::destroy($id); + Permissions::delete($id); return response()->json(['error' => 0]); } } diff --git a/app/Http/Controllers/Admin/Core/Auth/RoleController.php b/app/Http/Controllers/Admin/Core/Auth/RoleController.php index c8f6154b..1aa1b383 100644 --- a/app/Http/Controllers/Admin/Core/Auth/RoleController.php +++ b/app/Http/Controllers/Admin/Core/Auth/RoleController.php @@ -53,7 +53,7 @@ class RoleController extends Controller public function destroy(Request $request, $id = false) { $id = $id ? $id : $request->input('id'); - Roles::destroy($id); + Roles::delete($id); return response()->json(['error' => 0]); } diff --git a/app/Http/Controllers/Admin/Core/Auth/TeamController.php b/app/Http/Controllers/Admin/Core/Auth/TeamController.php index a714dcc2..2ddec4e8 100644 --- a/app/Http/Controllers/Admin/Core/Auth/TeamController.php +++ b/app/Http/Controllers/Admin/Core/Auth/TeamController.php @@ -49,8 +49,7 @@ class TeamController extends Controller public function edit($id) { $team = Team::find($id); - - return view('Admin.Core.Auth.Team.edit', compact('team', 'teams')); + return view('Admin.Core.Auth.Team.edit', compact('team')); } public function update(Request $request, $id) diff --git a/app/Http/Controllers/Admin/Shop/ArticleNatureController.php b/app/Http/Controllers/Admin/Shop/ArticleNatureController.php index 4460183a..6007628a 100644 --- a/app/Http/Controllers/Admin/Shop/ArticleNatureController.php +++ b/app/Http/Controllers/Admin/Shop/ArticleNatureController.php @@ -14,11 +14,6 @@ class ArticleNatureController extends Controller return $dataTable->render('Admin.Shop.ArticleNatures.list'); } - public function getDatatable(Request $request) - { - return ArticleNatures::getTables($request->all()); - } - public function create() { return view('Admin.Shop.ArticleNatures.create'); diff --git a/app/Http/Controllers/Admin/Shop/CategoryController.php b/app/Http/Controllers/Admin/Shop/CategoryController.php index 3d44c1cb..5b69c151 100644 --- a/app/Http/Controllers/Admin/Shop/CategoryController.php +++ b/app/Http/Controllers/Admin/Shop/CategoryController.php @@ -15,11 +15,6 @@ class CategoryController extends Controller return $dataTable->render('Admin.Shop.Categories.list'); } - public function getDatatable(Request $request) - { - return Categories::getTables($request->all()); - } - public function create() { $data = []; diff --git a/app/Http/Controllers/Admin/Shop/InvoiceController.php b/app/Http/Controllers/Admin/Shop/InvoiceController.php index 713c8066..de72885b 100644 --- a/app/Http/Controllers/Admin/Shop/InvoiceController.php +++ b/app/Http/Controllers/Admin/Shop/InvoiceController.php @@ -12,7 +12,7 @@ class InvoiceController extends Controller { public function index(InvoicesDataTable $dataTable) { - return $dataTable->render('Admin.Shop.Invoices.list', $data); + return $dataTable->render('Admin.Shop.Invoices.list'); } public function create() diff --git a/app/Http/Controllers/Admin/Shop/OrderController.php b/app/Http/Controllers/Admin/Shop/OrderController.php index b0ded7bd..5ea669fd 100644 --- a/app/Http/Controllers/Admin/Shop/OrderController.php +++ b/app/Http/Controllers/Admin/Shop/OrderController.php @@ -12,7 +12,7 @@ class OrderController extends Controller { public function index(OrdersDataTable $dataTable) { - return $dataTable->render('Admin.Shop.Orders.list', $data); + return $dataTable->render('Admin.Shop.Orders.list'); } public function create() diff --git a/app/Http/Controllers/Admin/Shop/PackageController.php b/app/Http/Controllers/Admin/Shop/PackageController.php index af02ff50..3fcd696c 100644 --- a/app/Http/Controllers/Admin/Shop/PackageController.php +++ b/app/Http/Controllers/Admin/Shop/PackageController.php @@ -17,11 +17,6 @@ class PackageController extends Controller return $dataTable->render('Admin.Shop.Packages.list', $data); } - public function getDatatable(Request $request) - { - return Packages::getTables($request->all()); - } - public function getOptionsByFamily(Request $request) { $id = $request->input('family_id'); diff --git a/app/Http/Controllers/Admin/Shop/TagController.php b/app/Http/Controllers/Admin/Shop/TagController.php index e7c3b32e..3a84a42f 100644 --- a/app/Http/Controllers/Admin/Shop/TagController.php +++ b/app/Http/Controllers/Admin/Shop/TagController.php @@ -16,11 +16,6 @@ class TagController extends Controller return $dataTable->render('Admin.Shop.Tags.list'); } - public function getDatatable(Request $request) - { - return Tags::getTables($request->all()); - } - public function create() { $data = []; diff --git a/app/Http/Controllers/Admin/Shop/TagGroupController.php b/app/Http/Controllers/Admin/Shop/TagGroupController.php index efc333ff..28e39d2b 100644 --- a/app/Http/Controllers/Admin/Shop/TagGroupController.php +++ b/app/Http/Controllers/Admin/Shop/TagGroupController.php @@ -16,11 +16,6 @@ class TagGroupController extends Controller return $dataTable->render('Admin.Shop.TagGroups.list'); } - public function getDatatable(Request $request) - { - return TagGroups::getTables($request->all()); - } - public function create() { $data['article_families'] = ArticleNatures::getOptions(); diff --git a/app/Http/Controllers/Admin/Shop/TaxController.php b/app/Http/Controllers/Admin/Shop/TaxController.php index f6202f8e..8e00145f 100644 --- a/app/Http/Controllers/Admin/Shop/TaxController.php +++ b/app/Http/Controllers/Admin/Shop/TaxController.php @@ -14,16 +14,9 @@ class TaxController extends Controller return $dataTable->render('Admin.Shop.Taxes.list'); } - public function getDatatable(Request $request) - { - return Taxes::getTables($request->all()); - } - public function create() { - $data = []; - $data['groups'] = TagGroups::getOptions(); - return view('Admin.Shop.Taxes.create', $data); + return view('Admin.Shop.Taxes.create'); } public function store(Request $request) @@ -41,15 +34,9 @@ class TaxController extends Controller public function edit($id) { $data = Taxes::get($id); - $data['groups'] = TagGroups::getOptions(); return view('Admin.Shop.Taxes.edit', $data); } - public function update(Request $request) - { - // - } - public function destroy($id) { return Taxes::destroy($id); diff --git a/app/Http/Controllers/Admin/Shop/UnityController.php b/app/Http/Controllers/Admin/Shop/UnityController.php index ebbf36aa..9b1b5ed6 100644 --- a/app/Http/Controllers/Admin/Shop/UnityController.php +++ b/app/Http/Controllers/Admin/Shop/UnityController.php @@ -19,11 +19,6 @@ class UnityController extends Controller return $dataTable->render('Admin.Shop.Unities.list', $data); } - public function getDatatable(Request $request) - { - return Unities::getTables($request->all()); - } - public function getOptionsByPackage(Request $request) { $id = $request->input('package_id'); diff --git a/app/Http/Controllers/Shop/CategoryController.php b/app/Http/Controllers/Shop/CategoryController.php index 65b488ab..a26578d6 100644 --- a/app/Http/Controllers/Shop/CategoryController.php +++ b/app/Http/Controllers/Shop/CategoryController.php @@ -15,11 +15,6 @@ class CategoryController extends Controller return $dataTable->render('Shop.Categories.list'); } - public function getDatatable(Request $request) - { - return Categories::getDatatable($request->all()); - } - public function show($id) { $data = self::init(); diff --git a/app/Models/Shop/Delivery.php b/app/Models/Shop/Delivery.php index aee27e14..1113858c 100644 --- a/app/Models/Shop/Delivery.php +++ b/app/Models/Shop/Delivery.php @@ -14,7 +14,7 @@ class Delivery extends Model return $this->hasMany(Customer::class); } - public function SaleChannel() + public function sale_channel() { return $this->belongsTo(SaleChannel::class); } diff --git a/app/Repositories/Core/App/Applications.php b/app/Repositories/Core/App/Applications.php index a90ba695..352f9eb6 100644 --- a/app/Repositories/Core/App/Applications.php +++ b/app/Repositories/Core/App/Applications.php @@ -10,9 +10,15 @@ use App\Repositories\Languages; class Applications { - public static function select_all() + + public static function getFullBySlug($slug) { - return Application::all()->toArray(); + return Application::with('clients')->active()->bySlug($slug)->first(); + } + + public static function getAll() + { + return Application::all(); } public static function getOptions() @@ -39,7 +45,9 @@ class Applications public static function update($data, $id = false) { $id = $id ? $id : $data['id']; - return self::get($id)->update($data); + $item = self::get($id); + $item->update($data); + return $item; } public static function destroy($id) @@ -97,4 +105,12 @@ class Applications { return Application::active()->bySlug($slug)->first(); } + + public static function toggleActive($id, $active) { + return self::update(['active' => $active], $id); + } + + public static function toggleVisible($id, $visible) { + return self::update(['visible' => $visible], $id); + } } diff --git a/app/Repositories/Core/Auth/NewUser.php b/app/Repositories/Core/Auth/NewUser.php deleted file mode 100644 index db379125..00000000 --- a/app/Repositories/Core/Auth/NewUser.php +++ /dev/null @@ -1,74 +0,0 @@ -markdown('notifications.email') - ->greeting(__('notifications.greeting', ['firstname' => $notifiable->first_name])) - ->subject(__('notifications.newuser.subject', ['name' => config('app.name')])) - ->line( - __( - 'notifications.newuser.intro', [ - 'name' => $currentUser->first_name.' '.$currentUser->last_name, - ] - ) - ) - ->action( - __('notifications.newuser.button'), - route('users.firstlogin', $notifiable->remember_token) - ) - ->salutation( - __( - 'notifications.salutation', [ - 'name' => $currentUser->first_name.' '.$currentUser->last_name, - ] - ) - ) - ->line(__('notifications.newuser.outro')); - } - - /** - * Get the array representation of the notification. - * - * @param mixed $notifiable - * - * @return array - */ - public function toArray($notifiable) - { - return [ - // - ]; - } -} diff --git a/app/Repositories/Core/Auth/PasswordSecurities.php b/app/Repositories/Core/Auth/PasswordSecurities.php index a33f44e3..b7738293 100644 --- a/app/Repositories/Core/Auth/PasswordSecurities.php +++ b/app/Repositories/Core/Auth/PasswordSecurities.php @@ -9,12 +9,19 @@ class PasswordSecurities { public static function create($user_id, $delay = 90) { - return PasswordSecurity::create( - [ + return PasswordSecurity::create([ 'user_id' => $user_id, 'password_expiry_days' => $delay, 'password_updated_at' => Carbon::now(), - ] - ); + ]); } + + public static function getUserName($id) { + return self::getUser($id)->username; + } + + public static function getUser($id) { + return PasswordSecurity::with('user')->find($id)->user; + } + } diff --git a/app/Repositories/Core/Auth/ResetPassword.php b/app/Repositories/Core/Auth/ResetPassword.php deleted file mode 100644 index 06daa6ce..00000000 --- a/app/Repositories/Core/Auth/ResetPassword.php +++ /dev/null @@ -1,31 +0,0 @@ -markdown('notifications.email') - ->greeting(__('notifications.greeting', ['firstname' => $notifiable->first_name])) - ->subject(__('notifications.resetpassword.subject')) - ->line(__('notifications.resetpassword.intro')) - ->action( - __('notifications.resetpassword.button'), - route('password.reset', $this->token) - ) - ->line(__('notifications.resetpassword.outro')); - } - */ -} diff --git a/app/Repositories/Core/Auth/UserClients.php b/app/Repositories/Core/Auth/UserClients.php index b0c87225..e7a2052f 100644 --- a/app/Repositories/Core/Auth/UserClients.php +++ b/app/Repositories/Core/Auth/UserClients.php @@ -2,11 +2,6 @@ namespace App\Repositories\Core\Auth; -use Hyn\Tenancy\Environment; -use Hyn\Tenancy\Database\Connection; -use App\Models\Admin\Website; -use Hyn\Tenancy\Contracts\Repositories\WebsiteRepository; - use App\Models\Core\Auth\UserClient; use App\Models\Core\Auth\User; @@ -48,7 +43,7 @@ class UserClients { $history = ""; foreach ($clients as $key => $client_id) { - $client = Clients::select_by_id($client_id); + $client = Clients::get($client_id); if ($client) { self::associate_client($user_id, $client_id); $history .= $client['name'] . "| "; diff --git a/app/Repositories/Core/Auth/Users.php b/app/Repositories/Core/Auth/Users.php index 1823f4df..9b7407d4 100644 --- a/app/Repositories/Core/Auth/Users.php +++ b/app/Repositories/Core/Auth/Users.php @@ -15,7 +15,9 @@ use App\Models\Core\Auth\RoleUser; use App\Repositories\Clients; use App\Repositories\Partners; +use App\Repositories\Core\Upload; +use LangleyFoxall\LaravelNISTPasswordRules\PasswordRules; class Users { use LaratrustUserTrait; @@ -35,16 +37,18 @@ class Users $data = $user->toArray(); $data['name'] = $user->name; $data['avatar'] = self::getAvatar($id); - $data['last_login'] = $user->previousLoginAt(); + // $data['last_login'] = $user->previousLoginAt(); // $data['roles'] = self::getRoles(); // $data['permissions'] = self::getPermissions(); $data['roles'] = $user->roles->pluck('id')->toArray(); $data['permissions'] = $user->allPermissions()->pluck('id')->toArray(); + $data['clients'] = $user->clients->pluck('id')->toArray(); return $data; } public static function store($data) { + $id = isset($data['id']) ? $data['id'] : false; if (!empty($data['password'])) { @@ -60,19 +64,20 @@ class Users $data['active'] = true; $user = $id ? self::update($data, $id) : self::create($data); + $user->roles()->sync(array_keys($data['roles'] ?? [])); - if (isset($data['roles'])) { - $user->roles()->sync(array_keys($data['roles'])); - } + UserClients::associate($user->id, $data['clients'] ?? false ); // $user->sendNewUserNotification($data['remember_token'], Auth::user()); return $user; } - public static function create($data) + public static function create($data, $copy_password = false) { - $data['password'] = $data['password'] ? Hash::make($data['password']) : Hash::make(Str::random(8)); - return User::create($data); + $data['password'] = $copy_password ? $data['password'] : ($data['password'] ? Hash::make($data['password']) : Hash::make(Str::random(8))); + $user = User::create($data); + PasswordSecurities::create($user->id); + return $user; } public static function update($data, $id = false) @@ -95,12 +100,17 @@ class Users return $user ? $user->id : false; } - public static function getName() + public static function getName($id = false) { - $user = self::getUser(); + $user = $id ? self::get($id) : self::getUser(); return $user->first_name . ' ' . $user->last_name; } + public static function getUsername($id = false) + { + return $id ? self::get($id)->username : self::getUser()->username; + } + public static function getUser() { return Auth::user(); @@ -113,7 +123,7 @@ class Users public static function getOptions() { - return User::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray(); + return User::orderBy('name')->pluck('name', 'id')->toArray(); } public static function delete($id) @@ -124,7 +134,7 @@ class Users public static function getListByRole($role) { - return self::selectOptions()->orderBy('name', 'asc')->whereRoleIs($role)->get(); + return self::selectOptions()->orderBy('name')->whereRoleIs($role)->get(); } public static function hasRole($role, $user = false) @@ -211,37 +221,36 @@ class Users return User::count(); } - // récupère tous les utilisateurs pour un statut donné public static function select_all_by_status_id($status_id) { return User::byStatus($status_id); } - // récupère toutes les informations d'un utilisateur pour un id donné public static function select_by_id($user_id) { return User::with('status')->find($user_id)->toArray(); } - // récupère toutes les informations d'un utilisateur pour un nom donné public static function select_by_name($name) { - return User::byName($name)->first()->toArray(); + return self::getByName($name)->toArray(); + } + + public static function getByUsername($username) + { + return User::byUsername($username)->withTrashed()->first(); } - // récupère les utilisateurs actifs d'un statut, d'une équipe et d'une entité donnés public static function select_by_status_and_team_and_entity($status_id, $team_id, $third_party_id) { return User::active()->byStatus($status_id)->byTeam($team_id)->byThirdParty($third_party_id)->get()->toArray(); } - // récupère toutes les informations nécessaires d'un utilisateur pour un id donné public static function select_datas_by_id($user_id) { return User::with('status')->find($user_id)->toArray(); } - // met à jour le statut actif/inactif d'un utilisateur public static function toggle_active($id, $active) { return self::get($id)->update(['active' => $active]); @@ -251,26 +260,29 @@ class Users { $targetDir = 'uploads'; $file = $request->file('avatar_file'); - $data = \App\Repositories\Core\Upload::getData($file); - $file_uploaded = \App\Repositories\Core\Upload::store($file, $targetDir); + $data = Upload::getData($file); + $file_uploaded = Upload::store($file, $targetDir); $tab = pathinfo($file_uploaded); $response['name'] = $tab['basename']; return $response; } - - // met à jour l'avatar d'un utilisateur public static function update_avatar($id, $avatar) { return User::find($id)->update(['avatar' => $avatar]); } - // met à jour le mot de passe d'un utilisateur public static function update_password($id, $password) { $password = Hash::make($password); UserClients::changePasswordsByUser($id, $password); - $connection = app(Connection::class); - return User::on($connection->systemName())->find($id)->update(['password' => $password]); + return User::find($id)->update(['password' => $password]); + // $connection = app(Connection::class); + // return User::on($connection->systemName())->find($id)->update(['password' => $password]); } + + public static function validate($username, $field = 'current_password') + { + return PasswordRules::changePassword($username, $field); + } } diff --git a/app/Repositories/Core/Comments.php b/app/Repositories/Core/Comments.php index 48cebaa4..a61e7496 100644 --- a/app/Repositories/Core/Comments.php +++ b/app/Repositories/Core/Comments.php @@ -40,7 +40,7 @@ class Comments public static function getClass($model) { - return 'App\Models\\' . str_replace('.','\\', $model); + return 'App\Models\\' . str_replace('.', '\\', $model); } public static function getByModel($model) @@ -66,7 +66,7 @@ class Comments unset($data['_token']); $data['commentable_type'] = Comments::getClass($data['commentable_type']); $data['commentable_id'] = (int) $data['commentable_id']; - return $id ? self::update($data, $id) : self::create($data); + return $id ? self::update($data, $id) : self::create($data); } public static function create($data) @@ -83,7 +83,7 @@ class Comments $model = self::get($id); $model->update($data); return $model; - } + } public static function deleteComments($model) { @@ -94,5 +94,4 @@ class Comments { return true; } - } diff --git a/app/Repositories/Core/Database.php b/app/Repositories/Core/Database.php index e39c1186..32725c70 100644 --- a/app/Repositories/Core/Database.php +++ b/app/Repositories/Core/Database.php @@ -3,7 +3,7 @@ namespace App\Repositories\Core; use Illuminate\Support\Facades\Schema; -use Collective\Html\Eloquent\FormAccessible; +use Collective\Html\Eloquent\Form; class Database { diff --git a/app/Repositories/Core/DateCalculation.php b/app/Repositories/Core/DateCalculation.php index e44b8cfe..ba9e4f31 100644 --- a/app/Repositories/Core/DateCalculation.php +++ b/app/Repositories/Core/DateCalculation.php @@ -6,8 +6,6 @@ use Illuminate\Support\Str; use Carbon\Carbon; use Jenssegers\Date\Date; -use App\Repositories\Languages; - class DateCalculation { public static function isPast($date, $format = false) @@ -20,12 +18,12 @@ class DateCalculation return Carbon::createFromFormat(self::getFormat($format), $date)->greaterThan(Carbon::now()); } - public static function isAfter($date1, $date2) + public static function isAfter($date1, $date2, $format = false) { return Carbon::createFromFormat(self::getFormat($format), $date1)->greaterThan(Carbon::createFromFormat(self::getFormat($format), $date2)); } - public static function isBefore($date1, $date2) + public static function isBefore($date1, $date2, $format = false) { return Carbon::createFromFormat(self::getFormat($format), $date1)->lessThan(Carbon::createFromFormat(self::getFormat($format), $date2)); } diff --git a/app/Repositories/Core/Export.php b/app/Repositories/Core/Export.php index 7160fd08..ec69b799 100644 --- a/app/Repositories/Core/Export.php +++ b/app/Repositories/Core/Export.php @@ -4,6 +4,14 @@ namespace App\Repositories\Core; class Export { + public $xls; + public $sheet; + public $filename; + public $stockage; + public $lig; + public $nb; + public $debug; + public function __construct() { set_time_limit(0); @@ -68,7 +76,7 @@ class Export $txt = $options[$key][$txt]; } if (isset($multioptions[$key])) { - $tabs = BaseController::getReverseMultiOptions($txt); + $tabs = self::getReverseMultiOptions($txt); foreach ($tabs as $key2 => $value) { $txt .= $multioptions[$key][$key2] . '\n'; } diff --git a/app/Repositories/Core/Stat.php b/app/Repositories/Core/Stat.php index 9c9b30b1..ff519dbc 100644 --- a/app/Repositories/Core/Stat.php +++ b/app/Repositories/Core/Stat.php @@ -2,6 +2,8 @@ namespace App\Repositories\Core; +use Carbon\Carbon; + class Stat { public static $is_debug = false; @@ -17,48 +19,38 @@ class Stat return $model->where('created_at', '<', $end)->count(); } - /* - fonctions de rendus - */ - public static function renderStatsbyMultiVar($var, $var_option = '') { - static::renderStatsJson(static::getStatsbyMultiVar($var, $var_option)); + self::renderStatsJson(self::getStatsbyMultiVar($var, $var_option)); } public static function renderStatsbyVar($var) { - static::renderStatsJson(static::getStatsbyVar($var)); + self::renderStatsJson(self::getStatsbyVar($var)); } public static function renderStatsbyOptions($var, $var_option = '') { - static::renderStatsJson(static::getStatsbyOptions($var, $var_option)); + self::renderStatsJson(self::getStatsbyOptions($var, $var_option)); } public static function renderStatsJson($data) { - Response::headers()->set('Content-Type', 'application/json'); - Response::setBody(json_encode($data, JSON_NUMERIC_CHECK)); + return json_encode($data, JSON_NUMERIC_CHECK); } - - /* - Fonctions internes - */ - public static function getStatsbyMultiVar($var, $var_option = '') { if (empty($var_option)) { $var_option = $var; } - $options = self::getInstance()->controller->getOption($var_option); - return self::getInstance()->getStatsbyMultiOptions($var, $options); + $options = self::getOption($var_option); + return self::getStatsbyMultiOptions($var, $options); } public static function getCountByPeriod($var, $begin, $end) { - $count = static::getModel() + $count = self::getModel() ->whereBetween($var, $begin, $end) ->count(); return $count; @@ -67,7 +59,7 @@ class Stat public static function getCountbyVar($var) { $db = self::getInstance()->app->db; - $data = static::getModel() + $data = self::getModel() ->select($db::raw("count(id) as y, $var as name")) ->groupBy($var) ->get(); @@ -82,7 +74,7 @@ class Stat $var_option = $var; } $options = self::getInstance()->controller->getOption($var_option); - $nb = static::getCountbyOption($var); + $nb = self::getCountbyOption($var); // var_Debug::message($nb); foreach ($options as $key => $value) { $y = (int) $nb[$key]; @@ -95,7 +87,7 @@ class Stat public static function getCountbyOption($var) { $db = self::getInstance()->app->db; - $data = static::getModel() + $data = self::getModel() ->select($db::raw('count(id) as nb')) ->groupBy($var) ->get(); @@ -112,7 +104,7 @@ class Stat public static function getStatsbyMultiOptions($var, $options) { foreach ($options as $key => $value) { - $nb = static::getCountbyBin($var, $key); + $nb = self::getCountbyBin($var, $key); $data[] = ['y' => $nb, 'name' => $value]; } return ($data); @@ -121,7 +113,7 @@ class Stat public static function getCountbyBin($var, $value) { $bit = pow(2, $value); - $count = static::getModel() + $count = self::getModel() ->where($var, '&', $bit) ->count(); return $count; @@ -149,7 +141,7 @@ class Stat public static function serializeValues($tab) { - return static::serializeByVar($tab, 'count'); + return self::serializeByVar($tab, 'count'); } public static function serializeByVar($tab, $var, $n = 0) diff --git a/app/Repositories/Core/Upload.php b/app/Repositories/Core/Upload.php index b8c11f60..9bdcb469 100644 --- a/app/Repositories/Core/Upload.php +++ b/app/Repositories/Core/Upload.php @@ -21,10 +21,8 @@ class Upload { $data = (is_array($data)) ? (object) $data : $data; $pos = strrpos($file, '/'); - $uuid = substr($file, $pos+1); + $uuid = substr($file, $pos + 1); $uuid = pathinfo($uuid, PATHINFO_FILENAME); - // $uuid = str_replace('.' . strtolower($data->filetype), '', $uuid); - // $uuid = str_replace('.' . $data->filetype, '', $uuid); return $uuid; } @@ -36,6 +34,7 @@ class Upload // $path = Storage::putFile('avatars', $request->file('avatar')); // $path = $request->file('avatar')->storeAs('avatars',$request->user()->id,'s3'); // $path = $request->file('avatar')->storePublicly('avatars', 's3'); + $request = Request(); return $request->has($var) ? basename($request->file($var)->store($path)) : false; } @@ -128,27 +127,17 @@ class Upload if (Storage::exists($dest)) { self::delete($dest); } - return Storage::move($source, $dest); // transfère et renomme le fichier du dossier temporaire au dossier du client + return Storage::move($source, $dest); } public static function delete($file) { - // Storage::delete($file); - // return unlink($file); - return Storage::delete($file); - } - - public static function deleteFile($path) - { - if (!Storage::exists($path)) { - return false; - } - return Storage::delete($path); + return Storage::exists($file) ? Storage::delete($file) : false; } public static function deleteRecursive($path) { - rmdir_recursive($targetDir); + return rmdir_recursive($path); } public function make_dir($path, $permissions = 0777) diff --git a/app/Repositories/Core/User/ShopCart.php b/app/Repositories/Core/User/ShopCart.php index 1b207d12..a8d2cd12 100644 --- a/app/Repositories/Core/User/ShopCart.php +++ b/app/Repositories/Core/User/ShopCart.php @@ -3,6 +3,7 @@ namespace App\Repositories\Core\User; use App\Repositories\Core\Auth\Users; +use \Cart; class ShopCart { @@ -11,8 +12,40 @@ class ShopCart return self::get()->add($data); } + public static function remove($id) + { + return self::get()->remove($id); + } + + public static function clear() + { + Cart::session(1)->clear(); + return Cart::clear(); + // return self::get()->clear(); + } + + public static function has($id) + { + return array_key_exists($id, self::getContent()->toArray()); + } + + public static function keys() + { + return array_keys(self::getContent()->toArray()); + } + + public static function count() + { + return self::getContent()->count(); + } + + public static function getContent() + { + return self::get()->getContent(); + } + public static function get() { - return \Cart::session(Users::getId()); + return Cart::session(Users::getId()); } } diff --git a/app/Repositories/Core/User/ShopCartStorage.php b/app/Repositories/Core/User/ShopCartStorage.php new file mode 100644 index 00000000..9075eebd --- /dev/null +++ b/app/Repositories/Core/User/ShopCartStorage.php @@ -0,0 +1,38 @@ +has($key)) { + return new CartCollection(CartStorage::find($key)->cart_data); + } else { + return []; + } + } + + public function put($key, $value) + { + if ($row = CartStorage::find($key)) { + $row->cart_data = $value; + $row->save(); + } else { + CartStorage::create([ + 'id' => $key, + 'cart_data' => $value + ]); + } + } +} diff --git a/app/Repositories/Shop/ArticleComponents.php b/app/Repositories/Shop/ArticleComponents.php deleted file mode 100644 index 56bb20c6..00000000 --- a/app/Repositories/Shop/ArticleComponents.php +++ /dev/null @@ -1,52 +0,0 @@ -make(true); - } - - public static function getAll() - { - return ArticleComponent::orderBy('name', 'asc')->get(); - } - - public static function get($id) - { - return ArticleComponent::find($id); - } - - public static function store($data) - { - $id = isset($data['id']) ? $data['id'] : false; - $item = $id ? self::update($data) : self::create($data); - return $item->id; - } - - public static function create($data) - { - return ArticleComponent::create($data); - } - - public static function update($data) - { - return ArticleComponent::find($id)->update($data); - } - - public static function destroy($id) - { - return ArticleComponent::destroy($id); - } -} diff --git a/app/Repositories/Shop/ArticlePrices.php b/app/Repositories/Shop/ArticlePrices.php deleted file mode 100644 index 662ad79b..00000000 --- a/app/Repositories/Shop/ArticlePrices.php +++ /dev/null @@ -1,96 +0,0 @@ -get(); - } - - public static function getByArticleWithAttribute($id) - { - return ArticlePrice::with('article_attribute.attribute_value')->byArticle($id)->get(); - } - - public static function getDatatable() - { - $model = ArticlePrice::orderBy('name'); - return Datatables::of($model)->make(true); - } - - public static function getAll() - { - return ArticlePrice::orderBy('name', 'asc')->get(); - } - - public static function get($id) - { - return ArticlePrice::find($id); - } - - public static function storePrices($article_id, $prices) - { - // dump($article_id); - // dump($prices); - // exit; - if ($prices) { - foreach ($prices as $key => $price) { - $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 { - return false; - } - } - - public static function store($data) - { - $attributes = isset($data['attributes']) ? $data['attributes'] : false; - unset($data['attributes']); - - $id = isset($data['id']) ? $data['id'] : false; - $price = $id ? self::update($data) : self::create($data); - - $ret = $attributes ? self::storeAttributes($price->id, $attributes) : false; - - return $price->id; - } - - public static function storeAttributes($article_price_id, $attributes) - { - return ArticleAttributes::storeAttribute($article_price_id, $attributes); - } - - - public static function create($data) - { - return ArticlePrice::create($data); - } - - public static function update($data, $id = false) - { - $id = isset($data['id']) ? $data['id'] : false; - $article = ArticlePrice::find($id); - $article->update($data); - return $article; - } - - public static function destroy($id) - { - return ArticlePrice::destroy($id); - } -} diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php index 617107e5..90eb6168 100644 --- a/app/Repositories/Shop/Articles.php +++ b/app/Repositories/Shop/Articles.php @@ -172,7 +172,7 @@ class Articles public static function getByCategory($category_id) { - return Article::byCategory($category_id)->with(['prices','product','image'])->get(); + return Article::byCategory($category_id)->with(['prices', 'product', 'image'])->get(); } public static function getCategoriesByArticle($article) @@ -223,7 +223,6 @@ class Articles self::storeImages($article, $images); self::storeCategories($article, $categories); self::storeTags($article, $tags); - self::storePrices($article, $prices); return $article->id; } @@ -270,11 +269,6 @@ class Articles return Tag::storeTags($article, $tags); } - public static function storePrices($article, $prices) - { - return ArticlePrices::storePrices($article->id, $prices); - } - public static function storeImages($article, $files) { return Medias::storeImages($article, $files); diff --git a/app/Repositories/Shop/Categories.php b/app/Repositories/Shop/Categories.php index 02cb0346..1865a500 100644 --- a/app/Repositories/Shop/Categories.php +++ b/app/Repositories/Shop/Categories.php @@ -118,7 +118,7 @@ class Categories public static function update($data, $id = false) { $id = $id ? $id : $data['id']; - $category = Category::find($id); + $category = self::get($id); $ret = $category->update($data); CategoryTrees::update($data, $category->category_id); return $category; @@ -127,7 +127,7 @@ class Categories public static function destroy($id) { $category = self::get($id); - self::deleteNode($category->category_id); + CategoryTrees::destroy($category->category_id); return Category::destroy($id); } diff --git a/app/Repositories/Shop/Merchandises.php b/app/Repositories/Shop/Merchandises.php new file mode 100644 index 00000000..70292022 --- /dev/null +++ b/app/Repositories/Shop/Merchandises.php @@ -0,0 +1,73 @@ +orderBy('name')->limit(30)->get()->pluck('name', 'id'); + $export = []; + foreach ($data as $key => $name) { + $export[] = ['value' => $key, 'text' => $name]; + } + return $export; + } + + public static function getPrices($id) + { + return Merchandise::with(['price_lists.price_list_values', 'price_lists.sale_channel'])->find($id); + } + + public static function getOptions() + { + return Merchandise::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']; + } + + public static function getAll() + { + return Merchandise::orderBy('name', 'asc')->get(); + } + + public static function get($id) + { + return Merchandise::find($id); + } + + public static function store($data) + { + $id = isset($data['id']) ? $data['id'] : false; + $item = $id ? self::update($data, $id) : self::create($data); + return $item->id; + } + + public static function create($data) + { + return Merchandise::create($data); + } + + public static function update($data, $id = false) + { + $id = $id ? $id : $data['id']; + $item = self::get($id); + $item->update($data); + return $item; + } + + public static function destroy($id) + { + return Merchandise::destroy($id); + } +} diff --git a/composer.json b/composer.json index 3065a93a..6e5dc615 100644 --- a/composer.json +++ b/composer.json @@ -70,6 +70,7 @@ "santigarcor/laratrust": "^6.0", "sebastienheyd/boilerplate": "^7.5", "smajohusic/laravel-mail-logger": "^1.0", + "softcreatr/php-mime-detector": "^3.2", "spatie/eloquent-sortable": "^3.11", "spatie/image-optimizer": "^1.4", "spatie/laravel-activitylog": "^3.6", diff --git a/config/app.php b/config/app.php index ef681e53..94044f34 100644 --- a/config/app.php +++ b/config/app.php @@ -165,6 +165,7 @@ return [ /* * Package Service Providers... */ + Darryldecode\Cart\CartServiceProvider::class, /* * Application Service Providers... @@ -226,6 +227,7 @@ return [ 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, + 'Cart' => Darryldecode\Cart\Facades\CartFacade::class, ], ]; diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 00000000..40be8e8f --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,161 @@ + + + PSR-2 The Laravel conventions + + + + + + + + + + + /app/Http/Resources/*\.php + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + *.php + + + database/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + app + config + public + resources + routes + tests + + */.phpstorm.meta.php + */_ide_helper.php + */database/* + */cache/* + */*.js + */*.css + */*.xml + */*.blade.php + */autoload.php + */storage/* + */docs/* + */vendor/* + */migrations/* + */config/* + */public/index.php + */*.blade.php + */Console/Kernel.php + */Exceptions/Handler.php + */Http/Kernel.php + */Providers/* + */resources/lang/* + + + + + diff --git a/resources/views/Admin/Shop/Articles/list.blade.php b/resources/views/Admin/Shop/Articles/list.blade.php index ba871dea..9c978ddc 100644 --- a/resources/views/Admin/Shop/Articles/list.blade.php +++ b/resources/views/Admin/Shop/Articles/list.blade.php @@ -4,8 +4,6 @@ 'breadcrumb' => [__('shop.articles.title')] ]) -@include('load.form.select2') - @section('content') @component('components.card') @include('components.datatable', ['route' => route('Admin.Shop.Articles.index'), 'model' => 'articles', 'with_filters' => true]) @@ -15,3 +13,4 @@ @endcomponent @endsection +@include('load.form.select2') diff --git a/resources/views/Admin/Shop/Packages/index.blade.php b/resources/views/Admin/Shop/Packages/index.blade.php deleted file mode 100644 index 23beca2e..00000000 --- a/resources/views/Admin/Shop/Packages/index.blade.php +++ /dev/null @@ -1,48 +0,0 @@ -@extends('layout.index', [ - 'title' => __('shop.packages.title'), - 'subtitle' => __('shop.packages.list'), - 'breadcrumb' => [__('shop.packages.title')] -]) - -@include('boilerplate::load.select2') - -@section('content') - - - -
- -
- @section('content') - @include('components.datatable', ['route' => route('Admin.Shop.Unities.index'), 'model' => 'ArticleAttributefamilies']) - @endsection -
- -
- @section('content') - @component('components.card') - @include('components.datatable', ['route' => route('Admin.Shop.ArticleAttributeValues.index'), 'model' => 'Unities']) - @endcomponent - - @component('components.layout.modal', ['title' => 'Filtres', 'id' => 'modal-filters']) - @include('Admin.Shop.Unities.partials.filters') - @endcomponent - @endsection -
- -
- -@endsection - -@push('scripts') - @include('components.js.datatable', ['route' => route('Admin.Shop.Unities.index'), 'model' => 'Unities']) -@endpush \ No newline at end of file diff --git a/resources/views/Admin/Shop/Packages/list.blade.php b/resources/views/Admin/Shop/Packages/list.blade.php index 61e495be..87b76a5d 100644 --- a/resources/views/Admin/Shop/Packages/list.blade.php +++ b/resources/views/Admin/Shop/Packages/list.blade.php @@ -5,13 +5,10 @@ ]) @section('content') - @component('components.card') @include('components.datatable', ['route' => route('Admin.Shop.Packages.index'), 'model' => 'packages', 'with_filters' => true]) + @component('components.layout.modal', ['title' => 'Filtres', 'id' => 'modal-packages-filters']) + @include('Admin.Shop.Packages.partials.filters') + @endcomponent @endcomponent - - @component('components.layout.modal', ['title' => 'Filtres', 'id' => 'modal-packages-filters']) - @include('Admin.Shop.Packages.partials.filters') - @endcomponent - @endsection diff --git a/resources/views/components/datatable.blade.php b/resources/views/components/datatable.blade.php index 823d04c1..4ea96631 100644 --- a/resources/views/components/datatable.blade.php +++ b/resources/views/components/datatable.blade.php @@ -1,5 +1,3 @@ -@include('load.datatables') -
@include('components.datatables.header') @if ($dataTable) @@ -7,6 +5,15 @@ @endif
+@if (($with_filters ?? false) && false) + @component('components.layout.modal', ['title' => 'Filtres', 'id' => 'modal-' . $model . '-filters']) + @dd($route) + @include('Admin.Shop.' . ucfirst($model) . '.partials.filters') + @endcomponent +@endif + +@include('load.datatables') + @push('js') @include('components.datatables.js.datatable') @endpush