593 lines
28 KiB
PHP
593 lines
28 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="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}}">
|
|
@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 data-toggle="select2">
|
|
<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
|
|
|
|
@php
|
|
$recordDateQuestion = null;
|
|
$doctorQuestions = [];
|
|
foreach ($questions as $q) {
|
|
if (isset($q->code) && $q->code === 'record_date') {
|
|
$recordDateQuestion = $q;
|
|
} else {
|
|
$doctorQuestions[] = $q;
|
|
}
|
|
}
|
|
@endphp
|
|
|
|
@if($recordDateQuestion)
|
|
<div class="col-md-12 mb-2">
|
|
<label for="field-{{$recordDateQuestion->code}}" class="form-label">{{$recordDateQuestion->question}} {!!$recordDateQuestion->required == 'yes' ? '<span class="text-danger">*</span>':''!!} </label>
|
|
<input type="{{$recordDateQuestion->type}}" id="field-{{$recordDateQuestion->code}}" name="{{$recordDateQuestion->code}}" class="form-control" {{$recordDateQuestion->required == 'yes'?'required':'' }} value="{{isset($recordDateQuestion->value)?$recordDateQuestion->value:''}}">
|
|
</div>
|
|
@endif
|
|
|
|
{{-- <div class="col-12 mb-2">
|
|
<button type="button" class="btn btn-outline-primary btn-sm" id="add-doctor-btn">Add Doctor</button>
|
|
</div> --}}
|
|
|
|
<div class="col-12" id="doctor-cards">
|
|
<div class="card doctor-card border border-2 mb-3">
|
|
<div class="card-body p-2">
|
|
<div class="d-flex align-items-end mb-2">
|
|
{{-- <div class="fw-bold">Doctor</div> --}}
|
|
<button type="button" class="btn btn-outline-danger btn-sm remove-doctor-btn d-none ms-auto">Remove</button>
|
|
</div>
|
|
|
|
@foreach($doctorQuestions as $question)
|
|
<div class="col-md-12 mb-2 doctor-field">
|
|
<label class="form-label">{{$question->question}} {!!$question->required == 'yes' ? '<span class="text-danger">*</span>':''!!} </label>
|
|
@switch($question->type)
|
|
@case('hidden')
|
|
<input type="{{$question->type}}" name="{{$question->code}}[]" data-code="{{$question->code}}" value="{{isset($question->value)?$question->value:''}}">
|
|
@break
|
|
@case('text')
|
|
@case('email')
|
|
@case('tel')
|
|
@case('date')
|
|
<input type="{{$question->type}}" name="{{$question->code}}[]" data-code="{{$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" name="{{$question->code}}[]" data-code="{{$question->code}}" class="form-control" {{$question->required == 'yes'?'required':'' }} value="{{isset($question->value)?$question->value:0}}">
|
|
@break
|
|
@case('textarea')
|
|
<textarea name="{{$question->code}}[]" data-code="{{$question->code}}" class="form-control" {{$question->required == 'yes'?'required':'' }}>{{isset($question->value)?$question->value:''}}</textarea>
|
|
@break
|
|
@case('dropdown')
|
|
<select class="form-control js-select2 {{ $question->code == 'contact_id' ? 'js-contact-id' : '' }} {{ $question->code == 'campaign_type' ? 'js-campaign-type' : '' }}" name="{{ $question->code }}[]" data-code="{{ $question->code }}" {{$question->required == 'yes'?'required':'' }} data-toggle="select2">
|
|
<option value=""> -- Select -- </option>
|
|
@foreach($question->options as $option)
|
|
@php
|
|
$legacy_code = isset($option->contact) ? $option->contact->legacy_code ?? '' : '';
|
|
$speciality = isset($option->contact) ? $option->contact->speciality ?? '' : '';
|
|
@endphp
|
|
<option value="{{$option->value}}"
|
|
{{isset($question->value) && $question->value == $option->value ? 'selected':''}}
|
|
@if($question->code == 'contact_id')
|
|
doctor_pcode="{{$legacy_code}}"
|
|
speciality="{{$speciality}}"
|
|
@endif
|
|
>{{$option->display}}</option>
|
|
@endforeach
|
|
</select>
|
|
|
|
@if($question->code == 'campaign_type')
|
|
<input type="hidden" class="js-campaign-opt1" name="campaign_type_7_pm_conversion_campaign[]" data-code="campaign_type_7_pm_conversion_campaign" value="0">
|
|
<input type="hidden" class="js-campaign-opt2" name="campaign_type_mlc_a_pedia_campaign[]" data-code="campaign_type_mlc_a_pedia_campaign" value="0">
|
|
@endif
|
|
@break
|
|
@case('radio')
|
|
@foreach($question->options as $option)
|
|
<div class="form-check mb-2 form-check-success">
|
|
<input class="form-check-input" type="radio" name="{{$question->code}}[]" data-code="{{$question->code}}" value="{{$option->value}}">
|
|
<label class="form-check-label">{{$option->display}}</label>
|
|
</div>
|
|
@endforeach
|
|
@break
|
|
@case('checkbox')
|
|
@foreach($question->options as $option)
|
|
<div class="form-check mb-2 form-check-primary ms-2">
|
|
<input class="form-check-input" type="checkbox" name="{{$question->code}}[][]" data-code="{{$question->code}}" value="{{$option->value}}" {{isset($question->value) && $question->value != '' && in_array($option->value, $question->value) ? 'checked':''}}>
|
|
<label class="form-check-label">{{$option->display}}</label>
|
|
</div>
|
|
@endforeach
|
|
@break
|
|
@case('file')
|
|
@if(!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes' ) )
|
|
<input type="file" name="{{$question->code}}[]" data-code="{{$question->code}}" class="form-control" value="" {{$question->required == 'yes'?'required':'' }}>
|
|
@elseif(isset($question->value))
|
|
<img src="{{$question->value}}" class="img-fluid">
|
|
@endif
|
|
@break
|
|
@endswitch
|
|
</div>
|
|
@endforeach
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@if(!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes' ) )
|
|
<div class="d-grid mt-3">
|
|
<button type="button" class="btn btn-outline-primary btn-sm" id="add-doctor-btn">Add Doctor</button>
|
|
</div>
|
|
<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 -->
|
|
|
|
</div> <!-- end col -->
|
|
</div>
|
|
<!-- end row -->
|
|
</div>
|
|
<!-- end container -->
|
|
</div>
|
|
<!-- end page -->
|
|
|
|
<style type="text/css">
|
|
#pageloader {
|
|
background: rgba( 255, 255, 255, 0.8 );
|
|
display: none;
|
|
height: 100%;
|
|
position: fixed;
|
|
width: 100%;
|
|
z-index: 9999;
|
|
}
|
|
|
|
#pageloader img {
|
|
left: 50%;
|
|
margin-left: -32px;
|
|
margin-top: -32px;
|
|
position: absolute;
|
|
top: 50%;
|
|
}
|
|
|
|
.form-label {
|
|
font-weight:bold;
|
|
font-size:16px;
|
|
}
|
|
</style>
|
|
|
|
@include('layouts.shared/footer-script')
|
|
<script src="{{asset('assets/libs/sweetalert2/sweetalert2.min.js')}}"></script>
|
|
<script src="{{ asset('assets/libs/select2/select2.min.js') }}"></script>
|
|
|
|
<script type="text/javascript">
|
|
jQuery(document).ready(function($){
|
|
initSelect2In($(document));
|
|
|
|
function syncCampaignTypeHidden($card) {
|
|
const $sel = $card.find('.js-campaign-type');
|
|
const val = ($sel.val() || '').toString();
|
|
const text = ($sel.find('option:selected').text() || '').toString();
|
|
const opt1 = '7 PM Conversion Campaign';
|
|
const opt2 = 'MLC A @Pedia Campaign';
|
|
|
|
const norm = (s) => (s || '')
|
|
.toString()
|
|
.replace(/&/g, '&')
|
|
.replace(/\s+/g, ' ')
|
|
.trim()
|
|
.toLowerCase();
|
|
|
|
const isOpt1 = norm(val) === norm(opt1) || norm(text) === norm(opt1);
|
|
const isOpt2 = norm(val) === norm(opt2) || norm(text) === norm(opt2);
|
|
$card.find('.js-campaign-opt1').val(isOpt1 ? 1 : 0);
|
|
$card.find('.js-campaign-opt2').val(isOpt2 ? 1 : 0);
|
|
}
|
|
|
|
function syncDoctorFieldsFromSelected($card) {
|
|
const $opt = $card.find('.js-contact-id option:selected');
|
|
const pcode = ($opt.attr('doctor_pcode') || '').toString();
|
|
const speciality = ($opt.attr('speciality') || '').toString();
|
|
$card.find('[data-code="doctor_pcode"]').val(pcode);
|
|
$card.find('[data-code="speciality"]').val(speciality);
|
|
}
|
|
|
|
function handleCampaignTypeChange(el) {
|
|
const $card = $(el).closest('.doctor-card');
|
|
syncCampaignTypeHidden($card);
|
|
}
|
|
|
|
$('#doctor-cards').on('change', '.js-campaign-type', function() {
|
|
handleCampaignTypeChange(this);
|
|
});
|
|
// Select2 sometimes triggers select events more reliably than native change
|
|
$('#doctor-cards').on('select2:select select2:clear', '.js-campaign-type', function() {
|
|
handleCampaignTypeChange(this);
|
|
});
|
|
|
|
$('#doctor-cards').on('change', '.js-contact-id', function() {
|
|
const $card = $(this).closest('.doctor-card');
|
|
syncDoctorFieldsFromSelected($card);
|
|
});
|
|
|
|
function resetDoctorCard($card) {
|
|
$card.find('input[type="text"], input[type="email"], input[type="tel"], input[type="number"], textarea').val('');
|
|
$card.find('input[type="hidden"]').each(function() {
|
|
const code = ($(this).attr('data-code') || '').toString();
|
|
if (code.indexOf('campaign_type_') === 0) {
|
|
$(this).val('0');
|
|
} else {
|
|
$(this).val('');
|
|
}
|
|
});
|
|
$card.find('input[type="checkbox"]').prop('checked', false);
|
|
$card.find('input[type="radio"]').prop('checked', false);
|
|
$card.find('select').each(function() {
|
|
$(this).val('');
|
|
}).trigger('change.select2');
|
|
}
|
|
|
|
function initSelect2In($root) {
|
|
$root.find('[data-toggle="select2"]').each(function() {
|
|
const $el = $(this);
|
|
if ($el.data('select2')) return;
|
|
$el.select2({ width: '100%' });
|
|
});
|
|
}
|
|
|
|
$('#add-doctor-btn').on('click', function() {
|
|
const $first = $('#doctor-cards .doctor-card').first();
|
|
const $clone = $first.clone(false, false);
|
|
|
|
// Clean select2 artifacts copied in DOM (container + attributes)
|
|
$clone.find('span.select2').remove();
|
|
$clone.find('select').each(function() {
|
|
$(this)
|
|
.removeClass('select2-hidden-accessible')
|
|
.removeAttr('data-select2-id')
|
|
.removeAttr('tabindex')
|
|
.removeAttr('aria-hidden')
|
|
.removeAttr('aria-controls')
|
|
.removeAttr('aria-labelledby');
|
|
});
|
|
$clone.find('option').removeAttr('data-select2-id');
|
|
|
|
$clone.find('.remove-doctor-btn').removeClass('d-none');
|
|
resetDoctorCard($clone);
|
|
$('#doctor-cards').append($clone);
|
|
initSelect2In($clone);
|
|
// Ensure initial hidden sync in new card
|
|
syncCampaignTypeHidden($clone);
|
|
syncDoctorFieldsFromSelected($clone);
|
|
});
|
|
|
|
$('#doctor-cards').on('click', '.remove-doctor-btn', function() {
|
|
$(this).closest('.doctor-card').remove();
|
|
});
|
|
|
|
// Populate doctor list on territory/user change (same pattern as other team4 forms)
|
|
$('#field-user_id').change(function(){
|
|
$("#pageloader").fadeIn();
|
|
const 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();
|
|
const $selects = $('#doctor-cards .js-contact-id');
|
|
if (!$selects.length) return;
|
|
$selects.html('');
|
|
$selects.append($("<option></option>").attr("value", '').text('-- Select --'));
|
|
for (let itm of data) {
|
|
$selects.append(
|
|
$("<option></option>")
|
|
.attr("value", itm.value)
|
|
.attr("doctor_pcode", itm.contact.legacy_code || '')
|
|
.attr("speciality", itm.contact.speciality || '')
|
|
.text(itm.display)
|
|
);
|
|
}
|
|
$selects.trigger('change.select2');
|
|
$('#doctor-cards .doctor-card').each(function() {
|
|
const $card = $(this);
|
|
syncDoctorFieldsFromSelected($card);
|
|
});
|
|
},
|
|
error: function() {
|
|
$("#pageloader").fadeOut();
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
// Define doctor dropdown
|
|
let $doctorSelect = $('.js-contact-id');
|
|
|
|
// Store original options
|
|
let originalOptions = $doctorSelect.find('option').clone();
|
|
|
|
$(document).on('change', '.js-campaign-type', function () {
|
|
|
|
/* let selectedCampaign = $(this).html(); */
|
|
let selectedCampaign = ($(this).val() || '').trim();
|
|
|
|
selectedCampaign = selectedCampaign.replace(/@/g, '').replace(/\s+/g, ' ').trim();
|
|
|
|
|
|
/* if (selectedCampaign === '7 PM Conversion Campaign') {
|
|
console.log("Selected 7 PM");
|
|
$('[data-code="rxs_given_for_montair_lc_adult"]')
|
|
.attr('min', 15);
|
|
|
|
} else if (selectedCampaign === 'MLC A Pedia Campaign') {
|
|
console.log("Selected MLC A");
|
|
$('[data-code="rxs_given_for_montair_lc_adult"]')
|
|
.attr('min', 8);
|
|
|
|
} */
|
|
|
|
|
|
let $wrapper2 = $(this).closest('.doctor-card');
|
|
|
|
let $rxField = $wrapper2.find('[data-code="rxs_given_for_montair_lc_adult"]');
|
|
|
|
if (selectedCampaign === '7 PM Conversion Campaign') {
|
|
console.log("Selected 7 PM");
|
|
|
|
$rxField.attr('min', 15);
|
|
|
|
} else if (selectedCampaign === 'MLC A Pedia Campaign') {
|
|
console.log("Selected MLC A");
|
|
|
|
$rxField.attr('min', 8);
|
|
}
|
|
|
|
|
|
|
|
console.log("Selected Campaign:", selectedCampaign);
|
|
|
|
let $wrapper = $(this).closest('.doctor-card');
|
|
|
|
// Doctor dropdown ONLY inside current wrapper
|
|
$doctorSelect = $wrapper.find('.js-contact-id');
|
|
|
|
// Destroy select2 temporarily
|
|
$doctorSelect.select2('destroy');
|
|
|
|
// Empty dropdown
|
|
$doctorSelect.empty();
|
|
|
|
// Array to collect pediatrician doctors
|
|
let pediatricianDoctors = [];
|
|
|
|
// Loop through original options
|
|
originalOptions.each(function () {
|
|
|
|
let $option = $(this).clone();
|
|
/* console.log($option); */
|
|
|
|
let speciality = ($option.attr('speciality') || '').trim();
|
|
|
|
|
|
/* console.log("Speciality:", speciality); */
|
|
|
|
// Keep default option
|
|
if ($option.val() === '') {
|
|
console.log("Doctor:",$option.val());
|
|
$doctorSelect.append($option);
|
|
return;
|
|
}
|
|
|
|
// Show all doctors
|
|
if (selectedCampaign === '7 PM Conversion Campaign') {
|
|
console.log("7PM");
|
|
$doctorSelect.append($option);
|
|
}else if (selectedCampaign === 'MLC A Pedia Campaign') {
|
|
console.log("*",selectedCampaign);
|
|
|
|
|
|
if (speciality === 'PAEDIATRICIAN' || speciality === 'Paediatrician' ||speciality === 'paediatrician' ) {
|
|
|
|
pediatricianDoctors.push($option)
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
// Append pediatrician doctors
|
|
if (selectedCampaign === 'MLC A Pedia Campaign') {
|
|
|
|
pediatricianDoctors.forEach(function ($doctor) {
|
|
|
|
$doctorSelect.append($doctor);
|
|
});
|
|
}
|
|
|
|
// Reinitialize select2
|
|
$doctorSelect.select2();
|
|
|
|
// Reset selection
|
|
$doctorSelect.val('').trigger('change');
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
$('#field-record_date').closest('.col-md-12').before(`
|
|
<div class="col-md-12 mb-3">
|
|
<div class="p-3 rounded shadow-sm border"
|
|
style="background: #fff8e1; border-left: 5px solid #ff9800;">
|
|
|
|
<h5 class="fw-bold text-dark mb-3 text-center">
|
|
Campaign Guidelines
|
|
</h5>
|
|
|
|
<div class="mb-3">
|
|
<h6 class="fw-bold text-primary">
|
|
7PM Conversion Campaign
|
|
</h6>
|
|
|
|
<p class="mb-1">
|
|
<strong>Target Drs :</strong>
|
|
25 Drs Mont+Fexo & Mont+Bila Drs
|
|
</p>
|
|
|
|
<p class="mb-1">
|
|
<strong>Conversion :</strong>
|
|
5 Conversions for Montair LC Adult
|
|
</p>
|
|
|
|
<p class="mb-1">
|
|
<strong> Goal : </strong>
|
|
Each conversion with 15 Rxs Montair LC Adult
|
|
</p>
|
|
</div>
|
|
|
|
<hr>
|
|
|
|
<div>
|
|
<h6 class="fw-bold text-primary">
|
|
MLC Adult @Pedia
|
|
</h6>
|
|
|
|
<p class="mb-1">
|
|
<strong>Target Drs :</strong>
|
|
10 Drs Mont+Fexo & Mont+Bila Drs
|
|
</p>
|
|
|
|
<p class="mb-1">
|
|
<strong>Conversion :</strong>
|
|
5 Conversions for Montair LC Adult
|
|
</p>
|
|
|
|
<p class="mb-1">
|
|
<strong>Goal : </strong>
|
|
Each conversion with 8 Rxs Montair LC Adult
|
|
</p>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
`);
|
|
|
|
|
|
|
|
$('#report-form').on('submit', function(event){
|
|
event.preventDefault();
|
|
$("#pageloader").fadeIn();
|
|
$.ajax({
|
|
type: "POST",
|
|
url: '/form/ajaxsubmitmultiple',
|
|
data: new FormData($('#report-form')[0]),
|
|
processData: false,
|
|
contentType: false,
|
|
success: function( data ) {
|
|
$("#pageloader").fadeOut();
|
|
if(data.status == 'success') {
|
|
Swal.fire({
|
|
title: 'Great!',
|
|
text: 'Your data is successfully submitted!',
|
|
icon: 'success'
|
|
})
|
|
$('#report-form').trigger("reset");
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: data.hasOwnProperty('message') ? 'You are not mapped to any position code' : 'Data not submitted',
|
|
text: data.hasOwnProperty('message') ? 'for resolution please email Position code, L1 Manager and L2 Manager details to support1@stratawiz.com':'Something went wrong, please try again after some time!'
|
|
})
|
|
}
|
|
},
|
|
error: function() {
|
|
$("#pageloader").fadeOut();
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Data not submitted',
|
|
text: 'Something went wrong, please try again after some time!'
|
|
})
|
|
}
|
|
});
|
|
});
|
|
|
|
// Initial sync (for edit mode)
|
|
$('#doctor-cards .doctor-card').each(function() {
|
|
const $card = $(this);
|
|
syncCampaignTypeHidden($card);
|
|
syncDoctorFieldsFromSelected($card);
|
|
});
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|
|
|