]> _ Git - pmi.git/commitdiff
wip #5989 @5:30
authorsoufiane <soufiane@cubedesigners.com>
Mon, 5 Jun 2023 15:42:36 +0000 (17:42 +0200)
committersoufiane <soufiane@cubedesigners.com>
Mon, 5 Jun 2023 15:42:36 +0000 (17:42 +0200)
app/Http/Controllers/AjaxController.php
app/Models/Client.php
app/Models/CommandPanierSchema.php
resources/js/app.js
resources/js/components/CartItem.vue
resources/views/components/item-cart.blade.php
resources/views/pages/product-detail.blade.php
resources/views/partials/product-link.blade.php

index a17e9ae77855105ff89030cc79f6cd7be0751564..9f06090466959fbc7b03a89c6911af53822b17d5 100644 (file)
@@ -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();
index cb9a2f4c078b0635fdce8bf73d0a067a88337576..bd32260640055d83423ecd381e6ea527898b3075 100644 (file)
@@ -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;
+    }
 }
index 4f7404861fd7f0d380e96918747cb87c625e219c..ad83292cf2683ebe7e3f3baa482bc17a349c2c07 100644 (file)
@@ -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;
     }
 }
index 5f4d363e1a77fdd507fabc5abda39eb7e0e6926f..2d74912b0eaf308718e14555d97ae71afb9711c1 100644 (file)
@@ -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: {
index 81a2226da30d0b65504581f5a33bd21efd17df72..e5270b45fc0129a9cbb59320f1b936ee210213c8 100644 (file)
                 <span class="mr-2">Quantité</span>
                 <number-input v-model="item.quantity" :min="1" inline center controls></number-input>
             </div>
-            <div v-if="!isNaN(item.price)">
-                <span class="text-navy">{{ Number.parseFloat(price).toFixed(2) }}€ HT</span>
+            <div v-if="!isNaN(item.price)" :class="{ 'line-through' : item.discount > 0 }">
+                <span class="text-navy">{{ Number.parseFloat(price).toFixed(2) }}<span>€ HT</span></span>
+            </div>
+            <div v-if="item.discount > 0">
+                <span class="text-navy">{{ Number.parseFloat(priceDiscount).toFixed(2) }}€ HT</span>
             </div>
             <a href="#" class="cart-delete-item text-red" @click.prevent="deleteItem">
                 Supprimer
         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
             }
         },
 
index f49baa4bb68ac95d9d43e7d39439d28ac0b9c24a..5b5a03a31b2681aa3074169d990ce1e88e704254 100644 (file)
                         <div>
                             <p class="no-m">{{ $product['ref'] }}</p>
                             <p class="no-m text-navy">{{ $product['name'] }}</p>
-                            @isset($product['basic_selling_price'])
+                            @isset($product['discount'])
                                 @if(floatval($product['basic_selling_price']))
-                                    <p class="no-m">{{ __('Prix unitaire') }} <span class="text-navy">{{
+                                    <p class="no-m">{{ __('Prix catalogue') }} : <span class="text-navy line-through">{{
                                         $product['basic_selling_price'] }} € HT</span>
                                     </p>
+                                    <p class="no-m">{{ __('Votre prix') }} : <span class="text-navy">{{
+                                        $product['basic_selling_price'] - (($product['basic_selling_price'] * $product['discount']) / 100) }} € HT</span>
+                                    </p>
                                 @endif
+                            @else
+                                @isset($product['basic_selling_price'])
+                                    @if(floatval($product['basic_selling_price']))
+                                        <p class="no-m">{{ __('Prix unitaire') }} : <span class="text-navy">{{
+                                            $product['basic_selling_price'] }} € HT</span>
+                                        </p>
+                                    @endif
+                                @endisset
                             @endisset
                             <p class="no-m">{{ __('Quantité') }} : <span class="text-navy">{{$product['quantity']}}</span></p>
                         </div>
index e3fa87c89693dc4b7d51e12d5c381b1dd40ca786..b0ba9d2337da26b76edbbff89161287100173409 100644 (file)
@@ -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')
                         <div class="opt-infos mb-8">
                             <div class="opt-ref text-navy" v-cloak>{{ __('Référence') }} : <span ref="refProduct" data-ref="{{ $product->reference }}">@{{ ref }}</span></div>
                             <div class="opt-price text-navy">
-                                {{ __('Prix unitaire') }} :
-                                <span ref="optprice" v-cloak data-default="{{ $product->basic_selling_price }}">@{{ price }}</span>{{ "€ ".__('HT') }}
+                                @if($discount)
+                                    <div>
+                                        {{ __('Prix catalogue') }} :
+                                        <span class="line-through" ref="optprice" v-cloak data-default="{{ $product->basic_selling_price }}">@{{ price }}</span>{{ "€ ".__('HT') }}
+                                    </div>
+                                    <div>
+                                        {{ __('Votre prix') }} :
+                                        <span ref="discount" data-value="{{ $discount }}"></span>
+                                        <span v-cloak data-default="{{ $product->basic_selling_price }}">@{{ priceDiscount }}</span>{{ "€ ".__('HT') }}
+                                    </div>
+                                @else
+                                    {{ __('Prix unitaire') }} :
+                                    <span ref="optprice" v-cloak data-default="{{ $product->basic_selling_price }}">@{{ price }}</span>{{ "€ ".__('HT') }}
+                                @endif
                             </div>
                             <div class="opt-statut">{{ __('Statut') }} :
                                 <span v-cloak :class="{ 'text-green' : statusConfig }" ref="statusConfig" data-incomplete="{{ __('La configuration est incomplète') }}" data-completed="{{ __('La configuration est complète') }}">
index 5263a8b484622d58088c12e9cd0dee68963cbfb7..308f6571a5bdecd1d45840209c12b9cbab9bd52f 100644 (file)
@@ -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
 
 <div data-product-id="{{ $id }}" class="product-grid-item bg-grey-200">
             @if($product->basic_selling_price && $product->json)
                 @php($options = true)
                 <p class="no-m text-sm mt-5">{{ __('Produit configurable') }}</p>
-                <p>{{ __('A partir de :').' '.$product->basic_selling_price }}€ HT</p>
+                <p>{{ __('A partir de :').' '. $price }}€ HT</p>
             @elseif($product->basic_selling_price && !$product->json)
-                <p class="mt-5">{{ __('Votre prix :').' '. $product->basic_selling_price }}€ HT</p>
+                <p class="no-m line-through text-sm mt-5">{{ __('Prix catalogue :').' '.$product->basic_selling_price }}€ HT</p>
+                <p>{{ __('Votre prix :').' '. $price }}€ HT</p>
             @endif
         </div>
         @if(config('features.quote'))