diff --git a/app/Core/Request.php b/app/Core/Request.php index 6c65884..fb82505 100644 --- a/app/Core/Request.php +++ b/app/Core/Request.php @@ -25,8 +25,8 @@ final class Request $this->queryParams = $_GET; $this->files = $_FILES; - $contentType = $this->getHeader('Content-Type'); - if ($contentType && str_contains($contentType, 'application/json')) { + $contentType = $this->getHeader('Content-Type') ?? $_SERVER['CONTENT_TYPE'] ?? ''; + if ($contentType && str_contains(strtolower($contentType), 'application/json')) { $this->body = json_decode(file_get_contents('php://input'), true) ?? []; } else { $this->body = $_POST; diff --git a/app/Modules/Invoices/InvoiceController.php b/app/Modules/Invoices/InvoiceController.php index 2d975b9..5ac7807 100644 --- a/app/Modules/Invoices/InvoiceController.php +++ b/app/Modules/Invoices/InvoiceController.php @@ -16,6 +16,15 @@ final class InvoiceController private readonly FileStorageService $storage ) {} + public function list(Request $request): void + { + $invoices = $this->invoiceModel->findByTenant($request->tenantId); + Response::json([ + 'success' => true, + 'data' => $invoices + ]); + } + public function upload(Request $request): void { $files = $request->getFiles(); diff --git a/app/Modules/Invoices/InvoiceModel.php b/app/Modules/Invoices/InvoiceModel.php index 3d8a436..8dc9208 100644 --- a/app/Modules/Invoices/InvoiceModel.php +++ b/app/Modules/Invoices/InvoiceModel.php @@ -10,6 +10,13 @@ final class InvoiceModel extends BaseModel { protected string $table = 'invoices'; + public function findByTenant(string $tenantId): array + { + $stmt = $this->db()->prepare("SELECT * FROM {$this->table} WHERE tenant_id = ? AND deleted_at IS NULL ORDER BY created_at DESC"); + $stmt->execute([$tenantId]); + return $stmt->fetchAll(); + } + public function findByStatus(string $status, ?string $tenantId = null): array { $sql = "SELECT * FROM {$this->table} WHERE status = ? AND deleted_at IS NULL"; diff --git a/public/shell.php b/public/shell.php index dc1b246..df7a246 100644 --- a/public/shell.php +++ b/public/shell.php @@ -455,10 +455,13 @@ modals.innerHTML = `
-

رفع فاتورة (JSON/XML)

-
+

رفع فاتورة للتدقيق

+ - +
+

اختر ملف الفاتورة (JSON/XML/PDF)

+ +
@@ -471,14 +474,18 @@ document.getElementById('upload-invoice-form').onsubmit = async (e) => { e.preventDefault(); try { - const companyId = document.getElementById('inv-comp-id').value; // Keep as string (UUID) - const payload = JSON.parse(document.getElementById('inv-payload').value); + const companyId = document.getElementById('inv-comp-id').value; + const fileInput = document.getElementById('inv-file'); + + const formData = new FormData(); + formData.append('company_id', companyId); + formData.append('invoice', fileInput.files[0]); const btn = e.target.querySelector('button[type="submit"]'); btn.textContent = 'جاري التحقق...'; btn.disabled = true; - await API.post('/invoices/upload', { company_id: companyId, payload }); + await API.upload('/invoices/upload', formData); document.getElementById('invoice-modal').remove(); renderInvoices(); } catch(err) {