diff --git a/resources/views/form/rapport-team3/1790230856-a5ff58a6-d509-4ac0-9b18-6d366a74965e-history.blade.php b/resources/views/form/rapport-team3/1790230856-a5ff58a6-d509-4ac0-9b18-6d366a74965e-history.blade.php index 88bfd49f..d685f332 100644 --- a/resources/views/form/rapport-team3/1790230856-a5ff58a6-d509-4ac0-9b18-6d366a74965e-history.blade.php +++ b/resources/views/form/rapport-team3/1790230856-a5ff58a6-d509-4ac0-9b18-6d366a74965e-history.blade.php @@ -92,9 +92,7 @@ @endforeach - @if(strtolower((string) ($submission->workflow_status ?? '')) === 'rejected') Edit / Re-upload - @endif @empty 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)
@csrf - @if($id) + @if($singleEdit) @endif @if(isset($form->manager_can_submit) && $form->manager_can_submit == true) @@ -114,6 +195,11 @@ ["record_date","select_rxber_type"] ) ) @continue; @endif + @php + $topValue = array_key_exists($question->code, $topValues) + ? $topValues[$question->code] + : (isset($question->value) ? $question->value : ''); + @endphp
+ @endforeach
- @if(!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != - 'yes' ) ) + @if(!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes'))
- @if(!$id) + @if(!$singleEdit && !$lockDoctorBlocks) @endif
@endif
- @elseif(!$id) -

You have submitted 10 doctors

- @endif @@ -341,7 +432,7 @@ $('#field-speciality').val($(this).find(":selected").attr("speciality")); }) - $('#field-msl_code,#field-speciality').attr('readonly',true); + $('[id^="field-msl_code"],[id^="field-speciality"]').attr('readonly',true); function initializeSelect2() { @@ -531,16 +622,18 @@ - var doctor_count = 0 - let numberOfSubmission=0; - console.log("Number of Submission : ",numberOfSubmission); + var doctor_count = {{ max(count($doctorRows) - 1, 0) }}; + let numberOfSubmission = {{ max(count($doctorRows) - 1, 0) }}; + var singleRecordEdit = {{ $singleEdit ? 'true' : 'false' }}; + var submitting = false; $('#adddoctor-btn').click(function() { - let doctorName=$('#field-contact_id').html(); + let doctorName = ($('#field-contact_id').html() || '') + .replace(/\sselected(?:=(?:"selected"|'selected'|selected))?/gi, '') + .replace(/\sdisabled(?:=(?:"disabled"|'disabled'|disabled))?/gi, '') + .replace(/ \(Already Added\)/g, ''); - console.log("Doctor Name : ",doctorName); doctor_count++; numberOfSubmission=numberOfSubmission+1; - console.log("Number of Submission : ",numberOfSubmission); let empty_doctor = ` @@ -608,8 +701,12 @@ $('#doctor-group-wrapper').append(empty_doctor) - - $('#field-contact_id-'+doctor_count).select2({ + + var $addedContact = $('#field-contact_id-' + doctor_count); + $addedContact.find('option').prop('selected', false); + $addedContact.val(''); + + $addedContact.select2({ width: '100%', placeholder: '-- Select Doctor --' @@ -652,11 +749,10 @@ }); $(this).closest('.doctor-wrapper').remove(); numberOfSubmission--; - doctor_count-- preventDuplicateDoctors(); - console.log("New Number of Submission : ",numberOfSubmission); - console.log("Number of doctors : ",doctor_count); - $('#adddoctor-btn').show(); + if ($('.doctor-wrapper').length < 10) { + $('#adddoctor-btn').show(); + } }) @@ -704,17 +800,40 @@ $('#report-form').on('submit', function(event) { event.preventDefault(); - - let isEditMode = $('input[name="id[0]"]').length > 0 && $('input[name="id[0]"]').val() !== ''; - - if (!isEditMode && numberOfSubmission != 9) { - alert(`You must submit 10 Doctors , Current Doctors : ${numberOfSubmission+1}`); - return; + if (submitting) { + return; } - + if (!singleRecordEdit) { + let doctorIds = []; + $('select[id^="field-contact_id"]').each(function() { + let value = $(this).val(); + if (value) { + doctorIds.push(value); + } + }); + if (doctorIds.length !== 10 || new Set(doctorIds).size !== 10) { + Swal.fire({ + icon: 'warning', + title: '10 doctors required', + text: 'Select 10 different doctors before submitting.' + }); + return; + } + } - $("#pageloader").fadeIn(); + submitting = true; + $('#submit-btn, #adddoctor-btn').prop('disabled', true); + $('#pageloader').show(); + $('#report-form .doctor-wrapper').each(function(index) { + $(this).find('[name]').each(function() { + let name = $(this).attr('name') || ''; + let match = name.match(/^(.*)\[(\d+)\]$/); + if (match) { + $(this).attr('name', match[1] + '[' + index + ']'); + } + }); + }); $.ajax({ type: "POST", url: '/form/ajaxsubmitmultiple', @@ -722,41 +841,21 @@ processData: false, contentType: false, success: function(data) { - $("#pageloader").fadeOut(); - if (data.status == 'success') { Swal.fire({ title: 'Great!', text: 'Your data is successfully submitted!', icon: 'success' }).then(() => { - location.reload(); // 🔥 page refresh here - }); - $('#report-form').trigger("reset"); + location.reload(); + }); } else { - Swal.fire({ - icon: 'error', - title: 'Data not submitted', - text: 'Something went wrong, please try again after some time!' - }) + location.reload(); } }, - - error: function(xhr, status, error) { - - $("#pageloader").fadeOut(); - - console.log("HTTP Status:", xhr.status); - console.log("Status:", status); - console.log("Error:", error); - console.log("Response:", xhr.responseText); - - Swal.fire({ - icon: 'error', - title: 'Server Error', - text: xhr.responseJSON?.message || error - }); - } + error: function() { + location.reload(); + } }); }); diff --git a/resources/views/layouts/shared/left-sidebar.blade.php b/resources/views/layouts/shared/left-sidebar.blade.php index 4a6d8ff4..ff5f6896 100644 --- a/resources/views/layouts/shared/left-sidebar.blade.php +++ b/resources/views/layouts/shared/left-sidebar.blade.php @@ -207,6 +207,23 @@ @endif + @if(\App\Helpers\HorizonReportAccess::canView()) +
  • + + + Custom Reports + + +
    + +
    +
  • + @endif + @if(auth()->user()->domain == 'iva')
  • diff --git a/routes/web.php b/routes/web.php index 197bdc2d..51fd428c 100755 --- a/routes/web.php +++ b/routes/web.php @@ -102,6 +102,7 @@ use App\Http\Controllers\NebmitratmmappingController; use App\Http\Controllers\DepotwithtmmappingController; use App\Http\Controllers\GennovadcReportController; +use App\Http\Controllers\HorizonreportController; use App\Http\Controllers\IvareportController; use App\Http\Controllers\ZenovaReportController; @@ -271,6 +272,7 @@ $modules = ['user' => UserController::class, 'coachingtooldashboard' => CoachingtoolDashboard::class, 'gennovadcreport' => GennovadcReportController::class, 'zenovareport' => ZenovaReportController::class, + 'horizonreport' => HorizonreportController::class, 'ivareport' => IvareportController::class, 'formhook' => FormhookController::class,