diff --git a/app/modules_app/companies/delete.php b/app/modules_app/companies/delete.php new file mode 100644 index 0000000..0a5845a --- /dev/null +++ b/app/modules_app/companies/delete.php @@ -0,0 +1,39 @@ +prepare("SELECT tenant_id FROM companies WHERE id = ?"); +$stmt->execute([$companyId]); +$company = $stmt->fetch(); + +if (!$company) { + json_error('الشركة غير موجودة', 404); +} + +if ($decoded['role'] === 'admin' && $company['tenant_id'] !== $decoded['tenant_id']) { + json_error('ليس لديك صلاحية لحذف هذه الشركة', 403); +} + +// Soft Delete +$stmt = $db->prepare("UPDATE companies SET deleted_at = NOW() WHERE id = ?"); +$stmt->execute([$companyId]); + +json_success(null, 'تم حذف الشركة بنجاح'); diff --git a/app/modules_app/invoices/upload.php b/app/modules_app/invoices/upload.php index 1f80cbb..dce4a39 100644 --- a/app/modules_app/invoices/upload.php +++ b/app/modules_app/invoices/upload.php @@ -14,6 +14,13 @@ $allowedRoles = ['admin', 'accountant', 'employee']; if (!in_array($decoded['role'], $allowedRoles)) { json_error('Unauthorized to upload invoices', 403); } +// 2. Validate Request +$data = input(); +$companyId = $data['company_id'] ?? null; + +if (!$companyId || !isset($_FILES['invoice'])) { + json_error('Company ID and invoice file are required', 422); +} // 3. Permission Check $tenantId = $decoded['tenant_id']; diff --git a/public/index.php b/public/index.php index 7d1bc66..3417085 100644 --- a/public/index.php +++ b/public/index.php @@ -24,6 +24,7 @@ $routes = [ 'v1/users/delete' => ['POST', 'users/delete.php'], 'v1/companies' => ['GET', 'companies/index.php'], 'v1/companies/create' => ['POST', 'companies/create.php'], + 'v1/companies/delete' => ['POST', 'companies/delete.php'], 'v1/invoices' => ['GET', 'invoices/index.php'], 'v1/invoices/upload' => ['POST', 'invoices/upload.php'], 'v1/dashboard/stats' => ['GET', 'dashboard/stats.php'], diff --git a/public/shell.php b/public/shell.php index 0fe4905..b4c0b2e 100644 --- a/public/shell.php +++ b/public/shell.php @@ -153,6 +153,42 @@ + +
| الشركة | +الأرقام الرسمية | +العنوان | +المكتب | +إجراءات | +
|---|---|---|---|---|
| لا توجد شركات بعد | ||||
| + + | +
+ TIN: +CRN: + |
+ + | + | + + | +