diff --git a/app/Console/Commands/CreateAdmin.php b/app/Console/Commands/CreateAdmin.php index 592dbb7..d62c8fc 100644 --- a/app/Console/Commands/CreateAdmin.php +++ b/app/Console/Commands/CreateAdmin.php @@ -39,9 +39,9 @@ class CreateAdmin extends Command */ public function handle() { - $firstname = $this->ask('What is the firstname?','Informatique'); - $lastname = $this->ask('What is the lastname?','Internet'); - $email = $this->ask('What is the email?', 'informatique.internet@ldc.fr'); + $firstname = $this->ask('What is the firstname?','Equipe'); + $lastname = $this->ask('What is the lastname?','Web'); + $email = $this->ask('What is the email?', 'equipe.web@ldc.fr'); $pwd = $this->secret('What is the password?'); $user = new User(); diff --git a/app/Enums/WeightUnit.php b/app/Enums/WeightUnit.php new file mode 100644 index 0000000..281af08 --- /dev/null +++ b/app/Enums/WeightUnit.php @@ -0,0 +1,45 @@ + 'G', + 'kg' => 'KG', + 'ton' => 'T', + ]; + } + + protected static function labels(): array + { + return [ + 'g' => __('Gramme'), + 'kg' => __('Kg'), + 'ton' => __('Tonne'), + ]; + } + + public static function convert(): array + { + return [ + 'G' => 0.001, + 'KG' => 1, + 'T' => 1000, + ]; + } + + public function __toString(): string + { + return (string)$this->label; + } +} diff --git a/app/Models/Product.php b/app/Models/Product.php index 9d838b5..8b7624b 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -2,6 +2,9 @@ namespace App\Models; +use App\Enums\InvoicingUnit; +use App\Enums\SellUnit; +use App\Enums\WeightUnit; use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -107,8 +110,26 @@ class Product extends Model implements Buyable if(isset($this->priceHt)) { return $this->priceHt; } else { - //no calculations, alias of db property - return $this->priceHt = $this->attributes['price']; + //tenir compte de l'unité de facturation et de l'unité de vente (qui doit être stricte) + //si facturation KG et vente piece + // prendre le poids, convertir en KG => pre-requis l'unité de poids doit être un enum + // multiplier le $this->attributes['price'] par les KG + //sinon + // value => value + if (config('bosettings.sell_unit_management') == "strict") { + $calculate = ($this->invoicing_unit == InvoicingUnit::kgm()->value && $this->sell_unit == SellUnit::pce()->value); + } else { + $calculate = false; + } + + if ($calculate) { + //weight converter + $weighted_price = $this->attributes['price'] * ($this->weight * WeightUnit::convert()[$this->weight_unit]); + return $this->priceHt = round($weighted_price * 100) / 100; + } else { + //no calculations, alias of db property + return $this->priceHt = $this->attributes['price']; + } } } @@ -226,10 +247,10 @@ class Product extends Model implements Buyable // //Buyable interface - // public function getBuyablePrice($options = null) - // { - // return $this->discountedPriceHt; - // } + public function getBuyablePrice($options = null) + { + return $this->priceHt; + } //Relations public function range() diff --git a/config/app.php b/config/app.php index 0f34bc0..794d070 100644 --- a/config/app.php +++ b/config/app.php @@ -245,6 +245,7 @@ return [ 'SellUnit' => \App\Enums\SellUnit::class, 'OrderUnit' => \App\Enums\OrderUnit::class, 'InvoicingUnit' => \App\Enums\InvoicingUnit::class, + 'WeightUnit' => \App\Enums\WeightUnit::class, ], ]; diff --git a/resources/views/bo/products/edit.blade.php b/resources/views/bo/products/edit.blade.php index 70bab59..0b6188d 100644 --- a/resources/views/bo/products/edit.blade.php +++ b/resources/views/bo/products/edit.blade.php @@ -166,8 +166,18 @@