59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Maintenance\Services;
|
|
|
|
use App\Business;
|
|
use App\User;
|
|
use App\Modules\Maintenance\Models\ActivityLog;
|
|
use App\Modules\Maintenance\Models\HistoryEntry;
|
|
|
|
class MaintenanceActivityService
|
|
{
|
|
public static function log(
|
|
Business $business,
|
|
string $action,
|
|
string $entityType,
|
|
?int $entityId,
|
|
?string $description = null,
|
|
?User $user = null,
|
|
?array $properties = null
|
|
): ActivityLog {
|
|
return ActivityLog::create([
|
|
'business_id' => $business->id,
|
|
'user_id' => $user?->id,
|
|
'action' => $action,
|
|
'entity_type' => $entityType,
|
|
'entity_id' => $entityId,
|
|
'description' => $description,
|
|
'properties' => $properties,
|
|
]);
|
|
}
|
|
|
|
public static function logEquipmentHistory(
|
|
Business $business,
|
|
int $equipmentId,
|
|
string $entryType,
|
|
string $title,
|
|
?string $description = null,
|
|
?User $user = null,
|
|
int $cost = 0,
|
|
?string $relatedType = null,
|
|
?int $relatedId = null,
|
|
?array $metadata = null
|
|
): HistoryEntry {
|
|
return HistoryEntry::create([
|
|
'business_id' => $business->id,
|
|
'equipment_id' => $equipmentId,
|
|
'entry_type' => $entryType,
|
|
'title' => $title,
|
|
'description' => $description,
|
|
'cost' => $cost,
|
|
'performed_by' => $user?->id,
|
|
'performed_at' => now(),
|
|
'related_type' => $relatedType,
|
|
'related_id' => $relatedId,
|
|
'metadata' => $metadata,
|
|
]);
|
|
}
|
|
}
|