diff --git a/htdocs/app/Services/AstmMessageService.php b/htdocs/app/Services/AstmMessageService.php index 3fae6f29..ae4330bd 100644 --- a/htdocs/app/Services/AstmMessageService.php +++ b/htdocs/app/Services/AstmMessageService.php @@ -650,6 +650,40 @@ class AstmMessageService return null; } + protected function splitBDAstmMessages(string $raw): array + { + // bersihkan karakter kontrol + $clean = preg_replace('/[\x02\x03\x04]/', '', $raw); + + $lines = preg_split("/\r\n|\n|\r/", $clean); + + $messages = []; + $current = []; + + foreach ($lines as $line) { + + // Ketemu H baru → simpan pesan sebelumnya + if (str_starts_with($line, 'H|') && !empty($current)) { + $messages[] = implode("\n", $current); + $current = []; + } + + $current[] = $line; + + // Akhir pesan + if (str_starts_with($line, 'L|')) { + $messages[] = implode("\n", $current); + $current = []; + } + } + + // sisa buffer + if (!empty($current)) { + $messages[] = implode("\n", $current); + } + + return $messages; + } protected function processBDAstmResponse(string $raw, $data): bool { @@ -787,9 +821,12 @@ class AstmMessageService $response = $data->rawdt; if ($data->alat == 'BD Mikro 1'){ if ($data->no_id != ''){ - $result = $this->processBDAstmResponse($response, $data->alat); + $messages = $this->splitBDAstmMessages($data->rawdt); + foreach ($messages as $msg) { + $ok = $this->processBDAstmResponse($msg, $data->alat); + } DataListiner::where('urut', $data->urut)->update([ - 'processed' => $result ? 1 : 9 + 'processed' => $ok ? 1 : 9 ]); Periksa::where('nofoto', $data->no_id)->whereNotIn('status', ['Selesai', 'Arsip', 'Dibatalkan (Arsip)', 'Batal'])->update([ 'status' => 'Data BD di Terima ('.$data->organisme.')',