feat(event): add date reschedule history
This commit is contained in:
@@ -86,6 +86,18 @@ class EventDate extends Model
|
|||||||
return $this->hasMany(self::class, 'rescheduled_to_event_date_id');
|
return $this->hasMany(self::class, 'rescheduled_to_event_date_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return HasMany<EventDateReschedule, $this> */
|
||||||
|
public function rescheduleHistory(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(EventDateReschedule::class, 'source_event_date_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return HasMany<EventDateReschedule, $this> */
|
||||||
|
public function destinationRescheduleHistory(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(EventDateReschedule::class, 'destination_event_date_id');
|
||||||
|
}
|
||||||
|
|
||||||
/** @return HasMany<Variant, $this> */
|
/** @return HasMany<Variant, $this> */
|
||||||
public function variants(): HasMany
|
public function variants(): HasMany
|
||||||
{
|
{
|
||||||
|
|||||||
58
app/Domains/Event/Models/EventDateReschedule.php
Normal file
58
app/Domains/Event/Models/EventDateReschedule.php
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Event\Models;
|
||||||
|
|
||||||
|
use App\Domains\Auth\Models\User;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
#[Fillable([
|
||||||
|
'tenant_code',
|
||||||
|
'source_event_date_id',
|
||||||
|
'destination_event_date_id',
|
||||||
|
'created_by_user_id',
|
||||||
|
'previous_date',
|
||||||
|
'new_date',
|
||||||
|
])]
|
||||||
|
class EventDateReschedule extends Model
|
||||||
|
{
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'source_event_date_id' => 'integer',
|
||||||
|
'destination_event_date_id' => 'integer',
|
||||||
|
'created_by_user_id' => 'integer',
|
||||||
|
'previous_date' => 'date:Y-m-d',
|
||||||
|
'new_date' => 'date:Y-m-d',
|
||||||
|
'created_at' => 'datetime',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return BelongsTo<Tenant, $this> */
|
||||||
|
public function tenant(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Tenant::class, 'tenant_code', 'codigo');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return BelongsTo<EventDate, $this> */
|
||||||
|
public function sourceEventDate(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(EventDate::class, 'source_event_date_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return BelongsTo<EventDate, $this> */
|
||||||
|
public function destinationEventDate(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(EventDate::class, 'destination_event_date_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return BelongsTo<User, $this> */
|
||||||
|
public function createdBy(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class, 'created_by_user_id')->withTrashed();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('event_date_reschedules', function (Blueprint $table): void {
|
||||||
|
$table->id();
|
||||||
|
$table->string('tenant_code');
|
||||||
|
$table->foreignId('source_event_date_id')->nullable()->constrained('event_dates')->nullOnDelete();
|
||||||
|
$table->foreignId('destination_event_date_id')->nullable()->constrained('event_dates')->nullOnDelete();
|
||||||
|
$table->foreignId('created_by_user_id')->nullable()->constrained('users')->nullOnDelete();
|
||||||
|
$table->date('previous_date');
|
||||||
|
$table->date('new_date');
|
||||||
|
$table->timestamp('created_at')->useCurrent();
|
||||||
|
|
||||||
|
$table->foreign('tenant_code')
|
||||||
|
->references('codigo')
|
||||||
|
->on('tenants')
|
||||||
|
->cascadeOnUpdate()
|
||||||
|
->cascadeOnDelete();
|
||||||
|
$table->index(['tenant_code', 'created_at']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('event_date_reschedules');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user