530 lines
31 KiB
PHP
530 lines
31 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
@include('layouts.shared/title-meta', ['title' => 'Form'])
|
|
@include('layouts.shared/head-css', ['mode' => $mode ?? '', 'demo' => $demo ?? ''])
|
|
<link href="{{ asset('assets/libs/sweetalert2/sweetalert2.min.css') }}" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<div id="pageloader">
|
|
<img src="http://cdnjs.cloudflare.com/ajax/libs/semantic-ui/0.16.1/images/loader-large.gif" alt="processing..." />
|
|
</div>
|
|
|
|
<body class="loading">
|
|
<div class="account-pages">
|
|
<div class="container">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-8 col-lg-6 col-xl-5 p-0">
|
|
<div class="card bg-pattern">
|
|
<div class="card-body p-3 row">
|
|
|
|
@if (Session::has('error'))
|
|
<div class="alert alert-danger">{{ Session::get('error') }}</div>
|
|
<br>
|
|
@endif
|
|
@if (session('success'))
|
|
<div class=" alert alert-success">{{ session('success') }}
|
|
</div>
|
|
<br>
|
|
@endif
|
|
<div class="col-8">
|
|
<h4 class="page-title">{{ $form->title }}</h4>
|
|
</div>
|
|
@if (!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes'))
|
|
<div class="col-4">
|
|
@if ($form->link_type == 'form')
|
|
<a href="/form/history" class="float-end pt-1">View History</a>
|
|
@else
|
|
<a href="{{ url()->previous() }}" class="float-end pt-1">Back</a>
|
|
@endif
|
|
</div>
|
|
@endif
|
|
@if (isset($form->user_info))
|
|
<div class="col-12">
|
|
<h6>Submitted By: {{ $form->user_info->name }}</h6>
|
|
</div>
|
|
@endif
|
|
|
|
|
|
@php
|
|
$history = Formhelper::getMultiformData($form->partition, $form->form_id, $form->user_id);
|
|
$history = $history->data->submissions;
|
|
@endphp
|
|
|
|
<form method="POST" action="/form/submit" id="report-form" enctype="multipart/form-data">
|
|
<input type="hidden" name="form_id" value="{{ $form_id }}">
|
|
@csrf
|
|
@if ($id)
|
|
<input type="hidden" name="id[0]" value="{{ $id }}">
|
|
@endif
|
|
@if (isset($form->manager_can_submit) && $form->manager_can_submit == true)
|
|
<div class="col-md-12 mb-2">
|
|
<label for="field-user_id" class="form-label"> Select User / Territory <span
|
|
class="text-danger">*</span> </label>
|
|
<select class="form-control" id="field-user_id" name="user_id" required>
|
|
<option value=""> -- Select -- </option>
|
|
@foreach ($form->users as $option)
|
|
<option value="{{ $option->value }}"
|
|
hierarchy="{{ $option->hierarchy_id }}"
|
|
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}>
|
|
{{ $option->display }}</option>
|
|
@endforeach
|
|
</select>
|
|
<input type="hidden" id="field-hierarchy_id" name="hierarchy_id"
|
|
value="">
|
|
</div>
|
|
@endif
|
|
|
|
@php
|
|
// Collect all doctor_name options for quick lookup
|
|
$doctor_option_names = [];
|
|
foreach ($questions as $question) {
|
|
if ($question->code == 'doctor_name' && isset($question->options) && is_array($question->options)) {
|
|
foreach ($question->options as $option) {
|
|
if (isset($option->contact->duolin_pedia_rcpa) && $option->contact->duolin_pedia_rcpa == 'Yes') {
|
|
$doctor_option_names[] = $option->display;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Track which submissions have been matched to an option
|
|
$matched_submission_ids = [];
|
|
@endphp
|
|
|
|
{{-- Loop through doctor_name options and show doctor-wrapper for each --}}
|
|
@foreach ($questions as $question)
|
|
@if ($question->code == 'doctor_name' && isset($question->options) && is_array($question->options))
|
|
@foreach ($question->options as $option)
|
|
@if (!isset($option->contact->duolin_pedia_rcpa) || $option->contact->duolin_pedia_rcpa != 'Yes')
|
|
@continue
|
|
@endif
|
|
@php
|
|
// Find a matching submission in $history where doctor_name matches $option->display
|
|
$matched_submission = null;
|
|
foreach ($history as $submission) {
|
|
if (
|
|
isset($submission->formdata->doctor_name) &&
|
|
$submission->formdata->doctor_name == $option->display
|
|
) {
|
|
$matched_submission = $submission;
|
|
$matched_submission_ids[] = $submission->id ?? spl_object_hash($submission);
|
|
break;
|
|
}
|
|
}
|
|
// If matched, fill all question values with that formdata
|
|
if ($matched_submission) {
|
|
foreach ($questions as $q) {
|
|
if (isset($matched_submission->formdata->{$q->code})) {
|
|
$q->value = $matched_submission->formdata->{$q->code};
|
|
}
|
|
}
|
|
} else {
|
|
// If not matched, clear values except for doctor_name and msl_code
|
|
foreach ($questions as $q) {
|
|
if ($q->code != 'doctor_name' && $q->code != 'msl_code') {
|
|
unset($q->value);
|
|
}
|
|
}
|
|
}
|
|
@endphp
|
|
<div class="row doctor-wrapper">
|
|
{{-- If this doctor is in history (i.e., $matched_submission is not null), add hidden id[] --}}
|
|
@if($matched_submission && isset($matched_submission->id))
|
|
<input type="hidden" name="id[]" value="{{ $matched_submission->id }}">
|
|
@endif
|
|
@foreach ($questions as $question)
|
|
@if($question->code == 'doctor_name')
|
|
@php
|
|
$question->type = 'text';
|
|
$question->value = $option->display;
|
|
@endphp
|
|
@endif
|
|
@if($question->code == 'msl_code')
|
|
@php
|
|
$question->value = $option->contact->msl_code;
|
|
@endphp
|
|
@endif
|
|
<div class="col-md-12 mb-2">
|
|
<label for="field-{{ $question->code }}"
|
|
class="form-label">{{ $question->question }}
|
|
{!! $question->required == 'yes' ? '<span class="text-danger">*</span>' : '' !!}
|
|
</label>
|
|
|
|
@switch($question->type)
|
|
@case('hidden')
|
|
<input type="{{ $question->type }}" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}[]"
|
|
value="{{ isset($question->value) ? $question->value : '' }}">
|
|
@break
|
|
|
|
@case('text')
|
|
@case('email')
|
|
|
|
@case('tel')
|
|
@case('date')
|
|
<input type="{{ $question->type }}" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}[]" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}
|
|
value="{{ isset($question->value) ? $question->value : '' }}"
|
|
@if($question->code == 'doctor_name') readonly @endif>
|
|
@break
|
|
|
|
@case('number')
|
|
<input type="{{ $question->type }}" min="0" max="9999999999"
|
|
step="1" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}[]" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}
|
|
value="{{ isset($question->value) ? $question->value : 0 }}">
|
|
@break
|
|
|
|
@endswitch
|
|
</div>
|
|
@endforeach
|
|
</div>
|
|
@endforeach
|
|
@endif
|
|
@endforeach
|
|
|
|
{{-- Now, show doctor-wrapper for submissions whose doctor_name is not in options --}}
|
|
@php
|
|
// Find unmatched submissions
|
|
$unmatched_submissions = [];
|
|
foreach ($history as $submission) {
|
|
$doctor_name = $submission->formdata->doctor_name ?? null;
|
|
// Use submission id or object hash as unique key
|
|
$submission_key = $submission->id ?? spl_object_hash($submission);
|
|
if (
|
|
$doctor_name &&
|
|
!in_array($doctor_name, $doctor_option_names) &&
|
|
!in_array($submission_key, $matched_submission_ids)
|
|
) {
|
|
$unmatched_submissions[] = $submission;
|
|
}
|
|
}
|
|
@endphp
|
|
|
|
@foreach ($unmatched_submissions as $submission)
|
|
@php
|
|
// For this submission, fill question values from formdata
|
|
foreach ($questions as $q) {
|
|
if (isset($submission->formdata->{$q->code})) {
|
|
$q->value = $submission->formdata->{$q->code};
|
|
} else {
|
|
unset($q->value);
|
|
}
|
|
}
|
|
@endphp
|
|
<div class="row doctor-wrapper">
|
|
{{-- Add hidden field for submission id --}}
|
|
<input type="hidden" name="id[]" value="{{ $submission->id ?? '' }}">
|
|
@foreach ($questions as $question)
|
|
@if($question->code == 'doctor_name')
|
|
@php
|
|
$question->type = 'text';
|
|
@endphp
|
|
@endif
|
|
<div class="col-md-12 mb-2">
|
|
<label for="field-{{ $question->code }}"
|
|
class="form-label">{{ $question->question }}
|
|
{!! $question->required == 'yes' ? '<span class="text-danger">*</span>' : '' !!}
|
|
</label>
|
|
|
|
@switch($question->type)
|
|
@case('hidden')
|
|
<input type="{{ $question->type }}" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}[]"
|
|
value="{{ isset($question->value) ? $question->value : '' }}">
|
|
@break
|
|
|
|
@case('text')
|
|
@case('email')
|
|
|
|
@case('tel')
|
|
@case('date')
|
|
<input type="{{ $question->type }}" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}[]" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}
|
|
value="{{ isset($question->value) ? $question->value : '' }}">
|
|
@break
|
|
|
|
@case('number')
|
|
<input type="{{ $question->type }}" min="0" max="9999999999"
|
|
step="1" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}[]" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}
|
|
value="{{ isset($question->value) ? $question->value : 0 }}">
|
|
@break
|
|
|
|
@endswitch
|
|
</div>
|
|
@endforeach
|
|
</div>
|
|
@endforeach
|
|
|
|
<div id="doctor-group-wrapper">
|
|
|
|
</div>
|
|
@if (!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes'))
|
|
<div class="text-center button-list">
|
|
@if (!$id)
|
|
<button class="btn btn-primary" type="button" id="adddoctor-btn"> Add
|
|
Doctor </button>
|
|
@endif
|
|
<button class="btn btn-primary" type="submit" id="submit-btn"> Submit </button>
|
|
</div>
|
|
@endif
|
|
</form>
|
|
|
|
</div> <!-- end card-body -->
|
|
</div>
|
|
<!-- end card -->
|
|
|
|
<!-- end row -->
|
|
|
|
</div> <!-- end col -->
|
|
</div>
|
|
<!-- end row -->
|
|
</div>
|
|
<!-- end container -->
|
|
</div>
|
|
<!-- end page -->
|
|
<style type="text/css">
|
|
#pageloader {
|
|
background: rgba(255, 255, 255, 0.8);
|
|
display: none;
|
|
height: 100%;
|
|
position: fixed;
|
|
width: 100%;
|
|
z-index: 9999;
|
|
}
|
|
|
|
#pageloader img {
|
|
left: 50%;
|
|
margin-left: -32px;
|
|
margin-top: -32px;
|
|
position: absolute;
|
|
top: 50%;
|
|
}
|
|
|
|
.doctor-wrapper {
|
|
border: 1px solid #ccc;
|
|
padding: 20px;
|
|
border-radius: 10px;
|
|
margin-bottom: 20px;
|
|
}
|
|
</style>
|
|
@include('layouts.shared/footer-script')
|
|
<script src="{{ asset('assets/libs/sweetalert2/sweetalert2.min.js') }}"></script>
|
|
<script type="text/javascript">
|
|
jQuery(document).ready(function($) {
|
|
|
|
var doctor_count = 0
|
|
let numberOfSubmission = 0;
|
|
console.log("Number of Submission : ", numberOfSubmission);
|
|
let empty_doctor = `<div class="row doctor-wrapper">
|
|
@foreach ($questions as $question)
|
|
@if($question->code == 'doctor_name')
|
|
@php
|
|
$question->type = 'text';
|
|
@endphp
|
|
@endif
|
|
<div class="col-md-12 mb-2">
|
|
<label for="field-{{ $question->code }}"
|
|
class="form-label">{{ $question->question }}
|
|
{!! $question->required == 'yes' ? '<span class="text-danger">*</span>' : '' !!}
|
|
</label>
|
|
|
|
@switch($question->type)
|
|
@case('hidden')
|
|
<input type="{{ $question->type }}" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}[]"
|
|
value="">
|
|
@break
|
|
|
|
@case('text')
|
|
@case('email')
|
|
|
|
@case('tel')
|
|
@case('date')
|
|
<input type="{{ $question->type }}" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}[]" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}
|
|
value="">
|
|
@break
|
|
|
|
@case('number')
|
|
<input type="{{ $question->type }}" min="0" max="9999999999"
|
|
step="1" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}[]" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}
|
|
value="{{ isset($question->value) ? $question->value : 0 }}">
|
|
@break
|
|
|
|
@endswitch
|
|
</div>
|
|
@endforeach
|
|
</div>`;
|
|
|
|
|
|
|
|
$('#adddoctor-btn').click(function() {
|
|
let doctorName = $('#field-contact_id').html();
|
|
console.log("Doctor Name : ", doctorName);
|
|
doctor_count++;
|
|
numberOfSubmission = numberOfSubmission + 1;
|
|
console.log("Number of Submission : ", numberOfSubmission);
|
|
|
|
let empty_doctor = `<div class="row doctor-wrapper">
|
|
@foreach ($questions as $question)
|
|
@if($question->code == 'doctor_name')
|
|
@php
|
|
$question->type = 'text';
|
|
@endphp
|
|
@endif
|
|
<div class="col-md-12 mb-2">
|
|
<label for="field-{{ $question->code }}"
|
|
class="form-label">{{ $question->question }}
|
|
{!! $question->required == 'yes' ? '<span class="text-danger">*</span>' : '' !!}
|
|
</label>
|
|
|
|
@switch($question->type)
|
|
@case('hidden')
|
|
<input type="{{ $question->type }}" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}[]"
|
|
value="">
|
|
@break
|
|
|
|
@case('text')
|
|
@case('email')
|
|
|
|
@case('tel')
|
|
@case('date')
|
|
<input type="{{ $question->type }}" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}[]" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}
|
|
value="">
|
|
@break
|
|
|
|
@case('number')
|
|
<input type="{{ $question->type }}" min="0" max="9999999999"
|
|
step="1" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}[]" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}
|
|
value="{{ isset($question->value) ? $question->value : 0 }}">
|
|
@break
|
|
|
|
@endswitch
|
|
</div>
|
|
@endforeach
|
|
</div>`;
|
|
|
|
|
|
$('#doctor-group-wrapper').append(empty_doctor)
|
|
|
|
if (numberOfSubmission > 14) {
|
|
$('#adddoctor-btn').hide();
|
|
} else {
|
|
$('#adddoctor-btn').show();
|
|
}
|
|
|
|
|
|
$('.btn-remove').unbind();
|
|
$('.btn-remove').click(function() {
|
|
$(this).closest('.doctor-wrapper').remove()
|
|
})
|
|
|
|
})
|
|
|
|
$('#field-user_id').change(function() {
|
|
$("#pageloader").fadeIn();
|
|
let hierarchy = $('option:selected', this).attr('hierarchy');
|
|
$('#field-hierarchy_id').val(hierarchy)
|
|
event.preventDefault();
|
|
$.ajax({
|
|
type: "GET",
|
|
url: '/form/getdoctorlist?partition={{ $form->partition }}&hierarchy=' +
|
|
hierarchy,
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(data) {
|
|
$("#pageloader").fadeOut();
|
|
$('#doctor-group-wrapper').html('')
|
|
// $('#field-contact_id').append($("<option></option>").attr("value", '')
|
|
// .text('-- Select --'));
|
|
for (let itm of data) {
|
|
// Only include doctors where duolin_pedia_rcpa == 'Yes'
|
|
if (!itm.contact || itm.contact.duolin_pedia_rcpa !== 'Yes') {
|
|
continue;
|
|
}
|
|
|
|
$('#field-contact_id').append($("<option></option>").attr("value",
|
|
itm.value).text(itm.display).attr("msl_code", itm
|
|
.contact.msl_code));
|
|
|
|
// Add empty_doctor to #doctor-group-wrapper with doctor name and msl_code
|
|
let doctorHtml = empty_doctor;
|
|
|
|
// Replace the doctor_name input value (assumes input with id="field-doctor_name")
|
|
doctorHtml = doctorHtml.replace(
|
|
/(<input[^>]*id="field-doctor_name"[^>]*value=")[^"]*(")/,
|
|
'$1' + itm.display + '$2'
|
|
);
|
|
|
|
// Replace the msl_code input value (assumes input with id="field-msl_code")
|
|
doctorHtml = doctorHtml.replace(
|
|
/(<input[^>]*id="field-msl_code"[^>]*value=")[^"]*(")/,
|
|
'$1' + itm.contact.msl_code + '$2'
|
|
);
|
|
|
|
$('#doctor-group-wrapper').append(doctorHtml);
|
|
}
|
|
|
|
// $('#field-contact_id').change(function() {
|
|
// $('#field-msl_code').val($('option:selected', this).attr(
|
|
// 'msl_code'))
|
|
// })
|
|
|
|
|
|
},
|
|
});
|
|
|
|
console.log(hierarchy)
|
|
})
|
|
|
|
|
|
$('#report-form').on('submit', function(event) {
|
|
event.preventDefault();
|
|
$("#pageloader").fadeIn();
|
|
$.ajax({
|
|
type: "POST",
|
|
url: '/form/ajaxsubmitmultiple',
|
|
data: new FormData($('#report-form')[0]),
|
|
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'
|
|
})
|
|
$('#report-form').trigger("reset");
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Data not submitted',
|
|
text: 'Something went wrong, please try again after some time!'
|
|
})
|
|
}
|
|
},
|
|
});
|
|
});
|
|
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|