Below is one way you can “re-map” your status levels so that:
- Completed and Cancelled share the same final level, making them final states that cannot be updated from one to the other (or to any other state).
- The statuses Rescheduled, No_Show, and No_Answer are kept as separate statuses that occur before the final “completed/cancelled” level—they must not come after the final level.
A suggested updated mapping could be:
| Level | Status / Group | Comment |
|---|
| 0 | pending | Job is awaiting confirmation. |
| 1 | confirmed | Job has been confirmed. |
| 2 | on_route | The technician is on the route. |
| 3 | arrived | The technician has arrived at the job location. |
| 4 | in_progress | The service is currently in progress. |
| 5 | rescheduled | The appointment was rescheduled (pre-final state). |
| 6 | no_show | The customer did not show up (pre-final state). |
| 7 | no_answer | There was no answer from the customer (pre-final state). |
| 8 | completed / cancelled | Both are considered final states and share the same level (final state). |
Explanation
-
Workflow progression:
The “normal” workflow progresses from pending → confirmed → on_route → arrived → in_progress. If any issues arise before finishing the service, you can mark the job as rescheduled, no_show, or no_answer. These statuses occur before the finalization, meaning they have levels lower than level 8.
-
Final states:
When the service is successfully delivered, use completed; if the job is terminated (or cancelled), then cancelled is used. Because both share the same level (level 8), you thereby prevent any “update” between them after that final state is reached. In your system’s workflow logic, you can simply check if a status is at level 8 and consider it locked.
Example Seeder Code in Laravel
Below is an example of how you might implement this in a Laravel seeder. (Assuming you have a table—for example, job_statuses—that stores these statuses.)
<?php
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class JobStatusesSeeder extends Seeder
{
public function run()
{
// Clear existing statuses (optional)
DB::table('job_statuses')->truncate();
// Insert statuses with their levels
DB::table('job_statuses')->insert([
[
'id' => 0,
'name' => 'pending',
'level' => 0,
'description' => 'Job is awaiting confirmation.'
],
[
'id' => 1,
'name' => 'confirmed',
'level' => 1,
'description' => 'Job has been confirmed.'
],
[
'id' => 2,
'name' => 'on_route',
'level' => 2,
'description' => 'Technician is on route to the service location.'
],
[
'id' => 3,
'name' => 'arrived',
'level' => 3,
'description' => 'Technician has arrived at the location.'
],
[
'id' => 4,
'name' => 'in_progress',
'level' => 4,
'description' => 'Service is currently in progress.'
],
[
'id' => 5,
'name' => 'rescheduled',
'level' => 5,
'description' => 'The appointment was rescheduled.'
],
[
'id' => 6,
'name' => 'no_show',
'level' => 6,
'description' => 'Customer did not show up.'
],
[
'id' => 7,
'name' => 'no_answer',
'level' => 7,
'description' => 'No answer from the customer.'
],
// Notice that both completed and cancelled share level 8.
[
'id' => 8,
'name' => 'completed',
'level' => 8,
'description' => 'Service has been completed successfully.'
],
[
'id' => 9,
'name' => 'cancelled',
'level' => 8,
'description' => 'Job was cancelled.'
],
]);
echo "Job statuses seeded successfully!" . PHP_EOL;
}
}
How This Meets Your Requirements
-
Final / Immutable States: Because both completed and cancelled have the same level (8), in your application logic you can enforce that no transitions occur between these two final states.
-
Status Order and Seeding: The statuses rescheduled, no_show, and no_answer are assigned levels before the final level (8) so that they never come “after” a final state. Each is seeded separately so you can easily reference them in your application for technicians performing services.
Feel free to adjust the numerical levels if needed, but the key idea is to separate the workflow states logically so that the final (immutable) statuses are the highest level and the alternate outcomes (like rescheduled/no_show/no_answer) are set prior to them.