'decimal:3', 'quantite_recue' => 'decimal:3', 'prix_unitaire_ht' => 'decimal:2', 'taux_tva' => 'decimal:2', 'montant_ht' => 'decimal:2', 'montant_ttc' => 'decimal:2', ]; protected static function booted(): void { static::saving(function (LigneCommande $ligne) { if ($ligne->prix_unitaire_ht !== null && $ligne->quantite !== null) { $ligne->montant_ht = round((float) $ligne->quantite * (float) $ligne->prix_unitaire_ht, 2); $ligne->montant_ttc = round((float) $ligne->montant_ht * (1 + (float) $ligne->taux_tva / 100), 2); } }); static::saved(function (LigneCommande $ligne) { $ligne->commande?->recalculerMontants(); }); static::deleted(function (LigneCommande $ligne) { $ligne->commande?->recalculerMontants(); }); } public function commande(): BelongsTo { return $this->belongsTo(Commande::class); } public function article(): BelongsTo { return $this->belongsTo(Article::class); } public function categorie(): BelongsTo { return $this->belongsTo(Categorie::class); } }