🚀 مُصادَق: تحديث برمجي جديد 2026-05-03 14:50
This commit is contained in:
31
app/Modules/Invoices/Actions/ListInvoicesAction.php
Normal file
31
app/Modules/Invoices/Actions/ListInvoicesAction.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace App\Modules\Invoices\Actions;
|
||||
|
||||
use App\Core\Database;
|
||||
|
||||
final class ListInvoicesAction {
|
||||
public function execute(string $tenantId, $user): array {
|
||||
$db = Database::getInstance();
|
||||
$role = $user->role ?? 'viewer';
|
||||
$assignedCompanyId = $user->assigned_company_id ?? null;
|
||||
|
||||
if ($role === 'super_admin' || $role === 'admin') {
|
||||
$stmt = $db->prepare("SELECT i.*, c.name as company_name
|
||||
FROM invoices i
|
||||
JOIN companies c ON i.company_id = c.id
|
||||
WHERE i.tenant_id = ? AND i.deleted_at IS NULL
|
||||
ORDER BY i.created_at DESC");
|
||||
$stmt->execute([$tenantId]);
|
||||
} else {
|
||||
$stmt = $db->prepare("SELECT i.*, c.name as company_name
|
||||
FROM invoices i
|
||||
JOIN companies c ON i.company_id = c.id
|
||||
WHERE i.tenant_id = ? AND i.company_id = ? AND i.deleted_at IS NULL
|
||||
ORDER BY i.created_at DESC");
|
||||
$stmt->execute([$tenantId, $assignedCompanyId]);
|
||||
}
|
||||
|
||||
return $stmt->fetchAll() ?: [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user