@@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
* @property string $role
|
||||
* @property string $decision
|
||||
* @property int|null $approver_id
|
||||
* @property array<string,mixed>|null $routing
|
||||
*/
|
||||
class ApprovalStep extends Model
|
||||
{
|
||||
@@ -17,4 +18,9 @@ class ApprovalStep extends Model
|
||||
public $timestamps = false;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['routing' => 'array'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,18 @@ class PurchaseOrder extends Model
|
||||
return ['snapshot' => 'array', 'issued_at' => 'datetime'];
|
||||
}
|
||||
|
||||
/** Older synthetic documents may predate the complete frozen document structure. */
|
||||
public function hasCompleteDocumentSnapshot(): bool
|
||||
{
|
||||
foreach (['company', 'department', 'cost_center', 'requisition', 'issuer', 'requester', 'supplier', 'quotation', 'award', 'approval_rules', 'decision_matrix', 'final_approvals'] as $key) {
|
||||
if (! is_array($this->snapshot[$key] ?? null)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @return HasMany<PurchaseOrderItem, $this> */
|
||||
public function items(): HasMany
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Enums\PurchasingRole;
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use App\Models\Concerns\HasWorkContext;
|
||||
use App\Services\ConflictGuard;
|
||||
use App\Services\RequisitionApprovalLevels;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -27,6 +28,7 @@ use Tempo\Purchasing\Internal\InternalRequisitions;
|
||||
* @property Carbon|null $submitted_at
|
||||
* @property Carbon|null $needed_by
|
||||
* @property array<string,mixed>|null $comparison_policy
|
||||
* @property array<string,mixed>|null $budget_distribution_preparation
|
||||
* @property Collection<int, ApprovalStep> $steps
|
||||
* @property Collection<int, RequisitionItem> $items
|
||||
*/
|
||||
@@ -37,9 +39,12 @@ class Requisition extends Model
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
// Stage-specific controllers expose authorised preparation explicitly, never quotation details through generic request JSON.
|
||||
protected $hidden = ['budget_distribution_preparation'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['draft_input' => 'array', 'approval_snapshot' => 'array', 'comparison_policy' => 'array', 'submitted_at' => 'datetime', 'needed_by' => 'date:Y-m-d'];
|
||||
return ['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> */
|
||||
@@ -75,10 +80,11 @@ class Requisition extends Model
|
||||
/** @param Builder<Requisition> $query */
|
||||
public function scopeVisibleTo(Builder $query, User $user): void
|
||||
{
|
||||
if ($user->departmentScoped()) {
|
||||
$query->where('department_id', $user->department_id);
|
||||
} elseif (! $user->hasFunctions([PurchasingRole::Admin, PurchasingRole::Procurement, PurchasingRole::Finance])) {
|
||||
$query->where('requester_id', $user->id);
|
||||
if ($user->departmentScoped() || ! $user->hasFunctions([PurchasingRole::Admin, PurchasingRole::Procurement, PurchasingRole::Finance])) {
|
||||
$query->where(function ($visible) use ($user) {
|
||||
$visible->where($user->departmentScoped() ? 'department_id' : 'requester_id', $user->departmentScoped() ? $user->department_id : $user->id);
|
||||
app(RequisitionApprovalLevels::class)->includeVisible($visible, $user);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,8 +96,9 @@ class Requisition extends Model
|
||||
|
||||
$next = InternalRequisitions::nextStep(['status' => $this->status, 'requester_id' => $this->requester_id, 'steps' => $this->steps->toArray()], $user->id);
|
||||
|
||||
return $next !== null && $user->hasFunctions([$next['role']])
|
||||
&& ($next['role'] !== 'department_head' || $this->department_id === $user->department_id)
|
||||
return $next !== null && (str_starts_with($next['role'], 'configured_')
|
||||
? app(RequisitionApprovalLevels::class)->eligible($user, $this, $next)
|
||||
: ($user->hasFunctions([$next['role']]) && ($next['role'] !== 'department_head' || $this->department_id === $user->department_id)))
|
||||
&& ! app(ConflictGuard::class)->participationBlocked($user, $this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
/**
|
||||
* @property array{country:string,catalogue:string,record_id:string}|null $geography_reference
|
||||
* @property array<string,mixed>|null $company_details
|
||||
* @property array<string,mixed>|null $requisition_approval_policy
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property int $first_limit_minor
|
||||
@@ -24,6 +25,6 @@ class Tenant extends Model
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['company_details' => 'array', 'geography_reference' => 'array', 'work_context_policy' => 'array', 'approval_includes_tax' => 'boolean', 'rules_provisional' => 'boolean', 'default_tax_rate' => 'decimal:2', 'comparison_policy' => 'array', 'intelligence_policy' => 'array'];
|
||||
return ['requisition_approval_policy' => 'array', 'company_details' => 'array', 'geography_reference' => 'array', 'work_context_policy' => 'array', 'approval_includes_tax' => 'boolean', 'rules_provisional' => 'boolean', 'default_tax_rate' => 'decimal:2', 'comparison_policy' => 'array', 'intelligence_policy' => 'array'];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user