Anforderung 15.07.2026: Nahezu alle WaWi-Einträge sind jetzt löschbar (Soft-Delete, deleted_at), mit Abhängigkeitsprüfung und Bestätigungs- warnung vor jeder Löschung. - Migration: deleted_at auf 14 WaWi-Tabellen (Stammdaten, ingredients, stock_entries, stock_disposals, productions); SoftDeletes-Trait in den Models (suppliers/packaging_items hatten es bereits). - Neuer App\Services\DeletionGuard: zentrale Abhängigkeitsprüfung je Entität — referenzierte Einträge sind nicht löschbar, Fehlermeldung nennt die Verwendungen (behebt auch Audit M-4: kein 500er/stiller Cascade-Verlust mehr beim Löschen verwendeter Stammdaten). - SettingCrudController::destroy() prüft Blocker; Supplier-, PackagingItem-, Ingredient-destroy ebenso (Ingredient: vollständige Prüfung inkl. Produktion/Ausschuss, Route GET→DELETE, Audit M-6). - Wareneingänge: auch gebuchte Eingänge löschbar, sofern kein Produktions-Verbrauch/Ausschuss darauf gebucht ist. - Ausschuss: löschbar (Menge steht dem Bestand wieder zur Verfügung). - Produktionen: löschbar (admin >= 7); Produktbestand wird per Gegenbuchung zurückgeführt (reverseProductionStock, append-only, withTrashed), Rohstoffverbrauch zählt nicht mehr (Bestandsqueries schließen gelöschte Produktionen aus). - lastNetPricePerSupplier: DB::query statt Model-Query (Global Scope auf Sub-Select-Alias). - Debug-Log-Reste im PackagingItemController entfernt (Audit N-16). - Views: Lösch-Buttons mit deutschen Bestätigungswarnungen (Ausschuss, Produktionen, gebuchte Wareneingänge, INCI als DELETE-Formular). Tests: neuer InventoryDeletionTest (10 Tests), StorageSettingsTest an neue Löschregel angepasst. Volle Suite: 214 grün, 783 Assertions. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
86 lines
1.9 KiB
PHP
86 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\User;
|
|
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;
|
|
|
|
protected $fillable = [
|
|
'product_id',
|
|
'location_id',
|
|
'produced_by',
|
|
'produced_at',
|
|
'quantity',
|
|
'notes',
|
|
'mhd_warning',
|
|
];
|
|
|
|
/**
|
|
* @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');
|
|
}
|
|
}
|