Team4 Changes
This commit is contained in:
parent
9eb935aac8
commit
40ffb04007
|
|
@ -45,6 +45,9 @@
|
||||||
|
|
||||||
@php
|
@php
|
||||||
$history = Formhelper::getMultiformData($form->partition, $form->form_id, $form->user_id);
|
$history = Formhelper::getMultiformData($form->partition, $form->form_id, $form->user_id);
|
||||||
|
/* echo "<pre>";
|
||||||
|
print_r($history->data->submissions[0]);
|
||||||
|
echo "</pre>"; */
|
||||||
@endphp
|
@endphp
|
||||||
|
|
||||||
<div class="col-12" id="table-wrapper">
|
<div class="col-12" id="table-wrapper">
|
||||||
|
|
@ -1004,7 +1007,7 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
<script>
|
{{-- <script>
|
||||||
|
|
||||||
// Existing submissions
|
// Existing submissions
|
||||||
let submissions = @json($history->data->submissions);
|
let submissions = @json($history->data->submissions);
|
||||||
|
|
@ -1089,8 +1092,146 @@
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script> --}}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
|
||||||
|
let submissions = @json($history->data->submissions);
|
||||||
|
|
||||||
|
function normalizeText(text) {
|
||||||
|
return text
|
||||||
|
.replace(/\s+/g, ' ')
|
||||||
|
.trim()
|
||||||
|
.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$('#field-plan_date').val()) {
|
||||||
|
|
||||||
|
let today = new Date();
|
||||||
|
|
||||||
|
let yyyy = today.getFullYear();
|
||||||
|
let mm = String(today.getMonth() + 1).padStart(2, '0');
|
||||||
|
let dd = String(today.getDate()).padStart(2, '0');
|
||||||
|
|
||||||
|
$('#field-plan_date').val(`${yyyy}-${mm}-${dd}`);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#field-plan_date').on('change', function () {
|
||||||
|
markMonthlyAddedDoctors();
|
||||||
|
let selectedOption = $('#field-contact_id').find(':selected');
|
||||||
|
|
||||||
|
// if now disabled => deselect
|
||||||
|
if (selectedOption.prop('disabled')) {
|
||||||
|
|
||||||
|
alert('Selected doctor already planned for this month');
|
||||||
|
|
||||||
|
$('#field-contact_id').val('').trigger('change');
|
||||||
|
|
||||||
|
$('#field-speciality').val('');
|
||||||
|
$('#field-msl_code').val('');
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
function markMonthlyAddedDoctors() {
|
||||||
|
|
||||||
|
/* let today = new Date();
|
||||||
|
|
||||||
|
let currentMonth = today.getMonth();
|
||||||
|
let currentYear = today.getFullYear(); */
|
||||||
|
|
||||||
|
let selectedDate = $('#field-plan_date').val();
|
||||||
|
|
||||||
|
if (!selectedDate) return;
|
||||||
|
|
||||||
|
let selected = new Date(selectedDate);
|
||||||
|
|
||||||
|
let currentMonth = selected.getMonth();
|
||||||
|
let currentYear = selected.getFullYear();
|
||||||
|
|
||||||
|
let addedDoctors = [];
|
||||||
|
|
||||||
|
submissions.forEach(function (submission) {
|
||||||
|
|
||||||
|
let doctorName = submission.formdata?.contact_id ?? '';
|
||||||
|
let planDate = submission.formdata?.plan_date ?? '';
|
||||||
|
|
||||||
|
if (!doctorName || !planDate) return;
|
||||||
|
|
||||||
|
let existingDate = new Date(planDate);
|
||||||
|
|
||||||
|
if (
|
||||||
|
existingDate.getMonth() === currentMonth &&
|
||||||
|
existingDate.getFullYear() === currentYear
|
||||||
|
) {
|
||||||
|
|
||||||
|
addedDoctors.push(
|
||||||
|
normalizeText(doctorName)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("Added Doctors:", addedDoctors);
|
||||||
|
|
||||||
|
$('#field-contact_id option').each(function () {
|
||||||
|
|
||||||
|
// Original option text
|
||||||
|
let optionText = $(this).text();
|
||||||
|
|
||||||
|
// Remove old label if already exists
|
||||||
|
optionText = optionText
|
||||||
|
.replace('(Already Added)', '')
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
// Reset first
|
||||||
|
$(this).text(optionText);
|
||||||
|
$(this).prop('disabled', false);
|
||||||
|
$(this).removeAttr('data-added');
|
||||||
|
|
||||||
|
// Skip empty option
|
||||||
|
if ($(this).val() === '') return;
|
||||||
|
|
||||||
|
let normalizedOption = normalizeText(optionText);
|
||||||
|
|
||||||
|
// Compare names
|
||||||
|
if (addedDoctors.includes(normalizedOption)) {
|
||||||
|
|
||||||
|
$(this).text(optionText + ' (Already Added)');
|
||||||
|
$(this).prop('disabled', true);
|
||||||
|
$(this).attr('data-added', 'yes');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run on page load
|
||||||
|
markMonthlyAddedDoctors();
|
||||||
|
|
||||||
|
// Extra protection
|
||||||
|
$('#field-contact_id').on('change', function () {
|
||||||
|
|
||||||
|
let selected = $(this).find(':selected');
|
||||||
|
|
||||||
|
if (selected.attr('data-added') === 'yes') {
|
||||||
|
|
||||||
|
alert('Doctor already planned for this month');
|
||||||
|
|
||||||
|
$(this).val('');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -308,11 +308,11 @@ echo "</div>";
|
||||||
@break
|
@break
|
||||||
|
|
||||||
@case('dropdown')
|
@case('dropdown')
|
||||||
<select class="form-control" id="field-{{ $question->code }}" name="{{ $question->code }}" {{ $question->required == 'yes' ? 'required' : '' }}>
|
<select class="form-control" id="field-{{ $question->code }}" name="{{ $question->code }}" {{ $question->required == 'yes' ? 'required' : '' }}>
|
||||||
<option value=""> -- Select -- </option>
|
<option value=""> -- Select -- </option>
|
||||||
@if ($question->code == 'contact_id')
|
@if ($question->code == 'contact_id')
|
||||||
@foreach ($question->options as $option)
|
@foreach ($question->options as $option)
|
||||||
@if ($option->contact->type == 'doctor')
|
@if ($option->contact->type == 'doctor' && strtolower(trim($option->contact->speciality ?? '')) != 'paediatrician')
|
||||||
<option value="{{ $option->value }}"
|
<option value="{{ $option->value }}"
|
||||||
msl_code="{{isset($option->contact->legacy_code)?$option->contact->legacy_code:''}}"
|
msl_code="{{isset($option->contact->legacy_code)?$option->contact->legacy_code:''}}"
|
||||||
speciality="{{isset($option->contact->speciality)?$option->contact->speciality:''}}" {{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}
|
speciality="{{isset($option->contact->speciality)?$option->contact->speciality:''}}" {{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}
|
||||||
|
|
@ -1264,7 +1264,7 @@ $(document).ready(function () {
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
{{-- <script>
|
||||||
|
|
||||||
// Existing submissions
|
// Existing submissions
|
||||||
let submissions = @json($history->data->submissions);
|
let submissions = @json($history->data->submissions);
|
||||||
|
|
@ -1349,6 +1349,145 @@ $(document).ready(function () {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
</script> --}}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
|
||||||
|
let submissions = @json($history->data->submissions);
|
||||||
|
|
||||||
|
function normalizeText(text) {
|
||||||
|
return text
|
||||||
|
.replace(/\s+/g, ' ')
|
||||||
|
.trim()
|
||||||
|
.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$('#field-plan_date').val()) {
|
||||||
|
|
||||||
|
let today = new Date();
|
||||||
|
|
||||||
|
let yyyy = today.getFullYear();
|
||||||
|
let mm = String(today.getMonth() + 1).padStart(2, '0');
|
||||||
|
let dd = String(today.getDate()).padStart(2, '0');
|
||||||
|
|
||||||
|
$('#field-plan_date').val(`${yyyy}-${mm}-${dd}`);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#field-plan_date').on('change', function () {
|
||||||
|
markMonthlyAddedDoctors();
|
||||||
|
let selectedOption = $('#field-contact_id').find(':selected');
|
||||||
|
|
||||||
|
// if now disabled => deselect
|
||||||
|
if (selectedOption.prop('disabled')) {
|
||||||
|
|
||||||
|
alert('Selected doctor already planned for this month');
|
||||||
|
|
||||||
|
$('#field-contact_id').val('').trigger('change');
|
||||||
|
|
||||||
|
$('#field-speciality').val('');
|
||||||
|
$('#field-msl_code').val('');
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
function markMonthlyAddedDoctors() {
|
||||||
|
|
||||||
|
/* let today = new Date();
|
||||||
|
|
||||||
|
let currentMonth = today.getMonth();
|
||||||
|
let currentYear = today.getFullYear(); */
|
||||||
|
|
||||||
|
let selectedDate = $('#field-plan_date').val();
|
||||||
|
|
||||||
|
if (!selectedDate) return;
|
||||||
|
|
||||||
|
let selected = new Date(selectedDate);
|
||||||
|
|
||||||
|
let currentMonth = selected.getMonth();
|
||||||
|
let currentYear = selected.getFullYear();
|
||||||
|
|
||||||
|
let addedDoctors = [];
|
||||||
|
|
||||||
|
submissions.forEach(function (submission) {
|
||||||
|
|
||||||
|
let doctorName = submission.formdata?.contact_id ?? '';
|
||||||
|
let planDate = submission.formdata?.plan_date ?? '';
|
||||||
|
|
||||||
|
if (!doctorName || !planDate) return;
|
||||||
|
|
||||||
|
let existingDate = new Date(planDate);
|
||||||
|
|
||||||
|
if (
|
||||||
|
existingDate.getMonth() === currentMonth &&
|
||||||
|
existingDate.getFullYear() === currentYear
|
||||||
|
) {
|
||||||
|
|
||||||
|
addedDoctors.push(
|
||||||
|
normalizeText(doctorName)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("Added Doctors:", addedDoctors);
|
||||||
|
|
||||||
|
$('#field-contact_id option').each(function () {
|
||||||
|
|
||||||
|
// Original option text
|
||||||
|
let optionText = $(this).text();
|
||||||
|
|
||||||
|
// Remove old label if already exists
|
||||||
|
optionText = optionText
|
||||||
|
.replace('(Already Added)', '')
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
// Reset first
|
||||||
|
$(this).text(optionText);
|
||||||
|
$(this).prop('disabled', false);
|
||||||
|
$(this).removeAttr('data-added');
|
||||||
|
|
||||||
|
// Skip empty option
|
||||||
|
if ($(this).val() === '') return;
|
||||||
|
|
||||||
|
let normalizedOption = normalizeText(optionText);
|
||||||
|
|
||||||
|
// Compare names
|
||||||
|
if (addedDoctors.includes(normalizedOption)) {
|
||||||
|
|
||||||
|
$(this).text(optionText + ' (Already Added)');
|
||||||
|
$(this).prop('disabled', true);
|
||||||
|
$(this).attr('data-added', 'yes');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run on page load
|
||||||
|
markMonthlyAddedDoctors();
|
||||||
|
|
||||||
|
// Extra protection
|
||||||
|
$('#field-contact_id').on('change', function () {
|
||||||
|
|
||||||
|
let selected = $(this).find(':selected');
|
||||||
|
|
||||||
|
if (selected.attr('data-added') === 'yes') {
|
||||||
|
|
||||||
|
alert('Doctor already planned for this month');
|
||||||
|
|
||||||
|
$(this).val('');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue