storage->store($files['invoice'], $tenantId, $companyId); $fileHash = $this->storage->getHash($filePath); $invoiceId = Uuid::uuid4()->toString(); $this->invoiceModel->create([ 'id' => $invoiceId, 'tenant_id' => $tenantId, 'company_id' => $companyId, 'uploaded_by' => $user->user_id ?? null, 'status' => 'uploaded', 'original_file_path' => $filePath, 'original_file_hash' => $fileHash, 'idempotency_key' => bin2hex(random_bytes(16)) ]); QueueService::push('invoice_extraction', [ 'invoice_id' => $invoiceId, 'file_path' => $filePath, 'mime_type' => mime_content_type($filePath) ]); return $invoiceId; } }