$event, 'data' => $data, 'company_id' => $company_id, ]); $ch = curl_init(defined('NODE_EMIT_URL') ? NODE_EMIT_URL : 'http://127.0.0.1:3000/emit'); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => $body, CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', 'x-emit-secret: ' . (defined('NODE_EMIT_SECRET') ? NODE_EMIT_SECRET : ''), ], CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 1, // never block PHP CURLOPT_CONNECTTIMEOUT => 1, ]); curl_exec($ch); curl_close($ch); } function gl_posted_payload(string $doc_type, int $id, string $action, array $lines): array { $has_revenue = false; $has_expense = false; foreach ($lines as $line) { $code = (int)($line['account_code'] ?? 0); if ($code >= 4000 && $code < 5000) $has_revenue = true; if ($code >= 5000) $has_expense = true; } return [ 'doc_type' => $doc_type, 'id' => $id, 'action' => $action, 'has_revenue' => $has_revenue, 'has_expense' => $has_expense, ]; }