fix: store opened_at and closed_at as DATETIME (not DATE)

DATE columns lose time information, causing timeline to show 00:00 for
car reception and WO closure. Migrated both columns to DATETIME and
updated: model casts (date → datetime), form pickers (DatePicker →
DateTimePicker with seconds:false), default to now() instead of today(),
and cleaned up defensive Carbon::parse() in getTimeline().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-09-11 04:52:03 +00:00
parent ce9f082612
commit 5a3275c2cf
4 changed files with 29 additions and 6 deletions
@@ -122,7 +122,7 @@ class WorkOrderDashboard extends Page
'icon' => '📋', 'icon' => '📋',
]; ];
} }
if ($wo->opened_at && $wo->opened_at->ne($wo->created_at)) { if ($wo->opened_at && $wo->opened_at->format('Y-m-d H:i') !== $wo->created_at?->format('Y-m-d H:i')) {
$events[] = [ $events[] = [
'at' => $wo->opened_at, 'at' => $wo->opened_at,
'kind' => 'opened', 'kind' => 'opened',
@@ -142,7 +142,7 @@ class WorkOrderDashboard extends Page
} }
if ($wo->closed_at) { if ($wo->closed_at) {
$events[] = [ $events[] = [
'at' => $wo->closed_at instanceof \Carbon\Carbon ? $wo->closed_at : \Carbon\Carbon::parse($wo->closed_at), 'at' => $wo->closed_at,
'kind' => 'closed', 'kind' => 'closed',
'label' => __('Fișă închisă'), 'label' => __('Fișă închisă'),
'meta' => null, 'meta' => null,
@@ -80,7 +80,7 @@ class WorkOrderResource extends Resource
->columns(4) ->columns(4)
->schema([ ->schema([
Forms\Components\TextInput::make('number')->label(__('Nr.'))->disabled()->dehydrated(false)->placeholder('auto'), Forms\Components\TextInput::make('number')->label(__('Nr.'))->disabled()->dehydrated(false)->placeholder('auto'),
Forms\Components\DatePicker::make('opened_at')->label(__('Deschis'))->default(today())->required(), Forms\Components\DateTimePicker::make('opened_at')->label(__('Deschis'))->default(now())->seconds(false)->required(),
Forms\Components\Select::make('status')->options(\App\Support\I18n::opts(WorkOrder::STATUSES))->default('new')->required(), Forms\Components\Select::make('status')->options(\App\Support\I18n::opts(WorkOrder::STATUSES))->default('new')->required(),
Forms\Components\Select::make('urgency')->label(__('Urgență')) Forms\Components\Select::make('urgency')->label(__('Urgență'))
->options(\App\Support\I18n::opts(\App\Models\Tenant\PricingCoefficient::URGENCY))->default('normal')->required(), ->options(\App\Support\I18n::opts(\App\Models\Tenant\PricingCoefficient::URGENCY))->default('normal')->required(),
@@ -192,7 +192,7 @@ class WorkOrderResource extends Resource
'style' => 'font-weight:600;color:' . ($record && $record->paidAmount() >= (float)$record->total ? '#16a34a' : '#dc2626'), 'style' => 'font-weight:600;color:' . ($record && $record->paidAmount() >= (float)$record->total ? '#16a34a' : '#dc2626'),
]), ]),
Forms\Components\Toggle::make('approved')->label(__('Aprobat de client')), Forms\Components\Toggle::make('approved')->label(__('Aprobat de client')),
Forms\Components\DatePicker::make('closed_at')->label(__('Închis')), Forms\Components\DateTimePicker::make('closed_at')->label(__('Închis'))->seconds(false),
]), ]),
]); ]);
} }
+2 -2
View File
@@ -45,8 +45,8 @@ class WorkOrder extends Model implements HasMedia
]; ];
protected $casts = [ protected $casts = [
'opened_at' => 'date', 'opened_at' => 'datetime',
'closed_at' => 'date', 'closed_at' => 'datetime',
'approved_at' => 'datetime', 'approved_at' => 'datetime',
'eta_at' => 'datetime', 'eta_at' => 'datetime',
'eta_promised' => 'datetime', 'eta_promised' => 'datetime',
@@ -0,0 +1,23 @@
<?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::table('work_orders', function (Blueprint $table) {
$table->dateTime('opened_at')->nullable()->change();
$table->dateTime('closed_at')->nullable()->change();
});
}
public function down(): void
{
Schema::table('work_orders', function (Blueprint $table) {
$table->date('opened_at')->nullable()->change();
$table->date('closed_at')->nullable()->change();
});
}
};