🚀 مُصادَق: تحديث برمجي جديد 2026-05-03 13:39
This commit is contained in:
@@ -89,4 +89,53 @@ final class InvoiceController
|
||||
Response::error($e->getMessage(), 'UPLOAD_FAILED', 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function detail(Request $request, array $vars): void
|
||||
{
|
||||
$tenantId = $request->tenantId;
|
||||
$invoiceId = $vars['id'] ?? null;
|
||||
|
||||
$db = \App\Core\Database::getInstance();
|
||||
$stmt = $db->prepare("SELECT * FROM invoices WHERE id = ? AND tenant_id = ? AND deleted_at IS NULL LIMIT 1");
|
||||
$stmt->execute([$invoiceId, $tenantId]);
|
||||
$invoice = $stmt->fetch();
|
||||
|
||||
if (!$invoice) {
|
||||
Response::error('الفاتورة غير موجودة', 'NOT_FOUND', 404);
|
||||
return;
|
||||
}
|
||||
|
||||
// Additional authorization check based on assigned company if needed
|
||||
$role = $request->user->role ?? 'viewer';
|
||||
if ($role !== 'super_admin' && $invoice['company_id'] !== $request->user->assigned_company_id) {
|
||||
Response::error('غير مصرح لك بمشاهدة هذه الفاتورة', 'FORBIDDEN', 403);
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch lines
|
||||
$stmt = $db->prepare("SELECT * FROM invoice_lines WHERE invoice_id = ? ORDER BY id ASC");
|
||||
$stmt->execute([$invoiceId]);
|
||||
$invoice['lines'] = $stmt->fetchAll();
|
||||
|
||||
Response::json([
|
||||
'success' => true,
|
||||
'data' => $invoice
|
||||
]);
|
||||
}
|
||||
|
||||
public function submit(Request $request, array $vars): void
|
||||
{
|
||||
$tenantId = $request->tenantId;
|
||||
$invoiceId = $vars['id'];
|
||||
|
||||
// Push to Queue for JoFotara Submission
|
||||
\App\Services\QueueService::push('submit_jofotara', [
|
||||
'invoice_id' => $invoiceId
|
||||
]);
|
||||
|
||||
Response::json([
|
||||
'success' => true,
|
||||
'message' => 'Invoice submission queued.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user