diff --git a/app/Models/Product.php b/app/Models/Product.php index 8b7624b2..9ed3d20b 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -125,7 +125,7 @@ class Product extends Model implements Buyable if ($calculate) { //weight converter $weighted_price = $this->attributes['price'] * ($this->weight * WeightUnit::convert()[$this->weight_unit]); - return $this->priceHt = round($weighted_price * 100) / 100; + return $this->priceHt = round($weighted_price * 1000) / 1000; } else { //no calculations, alias of db property return $this->priceHt = $this->attributes['price']; @@ -145,7 +145,7 @@ class Product extends Model implements Buyable return $this->discountedPriceHt; } else { $discountedPriceHt = $this->priceHt - $this->discountAmount; - $roundingdiscountedPriceHt = round($discountedPriceHt * 100) / 100; + $roundingdiscountedPriceHt = round($discountedPriceHt * 1000) / 1000; return $this->discountedPriceHt = $roundingdiscountedPriceHt; } } @@ -163,7 +163,8 @@ class Product extends Model implements Buyable } else { $priceTtc = $this->priceHt * ( 1 + ( $this->tax->rate / 100)); //on travaille avec des centimes puis on redivise par 100 pour avoir des unités monetaires - $roundingPriceTtc = round($priceTtc * 100) / 100; + //on augmente la précision à 3 digits, l'affichage formate les prix sur 2 décimales + $roundingPriceTtc = round($priceTtc * 1000) / 1000; return $this->priceTtc = $roundingPriceTtc; } } @@ -181,7 +182,8 @@ class Product extends Model implements Buyable } else { $discountedPriceTtc = $this->discountedPriceHt * ( 1 + ( $this->tax->rate / 100)); //on travaille avec des centimes puis on redivise par 100 pour avoir des unités monetaires - $roundingDiscountedPriceTTC = round($discountedPriceTtc * 100) / 100; + //on augmente la précision à 3 digits, l'affichage formate les prix sur 2 décimales + $roundingDiscountedPriceTTC = round($discountedPriceTtc * 1000) / 1000; return $this->discountedPriceTtc = $roundingDiscountedPriceTTC; } } @@ -207,9 +209,9 @@ class Product extends Model implements Buyable if ($promo_type == 1) { $discountAmount = $applicablePromotion->discount_value; } else { - //TODO : rounding au centime cf getDiscountedPriceTtcAttribute? + //on augmente la précision à 3 digits, l'affichage formate les prix sur 2 décimales $discountAmount = $this->priceHt * ($applicablePromotion->discount_value / 100); - $discountAmount = round($discountAmount * 100) / 100; + $discountAmount = round($discountAmount * 1000) / 1000; } } else { $discountAmount = 0; diff --git a/database/migrations/2021_11_18_144311_alter_price_to_products_table.php b/database/migrations/2021_11_18_144311_alter_price_to_products_table.php new file mode 100644 index 00000000..62b5b047 --- /dev/null +++ b/database/migrations/2021_11_18_144311_alter_price_to_products_table.php @@ -0,0 +1,34 @@ +decimal('price', 8, 3)->change(); + $table->decimal('price_buy', 8, 3)->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('products', function (Blueprint $table) { + $table->decimal('price', 8, 2)->change(); + $table->decimal('price_buy', 8, 2)->change(); + }); + } +} diff --git a/resources/views/bo/products/create.blade.php b/resources/views/bo/products/create.blade.php index cd1a60e6..c193160c 100644 --- a/resources/views/bo/products/create.blade.php +++ b/resources/views/bo/products/create.blade.php @@ -37,7 +37,7 @@
- +