@@ -13,6 +13,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Tempo\Purchasing\Internal\InternalRequisitions;
|
||||
|
||||
/**
|
||||
@@ -29,6 +30,7 @@ use Tempo\Purchasing\Internal\InternalRequisitions;
|
||||
* @property Carbon|null $needed_by
|
||||
* @property array<string,mixed>|null $comparison_policy
|
||||
* @property array<string,mixed>|null $budget_distribution_preparation
|
||||
* @property array<string,mixed>|null $approval_snapshot
|
||||
* @property Collection<int, ApprovalStep> $steps
|
||||
* @property Collection<int, RequisitionItem> $items
|
||||
*/
|
||||
@@ -44,7 +46,7 @@ class Requisition extends Model
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['draft_input' => 'array', 'budget_distribution_preparation' => 'array', 'approval_snapshot' => 'array', 'comparison_policy' => 'array', 'submitted_at' => 'datetime', 'needed_by' => 'date:Y-m-d'];
|
||||
return ['approval_cycle' => 'integer', 'draft_input' => 'array', 'budget_distribution_preparation' => 'array', 'approval_snapshot' => 'array', 'comparison_policy' => 'array', 'submitted_at' => 'datetime', 'needed_by' => 'date:Y-m-d'];
|
||||
}
|
||||
|
||||
/** @return HasMany<RequisitionItem, $this> */
|
||||
@@ -56,7 +58,15 @@ class Requisition extends Model
|
||||
/** @return HasMany<ApprovalStep, $this> */
|
||||
public function steps(): HasMany
|
||||
{
|
||||
return $this->hasMany(ApprovalStep::class)->orderBy('position');
|
||||
return $this->hasMany(ApprovalStep::class)->when(Schema::hasColumn('approval_steps', 'approval_cycle'), fn ($query) => $query->whereExists(fn ($current) => $current
|
||||
->selectRaw('1')->from('requisitions as current_cycle_request')->whereColumn('current_cycle_request.id', 'approval_steps.requisition_id')
|
||||
->whereColumn('current_cycle_request.approval_cycle', 'approval_steps.approval_cycle')))->orderBy('position');
|
||||
}
|
||||
|
||||
/** @return HasMany<ApprovalStep, $this> */
|
||||
public function allSteps(): HasMany
|
||||
{
|
||||
return $this->hasMany(ApprovalStep::class)->orderBy('id');
|
||||
}
|
||||
|
||||
/** @return BelongsTo<User, $this> */
|
||||
|
||||
Reference in New Issue
Block a user