1356 lines
64 KiB
PHP
1356 lines
64 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="/images/loader-large.gif" alt="processing..." />
|
|
</div>
|
|
|
|
{{-- @php
|
|
$history = Formhelper::getMultiformData($form->partition, $form->form_id, $form->user_id);
|
|
|
|
echo '<pre>';
|
|
|
|
foreach ($history->data->submissions as $index => $item) {
|
|
|
|
echo "Submission #".($index + 1)."\n";
|
|
echo "------------------------\n";
|
|
echo "Plan Date : " . ($item->formdata->plan_date ?? '-') . "\n";
|
|
echo "Type of Dr : " . ($item->formdata->type_of_dr ?? '-') . "\n";
|
|
echo "Planned Devices : " . ($item->formdata->how_many_flutter_devices_are_you_planning_to_give ?? '-') . "\n";
|
|
echo "Given Devices : " . ($item->formdata->how_many_flutter_devices_given ?? '-') . "\n";
|
|
echo "\n";
|
|
}
|
|
|
|
echo '</pre>';
|
|
exit;
|
|
@endphp --}}
|
|
|
|
|
|
@php
|
|
$monthlygiven = 0;
|
|
$submissionMeta = [];
|
|
|
|
// current month only
|
|
$selectedMonth = date('Y-m');
|
|
|
|
// ensure history exists
|
|
$history = $history ?? Formhelper::getMultiformData(
|
|
$form->partition,
|
|
$form->form_id,
|
|
$form->user_id
|
|
);
|
|
|
|
if (!empty($history->data->submissions)) {
|
|
foreach ($history->data->submissions as $item) {
|
|
|
|
$type = $item->formdata->type_of_dr ?? '';
|
|
$planDate = $item->formdata->plan_date ?? null;
|
|
$given = (int) ($item->formdata->how_many_flutter_devices_given ?? 0);
|
|
|
|
// ✅ monthly given calculation (UNCHANGED)
|
|
if (
|
|
$type === 'Flutter Dr' &&
|
|
$planDate &&
|
|
strtotime($planDate) !== false &&
|
|
date('Y-m', strtotime($planDate)) === $selectedMonth
|
|
) {
|
|
$monthlygiven += $given;
|
|
}
|
|
|
|
// ✅ NEW: collect id + createdAt safely
|
|
if (!empty($item->id) && !empty($item->createdAt)) {
|
|
$submissionMeta[] = [
|
|
'id' => $item->id,
|
|
'created_at' => $item->createdAt, // keep snake_case for JS clarity
|
|
];
|
|
}
|
|
}
|
|
}
|
|
/*
|
|
echo "<div class='container'>";
|
|
echo "<pre>";
|
|
print_r($history->data->submissions);
|
|
echo "</pre>";
|
|
|
|
echo "</div>";
|
|
*/
|
|
@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">
|
|
<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">Report Camp</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> -->
|
|
<button type="button" class="btn btn-primary btn-xs" id="add-camp-btn">Add
|
|
Plan</button>
|
|
@else
|
|
<a href="{{ url()->previous() }}" class="float-end pt-1">Back</a>
|
|
@endif
|
|
</div>
|
|
@endif
|
|
|
|
@php
|
|
$history = Formhelper::getMultiformData($form->partition, $form->form_id, $form->user_id);
|
|
|
|
// echo "<pre>"; print_r($history);
|
|
|
|
@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>Camp Plan Date</th>
|
|
<th>Execution Done</th>
|
|
<th>Doctor Name</th>
|
|
{{-- <th>Other Doctor Name</th> --}}
|
|
<th>Camp Execution Date</th>
|
|
<th>Legacy Code</th>
|
|
<th>Speciality</th>
|
|
<th>Type of Dr</th>
|
|
<th>Camp Planned Start Time</th>
|
|
<th>OPD Timing</th>
|
|
<th>Executed as per plan</th>
|
|
<th>Revised start time</th>
|
|
<th>Patient Screened</th>
|
|
<th>Patients Diagnosed</th>
|
|
<th>Erdostyne Capsule Rxn</th>
|
|
<th>Erdostyne Suspension Rxn</th>
|
|
<th>Total Rxns</th>
|
|
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach ($history->data->submissions as $sub)
|
|
@php
|
|
$sub->formdata->id = $sub->id;
|
|
$sub->formdata->createdAtForm = $sub->createdAt;
|
|
@endphp
|
|
|
|
|
|
@php
|
|
|
|
|
|
$sub->formdata->id = $sub->id;
|
|
|
|
// Parse plan date safely
|
|
$planDate = isset($sub->formdata->plan_date) ? \Carbon\Carbon::parse($sub->formdata->plan_date) : null;
|
|
|
|
// Define current date and allowed date range
|
|
$now = \Carbon\Carbon::now();
|
|
$startOfCurrentMonth = $now->copy()->startOfMonth();
|
|
$fifthOfNextMonth = $now->copy()->addMonth()->startOfMonth()->addDays(4); // 5th of next month
|
|
|
|
|
|
@endphp
|
|
|
|
|
|
<tr>
|
|
<td>
|
|
|
|
@if ( $planDate && $planDate->between($startOfCurrentMonth, $fifthOfNextMonth) && $now->greaterThanOrEqualTo($planDate))
|
|
<button type="button" class="btn btn-xs btn-info edit-btn"
|
|
plan_details="{{ json_encode($sub->formdata) }}"><i
|
|
class="mdi mdi-pencil"></i> Edit</button>
|
|
|
|
|
|
{{-- @elseif ($sub->workflow_status == 'rejected' ||
|
|
(isset($sub->formdata->execution_done) && $sub->formdata->execution_done == 'no'))
|
|
<button type="button" class="btn btn-xs btn-info edit-plan-btn"
|
|
plan_details="{{ json_encode($sub->formdata) }}">
|
|
<i class="mdi mdi-pencil"></i> Edit Plan
|
|
</button> --}}
|
|
@endif
|
|
</td>
|
|
<td>{{ $sub->formdata->plan_date }}</td>
|
|
<td>{{ isset($sub->formdata->execution_done) && $sub->formdata->execution_done == 'yes' ? 'Yes' : 'No' }}
|
|
</td>
|
|
|
|
<td>
|
|
@if (isset($sub->formdata->contact_id) && $sub->formdata->contact_id
|
|
!== '')
|
|
{{ $sub->formdata->contact_id }}
|
|
@elseif (isset($sub->formdata->doctor_name))
|
|
{{ $sub->formdata->doctor_name }}
|
|
@else
|
|
{{-- Default value or empty string, adjust as needed --}}
|
|
{{ '' }}
|
|
@endif
|
|
</td>
|
|
{{-- <td>
|
|
@if (isset($sub->formdata->contact_id_2) && $sub->formdata->contact_id_2
|
|
!== '')
|
|
{{ $sub->formdata->contact_id_2 }}
|
|
@elseif (isset($sub->formdata->doctor_name))
|
|
{{ $sub->formdata->doctor_name }}
|
|
@else
|
|
|
|
{{ '' }}
|
|
@endif
|
|
</td> --}}
|
|
<td>{{$sub->formdata->execution_date}}</td>
|
|
<td>{{isset($sub->formdata->msl_code) ? $sub->formdata->msl_code : '' }}
|
|
</td>
|
|
<td>{{isset($sub->formdata->speciality) ? $sub->formdata->speciality: ''}}
|
|
</td>
|
|
<td>{{isset($sub->formdata->type_of_dr) ? $sub->formdata->type_of_dr: ''}}
|
|
</td>
|
|
|
|
<td>{{isset($sub->formdata->camp_planned_start_time) ? $sub->formdata->camp_planned_start_time: ''}}
|
|
</td>
|
|
<td>{{isset($sub->formdata->opd_timing) ? $sub->formdata->opd_timing: ''}}
|
|
</td>
|
|
<td>{{isset($sub->formdata->executed_as_per_plan) ? $sub->formdata->executed_as_per_plan: ''}}
|
|
</td>
|
|
<td>{{isset($sub->formdata->revised_start_time) ? $sub->formdata->revised_start_time: ''}}
|
|
</td>
|
|
<td>{{isset($sub->formdata->patient_screened) ? $sub->formdata->patient_screened: ''}}
|
|
</td>
|
|
<td>{{isset($sub->formdata->patients_diagnosed) ? $sub->formdata->patients_diagnosed: ''}}
|
|
</td>
|
|
<td>{{isset($sub->formdata->erdostyne_capsule_rxn) ? $sub->formdata->erdostyne_capsule_rxn: ''}}
|
|
</td>
|
|
<td>{{isset($sub->formdata->erdostyne_suspension_rxn) ? $sub->formdata->erdostyne_suspension_rxn: ''}}
|
|
</td>
|
|
<td>{{isset($sub->formdata->total_rxns) ? $sub->formdata->total_rxns: ''}}
|
|
</td>
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="form-wrapper">
|
|
<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="form_id" value="{{ $form_id }}">
|
|
|
|
|
|
@csrf
|
|
@if ($id)
|
|
<input type="hidden" name="id" value="{{ $id }}">
|
|
@endif
|
|
@foreach ($questions as $question)
|
|
@if (in_array($question->code, ['execution_date','executed_as_per_plan' ,'revised_camp_start_time','patient_screened','patients_diagnosed','erdostyne_capsule_rxn','erdostyne_suspension_rxn','total_rxns','how_many_flutter_devices_given']))
|
|
@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')
|
|
<select class="form-control" id="field-{{ $question->code }}" name="{{ $question->code }}" {{ $question->required == 'yes' ? 'required' : '' }}>
|
|
<option value=""> -- Select -- </option>
|
|
@if ($question->code == 'contact_id')
|
|
@foreach ($question->options as $option)
|
|
@if ($option->contact->type == 'doctor')
|
|
<option value="{{ $option->value }}"
|
|
msl_code="{{isset($option->contact->legacy_code)?$option->contact->legacy_code:''}}"
|
|
speciality="{{isset($option->contact->speciality)?$option->contact->speciality:''}}" {{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}
|
|
ardc_css_restricted_drs="{{isset($option->contact->ardc_css_restricted_drs)?$option->contact->ardc_css_restricted_drs:''}}"
|
|
|
|
>
|
|
{{ $option->display }}
|
|
</option>
|
|
@endif
|
|
|
|
@endforeach
|
|
{{-- <option value="others" {{ isset($question->value) && $question->value == 'others' ? 'selected' : '' }}>
|
|
others
|
|
</option> --}}
|
|
@elseif($question->code=='contact_id_2')
|
|
@foreach ($question->options as $option)
|
|
|
|
<option value="{{ $option->value }}" msl_code="{{isset($option->contact->legacy_code)?$option->contact->legacy_code:''}}" speciality="{{isset($option->contact->speciality)?$option->contact->speciality:''}}" {{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}>
|
|
{{ $option->display }}
|
|
</option>
|
|
|
|
@endforeach
|
|
|
|
@else
|
|
@foreach ($question->options as $option)
|
|
<option value="{{ $option->value }}" {{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}>
|
|
{{ $option->display }}
|
|
</option>
|
|
@endforeach
|
|
@endif
|
|
</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 }}[]" 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')
|
|
<input type="file" id="field-{{ $question->code }}" name="{{ $question->code }}"
|
|
class="form-control" value="" accept="image/jpg, image/jpeg, image/png"
|
|
required>
|
|
@break
|
|
@endswitch
|
|
</div>
|
|
@endforeach
|
|
@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>
|
|
|
|
<div id="execution-form-wrapper">
|
|
<form method="POST" action="/form/submit" id="execution-form"
|
|
enctype="multipart/form-data">
|
|
<input type="hidden" name="form_id" value="{{ $form_id }}">
|
|
@csrf
|
|
<input type="hidden" name="id" value="" id="execution-id">
|
|
{{-- <input type="hidden" name="execution_done" value="yes"> --}}
|
|
@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="0" 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')
|
|
@if ($question->code == 'contact_id')
|
|
<select class="form-control" id="execution-{{ $question->code }}"
|
|
name="{{ $question->code }}"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>
|
|
<option value=""> -- Select -- </option>
|
|
@foreach ($question->options as $option)
|
|
@if ($option->contact->type == 'doctor')
|
|
<option value="{{ $option->value }}"
|
|
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}
|
|
msl_code="{{ isset($option->contact->msl_code) ? $option->contact->msl_code : '' }}"
|
|
speciality="{{ isset($option->contact->speciality) ? $option->contact->speciality : '' }}">
|
|
{{ $option->display }}
|
|
</option>
|
|
@endif
|
|
@endforeach
|
|
{{-- <option value="others"{{ isset($question->value) && $question->value == 'others' ? 'selected' : '' }}>
|
|
others
|
|
</option> --}}
|
|
|
|
</select>
|
|
|
|
@elseif ($question->code == 'contact_id_2')
|
|
<select class="form-control" id="execution-{{ $question->code }}"
|
|
name="{{ $question->code }}"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>
|
|
<option value=""> -- Select -- </option>
|
|
@foreach ($question->options as $option)
|
|
@if ($option->contact->type == 'doctor')
|
|
<option value="{{ $option->value }}"
|
|
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}
|
|
msl_code="{{ isset($option->contact->msl_code) ? $option->contact->msl_code : '' }}"
|
|
speciality="{{ isset($option->contact->speciality) ? $option->contact->speciality : '' }}">
|
|
{{ $option->display }}
|
|
</option>
|
|
@endif
|
|
@endforeach
|
|
<option value="others"{{ isset($question->value) && $question->value == 'others' ? 'selected' : '' }}>
|
|
others
|
|
</option>
|
|
|
|
</select>
|
|
|
|
@else
|
|
<select class="form-control" id="execution-{{ $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' : '' }}>
|
|
{{ $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="execution-{{ $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="execution-{{ $question->code }}-{{ $option->value }}">{{ $option->display }}</label>
|
|
</div>
|
|
@endforeach
|
|
@break
|
|
|
|
@case('file')
|
|
<input type="file" id="execution-{{ $question->code }}"
|
|
name="{{ $question->code }}" class="form-control" value=""
|
|
accept="image/jpg, image/jpeg, image/png">
|
|
@break
|
|
@endswitch
|
|
</div>
|
|
|
|
@endforeach
|
|
<div id="errorMessage"></div>
|
|
<div id="errorMessage2"></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>
|
|
|
|
</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 type="text/javascript">
|
|
jQuery(document).ready(function($) {
|
|
$('#form-wrapper').hide()
|
|
$('#execution-form-wrapper').hide()
|
|
|
|
// $('#add-camp-btn').click(function() {
|
|
// $('#form-wrapper').show()
|
|
// $('#table-wrapper').hide()
|
|
// })
|
|
|
|
$('#add-camp-btn').click(function() {
|
|
$('#table-wrapper').hide(0)
|
|
$('#form-wrapper').show(100, () => {
|
|
$('#add-camp-btn').hide(0);
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
$('#execution-revised_camp_start_time').parent().hide();
|
|
$('#execution-revised_camp_start_time').prop({"required":false});
|
|
|
|
// $('#execution-executed_as_per_plan').on('change',function(){
|
|
// var dropDown=$('#execution-executed_as_per_plan').val();
|
|
// console.log("DropDown is : ",dropDown);
|
|
// if(dropDown==='Yes'){
|
|
// $('#execution-revised_camp_start_time').parent().hide();
|
|
// $('#execution-revised_camp_start_time').prop({"required":false});
|
|
// }
|
|
// else if(dropDown==='No'){
|
|
// $('#execution-revised_camp_start_time').parent().show();
|
|
// $('#execution-revised_camp_start_time').prop({"required":true});
|
|
// }
|
|
// })
|
|
|
|
$('#execution-erdostyne_capsule_rxn,#execution-erdostyne_suspension_rxn').on('change',function(){
|
|
var a=parseInt($('#execution-erdostyne_capsule_rxn').val())||0;
|
|
var b=parseInt($('#execution-erdostyne_suspension_rxn').val())||0;
|
|
|
|
|
|
var total =a+b;
|
|
$('#execution-total_rxns').val(total);
|
|
|
|
});
|
|
|
|
$('#execution-total_rxns').prop({"readonly":true});
|
|
//$('#execution-executed_as_per_plan').prop("disabled",true);
|
|
|
|
$('.edit-btn').click(function() {
|
|
$('#execution-form-wrapper').show(100, () => {
|
|
$('#add-camp-btn').hide(0);
|
|
})
|
|
$('#table-wrapper').hide()
|
|
//$('#execution-contact_id').prop('disabled', true)
|
|
$('#execution-contact_id').prop('readonly', true)
|
|
// $('#execution-activity_type').prop('readonly', true)
|
|
$('#execution-speciality').prop('readonly', true)
|
|
$('#execution-plan_date').prop('readonly', true)
|
|
$('#execution-uid').prop('readonly',true);
|
|
//$('#execution-time').prop('disabled', true)
|
|
|
|
let contact = document.getElementById('execution-contact_id');
|
|
contact.addEventListener('mousedown', function(e) {
|
|
e.preventDefault();
|
|
})
|
|
|
|
/* let contact2 = document.getElementById('execution-contact_id_2');
|
|
contact2.addEventListener('mousedown', function(e) {
|
|
e.preventDefault();
|
|
}) */
|
|
|
|
// let typeOfDr = document.getElementById('execution-type_of_dr');
|
|
// typeOfDr.addEventListener('mousedown', function(e) {
|
|
// e.preventDefault();
|
|
// })
|
|
|
|
let selected = JSON.parse($(this).attr('plan_details'))
|
|
console.log("Plan Detail : ", selected);
|
|
if (selected['contact_id']) {
|
|
selected['contact_id'] = selected['contact_id'].trim();
|
|
}
|
|
console.log("Selected Doctor : ", selected['contact_id']);
|
|
if(selected['contact_id']==='others'){
|
|
$('#execution-contact_id_2').parent().show();
|
|
$('#execution-contact_id_2').prop('required',true);
|
|
|
|
$('#execution-contact_id').parent().hide();
|
|
$('#execution-contact_id').prop('required',false);
|
|
|
|
}
|
|
else{
|
|
$('#execution-contact_id_2').parent().hide();
|
|
$('#execution-contact_id_2').prop('required',false);
|
|
|
|
|
|
$('#execution-contact_id').parent().show();
|
|
$('#execution-contact_id').prop('required',true);
|
|
}
|
|
|
|
|
|
for (let k of Object.keys(selected)) {
|
|
if (selected[k] != '') {
|
|
if (k == 'contact_id') {
|
|
//$("#execution-contact_id option:contains(" + selected[k] + ")").prop('selected', true)
|
|
// console.log($("#execution-contact_id option:contains(" + selected[k] + ")").attr('value'))
|
|
$('#execution-contact_id').val($("#execution-contact_id option:contains(" +
|
|
selected[k] + ")").attr('value'));
|
|
} else
|
|
$('#execution-' + k).val(selected[k]);
|
|
}
|
|
// if(selected[k] != '')
|
|
// $('#execution-'+k).val(selected[k]);
|
|
}
|
|
let docid = $('#execution-contact_id option').map(function() {
|
|
if ($(this).text().trim() == selected['contact_id']) return this;
|
|
}).attr('value')
|
|
$('#execution-contact_id').val(docid)
|
|
$('#execution-id').val(selected['id'])
|
|
|
|
let docid2 = $('#execution-contact_id_2 option').map(function() {
|
|
if ($(this).text().trim() == selected['contact_id_2']) return this;
|
|
}).attr('value')
|
|
$('#execution-contact_id_2').val(docid2)
|
|
$('#execution-id').val(selected['id'])
|
|
|
|
$('#execution-form').append('<input type="hidden" name="execution_done" value="yes">');
|
|
|
|
const typeDr = $('#execution-type_of_dr').val();
|
|
const flutterDiv = $('#execution-how_many_flutter_devices_are_you_planning_to_give')
|
|
.closest('.col-md-12');
|
|
const flutterGivenDiv = $('#execution-how_many_flutter_devices_given')
|
|
.closest('.col-md-12');
|
|
|
|
if (typeDr === 'Flutter Dr') {
|
|
flutterDiv.show();
|
|
flutterGivenDiv.show();
|
|
$('#execution-how_many_flutter_devices_given').prop('required',true);
|
|
$('#execution-how_many_flutter_devices_are_you_planning_to_give').prop('required',true);
|
|
|
|
} else {
|
|
flutterDiv.hide();
|
|
flutterGivenDiv.hide();
|
|
$('#execution-how_many_flutter_devices_are_you_planning_to_give').val('');
|
|
$('#execution-how_many_flutter_devices_given').prop('required',false);
|
|
$('#execution-how_many_flutter_devices_are_you_planning_to_give').prop('required',false);
|
|
}
|
|
|
|
// newfield
|
|
$('#execution-type_of_dr, #execution-how_many_flutter_devices_are_you_planning_to_give')
|
|
.on('mousedown keydown change', function (e) {
|
|
e.preventDefault();
|
|
$(this).blur();
|
|
});
|
|
|
|
$('#execution-how_many_flutter_devices_given')
|
|
.closest('.col-md-12.mb-2')
|
|
.insertAfter(
|
|
$('#execution-how_many_flutter_devices_are_you_planning_to_give')
|
|
.closest('.col-md-12.mb-2')
|
|
);
|
|
})
|
|
|
|
|
|
/*
|
|
$('.edit-plan-btn').click(function() {
|
|
$('#execution-form-wrapper').show(100, () => {
|
|
$('#add-camp-btn').hide(0);
|
|
})
|
|
$('#table-wrapper').hide()
|
|
//$('#execution-contact_id').prop('disabled', true)
|
|
//$('#execution-contact_id').prop('readonly', true)
|
|
// $('#execution-activity_type').prop('readonly', true)
|
|
$('#execution-speciality').prop('readonly', true)
|
|
$('#execution-plan_date').prop('readonly', true)
|
|
$('#execution-uid').prop('readonly',true);
|
|
//$('#execution-time').prop('disabled', true)
|
|
|
|
$('#execution-execution_date,#execution-executed_as_per_plan,#execution-patient_screened,#execution-patients_diagnosed,#execution-erdostyne_capsule_rxn,#execution-erdostyne_suspension_rxn,#execution-total_rxns,#execution-how_many_flutter_devices_given').parent().hide();
|
|
$('#execution-execution_date,#execution-executed_as_per_plan,#execution-patient_screened,#execution-patients_diagnosed,#execution-erdostyne_capsule_rxn,#execution-erdostyne_suspension_rxn,#execution-total_rxns,#execution-how_many_flutter_devices_given').prop('required',false);
|
|
|
|
|
|
let selected = JSON.parse($(this).attr('plan_details'))
|
|
console.log("Plan Detail : ", selected);
|
|
if (selected['contact_id']) {
|
|
selected['contact_id'] = selected['contact_id'].trim();
|
|
}
|
|
console.log("Selected Doctor : ", selected['contact_id']);
|
|
if(selected['contact_id']==='others'){
|
|
$('#execution-contact_id_2').parent().show();
|
|
$('#execution-contact_id_2').prop('required',true);
|
|
|
|
$('#execution-contact_id').parent().hide();
|
|
$('#execution-contact_id').prop('required',false);
|
|
|
|
}
|
|
else{
|
|
$('#execution-contact_id_2').parent().hide();
|
|
$('#execution-contact_id_2').prop('required',false);
|
|
|
|
|
|
$('#execution-contact_id').parent().show();
|
|
$('#execution-contact_id').prop('required',true);
|
|
}
|
|
|
|
|
|
|
|
|
|
for (let k of Object.keys(selected)) {
|
|
if (selected[k] != '') {
|
|
if (k == 'contact_id') {
|
|
//$("#execution-contact_id option:contains(" + selected[k] + ")").prop('selected', true)
|
|
// console.log($("#execution-contact_id option:contains(" + selected[k] + ")").attr('value'))
|
|
$('#execution-contact_id').val($("#execution-contact_id option:contains(" +
|
|
selected[k] + ")").attr('value'));
|
|
} else
|
|
$('#execution-' + k).val(selected[k]);
|
|
}
|
|
// if(selected[k] != '')
|
|
// $('#execution-'+k).val(selected[k]);
|
|
}
|
|
let docid = $('#execution-contact_id option').map(function() {
|
|
if ($(this).text().trim() == selected['contact_id']) return this;
|
|
}).attr('value')
|
|
$('#execution-contact_id').val(docid)
|
|
$('#execution-id').val(selected['id'])
|
|
|
|
let docid2 = $('#execution-contact_id_2 option').map(function() {
|
|
if ($(this).text().trim() == selected['contact_id_2']) return this;
|
|
}).attr('value')
|
|
$('#execution-contact_id_2').val(docid2)
|
|
$('#execution-id').val(selected['id'])
|
|
|
|
|
|
$('#execution-contact_id').change(function() {
|
|
$('#execution-speciality').val($('option:selected', this).attr('speciality'))
|
|
})
|
|
|
|
$('#execution-contact_id').change(function() {
|
|
$('#execution-msl_code').val($('option:selected', this).attr('msl_code'))
|
|
})
|
|
|
|
|
|
$('#execution-contact_id_2').change(function() {
|
|
$('#execution-speciality').val($('option:selected', this).attr('speciality'))
|
|
})
|
|
|
|
$('#execution-contact_id_2').change(function() {
|
|
$('#execution-msl_code').val($('option:selected', this).attr('msl_code'))
|
|
})
|
|
|
|
// newfield
|
|
const $typeDr = $('#execution-type_of_dr');
|
|
const $flutterSelect = $('#execution-how_many_flutter_devices_are_you_planning_to_give');
|
|
const $flutterDiv = $flutterSelect.closest('.col-md-12');
|
|
|
|
function toggleFlutter() {
|
|
if ($typeDr.val() === 'Flutter Dr') {
|
|
$flutterDiv.slideDown();
|
|
$flutterSelect.prop('required', true);
|
|
} else {
|
|
$flutterDiv.slideUp();
|
|
$flutterSelect.prop('required', false);
|
|
$flutterSelect.val('');
|
|
}
|
|
}
|
|
toggleFlutter();
|
|
$typeDr.on('change', toggleFlutter);
|
|
})
|
|
|
|
*/
|
|
|
|
|
|
$('#report-form').on('submit', function(event) {
|
|
event.preventDefault();
|
|
|
|
$("#pageloader").fadeIn();
|
|
$.ajax({
|
|
type: "POST",
|
|
url: '/form/ajaxsubmit',
|
|
data: new FormData($('#report-form')[0]),
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(data) {
|
|
$("#pageloader").fadeOut();
|
|
if (data.status == 'success') {
|
|
Swal.fire({
|
|
title: 'Great!',
|
|
text: 'Your data is successfully submitted!',
|
|
icon: 'success'
|
|
})
|
|
window.location.reload();
|
|
//$('#report-form').trigger("reset");
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Data not submitted',
|
|
text: 'Something went wrong, please try again after some time!'
|
|
})
|
|
}
|
|
},
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#field-contact_id').change(function() {
|
|
|
|
})
|
|
|
|
$('#field-contact_id').change(function() {
|
|
$('#field-speciality').val($('option:selected', this).attr('speciality'))
|
|
$('#field-msl_code').val($('option:selected', this).attr('msl_code'))
|
|
let restricted=$(this).find(":selected").attr('ardc_css_restricted_drs');
|
|
console.log("restricted:",restricted);
|
|
if (restricted === 'Yes') {
|
|
|
|
alert('Planning with these Doctors not allowed');
|
|
|
|
// Deselect current option
|
|
$(this).val('').trigger('change');
|
|
|
|
// Clear msl code as well
|
|
$('#field-msl_code').val('');
|
|
}
|
|
})
|
|
|
|
|
|
$('#field-contact_id_2').parent().hide();
|
|
$('#field-contact_id_2').prop('required',false);
|
|
|
|
$('#field-contact_id').on('change',function(){
|
|
let val=$(this).val();
|
|
console.log(val);
|
|
if(val==='others'){
|
|
$('#field-contact_id_2').parent().show();
|
|
$('#field-contact_id_2').prop('required',true);
|
|
}
|
|
else{
|
|
$('#field-contact_id_2').parent().hide();
|
|
$('#field-contact_id_2').prop('required',false);
|
|
}
|
|
})
|
|
|
|
$('#field-msl_code').prop('readonly',true);
|
|
//$('#field-speciality').prop('readonly',true);
|
|
|
|
|
|
$('#field-contact_id_2').change(function() {
|
|
$('#field-speciality').val($('option:selected', this).attr('speciality'))
|
|
})
|
|
|
|
$('#field-contact_id_2').change(function() {
|
|
$('#field-msl_code').val($('option:selected', this).attr('msl_code'))
|
|
|
|
})
|
|
|
|
$('#execution-form').on('submit', function(event) {
|
|
event.preventDefault();
|
|
let patientsDiagnosedCount=parseInt(document.getElementById('execution-patients_diagnosed').value) ||0;
|
|
let totalRxn=parseInt(document.getElementById('execution-total_rxns').value)||0;
|
|
let patientsScreened=parseInt(document.getElementById('execution-patient_screened').value) ||0;
|
|
console.log("Patients Screened : ",patientsScreened);
|
|
console.log("Patients diagnosed :",patientsDiagnosedCount);
|
|
console.log("Total RXns: ",totalRxn);
|
|
|
|
|
|
if((patientsDiagnosedCount>patientsScreened) ){
|
|
$('#errorMessage').html('<p style="text-align:center;color:red">*Kindly review ,Your Patients Diagnosed is exceeding Total Patients Screened !</p>');
|
|
return;
|
|
}
|
|
else if(totalRxn>patientsDiagnosedCount){
|
|
$('#errorMessage2').html('<p style="text-align:center;color:red">*Kindly review,Your Total Rxns is exceeding Patients Diagnosed !</p>');
|
|
return;
|
|
}
|
|
else{
|
|
$('#errorMessage').html('');
|
|
$('#errorMessage2').html('');
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$("#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'
|
|
})
|
|
window.location.reload();
|
|
//$('#report-form').trigger("reset");
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Data not submitted',
|
|
text: 'Something went wrong, please try again after some time!'
|
|
})
|
|
}
|
|
},
|
|
});
|
|
});
|
|
|
|
var today = new Date();
|
|
var dd = String(today.getDate()).padStart(2, '0');
|
|
var mm = String(today.getMonth() + 1).padStart(2, '0');
|
|
var yyyy = today.getFullYear();
|
|
today = yyyy + '-' + mm + '-' + dd;
|
|
|
|
var recordDateField = document.getElementById('field-plan_date');
|
|
recordDateField.setAttribute('min', today);
|
|
|
|
var executionDateField = document.getElementById('execution-plan_date');
|
|
//executionDateField.setAttribute('min', today);
|
|
|
|
// $('.edit-btn').click(function() {
|
|
// var executionexeField = document.getElementById('execution-record_date');
|
|
// executionexeField.setAttribute('min', executionDateField.value);
|
|
// });
|
|
|
|
$('.edit-btn').click(function() {
|
|
var executionexeField = document.getElementById('execution-execution_date');
|
|
executionexeField.setAttribute('min', executionDateField.value);
|
|
});
|
|
|
|
$('#execution-execution_date').on('change',function(){
|
|
var executionexeField = document.getElementById('execution-execution_date').value;
|
|
var recordDateField = document.getElementById('execution-plan_date').value;
|
|
if(recordDateField!=executionexeField){
|
|
$('#execution-executed_as_per_plan').val('No');
|
|
$('#execution-revised_camp_start_time').parent().show();
|
|
}
|
|
else{
|
|
$('#execution-executed_as_per_plan').val('Yes');
|
|
$('#execution-revised_camp_start_time').parent().hide();
|
|
$('#execution-revised_camp_start_time').prop({"required":false});
|
|
}
|
|
})
|
|
|
|
|
|
executionDateField.addEventListener('change', function() {
|
|
console.log('gg');
|
|
var executionexeField = document.getElementById('execution-record_date');
|
|
executionexeField.setAttribute('min', executionDateField.value);
|
|
});
|
|
|
|
});
|
|
</script>
|
|
|
|
<script>
|
|
$(document).ready(function () {
|
|
|
|
const $typeDr = $('#field-type_of_dr');
|
|
const $flutterSelect = $('#field-how_many_flutter_devices_are_you_planning_to_give');
|
|
const $flutterDiv = $flutterSelect.closest('.col-md-12');
|
|
|
|
$flutterDiv.hide();
|
|
$flutterSelect.prop('required', false);
|
|
|
|
function toggleFlutter() {
|
|
if ($typeDr.val() === 'Flutter Dr') {
|
|
$flutterDiv.slideDown();
|
|
$flutterSelect.prop('required', true);
|
|
} else {
|
|
$flutterDiv.slideUp();
|
|
$flutterSelect.prop('required', false);
|
|
$flutterSelect.val('');
|
|
}
|
|
}
|
|
|
|
$typeDr.on('change', toggleFlutter);
|
|
|
|
});
|
|
</script>
|
|
|
|
<script>
|
|
const MONTHLY_FLUTTER_LIMIT = 15;
|
|
//const alreadymonthlygivenFlutter = 14;
|
|
|
|
const alreadymonthlygivenFlutter = {{ $monthlygiven }};
|
|
|
|
console.log('MONTHLY_FLUTTER_LIMIT:', MONTHLY_FLUTTER_LIMIT);
|
|
console.log('alreadymonthlygivenFlutter:', alreadymonthlygivenFlutter);
|
|
|
|
const submissionMeta = @json($submissionMeta);
|
|
console.log('submissionMeta:', submissionMeta);
|
|
|
|
</script>
|
|
|
|
<script>
|
|
$(document).ready(function () {
|
|
|
|
const MONTHLY_FLUTTER_LIMIT = 15;
|
|
const alreadyGivenFlutter = alreadymonthlygivenFlutter; // from PHP
|
|
|
|
// -------------------------------
|
|
// Selectors (create + edit)
|
|
// -------------------------------
|
|
const $plannedSelect = $(
|
|
'#field-how_many_flutter_devices_are_you_planning_to_give, ' +
|
|
'#execution-how_many_flutter_devices_are_you_planning_to_give'
|
|
);
|
|
|
|
const $givenSelect =
|
|
$('#execution-how_many_flutter_devices_given');
|
|
|
|
// Store original values (important for edit)
|
|
$plannedSelect.each(function () {
|
|
$(this).data('original', parseInt($(this).val() || 0));
|
|
});
|
|
|
|
$givenSelect.each(function () {
|
|
$(this).data('original', parseInt($(this).val() || 0));
|
|
});
|
|
|
|
// -------------------------------
|
|
// Planned devices restriction
|
|
// -------------------------------
|
|
$plannedSelect.on('change', function () {
|
|
|
|
const $this = $(this);
|
|
const selectedValue = parseInt($this.val() || 0);
|
|
|
|
const $typeDr = $this.closest('form').find(
|
|
'#field-type_of_dr, #execution-type_of_dr'
|
|
);
|
|
|
|
if ($typeDr.val() !== 'Flutter Dr') return;
|
|
|
|
const totalAfterSelection =
|
|
alreadyGivenFlutter + selectedValue;
|
|
|
|
if (totalAfterSelection > MONTHLY_FLUTTER_LIMIT) {
|
|
|
|
Swal.fire({
|
|
icon: 'warning',
|
|
title: 'Monthly Limit Exceeded',
|
|
html: `
|
|
You can plan <b>maximum ${MONTHLY_FLUTTER_LIMIT} Flutter devices</b> in a month.<br><br>
|
|
<b>Already given:</b> ${alreadyGivenFlutter}<br>
|
|
<b>Trying to plan:</b> ${selectedValue}
|
|
`,
|
|
confirmButtonText: 'OK'
|
|
});
|
|
|
|
$this.val('');
|
|
}
|
|
});
|
|
|
|
// -------------------------------
|
|
// GIVEN devices restriction
|
|
// -------------------------------
|
|
$givenSelect.on('change', function () {
|
|
|
|
const $this = $(this);
|
|
const selectedValue = parseInt($this.val() || 0);
|
|
|
|
const $typeDr = $this.closest('form').find(
|
|
'#field-type_of_dr, #execution-type_of_dr'
|
|
);
|
|
|
|
if ($typeDr.val() !== 'Flutter Dr') return;
|
|
|
|
const originalValue = parseInt($this.data('original') || 0);
|
|
|
|
const effectiveGiven =
|
|
alreadyGivenFlutter - originalValue + selectedValue;
|
|
|
|
if (effectiveGiven > MONTHLY_FLUTTER_LIMIT) {
|
|
|
|
Swal.fire({
|
|
icon: 'warning',
|
|
title: 'Monthly Given Limit Exceeded',
|
|
html: `
|
|
You can give <b>maximum ${MONTHLY_FLUTTER_LIMIT} Flutter devices</b> in a month.<br><br>
|
|
<b>Already given:</b> ${alreadyGivenFlutter - originalValue}<br>
|
|
<b>Trying to give:</b> ${selectedValue}
|
|
`,
|
|
confirmButtonText: 'OK'
|
|
});
|
|
|
|
// revert to previous value
|
|
$this.val(originalValue || '');
|
|
}
|
|
});
|
|
|
|
});
|
|
</script>
|
|
|
|
<script>
|
|
$(document).ready(function () {
|
|
|
|
const cutoffDate = '2026-01-08'; // lock records ON or BEFORE this date
|
|
|
|
const $typeSelect = $('#field-type_of_dr, #execution-type_of_dr');
|
|
|
|
const $plannedSelect = $(
|
|
'#field-how_many_flutter_devices_are_you_planning_to_give,' +
|
|
'#execution-how_many_flutter_devices_are_you_planning_to_give'
|
|
);
|
|
|
|
const $givenSelect = $('#execution-how_many_flutter_devices_given');
|
|
|
|
// -------------------------------
|
|
// STORE ORIGINAL VALUES (EDIT SAFE)
|
|
// -------------------------------
|
|
$plannedSelect.each(function () {
|
|
$(this).data('original', parseInt($(this).val() || 0));
|
|
});
|
|
|
|
$givenSelect.each(function () {
|
|
$(this).data('original', parseInt($(this).val() || 0));
|
|
});
|
|
|
|
// -------------------------------
|
|
// PLANNED DEVICES LIMIT
|
|
// -------------------------------
|
|
$plannedSelect.on('change', function () {
|
|
|
|
if ($typeSelect.val() !== 'Flutter Dr') return;
|
|
|
|
const selected = parseInt($(this).val() || 0);
|
|
const original = parseInt($(this).data('original') || 0);
|
|
|
|
const effectiveTotal = alreadyMonthlyGiven - original + selected;
|
|
|
|
if (effectiveTotal > MONTHLY_FLUTTER_LIMIT) {
|
|
|
|
Swal.fire({
|
|
icon: 'warning',
|
|
title: 'Monthly Limit Exceeded',
|
|
html: `
|
|
<b>Limit:</b> ${MONTHLY_FLUTTER_LIMIT}<br>
|
|
<b>Already given:</b> ${alreadyMonthlyGiven - original}<br>
|
|
<b>Trying to plan:</b> ${selected}
|
|
`
|
|
});
|
|
|
|
$(this).val(original || '');
|
|
}
|
|
});
|
|
|
|
// -------------------------------
|
|
// GIVEN DEVICES LIMIT
|
|
// -------------------------------
|
|
$givenSelect.on('change', function () {
|
|
|
|
if ($typeSelect.val() !== 'Flutter Dr') return;
|
|
|
|
const selected = parseInt($(this).val() || 0);
|
|
const original = parseInt($(this).data('original') || 0);
|
|
|
|
const effectiveTotal =
|
|
alreadyMonthlyGiven - original + selected;
|
|
|
|
if (effectiveTotal > MONTHLY_FLUTTER_LIMIT) {
|
|
|
|
Swal.fire({
|
|
icon: 'warning',
|
|
title: 'Monthly Given Limit Exceeded',
|
|
html: `
|
|
<b>Limit:</b> ${MONTHLY_FLUTTER_LIMIT}<br>
|
|
<b>Already given:</b> ${alreadyMonthlyGiven - original}<br>
|
|
<b>Trying to give:</b> ${selected}
|
|
`
|
|
});
|
|
|
|
$(this).val(original || '');
|
|
}
|
|
});
|
|
|
|
// -------------------------------
|
|
// EDIT MODE FIELD LOCKING
|
|
// -------------------------------
|
|
$(document).on('click', '.edit-btn, .edit-plan-btn', function () {
|
|
|
|
let details = {};
|
|
try {
|
|
details = JSON.parse($(this).attr('plan_details').replace(/"/g, '"'));
|
|
} catch {
|
|
return;
|
|
}
|
|
console.log('details', details);
|
|
if (!details.createdAtForm) return;
|
|
|
|
// 🔑 ISO date string comparison
|
|
if (details.createdAtForm > cutoffDate) return;
|
|
|
|
const fieldsToLock = [
|
|
'#execution-how_many_flutter_devices_are_you_planning_to_give',
|
|
'#execution-how_many_flutter_devices_given'
|
|
];
|
|
|
|
fieldsToLock.forEach(selector => {
|
|
|
|
const $field = $(selector);
|
|
if (!$field.length) return;
|
|
|
|
$field.prop('disabled', true)
|
|
.removeAttr('required');
|
|
|
|
$field.closest('.col-md-12, .form-group').hide();
|
|
});
|
|
});
|
|
|
|
});
|
|
</script>
|
|
|
|
<script>
|
|
|
|
// Existing submissions
|
|
let submissions = @json($history->data->submissions);
|
|
|
|
function markMonthlyAddedDoctors() {
|
|
|
|
// Current month & year
|
|
let today = new Date();
|
|
|
|
let currentMonth = today.getMonth();
|
|
let currentYear = today.getFullYear();
|
|
|
|
// Store doctors already added this month
|
|
let addedDoctors = [];
|
|
|
|
submissions.forEach(function(submission){
|
|
|
|
let doctorName = submission.formdata?.contact_id ?? '';
|
|
let planDate = submission.formdata?.plan_date ?? '';
|
|
|
|
if (!doctorName || !planDate) return;
|
|
|
|
let existingDate = new Date(planDate);
|
|
|
|
let existingMonth = existingDate.getMonth();
|
|
let existingYear = existingDate.getFullYear();
|
|
|
|
// Same current month + year
|
|
if (
|
|
existingMonth === currentMonth &&
|
|
existingYear === currentYear
|
|
) {
|
|
addedDoctors.push(doctorName.trim());
|
|
}
|
|
|
|
});
|
|
|
|
// Update dropdown options
|
|
$('#field-contact_id option').each(function(){
|
|
|
|
let optionText = $(this).text().replace(' (Already added)', '').trim();
|
|
|
|
// Reset old text
|
|
$(this).text(optionText);
|
|
|
|
// Skip placeholder
|
|
if ($(this).val() === '') return;
|
|
|
|
// If doctor already added this month
|
|
if (addedDoctors.includes(optionText)) {
|
|
|
|
$(this).text(optionText + ' (Already added)');
|
|
$(this).attr('data-added', 'yes');
|
|
|
|
} else {
|
|
|
|
$(this).removeAttr('data-added');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// Run initially
|
|
markMonthlyAddedDoctors();
|
|
|
|
// Prevent selection
|
|
$('#field-contact_id').change(function () {
|
|
|
|
let selectedOption = $(this).find(':selected');
|
|
|
|
let alreadyAdded = selectedOption.attr('data-added');
|
|
|
|
if (alreadyAdded === 'yes') {
|
|
|
|
alert('Doctor already added in this month');
|
|
|
|
$(this).val('').trigger('change');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html> |