32 lines
1.2 KiB
PHP
32 lines
1.2 KiB
PHP
<?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() ?: [];
|
|
}
|
|
}
|