'date', 'expiry_date' => 'date', 'output_quantity' => 'decimal:2', ]; public function getActivitylogOptions(): LogOptions { return LogOptions::defaults() ->logOnly([ 'code', 'status', 'output_quantity', 'output_batch_number', 'production_date', 'remark' ]) ->logOnlyDirty() ->dontSubmitEmptyLogs() ->setDescriptionForEvent(fn(string $eventName) => "生產工單已{$this->getEventDescription($eventName)}"); } protected function getEventDescription($eventName): string { return match ($eventName) { 'created' => '建立', 'updated' => '更新', 'deleted' => '刪除', default => $eventName, }; } public static function generateCode() { $prefix = 'PO' . now()->format('Ymd'); $lastOrder = self::where('code', 'like', $prefix . '%')->latest()->first(); if ($lastOrder) { $lastSequence = intval(substr($lastOrder->code, -3)); $sequence = str_pad($lastSequence + 1, 3, '0', STR_PAD_LEFT); } else { $sequence = '001'; } return $prefix . $sequence; } /** * @deprecated 使用 InventoryServiceInterface 獲取產品資訊 */ public function product() { return null; } /** * @deprecated 使用 InventoryServiceInterface 獲取倉庫資訊 */ public function warehouse() { return null; } /** * @deprecated 使用 CoreServiceInterface 獲取使用者資訊 */ public function user() { return null; } public function items(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(ProductionOrderItem::class); } }