2024-07-31 15:04:33 +00:00
|
|
|
<?php
|
2024-07-31 16:45:14 +00:00
|
|
|
|
2024-07-31 15:04:33 +00:00
|
|
|
namespace App\Livewire\MaintenanceHistory;
|
|
|
|
|
|
|
|
use App\Models\MaintenanceHistory;
|
|
|
|
use SteelAnts\DataTable\Livewire\DataTableComponent;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
|
|
|
|
class DataTable extends DataTableComponent
|
|
|
|
{
|
2024-08-08 08:33:21 +00:00
|
|
|
public string $type = "planned";
|
|
|
|
|
2024-07-31 15:04:33 +00:00
|
|
|
public $listeners = [
|
|
|
|
'maintenanceHistoryAdded' => '$refresh',
|
|
|
|
'closeModal' => '$refresh',
|
|
|
|
];
|
|
|
|
|
|
|
|
public function query(): Builder
|
|
|
|
{
|
2024-08-08 08:33:21 +00:00
|
|
|
$query = MaintenanceHistory::query();
|
|
|
|
|
|
|
|
if ($this->type == "planned") {
|
|
|
|
$query->whereNull('finished_at');
|
|
|
|
} elseif ($this->type == "history") {
|
|
|
|
$query->whereNotNull('finished_at');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $query;
|
2024-07-31 15:04:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function headers(): array
|
|
|
|
{
|
2024-08-08 08:33:21 +00:00
|
|
|
$headers = [
|
2024-07-31 15:04:33 +00:00
|
|
|
'maintenance.name' => 'maintenance.name',
|
2024-07-31 16:45:14 +00:00
|
|
|
'start_at' => 'start_at',
|
2024-07-31 15:04:33 +00:00
|
|
|
];
|
2024-08-08 08:33:21 +00:00
|
|
|
|
|
|
|
if ($this->type == "planned") {
|
|
|
|
$headers['guestor.name'] = 'guestor';
|
|
|
|
} else {
|
|
|
|
$headers['finished_at'] = 'finished_at';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $headers;
|
2024-07-31 15:04:33 +00:00
|
|
|
}
|
|
|
|
|
2024-07-31 16:45:14 +00:00
|
|
|
public function remove($maintenancehistory_id)
|
|
|
|
{
|
2024-07-31 15:04:33 +00:00
|
|
|
MaintenanceHistory::find($maintenancehistory_id)->delete();
|
|
|
|
}
|
2024-07-31 16:45:14 +00:00
|
|
|
|
|
|
|
public function renderColumnMaintenanceName($val, $row)
|
|
|
|
{
|
2024-08-08 08:33:21 +00:00
|
|
|
if ($this->type == "planned") {
|
|
|
|
$ret = '<a href="' . route('maintenance.planned.detail', $row['id']) . '">' . e($val) . '</a>';
|
|
|
|
} else {
|
|
|
|
$ret = '<a href="' . route('maintenance.history.detail', $row['id']) . '">' . e($val) . '</a>';
|
|
|
|
}
|
|
|
|
|
2024-07-31 16:45:14 +00:00
|
|
|
return $ret;
|
|
|
|
}
|
2024-08-06 14:57:48 +00:00
|
|
|
|
|
|
|
public function actions($item)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'type' => "livewire",
|
|
|
|
'action' => "remove",
|
|
|
|
'text' => "remove",
|
|
|
|
'parameters' => $item['id']
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
2024-07-31 15:04:33 +00:00
|
|
|
}
|