From bba5f6d984e0cd05915e98b8f8ed55b2af7b0b28 Mon Sep 17 00:00:00 2001 From: Ludovic CANDELLIER Date: Mon, 5 Apr 2021 23:58:37 +0200 Subject: [PATCH] Fixes --- .../Shop/PriceGenericCategoriesDataTable.php | 2 + .../Shop/Admin/PriceGenericController.php | 4 +- .../PriceGenerics/partials/prices.blade.php | 42 +++++++++++++++---- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/app/DataTables/Shop/PriceGenericCategoriesDataTable.php b/app/DataTables/Shop/PriceGenericCategoriesDataTable.php index cd54c45b..95e21596 100644 --- a/app/DataTables/Shop/PriceGenericCategoriesDataTable.php +++ b/app/DataTables/Shop/PriceGenericCategoriesDataTable.php @@ -12,6 +12,7 @@ class PriceGenericCategoriesDataTable extends DataTable public function query(PriceGenericCategory $model) { + $model = $model->withCount('price_generics'); return self::buildQuery($model); } @@ -19,6 +20,7 @@ class PriceGenericCategoriesDataTable extends DataTable { return [ Column::make('name')->title('Nom'), + Column::make('price_generics_count')->title('Nb Tarifs')->class('text-right'), self::makeColumnButtons(), ]; } diff --git a/app/Http/Controllers/Shop/Admin/PriceGenericController.php b/app/Http/Controllers/Shop/Admin/PriceGenericController.php index a27bd7ac..b7fca3eb 100644 --- a/app/Http/Controllers/Shop/Admin/PriceGenericController.php +++ b/app/Http/Controllers/Shop/Admin/PriceGenericController.php @@ -29,7 +29,7 @@ class PriceGenericController extends Controller public function create() { $data['unities'] = Unities::getOptions(); - $data['taxes'] = Taxes::getOptions(); + $data['taxes_options'] = Taxes::getOptions(); $data['categories'] = PriceGenericCategories::getOptions(); return view('Shop.Admin.PriceGenerics.create',$data); } @@ -39,7 +39,7 @@ class PriceGenericController extends Controller $data['generic'] = PriceGenerics::getFull($id)->toArray(); $data['packages'] = Packages::getSelectByFamily($data['generic']['category']['article_family_id']); $data['unities'] = ($data['packages']['id'] ?? false) ? Unities::getSelectByPackage($data['packages']['id']) : []; - $data['taxes'] = Taxes::getOptions(); + $data['taxes_options'] = Taxes::getOptions(); $data['categories'] = PriceGenericCategories::getOptions(); return view('Shop.Admin.PriceGenerics.edit', $data); } diff --git a/resources/views/Shop/Admin/PriceGenerics/partials/prices.blade.php b/resources/views/Shop/Admin/PriceGenerics/partials/prices.blade.php index a932c0a2..7e4b046a 100644 --- a/resources/views/Shop/Admin/PriceGenerics/partials/prices.blade.php +++ b/resources/views/Shop/Admin/PriceGenerics/partials/prices.blade.php @@ -12,6 +12,7 @@ function append_price() { handle_prices(); handle_prices_taxed(); + handle_change_package(); // handle_append_attribute(); // $('.select2').select2(); } @@ -61,16 +62,41 @@ }) } - function handle_packages() { - $('.delete-price-btn').click(function() { - var $selector = $(this).parents('.row-price'); - var id = $selector.find('.price_id').val(); - confirm_delete(id, laroute.route('Shop.Admin.PriceGenericValues.destroy', {id : id}), function() { - $selector.remove(); - }); - }); + function handle_change_package() { + $('.packages').change( function() { + var package_id = $(this).val(); + var $package = $(this); + var $parent = $package.parent().parent(); + var $selector = $parent.find('.unities'); + load_unities($selector, package_id); + }); } + function init_unities() { + $('.packages').each( function() { + var package_id = $(this).val(); + var $package = $(this); + var $parent = $package.parent().parent(); + var $selector = $parent.find('.unities'); + load_unities($selector, package_id); + value_id = $selector.data('id'); + $selector.val(value_id).trigger('change'); + }); + } + + function load_unities($selector, package_id) { + $.ajax({ + url : "{{ route('Shop.Admin.Unities.getOptionsByPackage') }}", + method : 'POST', + data: { package_id: package_id }, + success : function(data) { + setOptions($selector, data); + // $selector.empty().select2({data: data}); + } + }); + } + + @endpush