From daeece59c9ad8b477dcd66d27d8c32f4ae4d7b1c Mon Sep 17 00:00:00 2001 From: Ludovic CANDELLIER Date: Tue, 27 Jul 2021 17:33:18 +0200 Subject: [PATCH] Fixes on adding price & errors --- Gruntfile.js | 20 +++---- app/Datatables/Shop/PriceListsDataTable.php | 2 + app/Datatables/Shop/TariffsDataTable.php | 4 +- .../Admin/Shop/PriceListController.php | 2 +- ...oller.php => PriceListValueController.php} | 13 ++-- app/Models/Shop/PriceList.php | 15 +++++ app/Repositories/Shop/PriceLists.php | 19 +++--- build/css/main.css | 2 +- .../partials/row_price.blade.php | 12 ++++ .../admin/Shop/PriceLists/modal.blade.php | 60 ++++++++++++------- .../views/admin/Shop/Tariffs/form.blade.php | 24 ++++---- .../admin/Shop/Variations/form.blade.php | 5 +- resources/views/auth/login.blade.php | 8 +-- resources/views/components/card.blade.php | 2 +- .../views/components/layout/modal.blade.php | 4 +- resources/views/load/layout/modal.blade.php | 4 +- routes/Admin/Shop/PriceListValues.php | 2 +- routes/Admin/Shop/route.php | 1 + 18 files changed, 123 insertions(+), 76 deletions(-) rename app/Http/Controllers/Admin/Shop/{PriceListValuesController.php => PriceListValueController.php} (93%) create mode 100644 resources/views/admin/Shop/PriceListValues/partials/row_price.blade.php diff --git a/Gruntfile.js b/Gruntfile.js index 86dddd71..7dc36ba7 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -533,6 +533,12 @@ module.exports = function(grunt) { src: ['**'], dest: 'public/assets/plugins/tinymce/skins/ui/boilerplate', }, + { + expand: true, + cwd: 'node_modules/icheck-bootstrap/', + src: ['icheck-bootstrap.min.css'], + dest: 'public/assets/plugins/icheck/' + }, { expand: true, cwd: 'build/js/include/', @@ -544,22 +550,10 @@ module.exports = function(grunt) { }, watch: { dist: { - files: [ - 'Admin/*', - ], + files: ['build/js/*', 'build/css/*'], tasks: ['concat', 'copy'] } }, - handlebars: { - compile: { - options: { - namespace: "JST" - }, - files: { - "assets/tpl/content.hbs": "public/assets/tpl/content.hbs" - } - } - } }); // Load the plugin that provides the "uglify" task. diff --git a/app/Datatables/Shop/PriceListsDataTable.php b/app/Datatables/Shop/PriceListsDataTable.php index 60635dd4..a82b7c48 100644 --- a/app/Datatables/Shop/PriceListsDataTable.php +++ b/app/Datatables/Shop/PriceListsDataTable.php @@ -17,6 +17,7 @@ class PriceListsDataTable extends DataTable public function query(PriceList $model) { + $model = $model->with('sale_channel'); $model = self::filterByTariff($model); return self::buildQuery($model); } @@ -32,6 +33,7 @@ class PriceListsDataTable extends DataTable { return [ 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 da6ec451..b0fe3a4e 100644 --- a/app/Datatables/Shop/TariffsDataTable.php +++ b/app/Datatables/Shop/TariffsDataTable.php @@ -19,10 +19,10 @@ class TariffsDataTable extends DataTable protected function getColumns() { return [ - Column::make('sale_channel.name')->title('Canal de vente'), + Column::make('name')->title('Nom'), + Column::make('sale_channel.name')->title('Canal de vente par défaut'), Column::make('code')->title('Code'), Column::make('ref')->title('Référence'), - Column::make('name')->title('Nom'), self::makeColumnButtons(), ]; } diff --git a/app/Http/Controllers/Admin/Shop/PriceListController.php b/app/Http/Controllers/Admin/Shop/PriceListController.php index 4ec447d8..21a5c1ea 100644 --- a/app/Http/Controllers/Admin/Shop/PriceListController.php +++ b/app/Http/Controllers/Admin/Shop/PriceListController.php @@ -47,7 +47,7 @@ class PriceListController extends Controller public function modalEdit($id) { - $data['price_list'] = PriceLists::getFull($id); + $data['price_list'] = PriceLists::edit($id); $data['sale_channels'] = SaleChannels::getOptions(); $data['statuses'] = Tariffs::getStatuses(); return view('Admin.Shop.PriceLists.modal', $data); diff --git a/app/Http/Controllers/Admin/Shop/PriceListValuesController.php b/app/Http/Controllers/Admin/Shop/PriceListValueController.php similarity index 93% rename from app/Http/Controllers/Admin/Shop/PriceListValuesController.php rename to app/Http/Controllers/Admin/Shop/PriceListValueController.php index cad248d8..7b3d038a 100644 --- a/app/Http/Controllers/Admin/Shop/PriceListValuesController.php +++ b/app/Http/Controllers/Admin/Shop/PriceListValueController.php @@ -21,11 +21,6 @@ class PriceListValueController extends Controller return $dataTable->render('Admin.Shop.PriceListValues.list', $data); } - public function getDatatable(Request $request) - { - return PriceListValues::getTables($request->all()); - } - public function create() { $data['unities'] = Unities::getOptions(); @@ -66,4 +61,12 @@ class PriceListValueController extends Controller $data['generic'] = PriceListValues::getFull($id); return view('Admin.Shop.PriceListValues.partials.table-prices', $data); } + + public function addPrice($index) + { + $data['index'] = $index; + return view('Admin.Shop.PriceListValues.partials.row_price', $data); + } + + } diff --git a/app/Models/Shop/PriceList.php b/app/Models/Shop/PriceList.php index df1eaaee..c93e731f 100644 --- a/app/Models/Shop/PriceList.php +++ b/app/Models/Shop/PriceList.php @@ -26,4 +26,19 @@ class PriceList extends Model { return $this->hasMany('App\Models\Shop\PriceListValue'); } + + public function scopeByTariff($query, $id) + { + return $query->where('tariff_id', $id); + } + + public function scopeBySaleChannel($query, $id) + { + return $query->where('sale_channel_id', $id); + } + + public function scopeByStatus($query, $id) + { + return $query->where('status_id', $id); + } } diff --git a/app/Repositories/Shop/PriceLists.php b/app/Repositories/Shop/PriceLists.php index 70715629..0d7c01df 100644 --- a/app/Repositories/Shop/PriceLists.php +++ b/app/Repositories/Shop/PriceLists.php @@ -10,19 +10,14 @@ use App\Models\Shop\PriceList; class PriceLists { - public static function getByArticle($id) + public static function getByTariff($id) { - return PriceList::byArticle($id)->get(); - } - - public static function getByArticleWithValues($id) - { - return PriceList::with('values')->byArticle($id)->get(); + return PriceList::byTariff($id)->get(); } public static function getOptions() { - return PriceList::with('prices')->get()->toArray(); + return PriceList::pluck('name','id')->toArray(); } public static function getAll() @@ -30,6 +25,14 @@ class PriceLists return PriceList::orderBy('name', 'asc')->get(); } + public static function edit($id) + { + $price_list = self::getFull($id)->toArray(); + $n = count($price_list['price_list_values']); + $price_list['price_list_values'] += array_fill($n, 3 - $n, ''); + return $price_list; + } + public static function get($id) { return PriceList::find($id); diff --git a/build/css/main.css b/build/css/main.css index ac4b812f..dad31c7b 100644 --- a/build/css/main.css +++ b/build/css/main.css @@ -52,4 +52,4 @@ ul .jqtree_common { .yellow { color: #F2B90F!important; -} \ No newline at end of file +} diff --git a/resources/views/admin/Shop/PriceListValues/partials/row_price.blade.php b/resources/views/admin/Shop/PriceListValues/partials/row_price.blade.php new file mode 100644 index 00000000..8b0c83b5 --- /dev/null +++ b/resources/views/admin/Shop/PriceListValues/partials/row_price.blade.php @@ -0,0 +1,12 @@ + + + + @include('components.input', ['name' => 'price_list_values[' . $index . '][code]', 'value' => $price_list_value['code'] ?? null, 'required' => true]) + + + @include('components.number', ['name' => 'price_list_values[' . $index . '][quantity]', 'value' => $price_list_value['quantity'] ?? null, 'required' => true, 'meta' => "step = '.01'"]) + + + @include('components.money', ['name' => 'price_list_values[' . $index . '][price]', 'value' => $price_list_value['price'] ?? null, 'required' => true]) + + \ No newline at end of file diff --git a/resources/views/admin/Shop/PriceLists/modal.blade.php b/resources/views/admin/Shop/PriceLists/modal.blade.php index 3fa90fab..a136753c 100644 --- a/resources/views/admin/Shop/PriceLists/modal.blade.php +++ b/resources/views/admin/Shop/PriceLists/modal.blade.php @@ -4,26 +4,25 @@
-
+
+ {{ Form::label('name', 'Nom') }} + @include('components.input', ['name' => 'name', 'value' => $price_list['name'] ?? null, 'required' => true]) +
+
{{ Form::label('status_id', 'Etat') }} @include('components.select', ['name' => 'status_id', 'list' => $statuses ?? [], 'value' => $price_list['status_id'] ?? null, 'required' => true])
+
+ +
{{ Form::label('sale_channel_id', 'Canal de vente') }} @include('components.select', ['name' => 'sale_channel_id', 'list' => $sale_channels ?? [], 'value' => $price_list['sale_channel_id'] ?? null, 'required' => true, 'with_empty' => ''])
-
-
- {{ Form::label('name', 'Nom') }} - @include('components.input', ['name' => 'name', 'value' => $price_list['name'] ?? null, 'required' => true]) -
-
- - @component('components.card', ['title' => 'Prix']) - +
@@ -33,20 +32,37 @@ @foreach ($price_list['price_list_values'] as $price_list_value) - - - - - + @include('admin.Shop.PriceListValues.partials.row_price', ['index' => $loop->index]) @endforeach + + + + +
Code
- @include('components.input', ['name' => 'price_list_values[' . $loop->index . '][code]', 'value' => $price_list_value['name'] ?? null, 'required' => true]) - - @include('components.number', ['name' => 'price_list_values[' . $loop->index . '][quantity]', 'value' => $price_list_value['quantity'] ?? null, 'required' => true, 'meta' => "step = '.01'"]) - - @include('components.money', ['name' => 'price_list_values[' . $loop->index . '][price]', 'value' => $price_list_value['price'] ?? null, 'required' => true]) -
+ +
@endcomponent - \ No newline at end of file + + + + diff --git a/resources/views/admin/Shop/Tariffs/form.blade.php b/resources/views/admin/Shop/Tariffs/form.blade.php index c2471f75..c7dbab53 100644 --- a/resources/views/admin/Shop/Tariffs/form.blade.php +++ b/resources/views/admin/Shop/Tariffs/form.blade.php @@ -2,37 +2,39 @@
-
+
{{ Form::label('name', 'Nom') }} @include('components.input', ['name' => 'name', 'value' => $tariff['name'] ?? null, 'required' => true])
-
-
-
- {{ Form::label('name', 'Canal de vente') }} - @include('components.select', ['name' => 'sale_channel_id', 'list' => $sale_channels ?? [], 'value' => $tariff['sale_channel_id'] ?? null, 'required' => true, 'with_empty' => '']) -
-
+
{{ Form::label('name', 'Etat') }} @include('components.select', ['name' => 'status_id', 'list' => $statuses ?? [], 'value' => $tariff['status_id'] ?? null, 'required' => true, 'with_empty' => ''])
-
+
{{ Form::label('name', 'Code') }} @include('components.input', ['name' => 'code', 'value' => $tariff['code'] ?? null, 'required' => true])
-
+
{{ Form::label('name', 'Ref') }} @include('components.input', ['name' => 'ref', 'value' => $tariff['ref'] ?? null, 'required' => true])
-
+
+ +
+
+ {{ Form::label('name', 'Canal de vente par défaut') }} + @include('components.select', ['name' => 'sale_channel_id', 'list' => $sale_channels ?? [], 'value' => $tariff['sale_channel_id'] ?? null, 'required' => true, 'with_empty' => '']) +
+
{{ Form::label('name', 'Unité du tarif') }} @include('components.select', ['name' => 'tariff_unity_id', 'list' => $tariff_unities ?? [], 'value' => $tariff['tariff_unity_id'] ?? null, 'required' => true, 'with_empty' => ''])
+
{{ Form::label('description', 'Description') }} diff --git a/resources/views/admin/Shop/Variations/form.blade.php b/resources/views/admin/Shop/Variations/form.blade.php index 43d0ca4c..73b9b01d 100644 --- a/resources/views/admin/Shop/Variations/form.blade.php +++ b/resources/views/admin/Shop/Variations/form.blade.php @@ -26,13 +26,12 @@ @include('components.save') - -@include('boilerplate::load.tinymce') +@include('load.form.editor') @push('js') @endpush \ No newline at end of file diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index da507b8e..d72f9569 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -5,9 +5,9 @@ @section('content') {!! Form::open(['route' => 'boilerplate.login', 'method' => 'post', 'autocomplete'=> 'off']) !!} -
+
- +
@@ -26,7 +26,7 @@
-
+
-
+
diff --git a/resources/views/components/card.blade.php b/resources/views/components/card.blade.php index a990090f..37389f5e 100644 --- a/resources/views/components/card.blade.php +++ b/resources/views/components/card.blade.php @@ -7,7 +7,7 @@

