1606 lines
86 KiB
PHP
1606 lines
86 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
|
|
// $history = Formhelper::getMultiformData(
|
|
// $form->partition,
|
|
// $form->form_id,
|
|
// $form->user_id,
|
|
// );
|
|
|
|
// $submissions = DB::table('neblogistic')
|
|
// ->where('user_id', $form->user_id)
|
|
// ->orderByDesc('id')
|
|
// ->get();
|
|
|
|
// echo "<pre>"; print_r($submissions); exit;
|
|
@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>
|
|
|
|
{{-- <div class="col-12">
|
|
<div class="alert alert-danger" role="alert">
|
|
Hi kindly fill pending NAP patient data on priority, till the time no new request will be accepted
|
|
</div>
|
|
</div> --}}
|
|
|
|
@if (!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes'))
|
|
<div class="col-4">
|
|
@if ($form->link_type == 'form')
|
|
<button type="button" class="btn btn-primary btn-xs float-end"
|
|
id="add-camp-btn">Add
|
|
Request</button>
|
|
@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,
|
|
// );
|
|
|
|
$submissions = DB::table('neblogistic')
|
|
->where('user_id', $form->user_id)
|
|
->orderByDesc('id')
|
|
->get();
|
|
@endphp
|
|
|
|
@php
|
|
$userdetail = Formhelper::getUserInfoById($form->user_id, $form->partition);
|
|
|
|
// echo "<pre>";
|
|
// print_r($userdetail);
|
|
// echo "</pre>";
|
|
|
|
@endphp
|
|
|
|
<div class="col-12" id="table-wrapper">
|
|
<div class="table-responsive">
|
|
<table class="table table-borderless table-nowrap table-hover table-centered m-0">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<th>Action.</th>
|
|
<th>Status</th>
|
|
<th>MSL Code Of Dr</th>
|
|
<th>Speciality </th>
|
|
<th>Type of Nebuliser</th>
|
|
<th>No of Nebulizer</th>
|
|
<th>Value of the Parcel</th>
|
|
<th>Team</th>
|
|
<th>For what purpose Nebulisers will be used by Dr?</th>
|
|
<th>Dr Name</th>
|
|
<th>Doctor Mobile Number</th>
|
|
<th>Clinic / Hospital / Home Name</th>
|
|
<th>Building Name</th>
|
|
<th>Address line 1</th>
|
|
<th>Address line 2</th>
|
|
{{-- <th>Landmark</th> --}}
|
|
<th>State</th>
|
|
<th>City</th>
|
|
<th>Pin Code</th>
|
|
<th>Upload Request Letter</th>
|
|
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach ($submissions as $sub)
|
|
@php
|
|
//$sub->formdata = $sub;
|
|
// $sub->id = $sub->id;
|
|
@endphp
|
|
<tr>
|
|
<td>
|
|
@if (isset($sub->form_submit_type) && $sub->form_submit_type == 'submit_for_approval')
|
|
@else
|
|
<button type="button" class="btn btn-xs btn-info edit-btn"
|
|
plan_details="{{ json_encode($sub) }}">
|
|
<i class="mdi mdi-pencil"></i>
|
|
Edit
|
|
</button>
|
|
@endif
|
|
|
|
</td>
|
|
<td>{{ isset($sub->status) ? $sub->status : '' }}
|
|
</td>
|
|
|
|
<td>{{ isset($sub->msl_code) ? $sub->msl_code : '' }}
|
|
</td>
|
|
|
|
<td>{{ isset($sub->doctor_speciality) ? $sub->doctor_speciality : '' }}
|
|
</td>
|
|
<td>{{ isset($sub->type_of_nebulizer) ? $sub->type_of_nebulizer : '' }}
|
|
</td>
|
|
<td>{{ isset($sub->no_of_nebulizer) ? $sub->no_of_nebulizer : '' }}
|
|
</td>
|
|
<td>{{ isset($sub->value_of_the_parcel) ? $sub->value_of_the_parcel : '' }}
|
|
</td>
|
|
<td>{{ isset($sub->team) ? $sub->team : '' }}
|
|
</td>
|
|
<td>{{ isset($sub->nebulizer_purpose) ? $sub->nebulizer_purpose : '' }}
|
|
</td>
|
|
<td>{{ isset($sub->doctor_name) ? $sub->doctor_name : '' }}
|
|
</td>
|
|
<td>{{ isset($sub->doctor_phone) ? $sub->doctor_phone : '' }}
|
|
</td>
|
|
<td>{{ isset($sub->clinic_hospital_name) ? $sub->clinic_hospital_name : '' }}
|
|
</td>
|
|
<td>{{ isset($sub->address_building) ? $sub->address_building : '' }}
|
|
</td>
|
|
<td>{{ isset($sub->address_line_1) ? $sub->address_line_1 : '' }}
|
|
</td>
|
|
<td>{{ isset($sub->address_line_2) ? $sub->address_line_2 : '' }}
|
|
</td>
|
|
{{-- <td>{{ isset($sub->landmark) ? $sub->landmark : '' }}
|
|
</td> --}}
|
|
<td>{{ isset($sub->address_state) ? $sub->address_state : '' }}
|
|
</td>
|
|
<td>{{ isset($sub->address_city) ? $sub->address_city : '' }}
|
|
</td>
|
|
<td>{{ isset($sub->address_pin_code) ? $sub->address_pin_code : '' }}
|
|
</td>
|
|
@if (isset($sub->request_letter) && !empty($sub->request_letter))
|
|
@php
|
|
$url = \Illuminate\Support\Str::startsWith($sub->request_letter, ['http://', 'https://']) ? $sub->request_letter : 'https://did94hhhcgq1d.cloudfront.net' . $sub->request_letter;
|
|
@endphp
|
|
<td>
|
|
<a target="_blank"
|
|
href="{{ $url }}"
|
|
download="{{ $url }}"
|
|
class="btn btn-dark btn-xs">
|
|
<i class="mdi mdi-cloud-download me-1"></i> Download
|
|
</a>
|
|
</td>
|
|
@endif
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="field-form-wrapper">
|
|
<div class="row">
|
|
<div class="col-6"></div>
|
|
<div class="col-6">
|
|
<button type="button" class="btn btn-primary btn-xs float-end"
|
|
id="back-btn">Back</button>
|
|
</div>
|
|
</div>
|
|
|
|
<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="status" id="field-status" value="">
|
|
<input type="hidden" name="submission_id" id="field-sub_id" value="">
|
|
<input type="hidden" name="existing_letter" id="field-existing_letter"
|
|
value="">
|
|
|
|
<input type="hidden" name="emp_id" id="field-emp_id"
|
|
value="{{ $userdetail->user_info->emp_employee_code }}">
|
|
<input type="hidden" name="user_id" id="field-user_id"
|
|
value="{{ $form->user_id }}">
|
|
<input type="hidden" name="hierarchy_id" id="field-hierarchy_id"
|
|
value="{{ $form->hierarchy_id }}">
|
|
|
|
<input type="hidden" name="emp_name" id="hidden-field-emp_name"
|
|
value="{{ $userdetail->user_info->emp_name }}" disabled>
|
|
<input type="hidden" name="emp_phone" id="hidden-field-emp_phone"
|
|
value="{{ $userdetail->user_info->emp_phone }}" disabled>
|
|
<input type="hidden" name="emp_email" id="hidden-field-emp_email"
|
|
value="{{ $userdetail->user_info->emp_email }}" disabled>
|
|
|
|
@foreach ($userdetail->manager_info as $row)
|
|
@if ($row->emp_level == 2)
|
|
<input type="hidden" name="abm_name" id="hidden-field-abm_name"
|
|
value="{{ $row->emp_name }}" disabled>
|
|
<input type="hidden" name="abm_email" id="hidden-field-abm_email"
|
|
value="{{ $row->emp_email }}" disabled>
|
|
@endif
|
|
|
|
@if ($row->emp_level == 3)
|
|
<input type="hidden" name="rbm_name" id="hidden-field-rbm_name"
|
|
value="{{ $row->emp_name }}" disabled>
|
|
@endif
|
|
@endforeach
|
|
|
|
<input type="hidden" name="form_submit_type" id="field-form_submit_type"
|
|
value="">
|
|
<input type="hidden" name="geolocation_latitude" id="field-geolocation_latitude"
|
|
value="">
|
|
<input type="hidden" name="geolocation_longitude"
|
|
id="field-geolocation_longitude" value="">
|
|
<input type="hidden" name="geolocation_json" id="field-geolocation_json"
|
|
value="">
|
|
<input type="hidden" name="id" value="" id="field-id" disabled>
|
|
|
|
|
|
@csrf
|
|
@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 (in_array($question->code, ['status']))
|
|
@continue
|
|
@endif
|
|
<div class="col-md-12 mb-2">
|
|
@if ($question->code == 'dr_name')
|
|
<div class="card design-{{ $question->code }} p-2"
|
|
style="background-color: #fcf7e5;">
|
|
<h5 class="mb-2">Drop Address</h5>
|
|
<p id="geo-address" class="mb-0"></p>
|
|
</div>
|
|
@endif
|
|
<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')
|
|
@if ($question->code == 'geolocation_address')
|
|
<div class="d-flex align-items-center" style="gap: 10px;">
|
|
<input type="{{ $question->type }}"
|
|
id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}" class="form-control"
|
|
style="flex: 1; max-width: 300px;"
|
|
{{-- {{ $question->required == 'yes' ? '' : '' }} --}}
|
|
value="{{ $question->value ?? '' }}" readonly
|
|
{{-- required --}}
|
|
>
|
|
|
|
<button type="button" class="btn btn-primary"
|
|
id="get-location-btn"
|
|
style="white-space: nowrap; height: 38px;">
|
|
Get Location
|
|
</button>
|
|
</div>
|
|
@else
|
|
<input type="{{ $question->type }}" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}" class="form-control"
|
|
{{ $question->required == 'yes' ? '' : '' }}
|
|
value="{{ isset($question->value) ? $question->value : '' }}"
|
|
|
|
@if($question->code == 'clinic_hospital_home_name' || $question->code == 'building_name' || $question->code == 'address_line_1' || $question->code == 'address_line_2' || $question->code == 'city')
|
|
maxlength="40"
|
|
@elseif($question->code == 'pin_code')
|
|
maxlength="6"
|
|
@elseif($question->code == 'doctor_mobile_number' || $question->code == 'employee_phone' || $question->code == 'paramedic_alternate_contact_number')
|
|
pattern="[1-9]{1}[0-9]{9}"
|
|
maxlength="10"
|
|
@elseif($question->code == 'doctor_name_for' || $question->code == 'dr_name' || $question->code == 'msl_code' || $question->code == 'remarks')
|
|
maxlength="30"
|
|
@elseif($question->code == 'value_of_the_parcel')
|
|
maxlength="100"
|
|
@elseif($question->code == 'value_of_the_parcel' || $question->code == 'abm_name'
|
|
|| $question->code == 'abm_email' || $question->code == 'rbm_name'
|
|
|| $question->code == 'employee_name' || $question->code == 'employee_email')
|
|
maxlength="100"
|
|
@else
|
|
|
|
@endif
|
|
>
|
|
|
|
@if ($question->code == 'doctor_mobile_number' || $question->code == 'employee_phone' || $question->code == 'paramedic_alternate_contact_number')
|
|
<small class="field-error-msg-number text-danger"></small>
|
|
@elseif($question->code == 'pin_code')
|
|
<small class="field-error-msg-pincode text-danger"></small>
|
|
@endif
|
|
@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' ? '' : '' }}
|
|
value="{{ isset($question->value) ? $question->value : 0 }}">
|
|
@break
|
|
|
|
@case('textarea')
|
|
<textarea id="field-{{ $question->code }}" name="{{ $question->code }}" class="form-control"
|
|
{{ $question->required == 'yes' ? '' : '' }}>{{ isset($question->value) ? $question->value : '' }}</textarea>
|
|
@break
|
|
|
|
@case('dropdown')
|
|
@if ($question->code == 'state')
|
|
<select class="form-control" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}"
|
|
{{ $question->required == 'yes' ? '' : '' }}>
|
|
<option value=""> -- Select -- </option>
|
|
<option value="Andhra Pradesh">Andhra Pradesh</option>
|
|
<option value="Andaman and Nicobar Islands">Andaman and Nicobar
|
|
Islands</option>
|
|
<option value="Arunachal Pradesh">Arunachal Pradesh</option>
|
|
<option value="Assam">Assam</option>
|
|
<option value="Bihar">Bihar</option>
|
|
<option value="Chandigarh">Chandigarh</option>
|
|
<option value="Chhattisgarh">Chhattisgarh</option>
|
|
<option value="Dadar and Nagar Haveli">Dadar and Nagar Haveli
|
|
</option>
|
|
<option value="Daman and Diu">Daman and Diu</option>
|
|
<option value="Delhi">Delhi</option>
|
|
<option value="Lakshadweep">Lakshadweep</option>
|
|
<option value="Puducherry">Puducherry</option>
|
|
<option value="Goa">Goa</option>
|
|
<option value="Gujarat">Gujarat</option>
|
|
<option value="Haryana">Haryana</option>
|
|
<option value="Himachal Pradesh">Himachal Pradesh</option>
|
|
<option value="Jammu and Kashmir">Jammu and Kashmir</option>
|
|
<option value="Jharkhand">Jharkhand</option>
|
|
<option value="Karnataka">Karnataka</option>
|
|
<option value="Kerala">Kerala</option>
|
|
<option value="Madhya Pradesh">Madhya Pradesh</option>
|
|
<option value="Maharashtra">Maharashtra</option>
|
|
<option value="Manipur">Manipur</option>
|
|
<option value="Meghalaya">Meghalaya</option>
|
|
<option value="Mizoram">Mizoram</option>
|
|
<option value="Nagaland">Nagaland</option>
|
|
<option value="Odisha">Odisha</option>
|
|
<option value="Punjab">Punjab</option>
|
|
<option value="Rajasthan">Rajasthan</option>
|
|
<option value="Sikkim">Sikkim</option>
|
|
<option value="Tamil Nadu">Tamil Nadu</option>
|
|
<option value="Telangana">Telangana</option>
|
|
<option value="Tripura">Tripura</option>
|
|
<option value="Uttar Pradesh">Uttar Pradesh</option>
|
|
<option value="Uttarakhand">Uttarakhand</option>
|
|
<option value="West Bengal">West Bengal</option>
|
|
</select>
|
|
@else
|
|
<select class="form-control" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}"
|
|
{{ $question->required == 'yes' ? '' : '' }}>
|
|
<option value=""> -- Select -- </option>
|
|
@foreach ($question->options as $option)
|
|
<option value="{{ $option->value }}"
|
|
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}>
|
|
{{ $option->display }}</option>
|
|
@endforeach
|
|
</select>
|
|
@endif
|
|
@break
|
|
|
|
@case('radio')
|
|
@foreach ($question->options as $option)
|
|
<div class="form-check mb-2 form-check-success">
|
|
<input class="form-check-input" type="radio"
|
|
name="{{ $question->code }}"
|
|
id="field-{{ $question->code }}_{{ $option->value }}"
|
|
value="{{ $option->value }}">
|
|
<label class="form-check-label"
|
|
for="field-{{ $question->code }}_{{ $option->value }}">{{ $option->display }}</label>
|
|
</div>
|
|
@endforeach
|
|
@break
|
|
|
|
@case('checkbox')
|
|
@foreach ($question->options as $option)
|
|
<div class="form-check mb-2 form-check-primary ms-2">
|
|
<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' ? '' : '' }}>
|
|
|
|
<small class="field-error-msg-file text-danger"></small>
|
|
@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
|
|
|
|
|
|
</form>
|
|
|
|
@if (!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes'))
|
|
<div class="text-center d-grid mt-3">
|
|
<div id="form-error" class="form-error text-danger py-2"></div>
|
|
<div class="d-flex align-items-center flex-column" style="gap: 10px;">
|
|
|
|
<button class="btn btn-warning" type="submit" id="save-btn" style="min-width:220px;">Save Partial Data
|
|
</button>
|
|
<button class="btn btn-success" type="submit" id="submit-btn" style="min-width:220px;"> Submit
|
|
For Approval </button>
|
|
</div>
|
|
</div>
|
|
@endif
|
|
</div>
|
|
|
|
</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%;
|
|
}
|
|
|
|
.form-label {
|
|
font-weight: bold;
|
|
font-size: 16px;
|
|
}
|
|
</style>
|
|
@include('layouts.shared/footer-script')
|
|
<script src="{{ asset('assets/libs/sweetalert2/sweetalert2.min.js') }}"></script>
|
|
|
|
|
|
<script>
|
|
// let externalValidationGEO = false;
|
|
function checkGeolocationParams() {
|
|
let params = new URLSearchParams(window.location.search);
|
|
|
|
// params.set('latitude', '27.397563');
|
|
// params.set('longitude', '80.135867');
|
|
|
|
const lat = params.get('latitude');
|
|
const lng = params.get('longitude');
|
|
|
|
// const lat = 19.0760;
|
|
// const lng = 72.8777;
|
|
|
|
|
|
|
|
// Check if params exist, are not empty, are valid numbers, and are not zero
|
|
const latNum = parseFloat(lat);
|
|
const lngNum = parseFloat(lng);
|
|
|
|
if (!params.has('latitude') || !params.has('longitude') ||
|
|
!lat || !lng ||
|
|
lat.trim() === '' || lng.trim() === '' ||
|
|
isNaN(latNum) || isNaN(lngNum) ||
|
|
latNum === 0 || lngNum === 0) {
|
|
// $('#field-geolocation_address').prop('required', false);
|
|
// $('label[for="field-geolocation_address"] span.text-danger').remove();
|
|
|
|
// Swal.fire({
|
|
// icon: 'error',
|
|
// title: 'Geolocation Not Enabled',
|
|
// html: `
|
|
// <p><b>Geolocation is required to use this form.</b></p>
|
|
// <p>Please enable location services in your device settings and ensure T3 unstoppables has permission to access your location.</p>
|
|
// <hr>
|
|
// <p><b>For iOS App:</b></p>
|
|
// <ol style="text-align: left; padding-left: 20px; margin-bottom: 15px;">
|
|
// <li>Go to <b>Settings</b> on your iPhone/iPad</li>
|
|
// <li>Scroll down and tap on <b>T3 unstoppables</b></li>
|
|
// <li>Tap on <b>Location</b> or <b>Privacy & Security</b> → <b>Location Services</b></li>
|
|
// <li>Select <b>"While Using the App"</b> or <b>"Always"</b></li>
|
|
// <li>Make sure <b>Location Services</b> is enabled in Settings → Privacy & Security → Location Services</li>
|
|
// <li>Close and reopen T3 unstoppables, then try again</li>
|
|
// </ol>
|
|
// <p><b>For Android App:</b></p>
|
|
// <ol style="text-align: left; padding-left: 20px; margin-bottom: 15px;">
|
|
// <li>Go to <b>Settings</b> on your Android device</li>
|
|
// <li>Tap on <b>Apps</b> or <b>Application Manager</b></li>
|
|
// <li>Find and tap on <b>T3 unstoppables</b></li>
|
|
// <li>Tap on <b>Permissions</b></li>
|
|
// <li>Enable <b>Location</b> permission</li>
|
|
// <li>Make sure <b>Location</b> is turned ON in Settings → Location</li>
|
|
// <li>Close and reopen T3 unstoppables, then try again</li>
|
|
// </ol>
|
|
// `,
|
|
// confirmButtonText: 'OK',
|
|
// width: '650px'
|
|
// });
|
|
// return false;
|
|
// externalValidationGEO = false;
|
|
}
|
|
// else{
|
|
// // externalValidationGEO = true;
|
|
// $('#field-geolocation_address').prop('required', true);
|
|
// let label = $('label[for="field-geolocation_address"]');
|
|
// if (label.find('span.text-danger').length === 0) {
|
|
// label.append(' <span class="text-danger">*</span>');
|
|
// }
|
|
// }
|
|
return true;
|
|
}
|
|
|
|
// Check on page load
|
|
jQuery(document).ready(function($) {
|
|
checkGeolocationParams();
|
|
});
|
|
|
|
$('#form-wrapper').hide()
|
|
$('#field-form-wrapper').hide()
|
|
$('#add-camp-btn').click(function() {
|
|
// Check geolocation before showing form
|
|
if (!checkGeolocationParams()) {
|
|
return;
|
|
}
|
|
|
|
$('#table-wrapper').hide(0)
|
|
$('#field-form-wrapper').show(100, () => {
|
|
$('#add-camp-btn').hide(0);
|
|
|
|
let emp_name = $('#hidden-field-emp_name').val();
|
|
let emp_phone = $('#hidden-field-emp_phone').val();
|
|
let emp_email = $('#hidden-field-emp_email').val();
|
|
let abm_name = $('#hidden-field-abm_name').val();
|
|
let abm_email = $('#hidden-field-abm_email').val();
|
|
let rbm_name = $('#hidden-field-rbm_name').val();
|
|
$('#report-form')[0].reset();
|
|
$('#field-employee_name').val(emp_name);
|
|
$('#field-employee_phone').val(emp_phone);
|
|
$('#field-employee_email').val(emp_email);
|
|
$('#field-abm_name').val(abm_name);
|
|
$('#field-abm_email').val(abm_email);
|
|
$('#field-rbm_name').val(rbm_name);
|
|
|
|
$('#field-id').val('').prop('disabled', true);
|
|
})
|
|
})
|
|
|
|
$('#back-btn').click(function() {
|
|
$('#table-wrapper').show(0)
|
|
$('#add-camp-btn').show(0);
|
|
$('#field-form-wrapper').hide(0)
|
|
})
|
|
|
|
$('.edit-btn').click(function() {
|
|
// Check geolocation before showing form
|
|
if (!checkGeolocationParams()) {
|
|
return;
|
|
}
|
|
|
|
$('#field-form-wrapper').show(100, () => {
|
|
$('#add-camp-btn').hide(0);
|
|
})
|
|
$('#table-wrapper').hide()
|
|
|
|
let selected = JSON.parse($(this).attr('plan_details'))
|
|
console.log('selected', selected)
|
|
for (let k of Object.keys(selected)) {
|
|
if (selected[k] != '') {
|
|
if (k == 'contact_id') {
|
|
$('#field-contact_id').val($("#field-contact_id option:contains(" +
|
|
selected[k] + ")").attr('value'));
|
|
} else if (k == 'id') {
|
|
$('#field-sub_id').val(selected[k]);
|
|
} else if (k == 'request_letter') {
|
|
$('#field-existing_letter').val(selected[k]);
|
|
}
|
|
else if(k == 'doctor_name'){
|
|
$('#field-doctor_name_for').val(selected[k]);
|
|
$('#field-dr_name').val(selected[k]);
|
|
}
|
|
else if(k == 'emp_name'){
|
|
$('#field-employee_name').val(selected[k]);
|
|
}
|
|
else if(k == 'emp_phone'){
|
|
$('#field-employee_phone').val(selected[k]);
|
|
}
|
|
else if(k == 'emp_email'){
|
|
$('#field-employee_email').val(selected[k]);
|
|
}
|
|
else if(k == 'doctor_speciality'){
|
|
$('#field-speciality').val(selected[k]);
|
|
}
|
|
else if(k == 'type_of_nebulizer'){
|
|
$('#field-type_of_nebuliser').val(selected[k]);
|
|
}
|
|
else if(k == 'more_than_5_nebulizer'){
|
|
$('#field-do_you_need_more_than_5_nebulizers').val(selected[k]);
|
|
}
|
|
else if(k == 'nebulizer_purpose'){
|
|
$('#field-for_what_purpose_nebulisers_will_be_used_by_dr').val(selected[k]);
|
|
}
|
|
else if(k == 'doctor_phone'){
|
|
$('#field-doctor_mobile_number').val(selected[k]);
|
|
}
|
|
else if(k == 'clinic_hospital_name'){
|
|
$('#field-clinic_hospital_home_name').val(selected[k]);
|
|
}
|
|
else if(k == 'address_building'){
|
|
$('#field-building_name').val(selected[k]);
|
|
}
|
|
else if(k == 'address_building'){
|
|
$('#field-building_name').val(selected[k]);
|
|
}
|
|
else if(k == 'address_state'){
|
|
$('#field-state').val(selected[k]);
|
|
}
|
|
else if(k == 'address_city'){
|
|
$('#field-city').val(selected[k]);
|
|
}
|
|
else if(k == 'address_pin_code'){
|
|
$('#field-pin_code').val(selected[k]);
|
|
}
|
|
else if(k == 'value_of_parcel'){
|
|
$('#field-value_of_the_parcel').val(selected[k]);
|
|
}
|
|
else {
|
|
console.log(k);
|
|
console.log(selected[k]);
|
|
$('#field-' + k).val(selected[k]);
|
|
}
|
|
}
|
|
}
|
|
|
|
let neb = parseInt(selected["no_of_nebulizer"]) || 0;
|
|
let morethan = selected["more_than_5_nebulizer"]; // Yes / No
|
|
let dropdown = $("#field-no_of_nebulizer");
|
|
dropdown.empty().append('<option value=""> -- Select -- </option>');
|
|
let max = (morethan === "Yes") ? 10 : 5;
|
|
let fro = (morethan === "Yes") ? 6 : 1;
|
|
for (i = fro; i <= max; i++) {
|
|
dropdown.append(`<option value="${i}">${i}</option>`);
|
|
}
|
|
dropdown.val(neb);
|
|
|
|
let docid = $('#field-contact_id option').map(function() {
|
|
if ($(this).text().trim() == selected['contact_id']) return this;
|
|
}).attr('value')
|
|
$('#field-contact_id').val(docid)
|
|
$('#field-id').val(selected['id']).prop('disabled', false);
|
|
$('#field-id').val(selected['id'])
|
|
|
|
const field = $('#field-msl_code');
|
|
if (field.val().length > 0) {
|
|
field.trigger('input');
|
|
}
|
|
})
|
|
</script>
|
|
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD77kr6abgQELNhp41Jpgr1gqCNdo_EHrs&libraries=places"></script>
|
|
<script type="text/javascript">
|
|
jQuery(document).ready(function($) {
|
|
let isValidNum = true;
|
|
let isValidAltNum = true;
|
|
|
|
function handlePhoneNumber(e) {
|
|
const $input = $(e.target);
|
|
const value = $input.val().trim();
|
|
const new_Number = parseInt(value);
|
|
const $errorMsg = $input.parent().find('.field-error-msg-number');
|
|
|
|
if (isNaN(new_Number)) {
|
|
$input.css({
|
|
'border': '1px solid red'
|
|
});
|
|
$errorMsg.html('* Invalid Number!');
|
|
isValidNum = false;
|
|
return;
|
|
}
|
|
|
|
if (/^\d{10}$/.test(value)) {
|
|
$input.css({
|
|
'border': '1px solid #ced4da'
|
|
});
|
|
$errorMsg.html('');
|
|
isValidNum = true;
|
|
} else {
|
|
$input.css({
|
|
'border': '1px solid red'
|
|
});
|
|
$errorMsg.html('* Number must be 10 digits long!');
|
|
isValidNum = false;
|
|
}
|
|
}
|
|
|
|
function handlealternatenumber(e) {
|
|
const $input = $(e.target);
|
|
const value = $input.val().trim();
|
|
const $errorMsg = $input.parent().find('.field-error-msg-number');
|
|
|
|
// If blank, treat as valid
|
|
if (value === '') {
|
|
$input.css('border', '1px solid #ced4da');
|
|
$errorMsg.html('');
|
|
isValidAltNum = true;
|
|
return;
|
|
}
|
|
|
|
// Check if numeric
|
|
if (!/^\d+$/.test(value)) {
|
|
$input.css('border', '1px solid red');
|
|
$errorMsg.html('* Invalid Number!');
|
|
isValidAltNum = false;
|
|
return;
|
|
}
|
|
|
|
// Check if exactly 10 digits
|
|
if (value.length === 10) {
|
|
$input.css('border', '1px solid #ced4da');
|
|
$errorMsg.html('');
|
|
isValidAltNum = true;
|
|
} else {
|
|
$input.css('border', '1px solid red');
|
|
$errorMsg.html('* Number must be 10 digits long!');
|
|
isValidAltNum = false;
|
|
}
|
|
}
|
|
|
|
function handlePincode(e) {
|
|
const $input = $(e.target);
|
|
const value = $input.val().trim();
|
|
const pincodeRegex = /^\d{6}$/;
|
|
|
|
if (!pincodeRegex.test(value)) {
|
|
$input.css({
|
|
'border': '1px solid red'
|
|
});
|
|
$input.siblings('.field-error-msg-pincode').html(
|
|
isNaN(value) ? '* Invalid Pincode!' : '* Pincode must be exactly 6 digits!'
|
|
);
|
|
isValidNum = false;
|
|
} else {
|
|
$input.css({
|
|
'border': '1px solid #ced4da'
|
|
});
|
|
$input.siblings('.field-error-msg-pincode').html('');
|
|
isValidNum = true;
|
|
}
|
|
}
|
|
|
|
function handleFileValidation(e) {
|
|
const file = e.target.files[0];
|
|
const $errorMsg = $(e.target).siblings('.field-error-msg-file');
|
|
|
|
if (!file) return;
|
|
|
|
const validTypes = ['application/pdf', 'image/jpeg', 'image/jpg', 'image/png'];
|
|
const maxSize = 10 * 1024 * 1024;
|
|
|
|
if (!validTypes.includes(file.type)) {
|
|
$errorMsg.text('* Only PDF, JPG, JPEG, PNG files are allowed.');
|
|
$(e.target).css('border', '1px solid red');
|
|
isValidNum = false;
|
|
return;
|
|
}
|
|
|
|
if (file.size > maxSize) {
|
|
$errorMsg.text('* File size must not exceed 10 MB.');
|
|
$(e.target).css('border', '1px solid red');
|
|
isValidNum = false;
|
|
return;
|
|
}
|
|
|
|
$errorMsg.text('');
|
|
$(e.target).css('border', '1px solid #ced4da');
|
|
isValidNum = true;
|
|
}
|
|
|
|
$('#field-employee_phone').on('change', handlePhoneNumber);
|
|
$('#field-doctor_mobile_number').on('change', handlePhoneNumber);
|
|
$('#field-paramedic_alternate_contact_number').on('change', handlealternatenumber);
|
|
|
|
|
|
$('#field-pin_code').on('change', handlePincode);
|
|
$('#field-upload_request_letter').on('change', handleFileValidation);
|
|
|
|
|
|
$('#field-doctor_name_for').on('input', function () {
|
|
const inputVal = $(this).val();
|
|
$('#field-dr_name').val(inputVal);
|
|
});
|
|
|
|
//'#field-geolocation_address',
|
|
const requiredFields = ['#field-msl_code', '#field-upload_request_letter',
|
|
'#field-speciality', '#field-type_of_nebuliser',
|
|
'#field-no_of_nebulizer', '#field-value_of_the_parcel', '#field-team',
|
|
'#field-for_what_purpose_nebulisers_will_be_used_by_dr', '#field-dr_name',
|
|
'#field-doctor_mobile_number', '#field-clinic_hospital_home_name',
|
|
'#field-building_name', '#field-address_line_1', '#field-address_line_2',
|
|
'#field-state', '#field-city', '#field-pin_code', '#field-employee_name',
|
|
'#field-employee_phone', '#field-employee_email', '#field-abm_name', '#field-abm_email',
|
|
'#field-rbm_name', '#field-doctor_name_for', '#field-address_type', '#field-do_you_need_more_than_5_nebulizers'
|
|
];
|
|
|
|
const requiredFieldsForSaveBtn = ['#field-doctor_name_for', '#field-msl_code', '#field-dr_name'];
|
|
|
|
$('#submit-btn').on('click', function() {
|
|
submitForm('submit_for_approval', 'Requested');
|
|
});
|
|
|
|
$('#save-btn').on('click', function() {
|
|
submitForm('submit_to_save', 'Partially Saved');
|
|
});
|
|
|
|
function submitForm(submitType, status) {
|
|
|
|
if (!isValidNum) {
|
|
$('#form-error').html(
|
|
'* Form can not be submitted! Please check and fillup all form fields correctly!');
|
|
return;
|
|
}
|
|
|
|
if (!isValidAltNum) {
|
|
$('#form-error').html(
|
|
'* Form can not be submitted! Please check and fillup all form fields correctly!');
|
|
return;
|
|
}
|
|
|
|
// const tmnum = $('#field-employee_phone').val();
|
|
// const docnum = $('#field-doctor_mobile_number').val();
|
|
// if(tmnum == docnum){
|
|
// console.log('tmnum',tmnum);
|
|
// console.log(docnum);
|
|
|
|
// Swal.fire({
|
|
// title: 'Warning',
|
|
// html: 'Duplicate Mobile Number, TM Mobile Number & Doctor Mobile Number Cannot Be Same!',
|
|
// icon: 'info'
|
|
// })
|
|
// return;
|
|
// }
|
|
|
|
const $form = $('#report-form');
|
|
$('#field-form_submit_type').val(submitType);
|
|
$('#field-status').val(status);
|
|
if (submitType === 'submit_for_approval') {
|
|
let isValid = true;
|
|
// // Get the Employee Code from the relevant hidden field
|
|
// const employeeCode = $('#field-emp_id').val();
|
|
// if (!employeeCode) {
|
|
// Swal.fire({
|
|
// title: "Employee Code Missing",
|
|
// text: "Unable to find employee code to check NAP request block. Please contact administrator.",
|
|
// icon: "error"
|
|
// });
|
|
// return;
|
|
// }
|
|
|
|
// // API Call to check if NAP requests are blocked for this employee
|
|
// $.ajax({
|
|
// url: 'https://nap.easyspacebooking.com/APi/GetStatusToBlockOrNotByEmployeeCode/' + encodeURIComponent(employeeCode),
|
|
// method: 'GET',
|
|
// dataType: 'json',
|
|
// async: false, // block the form submit until we get API response
|
|
// success: function(response) {
|
|
// // response should be something like: [{"blocked":"Yes"}]
|
|
// if (Array.isArray(response) && response.length > 0 && response[0].blocked === "Yes") {
|
|
// Swal.fire({
|
|
// title: "Request Blocked",
|
|
// text: "You are not allowed to raise a new NAP request at this time.",
|
|
// icon: "error"
|
|
// });
|
|
// isValid = false;
|
|
// return;
|
|
// }
|
|
// },
|
|
// error: function(xhr, status, error) {
|
|
// Swal.fire({
|
|
// title: "Unable to Check NAP Status",
|
|
// text: "Could not verify NAP request status. Please try again or contact support.",
|
|
// icon: "error"
|
|
// });
|
|
// isValid = false;
|
|
// return;
|
|
// }
|
|
// });
|
|
// if (!isValid) return;
|
|
|
|
requiredFields.forEach(function(selector) {
|
|
const $field = $(selector);
|
|
|
|
if (!$field.length) {
|
|
console.log('Missing field for selector:', selector);
|
|
}
|
|
console.log('f', $field)
|
|
|
|
if (selector == '#field-upload_request_letter') {
|
|
const hasOldFile = $('#field-existing_letter').val();
|
|
if (!hasOldFile && !$field[0].files.length) {
|
|
$field.attr('required', true);
|
|
} else {
|
|
$field.removeAttr('required');
|
|
}
|
|
} else {
|
|
$field.attr('required', true);
|
|
}
|
|
|
|
// if (selector == '#field-geolocation_address') {
|
|
// if (selector == '#field-geolocation_address') {
|
|
// if(externalValidationGEO){
|
|
// if (!$field.val().trim()) {
|
|
// isValid = false;
|
|
// $('#form-error').html('* Form can not be submitted! Please select location!');
|
|
// $field.focus();
|
|
// return false;
|
|
// }
|
|
// }
|
|
|
|
// }
|
|
// }
|
|
|
|
if (!$field[0].checkValidity()) {
|
|
isValid = false;
|
|
$field[0].reportValidity();
|
|
return false;
|
|
}
|
|
});
|
|
if (!isValid) return;
|
|
}
|
|
else if(submitType === 'submit_to_save'){
|
|
let isValid = true;
|
|
requiredFieldsForSaveBtn.forEach(function(selector) {
|
|
const $fieldsavebtn = $(selector);
|
|
$fieldsavebtn.attr('required', true);
|
|
if (!$fieldsavebtn[0].checkValidity()) {
|
|
isValid = false;
|
|
$fieldsavebtn[0].reportValidity();
|
|
return false;
|
|
}
|
|
});
|
|
if (!isValid) return;
|
|
}
|
|
else {
|
|
requiredFields.forEach(selector => $(selector).removeAttr('required'));
|
|
}
|
|
const formData = new FormData($form[0]);
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: '/form/ajaxsubmit',
|
|
data: formData,
|
|
processData: false,
|
|
contentType: false,
|
|
|
|
beforeSend: function() {
|
|
$("#pageloader").fadeIn();
|
|
},
|
|
|
|
success: function(data) {
|
|
$("#pageloader").fadeOut();
|
|
if (data.status == 'success') {
|
|
console.log("ss", submitType);
|
|
|
|
if (submitType == 'submit_to_save') {
|
|
Swal.fire({
|
|
title: 'Your data is partially saved.',
|
|
html: 'To submit your request for approval, click on the button "Submit for Approval".',
|
|
icon: 'info'
|
|
})
|
|
.then(function() {
|
|
window.location.reload();
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
title: 'Great!',
|
|
text: 'Your data is successfully submitted!',
|
|
icon: 'success'
|
|
}).then(function() {
|
|
window.location.reload();
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//$('#report-form').trigger("reset");
|
|
} else if (data.status == 'mapping error') {
|
|
Swal.fire({
|
|
icon: 'info',
|
|
title: 'Message',
|
|
text: data.message
|
|
})
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Data not submitted',
|
|
text: data.message ? data.message : 'Something went wrong, please try again after some time!'
|
|
})
|
|
}
|
|
},
|
|
|
|
error: function(xhr, status, error) {
|
|
$("#pageloader").fadeOut();
|
|
},
|
|
});
|
|
|
|
}
|
|
|
|
$('#get-location-btn').on('click', function() {
|
|
|
|
const btn = $(this);
|
|
const existingAddress = $('#field-geolocation_address').val().trim();
|
|
|
|
if (existingAddress !== '' && !btn.data('confirmed')) {
|
|
Swal.fire({
|
|
title: 'Location already captured',
|
|
text: 'You already have a saved location. Getting location again will overwrite it with your current location. Do you want to continue?',
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonText: 'Yes, replace it',
|
|
cancelButtonText: 'No, keep existing',
|
|
confirmButtonColor: '#d33'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
btn.data('confirmed', true);
|
|
$('#field-geolocation_address').val('');
|
|
btn.trigger('click');
|
|
}
|
|
});
|
|
return;
|
|
}
|
|
btn.removeData('confirmed');
|
|
|
|
let params = new URLSearchParams(window.location.search);
|
|
console.log("params", params);
|
|
// params.set('latitude', '27.397563');
|
|
// params.set('longitude', '80.135867');
|
|
|
|
if (params.has('latitude') && params.has('longitude')) {
|
|
const lat = params.get("latitude");
|
|
const lng = params.get("longitude");
|
|
// const lat = 27.397563;
|
|
// const lng = 80.135867;
|
|
$('#field-geolocation_latitude').val(lat)
|
|
$('#field-geolocation_longitude').val(lng)
|
|
|
|
|
|
if (lat && lng) {
|
|
console.log("inside");
|
|
// First try OpenStreetMap reverse geocoding
|
|
fetch(
|
|
`https://nominatim.openstreetmap.org/reverse?format=json&lat=${lat}&lon=${lng}`
|
|
)
|
|
.then(res => res.json())
|
|
.then(data => {
|
|
console.log('OSM data:', data);
|
|
const address = data.display_name;
|
|
const city = data.address && (data.address.city || data.address.town || data.address.village);
|
|
const state = data.address && data.address.state;
|
|
const pincode = data.address && data.address.postcode;
|
|
|
|
if (address) {
|
|
if (city) $('#field-city').val(city);
|
|
if (pincode) $('#field-pin_code').val(pincode);
|
|
if (state) $('#field-state').val(state);
|
|
|
|
$('#field-geolocation_latitude').val(data.lat);
|
|
$('#field-geolocation_longitude').val(data.lon);
|
|
$('#field-geolocation_address').val(address);
|
|
$('#field-geolocation_json').val(JSON.stringify(data.address || {}));
|
|
$('#geo-address').html('<strong>Geolocation Detected:</strong> ' + address);
|
|
}
|
|
|
|
// If all critical fields are available and address is sufficiently long, we consider OSM a success
|
|
if (address && city && state && pincode && address.length > 80) {
|
|
return; // Success, stop here.
|
|
} else {
|
|
// Fallback to Google Maps JavaScript API Geocoder
|
|
if (typeof google !== "undefined" && google.maps && google.maps.Geocoder) {
|
|
const geocoder = new google.maps.Geocoder();
|
|
const latLngObj = { lat: parseFloat(lat), lng: parseFloat(lng) };
|
|
geocoder.geocode({ location: latLngObj }, (results, status) => {
|
|
if (status === "OK" && results && results.length > 0) {
|
|
console.log("Geocode results:", results);
|
|
const result = results[0];
|
|
const g_address = result.formatted_address || "";
|
|
let g_city = city || ""; // If OSM city exists, prefer it
|
|
let g_state = state || "";
|
|
let g_pincode = pincode || "";
|
|
if (result.address_components) {
|
|
for (let comp of result.address_components) {
|
|
if (comp.types.includes('locality') ||
|
|
comp.types.includes('sublocality') ||
|
|
comp.types.includes('administrative_area_level_2') ||
|
|
comp.types.includes('postal_town')) {
|
|
if (!g_city) g_city = comp.long_name;
|
|
}
|
|
if (comp.types.includes('administrative_area_level_1')) {
|
|
if (!g_state) g_state = comp.long_name;
|
|
}
|
|
if (comp.types.includes('postal_code')) {
|
|
if (!g_pincode) g_pincode = comp.long_name;
|
|
}
|
|
}
|
|
}
|
|
if (g_city) $('#field-city').val(g_city);
|
|
if (g_pincode) $('#field-pin_code').val(g_pincode);
|
|
if (g_state) $('#field-state').val(g_state);
|
|
$('#field-geolocation_latitude').val(lat);
|
|
$('#field-geolocation_longitude').val(lng);
|
|
if (g_address) {
|
|
$('#field-geolocation_address').val(g_address);
|
|
$('#geo-address').html('<strong>Geolocation Detected:</strong> ' + g_address);
|
|
}
|
|
$('#field-geolocation_json').val(JSON.stringify(result));
|
|
} else {
|
|
// All fails: clear fields
|
|
$('#field-city').val('');
|
|
$('#field-pin_code').val('');
|
|
$('#field-state').val('');
|
|
$('#field-geolocation_address').val('');
|
|
$('#geo-address').html('<strong>Unable to detect location details.</strong>');
|
|
$('#field-geolocation_json').val('');
|
|
}
|
|
});
|
|
} else {
|
|
// Google Maps API not loaded
|
|
console.error("Google Maps JavaScript API is not loaded! Please include the Maps script with your browser-restricted key.");
|
|
if (!address) {
|
|
$('#field-city').val('');
|
|
$('#field-pin_code').val('');
|
|
$('#field-state').val('');
|
|
$('#field-geolocation_address').val('');
|
|
$('#geo-address').html('<strong>Unable to detect location details.</strong>');
|
|
$('#field-geolocation_json').val('');
|
|
}
|
|
}
|
|
}
|
|
})
|
|
.catch(osmErr => {
|
|
// If OSM fails completely, fallback to Google Maps JavaScript API Geocoder
|
|
console.error("OSM Geocoding error:", osmErr);
|
|
if (typeof google !== "undefined" && google.maps && google.maps.Geocoder) {
|
|
const geocoder = new google.maps.Geocoder();
|
|
const latLngObj = { lat: parseFloat(lat), lng: parseFloat(lng) };
|
|
geocoder.geocode({ location: latLngObj }, (results, status) => {
|
|
if (status === "OK" && results && results.length > 0) {
|
|
console.log("Geocode results:", results);
|
|
const result = results[0];
|
|
const address = result.formatted_address || "";
|
|
let city = "";
|
|
let state = "";
|
|
let pincode = "";
|
|
if (result.address_components) {
|
|
for (let comp of result.address_components) {
|
|
if (comp.types.includes('locality') ||
|
|
comp.types.includes('sublocality') ||
|
|
comp.types.includes('administrative_area_level_2') ||
|
|
comp.types.includes('postal_town')) {
|
|
if (!city) city = comp.long_name;
|
|
}
|
|
if (comp.types.includes('administrative_area_level_1')) {
|
|
if (!state) state = comp.long_name;
|
|
}
|
|
if (comp.types.includes('postal_code')) {
|
|
if (!pincode) pincode = comp.long_name;
|
|
}
|
|
}
|
|
}
|
|
if (city) $('#field-city').val(city);
|
|
if (pincode) $('#field-pin_code').val(pincode);
|
|
if (state) $('#field-state').val(state);
|
|
$('#field-geolocation_latitude').val(lat);
|
|
$('#field-geolocation_longitude').val(lng);
|
|
$('#field-geolocation_address').val(address);
|
|
$('#geo-address').html('<strong>Geolocation Detected:</strong> ' + address);
|
|
$('#field-geolocation_json').val(JSON.stringify(result));
|
|
} else {
|
|
$('#field-city').val('');
|
|
$('#field-pin_code').val('');
|
|
$('#field-state').val('');
|
|
$('#field-geolocation_address').val('');
|
|
$('#geo-address').html('<strong>Unable to detect location details.</strong>');
|
|
$('#field-geolocation_json').val('');
|
|
}
|
|
});
|
|
} else {
|
|
// Google Maps API not loaded
|
|
console.error("Google Maps JavaScript API is not loaded! Please include the Maps script with your browser-restricted key.");
|
|
$('#field-city').val('');
|
|
$('#field-pin_code').val('');
|
|
$('#field-state').val('');
|
|
$('#field-geolocation_address').val('');
|
|
$('#geo-address').html('<strong>Unable to detect location details.</strong>');
|
|
$('#field-geolocation_json').val('');
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
// lang val
|
|
|
|
const fields = [ "#field-address_type", "#field-building_name", "#field-address_line_1", "#field-address_line_2", "#field-city", "#field-pin_code" ];
|
|
|
|
fields.forEach(function (id) {
|
|
$(id).after('<small class="eng-msg" style="color:red;"></small>');
|
|
});
|
|
const regex = /^[A-Za-z0-9 ., -]*$/;
|
|
fields.forEach(function (id) {
|
|
$(id).on("input", function () {
|
|
let value = $(this).val();
|
|
if (!regex.test(value)) {
|
|
$(this).next(".eng-msg").text("Please use English characters only.");
|
|
$(this).val(value.replace(/[^A-Za-z0-9 ., -]/g, ""));
|
|
} else {
|
|
$(this).next(".eng-msg").text("");
|
|
}
|
|
});
|
|
});
|
|
|
|
//
|
|
|
|
});
|
|
</script>
|
|
|
|
<script>
|
|
$("#field-do_you_need_more_than_5_nebulizers").on("change", function () {
|
|
let countField = $("#field-no_of_nebulizer");
|
|
if ($(this).val() === "Yes") {
|
|
Swal.fire({
|
|
title: "Approval Needed",
|
|
text: "For requesting more than 5 nebulizers, you will need approval from ZBM and RBM. Do you want to proceed further?",
|
|
icon: "warning",
|
|
showCancelButton: true,
|
|
confirmButtonText: "Yes",
|
|
cancelButtonText: "Cancel",
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
countField.html(`
|
|
<option value=""> -- Select -- </option>
|
|
<option value="6">6</option>
|
|
<option value="7">7</option>
|
|
<option value="8">8</option>
|
|
<option value="9">9</option>
|
|
<option value="10">10</option>
|
|
`);
|
|
|
|
} else {
|
|
$("#field-do_you_need_more_than_5_nebulizers").val("No").trigger("change");
|
|
countField.html(`
|
|
<option value=""> -- Select -- </option>
|
|
<option value="1">1</option>
|
|
<option value="2">2</option>
|
|
<option value="3">3</option>
|
|
<option value="4">4</option>
|
|
<option value="5">5</option>
|
|
`);
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if ($(this).val() === "No") {
|
|
countField.html(`
|
|
<option value=""> -- Select -- </option>
|
|
<option value="1">1</option>
|
|
<option value="2">2</option>
|
|
<option value="3">3</option>
|
|
<option value="4">4</option>
|
|
<option value="5">5</option>
|
|
`);
|
|
}
|
|
|
|
});
|
|
</script>
|
|
|
|
<script>
|
|
jQuery(document).ready(function($) {
|
|
|
|
$('#field-msl_code').after(`
|
|
<div id="msl-spinner" style="display:none; font-size:12px; margin-top:3px;">
|
|
<span class="spinner-border spinner-border-sm"></span> Checking...
|
|
</div>
|
|
`);
|
|
|
|
let timer;
|
|
let existingCount = 0;
|
|
|
|
function limitAllowed() {
|
|
return $('#field-do_you_need_more_than_5_nebulizers').val() === 'Yes';
|
|
}
|
|
|
|
function validateLimit() {
|
|
if (limitAllowed()) {
|
|
disableButtons(false);
|
|
return;
|
|
}
|
|
|
|
let selected = Number($('#field-no_of_nebulizer').val()) || 0;
|
|
|
|
if (existingCount >= 5) {
|
|
disableButtons(true);
|
|
Swal.fire({
|
|
title: 'Limit Reached',
|
|
html: `You have already reached the monthly limit of <b>5</b> nebulizer requests for this doctor.`,
|
|
icon: 'warning'
|
|
});
|
|
return;
|
|
}
|
|
|
|
let remaining = 5 - existingCount;
|
|
if (selected > remaining) {
|
|
disableButtons(true);
|
|
Swal.fire({
|
|
title: 'Limit Exceeded',
|
|
html: `Only <b>${remaining}</b> more nebulizer(s) can be requested this month.`,
|
|
icon: 'info'
|
|
});
|
|
} else {
|
|
disableButtons(false);
|
|
}
|
|
}
|
|
|
|
$('#field-msl_code').on('input', function () {
|
|
clearTimeout(timer);
|
|
let msl = $(this).val().trim();
|
|
$('#msl-spinner').show();
|
|
disableButtons(true);
|
|
|
|
timer = setTimeout(function() {
|
|
|
|
if (msl === "") {
|
|
$('#msl-spinner').hide();
|
|
existingCount = 0;
|
|
disableButtons(false);
|
|
return;
|
|
}
|
|
|
|
$.ajax({
|
|
type: "GET",
|
|
url: '/form/getnebcountajax?mslcode=' + msl,
|
|
success: function(data) {
|
|
$('#msl-spinner').hide();
|
|
existingCount = Number(data.count) || 0;
|
|
validateLimit();
|
|
},
|
|
error: function() {
|
|
$('#msl-spinner').hide();
|
|
disableButtons(false);
|
|
}
|
|
});
|
|
|
|
}, 500);
|
|
});
|
|
|
|
$('#field-no_of_nebulizer').on('change', function() {
|
|
validateLimit();
|
|
});
|
|
|
|
$('#field-do_you_need_more_than_5_nebulizers').on('change', function() {
|
|
validateLimit();
|
|
});
|
|
|
|
function disableButtons(flag) {
|
|
$('#submit-btn').prop('disabled', flag);
|
|
}
|
|
|
|
if ($('#field-msl_code').val().trim() !== "") {
|
|
$('#field-msl_code').trigger('input');
|
|
}
|
|
|
|
});
|
|
</script>
|
|
|
|
<script>
|
|
jQuery(document).ready(function($){
|
|
const formData = new FormData();
|
|
formData.append('form_id', $('[name="form_id"]').val());
|
|
formData.append('emp_id', $('#field-emp_id').val());
|
|
formData.append('user_id', $('#field-user_id').val());
|
|
formData.append('GetStatusToBlockOrNotByEmployeeCode', 'yes');
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: '/form/ajaxsubmit',
|
|
data: formData,
|
|
processData: false,
|
|
contentType: false,
|
|
|
|
beforeSend: function() {
|
|
$("#pageloader").fadeIn();
|
|
},
|
|
|
|
success: function(data) {
|
|
$("#pageloader").fadeOut();
|
|
if (data.status == 'failure') {
|
|
$('#add-camp-btn').prop('disabled', true);
|
|
|
|
let btnHtml = '';
|
|
if (data.redirect_url) {
|
|
btnHtml = `
|
|
<br>
|
|
<p><i>Use below button to view patient status data<i></p>
|
|
<a href="${data.redirect_url}" target="_blank" class="swal2-confirm swal2-styled" style="text-decoration:none;">
|
|
View Patient Status Data
|
|
</a>
|
|
`;
|
|
}
|
|
|
|
let tableHtml = '';
|
|
if (Array.isArray(data.allemployeerequest) && data.allemployeerequest.length > 0) {
|
|
tableHtml = `
|
|
<div style="
|
|
position: relative;
|
|
max-height: 300px;
|
|
overflow-y: auto;
|
|
overflow-x: auto;
|
|
margin-top: 12px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 6px;
|
|
cursor: pointer;
|
|
">
|
|
<!-- Scroll hint -->
|
|
<div style="
|
|
position: sticky;
|
|
top: 0;
|
|
background: #fff;
|
|
padding: 6px 10px;
|
|
font-size: 12px;
|
|
color: #666;
|
|
border-bottom: 1px dashed #ddd;
|
|
text-align: center;
|
|
">
|
|
Scroll to view more details →
|
|
</div>
|
|
|
|
|
|
<table style="
|
|
width:100%;
|
|
border-collapse: collapse;
|
|
min-width: 500px;
|
|
font-size: 14px;
|
|
">
|
|
<thead style="
|
|
position: sticky;
|
|
top: 32px;
|
|
background: #f3f3f3;
|
|
z-index: 1;
|
|
">
|
|
<tr>
|
|
<th style="border:1px solid #ddd;padding:8px;">Doctor Name</th>
|
|
<th style="border:1px solid #ddd;padding:8px;">Nebulizers</th>
|
|
<th style="border:1px solid #ddd;padding:8px;">Allocated</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
`;
|
|
|
|
|
|
data.allemployeerequest.forEach(function (item) {
|
|
tableHtml += `
|
|
<tr>
|
|
<td style="border:1px solid #ddd;padding:8px;white-space: nowrap;">
|
|
${item.doctorName}
|
|
</td>
|
|
<td style="border:1px solid #ddd;padding:8px;text-align:center;">
|
|
${item.noofNebulizer}
|
|
</td>
|
|
<td style="border:1px solid #ddd;padding:8px;text-align:center;">
|
|
${item.patientAllocatedFromTotal}
|
|
</td>
|
|
</tr>
|
|
`;
|
|
});
|
|
|
|
tableHtml += `
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
Swal.fire({
|
|
icon: 'warning',
|
|
title: 'Message',
|
|
// html: ` <p><b>${data.message ? data.message : 'Something went wrong, please try again later!'}</b></p> ${btnHtml} `,
|
|
html: `
|
|
<p style="margin-bottom:8px;">
|
|
<b>${data.message ?? 'Something went wrong, please try again later!'}</b>
|
|
</p>
|
|
${tableHtml}
|
|
${btnHtml}
|
|
`,
|
|
showConfirmButton: false
|
|
})
|
|
|
|
}
|
|
},
|
|
error: function(xhr, status, error) {
|
|
$("#pageloader").fadeOut();
|
|
},
|
|
});
|
|
});
|
|
</script>
|
|
|
|
|
|
</body>
|
|
|
|
</html> |