Consolida recepcoes, stock, equipamentos e identidade SGC
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Enums\PurchasingRole;
|
||||
use App\Models\GoodsReceipt;
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Models\Requisition;
|
||||
use App\Models\User;
|
||||
|
||||
class GoodsReceiptPolicy
|
||||
{
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return $user->tenant_id !== null && in_array($user->purchasing_role, [PurchasingRole::Admin, PurchasingRole::Procurement, PurchasingRole::Finance, PurchasingRole::Warehouse, PurchasingRole::DepartmentHead]);
|
||||
}
|
||||
|
||||
public function viewOrder(User $user, PurchaseOrder $order): bool
|
||||
{
|
||||
return $this->viewAny($user) && $user->tenant_id === $order->tenant_id &&
|
||||
($user->purchasing_role !== PurchasingRole::DepartmentHead || Requisition::query()->whereKey($order->requisition_id)->where('department_id', $user->department_id)->exists());
|
||||
}
|
||||
|
||||
public function view(User $user, GoodsReceipt $receipt): bool
|
||||
{
|
||||
$order = PurchaseOrder::query()->find($receipt->purchase_order_id);
|
||||
|
||||
return $order !== null && $this->viewOrder($user, $order);
|
||||
}
|
||||
|
||||
public function create(User $user, PurchaseOrder $order): bool
|
||||
{
|
||||
return $user->tenant_id === $order->tenant_id && $user->purchasing_role === PurchasingRole::Warehouse && $user->id !== $order->issued_by;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user