32 lines
992 B
PHP
32 lines
992 B
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Enums\PurchasingRole;
|
|
use App\Models\Supplier;
|
|
use App\Models\User;
|
|
use App\Services\SupplierParticipation;
|
|
|
|
class SupplierPolicy
|
|
{
|
|
public function viewAny(User $user): bool
|
|
{
|
|
return $user->tenant_id !== null && $user->hasFunctions([PurchasingRole::Admin, PurchasingRole::Procurement, PurchasingRole::Finance, PurchasingRole::DepartmentHead]);
|
|
}
|
|
|
|
public function view(User $user, Supplier $supplier): bool
|
|
{
|
|
return $this->viewAny($user) && $user->tenant_id === $supplier->tenant_id;
|
|
}
|
|
|
|
public function update(User $user, Supplier $supplier): bool
|
|
{
|
|
return app(SupplierParticipation::class)->canPrepare($user) && $user->tenant_id === $supplier->tenant_id;
|
|
}
|
|
|
|
public function viewDocuments(User $user, Supplier $supplier): bool
|
|
{
|
|
return $this->view($user, $supplier) && $user->hasFunctions([PurchasingRole::Admin, PurchasingRole::Procurement, PurchasingRole::Finance]);
|
|
}
|
|
}
|