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:
@@ -122,7 +122,7 @@ class WorkOrderDashboard extends Page
|
||||
'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[] = [
|
||||
'at' => $wo->opened_at,
|
||||
'kind' => 'opened',
|
||||
@@ -142,7 +142,7 @@ class WorkOrderDashboard extends Page
|
||||
}
|
||||
if ($wo->closed_at) {
|
||||
$events[] = [
|
||||
'at' => $wo->closed_at instanceof \Carbon\Carbon ? $wo->closed_at : \Carbon\Carbon::parse($wo->closed_at),
|
||||
'at' => $wo->closed_at,
|
||||
'kind' => 'closed',
|
||||
'label' => __('Fișă închisă'),
|
||||
'meta' => null,
|
||||
|
||||
@@ -80,7 +80,7 @@ class WorkOrderResource extends Resource
|
||||
->columns(4)
|
||||
->schema([
|
||||
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('urgency')->label(__('Urgență'))
|
||||
->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'),
|
||||
]),
|
||||
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),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -45,8 +45,8 @@ class WorkOrder extends Model implements HasMedia
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'opened_at' => 'date',
|
||||
'closed_at' => 'date',
|
||||
'opened_at' => 'datetime',
|
||||
'closed_at' => 'datetime',
|
||||
'approved_at' => 'datetime',
|
||||
'eta_at' => '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();
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user