1201 lines
62 KiB
PHP
1201 lines
62 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
@include('layouts.shared/title-meta', ['title' => 'Form'])
|
|
@include('layouts.shared/head-css', ['mode' => $mode ?? '', 'demo' => $demo ?? ''])
|
|
<link href="{{ asset('assets/libs/sweetalert2/sweetalert2.min.css') }}" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<div id="pageloader">
|
|
<img src="http://cdnjs.cloudflare.com/ajax/libs/semantic-ui/0.16.1/images/loader-large.gif" alt="processing..." />
|
|
</div>
|
|
|
|
@php
|
|
// echo "<pre>";
|
|
// print_r($form);
|
|
// exit;
|
|
@endphp
|
|
|
|
@php
|
|
$history = Formhelper::getMultiformData($form->partition, $form->form_id, $form->user_id);
|
|
// echo '<pre>';
|
|
// print_r($history->data->submissions);
|
|
|
|
$newdata = [];
|
|
|
|
foreach ($history->data->submissions as $data) {
|
|
$newdata[] = $data->formdata->quarter ?? null;
|
|
}
|
|
|
|
$countofsub = count($newdata);
|
|
|
|
$alreadySelectedDoctors = collect($history->data->submissions)->pluck('contacts.0.id')->toArray();
|
|
|
|
// echo '<pre>';
|
|
// print_r($newdata);
|
|
// echo count($newdata);
|
|
// exit();
|
|
|
|
@endphp
|
|
|
|
<body class="loading">
|
|
<div class="account-pages">
|
|
<div class="container">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-8 col-lg-6 col-xl-5 p-0">
|
|
<div class="card bg-pattern">
|
|
<div class="card-body p-3 row">
|
|
|
|
@if (Session::has('error'))
|
|
<div class="alert alert-danger">{{ Session::get('error') }}</div>
|
|
<br>
|
|
@endif
|
|
@if (session('success'))
|
|
<div class=" alert alert-success">{{ session('success') }}
|
|
</div>
|
|
<br>
|
|
@endif
|
|
<div class="col-8">
|
|
<h4 class="page-title">{{ $form->title }}</h4>
|
|
</div>
|
|
@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
|
|
|
|
@if ($countofsub > 0)
|
|
<div class="col-md-12" id="table-wrapper">
|
|
<div class="card">
|
|
<div class="card-body p-0">
|
|
<div class="table-responsive">
|
|
<table
|
|
class="table table-striped table-hover table-nowrap table-centered m-0">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<th>Action</th>
|
|
<th>Date</th>
|
|
<th>Quarter</th>
|
|
<th>Doctor Name</th>
|
|
<th>MSL Code</th>
|
|
<th>Speciality</th>
|
|
<th>Dr Potential for Glycohale in Units</th>
|
|
<th>% Sales Contribution of Glycohale vs Competition</th>
|
|
<th>(Other) % Sales Contribution of Glycohale vs Competition</th>
|
|
<th>Competition Brand Name</th>
|
|
<th>(Other) Competition Brand Name</th>
|
|
<th>Competition Sales Unit per month</th>
|
|
<th>Glycohale Sales Unit per month</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach ($history->data->submissions as $sub)
|
|
@php
|
|
$sub->formdata->id = $sub->id;
|
|
$sub->formdata->og_contact_id = $sub->contacts[0]->id;
|
|
@endphp
|
|
<tr>
|
|
<td>
|
|
<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>
|
|
</td>
|
|
<td>{{ $sub->formdata->record_date ?? '' }}</td>
|
|
<td>{{ $sub->formdata->quarter ?? '' }}</td>
|
|
<td>{{ $sub->formdata->doctor_name ?? '' }}</td>
|
|
<td>{{ $sub->formdata->msl_code ?? '' }}</td>
|
|
<td>{{ $sub->formdata->speciality ?? '' }}</td>
|
|
<td>{{ $sub->formdata->dr_potential_for_glycohale_in_units ?? '' }}
|
|
</td>
|
|
<td>{{ $sub->formdata->sales_contribution_of_glycohale_vs_competition ?? '' }}
|
|
</td>
|
|
<td>{{ $sub->formdata->enter_other_sales_contribution_of_glycohale_vs_competition ?? '' }}</td>
|
|
<td>{{ $sub->formdata->competition_brand_name ?? '' }}
|
|
</td>
|
|
<td>{{ $sub->formdata->other_competition_brand_name ?? '' }}
|
|
</td>
|
|
<td>{{ $sub->formdata->competition_sales_unit_per_month ?? '' }}
|
|
</td>
|
|
<td>{{ $sub->formdata->glycohale_sales_unit_per_month ?? '' }}
|
|
</td>
|
|
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</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="user_id" value="{{ $form->user_id }}">
|
|
|
|
<input type="hidden" name="is_edit" value="yes" id="execution-is_edit">
|
|
<input type="hidden" name="og_contact_id" value=""
|
|
id="execution-og_contact_id">
|
|
|
|
@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 == 'doctor_name')
|
|
<select class="form-control" id="execution-{{ $question->code }}"
|
|
name="{{ $question->code }}"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>
|
|
<option value=""> -- Select -- </option>
|
|
@foreach ($question->options as $option)
|
|
@php $spec = $option->contact->speciality ?? ''; @endphp
|
|
@if (in_array($spec, ['CHEST PHYSICIAN', 'PULMONOLOGIST', 'CONSULTING PHYSICIAN', 'INTENSIVIST', 'intensivist', 'Intensivist']))
|
|
<option value="{{ $option->value }}"
|
|
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}
|
|
msl_code="{{ $option->contact->msl_code ?? '' }}"
|
|
speciality="{{ $spec }}">
|
|
{{ $option->display }}
|
|
</option>
|
|
@endif
|
|
@endforeach
|
|
</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
|
|
@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>
|
|
@else
|
|
<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 }}">
|
|
<input type="hidden" name="hierarchy_id" value="{{ $form->hierarchy_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')
|
|
@if ($question->code == 'doctor_name')
|
|
<select class="form-control" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>
|
|
<option value=""> -- Select -- </option>
|
|
@foreach ($question->options as $option)
|
|
@php $spec = $option->contact->speciality ?? ''; @endphp
|
|
@if (in_array($spec, ['CHEST PHYSICIAN', 'PULMONOLOGIST', 'CONSULTING PHYSICIAN', 'INTENSIVIST', 'intensivist', 'Intensivist']))
|
|
<option value="{{ $option->value }}"
|
|
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}
|
|
msl_code="{{ $option->contact->msl_code ?? '' }}"
|
|
speciality="{{ $spec }}">
|
|
{{ $option->display }}
|
|
</option>
|
|
@endif
|
|
@endforeach
|
|
</select>
|
|
@else
|
|
<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' : '' }}>
|
|
{{ $option->display }}</option>
|
|
@endforeach
|
|
</select>
|
|
@endif
|
|
@break
|
|
|
|
@case('radio')
|
|
@foreach ($question->options as $option)
|
|
<div class="form-check mb-2 form-check-success">
|
|
<input class="form-check-input" type="radio"
|
|
name="{{ $question->code }}"
|
|
id="field-{{ $question->code }}_{{ $option->value }}"
|
|
value="{{ $option->value }}">
|
|
<label class="form-check-label"
|
|
for="field-{{ $question->code }}_{{ $option->value }}">{{ $option->display }}</label>
|
|
</div>
|
|
@endforeach
|
|
@break
|
|
|
|
@case('radiometrix')
|
|
@php
|
|
// Decode the first option's value to use as heading labels
|
|
$headings =
|
|
count($question->options) > 0
|
|
? json_decode($question->options[0]->value)
|
|
: [];
|
|
@endphp
|
|
|
|
{{-- Matrix Wrapper with Horizontal Scroll on Small Screens --}}
|
|
<div class="table-responsive">
|
|
<div class="d-table w-100">
|
|
{{-- Table Headers --}}
|
|
<div class="d-table-row font-weight-bold">
|
|
<div class="d-table-cell p-2" style="width: 150px;"></div>
|
|
{{-- Placeholder for row labels --}}
|
|
@foreach ($headings as $head)
|
|
<div class="d-table-cell text-center p-2">
|
|
{{ $head }}
|
|
</div>
|
|
@endforeach
|
|
</div>
|
|
|
|
{{-- Table Rows --}}
|
|
@foreach ($question->options as $option)
|
|
@php $nn = json_decode($option->value); @endphp
|
|
<div class="d-table-row align-middle">
|
|
<div class="d-table-cell font-weight-bold p-2"
|
|
style="width: 150px;">
|
|
{{ $option->display }}
|
|
</div>
|
|
|
|
@foreach ($nn as $value)
|
|
<div class="d-table-cell text-center p-2">
|
|
<input type="radio"
|
|
id="field-{{ $option->display }}-{{ $value }}"
|
|
name="{{ $question->code }}[{{ $option->display }}]"
|
|
value="{{ $value }}"
|
|
class="form-check-input"
|
|
{{ isset($question->display) && $option->display != $option->display ? 'checked' : '' }}>
|
|
|
|
</div>
|
|
@endforeach
|
|
</div>
|
|
@endforeach
|
|
</div>
|
|
</div>
|
|
@break
|
|
|
|
@case('checkbox')
|
|
@foreach ($question->options as $option)
|
|
<div class="form-check mb-2 form-check-primary ms-2">
|
|
<input class="form-check-input" type="checkbox"
|
|
id="field-{{ $question->code }}-{{ $option->value }}"
|
|
name="{{ $question->code }}[]"
|
|
value="{{ $option->value }}"
|
|
{{ isset($question->value) && $question->value != '' && in_array($option->value, $question->value) ? 'checked' : '' }}>
|
|
<label class="form-check-label"
|
|
for="field-{{ $question->code }}-{{ $option->value }}">{{ $option->display }}</label>
|
|
</div>
|
|
@endforeach
|
|
@break
|
|
|
|
@case('file')
|
|
@if (!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes'))
|
|
<input type="file" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}" class="form-control"
|
|
value=""
|
|
{{ $question->required == 'yes' ? '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>
|
|
@endif
|
|
|
|
|
|
|
|
</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">
|
|
option:disabled {
|
|
color: #999 !important;
|
|
background: #f2f2f2;
|
|
}
|
|
|
|
#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;
|
|
}
|
|
|
|
#field-quarter option:disabled {
|
|
color: #999;
|
|
}
|
|
</style>
|
|
@include('layouts.shared/footer-script')
|
|
<script src="{{ asset('assets/libs/sweetalert2/sweetalert2.min.js') }}"></script>
|
|
<script type="text/javascript">
|
|
var submittedCount = {{ $countofsub }};
|
|
var currentCount = 1;
|
|
|
|
var alreadySubmitted = @json($alreadySelectedDoctors);
|
|
|
|
jQuery(document).ready(function($) {
|
|
|
|
$('#execution-form-wrapper').hide()
|
|
|
|
$('.edit-btn').click(function() {
|
|
let selected = JSON.parse($(this).attr('plan_details'))
|
|
for (let k of Object.keys(selected)) {
|
|
console.log(selected[k])
|
|
if (selected[k] != '') {
|
|
$('#execution-' + k).val(selected[k]);
|
|
}
|
|
|
|
if (k == 'doctor_name') {
|
|
$('#execution-doctor_name').val(selected[k]);
|
|
$('#execution-doctor_name option').each(function() {
|
|
if ($(this).text().trim() === selected[k]) {
|
|
$(this).prop('selected', true);
|
|
}
|
|
});
|
|
$('#execution-doctor_name').trigger('change');
|
|
}
|
|
|
|
if (k == 'og_contact_id') {
|
|
console.log("hello" + selected[k])
|
|
$('#execution-og_contact_id').val(selected[k]);
|
|
}
|
|
|
|
}
|
|
$('#execution-id').val(selected['id'])
|
|
$('#form-wrapper').hide()
|
|
$('#execution-form-wrapper').show()
|
|
$('#table-wrapper').hide()
|
|
|
|
$('#execution-msl_code').prop('readonly', true)
|
|
$('#execution-speciality').prop('readonly', true)
|
|
|
|
$('#execution-doctor_name').on('change', function() {
|
|
let selectedOption = $(this).find(':selected');
|
|
let mslCode = selectedOption.attr('msl_code');
|
|
let speciality = selectedOption.attr('speciality');
|
|
$('#execution-msl_code').val(mslCode || '');
|
|
$('#execution-speciality').val(speciality || '');
|
|
});
|
|
|
|
$(function() {
|
|
$('#execution-quarter option').each(function() {
|
|
$(this).prop('disabled', $(this).val() !== '' && $(this).val() !==
|
|
'Q4');
|
|
});
|
|
});
|
|
|
|
// $('#execution-enter_other_sales_contribution_of_glycohale_vs_competition').closest(
|
|
// '.col-md-12').hide().find('input').prop('required', false);
|
|
// $('#execution-other_competition_brand_name').closest('.col-md-12').hide().find('input')
|
|
// .prop('required', false);
|
|
// $('#execution-sales_contribution_of_glycohale_vs_competition').on('change', function() {
|
|
// toggleOther($(this).val(),
|
|
// '#execution-enter_other_sales_contribution_of_glycohale_vs_competition');
|
|
// });
|
|
// $('#execution-competition_brand_name').on('change', function() {
|
|
// toggleOther($(this).val(), '#execution-other_competition_brand_name');
|
|
// });
|
|
|
|
// function toggleOther(value, inputSelector) {
|
|
// let div = $(inputSelector).closest('.col-md-12');
|
|
// if (value === 'Other') {
|
|
// div.show();
|
|
// $(inputSelector).prop('required', true);
|
|
// } else {
|
|
// div.hide();
|
|
// $(inputSelector).prop('required', false).val('');
|
|
// }
|
|
// }
|
|
|
|
$('#execution-sales_contribution_of_glycohale_vs_competition').val(selected.sales_contribution_of_glycohale_vs_competition).trigger('change');
|
|
$('#execution-competition_brand_name').val(selected.competition_brand_name).trigger('change');
|
|
|
|
|
|
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();
|
|
var minDate = yyyy + '-' + mm + '-' + dd;
|
|
var lastDay = new Date(yyyy, today.getMonth() + 1, 0).getDate();
|
|
var maxDate = yyyy + '-' + mm + '-' + String(lastDay).padStart(2, '0');
|
|
var plandateField = document.getElementById('execution-record_date');
|
|
plandateField.setAttribute('min', minDate);
|
|
plandateField.setAttribute('max', maxDate);
|
|
|
|
$(document).on('input',
|
|
'#execution-enter_other_sales_contribution_of_glycohale_vs_competition',
|
|
function() {
|
|
let input = this;
|
|
let v = input.value.replace(/[^\d]/g, '');
|
|
input.value = v ? v + '%' : '';
|
|
});
|
|
$(document).on('click keyup',
|
|
'#execution-enter_other_sales_contribution_of_glycohale_vs_competition',
|
|
function() {
|
|
let len = this.value.length;
|
|
if (this.value.endsWith('%')) {
|
|
this.setSelectionRange(len - 1, len - 1);
|
|
}
|
|
});
|
|
|
|
console.log("Already submitted doctors:", alreadySubmitted);
|
|
|
|
let currentDoctor = $('#execution-doctor_name').val();
|
|
$('#execution-doctor_name option').each(function() {
|
|
let val = $(this).val();
|
|
if (alreadySubmitted.includes(val) && val !== currentDoctor) {
|
|
$(this)
|
|
.prop('disabled', true)
|
|
.text($(this).text().replace(' (Already selected)', '') +
|
|
' (Already selected)');
|
|
}
|
|
});
|
|
|
|
|
|
|
|
// exe form
|
|
|
|
$('#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!'
|
|
})
|
|
}
|
|
},
|
|
});
|
|
});
|
|
|
|
// --
|
|
})
|
|
|
|
$(function () {
|
|
|
|
const salesOther = $('#execution-enter_other_sales_contribution_of_glycohale_vs_competition').closest('.col-md-12');
|
|
const brandOther = $('#execution-other_competition_brand_name').closest('.col-md-12');
|
|
|
|
function toggleOther(val, div, input) {
|
|
if (val && val.toLowerCase() === 'other') {
|
|
div.show();
|
|
$(input).prop('required', true);
|
|
} else {
|
|
div.hide();
|
|
$(input).prop('required', false).val('');
|
|
}
|
|
}
|
|
|
|
$('#execution-sales_contribution_of_glycohale_vs_competition').on('change', function () {
|
|
toggleOther(this.value, salesOther, '#execution-enter_other_sales_contribution_of_glycohale_vs_competition');
|
|
});
|
|
|
|
$('#execution-competition_brand_name').on('change', function () {
|
|
toggleOther(this.value, brandOther, '#execution-other_competition_brand_name');
|
|
});
|
|
|
|
});
|
|
|
|
|
|
$('#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));
|
|
}
|
|
},
|
|
});
|
|
|
|
console.log(hierarchy)
|
|
})
|
|
|
|
$('#report-form').on('submit', function(event) {
|
|
event.preventDefault();
|
|
|
|
console.log('currentCount', currentCount)
|
|
if (currentCount != 5) {
|
|
Swal.fire({
|
|
title: 'Warning',
|
|
text: 'Please select 5 Doctors for Enrolment',
|
|
icon: 'warning'
|
|
})
|
|
return
|
|
}
|
|
|
|
if (submittedCount >= 5) {
|
|
Swal.fire({
|
|
title: "Limit Reached",
|
|
text: "You have submitted 5 doctors. You cannot add more.",
|
|
icon: "warning"
|
|
});
|
|
|
|
$('.add-doctor-group').prop('disabled', true).hide();
|
|
$('.remove-doctor-group').prop('disabled', true).hide();
|
|
|
|
return false;
|
|
}
|
|
|
|
$("#pageloader").fadeIn();
|
|
$.ajax({
|
|
type: "POST",
|
|
url: '/form/ajaxsubmitmultiple',
|
|
data: new FormData($('#report-form')[0]),
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(data) {
|
|
|
|
if (data.status == 'success') {
|
|
Swal.fire({
|
|
title: 'Great!',
|
|
text: 'Your data is successfully submitted!',
|
|
icon: 'success'
|
|
}).then(() => {
|
|
location.reload();
|
|
});
|
|
$('#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!'
|
|
})
|
|
}
|
|
|
|
$("#pageloader").fadeOut();
|
|
},
|
|
});
|
|
});
|
|
|
|
// 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('min', today);
|
|
|
|
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 date
|
|
var minDate = yyyy + '-' + mm + '-' + dd;
|
|
|
|
// Last date of current month
|
|
var lastDay = new Date(yyyy, today.getMonth() + 1, 0).getDate();
|
|
var maxDate = yyyy + '-' + mm + '-' + String(lastDay).padStart(2, '0');
|
|
|
|
var plandateField = document.getElementById('field-record_date');
|
|
|
|
// Set min and max
|
|
plandateField.setAttribute('min', minDate);
|
|
plandateField.setAttribute('max', maxDate);
|
|
|
|
|
|
|
|
|
|
});
|
|
</script>
|
|
|
|
{{-- --}}
|
|
|
|
{{-- <script>
|
|
$(function() {
|
|
$('#field-quarter option').each(function() {
|
|
$(this).prop('disabled', $(this).val() !== '' && $(this).val() !== 'Q4');
|
|
});
|
|
|
|
});
|
|
</script>
|
|
|
|
<script>
|
|
$(document).on('input', 'input[id^="field-other_competition_brand_name_"]', function() {
|
|
$(this).val($(this).val().replace(/[^a-zA-Z\s]/g, ''));
|
|
});
|
|
</script> --}}
|
|
|
|
<script>
|
|
$(document).on('input', 'input[id^="field-enter_other_sales_contribution_of_glycohale_vs_competition_"]',
|
|
function() {
|
|
|
|
let v = $(this).val();
|
|
|
|
v = v.replace(/%/g, '').replace(/\D/g, '');
|
|
|
|
if (v !== '') {
|
|
let num = parseInt(v, 10);
|
|
if (num > 100) num = 100;
|
|
v = num.toString();
|
|
}
|
|
|
|
$(this).val(v ? (v + '%') : '');
|
|
});
|
|
|
|
$(document).on('click keyup', 'input[id^="field-enter_other_sales_contribution_of_glycohale_vs_competition_"]',
|
|
function() {
|
|
let val = $(this).val();
|
|
if (val.endsWith('%')) {
|
|
this.setSelectionRange(val.length - 1, val.length - 1);
|
|
}
|
|
});
|
|
</script>
|
|
|
|
|
|
<script>
|
|
$(document).ready(function() {
|
|
|
|
if (submittedCount >= 5) {
|
|
|
|
Swal.fire({
|
|
title: "Limit Reached",
|
|
text: "You have submitted 5 doctors. You cannot add more.",
|
|
icon: "warning"
|
|
});
|
|
|
|
$('.add-doctor-group').prop('disabled', true).hide();
|
|
$('.remove-doctor-group').prop('disabled', true).hide();
|
|
|
|
$('#report-form').on('submit', function(e) {
|
|
e.preventDefault();
|
|
Swal.fire({
|
|
title: "Not Allowed",
|
|
text: "Submission limit reached (5 doctors).",
|
|
icon: "error"
|
|
});
|
|
return false;
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
</script>
|
|
|
|
|
|
<script>
|
|
$(function() {
|
|
$('#field-quarter option').each(function() {
|
|
$(this).prop('disabled', $(this).val() !== '' && $(this).val() !== 'Q4');
|
|
});
|
|
});
|
|
|
|
|
|
|
|
$(document).on('input', 'input[id^="field-other_competition_brand_name"]', function() {
|
|
$(this).val($(this).val().replace(/[^a-zA-Z\s]/g, ''));
|
|
});
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
const maxGroups = 5;
|
|
|
|
|
|
const $fields = $('#field-doctor_name')
|
|
.closest('.col-md-12')
|
|
.nextUntil(null, '.col-md-12')
|
|
.addBack();
|
|
|
|
$fields.first().before(
|
|
` <p class="doctor-note text-muted mb-2" style="color: #BF360C !important; font-size: 14px; font-weight: 700; font-style: italic;" id="show-wrapper-count">1 / 5 Total No of Doctor Groups Added.</p> `
|
|
);
|
|
|
|
$fields.wrapAll(`
|
|
<div class="doctor-group-wrapper"
|
|
data-group="1"
|
|
style="border:2px solid #0d6efd; padding:15px; border-radius:10px; margin-bottom:15px;">
|
|
</div>
|
|
`);
|
|
|
|
$('.doctor-group-wrapper').prepend(`
|
|
<div class="doctor-group-header" style="display:flex; justify-content:space-between; align-items:center; margin-bottom:10px;">
|
|
<b style="color:#0d6efd;">Doctor Group</b>
|
|
<div>
|
|
<button type="button" class="btn btn-sm btn-primary add-doctor-group">+ Add</button>
|
|
<button type="button" class="btn btn-sm btn-danger remove-doctor-group" style="display:none;">Remove</button>
|
|
</div>
|
|
</div>
|
|
`);
|
|
|
|
|
|
function fixFirstWrapperIds() {
|
|
$('.doctor-group-wrapper').first().find('input, select, textarea').each(function() {
|
|
const $el = $(this);
|
|
|
|
if ($el.attr('id') && !$el.attr('id').match(/_\d+$/)) {
|
|
$el.attr('id', $el.attr('id') + '_1');
|
|
}
|
|
});
|
|
|
|
$('.doctor-group-wrapper').first().find('label').each(function() {
|
|
const $lb = $(this);
|
|
|
|
if ($lb.attr('for') && !$lb.attr('for').match(/_\d+$/)) {
|
|
$lb.attr('for', $lb.attr('for') + '_1');
|
|
}
|
|
});
|
|
}
|
|
fixFirstWrapperIds();
|
|
|
|
|
|
function makeFirstWrapperNamesArray() {
|
|
$('.doctor-group-wrapper').first().find('input, select, textarea').each(function() {
|
|
const $el = $(this);
|
|
const nm = $el.attr('name');
|
|
|
|
if (!nm) return;
|
|
if (nm.includes('[]')) return;
|
|
|
|
$el.attr('name', nm + '[]');
|
|
});
|
|
}
|
|
makeFirstWrapperNamesArray();
|
|
|
|
|
|
|
|
function toggleSalesOther($wrap) {
|
|
|
|
const $select = $wrap.find('[id^="field-sales_contribution_of_glycohale_vs_competition_"]');
|
|
const groupNo = $select.attr('id').split('_').pop();
|
|
|
|
const $input = $('#field-enter_other_sales_contribution_of_glycohale_vs_competition_' + groupNo);
|
|
const $div = $input.closest('.col-md-12');
|
|
|
|
const isOther = $select.val() === 'Other';
|
|
|
|
if (isOther) {
|
|
$div.show();
|
|
$input.prop('required', true);
|
|
|
|
// ❌ DO NOT clear user value here
|
|
// $input.val('');
|
|
|
|
} else {
|
|
$div.hide();
|
|
$input.prop('required', false);
|
|
|
|
// ✅ only clear when hidden (optional)
|
|
$input.val('');
|
|
}
|
|
}
|
|
|
|
|
|
function toggleBrandOther($wrap) {
|
|
|
|
const $select = $wrap.find('[id^="field-competition_brand_name_"]');
|
|
const groupNo = $select.attr('id').split('_').pop();
|
|
|
|
const $input = $('#field-other_competition_brand_name_' + groupNo);
|
|
const $div = $input.closest('.col-md-12');
|
|
|
|
const isOther = $select.val() === 'Other';
|
|
|
|
if (isOther) {
|
|
$div.show();
|
|
$input.prop('required', true);
|
|
|
|
// ❌ don't clear while showing
|
|
// $input.val('');
|
|
|
|
} else {
|
|
$div.hide();
|
|
$input.prop('required', false);
|
|
|
|
// ✅ clear only when hidden
|
|
$input.val('');
|
|
}
|
|
}
|
|
|
|
|
|
function initWrapper($wrap) {
|
|
toggleSalesOther($wrap);
|
|
toggleBrandOther($wrap);
|
|
}
|
|
|
|
$(document).on('change', '[id^="field-sales_contribution_of_glycohale_vs_competition_"]', function() {
|
|
initWrapper($(this).closest('.doctor-group-wrapper'));
|
|
});
|
|
|
|
$(document).on('change', '[id^="field-competition_brand_name_"]', function() {
|
|
initWrapper($(this).closest('.doctor-group-wrapper'));
|
|
});
|
|
|
|
|
|
|
|
$(document).on('change', '[id^="field-doctor_name_"]', function() {
|
|
|
|
let $wrap = $(this).closest('.doctor-group-wrapper');
|
|
let $opt = $('option:selected', this);
|
|
|
|
$wrap.find('[id^="field-speciality_"]')
|
|
.val($opt.attr('speciality') || '')
|
|
.prop('readonly', true);
|
|
|
|
$wrap.find('[id^="field-msl_code_"]')
|
|
.val($opt.attr('msl_code') || '')
|
|
.prop('readonly', true);
|
|
});
|
|
|
|
$(document).on('focus', '[id^="field-speciality_"], [id^="field-msl_code_"]', function() {
|
|
$(this).prop('readonly', true);
|
|
});
|
|
|
|
|
|
|
|
function updateDoctorOptions() {
|
|
|
|
// collect selected doctor ids
|
|
let selected = $('[name="doctor_name[]"]').map(function() {
|
|
return $(this).val();
|
|
}).get().filter(v => v);
|
|
|
|
// reset all options
|
|
$('[name="doctor_name[]"] option').prop('disabled', false);
|
|
|
|
// disable selected in other dropdowns
|
|
$('[name="doctor_name[]"]').each(function() {
|
|
|
|
let currentVal = $(this).val();
|
|
|
|
$(this).find('option').each(function() {
|
|
let optVal = $(this).val();
|
|
if (!optVal) return;
|
|
|
|
if (selected.includes(optVal) && optVal !== currentVal) {
|
|
$(this).prop('disabled', true);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
$(document).on('change', '[name="doctor_name[]"]', function() {
|
|
|
|
let val = $(this).val();
|
|
if (!val) return;
|
|
|
|
let sameCount = $('[name="doctor_name[]"]').filter(function() {
|
|
return $(this).val() === val;
|
|
}).length;
|
|
|
|
if (sameCount > 1) {
|
|
Swal.fire({
|
|
title: 'Warning',
|
|
text: 'This doctor is already selected in another group.',
|
|
icon: 'warning'
|
|
});
|
|
$(this).val('');
|
|
}
|
|
|
|
updateDoctorOptions();
|
|
});
|
|
|
|
|
|
|
|
function updateButtons() {
|
|
const total = $('.doctor-group-wrapper').length;
|
|
$('.add-doctor-group').toggle(total < maxGroups);
|
|
$('.remove-doctor-group').toggle(total > 1);
|
|
}
|
|
|
|
|
|
|
|
$(document).on('click', '.add-doctor-group', function() {
|
|
currentCount++;
|
|
$('#show-wrapper-count').text(currentCount + ' / 5 Total No of Doctor Groups Added.');
|
|
const total = $('.doctor-group-wrapper').length;
|
|
if (total >= maxGroups) return;
|
|
|
|
const groupIndex = total + 1;
|
|
|
|
const $clone = $('.doctor-group-wrapper').first().clone();
|
|
$clone.attr('data-group', groupIndex);
|
|
|
|
$clone.find('input').each(function() {
|
|
const type = ($(this).attr('type') || '').toLowerCase();
|
|
$(this).val(type === 'number' ? 0 : '');
|
|
});
|
|
|
|
$clone.find('select').val('');
|
|
|
|
$clone.find('input, select, textarea').each(function() {
|
|
|
|
const $el = $(this);
|
|
|
|
if ($el.attr('id')) {
|
|
const baseId = $el.attr('id').replace(/_\d+$/, '');
|
|
$el.attr('id', baseId + '_' + groupIndex);
|
|
}
|
|
|
|
if ($el.attr('name')) {
|
|
let nm = $el.attr('name');
|
|
if (!nm.includes('[]')) {
|
|
$el.attr('name', nm + '[]');
|
|
}
|
|
}
|
|
});
|
|
|
|
$clone.find('label').each(function() {
|
|
const $lb = $(this);
|
|
if ($lb.attr('for')) {
|
|
const baseFor = $lb.attr('for').replace(/_\d+$/, '');
|
|
$lb.attr('for', baseFor + '_' + groupIndex);
|
|
}
|
|
});
|
|
|
|
$('.doctor-group-wrapper').last().after($clone);
|
|
|
|
initWrapper($clone);
|
|
|
|
updateButtons();
|
|
updateDoctorOptions();
|
|
});
|
|
|
|
|
|
|
|
$(document).on('click', '.remove-doctor-group', function() {
|
|
currentCount--;
|
|
$('#show-wrapper-count').text(currentCount + ' / 5 Total No of Doctor Groups Added.');
|
|
if ($('.doctor-group-wrapper').length > 1) {
|
|
$(this).closest('.doctor-group-wrapper').remove();
|
|
}
|
|
|
|
updateButtons();
|
|
updateDoctorOptions();
|
|
});
|
|
|
|
|
|
|
|
$('.doctor-group-wrapper').each(function() {
|
|
initWrapper($(this));
|
|
});
|
|
|
|
updateButtons();
|
|
updateDoctorOptions();
|
|
|
|
});
|
|
</script>
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|