🚀 مُصادَق: تحديث برمجي جديد 2026-05-03 14:02
This commit is contained in:
@@ -58,9 +58,14 @@ final class AuthController
|
||||
|
||||
public function me(Request $request): void
|
||||
{
|
||||
$db = \App\Core\Database::getInstance();
|
||||
$stmt = $db->prepare("SELECT id, tenant_id, name, email, role, totp_enabled FROM users WHERE id = ?");
|
||||
$stmt->execute([$request->user->user_id]);
|
||||
$user = $stmt->fetch();
|
||||
|
||||
Response::json([
|
||||
'success' => true,
|
||||
'data' => $request->user
|
||||
'data' => $user
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ final class CompanyController
|
||||
];
|
||||
|
||||
try {
|
||||
$this->companyService->createCompany(array_merge($data, ['id' => $id])); // Reuses encryption logic
|
||||
$this->companyService->updateJoFotara($id, $data);
|
||||
Response::json([
|
||||
'success' => true,
|
||||
'message' => 'تم تحديث بيانات جو-فواتير بنجاح'
|
||||
|
||||
@@ -34,6 +34,21 @@ final class CompanyService
|
||||
return (string)$this->companyModel->create($data);
|
||||
}
|
||||
|
||||
public function updateJoFotara(string $id, array $data): bool
|
||||
{
|
||||
if (isset($data['jofotara_client_id'])) {
|
||||
$data['jofotara_client_id_encrypted'] = $this->encryption->encrypt($data['jofotara_client_id']);
|
||||
unset($data['jofotara_client_id']);
|
||||
}
|
||||
|
||||
if (isset($data['jofotara_secret_key'])) {
|
||||
$data['jofotara_secret_key_encrypted'] = $this->encryption->encrypt($data['jofotara_secret_key']);
|
||||
unset($data['jofotara_secret_key']);
|
||||
}
|
||||
|
||||
return $this->companyModel->update($id, $data);
|
||||
}
|
||||
|
||||
public function getJoFotaraCredentials(string $companyId): array
|
||||
{
|
||||
$company = $this->companyModel->find($companyId);
|
||||
|
||||
@@ -33,8 +33,8 @@ final class DashboardController
|
||||
$stmt->execute($params);
|
||||
$statusCounts = $stmt->fetchAll();
|
||||
|
||||
// 3. Recent Activity
|
||||
$stmt = $db->prepare("SELECT i.*, c.name as company_name FROM invoices i JOIN companies c ON i.company_id = c.id {$where} ORDER BY i.created_at DESC LIMIT 5");
|
||||
// 3. Recent Activity - Fixed ambiguity
|
||||
$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 = ? " . ($role !== 'super_admin' ? " AND i.company_id = ?" : "") . " ORDER BY i.created_at DESC LIMIT 5");
|
||||
$stmt->execute($params);
|
||||
$recent = $stmt->fetchAll();
|
||||
|
||||
|
||||
@@ -25,11 +25,11 @@ final class InvoiceController
|
||||
$assignedCompanyId = $request->user->assigned_company_id ?? null;
|
||||
|
||||
if ($role === 'super_admin') {
|
||||
$invoices = $this->invoiceModel->findByTenant($tenantId);
|
||||
$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]);
|
||||
$invoices = $stmt->fetchAll();
|
||||
} else {
|
||||
// Filter by assigned company for admin, accountant, etc.
|
||||
$db = \App\Core\Database::getInstance();
|
||||
$stmt = $db->prepare("SELECT * FROM invoices WHERE tenant_id = ? AND company_id = ? AND deleted_at IS NULL ORDER BY created_at DESC");
|
||||
$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]);
|
||||
$invoices = $stmt->fetchAll();
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ final class UserController
|
||||
'success' => true,
|
||||
'data' => $user
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(Request $request): void
|
||||
{
|
||||
$tenantId = $request->tenantId;
|
||||
|
||||
@@ -15,6 +15,10 @@ $router = $app->getRouter();
|
||||
// ══ Auth Routes ══════════════════════════════════════════════
|
||||
$router->addRoute('POST', '/api/v1/auth/login', [AuthController::class, 'login']);
|
||||
$router->addRoute('POST', '/api/v1/auth/register', [AuthController::class, 'register']);
|
||||
$router->addRoute('GET', '/api/v1/auth/me', [
|
||||
'middleware' => [\App\Middleware\AuthMiddleware::class],
|
||||
'handler' => [AuthController::class, 'me']
|
||||
]);
|
||||
$router->addRoute('POST', '/api/v1/auth/2fa/enable', [
|
||||
'middleware' => [\App\Middleware\AuthMiddleware::class],
|
||||
'handler' => [AuthController::class, 'enable2FA']
|
||||
@@ -37,7 +41,7 @@ $router->addRoute('POST', '/api/v1/companies', [
|
||||
'middleware' => [\App\Middleware\AuthMiddleware::class],
|
||||
'handler' => [\App\Modules\Companies\CompanyController::class, 'create']
|
||||
]);
|
||||
$router->addRoute('PUT', '/api/v1/companies/{id}/jofotara', [
|
||||
$router->addRoute('POST', '/api/v1/companies/{id}/jofotara', [
|
||||
'middleware' => [\App\Middleware\AuthMiddleware::class],
|
||||
'handler' => [\App\Modules\Companies\CompanyController::class, 'updateJoFotara']
|
||||
]);
|
||||
|
||||
1597
public/shell.php
1597
public/shell.php
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user