Aesthetic Fixes
This commit is contained in:
@@ -4,18 +4,19 @@ namespace Modules\ProjectManagement\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Traits\BelongsToTenant;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Traits\HasPublicIdentifier;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Modules\BiddingManagement\Models\BidPackage;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Modules\BiddingManagement\Models\BidPackage;
|
||||
use Modules\ContractorManagement\Models\Contractor;
|
||||
use Modules\MasterData\Models\MaterialGroup;
|
||||
use Modules\ProjectManagement\Enums\ProjectStatus;
|
||||
use Modules\MaterialLogistics\Models\ProjectInventory;
|
||||
use Modules\MaterialLogistics\Models\Warehouse;
|
||||
use Modules\ProjectManagement\Enums\DelayReason;
|
||||
use Modules\ProjectManagement\Enums\ProjectStatus;
|
||||
|
||||
class Project extends Model
|
||||
{
|
||||
@@ -58,7 +59,8 @@ class Project extends Model
|
||||
static::creating(function (self $project) {
|
||||
if (empty($project->code)) {
|
||||
$year = now()->year;
|
||||
$lastCode = static::withTrashed()
|
||||
$lastCode = static::withoutGlobalScopes()
|
||||
->withTrashed()
|
||||
->where('code', 'like', "PRJ-{$year}-%")
|
||||
->orderByDesc('code')
|
||||
->value('code');
|
||||
@@ -87,7 +89,7 @@ class Project extends Model
|
||||
|
||||
public function inventories(): HasMany
|
||||
{
|
||||
return $this->hasMany(\Modules\MaterialLogistics\Models\ProjectInventory::class);
|
||||
return $this->hasMany(ProjectInventory::class);
|
||||
}
|
||||
|
||||
public function contractor(): BelongsTo
|
||||
@@ -134,7 +136,7 @@ class Project extends Model
|
||||
{
|
||||
$currentStatus = $this->status;
|
||||
|
||||
if (!in_array($newStatus, $currentStatus->allowedTransitions())) {
|
||||
if (! in_array($newStatus, $currentStatus->allowedTransitions())) {
|
||||
throw new \InvalidArgumentException(
|
||||
"Cannot transition from {$currentStatus->label()} to {$newStatus->label()}"
|
||||
);
|
||||
@@ -143,7 +145,7 @@ class Project extends Model
|
||||
// Guard: can't move to InProgress without assigned PM
|
||||
if ($newStatus === ProjectStatus::InProgress) {
|
||||
$hasPm = $this->personnel()->wherePivot('role', 'pm')->exists();
|
||||
if (!$hasPm) {
|
||||
if (! $hasPm) {
|
||||
throw new \InvalidArgumentException('Cannot start project without a Project Manager assigned');
|
||||
}
|
||||
}
|
||||
@@ -167,7 +169,10 @@ class Project extends Model
|
||||
|
||||
public function getCapitalizationPercentageAttribute(): float
|
||||
{
|
||||
if ($this->contract_value <= 0) return 0;
|
||||
if ($this->contract_value <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return round(($this->total_capitalization / $this->contract_value) * 100, 2);
|
||||
}
|
||||
|
||||
@@ -185,7 +190,9 @@ class Project extends Model
|
||||
public function getMilestoneCompletionAttribute(): float
|
||||
{
|
||||
$milestones = $this->milestones;
|
||||
if ($milestones->isEmpty()) return 0;
|
||||
if ($milestones->isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (float) $milestones
|
||||
->where('actual_date', '!=', null)
|
||||
@@ -198,8 +205,8 @@ class Project extends Model
|
||||
|
||||
$taskDelayHours = (float) $this->tasks->flatMap(
|
||||
fn (Task $task) => $task->delays
|
||||
)->where('reason_type', \Modules\ProjectManagement\Enums\DelayReason::Weather)
|
||||
->sum('lost_hours');
|
||||
)->where('reason_type', DelayReason::Weather)
|
||||
->sum('lost_hours');
|
||||
|
||||
return $milestoneDays + (int) ceil($taskDelayHours / 8);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user