LAR_Maintenance/app/Http/Controllers/MaintenanceController.php

86 lines
2.6 KiB
PHP
Raw Normal View History

2024-07-30 16:13:21 +00:00
<?php
namespace App\Http\Controllers;
2024-07-31 16:45:14 +00:00
use App\Models\MaintenanceHistory;
use Carbon\Carbon;
2024-08-07 05:52:07 +00:00
use Illuminate\Http\Request;
2024-07-31 16:45:14 +00:00
2024-07-30 16:13:21 +00:00
class MaintenanceController extends BaseController
{
public function index()
{
return view('maintenance.index');
}
2024-07-31 15:04:33 +00:00
public function planned()
{
return view('maintenance.planned');
}
2024-07-31 16:45:14 +00:00
public function plannedDetail(MaintenanceHistory $maintenance_history)
{
2024-08-09 06:37:00 +00:00
if (!empty($maintenance_history->finished_at)) {
abort(404);
}
2024-07-31 16:45:14 +00:00
return view('maintenance.planned-detail', [
'maintenance_history' => $maintenance_history,
]);
}
2024-08-07 05:52:07 +00:00
public function plannedDetailPut(Request $request, MaintenanceHistory $maintenance_history)
{
2024-08-09 06:37:00 +00:00
if (!empty($maintenance_history->finished_at)) {
abort(404);
}
2024-08-07 05:52:07 +00:00
return view('maintenance.planned-detail-done', [
'maintenance_history' => $maintenance_history,
'maintenance_task_status' => $request->input('maintenance_task_status'),
2024-08-09 06:37:00 +00:00
'maintenance_host_skipped' => $request->input('maintenance_host_skipped'),
2024-08-07 05:52:07 +00:00
]);
}
public function plannedDetailFinishPost(Request $request, MaintenanceHistory $maintenance_history)
{
2024-08-09 06:37:00 +00:00
if (!empty($maintenance_history->finished_at)) {
abort(404);
}
foreach ($request->input('skippedHostsSummary') as $history_host_id => $summary) {
$maintenance_history->historyHosts->find($history_host_id)->update([
'summary' => $summary,
]);
}
if (!$request->has('skippedHostsTasksSummary')) {
foreach ($maintenance_history->historyHosts as $history_host) {
if (!isset($request->input('skippedHostsTasksSummary')[$history_host->id]))
continue;
foreach ($request->input('skippedHostsTasksSummary')[$history_host->id] as $history_task_id => $task_summary) {
$history_host->find($history_task_id)->update([
'summary' => $task_summary,
]);
}
}
}
$maintenance_history->finished_at = Carbon::now();
$maintenance_history->save();
return redirect()->route('maintenance.history.detail', $maintenance_history->id);
}
2024-08-09 06:37:00 +00:00
public function history(Request $request)
{
return view('maintenance.history');
}
2024-08-09 06:37:00 +00:00
public function historyDetail(Request $request, MaintenanceHistory $maintenance_history)
{
dd($maintenance_history->historyHosts);
}
2024-07-30 16:13:21 +00:00
}