execute($request->tenantId, $request->user); Response::json(['success' => true, 'data' => $invoices]); } catch (Throwable $e) { Response::error($e->getMessage(), 'LIST_ERROR', (int)($e->getCode() ?: 500)); } } public function upload(Request $request): void { try { $action = new UploadInvoiceAction($this->storage, $this->invoiceModel); $invoiceId = $action->execute( $request->getFiles(), (string)$request->input('company_id'), $request->tenantId, $request->user ); Response::json([ 'success' => true, 'data' => ['invoice_id' => $invoiceId], 'message' => 'تم رفع الفاتورة بنجاح وجاري استخراج البيانات بالذكاء الاصطناعي' ], 202); } catch (Throwable $e) { Response::error($e->getMessage(), 'UPLOAD_ERROR', (int)($e->getCode() ?: 500)); } } public function detail(Request $request, string $id): void { try { $action = new GetInvoiceDetailAction(); $invoice = $action->execute($id, $request->tenantId, $request->user); Response::json(['success' => true, 'data' => $invoice]); } catch (Throwable $e) { Response::error($e->getMessage(), 'DETAIL_ERROR', (int)($e->getCode() ?: 500)); } } public function submit(Request $request, string $id): void { try { $action = new SubmitInvoiceAction(); $action->execute($id, $request->tenantId); Response::json(['success' => true, 'message' => 'Invoice submission queued.']); } catch (Throwable $e) { Response::error($e->getMessage(), 'SUBMIT_ERROR', (int)($e->getCode() ?: 500)); } } public function downloadFile(Request $request, string $id): void { try { $action = new DownloadInvoiceFileAction(); $file = $action->execute($id, $request->tenantId, $request->user); header("Content-Type: {$file['mime']}"); header("Content-Disposition: inline; filename=\"{$file['name']}\""); header("Content-Length: " . filesize($file['path'])); readfile($file['path']); exit; } catch (Throwable $e) { Response::error($e->getMessage(), 'DOWNLOAD_ERROR', (int)($e->getCode() ?: 500)); } } }