LogOptions on Artist, ArtistEngagement, Stage, Performance, Genre now
list the specific attributes the audit log captures (per §8 last
paragraph) instead of logFillable. Each model gets a distinct
log_name (artist / artist_engagement / stage / performance / genre)
so the activity-log filter can scope queries by domain.
tapActivity() on every model adds organisation_id (and event_id where
relevant) to the activity entry's properties. The audit-log filter in
the SPA can then query
`->where('properties->event_id', $event->id)` without joining through
multiple subject types.
Performance gets dontLogIfAttributesChangedOnly(['updated_at',
'version']) so the bookkeeping touch from PerformanceObserver doesn't
generate noise when nothing user-meaningful changed.
Custom activity events emitted by services for the cases where the
auto-log can't infer intent:
performance.moved — LaneCascadeService::move writes a single
parent entry with cascade_count and
cascaded_ids[] after the cascade-bump
commits. Per-row updates still flow
through the model trait so the audit log
shows both the summary and the diffs.
stage.day_added /
stage.day_removed — StageDayService::replaceDays writes one
entry per added/removed event_id, performed
on the parent Stage so the log groups by
stage rather than by pivot row.
stage.reordered — StageService::reorder writes one entry on
the parent Event with the full new
stage_ids[] order.
artist_engagement.
status_changed /
cancelled — ArtistEngagementService::transitionStatus
emits one of these depending on the target
status; pairs with the auto-logged `updated`
row.
The remaining artist_engagement.option_expired event lands in Step 10
when the DemoteExpiredOptions command writes a system-causer entry.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
142 lines
4.0 KiB
PHP
142 lines
4.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\Artist\ArtistEngagementStatus;
|
|
use App\Enums\Artist\BumaHandledBy;
|
|
use App\Enums\Artist\FeeType;
|
|
use App\Enums\Artist\PaymentStatus;
|
|
use App\Models\Scopes\OrganisationScope;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Spatie\Activitylog\Models\Concerns\LogsActivity;
|
|
use Spatie\Activitylog\Support\LogOptions;
|
|
|
|
final class ArtistEngagement extends Model
|
|
{
|
|
use HasFactory;
|
|
use HasUlids;
|
|
use LogsActivity;
|
|
use SoftDeletes;
|
|
|
|
protected static function booted(): void
|
|
{
|
|
self::addGlobalScope(new OrganisationScope);
|
|
}
|
|
|
|
protected $fillable = [
|
|
'organisation_id',
|
|
'artist_id',
|
|
'event_id',
|
|
'booking_status',
|
|
'project_leader_id',
|
|
'fee_amount',
|
|
'fee_currency',
|
|
'fee_type',
|
|
'buma_applicable',
|
|
'buma_percentage',
|
|
'buma_handled_by',
|
|
'vat_applicable',
|
|
'vat_percentage',
|
|
'deal_breakdown',
|
|
'deposit_percentage',
|
|
'deposit_due_date',
|
|
'balance_due_date',
|
|
'payment_status',
|
|
'crew_count',
|
|
'guests_count',
|
|
'requested_at',
|
|
'option_expires_at',
|
|
'advance_open_from',
|
|
'advance_open_to',
|
|
'portal_token',
|
|
'advancing_completed_count',
|
|
'advancing_total_count',
|
|
'notes',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'booking_status' => ArtistEngagementStatus::class,
|
|
'fee_type' => FeeType::class,
|
|
'buma_handled_by' => BumaHandledBy::class,
|
|
'payment_status' => PaymentStatus::class,
|
|
'buma_applicable' => 'boolean',
|
|
'vat_applicable' => 'boolean',
|
|
'deal_breakdown' => 'array',
|
|
'deposit_due_date' => 'date',
|
|
'balance_due_date' => 'date',
|
|
'crew_count' => 'integer',
|
|
'guests_count' => 'integer',
|
|
'requested_at' => 'datetime',
|
|
'option_expires_at' => 'datetime',
|
|
'advance_open_from' => 'datetime',
|
|
'advance_open_to' => 'datetime',
|
|
'advancing_completed_count' => 'integer',
|
|
'advancing_total_count' => 'integer',
|
|
];
|
|
}
|
|
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logOnly([
|
|
'booking_status',
|
|
'fee_amount', 'fee_currency', 'fee_type',
|
|
'buma_applicable', 'buma_percentage', 'buma_handled_by',
|
|
'vat_applicable', 'vat_percentage',
|
|
'project_leader_id',
|
|
'option_expires_at',
|
|
'payment_status',
|
|
])
|
|
->logOnlyDirty()
|
|
->dontLogIfAttributesChangedOnly(['updated_at'])
|
|
->useLogName('artist_engagement');
|
|
}
|
|
|
|
public function tapActivity(Activity $activity, string $eventName): void
|
|
{
|
|
$properties = $activity->properties?->toArray() ?? [];
|
|
$properties['organisation_id'] = $this->organisation_id;
|
|
$properties['event_id'] = $this->event_id;
|
|
$activity->properties = collect($properties);
|
|
}
|
|
|
|
public function organisation(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Organisation::class);
|
|
}
|
|
|
|
public function artist(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Artist::class);
|
|
}
|
|
|
|
public function event(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Event::class);
|
|
}
|
|
|
|
public function projectLeader(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'project_leader_id');
|
|
}
|
|
|
|
public function performances(): HasMany
|
|
{
|
|
return $this->hasMany(Performance::class, 'engagement_id');
|
|
}
|
|
|
|
public function advanceSections(): HasMany
|
|
{
|
|
return $this->hasMany(AdvanceSection::class, 'engagement_id');
|
|
}
|
|
}
|