Kundennachtrag 09.09.2026: Ist-Mengen je Charge in der Produktion sollen auf das Milligramm eingegeben werden können (z. B. 0,125 g). Bisher rundeten Datenbank (decimal 12,2), Bestandslogik, Anzeige und Toleranzsockel auf zwei Stellen; „0,125" wurde still zu 0,13, „0.125" nach der Punkt-Regel zu 125 g. - Migration 2026_09_09_100000: production_ingredients.quantity_used, stock_entries.ordered_quantity/received_quantity, stock_disposals.quantity → decimal(12,3); Casts decimal:3. Auf der Dev-DB (Live-Kopie) ausgeführt, 53/78/7 Zeilen unverändert. - InventoryService::QUANTITY_DECIMALS = 3; roundWawiQuantity() ersetzt alle round(…, 2) in InventoryService, ProductionService, StockDisposalController/-Request, StockEntryRepository/-Controller, RawMaterialStockController. - formatWawiQuantity($v, $min = 2): bis drei Stellen, mindestens zwei — Produktionsdetail, Einkauf Liste/Detail/Formular, Ausschuss-Liste, Chargen-Rest im Rohstoff-Detail. - Eingaberegel (reFormatWawiNumber, JS parseGerman/parseNumber): zusätzlich „0.xxx" als Dezimalzahl; „1.500" bleibt 1500. Produktions-JS: fmt() bis drei Stellen, fmtInput() schreibt gespeicherte Zahlen deutsch ins Feld (1,125 statt 1.125 = 1125). - Soll-Ist-Toleranz: Sockel 0,05 → 0,005 g; Ausschuss min 0,001. - Doku: Hinweise (Neu/geändert), Leitfaden Version 3.1 mit Abschnitt 26, Plan V7 AP-53, README (Deploy-Checkliste, Suite 378). Tests: QuantityPrecisionTest (6) — Parsing, Anzeige, Produktion 0,125 g exakt + Rest 9,875 g, Entwurf 1,125 wiederöffnen, Toleranz Kleinmengen, Ausschuss 0,005 g. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
152 lines
3.7 KiB
PHP
152 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\User;
|
|
use Database\Factories\StockEntryFactory;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class StockEntry extends Model
|
|
{
|
|
/** @use HasFactory<StockEntryFactory> */
|
|
use HasFactory;
|
|
|
|
use SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'entry_type',
|
|
'ingredient_id',
|
|
'packaging_item_id',
|
|
'supplier_id',
|
|
'location_id',
|
|
'unit',
|
|
'purchase_unit',
|
|
'density_used',
|
|
'ordered_by',
|
|
'ordered_at',
|
|
'ordered_quantity',
|
|
'price_per_kg',
|
|
'price_per_kg_gross',
|
|
'price_total',
|
|
'tax_rate_id',
|
|
'tax_rate_percent',
|
|
'received_by',
|
|
'received_at',
|
|
'received_quantity',
|
|
'batch_number',
|
|
'best_before',
|
|
'quality_id',
|
|
'status',
|
|
];
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'ordered_at' => 'date',
|
|
'received_at' => 'date',
|
|
'best_before' => 'date',
|
|
'ordered_quantity' => 'decimal:3',
|
|
'received_quantity' => 'decimal:3',
|
|
'density_used' => 'decimal:4',
|
|
'price_per_kg' => 'decimal:4',
|
|
'price_per_kg_gross' => 'decimal:4',
|
|
'price_total' => 'decimal:4',
|
|
'tax_rate_percent' => 'decimal:2',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Ingredient, $this>
|
|
*/
|
|
public function ingredient(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Ingredient::class);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<PackagingItem, $this>
|
|
*/
|
|
public function packagingItem(): BelongsTo
|
|
{
|
|
return $this->belongsTo(PackagingItem::class);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Supplier, $this>
|
|
*/
|
|
public function supplier(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Supplier::class);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Location, $this>
|
|
*/
|
|
public function location(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Location::class);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<TaxRate, $this>
|
|
*/
|
|
public function taxRate(): BelongsTo
|
|
{
|
|
return $this->belongsTo(TaxRate::class);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<MaterialQuality, $this>
|
|
*/
|
|
public function quality(): BelongsTo
|
|
{
|
|
return $this->belongsTo(MaterialQuality::class, 'quality_id');
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<User, $this>
|
|
*/
|
|
public function orderedByUser(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'ordered_by');
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<User, $this>
|
|
*/
|
|
public function receivedByUser(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'received_by');
|
|
}
|
|
|
|
public function isPending(): bool
|
|
{
|
|
return $this->status === 'pending';
|
|
}
|
|
|
|
/**
|
|
* AP-27: Gruppierungsschlüssel für die Chargen-Zusammenführung.
|
|
* Einträge mit Chargennummer werden je Charge zusammengefasst,
|
|
* Einträge ohne Chargennummer bleiben einzeln.
|
|
* Audit N-1 (Kundenentscheid 15.07.2026): Chargennummern kommen von
|
|
* extern und können kollidieren — der Lieferant gehört zum Schlüssel,
|
|
* damit gleiche Lot-Nummern verschiedener Lieferanten getrennt bleiben.
|
|
*/
|
|
public function batchGroupKey(): string
|
|
{
|
|
$batch = trim((string) $this->batch_number);
|
|
|
|
return $batch !== '' ? 'b:'.((int) $this->supplier_id).':'.$batch : 'e:'.$this->id;
|
|
}
|
|
|
|
public function isReceived(): bool
|
|
{
|
|
return $this->status === 'received';
|
|
}
|
|
}
|