diff --git a/resources/views/form/rapport-team3/1793772514-e8e67206-8dba-471e-b08f-deece5d36d11.blade.php b/resources/views/form/rapport-team3/1793772514-e8e67206-8dba-471e-b08f-deece5d36d11.blade.php index 85d48f00..cbd86ba4 100644 --- a/resources/views/form/rapport-team3/1793772514-e8e67206-8dba-471e-b08f-deece5d36d11.blade.php +++ b/resources/views/form/rapport-team3/1793772514-e8e67206-8dba-471e-b08f-deece5d36d11.blade.php @@ -85,16 +85,97 @@ @endif @php - $submissions = Formhelper::getMultiformData( $form->partition, $form_id, $form->user_id); - $submissions = $submissions->data->submissions; - + $history = Formhelper::getMultiformData($form->partition, $form_id, $form->user_id); + $submissions = []; + if (isset($history->data->submissions)) { + $rawSubmissions = $history->data->submissions; + if (is_array($rawSubmissions)) { + $submissions = $rawSubmissions; + } elseif ($rawSubmissions instanceof \Traversable) { + $submissions = iterator_to_array($rawSubmissions); + } + } + $singleEdit = !empty($id); + $normalizeDate = function ($value) { + $value = trim((string) $value); + if ($value === '') { + return ''; + } + if (preg_match('/^\d{4}-\d{2}-\d{2}/', $value)) { + return substr($value, 0, 10); + } + if (ctype_digit($value)) { + $timestamp = strlen($value) > 10 ? (int) ($value / 1000) : (int) $value; + return date('Y-m-d', $timestamp); + } + return $value; + }; + $doctorContactId = function ($row) { + if (!$row || !isset($row->formdata)) { + return ''; + } + if (!empty($row->formdata->cont_id)) { + return trim((string) $row->formdata->cont_id); + } + $contactId = $row->formdata->contact_id ?? ''; + if (is_array($contactId)) { + $contactId = reset($contactId); + } + return trim((string) $contactId); + }; + + $doctorRows = []; + if (!$singleEdit) { + $seenDoctors = []; + foreach ($submissions as $submission) { + if (is_array($submission)) { + $submission = json_decode(json_encode($submission)); + } + if (empty($submission->id)) { + continue; + } + $contactKey = $doctorContactId($submission); + if ($contactKey === '' || isset($seenDoctors[$contactKey])) { + continue; + } + $seenDoctors[$contactKey] = true; + $doctorRows[] = $submission; + if (count($doctorRows) >= 10) { + break; + } + } + } + if (count($doctorRows) === 0) { + $doctorRows = [null]; + } + $lockDoctorBlocks = !$singleEdit && $doctorRows[0] !== null && count($doctorRows) >= 10; + + $topValues = []; + if (!$singleEdit && $doctorRows[0] !== null && isset($doctorRows[0]->formdata)) { + $firstForm = $doctorRows[0]->formdata; + foreach (['record_date', 'select_rxber_type'] as $sharedCode) { + if (!isset($firstForm->{$sharedCode})) { + continue; + } + $shared = $firstForm->{$sharedCode}; + if (is_array($shared)) { + $shared = reset($shared); + } + if (is_object($shared)) { + continue; + } + if ($sharedCode === 'record_date') { + $shared = $normalizeDate($shared); + } + $topValues[$sharedCode] = $shared; + } + } @endphp - @if(count($submissions)===0 || $id)
- @elseif(!$id) -