Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions app/Enums/Concerns/HasProgress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\Enums\Concerns;

trait HasProgress
{
/**
* Get list of pending enum cases.
*
* @return list<self>
*/
abstract public static function pendingCases(): array;

/**
* Get list of complete enum cases.
*
* @return list<self>
*/
abstract public static function completeCases(): array;

/**
* Determine if the enum case is pending.
*/
public function isPending(): bool
{
return in_array($this, static::pendingCases());
}

/**
* Determine if the enum case is void (excluded from progress calculations).
*/
public function isVoid(): bool
{
return ! $this->isPending() && ! $this->isComplete();
}

/**
* Determine if the enum case is complete.
*/
public function isComplete(): bool
{
return in_array($this, static::completeCases());
}
}
22 changes: 21 additions & 1 deletion app/Enums/DeviceStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace App\Enums;

use App\Enums\Concerns\HasProgress;
use App\Enums\Concerns\HasValues;

enum DeviceStatus: string
{
use HasValues;
use HasProgress, HasValues;

/**
* Device has been received and is awaiting repair.
Expand All @@ -32,4 +33,23 @@ enum DeviceStatus: string
* Device has been delivered to the customer.
*/
case Delivered = 'delivered';

// METHODS /////////////////////////////////////////////////////////////////////////////////////

public static function pendingCases(): array
{
return [
self::Received,
self::OnHold,
self::UnderRepair,
];
}

public static function completeCases(): array
{
return [
self::Ready,
self::Delivered,
];
}
}
22 changes: 21 additions & 1 deletion app/Enums/InvoiceStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace App\Enums;

use App\Enums\Concerns\HasProgress;
use App\Enums\Concerns\HasValues;

enum InvoiceStatus: string
{
use HasValues;
use HasProgress, HasValues;

/**
* Invoice has been created and is awaiting approval.
Expand Down Expand Up @@ -37,4 +38,23 @@ enum InvoiceStatus: string
* Invoice has been cancelled.
*/
case Cancelled = 'cancelled';

// METHODS /////////////////////////////////////////////////////////////////////////////////////

public static function pendingCases(): array
{
return [
self::Draft,
self::Issued,
self::Sent,
];
}

public static function completeCases(): array
{
return [
self::Paid,
self::Refunded,
];
}
}
20 changes: 19 additions & 1 deletion app/Enums/OrderStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace App\Enums;

use App\Enums\Concerns\HasProgress;
use App\Enums\Concerns\HasValues;

enum OrderStatus: string
{
use HasValues;
use HasProgress, HasValues;

/**
* Represents an order that has been created and is awaiting processing.
Expand All @@ -29,4 +30,21 @@ enum OrderStatus: string
* Represents an order that has been cancelled by the customer or by the system.
*/
case Cancelled = 'cancelled';

// METHODS /////////////////////////////////////////////////////////////////////////////////////

public static function pendingCases(): array
{
return [
self::New,
self::Shipped,
];
}

public static function completeCases(): array
{
return [
self::Received,
];
}
}
36 changes: 36 additions & 0 deletions app/Enums/Priority.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Enums;

use App\Enums\Concerns\HasValues;

enum Priority: string
{
use HasValues;

/**
* The ticket has a low priority and can be addressed within 2 weeks.
* Suitable for non-urgent customer requests, awaiting parts, or when workload is heavy.
*/
case Low = 'low';

/**
* The ticket has a medium priority and should be addressed within 1 week.
* Standard business priority for most customer requests and routine workflow.
*
* @default
*/
case Medium = 'medium';

/**
* The ticket has a high priority and should be addressed within 2 days.
* Important for premium customers, express service requests, or business commitments.
*/
case High = 'high';

/**
* The ticket has an urgent priority and requires immediate attention (same day).
* Critical for VIP customers, emergency requests, or when delays impact business operations.
*/
case Urgent = 'urgent';
}
19 changes: 18 additions & 1 deletion app/Enums/TaskStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace App\Enums;

use App\Enums\Concerns\HasProgress;
use App\Enums\Concerns\HasValues;

enum TaskStatus: string
{
use HasValues;
use HasProgress, HasValues;

/**
* Represents an task that has been created and is pending approval.
Expand All @@ -24,4 +25,20 @@ enum TaskStatus: string
* Represents an task that has been cancelled.
*/
case Cancelled = 'cancelled';

// METHODS /////////////////////////////////////////////////////////////////////////////////////

public static function pendingCases(): array
{
return [
self::New,
];
}

public static function completeCases(): array
{
return [
self::Completed,
];
}
}
27 changes: 0 additions & 27 deletions app/Enums/TicketPriority.php

This file was deleted.

21 changes: 20 additions & 1 deletion app/Enums/TicketStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace App\Enums;

use App\Enums\Concerns\HasProgress;
use App\Enums\Concerns\HasValues;

enum TicketStatus: string
{
use HasValues;
use HasProgress, HasValues;

/**
* The ticket is new and has not been assigned to anyone.
Expand Down Expand Up @@ -35,4 +36,22 @@ enum TicketStatus: string
*/
case Closed = 'closed';

// METHODS /////////////////////////////////////////////////////////////////////////////////////

public static function pendingCases(): array
{
return [
self::New,
self::InProgress,
self::OnHold,
];
}

public static function completeCases(): array
{
return [
self::Resolved,
self::Closed,
];
}
}
64 changes: 64 additions & 0 deletions app/Models/Concerns/Assignable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace App\Models\Concerns;

use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

trait Assignable
{
private const ASSIGNEE_ID = 'assignee_id';

/**
* Determine if the model is assigned.
*/
public function isAssigned(): bool
{
return $this->{static::ASSIGNEE_ID} !== null;
}

/**
* Assign the model to a user.
*/
public function assignTo(User $user): void
{
$this->assignee()->associate($user)->save();
}

/**
* Unassign the model from a user.
*/
public function unassign(): void
{
$this->assignee()->dissociate()->save();
}

// RELATIONS ///////////////////////////////////////////////////////////////////////////////////

/**
* Get the assignee (user) for the model.
*/
public function assignee(): BelongsTo
{
return $this->belongsTo(User::class, static::ASSIGNEE_ID);
}

// SCOPES //////////////////////////////////////////////////////////////////////////////////////

/**
* Scope a query to only include models that are already assigned.
*/
public function scopeAssigned(Builder $query): void
{
$query->whereNotNull(static::ASSIGNEE_ID);
}

/**
* Scope a query to only include models that are unassigned.
*/
public function scopeUnassigned(Builder $query): void
{
$query->whereNull(static::ASSIGNEE_ID);
}
}
Loading