990 lines
53 KiB
PHP
990 lines
53 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
|
|
$submissions = Formhelper::getMultiformData($form->partition, $form_id, $form->user_id);
|
|
$submissions = $submissions->data->submissions ?? 0;
|
|
// echo "<pre>"; print_r($submissions); exit;
|
|
$alreadySubmittedDoctors = [];
|
|
@endphp
|
|
|
|
@foreach (collect($submissions)->sortByDesc('formdata.record_date') as $sub)
|
|
<button type="button" class="btn btn-xs btn-info edit-btn"
|
|
plan_details="{{ json_encode($sub->formdata) }}" style="display: none">
|
|
<i class="mdi mdi-pencil"></i>
|
|
Edit</button>
|
|
@endforeach
|
|
|
|
<div class="col-md-12" id="table-wrapper">
|
|
<div class="card">
|
|
<div class="card-body p-0">
|
|
<div class="table-responsive">
|
|
|
|
<table
|
|
class="table table-striped table-hover table-nowrap table-centered m-0">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<th>#</th>
|
|
<th>Action</th>
|
|
<th>Doctor Name</th>
|
|
<th>MSL Code</th>
|
|
<th>Speciality</th>
|
|
<th>BF Educator Code</th>
|
|
<th>BF Educator Name</th>
|
|
<th>BF MSL Selected</th>
|
|
<th>Monthly MLC Support</th>
|
|
<th>Monthly MLC Competition Support</th>
|
|
</tr>
|
|
</thead>
|
|
|
|
<tbody>
|
|
@forelse($submissions as $key => $sub)
|
|
@php
|
|
$d = $sub->formdata ?? null;
|
|
$alreadySubmittedDoctors[] = $d->contact_id
|
|
@endphp
|
|
|
|
@if ($d)
|
|
<tr>
|
|
<td>{{ $key + 1 }}</td>
|
|
<td>
|
|
@if (strtolower($sub->workflow_status) == 'rejected')
|
|
<button
|
|
class="btn btn-sm btn-primary load-rejected"
|
|
data-sub='@json($sub)'
|
|
data-rejected="{{ $sub->rejected_index ?? 0 }}"
|
|
>
|
|
Edit
|
|
</button>
|
|
@else
|
|
<button
|
|
class="btn btn-sm btn-secondary load-submission"
|
|
data-sub='@json($sub)' style="display: none"
|
|
demo-data="@php print_r($alreadySubmittedDoctors) @endphp">
|
|
View
|
|
</button>
|
|
@endif
|
|
</td>
|
|
|
|
<td>{{ $d->contact_id ?? '-' }}</td>
|
|
<td>{{ $d->msl_code ?? '-' }}</td>
|
|
<td>{{ $d->speciality ?? '-' }}</td>
|
|
<td>{{ $d->bf_educator_emp_code ?? '-' }}</td>
|
|
<td>{{ $d->bf_educator_emp_name ?? '-' }}</td>
|
|
<td>{{ $d->bf_msl_for_same_dr_selected ?? '-' }}</td>
|
|
<td>{{ $d->monthly_mlc_support_in_value ?? 0 }}</td>
|
|
<td>{{ $d->monthly_mlc_competition_support_in_value ?? 0 }}
|
|
</td>
|
|
|
|
|
|
</tr>
|
|
@endif
|
|
@empty
|
|
<tr>
|
|
<td colspan="12" class="text-center text-muted">No
|
|
submissions found</td>
|
|
</tr>
|
|
@endforelse
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<button type="button" id="backToTable"
|
|
class="btn btn-sm btn-secondary float-end mb-2 d-none">
|
|
← Back
|
|
</button>
|
|
|
|
|
|
|
|
|
|
|
|
<form method="POST" action="/form/submit" id="report-form" enctype="multipart/form-data">
|
|
<input type="hidden" name="form_id" value="{{ $form_id }}">
|
|
@csrf
|
|
|
|
{{-- <input type="hidden" name="id" id="submission-id"> --}}
|
|
|
|
@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 (!in_array($question->code, ['record_date', 'select_month']))
|
|
@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 }}" min="1">
|
|
@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')
|
|
<select class="form-control" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>
|
|
<option value=""> -- 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 == 'doctor_name' ? 'speciality= ' . (isset($option->contact->speciality) ? $option->contact->speciality : '') . ' ' : '' }}
|
|
>
|
|
{{ $option->display }}
|
|
</option>
|
|
@endforeach
|
|
</select>
|
|
@break
|
|
@endswitch
|
|
</div>
|
|
@endforeach
|
|
<div class="doctor-wrapper">
|
|
<h5 class="mb-3">Add Doctor 1</h5>
|
|
@foreach ($questions as $question)
|
|
@if (in_array($question->code, ['record_date', 'select_month']))
|
|
@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 }}[0]"
|
|
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 }}[0]" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}
|
|
value="{{ isset($question->value) ? $question->value : '' }}">
|
|
@break
|
|
|
|
@case('number')
|
|
<input type="{{ $question->type }}" min="1" max="9999999999"
|
|
step="1" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}[0]" 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 }}[0]" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>{{ isset($question->value) ? $question->value : '' }}</textarea>
|
|
@break
|
|
|
|
@case('dropdown')
|
|
<select class="form-control" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}[0]"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>
|
|
<option value=""> -- 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 : '') . ' ' : '' }} --}}
|
|
{!! $question->code == 'contact_id' ? 'speciality=' . json_encode($option->contact->speciality ?? '') : '' !!}
|
|
|
|
>
|
|
{{ $option->display }}
|
|
</option>
|
|
@endforeach
|
|
</select>
|
|
@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 }}[0]" 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
|
|
@endswitch
|
|
</div>
|
|
@endforeach
|
|
</div>
|
|
<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>
|
|
|
|
<form method="POST" action="/form/submit" id="execution-form"
|
|
enctype="multipart/form-data" style="display:none;">
|
|
<input type="hidden" name="form_id" value="{{ $form_id }}">
|
|
@csrf
|
|
<input type="hidden" name="id" value="" id="execution-id">
|
|
|
|
@foreach ($questions as $question)
|
|
<div class="col-md-12 mb-2">
|
|
<label for="execution-{{ $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="execution-{{ $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="execution-{{ $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="1" max="9999999999"
|
|
step="1" id="execution-{{ $question->code }}"
|
|
name="{{ $question->code }}" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}
|
|
value="{{ isset($question->value) ? $question->value : 0 }}">
|
|
@break
|
|
|
|
@case('textarea')
|
|
<textarea id="execution-{{ $question->code }}" name="{{ $question->code }}" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>{{ isset($question->value) ? $question->value : '' }}</textarea>
|
|
@break
|
|
|
|
@case('dropdown')
|
|
<select class="form-control" id="execution-{{ $question->code }}"
|
|
name="{{ $question->code }}"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>
|
|
<option value=""> -- Select -- </option>
|
|
@foreach ($question->options as $option)
|
|
@php
|
|
$currentDoctor = $question->value ?? [];
|
|
@endphp
|
|
<option value="{{ $option->value }}" data-issue="@php print_r($currentDoctor); @endphp"
|
|
{{ 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 : '') . ' ' : '' }} --}}
|
|
{!! $question->code == 'contact_id' ? 'speciality=' . json_encode($option->contact->speciality ?? '') : '' !!}
|
|
|
|
{{ in_array($option->display, $alreadySubmittedDoctors) ? 'disabled' : '' }}
|
|
>
|
|
{{ $option->display }}
|
|
{{ in_array($option->display, $alreadySubmittedDoctors) ? '(Already Selected)' : '' }}
|
|
|
|
</option>
|
|
@endforeach
|
|
</select>
|
|
@break
|
|
@endswitch
|
|
</div>
|
|
@endforeach
|
|
|
|
@if (!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes'))
|
|
<div class="text-center button-list">
|
|
<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>
|
|
const submissions = @json($submissions);
|
|
|
|
function setHiddenId(id) {
|
|
if ($('#execution-id').length === 0) {
|
|
$('#execution-form').append('<input type="hidden" name="id" id="execution-id">');
|
|
}
|
|
$('#execution-id').val(id);
|
|
}
|
|
</script>
|
|
|
|
<script>
|
|
jQuery(document).ready(function($) {
|
|
|
|
let doctor_count = 0;
|
|
const REQUIRED_DOCTORS = 10;
|
|
|
|
function clearHiddenId() {
|
|
$('#execution-id').remove();
|
|
}
|
|
|
|
function getFirstDoctorDropdownHTML() {
|
|
return $('#field-contact_id').html(); // use your main select as template
|
|
}
|
|
|
|
function addDoctor() {
|
|
let doctorName = getFirstDoctorDropdownHTML();
|
|
doctor_count++;
|
|
let index = doctor_count;
|
|
|
|
let html = `<div class="doctor-wrapper border p-3 mb-3 rounded" data-index="${index}"> <h5 class="mb-3">Add Doctor ${index+1}</h5>
|
|
<div class="col-md-12 mb-2">
|
|
<label>Doctor Name <span class="text-danger"></span></label>
|
|
<select class="form-control execution-contact_id" id="execution-contact_id-${index}" name="contact_id[${index}]">${doctorName}</select>
|
|
</div>
|
|
<div class="col-md-12 mb-2"><label>MSL Code <span class="text-danger"></span></label>
|
|
<input type="text" id="execution-msl_code-${index}" name="msl_code[${index}]" class="form-control">
|
|
</div>
|
|
<div class="col-md-12 mb-2"><label>Speciality <span class="text-danger"></span></label>
|
|
<input type="text" id="execution-speciality-${index}" name="speciality[${index}]" class="form-control">
|
|
</div>
|
|
<div class="col-md-12 mb-2"><label>BF Educator EMP Code <span class="text-danger"></span></label>
|
|
<input type="text" id="execution-bf_educator_emp_code-${index}" name="bf_educator_emp_code[${index}]" class="form-control">
|
|
</div>
|
|
<div class="col-md-12 mb-2"><label>BF Educator EMP Name <span class="text-danger"></span></label>
|
|
<input type="text" id="execution-bf_educator_emp_name-${index}" name="bf_educator_emp_name[${index}]" class="form-control">
|
|
</div>
|
|
<div class="col-md-12 mb-2"><label>BF MSL For Same DR Selected <span class="text-danger"></span></label>
|
|
<input type="text" id="execution-bf_msl_for_same_dr_selected-${index}" name="bf_msl_for_same_dr_selected[${index}]" class="form-control">
|
|
</div>
|
|
<div class="col-md-12 mb-2"><label>Monthly MLC Support in Value<span class="text-danger"></span></label>
|
|
<input type="number" min="0" id="execution-monthly_mlc_support_in_value-${index}" name="monthly_mlc_support_in_value[${index}]" class="form-control" value="0">
|
|
</div>
|
|
<div class="col-md-12 mb-2"><label>Monthly MLC Competition Support in Value<span class="text-danger"></span></label>
|
|
<input type="number" min="0" id="execution-monthly_mlc_competition_support_in_value-${index}" name="monthly_mlc_competition_support_in_value[${index}]" class="form-control" value="0">
|
|
</div>
|
|
</div>`;
|
|
|
|
$('#doctor-group-wrapper').append(html);
|
|
|
|
updateDoctorDropdowns();
|
|
}
|
|
|
|
// ===================== Prevent Duplicate Selection =====================
|
|
function updateDoctorDropdowns(currentSubmissionDoctors = []) {
|
|
// collect all selected values
|
|
let selectedDoctors = {};
|
|
$('[id^=field-contact_id], [id^=execution-contact_id]').each(function() {
|
|
let val = $(this).val();
|
|
if (val && val !== '') selectedDoctors[val] = true;
|
|
});
|
|
|
|
// update all dropdowns
|
|
$('[id^=field-contact_id], [id^=execution-contact_id]').each(function() {
|
|
let currentVal = $(this).val();
|
|
|
|
// $(this).find('option').each(function() {
|
|
// let text = $(this).data('original-text') || $(this).text().replace(
|
|
// /\s*\(Already selected\)$/, '');
|
|
// $(this).data('original-text', text);
|
|
|
|
// if ($(this).val() === '') {
|
|
// $(this).prop('disabled', false).text(text);
|
|
// } else if ($(this).val() === currentVal) {
|
|
// $(this).prop('disabled', false).text(text);
|
|
// } else if (selectedDoctors[$(this).val()] && !currentSubmissionDoctors
|
|
// .includes($(this).val())) {
|
|
// $(this).prop('disabled', true).text(`${text} (Already selected)`);
|
|
// } else {
|
|
// $(this).prop('disabled', false).text(text);
|
|
// }
|
|
// });
|
|
$(this).find('option').each(function() {
|
|
|
|
let text = $(this).data('original-text') || $(this).text().replace(/\s*\(Already selected\)$/, '');
|
|
$(this).data('original-text', text);
|
|
|
|
|
|
if ($(this).prop('disabled') && !$(this).data('js-controlled')) {
|
|
return;
|
|
}
|
|
|
|
if ($(this).val() === '') {
|
|
$(this).prop('disabled', false).text(text);
|
|
}
|
|
else if ($(this).val() === currentVal) {
|
|
$(this).prop('disabled', false).text(text);
|
|
}
|
|
else if (selectedDoctors[$(this).val()] && !currentSubmissionDoctors.includes($(this).val())) {
|
|
$(this).prop('disabled', true).text(`${text} (Already selected)`);
|
|
$(this).data('js-controlled', true);
|
|
}
|
|
else {
|
|
$(this).prop('disabled', false).text(text);
|
|
}
|
|
});
|
|
|
|
});
|
|
}
|
|
|
|
// ===================== Auto MSL & Speciality =====================
|
|
$(document).on('change', '[id^=field-contact_id], [id^=execution-contact_id]', function() {
|
|
let index = $(this).attr('id').split('-').pop();
|
|
let selectedOption = $(this).find(':selected');
|
|
let msl = selectedOption.attr('msl_code') || '';
|
|
let speciality = selectedOption.attr('speciality') || '';
|
|
|
|
let prefix = $(this).attr('id').startsWith('field-') ? 'field' : 'execution';
|
|
|
|
$('#' + prefix + '-msl_code' + (index == 'contact_id' ? '' : '-' + index))
|
|
.val(msl)
|
|
.prop('readonly', true);
|
|
|
|
$('#' + prefix + '-speciality' + (index == 'contact_id' ? '' : '-' + index))
|
|
.val(speciality)
|
|
.prop('readonly', true);
|
|
|
|
updateDoctorDropdowns();
|
|
});
|
|
|
|
// ===================== Populate Existing Doctors =====================
|
|
function showAllDoctors(subs) {
|
|
if (!Array.isArray(subs)) subs = Object.values(subs);
|
|
|
|
let currentSubmissionDoctors = []; // store IDs of this submission
|
|
subs.forEach((sub, index) => {
|
|
let data = sub.formdata ?? sub;
|
|
if (index > 0) addDoctor();
|
|
|
|
Object.keys(data).forEach(function(key) {
|
|
let field = (index === 0) ? '#execution-' + key : '#execution-' + key +
|
|
'-' + index;
|
|
if (!$(field).length) return;
|
|
|
|
if (key === 'contact_id') {
|
|
let val = data.cont_id || $(field + " option").filter(function() {
|
|
return $(this).text().trim() === data.contact_id.trim();
|
|
}).val();
|
|
$(field).val(val).trigger('change');
|
|
currentSubmissionDoctors.push(val);
|
|
} else {
|
|
$(field).val(data[key]);
|
|
}
|
|
});
|
|
});
|
|
|
|
doctor_count = subs.length - 1;
|
|
updateDoctorDropdowns(currentSubmissionDoctors);
|
|
}
|
|
|
|
// ===================== Initialize Form =====================
|
|
if (submissions && submissions.length > 0) {
|
|
$('#report-form').hide();
|
|
$('#table-wrapper').show();
|
|
clearHiddenId();
|
|
} else {
|
|
$('#report-form').show();
|
|
$('#table-wrapper').hide();
|
|
for (let i = 1; i < REQUIRED_DOCTORS; i++) addDoctor();
|
|
}
|
|
|
|
$('#execution-msl_code').prop('readonly', true);
|
|
$('#execution-speciality').prop('readonly', true);
|
|
|
|
// ===================== Resubmission / Edit Button =====================
|
|
$(document).on('click', '.load-rejected', function() {
|
|
let submission = $(this).data('sub');
|
|
let rejectedIndex = $(this).data('rejected') ?? 0;
|
|
|
|
let submissionId = submission.id || submission._id || submission.submission_id || '';
|
|
setHiddenId(submissionId);
|
|
|
|
let subs = submission.formdata;
|
|
if (!Array.isArray(subs)) subs = [subs];
|
|
|
|
$('#table-wrapper').hide();
|
|
$('#report-form').hide();
|
|
$('#execution-form').show();
|
|
$('#backToTable').removeClass('d-none');
|
|
|
|
$('#doctor-group-wrapper').html($('#doctor-group-wrapper').children().first().prop(
|
|
'outerHTML'));
|
|
$('#doctor-group-wrapper .doctor-wrapper:first').find('input,select').val('');
|
|
doctor_count = 0;
|
|
|
|
showAllDoctors(subs);
|
|
|
|
console.log(submission.formdata)
|
|
|
|
$('#execution-contact_id option').each(function(){
|
|
console.log($(this))
|
|
if( $(this).attr('value') == submission.formdata.cont_id) {
|
|
$(this).removeAttr('disabled')
|
|
}
|
|
})
|
|
|
|
$('#doctor-group-wrapper input, #doctor-group-wrapper select').prop('readonly', true);
|
|
|
|
let rejectedWrapper = $('#doctor-group-wrapper .doctor-wrapper').eq(rejectedIndex);
|
|
rejectedWrapper.find('input,select').prop('readonly', false);
|
|
|
|
rejectedWrapper.css({
|
|
border: '3px solid red',
|
|
background: '#fff5f5'
|
|
});
|
|
|
|
$('#is_resubmission').val(1);
|
|
|
|
$('html,body').animate({
|
|
scrollTop: rejectedWrapper.offset().top - 80
|
|
}, 500);
|
|
});
|
|
|
|
// ===================== Back Button =====================
|
|
$('#backToTable').on('click', function() {
|
|
$('#report-form').hide();
|
|
$('#execution-form').hide();
|
|
$('#table-wrapper').show();
|
|
$(this).addClass('d-none');
|
|
clearHiddenId();
|
|
});
|
|
|
|
// Initial call for first-time load
|
|
updateDoctorDropdowns();
|
|
|
|
$('#field-contact_id').on('change',function(){
|
|
let name=$('#field-contact_id').val();
|
|
if(name===''){
|
|
$('#field-msl_code,#field-speciality,#field-bf_educator_emp_code,#field-bf_educator_emp_name,#field-bf_msl_for_same_dr_selected,#field-monthly_mlc_support_in_value,#field-monthly_mlc_competition_support_in_value').attr('required',false);
|
|
}
|
|
else{
|
|
$('#field-msl_code,#field-speciality,#field-bf_educator_emp_code,#field-bf_educator_emp_name,#field-bf_msl_for_same_dr_selected,#field-monthly_mlc_support_in_value,#field-monthly_mlc_competition_support_in_value').attr('required',true);
|
|
}
|
|
})
|
|
|
|
let fields = $('#field-contact_id,#field-msl_code, #field-speciality, #field-bf_educator_emp_code, #field-bf_educator_emp_name, #field-bf_msl_for_same_dr_selected, #field-monthly_mlc_support_in_value, #field-monthly_mlc_competition_support_in_value');
|
|
|
|
fields.on('input change', function(){
|
|
|
|
let anyFilled = false;
|
|
|
|
fields.each(function(){
|
|
if($.trim($(this).val()) !== ''){
|
|
anyFilled = true;
|
|
return false; // loop break (performance better)
|
|
}
|
|
});
|
|
|
|
// IMPORTANT: both conditions handled
|
|
fields.prop('required', anyFilled);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('[id^="execution-contact_id-"]').on('change', function () {
|
|
|
|
let index = $(this).attr('id').split('-').pop();
|
|
let value = $(this).val();
|
|
|
|
let fields = getFields(index);
|
|
|
|
$(fields).prop("required", value !== '');
|
|
|
|
});
|
|
|
|
|
|
$(document).on('input change', '[id^="execution-msl_code-"], [id^="execution-speciality-"], [id^="execution-bf_educator_emp_code-"], [id^="execution-bf_educator_emp_name-"], [id^="execution-bf_msl_for_same_dr_selected-"], [id^="execution-monthly_mlc_support_in_value-"], [id^="execution-monthly_mlc_competition_support_in_value-"]', function(){
|
|
|
|
let index = $(this).attr('id').split('-').pop();
|
|
let fields = getFields(index);
|
|
|
|
let anyFilled = false;
|
|
|
|
$(fields).each(function(){
|
|
if($.trim($(this).val()) !== ''){
|
|
anyFilled = true;
|
|
return false; // break loop
|
|
}
|
|
});
|
|
|
|
$(fields).prop('required', anyFilled);
|
|
|
|
});
|
|
|
|
|
|
|
|
function getFields(index){
|
|
return `
|
|
#execution-contact_id-${index},
|
|
#execution-msl_code-${index},
|
|
#execution-speciality-${index},
|
|
#execution-bf_educator_emp_code-${index},
|
|
#execution-bf_educator_emp_name-${index},
|
|
#execution-bf_msl_for_same_dr_selected-${index},
|
|
#execution-monthly_mlc_support_in_value-${index},
|
|
#execution-monthly_mlc_competition_support_in_value-${index}
|
|
`;
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
</script>
|
|
|
|
|
|
|
|
<script>
|
|
jQuery(document).ready(function($) {
|
|
|
|
|
|
$('#field-user_id').change(function() {
|
|
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();
|
|
$('#field-contact_id').html('')
|
|
$('#field-contact_id').append($("<option></option>").attr("value", '')
|
|
.text('-- Select --'));
|
|
for (let itm of data) {
|
|
$('#field-contact_id').append($("<option></option>").attr("value",
|
|
itm.value).text(itm.display).attr("msl_code", itm
|
|
.contact.msl_code));
|
|
}
|
|
|
|
$('#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 successfully submitted!',
|
|
// icon: 'success'
|
|
// })
|
|
// $('#report-form').trigger("reset");
|
|
// window.location.reload();
|
|
// $('#report-form').hide();
|
|
// $('#table-wrapper').show();
|
|
// } else {
|
|
// Swal.fire({
|
|
// icon: 'error',
|
|
// title: 'Data not submitted',
|
|
// text: 'Something went wrong, please try again after some time!'
|
|
// })
|
|
// }
|
|
// },
|
|
// });
|
|
// });
|
|
|
|
|
|
$('#report-form').on('submit', function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
// ✅ STEP 1: Remove Empty Doctor Wrappers
|
|
$('.doctor-wrapper').each(function () {
|
|
|
|
let wrapper = $(this);
|
|
let hasData = false;
|
|
|
|
wrapper.find('input, select').each(function () {
|
|
|
|
let value = $(this).val();
|
|
|
|
if (value && value.trim() !== '' && value !== '0') {
|
|
hasData = true;
|
|
return false; // break loop
|
|
}
|
|
|
|
});
|
|
|
|
if (!hasData) {
|
|
wrapper.remove(); // 🔥 remove empty wrapper
|
|
}
|
|
|
|
});
|
|
|
|
// ✅ STEP 2: Create FormData AFTER cleaning DOM
|
|
let formData = new FormData($('#report-form')[0]);
|
|
|
|
/*
|
|
// Optional Debug
|
|
for (let pair of formData.entries()) {
|
|
console.log(pair[0] + ': ' + pair[1]);
|
|
}
|
|
*/
|
|
|
|
$("#pageloader").fadeIn();
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: '/form/ajaxsubmitmultiple',
|
|
data: formData,
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(data) {
|
|
|
|
$("#pageloader").fadeOut();
|
|
|
|
if (data.status == 'success') {
|
|
|
|
Swal.fire({
|
|
title: 'Great!',
|
|
text: 'Your data successfully submitted!',
|
|
icon: 'success'
|
|
});
|
|
|
|
window.location.reload();
|
|
|
|
} else {
|
|
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Data not submitted',
|
|
text: 'Something went wrong, please try again after some time!'
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
});
|
|
|
|
});
|
|
|
|
|
|
$('#execution-form').on('submit', function(event) {
|
|
event.preventDefault();
|
|
$("#pageloader").fadeIn();
|
|
$.ajax({
|
|
type: "POST",
|
|
url: '/form/ajaxsubmit',
|
|
data: new FormData($('#execution-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'
|
|
})
|
|
$('#execution-form').trigger("reset");
|
|
window.location.reload();
|
|
$('#execution-form').hide();
|
|
$('#table-wrapper').show();
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Data not submitted',
|
|
text: 'Something went wrong, please try again after some time!'
|
|
})
|
|
}
|
|
},
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$('input[name^="bf_educator_emp_name"]').on('input', function() {
|
|
this.value = this.value.replace(/\d/g, '');
|
|
});
|
|
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|