feat(ticketing): resolve validity in tenant timezone

This commit is contained in:
2026-09-21 15:19:09 -03:00
parent f4de2ff5b2
commit 3e3b3bfac0
17 changed files with 354 additions and 45 deletions

View File

@@ -0,0 +1,41 @@
<?php
use Carbon\CarbonImmutable;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('tenants', function (Blueprint $table): void {
$table->string('timezone')->default('America/Argentina/Buenos_Aires');
});
// Correct legacy event windows once, using their original local date and hours.
// Subsequent tenant timezone changes do not rewrite stored UTC instants.
DB::table('event_dates')->orderBy('id')->chunkById(200, function ($dates): void {
foreach ($dates as $date) {
$timezone = DB::table('tenants')->where('codigo', $date->tenant_code)->value('timezone');
$start = CarbonImmutable::parse(substr($date->date, 0, 10).' '.$date->time_start, $timezone);
$end = CarbonImmutable::parse(substr($date->date, 0, 10).' '.$date->time_end, $timezone);
if ($end->lessThanOrEqualTo($start)) {
$end = $end->addDay();
}
DB::table('validity_times')->where('id', $date->validity_time_id)->update([
'fixed_starts_at' => $start->utc()->format('Y-m-d H:i:s'),
'fixed_expires_at' => $end->utc()->format('Y-m-d H:i:s'),
]);
}
});
}
public function down(): void
{
Schema::table('tenants', function (Blueprint $table): void {
$table->dropColumn('timezone');
});
}
};