From: soufiane Date: Mon, 5 Jun 2023 15:42:36 +0000 (+0200) Subject: wip #5989 @5:30 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=6bd7bb9a74c50d0151f892d018a218aff5f5d4cf;p=pmi.git wip #5989 @5:30 --- diff --git a/app/Http/Controllers/AjaxController.php b/app/Http/Controllers/AjaxController.php index a17e9ae..9f06090 100644 --- a/app/Http/Controllers/AjaxController.php +++ b/app/Http/Controllers/AjaxController.php @@ -172,8 +172,11 @@ class AjaxController extends CubistFrontController $needs_update = false; $product = Product::find($id); + $currentItem = false; if($product) { + $categoryProduct = $product->category; + $discount = \App\Models\Client::discountArray($categoryProduct); $currentItem = array_filter($cart_items, function ($n) use ($ref) { return $n['ref'] === $ref; }); @@ -191,6 +194,7 @@ class AjaxController extends CubistFrontController 'name' => $product->name, 'reference' => $product->reference, 'category' => $product->type->name, + 'discount' => $discount ?? 0, 'quantity' => $quantity, 'image' => $product->image, 'URL' => $product->url, @@ -587,7 +591,7 @@ class AjaxController extends CubistFrontController /** * */ - $data = Panier::fillData($currentCartRef, $data); + $data = Panier::fillData($currentCartRef, $data, false); if(sizeof($lastCartRefs) !== sizeof($intersect) || (sizeof($lastCartRefs) === sizeof($intersect) && sizeof($currentCartRef) != sizeof($lastCartRefs)) ) { @@ -666,6 +670,8 @@ class AjaxController extends CubistFrontController $currentCartRef = Panier::getRefs($data['products']); $data = Command::fillData($currentCartRef, $data); +// dd($data); + if($data) { $order = Command::create($data); $order->save(); diff --git a/app/Models/Client.php b/app/Models/Client.php index cb9a2f4..bd32260 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -80,7 +80,17 @@ class Client extends CubistMagicAbstractModel 'type' => 'Checkbox', 'column' => true, 'tab' => 'Informations client' - ]); + ]); + + $this->addField(['name' => 'discount', + 'label' => 'Remise', + 'type' => 'select_from_array', + 'options' => ['A','B','C','D','E'], + 'allows_null' => false, + 'default' => 'A', + 'column' => true, + 'tab' => 'Informations client' + ]); $this->addField([ 'name' => 'remember_token', @@ -94,4 +104,30 @@ class Client extends CubistMagicAbstractModel public static function getClientConnected() { return Auth::guard('web-clients')->user(); } + + public static function discountArray($categoryProduct) { + $categoryClient = self::getClientConnected()->discount ?? 'A'; + $category_array = [ + 'A' => 0, + 'B' => 5, + 'C' => 10, + 'D' => 15, + 'E' => 20, + ]; + $discount_array = ['A','B','C','D','E']; + + $discount_array_save_keys = $discount_array; + + foreach ($discount_array as &$value) { + $value = $category_array; + } + + $discount_array = array_combine($discount_array_save_keys,$discount_array); + + if($categoryProduct && $categoryClient) { + return $discount_array[$categoryClient][$categoryProduct]; + } + + return null; + } } diff --git a/app/Models/CommandPanierSchema.php b/app/Models/CommandPanierSchema.php index 4f74048..ad83292 100644 --- a/app/Models/CommandPanierSchema.php +++ b/app/Models/CommandPanierSchema.php @@ -36,7 +36,7 @@ class CommandPanierSchema extends CubistMagicAbstractModel return self::all()->where('user_id', $userID)->toArray(); } - public static function fillData($currentCartRef, $data) { + public static function fillData($currentCartRef, $data, $haveStatus = true) { /** * */ @@ -65,7 +65,9 @@ class CommandPanierSchema extends CubistMagicAbstractModel }) : 0; $basicPriceByProductId = $data['products'][$keyRefs]["basic_selling_price"]; + $discount = floatval($data['products'][$keyRefs]["discount"]) ?? 0; $price = floatval($basicPriceByProductId + $totalOptionsPrice); + $price = ($price - (($price * $discount) / 100)); $total[] = floatval($price * $quantity); $data['products'][$keyRefs]["price"] = $price; } @@ -84,6 +86,9 @@ class CommandPanierSchema extends CubistMagicAbstractModel $data['addresses'] = json_encode($data['addresses']); $data['products'] = json_encode($data['products']); + if($haveStatus) + $data['status'] = 'new'; + return $data; } } diff --git a/resources/js/app.js b/resources/js/app.js index 5f4d363..2d74912 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -81,6 +81,7 @@ const app = new Vue({ ref: '', statusConfig: false, statusText: '', + discount: 0, // nameSaved: {}, confirmMessageCart: '' @@ -116,6 +117,7 @@ const app = new Vue({ this.ref = this.$refs.refProduct?.dataset.ref this.price = parseFloat(this.$refs.optprice ?.dataset.default).toFixed(2) this.statusText = this.$refs.statusConfig ?.dataset.incomplete + this.discount = this.$refs.discount ?.dataset.value }, watch: { @@ -139,7 +141,7 @@ const app = new Vue({ }, total() { - let prices = this.items.length ? this.items.map(item => item.price * item.quantity) : false + let prices = this.items.length ? this.items.map(item => (item.price - ((item.price * item.discount) / 100)) * item.quantity) : false prices = prices ? Number.parseFloat(prices.reduce((init, current) => init + current)) : 0 prices += (prices > 1000) ? 20 : 0 @@ -156,6 +158,12 @@ const app = new Vue({ let total = this.total ? parseFloat(this.total) + parseFloat(this.tva) : 0 return total.toFixed(2) }, + + priceDiscount() { + let discount = this.discount ?? 0 + let newValue = (this.price * discount) / 100 + return this.price - newValue.toFixed(2) + } }, methods: { diff --git a/resources/js/components/CartItem.vue b/resources/js/components/CartItem.vue index 81a2226..e5270b4 100644 --- a/resources/js/components/CartItem.vue +++ b/resources/js/components/CartItem.vue @@ -16,8 +16,11 @@ Quantité -
- {{ Number.parseFloat(price).toFixed(2) }}€ HT +
+ {{ Number.parseFloat(price).toFixed(2) }}€ HT +
+
+ {{ Number.parseFloat(priceDiscount).toFixed(2) }}€ HT
Supprimer @@ -66,6 +69,11 @@ computed: { price() { return this.item.price * this.item.quantity + }, + + priceDiscount() { + let newValue = (this.item.price * this.item.discount) / 100 + return (this.item.price - newValue.toFixed(2)) * this.item.quantity } }, diff --git a/resources/views/components/item-cart.blade.php b/resources/views/components/item-cart.blade.php index f49baa4..5b5a03a 100644 --- a/resources/views/components/item-cart.blade.php +++ b/resources/views/components/item-cart.blade.php @@ -30,12 +30,23 @@

