🚀 مُصادَق: تحديث برمجي جديد 2026-05-03 14:50

This commit is contained in:
Hamza-Ayed
2026-05-03 14:50:24 +03:00
parent fe075e64d1
commit 3aeb3220f1
9 changed files with 362 additions and 127 deletions

View 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() ?: [];
}
}