Rapport-Laravel/resources/views/form/rapport-team2/1781682846-cda121aa-ae5a-48...

1217 lines
58 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" />
<link href="{{ asset('assets/libs/select2/select2.min.css') }}" rel="stylesheet" type="text/css" />
</head>
<div id="pageloader">
<img src="/images/loader-large.gif" alt="processing..." />
</div>
<body class="loading">
<div class="account-pages">
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8 col-lg-6 col-xl-5 p-0">
<div class="card">
<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 Ace Novel Meet</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 Meet 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);
@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>Activity</th>
<th>Plan Date</th>
<th>Speaker Name</th>
<th>Execution Done</th>
<th>Actual Activity Date</th>
{{-- <th>Pcode</th>
<th>Expected No. Of Attendees</th> --}}
<th>Actual No. Of Attendees</th>
</tr>
</thead>
<tbody>
@foreach ($history->data->submissions as $sub)
@php
$sub->formdata->id = $sub->id;
@endphp
<tr>
<td>
@if(isset($sub->formdata->execution_done) && $sub->formdata->execution_done == 'yes')
Executed
@else
<button type="button" class="btn btn-xs btn-info edit-btn"
plan_details="{{ json_encode($sub->formdata) }}"><i
class="mdi mdi-pencil"></i>Report Ace Novel Meet</button>
@endif
</td>
<td>{{$sub->formdata->select_activity}}</td>
<td>{{ $sub->formdata->plan_date }}</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>{{ isset($sub->formdata->execution_done) && $sub->formdata->execution_done == 'yes' ? 'Yes' : 'No' }}
</td>
<td>{{$sub->formdata->execution_date}}</td>
{{-- <td>{{isset($sub->formdata->msl_code ) ? $sub->formdata->msl_code : ''}}</td>
<td>{{isset($sub->formdata->expected_no_of_attendees) ? $sub->formdata->expected_no_of_attendees : '' }}</td> --}}
<td>{{isset($sub->formdata->actual_no_of_attendees) ? $sub->formdata->actual_no_of_attendees : '' }}
</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 }}">
<h4 class="page-title">ACE/NOVEL plan details</h4>
@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="manager_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, ['execution_date','actual_no_of_attendees' ,'hcp_name','pcode_of_wrapper_doctor','speaker_name']))
@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>
@foreach ($question->options as $option)
<option value="{{ $option->value }}" {{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }} {{ $question->code == 'contact_id' ? 'msl_code= ' . $option->contact->msl_code . ' ' : '' }} {{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }} {{ $question->code == 'contact_id' ? 'speciality= ' . (isset($option->contact->speciality) ? $option->contact->speciality :'') . ' ' : '' }} >
{{ $option->display }}
</option>
@endforeach
@if($question->code == 'contact_id')
<option value="Other">Other</option>
@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">
<h4 class="page-title">ACE/NOVEL Execution details</h4>
<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')
<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 }}"
@if(isset($question->value) && $question->value == $option->value) selected @endif
msl_code="{{ (isset($option->contact->msl_code) ? $option->contact->msl_code : '') }}"
speciality="{{ (isset($option->contact->speciality) ? $option->contact->speciality : '') }}"
>
{{ $option->display }}
</option>
@endforeach
</select>
@break
@case('checkbox')
@foreach ($question->options as $option)
<div class="form-check mb-2 form-check-primary">
<input class="form-check-input" type="checkbox"
id="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 class="doctor-group-wrapper">
<div class="row">
<div class="col-12"><h4>Add Attendees/Speaker</h4></div>
{{-- <div class="col-6"><button class="btn btn-info btn-xs float-end" type="button" id="add-doctor">Add</button></div>
</div> --}}
<div class="doctor-group row">
<div class="col-10">
@foreach ($questions as $question)
@if(in_array($question->code,['hcp_name','speaker_name']))
<label for="field-{{ $question->code }}"
class="form-label mt-2">{{ $question->question }} {!! $question->required == 'yes' ? '<span class="text-danger">*</span>' : '' !!}
</label>
<select class="form-control doctor_select" id="field-{{ $question->code }}" name="{{ $question->code }}" {{ $question->required == 'yes' ? 'required' : '' }}>
<option value=""> -- Select -- </option>
@foreach ($question->options as $option)
<option value="{{ $option->value }}" {{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }} {{ $question->code == 'hcp_name' ? 'msl_code= ' . $option->contact->msl_code . ' ' : '' }} {{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }} {{ $question->code == 'hcp_name' ? 'speciality= ' . (isset($option->contact->speciality) ? $option->contact->speciality :'') . ' ' : '' }} >
{{ $option->display }}
</option>
@endforeach
</select>
@endif
@if(in_array($question->code,['pcode_of_wrapper_doctor']))
<label for="field-{{ $question->code }}"
class="form-label mt-2">{{ $question->question }} {!! $question->required == 'yes' ? '<span class="text-danger">*</span>' : '' !!}
</label>
<input type="{{ $question->type }}" id="field-{{ $question->code }}"
name="{{ $question->code }}" class="form-control"
{{ $question->required == 'yes' ? 'required' : '' }}
value="{{ isset($question->value) ? $question->value : '' }}">
@endif
@endforeach
</div>
<div class="col-2">
<button class="btn btn-danger btn-xs float-end remove-doctor mt-4 d-none" type="button"><i class="mdi mdi-close"></i></button>
</div>
</div>
<hr style="margin:0px" />
</div>
<div class="execution-doctor-group-wrapper"></div>
@if (!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval
!= 'yes'))
<div class="text-center d-grid mt-3">
<button class="btn btn-primary" type="submit" id="submit-btn"> Submit
</button>
</div>
@endif
</form>
</div>
</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 src="{{ asset('assets/libs/select2/select2.min.js') }}"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#form-wrapper').hide()
$('#execution-form-wrapper').hide();
$('[data-toggle="select2"]').select2();
$('#field-user_id').change(function() {
$("#pageloader").fadeIn();
let hierarchy = $('option:selected', this).attr('hierarchy');
$('#field-hierarchy_id').val(hierarchy)
event.preventDefault();
$.ajax({
type: "GET",
url: '/form/getdoctorlist?partition={{$form->partition}}&hierarchy=' +
hierarchy,
processData: false,
contentType: false,
success: function(data) {
console.log("data",data);
$("#pageloader").fadeOut();
$('#field-contact_id').html('')
$('#field-contact_id').append($("<option></option>").attr("value", '')
.text('-- Select --'));
for (let itm of data) {
if (itm.contact && itm.contact.type == 'doctor') {
$('#field-contact_id').append($("<option></option>").attr("value",
itm.value).text(itm.display).attr("speciality", itm.contact.speciality).attr("msl_code", itm.contact.msl_code));
}
}
$('#field-contact_id').change(function() {
$('#field-speciality').val($('option:selected', this).attr(
'speciality'))
})
$('#field-contact_id').change(function() {
$('#field-msl_code').val($('option:selected', this).attr('msl_code'))
})
if ($('#field-contact_id').hasClass('select2-hidden-accessible')) {
$('#field-contact_id').select2('destroy');
}
$('#field-contact_id').select2();
/* Additional Speaker */
$('#field-name_of_additional_speaker').html('')
$('#field-name_of_additional_speaker').append($("<option></option>").attr("value", '')
.text('-- Select --'));
for (let itm of data) {
if (itm.contact && itm.contact.type == 'doctor') {
$('#field-name_of_additional_speaker').append($("<option></option>").attr("value",
itm.value).text(itm.display).attr("speciality", itm.contact.speciality).attr("msl_code", itm.contact.msl_code));
}
}
$('#field-name_of_additional_speaker').change(function() {
$('#field-additional_speaker_pcode').val($('option:selected', this).attr('msl_code'))
})
$('#field-additional_speaker_pcode').attr('readOnly',true);
if ($('#field-name_of_additional_speaker').hasClass('select2-hidden-accessible')) {
$('#field-name_of_additional_speaker').select2('destroy');
}
$('#field-name_of_additional_speaker').select2();
},
});
console.log(hierarchy)
})
var count = 1
let executionHierarchyId = '';
let executionPlanDetails = null;
function fillHcpSelect($select, doctors, selectedValue) {
$select.html('');
$select.append($("<option></option>").attr("value", '').text('-- Select --'));
for (let itm of doctors) {
if (itm.contact && itm.contact.type == 'doctor') {
$select.append(
$("<option></option>")
.attr("value", itm.display)
.text(itm.display)
.attr("msl_code", (itm.contact && itm.contact.msl_code) ? itm.contact.msl_code : '')
);
}
}
if ($select.hasClass('select2-hidden-accessible')) {
$select.trigger('change');
} else {
$select.select2({
width: '100%'
});
}
if (!selectedValue) {
return;
}
let normalized = String(selectedValue).trim();
let $byValue = $select.find('option[value="' + normalized.replace(/"/g, '\\"') + '"]');
if ($byValue.length) {
$select.val(normalized);
return;
}
let $byText = $select.find('option').filter(function() {
return $(this).text().trim() === normalized;
});
if ($byText.length) {
$select.val($byText.first().val());
}
}
function bindHcpPcodeLinkage($hcpSelect) {
let fieldId = $hcpSelect.attr('id') || '';
let suffix = fieldId.replace('field-hcp_name', '');
let pcodeSelector = suffix === '' ? '#field-pcode_of_wrapper_doctor' : '#field-pcode_of_wrapper_doctor' + suffix;
// NEW CODE START
let doctorNameSelector = suffix === ''
? '#field-hcp_name'
: '#field-hcp_name' + suffix;
// NEW CODE END
$hcpSelect.off('change.hcpPcode').on('change.hcpPcode', function() {
$(pcodeSelector).val($('option:selected', this).attr('msl_code') || '');
});
// NEW CODE START
$(doctorNameSelector).val(
$('option:selected', this).text()
);
// NEW CODE END
}
function loadHcpDoctorDropdowns(selectedValues) {
if (!executionHierarchyId) {
return;
}
$("#pageloader").fadeIn();
$.ajax({
type: "GET",
url: '/form/getdoctorlist?partition={{ $form->partition }}&hierarchy=' + executionHierarchyId,
success: function(data) {
$("#pageloader").fadeOut();
$('.doctor-group').each(function() {
$(this).find('select.doctor_select[id^="field-hcp_name"]').each(function() {
let $select = $(this);
let fieldName = $select.attr('name');
let selectedVal = selectedValues && selectedValues[fieldName] ? selectedValues[fieldName] : '';
fillHcpSelect($select, data, selectedVal);
bindHcpPcodeLinkage($select);
if (selectedVal) {
$select.trigger('change.hcpPcode');
}
});
});
bindUniqueDoctorSelection(); // <-- Add this line
},
error: function() {
$("#pageloader").fadeOut();
Swal.fire({
icon: 'error',
title: 'Error',
text: 'Could not load doctors for this territory.'
});
}
});
}
/* function bindUniqueDoctorSelection() {
$(document).off('change.uniqueDoctor', 'select.doctor_select');
$(document).on('change.uniqueDoctor', 'select.doctor_select', function() {
let selectedDoctors = [];
$('select.doctor_select').each(function() {
let val = $(this).val();
if (val) {
selectedDoctors.push(val);
}
});
$('select.doctor_select').each(function() {
let currentVal = $(this).val();
$(this).find('option').each(function() {
let optionVal = $(this).val();
if (
optionVal !== '' &&
optionVal !== currentVal &&
selectedDoctors.includes(optionVal)
) {
$(this).prop('disabled', true);
} else {
$(this).prop('disabled', false);
}
});
});
});
$('select.doctor_select').trigger('change.uniqueDoctor');
} */
function bindUniqueDoctorSelection() {
$(document).off(
'change.uniqueDoctor',
'select[id^="field-hcp_name"]'
);
$(document).on(
'change.uniqueDoctor',
'select[id^="field-hcp_name"]',
function() {
let selectedDoctors = [];
$('select[id^="field-hcp_name"]').each(function() {
let val = $(this).val();
if (val) {
selectedDoctors.push(val);
}
});
$('select[id^="field-hcp_name"]').each(function() {
let currentVal = $(this).val();
$(this).find('option').each(function() {
let optionVal = $(this).val();
if (
optionVal &&
optionVal !== currentVal &&
selectedDoctors.includes(optionVal)
) {
$(this).prop('disabled', true);
} else {
$(this).prop('disabled', false);
}
});
});
}
);
$('select[id^="field-hcp_name"]').trigger('change.uniqueDoctor');
}
/*function renderExecutionDoctorGroups(attendees) {
$('.execution-doctor-group-wrapper').empty();
if (attendees <= 0) {
$('.doctor-group-wrapper').hide();
return;
}
$('.doctor-group-wrapper').show();
let firstGroup = $('.doctor-group').first();
firstGroup.find('select.doctor_select').val('');
firstGroup.find('input[type=text]').val('');
for (let attendeeCount = 2; attendeeCount <= attendees; attendeeCount++) {
let doctor_html = firstGroup.html();
doctor_html = doctor_html.replaceAll('hcp_name', 'hcp_name_' + attendeeCount);
doctor_html = doctor_html.replaceAll('pcode_of_wrapper_doctor', 'pcode_of_wrapper_doctor_' + attendeeCount);
doctor_html = doctor_html.replaceAll('speaker_name', 'speaker_name_' + attendeeCount);
$('.execution-doctor-group-wrapper').append(
'<div class="doctor-group row">' + doctor_html + '</div>'
);
}
loadHcpDoctorDropdowns(executionPlanDetails);
setTimeout(function() {
bindUniqueDoctorSelection();
}, 200);
}*/
function renderExecutionDoctorGroups(attendees) {
$('.execution-doctor-group-wrapper').empty();
if (attendees <= 0) {
$('.doctor-group-wrapper').hide();
return;
}
$('.doctor-group-wrapper').show();
let firstGroup = $('.doctor-group').first();
firstGroup.find('select.doctor_select').val('');
firstGroup.find('input[type=text]').val('');
for (let attendeeCount = 2; attendeeCount <= attendees; attendeeCount++) {
let doctor_html = firstGroup.html();
doctor_html = doctor_html.replaceAll('hcp_name', 'hcp_name_' + attendeeCount);
doctor_html = doctor_html.replaceAll('pcode_of_wrapper_doctor', 'pcode_of_wrapper_doctor_' + attendeeCount);
doctor_html = doctor_html.replaceAll('speaker_name', 'speaker_name_' + attendeeCount);
let tempDiv = $('<div>').html(doctor_html);
tempDiv.find('label').each(function() {
let labelText = $(this).clone()
.children()
.remove()
.end()
.text()
.trim();
if (labelText === 'HCP Name') {
$(this).contents().first()[0].textContent =
'HCP Name ' + attendeeCount + ' ';
}
if (labelText === 'P Code') {
$(this).contents().first()[0].textContent =
'P Code ' + attendeeCount + ' ';
}
if (labelText === 'Speaker/ Attendee') {
$(this).contents().first()[0].textContent =
'Speaker/ Attendee ' + attendeeCount + ' ';
}
});
doctor_html = tempDiv.html();
$('.execution-doctor-group-wrapper').append(
'<div class="doctor-group row">' + doctor_html + '</div>'
);
}
loadHcpDoctorDropdowns(executionPlanDetails);
setTimeout(function() {
bindUniqueDoctorSelection();
}, 200);
}
$('.doctor-group-wrapper').hide();
$('#execution-actual_no_of_attendees').on('input', function() {
let attendees = parseInt($(this).val()) || 0;
if (attendees > 25) {
Swal.fire({
icon: 'warning',
title: 'Maximum Limit Exceeded',
text: 'Actual No. of Attendees cannot be greater than 25.'
});
$(this).val(25);
attendees = 25;
}
renderExecutionDoctorGroups(attendees);
});
$('.remove-doctor').click(function(){
$(this).parent().parent()[0].remove()
})
$('#field-doctor_1').change(function() {
$('#field-speciality_1').val($('option:selected', this).attr(
'speciality'))
$('#field-msl_code_1').val($('option:selected', this).attr(
'msl_code'))
})
$('#add-camp-btn').click(function() {
$('#table-wrapper').hide(0)
$('#form-wrapper').show(100, () => {
$('#add-camp-btn').hide(0);
})
})
$('#field-select_activity').on('change',function(){
$('#report-form input.dynamic-hidden').remove();
let activity=$(this).val();
if(activity==='Ace'){
$('#report-form').append('<input class="dynamic-hidden" type="hidden" name="ace_planned" value="1" />')
}
else if(activity==='Novel'){
$('#report-form').append('<input class="dynamic-hidden" type="hidden" name="novel_planned" value="1" />')
}
else{
$('#report-form').append('<input class="dynamic-hidden" type="hidden" name="no_meeting" value="0" />')
}
})
$('.edit-btn').click(function() {
$('#execution-form-wrapper').show(100, () => {
$('#add-camp-btn').hide(0);
})
$('#table-wrapper').hide()
$('#execution-plan_date').prop('readonly', true);
$('#execution-msl_code').prop('readonly',true);
$('#execution-expected_no_of_attendees').prop('readonly',true);
$('#execution-additional_speaker_pcode').prop('readonly',true);
$('#execution-eas_id').prop('readonly',true);
let contacts = document.getElementById('execution-contact_id');
contacts.addEventListener('mousedown', function(e) {
e.preventDefault();
})
let speaker = document.getElementById('execution-name_of_additional_speaker');
speaker.addEventListener('mousedown', function(e) {
e.preventDefault();
})
let meet = document.getElementById('execution-select_activity');
meet.addEventListener('mousedown', function(e) {
e.preventDefault();
})
let selected = JSON.parse($(this).attr('plan_details'));
executionHierarchyId = selected['hierarchy_id'] || '';
executionPlanDetails = selected;
if (selected['contact_id']) {
selected['contact_id'] = selected['contact_id'].trim();
}
console.log("Selected Doctor:", selected['contact_id']);
console.log("selected : ",selected);
/* for (let k of Object.keys(selected)) {
//console.log("k",k);
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 if (k == 'upload_photo_1' || k == 'upload_photo_2') {
continue;
} else {
$('#execution-' + k).val(selected[k]);
}
}
// if(selected[k] != '')
// $('#execution-'+k).val(selected[k]);
} */
for (let k of Object.keys(selected)) {
if (selected[k] != '') {
if (k == 'contact_id') {
console.log('insie')
console.log(selected['hierarchy_id'])
$.ajax({
type: "GET",
url: '/form/getdoctorlist?partition={{$form->partition}}&hierarchy=' + selected['hierarchy_id'],
processData: false,
contentType: false,
success: function(data) {
$("#pageloader").fadeOut();
$('#execution-contact_id').html('')
$('#execution-contact_id').append(
$("<option></option>").attr("value", '').text('-- Select --')
);
for (var itm of data) {
$('#execution-contact_id').append(
$("<option></option>").attr("value", itm.value).text(itm.display)
);
}
var targetText = selected[k];
var option = $("#execution-contact_id option").filter(function() {
return $(this).text().trim() === targetText;
});
if (option.length) {
$('#execution-contact_id').val(option.val());
}
console.log('actual con', selected[k]);
}
});
}
else if (k == 'name_of_additional_speaker') {
console.log('insie')
console.log(selected['hierarchy_id'])
$.ajax({
type: "GET",
url: '/form/getdoctorlist?partition={{$form->partition}}&hierarchy=' + selected['hierarchy_id'],
processData: false,
contentType: false,
success: function(data) {
$("#pageloader").fadeOut();
$('#execution-name_of_additional_speaker').html('')
$('#execution-name_of_additional_speaker').append(
$("<option></option>").attr("value", '').text('-- Select --')
);
for (var itm of data) {
$('#execution-name_of_additional_speaker').append(
$("<option></option>").attr("value", itm.value).text(itm.display)
);
}
var targetText = selected[k];
var option = $("#execution-name_of_additional_speaker option").filter(function() {
return $(this).text().trim() === targetText;
});
if (option.length) {
$('#execution-name_of_additional_speaker').val(option.val());
}
console.log('actual additional con', selected[k]);
}
});
}
else if (k == 'upload_photo_1' || k == 'upload_photo_2') {
continue;
}
else {
$('#execution-' + k).val(selected[k]);
}
}
}
let docid = $('#execution-contact_id option').map(function() {
if ($(this).text().trim() == selected['contact_id'] || $(this).val().trim() == selected['cont_id']) return this;
}).attr('value')
console.log("docid",docid);
$('#execution-contact_id').val(docid)
$('#execution-id').val(selected['id'])
let docid2 = $('#execution-name_of_additional_speaker option').map(function() {
if ($(this).text().trim() == selected['name_of_additional_speaker'] || $(this).val().trim() == selected['cont_id']) return this;
}).attr('value')
console.log("docid2",docid2);
$('#execution-name_of_additional_speaker').val(docid2)
if(selected['contact_id']==='Other'){
$('#execution-name_of_other_doctor,#execution-pcode_of_other_doctor').parent().show();
$('#execution-name_of_other_doctor,#execution-pcode_of_other_doctor').prop({"required":true});
$('#execution-msl_code').parent().hide();
$('#execution-msl_code').prop({"required":false});
}
if(selected['contact_id']!='Other'){
$('#execution-name_of_other_doctor,#execution-pcode_of_other_doctor').parent().hide();
$('#execution-name_of_other_doctor,#execution-pcode_of_other_doctor').prop({"required":false});
$('#execution-msl_code').parent().show();
$('#execution-msl_code').prop({"required":true});
}
$('#execution-hcp_name,#execution-pcode_of_wrapper_doctor,#execution-speaker_name').parent().hide();
$('#execution-hcp_name,#execution-pcode_of_wrapper_doctor,#execution-speaker_name').attr('required',false);
let activity=$('#execution-select_activity').val();
if(activity==='Ace'){
$('#execution-form').append('<input type="hidden" name="ace_executed" value="1"/>');
}
else if(activity==='Novel'){
$('#execution-form').append('<input type="hidden" name="novel_executed" value="1"/>');
}
else{
$('#execution-form').append('<input type="hidden" name="no_meeting" value="0"/>');
}
let attendees = parseInt($('#execution-actual_no_of_attendees').val()) || 0;
if (attendees > 25) {
attendees = 25;
$('#execution-actual_no_of_attendees').val(25);
}
renderExecutionDoctorGroups(attendees);
$('#execution-plan_date').css('pointer-events', 'none');
$('#execution-plan_date').css('background', '#f2f2f2');
document.querySelectorAll('[id^="field-pcode_of_wrapper_doctor"]')
.forEach(function(el) {
el.readOnly = true;
});
})
$('#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-msl_code').attr({'readonly':true});
$('#field-name_of_other_doctor,#field-pcode_of_other_doctor').parent().hide();
$('#field-name_of_other_doctor,#field-pcode_of_other_doctor').attr('required',false);
$('#field-contact_id').on('change',function(){
let value=$(this).val();
if(value==='Other'){
$('#field-name_of_other_doctor,#field-pcode_of_other_doctor').parent().show();
$('#field-name_of_other_doctor,#field-pcode_of_other_doctor').attr('required',true);
$('#field-msl_code').parent().hide();
$('#field-msl_code').attr('required',false);
}
else{
$('#field-name_of_other_doctor,#field-pcode_of_other_doctor').parent().hide();
$('#field-name_of_other_doctor,#field-pcode_of_other_doctor').attr('required',false);
$('#field-msl_code').parent().show();
$('#field-msl_code').attr('required',true);
}
})
$('#field-contact_id').change(function() {
$('#field-speciality').val($('option:selected', this).attr(
'speciality'))
})
$('#field-contact_id').change(function() {
$('#field-msl_code').val($('option:selected', this).attr('msl_code'))
})
$('#execution-form').on('submit', function(event) {
event.preventDefault();
$("#pageloader").fadeIn();
$.ajax({
type: "POST",
url: '/form/ajaxsubmit',
data: new FormData($('#execution-form')[0]),
processData: false,
contentType: false,
success: function(data) {
$("#pageloader").fadeOut();
if (data.status == 'success') {
Swal.fire({
title: 'Great!',
text: 'Your data is successfully submitted!',
icon: 'success'
})
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-execution_date');
executionexeField.setAttribute('max', executionDateField.value);
});
executionDateField.addEventListener('change', function() {
console.log('gg');
var executionexeField = document.getElementById('execution-record_date');
executionexeField.setAttribute('min', executionDateField.value);
});
});
</script>
</body>
</html>