{{ $product['ref'] }}

{{ $product['name'] }}

- @isset($product['basic_selling_price']) + @isset($product['discount']) @if(floatval($product['basic_selling_price'])) -

{{ __('Prix unitaire') }} {{ +

{{ __('Prix catalogue') }} : {{ $product['basic_selling_price'] }} € HT

+

{{ __('Votre prix') }} : {{ + $product['basic_selling_price'] - (($product['basic_selling_price'] * $product['discount']) / 100) }} € HT +

@endif + @else + @isset($product['basic_selling_price']) + @if(floatval($product['basic_selling_price'])) +

{{ __('Prix unitaire') }} : {{ + $product['basic_selling_price'] }} € HT +

+ @endif + @endisset @endisset

{{ __('Quantité') }} : {{$product['quantity']}}

diff --git a/resources/views/pages/product-detail.blade.php b/resources/views/pages/product-detail.blade.php index e3fa87c..b0ba9d2 100644 --- a/resources/views/pages/product-detail.blade.php +++ b/resources/views/pages/product-detail.blade.php @@ -1,11 +1,14 @@ @php $technical_sheet = $product->getMediaUrl('technical_sheet', false); $specs = $product->json; + $categoryProduct = $product->category; $template = $view_name; $options = false; if($product->basic_selling_price && $product->json) { $options = true; } + + $discount = \App\Models\Client::discountArray($categoryProduct); @endphp @extends('layouts/app') @@ -85,8 +88,20 @@
{{ __('Référence') }} : @{{ ref }}
- {{ __('Prix unitaire') }} : - @{{ price }}{{ "€ ".__('HT') }} + @if($discount) +
+ {{ __('Prix catalogue') }} : + @{{ price }}{{ "€ ".__('HT') }} +
+
+ {{ __('Votre prix') }} : + + @{{ priceDiscount }}{{ "€ ".__('HT') }} +
+ @else + {{ __('Prix unitaire') }} : + @{{ price }}{{ "€ ".__('HT') }} + @endif
{{ __('Statut') }} : diff --git a/resources/views/partials/product-link.blade.php b/resources/views/partials/product-link.blade.php index 5263a8b..308f657 100644 --- a/resources/views/partials/product-link.blade.php +++ b/resources/views/partials/product-link.blade.php @@ -2,6 +2,11 @@ $technical_sheet = $product->getMediaUrl('technical_sheet', false); $template = $view_name; $options = false; + + $categoryProduct = $product->category; + $discount = \App\Models\Client::discountArray($categoryProduct); + + $price = number_format($product->basic_selling_price - (($product->basic_selling_price * $discount) / 100), 2); @endphp
@@ -26,9 +31,10 @@ @if($product->basic_selling_price && $product->json) @php($options = true)

{{ __('Produit configurable') }}

-

{{ __('A partir de :').' '.$product->basic_selling_price }}€ HT

+

{{ __('A partir de :').' '. $price }}€ HT

@elseif($product->basic_selling_price && !$product->json) -

{{ __('Votre prix :').' '. $product->basic_selling_price }}€ HT

+

{{ __('Prix catalogue :').' '.$product->basic_selling_price }}€ HT

+

{{ __('Votre prix :').' '. $price }}€ HT

@endif
@if(config('features.quote'))