579 lines
26 KiB
PHP
579 lines
26 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>
|
|
|
|
@php
|
|
$data = DB::table('team3_tripleimpact')->where('hierarchy_id', $form->hierarchy_id)->get();
|
|
$history = Formhelper::getMultiformData($form->partition, $form->form_id, $form->user_id);
|
|
$existingCounts = [
|
|
'chest' => 0,
|
|
'pedia' => 0,
|
|
'gp' => 0,
|
|
];
|
|
|
|
if (!empty($history->data->submissions)) {
|
|
foreach ($history->data->submissions as $sub) {
|
|
$spec = strtolower($sub->formdata->speciality ?? '');
|
|
|
|
if ($spec === 'chest') {
|
|
$existingCounts['chest']++;
|
|
}
|
|
if ($spec === 'pedia') {
|
|
$existingCounts['pedia']++;
|
|
}
|
|
if ($spec === 'gp') {
|
|
$existingCounts['gp']++;
|
|
}
|
|
}
|
|
}
|
|
|
|
@endphp
|
|
|
|
<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
|
|
<form method="POST" action="/form/submit" id="report-form" enctype="multipart/form-data">
|
|
<input type="hidden" name="form_id" value="{{ $form_id }}">
|
|
<input type="hidden" name="user_id" value="{{ $form->user_id }}">
|
|
|
|
@csrf
|
|
@php
|
|
$editmode = false;
|
|
@endphp
|
|
@if ($id)
|
|
<input type="hidden" name="id" value="{{ $id }}">
|
|
@php
|
|
$editmode = true;
|
|
@endphp
|
|
@endif
|
|
@if ($id)
|
|
<input type="hidden" name="id" 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
|
|
|
|
|
|
@foreach ($questions as $question)
|
|
@if ($question->code == 'msl_code' && !$editmode)
|
|
@continue;
|
|
@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
|
|
|
|
@case('textarea')
|
|
<textarea id="field-{{ $question->code }}" name="{{ $question->code }}" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>{{ isset($question->value) ? $question->value : '' }}</textarea>
|
|
@break
|
|
|
|
@case('dropdown')
|
|
@if ($question->code == 'contact_id')
|
|
<select class="form-control" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}" disabled
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>
|
|
<option>--Select--</option>
|
|
@foreach ($question->options as $option)
|
|
<option value="{{ $option->value }}"
|
|
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}
|
|
{{ $question->code == 'contact_id' ? 'msl_code= ' . $option->contact->msl_code . ' ' : '' }}
|
|
{{ $question->code == 'contact_id' ? 'speciality= ' . (isset($option->contact->speciality) ? $option->contact->speciality : '') . ' ' : '' }}>
|
|
{{ $option->display }}
|
|
</option>
|
|
@endforeach
|
|
</select>
|
|
@else
|
|
<select class="form-control" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>
|
|
<option>--Select--</option>
|
|
@foreach ($question->options as $option)
|
|
<option value="{{ $option->value }}"
|
|
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}
|
|
{{ $question->code == 'contact_id' ? 'msl_code= ' . $option->contact->msl_code . ' ' : '' }}
|
|
{{ $question->code == 'contact_id' ? 'speciality= ' . (isset($option->contact->speciality) ? $option->contact->speciality : '') . ' ' : '' }}>
|
|
{{ $option->display }}
|
|
</option>
|
|
@endforeach
|
|
</select>
|
|
@endif
|
|
@break
|
|
|
|
@case('checkbox')
|
|
@foreach ($question->options as $option)
|
|
<div class="form-check mb-2 form-check-primary">
|
|
<input class="form-check-input" type="checkbox"
|
|
id="field-{{ $question->code }}-{{ $option->value }}"
|
|
name="{{ $question->code }}[]" value="{{ $option->value }}"
|
|
{{ isset($question->value) && $question->value != '' && in_array($option->value, $question->value) ? 'checked' : '' }}>
|
|
<label class="form-check-label"
|
|
for="field-{{ $question->code }}-{{ $option->value }}">{{ $option->display }}</label>
|
|
</div>
|
|
@endforeach
|
|
@break
|
|
|
|
@case('file')
|
|
@if (!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes'))
|
|
<input type="file" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}" class="form-control" value=""
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>
|
|
@elseif(isset($question->value))
|
|
<img src="{{ $question->value }}" class="img-fluid">
|
|
@endif
|
|
@break
|
|
|
|
@case('multitextbox')
|
|
<div class="row">
|
|
@foreach ($question->options as $option)
|
|
<div class="col-6">{{ $option->display }}</div>
|
|
<div class="col-6 mb-1">
|
|
<input type="number" id="field-{{ $option->value }}"
|
|
name="{{ $option->value }}" class="form-control" required
|
|
value="{{ isset($option->val) ? $option->val : 0 }}">
|
|
</div>
|
|
@endforeach
|
|
</div>
|
|
@break
|
|
|
|
@case('time')
|
|
<input type="time" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}
|
|
value="{{ isset($question->value) ? $question->value : '' }}">
|
|
@break
|
|
@endswitch
|
|
</div>
|
|
@endforeach
|
|
|
|
<div
|
|
class="d-flex flex-column flex-md-row align-items-start align-items-md-center gap-2 mt-2">
|
|
|
|
<button type="button" id="add_row" class="btn btn-primary">
|
|
Add Doctor
|
|
</button>
|
|
|
|
<span id="doctor_limit_info" class="text-muted fw-semibold"></span>
|
|
|
|
</div>
|
|
|
|
<div class="mb-2" id="doctor_msl_wrapper"></div>
|
|
@if (!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes'))
|
|
<div class="text-center d-grid mt-3">
|
|
<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%;
|
|
}
|
|
</style>
|
|
@include('layouts.shared/footer-script')
|
|
<script src="{{ asset('assets/libs/sweetalert2/sweetalert2.min.js') }}"></script>
|
|
|
|
<script>
|
|
let specialityData = @json($data[0]);
|
|
let existingCounts = @json($existingCounts);
|
|
let history = @json($history ?? null);
|
|
</script>
|
|
|
|
<script type="text/javascript">
|
|
jQuery(document).ready(function($) {
|
|
|
|
// =========================
|
|
// HISTORY SETUP
|
|
// =========================
|
|
let submittedMSL = new Set();
|
|
let submittedIDs = new Set();
|
|
|
|
if (history && history.data && history.data.submissions) {
|
|
history.data.submissions.forEach(sub => {
|
|
if (sub.contacts && sub.contacts.length) {
|
|
sub.contacts.forEach(doc => {
|
|
if (doc.msl_code) submittedMSL.add(String(doc.msl_code));
|
|
if (doc.id) submittedIDs.add(String(doc.id));
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
// =========================
|
|
// GLOBAL TRACKING (NEW FIX)
|
|
// =========================
|
|
function getAllSelectedDoctors() {
|
|
let arr = [];
|
|
$('.field-contact').each(function() {
|
|
let v = $(this).val();
|
|
if (v) arr.push(v);
|
|
});
|
|
return arr;
|
|
}
|
|
|
|
function isDuplicate(value) {
|
|
return getAllSelectedDoctors().filter(v => v === value).length > 1;
|
|
}
|
|
|
|
function isAlreadySubmitted(value) {
|
|
return submittedIDs.has(String(value));
|
|
}
|
|
|
|
// =========================
|
|
// USER CHANGE → LOAD DOCTORS
|
|
// =========================
|
|
$('#field-user_id').change(function() {
|
|
|
|
let hierarchy = $('option:selected', this).attr('hierarchy');
|
|
$('#field-hierarchy_id').val(hierarchy);
|
|
|
|
event.preventDefault();
|
|
$("#pageloader").fadeIn();
|
|
|
|
$.ajax({
|
|
type: "GET",
|
|
url: '/form/getdoctorlist?partition={{ $form->partition }}&hierarchy=' + hierarchy,
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(data) {
|
|
|
|
$("#pageloader").fadeOut();
|
|
|
|
$('#field-contact_id').html('');
|
|
$('#field-contact_id').append(
|
|
$("<option></option>").attr("value", '').text('-- Select --')
|
|
);
|
|
|
|
for (let itm of data) {
|
|
|
|
let id = String(itm.value);
|
|
|
|
let isDisabled = isAlreadySubmitted(id);
|
|
|
|
let option = $("<option></option>")
|
|
.attr("value", id)
|
|
.text(itm.display)
|
|
.attr("msl_code", itm.contact.msl_code)
|
|
.attr("speciality", itm.contact.speciality);
|
|
|
|
if (isDisabled) {
|
|
option.prop('disabled', true)
|
|
.text(itm.display + " (Already Submitted)");
|
|
}
|
|
|
|
$('#field-contact_id').append(option);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
// =========================
|
|
// MATERIAL FILTER (UNCHANGED)
|
|
// =========================
|
|
const pediaMaterials = ['Pedia Hight Chart','Pedia Weighing Scale','Examination bedsheet','Torch'];
|
|
const chestMaterials = ['X-ray Screen','BP Appratus Digital','Adult Weighing Scale'];
|
|
const gpMaterials = ['X-ray Screen - H1','Pulse Oximeter - H1','BP Appratus Analog - H1','Torch - H1','Adult Weighing Scale - H1','Sthetoscope - H1'];
|
|
|
|
$('#field-speciality').on('change', function() {
|
|
|
|
let speciality = $(this).val();
|
|
|
|
$('#field-material_name option').each(function() {
|
|
|
|
let text = $(this).text().trim();
|
|
|
|
if (speciality === 'Pedia') {
|
|
$(this).toggle(pediaMaterials.includes(text) || text === '-- Select --');
|
|
} else if (speciality === 'Chest') {
|
|
$(this).toggle(chestMaterials.includes(text) || text === '-- Select --');
|
|
} else if (speciality === 'GP') {
|
|
$(this).toggle(gpMaterials.includes(text) || text === '-- Select --');
|
|
} else {
|
|
$(this).show();
|
|
}
|
|
});
|
|
|
|
$('#field-material_name').val('');
|
|
});
|
|
|
|
$('#field-contact_id').parent().hide();
|
|
$('#field-contact_id').prop('required', false);
|
|
|
|
// =========================
|
|
// DOCTOR CONFIG
|
|
// =========================
|
|
let maxCount = 0;
|
|
let currentCount = 0;
|
|
let batchSize = 5;
|
|
let doctorName = $('#field-contact_id').html();
|
|
|
|
// =========================
|
|
// SPECIALITY LOGIC
|
|
// =========================
|
|
$('#field-speciality').on('change', function() {
|
|
|
|
let selected = $(this).val().toLowerCase();
|
|
|
|
let totalAllowed =
|
|
selected === 'chest' ? specialityData.chest :
|
|
selected === 'pedia' ? specialityData.pedia :
|
|
selected === 'gp' ? specialityData.gp : 0;
|
|
|
|
let alreadyAdded = existingCounts[selected] || 0;
|
|
|
|
maxCount = totalAllowed - alreadyAdded;
|
|
if (maxCount < 0) maxCount = 0;
|
|
|
|
$('#doctor_msl_wrapper').html('');
|
|
currentCount = 0;
|
|
|
|
if (maxCount === 0) {
|
|
$('#submit-btn').prop('disabled', true);
|
|
return;
|
|
}
|
|
|
|
$('#submit-btn').prop('disabled', false);
|
|
|
|
$('#doctor_limit_info')
|
|
.removeClass('text-danger text-success')
|
|
.addClass('text-success')
|
|
.html(`You can add up to ${maxCount} doctors (in multiples of 5).`);
|
|
|
|
addDoctorBatch(5);
|
|
});
|
|
|
|
// =========================
|
|
// ADD DOCTOR BATCH
|
|
// =========================
|
|
function addDoctorBatch(count) {
|
|
|
|
if (maxCount === 0) return;
|
|
|
|
let nextBatch = count;
|
|
|
|
if (currentCount + nextBatch > maxCount) {
|
|
nextBatch = maxCount - currentCount;
|
|
}
|
|
|
|
if (nextBatch <= 0) return;
|
|
|
|
for (let i = 1; i <= nextBatch; i++) {
|
|
|
|
let index = currentCount + i;
|
|
|
|
$('#doctor_msl_wrapper').append(`
|
|
<div class="doctor-row card shadow-sm border-0 mb-3" data-index="${index}">
|
|
<div class="card-body p-3">
|
|
|
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
|
<h6 class="mb-0 fw-semibold text-primary">Doctor ${index}</h6>
|
|
<button type="button" class="btn btn-sm btn-outline-danger remove_row">Remove</button>
|
|
</div>
|
|
|
|
<div class="row g-3">
|
|
<div class="col-md-6">
|
|
<label class="form-label mb-1">Doctor Name</label>
|
|
<select class="form-control field-contact" name="contact_id[]" required>
|
|
${doctorName}
|
|
</select>
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<label class="form-label mb-1">MSL Code</label>
|
|
<input type="text" class="form-control field-msl" name="msl_code[]" readonly required>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
`);
|
|
}
|
|
|
|
currentCount += nextBatch;
|
|
}
|
|
|
|
// =========================
|
|
// ADD BUTTON
|
|
// =========================
|
|
$('#add_row').on('click', function() {
|
|
if (maxCount === 0) return;
|
|
if (currentCount >= maxCount) return;
|
|
addDoctorBatch(batchSize);
|
|
});
|
|
|
|
// =========================
|
|
// REMOVE ROW
|
|
// =========================
|
|
$(document).on('click', '.remove_row', function() {
|
|
$(this).closest('.doctor-row').remove();
|
|
currentCount = Math.max(0, currentCount - 1);
|
|
});
|
|
|
|
// =========================
|
|
// AUTO MSL FILL + DUPLICATE FIX (IMPORTANT CHANGE)
|
|
// =========================
|
|
$(document).on('change', '.field-contact', function() {
|
|
|
|
let val = $(this).val();
|
|
let row = $(this).closest('.doctor-row');
|
|
|
|
// ❌ prevent already submitted doctor
|
|
if (isAlreadySubmitted(val)) {
|
|
$(this).val('');
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Already submitted doctor cannot be selected again'
|
|
});
|
|
return;
|
|
}
|
|
|
|
// ❌ prevent duplicate in current UI
|
|
if (isDuplicate(val)) {
|
|
$(this).val('');
|
|
Swal.fire({
|
|
icon: 'warning',
|
|
title: 'Duplicate Doctor'
|
|
});
|
|
return;
|
|
}
|
|
|
|
let msl = $(this).find(':selected').attr('msl_code');
|
|
row.find('.field-msl').val(msl);
|
|
});
|
|
|
|
// =========================
|
|
// SUBMIT AJAX
|
|
// =========================
|
|
$('#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('Success', 'Submitted!', 'success')
|
|
.then(() => location.reload());
|
|
} else {
|
|
Swal.fire('Error', 'Failed', 'error');
|
|
}
|
|
},
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |