Add piece_weight calibration: enter Stück + Gramm per delivery, average auto-calculated
Deploy / deploy (push) Successful in 17s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Malek TellissiandClaude Sonnet 4.6 committed 2026-09-13 01:26:17 +02:00
1 parent 38bcf60778
commit d87383672c
5 files changed
+73 -1

No files matched your search

+14 -1
View File
@@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model;
class Spice extends Model
{
protected $fillable = ['name', 'quantity', 'unit'];
protected $fillable = ['name', 'quantity', 'unit', 'piece_weight'];
public function recipes()
{
@@ -24,4 +24,17 @@ class Spice extends Model
{
$this->update(['quantity' => $this->stockMovements()->sum('amount')]);
}
public function recalculatePieceWeight(): void
{
$result = SpiceSupplier::where('spice_id', $this->id)
->whereNotNull('weight_g')
->where('weight_g', '>', 0)
->selectRaw('SUM(weight_g) as total_grams, SUM(amount) as total_pieces')
->first();
if ($result && $result->total_pieces > 0) {
$this->update(['piece_weight' => round($result->total_grams / $result->total_pieces, 3)]);
}
}
}