From 41f941cfbc1ed648e4423150bfd85557797fb5e7 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Wed, 8 Oct 2025 14:32:04 +0200 Subject: [PATCH] overhauled workorder module --- .../RMLWorkorderAdminController.php | 8 -- .../RMLWorkorderCompanyController.php | 8 -- .../WorkorderBase/WorkorderBaseController.php | 3 +- .../WorkorderCompanyController.php | 21 +++++- ...251008140000_workorder_add_in_progress.php | 74 +++++++++++++++++++ 5 files changed, 95 insertions(+), 19 deletions(-) delete mode 100644 application/RMLWorkorderAdmin/RMLWorkorderAdminController.php delete mode 100644 application/RMLWorkorderCompany/RMLWorkorderCompanyController.php create mode 100644 db/migrations/20251008140000_workorder_add_in_progress.php diff --git a/application/RMLWorkorderAdmin/RMLWorkorderAdminController.php b/application/RMLWorkorderAdmin/RMLWorkorderAdminController.php deleted file mode 100644 index 71a95fac2..000000000 --- a/application/RMLWorkorderAdmin/RMLWorkorderAdminController.php +++ /dev/null @@ -1,8 +0,0 @@ -needlogin = true; - $this->redirect("WorkorderAdmin"); - } -} \ No newline at end of file diff --git a/application/RMLWorkorderCompany/RMLWorkorderCompanyController.php b/application/RMLWorkorderCompany/RMLWorkorderCompanyController.php deleted file mode 100644 index 3c83ff9b2..000000000 --- a/application/RMLWorkorderCompany/RMLWorkorderCompanyController.php +++ /dev/null @@ -1,8 +0,0 @@ -needlogin = true; - $this->redirect("WorkorderCompany"); - } -} \ No newline at end of file diff --git a/application/WorkorderBase/WorkorderBaseController.php b/application/WorkorderBase/WorkorderBaseController.php index 281872390..5e1e2ca56 100644 --- a/application/WorkorderBase/WorkorderBaseController.php +++ b/application/WorkorderBase/WorkorderBaseController.php @@ -13,6 +13,7 @@ class WorkorderBaseController extends TTCrud ['value' => 'new', 'text' => 'Neu', 'icon' => 'fas fa-star text-primary'], ['value' => 'assigned', 'text' => 'Zugewiesen', 'icon' => 'fas fa-user-check text-info'], ['value' => 'scheduled', 'text' => 'Geplant', 'icon' => 'fas fa-calendar-check text-warning'], + ['value' => 'in_progress', 'text' => 'In Bearbeitung', 'icon' => 'fas fa-cog text-warning'], ['value' => 'correction_requested', 'text' => 'Korrektur angefordert', 'icon' => 'fas fa-exclamation-triangle text-danger'], ['value' => 'intervention_required', 'text' => 'Eingriff erforderlich', 'icon' => 'fas fa-times-circle text-danger'], ['value' => 'civil_engineering_required', 'text' => 'Tiefbau benötigt', 'icon' => 'fas fa-hard-hat text-orange'], @@ -211,7 +212,7 @@ class WorkorderBaseController extends TTCrud $activePreorderIds = array_column(PreorderModel::searchActive($activeFilters), 'id'); $activePreorderIdsSet = array_flip($activePreorderIds); - $statusesToCheck = ['new', 'assigned', 'scheduled', 'correction_requested', 'intervention_required', 'civil_engineering_required', 'civil_engineering_completed', 'problem_solved']; + $statusesToCheck = ['new', 'assigned', 'scheduled', 'in_progress', 'correction_requested', 'intervention_required', 'civil_engineering_required', 'civil_engineering_completed', 'problem_solved']; $allTenantPreorders = PreorderModel::getAll(['preordercampaign_id' => $tenantCampaignIds]); if(empty($allTenantPreorders)) continue; diff --git a/application/WorkorderCompany/WorkorderCompanyController.php b/application/WorkorderCompany/WorkorderCompanyController.php index 8a8a66891..7c501f946 100644 --- a/application/WorkorderCompany/WorkorderCompanyController.php +++ b/application/WorkorderCompany/WorkorderCompanyController.php @@ -174,9 +174,26 @@ class WorkorderCompanyController extends WorkorderBaseController { } $workorder = WorkorderModel::get($workorderId); - if (in_array($workorder->status, ['correction_requested', 'problem_solved', 'civil_engineering_completed'])) { - $workorder->status = 'assigned'; + $oldStatus = $workorder->status; + $newStatus = null; + + if (in_array($oldStatus, ['assigned', 'scheduled'])) { + $newStatus = 'in_progress'; + } else if (in_array($oldStatus, ['correction_requested', 'problem_solved', 'civil_engineering_completed'])) { + $newStatus = 'assigned'; + } + + if ($newStatus) { + $workorder->status = $newStatus; WorkorderModel::update((array)$workorder); + + WorkorderJournalModel::create([ + 'workorderId' => $workorder->id, + 'text' => 'Status wurde nach Dokumenten-Upload automatisch auf In Beearbeitung gesetzt.', + 'statusChange' => $this->getStatusText($oldStatus) . " -> " . $this->getStatusText($newStatus), + 'create' => time(), + 'createBy' => $this->user->id, + ]); } self::returnJson(['success' => true, 'message' => "Datei(en) erfolgreich hochgeladen."]); diff --git a/db/migrations/20251008140000_workorder_add_in_progress.php b/db/migrations/20251008140000_workorder_add_in_progress.php new file mode 100644 index 000000000..0b7442aff --- /dev/null +++ b/db/migrations/20251008140000_workorder_add_in_progress.php @@ -0,0 +1,74 @@ +getEnvironment() !== 'thetool') return; + + $this->table('Workorder') + ->changeColumn('status', 'enum', [ + 'values' => [ + 'new', + 'assigned', + 'scheduled', + 'in_progress', + 'correction_requested', + 'intervention_required', + 'civil_engineering_required', + 'civil_engineering_completed', + 'problem_solved', + 'documented', + 'completed', + 'cancelled', + 'archived', + 'charged' + ], + 'default' => 'new', + 'null' => false, + ]) + ->save(); + + // Update existing Workorders that are assigned or scheduled and already have documentation. + $this->execute(" + UPDATE Workorder w + SET w.status = 'in_progress' + WHERE w.status IN ('assigned', 'scheduled') + AND EXISTS ( + SELECT 1 + FROM WorkorderDocumentation wd + WHERE wd.workorderId = w.id + ) + "); + + } + + public function down(): void { + if ($this->getEnvironment() !== 'thetool') return; + + $this->table('Workorder') + ->changeColumn('status', 'enum', [ + 'values' => [ + 'new', + 'assigned', + 'scheduled', + 'correction_requested', + 'intervention_required', + 'civil_engineering_required', + 'civil_engineering_completed', + 'problem_solved', + 'documented', + 'completed', + 'cancelled', + 'archived', + 'charged' + ], + 'default' => 'new', + 'null' => false, + ]) + ->save(); + } +} +