{{ $title }}

@isset($tools)
- {{ $tools }} + {!! $tools !!}
@endisset @endisset diff --git a/resources/views/components/layout/modal.blade.php b/resources/views/components/layout/modal.blade.php index 7bf58043..66997aa7 100644 --- a/resources/views/components/layout/modal.blade.php +++ b/resources/views/components/layout/modal.blade.php @@ -14,8 +14,8 @@ @if (isset($buttons)) {{ $buttons }} @endif - - + +
diff --git a/resources/views/load/layout/modal.blade.php b/resources/views/load/layout/modal.blade.php index 2552f2b9..da0934a9 100644 --- a/resources/views/load/layout/modal.blade.php +++ b/resources/views/load/layout/modal.blade.php @@ -57,11 +57,11 @@ if (!no_confirm) { var buttons = { cancel: { - label: '{{ __('cancel') }}', + label: '{{ __('Annuler') }}', className: 'btn-secondary' }, confirm: { - label: '{{ __('save') }}', + label: '{{ __('Sauver') }}', className: 'btn-success', callback: function() { submitModal(form_id); diff --git a/routes/Admin/Shop/PriceListValues.php b/routes/Admin/Shop/PriceListValues.php index 203fb85c..94d2a8b6 100644 --- a/routes/Admin/Shop/PriceListValues.php +++ b/routes/Admin/Shop/PriceListValues.php @@ -4,8 +4,8 @@ Route::prefix('PriceListValues')->name('PriceListValues.')->group(function () { Route::get('', 'PriceListValueController@index')->name('index'); Route::get('create', 'PriceListValueController@create')->name('create'); Route::delete('destroy/{id?}', 'PriceListValueController@destroy')->name('destroy'); - Route::post('update', 'PriceListValueController@update')->name('update'); Route::post('store', 'PriceListValueController@store')->name('store'); Route::get('edit/{id}', 'PriceListValueController@edit')->name('edit'); + Route::get('addPrice/{index?}', 'PriceListValueController@addPrice')->name('addPrice'); }); diff --git a/routes/Admin/Shop/route.php b/routes/Admin/Shop/route.php index e432274a..fbf995f9 100644 --- a/routes/Admin/Shop/route.php +++ b/routes/Admin/Shop/route.php @@ -13,6 +13,7 @@ Route::middleware('auth')->prefix('Shop')->namespace('Shop')->name('Shop.')->gro include __DIR__ . '/Orders.php'; include __DIR__ . '/Packages.php'; include __DIR__ . '/PriceLists.php'; + include __DIR__ . '/PriceListValues.php'; include __DIR__ . '/SaleChannels.php'; include __DIR__ . '/Tags.php'; include __DIR__ . '/TagGroups.php';