Der Speicher-Button heißt jetzt „Produktion abschließen"; daneben gibt es „Zwischenspeichern (Entwurf)". Ein Entwurf sichert den Stand ohne Pflichtfeld- und ohne Bestandsprüfung und bucht KEINEN Bestand (Roh-/Produkt-/Verpackung). Erst „abschließen" prüft vollständig und bucht. - Migration: productions.status (default 'completed'; Bestand ist bereits gebucht). - Production-Model: STATUS_DRAFT/COMPLETED, isDraft(), scopeBooked(). - InventoryService: Entwürfe fallen aus allen Verbrauchs-/Bestandsjoins heraus (status != draft an den 4 productions-Joins). - ProductionService store()/updateProduction() bekommen $draft: Entwurf überspringt Rezeptur-/Mengen-/Bestandsprüfung + Buchungen, sichert nur vollständige Chargen-Zeilen (filterCompleteLines) und die angegebenen Outputs. Ein abgeschlossene Produktion kann NICHT zurück in den Entwurf (sonst verwaisen die Buchungen) — Guard wirft ValidationException. - StoreProductionRequest: save_mode=draft => nur Kopfdaten Pflicht, Chargen/ Ergebnis optional; validatedPayload filtert unvollständige Zeilen/Outputs. - Controller: Entwurf löst Chargen tolerant auf (nicht auflösbare Chargen werden übersprungen, Entwurf ist immer speicherbar) und leitet zur Bearbeitung zurück. - Views: create/edit „abschließen" + „Zwischenspeichern"-Button (nur solange Entwurf); Entwurf-Badge in Liste + Bearbeiten-Kopf. Tests: 5 neue (kein Produktbestand, kein Rohstoffverbrauch, Abschluss bucht, Rück-Entwurf verboten, HTTP-Entwurf ohne Ergebnis ok / Abschluss erzwingt Ergebnis). Migration auf Dev-/Live-DB. Suite 336 grün. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
114 lines
2.7 KiB
PHP
114 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\User;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Production extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
/** AP-43: Entwurf — gespeichert, aber noch nicht gebucht. */
|
|
public const STATUS_DRAFT = 'draft';
|
|
|
|
/** AP-43: Abgeschlossen — Bestand gebucht (Alt-Verhalten, Default). */
|
|
public const STATUS_COMPLETED = 'completed';
|
|
|
|
protected $fillable = [
|
|
'product_id',
|
|
'location_id',
|
|
'produced_by',
|
|
'produced_at',
|
|
'quantity',
|
|
'notes',
|
|
'mhd_warning',
|
|
'status',
|
|
];
|
|
|
|
/**
|
|
* AP-43: true, solange die Produktion ein Entwurf ist (kein Bestand gebucht).
|
|
*/
|
|
public function isDraft(): bool
|
|
{
|
|
return $this->status === self::STATUS_DRAFT;
|
|
}
|
|
|
|
/**
|
|
* AP-43: Nur gebuchte (abgeschlossene) Produktionen — Entwürfe zählen nicht
|
|
* in Bestands-/Verbrauchsberechnungen.
|
|
*
|
|
* @param Builder<Production> $query
|
|
* @return Builder<Production>
|
|
*/
|
|
public function scopeBooked($query)
|
|
{
|
|
return $query->where('status', '!=', self::STATUS_DRAFT);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'produced_at' => 'date',
|
|
'mhd_warning' => 'boolean',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Product, $this>
|
|
*/
|
|
public function product(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Product::class);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Location, $this>
|
|
*/
|
|
public function location(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Location::class);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<User, $this>
|
|
*/
|
|
public function producedByUser(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'produced_by');
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<ProductionIngredient, $this>
|
|
*/
|
|
public function productionIngredients(): HasMany
|
|
{
|
|
return $this->hasMany(ProductionIngredient::class);
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<ProductionPackaging, $this>
|
|
*/
|
|
public function productionPackagings(): HasMany
|
|
{
|
|
return $this->hasMany(ProductionPackaging::class);
|
|
}
|
|
|
|
/**
|
|
* AP-28: Produktionsergebnis-Zeilen — buchen den Produktbestand;
|
|
* `quantity` an der Produktion ist nur noch die Planung.
|
|
*
|
|
* @return HasMany<ProductionOutput, $this>
|
|
*/
|
|
public function outputs(): HasMany
|
|
{
|
|
return $this->hasMany(ProductionOutput::class)->orderBy('pos')->orderBy('id');
|
|
}
|
|
}
|