$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;
});
'name' => $product->name,
'reference' => $product->reference,
'category' => $product->type->name,
+ 'discount' => $discount ?? 0,
'quantity' => $quantity,
'image' => $product->image,
'URL' => $product->url,
/**
*
*/
- $data = Panier::fillData($currentCartRef, $data);
+ $data = Panier::fillData($currentCartRef, $data, false);
if(sizeof($lastCartRefs) !== sizeof($intersect) ||
(sizeof($lastCartRefs) === sizeof($intersect) && sizeof($currentCartRef) != sizeof($lastCartRefs)) ) {
$currentCartRef = Panier::getRefs($data['products']);
$data = Command::fillData($currentCartRef, $data);
+// dd($data);
+
if($data) {
$order = Command::create($data);
$order->save();
'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',
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;
+ }
}
return self::all()->where('user_id', $userID)->toArray();
}
- public static function fillData($currentCartRef, $data) {
+ public static function fillData($currentCartRef, $data, $haveStatus = true) {
/**
*
*/
}) : 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;
}
$data['addresses'] = json_encode($data['addresses']);
$data['products'] = json_encode($data['products']);
+ if($haveStatus)
+ $data['status'] = 'new';
+
return $data;
}
}
ref: '',
statusConfig: false,
statusText: '',
+ discount: 0,
//
nameSaved: {},
confirmMessageCart: ''
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: {
},
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
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: {
<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
}
},
<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>
@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') }}">
$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'))