554 lines
26 KiB
PHP
554 lines
26 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
@include('layouts.shared/title-meta', ['title' => "Form"])
|
|
@include('layouts.shared/head-css', ["mode" => $mode ?? '', "demo" => $demo ?? ''])
|
|
<link href="{{asset('assets/libs/sweetalert2/sweetalert2.min.css')}}" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<div id="pageloader">
|
|
<img src="http://cdnjs.cloudflare.com/ajax/libs/semantic-ui/0.16.1/images/loader-large.gif" alt="processing..." />
|
|
</div>
|
|
<body class="loading">
|
|
<div class="account-pages">
|
|
<div class="container">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-8 col-lg-6 col-xl-5 p-0">
|
|
<div class="card bg-pattern">
|
|
<div class="card-body p-3 row">
|
|
|
|
@if(Session::has('error'))<div class="alert alert-danger">{{Session::get('error')}}</div>
|
|
<br>@endif
|
|
@if(session('success'))<div class=" alert alert-success">{{ session('success') }}
|
|
</div>
|
|
<br>@endif
|
|
<div class="col-8">
|
|
<h4 class="page-title">{{$form->title}}</h4>
|
|
</div>
|
|
@if(!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes' ) )
|
|
<div class="col-4">
|
|
@if($form->link_type == 'form')
|
|
<a href="/form/history" class="float-end pt-1">View History</a>
|
|
@else
|
|
<a href="{{url()->previous()}}" class="float-end pt-1">Back</a>
|
|
@endif
|
|
</div>
|
|
@endif
|
|
@if(isset($form->user_info))
|
|
<div class="col-12">
|
|
<h6>Submitted By: {{$form->user_info->name}}</h6>
|
|
</div>
|
|
@endif
|
|
<form method="POST" action="/form/submit" id="report-form" enctype="multipart/form-data">
|
|
<input type="hidden" name="form_id" value="{{$form_id}}">
|
|
<input type="hidden" name="user_id" value="{{$form->user_id}}">
|
|
|
|
@csrf
|
|
@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)
|
|
<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 . ' ' : '' }}
|
|
{{ $question->code == 'contact_id' ? 'speciality= ' . (isset($option->contact->speciality) ? $option->contact->speciality :'') . ' ' : '' }} >
|
|
{{ $option->display }}
|
|
</option>
|
|
|
|
@endforeach
|
|
</select>
|
|
@break
|
|
@case('checkbox')
|
|
@foreach($question->options as $index => $option)
|
|
<div class="form-check mb-2 form-check-primary">
|
|
<input class="form-check-input" type="checkbox" id="field-{{$question->code}}-{{$option->value}}" name="{{$question->code}}[]" value="{{$option->value}}" {{isset($question->value) && $question->value != '' && in_array($option->value, $question->value) ? 'checked':''}} >
|
|
<label class="form-check-label" for="field-{{$question->code}}-{{$option->value}}">{{$option->display}}</label>
|
|
</div>
|
|
@endforeach
|
|
@break
|
|
@case('file')
|
|
@if(!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes' ) )
|
|
<input type="file" id="field-{{$question->code}}" name="{{$question->code}}" class="form-control" value="" {{$question->required == 'yes'?'required':'' }}>
|
|
@elseif(isset($question->value))
|
|
<img src="{{$question->value}}" class="img-fluid">
|
|
@endif
|
|
|
|
@break
|
|
@case('multitextbox')
|
|
<div class="row">
|
|
@foreach($question->options as $option)
|
|
<div class="col-6">{{$option->display}}</div>
|
|
<div class="col-6 mb-1">
|
|
<input type="number" id="field-{{$option->value}}" name="{{$option->value}}" class="form-control" required value="{{isset($option->val)?$option->val:0}}">
|
|
</div>
|
|
@endforeach
|
|
</div>
|
|
@break
|
|
@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> <!-- 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($){
|
|
$('#field-user_id').change(function(){
|
|
let hierarchy = $('option:selected', this).attr('hierarchy');
|
|
$('#field-hierarchy_id').val(hierarchy)
|
|
event.preventDefault();
|
|
$.ajax({
|
|
type: "GET",
|
|
url: '/form/getdoctorlist?partition={{$form->partition}}&hierarchy='+hierarchy,
|
|
processData: false,
|
|
contentType: false,
|
|
success: function( data ) {
|
|
$("#pageloader").fadeOut();
|
|
$('#field-contact_id').html('')
|
|
$('#field-contact_id').append($("<option></option>").attr("value",'').text('-- Select --'));
|
|
for (let itm of data) {
|
|
$('#field-contact_id').append($("<option></option>").attr("value",itm.value).text(itm.display).attr("msl_code", itm.contact.msl_code));
|
|
}
|
|
|
|
$('#field-contact_id').change(function() {
|
|
$('#field-msl_code').val($('option:selected', this).attr('msl_code'))
|
|
})
|
|
},
|
|
});
|
|
|
|
console.log(hierarchy)
|
|
})
|
|
|
|
$('#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'))
|
|
})
|
|
|
|
$('#field-if_no_way,#field-other_trigger_for_patient_inquiry,#field-other_factors_when_stocking_a_nebulizer_brand,#field-chemist_attached_to_other').parent().hide();
|
|
$('#field-if_no_way,#field-other_trigger_for_patient_inquiry,#field-other_factors_when_stocking_a_nebulizer_brand,#field-chemist_attached_to_other').prop('required',false);
|
|
|
|
$('#field-chemist_attached_to-Other').on('change',function(){
|
|
let check=$(this).is(":checked");
|
|
if(check){
|
|
$('#field-chemist_attached_to_other').parent().show();
|
|
$('#field-chemist_attached_to_other').attr('required',true);
|
|
|
|
}
|
|
else{
|
|
$('#field-chemist_attached_to_other').parent().hide();
|
|
$('#field-chemist_attached_to_other').attr('required',false);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
$('#field-nebulizers_kept_in_regular_stock-No').on('change',function(){
|
|
let check=$(this).is(":checked");
|
|
if(check){
|
|
$('#field-if_no_way').parent().show();
|
|
$('#field-if_no_way').attr('required',true);
|
|
|
|
}
|
|
else{
|
|
$('#field-if_no_way').parent().hide();
|
|
$('#field-if_no_way').attr('required',false);
|
|
}
|
|
|
|
})
|
|
|
|
$('#field-what_matters_most_to_you_when_stocking_nebulizer_brand-Other').on('change',function(){
|
|
let check=$(this).is(":checked");
|
|
if(check){
|
|
$('#field-other_factors_when_stocking_a_nebulizer_brand').parent().show();
|
|
$('#field-other_factors_when_stocking_a_nebulizer_brand').attr('required',true);
|
|
|
|
}
|
|
else{
|
|
$('#field-other_factors_when_stocking_a_nebulizer_brand').parent().hide();
|
|
$('#field-other_factors_when_stocking_a_nebulizer_brand').attr('required',false);
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
$('#field-what_is_the_main_trigger_for_patient_inquiry-Other').on('change',function(){
|
|
let check=$(this).is(":checked");
|
|
if(check){
|
|
$('#field-other_trigger_for_patient_inquiry').parent().show();
|
|
$('#field-other_trigger_for_patient_inquiry').attr('required',true);
|
|
}
|
|
else{
|
|
$('#field-other_trigger_for_patient_inquiry').parent().hide();
|
|
$('#field-other_trigger_for_patient_inquiry').attr('required',false);
|
|
}
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$('input[name="chemist_attached_to[]"]').on('change', function () {
|
|
|
|
if ($(this).is(':checked')) {
|
|
|
|
// Uncheck all except current
|
|
$('input[name="chemist_attached_to[]"]').not(this).prop('checked', false);
|
|
|
|
if ($(this).attr('id') !== 'field-chemist_attached_to-Other') {
|
|
$('#field-chemist_attached_to_other').parent().hide();
|
|
$('#field-chemist_attached_to_other').prop('required', false);
|
|
$('#field-chemist_attached_to_other').val('');
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
$('#field-chemist_name, #field-region_area').on('input', function () {
|
|
this.value = this.value.replace(/[^a-zA-Z ]/g, '');
|
|
});
|
|
|
|
|
|
|
|
$('input[name="nebulizers_kept_in_regular_stock[]"]').on('change', function () {
|
|
|
|
if ($(this).is(':checked')) {
|
|
|
|
// Uncheck all except current
|
|
$('input[name="nebulizers_kept_in_regular_stock[]"]').not(this).prop('checked', false);
|
|
|
|
if ($(this).attr('id') !== 'field-nebulizers_kept_in_regular_stock-No') {
|
|
$('#field-if_no_way').parent().hide();
|
|
$('#field-if_no_way').prop('required', false);
|
|
$('#field-if_no_way').val('');
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$('input[name="how_many_brands_are_readily[]"]').on('change', function () {
|
|
|
|
if ($(this).is(':checked')) {
|
|
|
|
// Uncheck all except current
|
|
$('input[name="how_many_brands_are_readily[]"]').not(this).prop('checked', false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$('input[name="in_30_days_how_many_nebulizer_purchases[]"]').on('change', function () {
|
|
|
|
if ($(this).is(':checked')) {
|
|
|
|
// Uncheck all except current
|
|
$('input[name="in_30_days_how_many_nebulizer_purchases[]"]').not(this).prop('checked', false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$('input[name="average_nebulizer_cost_purchased_by_patients[]"]').on('change', function () {
|
|
|
|
if ($(this).is(':checked')) {
|
|
|
|
// Uncheck all except current
|
|
$('input[name="average_nebulizer_cost_purchased_by_patients[]"]').not(this).prop('checked', false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$('input[name="how_much_discount_are_given_on_current_nebulizer[]"]').on('change', function () {
|
|
|
|
if ($(this).is(':checked')) {
|
|
|
|
// Uncheck all except current
|
|
$('input[name="how_much_discount_are_given_on_current_nebulizer[]"]').not(this).prop('checked', false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$('input[name="how_often_do_companies_provide_rate_discounts[]"]').on('change', function () {
|
|
|
|
if ($(this).is(':checked')) {
|
|
|
|
// Uncheck all except current
|
|
$('input[name="how_often_do_companies_provide_rate_discounts[]"]').not(this).prop('checked', false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
$('label[for="field-record_date"]').html("Date<span class='text-danger'>*</span>");
|
|
$('label[for="field-chemist_name"]').html("Chemist Name<span class='text-danger'>*</span>");
|
|
$('label[for="field-region_area"]').html("Region / Area name<span class='text-danger'>*</span>");
|
|
$('label[for="field-chemist_attached_to"]').html("Chemist attached to<span class='text-danger'>*</span>");
|
|
$('label[for="field-chemist_attached_to_other"]').html("Chemist attached to (Other)<span class='text-danger'>*</span>");
|
|
$('label[for="field-nebulizers_kept_in_regular_stock"]').html("Nebulizers kept in regular stock ?<span class='text-danger'>*</span>");
|
|
$('label[for="field-if_no_way"]').html("If No, why?<span class='text-danger'>*</span>");
|
|
$('label[for="field-how_many_brands_are_readily"]').html("How many brands are readily available in regular stock?<span class='text-danger'>*</span>");
|
|
$('label[for="field-in_30_days_how_many_nebulizer_purchases"]').html("In 30 days, how many nebulizer purchases have been completed?<span class='text-danger'>*</span>");
|
|
$('label[for="field-what_is_the_main_trigger_for_patient_inquiry"]').html("What is the main trigger for patient inquiry?<span class='text-danger'>*</span>");
|
|
$('label[for="field-other_trigger_for_patient_inquiry"]').html("Other Trigger for patient inquiry?<span class='text-danger'>*</span>");
|
|
$('label[for="field-brand_1"]').html("Top 3 brands asked by name from customers<br>Brand 1<span class='text-danger'>*</span>");
|
|
$('label[for="field-brand_2"]').html("Brand 2");
|
|
$('label[for="field-brand_3"]').html("Brand 3");
|
|
$('label[for="field-average_nebulizer_cost_purchased_by_patients"]').html("Average Nebulizer cost purchased by patients?<span class='text-danger'>*</span>");
|
|
$('label[for="field-how_much_discount_are_given_on_current_nebulizer"]').html("How much discount % are given on current available nebulizer machines in the market?<span class='text-danger'>*</span>");
|
|
$('label[for="field-how_often_do_companies_provide_rate_discounts"]').html("How often do companies provide rate discounts / incentives?<span class='text-danger'>*</span>");
|
|
$('label[for="field-what_matters_most_to_you_when_stocking_nebulizer_brand"]').html("What matters most to you when stocking a nebulizer brand?<span class='text-danger'>*</span>");
|
|
$('label[for="field-other_factors_when_stocking_a_nebulizer_brand"]').html("Other factor that matters<span class='text-danger'>*</span>");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// $('#report-form').on('submit', function(event){
|
|
// event.preventDefault();
|
|
|
|
// if ($('input[name="chemist_attached_to[]"]:checked').length === 0) {
|
|
// event.preventDefault();
|
|
// alert('Please select at least one option for Chemist attached to.');
|
|
// }
|
|
|
|
// if ($('input[name="nebulizers_kept_in_regular_stock[]"]:checked').length === 0) {
|
|
// event.preventDefault();
|
|
// alert('Please select at least one option for Nebulizers kept in regular stock.');
|
|
// }
|
|
|
|
// if ($('input[name="how_many_brands_are_readily[]"]:checked').length === 0) {
|
|
// event.preventDefault();
|
|
// alert('Please select at least one option for Nebulizers kept in regular stock.');
|
|
// }
|
|
|
|
// if ($('input[name="in_30_days_how_many_nebulizer_purchases[]"]:checked').length === 0) {
|
|
// event.preventDefault();
|
|
// alert('Please select at least one option for Nebulizers kept in regular stock.');
|
|
// }
|
|
|
|
// if ($('input[name="what_is_the_main_trigger_for_patient_inquiry[]"]:checked').length === 0) {
|
|
// event.preventDefault();
|
|
// alert('Please select at least one option for Nebulizers kept in regular stock.');
|
|
// }
|
|
|
|
// if ($('input[name="average_nebulizer_cost_purchased_by_patients[]"]:checked').length === 0) {
|
|
// event.preventDefault();
|
|
// alert('Please select at least one option for Nebulizers kept in regular stock.');
|
|
// }
|
|
|
|
// if ($('input[name="how_much_discount_are_given_on_current_nebulizer[]"]:checked').length === 0) {
|
|
// event.preventDefault();
|
|
// alert('Please select at least one option for Nebulizers kept in regular stock.');
|
|
// }
|
|
|
|
// if ($('input[name="how_often_do_companies_provide_rate_discounts[]"]:checked').length === 0) {
|
|
// event.preventDefault();
|
|
// alert('Please select at least one option for Nebulizers kept in regular stock.');
|
|
// }
|
|
|
|
// if ($('input[name="what_matters_most_to_you_when_stocking_nebulizer_brand[]"]:checked').length === 0) {
|
|
// event.preventDefault();
|
|
// alert('Please select at least one option for Nebulizers kept in regular stock.');
|
|
// }
|
|
|
|
|
|
// const formData = new FormData($('#report-form')[0]);
|
|
|
|
// // Log form data to console
|
|
// for (let [key, value] of formData.entries()) {
|
|
// console.log(key, value);
|
|
// }
|
|
|
|
|
|
// $("#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'
|
|
// })
|
|
// $('#report-form').trigger("reset");
|
|
// } else {
|
|
// Swal.fire({
|
|
// icon: 'error',
|
|
// title: 'Data not submitted',
|
|
// text: 'Something went wrong, please try again after some time!'
|
|
// })
|
|
// }
|
|
// },
|
|
// });
|
|
// });
|
|
|
|
$('#report-form').on('submit', function(event){
|
|
|
|
event.preventDefault();
|
|
|
|
let checkboxGroups = [
|
|
'chemist_attached_to[]',
|
|
'nebulizers_kept_in_regular_stock[]',
|
|
'how_many_brands_are_readily[]',
|
|
'in_30_days_how_many_nebulizer_purchases[]',
|
|
'what_is_the_main_trigger_for_patient_inquiry[]',
|
|
'average_nebulizer_cost_purchased_by_patients[]',
|
|
'how_much_discount_are_given_on_current_nebulizer[]',
|
|
'how_often_do_companies_provide_rate_discounts[]',
|
|
'what_matters_most_to_you_when_stocking_nebulizer_brand[]'
|
|
];
|
|
|
|
let isValid = true;
|
|
|
|
for (let i = 0; i < checkboxGroups.length; i++) {
|
|
|
|
if ($('input[name="'+checkboxGroups[i]+'"]:checked').length === 0) {
|
|
isValid = false;
|
|
alert('Please select at least one option for all required questions.');
|
|
break; // stop checking further
|
|
}
|
|
}
|
|
|
|
if (!isValid) {
|
|
return; // 🔥 STOP here — do NOT run AJAX
|
|
}
|
|
|
|
// If validation passed, run AJAX
|
|
const formData = new FormData($('#report-form')[0]);
|
|
|
|
$("#pageloader").fadeIn();
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: '/form/ajaxsubmit',
|
|
data: formData,
|
|
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'
|
|
});
|
|
$('#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 plandateField = document.getElementById('field-record_date');
|
|
|
|
plandateField.setAttribute('max', today);
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html> |