44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Database\Factories\LocationFactory;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Location extends Model
|
|
{
|
|
/** @use HasFactory<LocationFactory> */
|
|
use HasFactory;
|
|
|
|
use SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'active',
|
|
];
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'active' => 'boolean',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* AP-50 / Prüfung 08.09.2026 F-17: Standard-Lagerort für alle Erfassungsmasken
|
|
* (Einkauf, Produktion, Ausschuss) — Köln, sofern aktiv; sonst der erste aktive
|
|
* Standort. Inaktive Standorte stehen nicht zur Auswahl und werden nicht vorbelegt.
|
|
*/
|
|
public static function defaultId(): ?int
|
|
{
|
|
$id = static::query()->where('active', true)->where('name', 'like', '%öln%')->orderBy('id')->value('id')
|
|
?? static::query()->where('active', true)->orderBy('name')->value('id');
|
|
|
|
return $id !== null ? (int) $id : null;
|
|
}
|
|
}
|