Merge branch 'main' of http://192.168.1.200:3000/Stratawiz/Rapport-Laravel
Specific Folder FTP Upload / ftp-deploy (push) Successful in 36s
Details
Specific Folder FTP Upload / ftp-deploy (push) Successful in 36s
Details
This commit is contained in:
commit
49053e37d8
|
|
@ -19,8 +19,7 @@
|
||||||
<h4 class="page-title">{{$formname}}</h4>
|
<h4 class="page-title">{{$formname}}</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-4 p-2">
|
<div class="col-4 p-2">
|
||||||
<a href="/form/downloaddata?form_id={{$form_id}}" id="download-btn" class="btn btn-info btn-xs float-end">Download</a>
|
<button type="button" id="export-btn" class="btn btn-info btn-xs float-end" data-bs-toggle="modal" data-bs-target="#export-modal">Export</button>
|
||||||
<button type="button" id="emailme" class="btn btn-warning btn-xs float-end me-2">Email</button>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -116,6 +115,33 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="modal fade" id="export-modal" tabindex="-1" role="dialog" aria-labelledby="export-modal-label" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-sm" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="export-modal-label">Export</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="mb-2">
|
||||||
|
<label for="export-startdate" class="form-label">Start Date</label>
|
||||||
|
<input type="date" class="form-control form-control-sm" id="export-startdate" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-2">
|
||||||
|
<label for="export-enddate" class="form-label">End Date</label>
|
||||||
|
<input type="date" class="form-control form-control-sm" id="export-enddate" required>
|
||||||
|
</div>
|
||||||
|
<div id="export-date-error" class="text-danger small d-none"></div>
|
||||||
|
<small class="text-muted">Maximum date range is 12 months.</small>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-warning btn-sm" id="export-email-btn">Email</button>
|
||||||
|
<button type="button" class="btn btn-info btn-sm" id="export-download-btn">Download</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
#pageloader {
|
#pageloader {
|
||||||
background: rgba( 255, 255, 255, 0.8 );
|
background: rgba( 255, 255, 255, 0.8 );
|
||||||
|
|
@ -260,20 +286,85 @@
|
||||||
@endforeach
|
@endforeach
|
||||||
],
|
],
|
||||||
"initComplete": function(settings, json) {
|
"initComplete": function(settings, json) {
|
||||||
var api = this.api();
|
|
||||||
var textBox = $('.dataTables_filter label input');
|
var textBox = $('.dataTables_filter label input');
|
||||||
textBox.unbind();
|
textBox.unbind();
|
||||||
textBox.bind('keyup input', function(e) {
|
textBox.on('keydown', function(e) {
|
||||||
if(e.keyCode == 8 && !textBox.val() || e.keyCode == 46 && !textBox.val()) {
|
if (e.keyCode === 13) {
|
||||||
// do nothing
|
e.preventDefault();
|
||||||
} else if(e.keyCode == 13 || !textBox.val()) {
|
runServerSearch($(this).val());
|
||||||
api.search(this.value).draw();
|
}
|
||||||
|
});
|
||||||
|
textBox.on('input', function() {
|
||||||
|
if (!$(this).val()) {
|
||||||
|
runServerSearch('');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let lastkey = '{{$lastkey}}';
|
let lastkey = '{{$lastkey}}';
|
||||||
|
let currentFilterParams = {};
|
||||||
|
|
||||||
|
function runServerSearch(keyword) {
|
||||||
|
currentFilterParams = Object.assign({}, currentFilterParams, {
|
||||||
|
form_id: $('#form_id').val(),
|
||||||
|
startdate: $('#startdate').val(),
|
||||||
|
enddate: $('#enddate').val()
|
||||||
|
});
|
||||||
|
keyword = (keyword || '').trim();
|
||||||
|
if (keyword) {
|
||||||
|
currentFilterParams.keyword = keyword;
|
||||||
|
} else {
|
||||||
|
delete currentFilterParams.keyword;
|
||||||
|
}
|
||||||
|
lastkey = 1;
|
||||||
|
loadRows(lastkey, false, currentFilterParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseYmd(ymd) {
|
||||||
|
var parts = String(ymd || '').split('-');
|
||||||
|
if (parts.length !== 3) return null;
|
||||||
|
var y = parseInt(parts[0], 10);
|
||||||
|
var m = parseInt(parts[1], 10) - 1;
|
||||||
|
var d = parseInt(parts[2], 10);
|
||||||
|
if (isNaN(y) || isNaN(m) || isNaN(d)) return null;
|
||||||
|
var date = new Date(y, m, d);
|
||||||
|
if (date.getFullYear() !== y || date.getMonth() !== m || date.getDate() !== d) return null;
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addMonthsClamped(date, months) {
|
||||||
|
var y = date.getFullYear();
|
||||||
|
var m = date.getMonth() + months;
|
||||||
|
var d = date.getDate();
|
||||||
|
var result = new Date(y, m, 1);
|
||||||
|
var lastDay = new Date(result.getFullYear(), result.getMonth() + 1, 0).getDate();
|
||||||
|
result.setDate(Math.min(d, lastDay));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateExportDateRange(startdate, enddate, silent) {
|
||||||
|
if (!startdate || !enddate) {
|
||||||
|
if (!silent) Swal.fire('Error!', 'Start date and end date are required.', 'error');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var start = parseYmd(startdate);
|
||||||
|
var end = parseYmd(enddate);
|
||||||
|
if (!start || !end) {
|
||||||
|
if (!silent) Swal.fire('Error!', 'Start date or end date is invalid.', 'error');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (end < start) {
|
||||||
|
if (!silent) Swal.fire('Error!', 'End date must be on or after start date.', 'error');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var maxEnd = addMonthsClamped(start, 12);
|
||||||
|
if (end > maxEnd) {
|
||||||
|
if (!silent) Swal.fire('Error!', 'Date range must not exceed 12 months.', 'error');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function bindRowActions() {
|
function bindRowActions() {
|
||||||
$('.btn-edit').off('click').on('click', function(){
|
$('.btn-edit').off('click').on('click', function(){
|
||||||
|
|
@ -406,14 +497,16 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let currentFilterParams = {};
|
|
||||||
|
|
||||||
$('#apply-date-range').on('click', function() {
|
$('#apply-date-range').on('click', function() {
|
||||||
|
var keyword = currentFilterParams.keyword || '';
|
||||||
currentFilterParams = {
|
currentFilterParams = {
|
||||||
form_id: $('#form_id').val(),
|
form_id: $('#form_id').val(),
|
||||||
startdate: $('#startdate').val(),
|
startdate: $('#startdate').val(),
|
||||||
enddate: $('#enddate').val()
|
enddate: $('#enddate').val()
|
||||||
};
|
};
|
||||||
|
if (keyword) {
|
||||||
|
currentFilterParams.keyword = keyword;
|
||||||
|
}
|
||||||
lastkey = 1;
|
lastkey = 1;
|
||||||
loadRows(lastkey, false, currentFilterParams);
|
loadRows(lastkey, false, currentFilterParams);
|
||||||
});
|
});
|
||||||
|
|
@ -431,17 +524,84 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.btn-primary').click(function(){
|
$('#export-modal').on('show.bs.modal', function() {
|
||||||
$("#pageloader").fadeIn();
|
$('#export-startdate').val($('#startdate').val() || '');
|
||||||
|
$('#export-enddate').val($('#enddate').val() || '');
|
||||||
|
$('#export-date-error').addClass('d-none').text('');
|
||||||
|
syncExportDateLimits();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#emailme').click(function(){
|
function formatYmd(date) {
|
||||||
|
var y = date.getFullYear();
|
||||||
|
var m = String(date.getMonth() + 1).padStart(2, '0');
|
||||||
|
var d = String(date.getDate()).padStart(2, '0');
|
||||||
|
return y + '-' + m + '-' + d;
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncExportDateLimits() {
|
||||||
|
var startdate = $('#export-startdate').val() || '';
|
||||||
|
var enddate = $('#export-enddate').val() || '';
|
||||||
|
var start = parseYmd(startdate);
|
||||||
|
var end = parseYmd(enddate);
|
||||||
|
var $startInput = $('#export-startdate');
|
||||||
|
var $endInput = $('#export-enddate');
|
||||||
|
var $error = $('#export-date-error');
|
||||||
|
|
||||||
|
$startInput.removeAttr('max');
|
||||||
|
$endInput.removeAttr('min').removeAttr('max');
|
||||||
|
|
||||||
|
if (start) {
|
||||||
|
$endInput.attr('min', startdate);
|
||||||
|
$endInput.attr('max', formatYmd(addMonthsClamped(start, 12)));
|
||||||
|
}
|
||||||
|
if (end) {
|
||||||
|
$startInput.attr('max', enddate);
|
||||||
|
$startInput.attr('min', formatYmd(addMonthsClamped(end, -12)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startdate && enddate && !validateExportDateRange(startdate, enddate, true)) {
|
||||||
|
var msg = 'Date range must not exceed 12 months.';
|
||||||
|
if (end && start && end < start) {
|
||||||
|
msg = 'End date must be on or after start date.';
|
||||||
|
}
|
||||||
|
$error.removeClass('d-none').text(msg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$error.addClass('d-none').text('');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#export-startdate, #export-enddate').on('change input', function() {
|
||||||
|
syncExportDateLimits();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#export-download-btn').on('click', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var startdate = $('#export-startdate').val() || '';
|
||||||
|
var enddate = $('#export-enddate').val() || '';
|
||||||
|
if (!validateExportDateRange(startdate, enddate)) {
|
||||||
|
syncExportDateLimits();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var url = '/form/downloaddata?form_id=' + encodeURIComponent(formId)
|
||||||
|
+ '&startdate=' + encodeURIComponent(startdate)
|
||||||
|
+ '&enddate=' + encodeURIComponent(enddate);
|
||||||
|
window.location.href = url;
|
||||||
|
$('#export-modal').modal('hide');
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#export-email-btn').on('click', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var startdate = $('#export-startdate').val() || '';
|
||||||
|
var enddate = $('#export-enddate').val() || '';
|
||||||
|
if (!validateExportDateRange(startdate, enddate)) {
|
||||||
|
syncExportDateLimits();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$("#pageloader").fadeIn();
|
$("#pageloader").fadeIn();
|
||||||
var startdate = $('#startdate').val() || '';
|
var url = '/form/downloaddata?email=1&form_id=' + encodeURIComponent(formId)
|
||||||
var enddate = $('#enddate').val() || '';
|
+ '&startdate=' + encodeURIComponent(startdate)
|
||||||
var url = '/form/downloaddata?email=1&form_id=' + encodeURIComponent(formId);
|
+ '&enddate=' + encodeURIComponent(enddate);
|
||||||
if (startdate) url += '&startdate=' + encodeURIComponent(startdate);
|
|
||||||
if (enddate) url += '&enddate=' + encodeURIComponent(enddate);
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "GET",
|
type: "GET",
|
||||||
|
|
@ -449,22 +609,15 @@
|
||||||
success: function() {
|
success: function() {
|
||||||
$('#notifications').append('<div class="alert alert-success">Email Sent Successfully</div>');
|
$('#notifications').append('<div class="alert alert-success">Email Sent Successfully</div>');
|
||||||
$("#pageloader").fadeOut();
|
$("#pageloader").fadeOut();
|
||||||
|
$('#export-modal').modal('hide');
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function(xhr) {
|
||||||
$("#pageloader").fadeOut();
|
$("#pageloader").fadeOut();
|
||||||
Swal.fire('Error!', 'Could not send email.', 'error');
|
var message = xhr.responseJSON?.message || 'Could not send email.';
|
||||||
|
Swal.fire('Error!', message, 'error');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#startdate, #enddate').on('change', function(){
|
|
||||||
var startdate = $('#startdate').val() || '';
|
|
||||||
var enddate = $('#enddate').val() || '';
|
|
||||||
var url = '/form/downloaddata?form_id=' + encodeURIComponent(formId);
|
|
||||||
if (startdate) url += '&startdate=' + encodeURIComponent(startdate);
|
|
||||||
if (enddate) url += '&enddate=' + encodeURIComponent(enddate);
|
|
||||||
$('#download-btn').attr('href', url);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -209,8 +209,12 @@
|
||||||
@endif
|
@endif
|
||||||
<div class="col-md-12 mb-2">
|
<div class="col-md-12 mb-2">
|
||||||
<label for="field-{{$question->code}}"
|
<label for="field-{{$question->code}}"
|
||||||
class="form-label">{{$question->question}} {!!$question->required == 'yes' ?
|
class="form-label">{{$question->question}} @if($question->code=='contact_id')
|
||||||
'<span class="text-danger">*</span>':''!!} </label>
|
{{ $i + 1 }}
|
||||||
|
@endif{!!$question->required == 'yes' ?
|
||||||
|
'<span class="text-danger">*</span>':''!!}
|
||||||
|
|
||||||
|
</label>
|
||||||
@switch($question->type)
|
@switch($question->type)
|
||||||
@case('hidden')
|
@case('hidden')
|
||||||
<input type="{{$question->type}}" id="field-{{$question->code}}-{{$i}}"
|
<input type="{{$question->type}}" id="field-{{$question->code}}-{{$i}}"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,131 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
@include('layouts.shared/title-meta', ['title' => "History"])
|
||||||
|
@include('layouts.shared/head-css', ["mode" => $mode ?? '', "demo" => $demo ?? ''])
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body class="loading">
|
||||||
|
<div class="account-pages">
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<!-- start page title -->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-8 p-2">
|
||||||
|
<h4 class="page-title">{{$formname}}</h4>
|
||||||
|
</div>
|
||||||
|
<div class="col-4 p-2">
|
||||||
|
<a href="/form/show" class="float-end pt-1">New Submission</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- end page title -->
|
||||||
|
@if(session()->has('message'))
|
||||||
|
<div class="alert alert-success">
|
||||||
|
{{ session()->get('message') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
@if(session()->has('error'))
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
{{ session()->get('error') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12 p-0">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="responsive-table-plugin">
|
||||||
|
<div class="table-rep-plugin">
|
||||||
|
<div class="table-responsive" data-pattern="priority-columns">
|
||||||
|
<table id="tech-companies-1" class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th data-priority="1">Submission Date</th>
|
||||||
|
@foreach($questions as $code => $question)
|
||||||
|
@if($question->type == 'hidden')
|
||||||
|
@continue;
|
||||||
|
@endif
|
||||||
|
@if($question->type == 'multitextbox')
|
||||||
|
@foreach($question->options as $k => $v)
|
||||||
|
<th data-priority="1">{{ is_object($v) ? ($v->display ?? $v->label ?? $k) : $v }} ({{$question->label}})</th>
|
||||||
|
@endforeach
|
||||||
|
@else
|
||||||
|
<th data-priority="1">{{$question->label}}</th>
|
||||||
|
@endif
|
||||||
|
@endforeach
|
||||||
|
<th data-priority="1">Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach($submissions as $submission)
|
||||||
|
<tr>
|
||||||
|
<th>{{date("d M Y", strtotime($submission->updatedAt))}}</th>
|
||||||
|
@foreach($questions as $code => $question)
|
||||||
|
@if($question->type == 'hidden')
|
||||||
|
@continue;
|
||||||
|
@endif
|
||||||
|
@if($question->type == 'file')
|
||||||
|
<td><a target="_blank" href="{{ isset($submission->formdata->{$code}) ? is_array($submission->formdata->{$code})? implode(', ', $submission->formdata->{$code}) :(is_string($submission->formdata->{$code}) ? $submission->formdata->{$code} : '' ) : $code }}" download="{{ isset($submission->formdata->{$code}) ? is_array($submission->formdata->{$code})? implode(', ', $submission->formdata->{$code}) : (is_string($submission->formdata->{$code}) ? $submission->formdata->{$code} : '' ) : $code }}" class="btn btn-dark btn-xs"><i class="mdi mdi-cloud-download me-1"></i> Download</a></td>
|
||||||
|
|
||||||
|
@elseif($question->type == 'radiometrix' && isset($submission->formdata->{$code}) && is_object($submission->formdata->{$code}))
|
||||||
|
<td>
|
||||||
|
{{ collect((array)$submission->formdata->{$code})->map(function($val, $key){ return "$key: $val"; })->implode(', ') }}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
@elseif($question->type == 'multitextbox')
|
||||||
|
@foreach($question->options as $k => $v)
|
||||||
|
@php
|
||||||
|
$optKey = is_object($v) ? ($v->value ?? $k) : $k;
|
||||||
|
$optVal = '';
|
||||||
|
if (isset($submission->formdata->{$optKey})) {
|
||||||
|
$raw = $submission->formdata->{$optKey};
|
||||||
|
$optVal = is_array($raw) ? implode(', ', $raw) : (is_object($raw) ? json_encode($raw) : $raw);
|
||||||
|
} elseif (isset($submission->formdata->{$code}) && (is_object($submission->formdata->{$code}) || is_array($submission->formdata->{$code}))) {
|
||||||
|
$box = (array) $submission->formdata->{$code};
|
||||||
|
if (array_key_exists($optKey, $box)) {
|
||||||
|
$raw = $box[$optKey];
|
||||||
|
$optVal = is_array($raw) ? implode(', ', $raw) : (is_object($raw) ? json_encode($raw) : $raw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@endphp
|
||||||
|
<td>{{ $optVal }}</td>
|
||||||
|
@endforeach
|
||||||
|
|
||||||
|
@elseif(count((array)$question->options) > 0 && 1==2 )
|
||||||
|
<td>{{ $question->options->{ $submission->formdata->{$code} } }}</td>
|
||||||
|
@else
|
||||||
|
<td>{{ isset($submission->formdata->{$code}) ? is_array($submission->formdata->{$code})? implode(', ', $submission->formdata->{$code}) : (is_object($submission->formdata->{$code}) ? collect((array)$submission->formdata->{$code})->map(function($val, $key){ return "$key: $val"; })->implode(', ') : $submission->formdata->{$code}) : '' }}</td>
|
||||||
|
@endif
|
||||||
|
@endforeach
|
||||||
|
<th>
|
||||||
|
@if($question->can_edit == 'yes' || sizeof($submission->workflow_approvals) == 0 )
|
||||||
|
@if($submission->workflow == 'yes' && $submission->workflow_status == 'approved' )
|
||||||
|
<p>Approved</p>
|
||||||
|
@else
|
||||||
|
{{-- <a href="/form/show?form_id={{$submission->formdata->form_id}}&id={{$submission->id}}" class="btn btn-primary btn-xs">Edit</button> --}}
|
||||||
|
@if(isset($form->allow_delete_by_user) && $form->allow_delete_by_user == 'yes')
|
||||||
|
<a href="/form/delete?form_id={{$submission->formdata->form_id}}&id={{$submission->id}}" onclick="return confirm('Are you sure you want to delete this submission? This is not recoverable!');" class="btn btn-danger btn-xs mt-1">Delete</button>
|
||||||
|
@endif
|
||||||
|
@endif
|
||||||
|
@endif
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div> <!-- end .table-responsive -->
|
||||||
|
|
||||||
|
</div> <!-- end .table-rep-plugin-->
|
||||||
|
</div> <!-- end .responsive-table-plugin-->
|
||||||
|
|
||||||
|
</div> <!-- end card body-->
|
||||||
|
</div> <!-- end card -->
|
||||||
|
</div><!-- end col-->
|
||||||
|
</div>
|
||||||
|
<!-- end row-->
|
||||||
|
</div> <!-- container -->
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<!-- end page -->
|
||||||
|
@include('layouts.shared/footer-script')
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -0,0 +1,947 @@
|
||||||
|
<!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="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
|
||||||
|
<style>
|
||||||
|
|
||||||
|
/* =========================
|
||||||
|
SELECT2 CUSTOM HIGHLIGHT
|
||||||
|
========================= */
|
||||||
|
|
||||||
|
.select2-container .select2-selection--single{
|
||||||
|
height: 38px !important;
|
||||||
|
border: 1px solid #ced4da !important;
|
||||||
|
border-radius: 6px !important;
|
||||||
|
padding-top: 4px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.select2-container--default .select2-selection--single .select2-selection__rendered{
|
||||||
|
line-height: 28px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.select2-container--default .select2-selection--single .select2-selection__arrow{
|
||||||
|
height: 36px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Dropdown option hover */
|
||||||
|
.select2-results__option--highlighted{
|
||||||
|
background-color: #0d6efd !important;
|
||||||
|
color: white !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Selected option */
|
||||||
|
.select2-results__option[aria-selected=true]{
|
||||||
|
background-color: #dbe9ff !important;
|
||||||
|
color: black !important;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Search box */
|
||||||
|
.select2-search__field{
|
||||||
|
border-radius: 5px !important;
|
||||||
|
padding: 6px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</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
|
||||||
|
|
||||||
|
@php
|
||||||
|
$submissions = Formhelper::getMultiformData( $form->partition, $form_id, $form->user_id);
|
||||||
|
$submissions = $submissions->data->submissions;
|
||||||
|
$submittedDoctors = collect($submissions)->map(function ($item) {
|
||||||
|
return $item->formdata->cont_id ?? null;
|
||||||
|
})->filter()->unique()->values()->toArray();
|
||||||
|
|
||||||
|
|
||||||
|
@endphp
|
||||||
|
@if(count($submissions)===0 || $id)
|
||||||
|
<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[0]" 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)
|
||||||
|
@if( !in_array($question->code,
|
||||||
|
["record_date"] ) )
|
||||||
|
@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' ? 'legacy_code= ' . $option->contact->legacy_code . ' ' : '' }} {{ $question->code == 'doctor_name' ? 'speciality= ' . (isset($option->contact->speciality) ? $option->contact->speciality :'') . ' ' : '' }} >
|
||||||
|
{{ $option->display }}
|
||||||
|
</option>
|
||||||
|
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
@break
|
||||||
|
@endswitch
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
<div class="doctor-wrapper">
|
||||||
|
<h4 class="doctor-title mb-3 text-primary">
|
||||||
|
Doctor 1
|
||||||
|
</h4>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@foreach($questions as $question)
|
||||||
|
@if( in_array($question->code,
|
||||||
|
["record_date","select_rxber_type"] ) )
|
||||||
|
@continue;
|
||||||
|
@endif
|
||||||
|
<div class="col-md-12 mb-2">
|
||||||
|
<label
|
||||||
|
for="field-{{$question->code}}"
|
||||||
|
class="form-label @if($question->code=='contact_id') doctor-name-label @endif">
|
||||||
|
|
||||||
|
{{$question->question}}
|
||||||
|
|
||||||
|
@if($question->code=='contact_id')
|
||||||
|
{{1}}
|
||||||
|
@endif
|
||||||
|
|
||||||
|
{!! $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}}[0]"
|
||||||
|
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}}[0]" 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}}[0]"
|
||||||
|
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}}[0]"
|
||||||
|
class="form-control"
|
||||||
|
{{$question->required == 'yes'?'required':'' }}>{{isset($question->value)?$question->value:''}}</textarea>
|
||||||
|
@break
|
||||||
|
@case('dropdown')
|
||||||
|
@if ($question->code == 'contact_id')
|
||||||
|
<select class="form-control" id="field-{{ $question->code }}"
|
||||||
|
name="{{ $question->code }}[0]"
|
||||||
|
{{ $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' : '' }}
|
||||||
|
@if($question->code == 'contact_id')
|
||||||
|
legacy_code="{{ (isset($option->contact->legacy_code) ? $option->contact->legacy_code : '') }}"
|
||||||
|
speciality="{{ (isset($option->contact->speciality) ? $option->contact->speciality : '') }}"
|
||||||
|
@endif
|
||||||
|
>
|
||||||
|
{{ $option->display }}
|
||||||
|
</option>
|
||||||
|
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
@else
|
||||||
|
<select class="form-control" id="execution-{{ $question->code }}"
|
||||||
|
name="{{ $question->code }}[0]"
|
||||||
|
{{ $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="field-{{$question->code}}-{{$option->value}}"
|
||||||
|
name="{{$question->code}}[0]" 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>
|
||||||
|
{{-- Added this Heading/label for brands --}}
|
||||||
|
@if($question->code == 'speciality')
|
||||||
|
<h5 class="mt-3">Enter Monthly Rx of Competition Brand</h5>
|
||||||
|
@endif
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
<div id="doctor-group-wrapper">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
@if(!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval !=
|
||||||
|
'yes' ) )
|
||||||
|
<div class="text-center button-list">
|
||||||
|
@if(!$id)
|
||||||
|
<button class="btn btn-primary" type="button" id="adddoctor-btn"> Add Doctor </button>
|
||||||
|
@endif
|
||||||
|
<button class="btn btn-primary" type="submit" id="submit-btn"> Submit </button>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</form>
|
||||||
|
@elseif(!$id)
|
||||||
|
<h4>
|
||||||
|
You have already submitted Voltido RCPA data for <strong>{{ count($submissions) }}</strong> Doctor(s).
|
||||||
|
|
||||||
|
</h4>
|
||||||
|
@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">
|
||||||
|
#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%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.doctor-wrapper {
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 10px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
@include('layouts.shared/footer-script')
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
|
||||||
|
<script src="{{asset('assets/libs/sweetalert2/sweetalert2.min.js')}}"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
jQuery(document).ready(function($) {
|
||||||
|
function updateDoctorLabels() {
|
||||||
|
|
||||||
|
$('.doctor-wrapper').each(function(index) {
|
||||||
|
|
||||||
|
// Doctor Heading
|
||||||
|
$(this).find('.doctor-title')
|
||||||
|
.text('Doctor ' + (index + 1));
|
||||||
|
|
||||||
|
// Doctor Name Label
|
||||||
|
$(this).find('.doctor-name-label').each(function () {
|
||||||
|
|
||||||
|
let required = $(this).find('.text-danger').length
|
||||||
|
? ' <span class="text-danger">*</span>'
|
||||||
|
: '';
|
||||||
|
|
||||||
|
$(this).html('Doctor Name ' + (index + 1) + required);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
$('#field-record_date').attr(
|
||||||
|
'max',
|
||||||
|
new Date().toISOString().split('T')[0]
|
||||||
|
);
|
||||||
|
const MIN_DOCTORS = 5;
|
||||||
|
const MAX_DOCTORS = 15;
|
||||||
|
const numberFields = [
|
||||||
|
'voltido_rx',
|
||||||
|
'vilor_f_glenmark_rx',
|
||||||
|
'vilfuro_lupin_rx',
|
||||||
|
'besvil_sun_rx',
|
||||||
|
'others_rx'
|
||||||
|
];
|
||||||
|
|
||||||
|
// Only positive integers
|
||||||
|
$(document).on('input', numberFields.map(f => `input[id^="field-${f}"]`).join(','), function () {
|
||||||
|
|
||||||
|
// Remove everything except digits
|
||||||
|
this.value = this.value.replace(/\D/g, '');
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// Prevent typing -, +, ., e
|
||||||
|
$(document).on('keydown', numberFields.map(f => `input[id^="field-${f}"]`).join(','), function (e) {
|
||||||
|
|
||||||
|
if (['-', '+', '.', 'e', 'E'].includes(e.key)) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#field-contact_id').on('change',function(){
|
||||||
|
$('#field-legacy_code').val($(this).find(":selected").attr("legacy_code"));
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#field-contact_id').on('change',function(){
|
||||||
|
$('#field-speciality').val($(this).find(":selected").attr("speciality"));
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#field-legacy_code,#field-speciality').attr('readonly',true);
|
||||||
|
|
||||||
|
function initializeSelect2() {
|
||||||
|
|
||||||
|
$('select[id^="field-contact_id"]').select2({
|
||||||
|
width: '100%',
|
||||||
|
placeholder: '-- Select Doctor --'
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#field-user_id').select2({
|
||||||
|
width: '100%',
|
||||||
|
placeholder: '-- Select User / Territory --'
|
||||||
|
});
|
||||||
|
|
||||||
|
$('select[id^="execution-"]').select2({
|
||||||
|
width: '100%'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
window.submittedDoctors = @json($submittedDoctors);
|
||||||
|
|
||||||
|
@if($id)
|
||||||
|
let currentDoctor = $('#field-contact_id').val();
|
||||||
|
|
||||||
|
window.submittedDoctors =
|
||||||
|
window.submittedDoctors.filter(
|
||||||
|
doctor => doctor != currentDoctor
|
||||||
|
);
|
||||||
|
@endif
|
||||||
|
|
||||||
|
initializeSelect2();
|
||||||
|
preventDuplicateDoctors(window.submittedDoctors);
|
||||||
|
updateDoctorLabels();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* function preventDuplicateDoctors() {
|
||||||
|
|
||||||
|
let selectedValues = [];
|
||||||
|
|
||||||
|
// Get all selected doctor values
|
||||||
|
$('select[id^="field-contact_id"]').each(function () {
|
||||||
|
|
||||||
|
let value = $(this).val();
|
||||||
|
|
||||||
|
if (value) {
|
||||||
|
selectedValues.push(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// Apply duplicate prevention
|
||||||
|
$('select[id^="field-contact_id"]').each(function () {
|
||||||
|
|
||||||
|
let currentSelect = $(this);
|
||||||
|
let currentValue = currentSelect.val();
|
||||||
|
|
||||||
|
currentSelect.find('option').each(function () {
|
||||||
|
|
||||||
|
let option = $(this);
|
||||||
|
let optionValue = option.val();
|
||||||
|
|
||||||
|
if (!optionValue) return;
|
||||||
|
|
||||||
|
// Remove old text
|
||||||
|
let cleanText = option.text().replace(' (Already Added)', '');
|
||||||
|
|
||||||
|
if (
|
||||||
|
selectedValues.includes(optionValue) &&
|
||||||
|
optionValue !== currentValue
|
||||||
|
) {
|
||||||
|
|
||||||
|
option.prop('disabled', true);
|
||||||
|
option.text(cleanText + ' (Already Added)');
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
option.prop('disabled', false);
|
||||||
|
option.text(cleanText);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// 🔥 IMPORTANT
|
||||||
|
currentSelect.select2('destroy');
|
||||||
|
|
||||||
|
currentSelect.select2({
|
||||||
|
width: '100%',
|
||||||
|
placeholder: '-- Select Doctor --'
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
} */
|
||||||
|
|
||||||
|
/* function preventDuplicateDoctors() {
|
||||||
|
|
||||||
|
let selectedValues = [];
|
||||||
|
|
||||||
|
// Collect selected values
|
||||||
|
$('select[id^="field-contact_id"]').each(function () {
|
||||||
|
|
||||||
|
let value = $(this).val();
|
||||||
|
|
||||||
|
if (value) {
|
||||||
|
selectedValues.push(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$('select[id^="field-contact_id"]').each(function () {
|
||||||
|
|
||||||
|
let currentSelect = $(this);
|
||||||
|
let currentValue = currentSelect.val();
|
||||||
|
|
||||||
|
currentSelect.find('option').each(function () {
|
||||||
|
|
||||||
|
let option = $(this);
|
||||||
|
let optionValue = option.val();
|
||||||
|
|
||||||
|
if (!optionValue) return;
|
||||||
|
|
||||||
|
// remove previous label
|
||||||
|
let cleanText = option.text().replace(' (Already Added)', '');
|
||||||
|
|
||||||
|
// IMPORTANT:
|
||||||
|
// keep currently selected option enabled
|
||||||
|
if (
|
||||||
|
selectedValues.includes(optionValue) &&
|
||||||
|
optionValue !== currentValue
|
||||||
|
) {
|
||||||
|
|
||||||
|
option.prop('disabled', true);
|
||||||
|
option.text(cleanText + ' (Already Added)');
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
option.prop('disabled', false);
|
||||||
|
option.text(cleanText);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// refresh select2 safely
|
||||||
|
if (currentSelect.hasClass("select2-hidden-accessible")) {
|
||||||
|
currentSelect.select2('destroy');
|
||||||
|
}
|
||||||
|
|
||||||
|
currentSelect.select2({
|
||||||
|
width: '100%',
|
||||||
|
placeholder: '-- Select Doctor --'
|
||||||
|
});
|
||||||
|
|
||||||
|
// VERY IMPORTANT FOR EDIT MODE
|
||||||
|
currentSelect.val(currentValue).trigger('change.select2');
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
function preventDuplicateDoctors(submittedDoctors = []) {
|
||||||
|
|
||||||
|
let selectedDoctors = [];
|
||||||
|
|
||||||
|
// Get currently selected doctors from form
|
||||||
|
$('select[id^="field-contact_id"]').each(function () {
|
||||||
|
|
||||||
|
let value = $(this).val();
|
||||||
|
|
||||||
|
if (value) {
|
||||||
|
selectedDoctors.push(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// Merge current + submitted doctors
|
||||||
|
let blockedDoctors = [
|
||||||
|
...new Set([
|
||||||
|
...selectedDoctors,
|
||||||
|
...submittedDoctors
|
||||||
|
])
|
||||||
|
];
|
||||||
|
|
||||||
|
$('select[id^="field-contact_id"]').each(function () {
|
||||||
|
|
||||||
|
let currentSelect = $(this);
|
||||||
|
let currentValue = currentSelect.val();
|
||||||
|
|
||||||
|
currentSelect.find('option').each(function () {
|
||||||
|
|
||||||
|
let option = $(this);
|
||||||
|
let optionValue = option.val();
|
||||||
|
|
||||||
|
if (!optionValue) return;
|
||||||
|
|
||||||
|
// Remove old labels
|
||||||
|
let cleanText = option.text()
|
||||||
|
.replace(' (Already Added)', '')
|
||||||
|
.replace(' (Already Submitted)', '');
|
||||||
|
|
||||||
|
// Keep currently selected option enabled
|
||||||
|
if (
|
||||||
|
blockedDoctors.includes(optionValue) &&
|
||||||
|
optionValue !== currentValue
|
||||||
|
) {
|
||||||
|
|
||||||
|
option.prop('disabled', true);
|
||||||
|
|
||||||
|
/*if (submittedDoctors.includes(optionValue)) {
|
||||||
|
|
||||||
|
option.text(cleanText + ' (Already Submitted)');
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
option.text(cleanText + ' (Already Added)');
|
||||||
|
|
||||||
|
}*/
|
||||||
|
if (
|
||||||
|
submittedDoctors.includes(optionValue) &&
|
||||||
|
!selectedDoctors.includes(optionValue)
|
||||||
|
) {
|
||||||
|
|
||||||
|
option.text(cleanText + ' (Already Submitted)');
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
option.text(cleanText + ' (Already Added)');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
option.prop('disabled', false);
|
||||||
|
option.text(cleanText);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// Refresh Select2
|
||||||
|
if (currentSelect.hasClass('select2-hidden-accessible')) {
|
||||||
|
currentSelect.select2('destroy');
|
||||||
|
}
|
||||||
|
|
||||||
|
currentSelect.select2({
|
||||||
|
width: '100%',
|
||||||
|
placeholder: '-- Select Doctor --'
|
||||||
|
});
|
||||||
|
|
||||||
|
currentSelect.val(currentValue).trigger('change.select2');
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$(document).on('change', 'select[id^="field-contact_id"]', function () {
|
||||||
|
|
||||||
|
let selectedOption = $(this).find(':selected');
|
||||||
|
|
||||||
|
let id = $(this).attr('id').split('-').pop(); // get doctor_count dynamically
|
||||||
|
|
||||||
|
$('#field-legacy_code-' + id).val(selectedOption.attr('legacy_code'));
|
||||||
|
$('#field-speciality-' + id).val(selectedOption.attr('speciality'));
|
||||||
|
|
||||||
|
let activeSelections = [];
|
||||||
|
|
||||||
|
$('select[id^="field-contact_id"]').each(function () {
|
||||||
|
|
||||||
|
let val = $(this).val();
|
||||||
|
|
||||||
|
if (val) {
|
||||||
|
activeSelections.push(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
let filteredSubmittedDoctors =
|
||||||
|
window.submittedDoctors.filter(
|
||||||
|
doctor => !activeSelections.includes(doctor)
|
||||||
|
);
|
||||||
|
|
||||||
|
preventDuplicateDoctors(filteredSubmittedDoctors);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var doctor_count = 0
|
||||||
|
let uniqueDoctorId = 0;
|
||||||
|
|
||||||
|
let numberOfSubmission=0;
|
||||||
|
console.log("Number of Submission : ",numberOfSubmission);
|
||||||
|
$('#adddoctor-btn').click(function() {
|
||||||
|
if ($('.doctor-wrapper').length >= MAX_DOCTORS) {
|
||||||
|
Swal.fire({
|
||||||
|
icon: 'warning',
|
||||||
|
title: 'Maximum Limit',
|
||||||
|
text: 'You can add maximum 15 doctors.'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let doctorName=$('#field-contact_id').html();
|
||||||
|
|
||||||
|
console.log("Doctor Name : ",doctorName);
|
||||||
|
doctor_count++;
|
||||||
|
uniqueDoctorId++;
|
||||||
|
numberOfSubmission++;
|
||||||
|
console.log("Number of Submission : ",numberOfSubmission);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*<button type="button" class="btn btn-danger btn-remove float-end" style="margin-top:-25px; margin-right:-25px"><i class="mdi mdi-close"></i></button> ye Remove Button <div class="doctor-wrapper"> ke nich tha...but abhi ke liye remove option nikal diya h */
|
||||||
|
|
||||||
|
let empty_doctor = `
|
||||||
|
|
||||||
|
<div class="doctor-wrapper">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h4 class="doctor-title mb-3 text-primary">
|
||||||
|
Doctor ${doctor_count + 1}
|
||||||
|
</h4>
|
||||||
|
|
||||||
|
@foreach($questions as $question)
|
||||||
|
|
||||||
|
@if( in_array($question->code,
|
||||||
|
["record_date","select_rxber_type"] ) )
|
||||||
|
@continue;
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<div class="col-md-12 mb-2">
|
||||||
|
<label
|
||||||
|
for="field-{{$question->code}}-${uniqueDoctorId}"
|
||||||
|
class="form-label @if($question->code=='contact_id') doctor-name-label @endif">
|
||||||
|
|
||||||
|
{{$question->question}}
|
||||||
|
|
||||||
|
@if($question->code=='contact_id')
|
||||||
|
${doctor_count + 1}
|
||||||
|
@endif
|
||||||
|
|
||||||
|
{!! $question->required == 'yes' ? '<span class="text-danger">*</span>' : '' !!}
|
||||||
|
</label>
|
||||||
|
|
||||||
|
@switch($question->type)
|
||||||
|
@case('hidden')
|
||||||
|
<input type="{{$question->type}}" id="field-{{$question->code}}-${uniqueDoctorId}" name="{{$question->code}}[${uniqueDoctorId}]" value="{{isset($question->value)?$question->value:''}}">
|
||||||
|
@break
|
||||||
|
@case('text')
|
||||||
|
@case('file')
|
||||||
|
@case('email')
|
||||||
|
@case('tel')
|
||||||
|
@case('date')
|
||||||
|
<input type="{{$question->type}}" id="field-{{$question->code}}-${uniqueDoctorId}" name="{{$question->code}}[${uniqueDoctorId}]" 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}}-${uniqueDoctorId}" name="{{$question->code}}[${uniqueDoctorId}]" class="form-control" {{$question->required == 'yes'?'required':'' }} value="{{isset($question->value)?$question->value:0}}">
|
||||||
|
@break
|
||||||
|
@case('dropdown')
|
||||||
|
<select class="form-control" id="field-{{$question->code}}-${uniqueDoctorId}" name="{{$question->code}}[${uniqueDoctorId}]" {{$question->required == 'yes'?'required':'' }}>
|
||||||
|
@if($question->code=='contact_id')
|
||||||
|
${doctorName}
|
||||||
|
@else
|
||||||
|
<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' ? 'legacy_code= ' . $option->contact->legacy_code . ' ' : '' }} {{ $question->code == 'contact_id' ? 'speciality= ' . (isset($option->contact->speciality) ? $option->contact->speciality :'') . ' ' : '' }} >
|
||||||
|
{{ $option->display }}
|
||||||
|
</option>
|
||||||
|
@endforeach
|
||||||
|
@endif
|
||||||
|
</select>
|
||||||
|
@break
|
||||||
|
@endswitch
|
||||||
|
</div>
|
||||||
|
@if($question->code == 'speciality')
|
||||||
|
<h5 class="mt-3">Enter Monthly Rx of Competition Brand</h5>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
|
||||||
|
@endforeach </div>`;
|
||||||
|
|
||||||
|
|
||||||
|
$('#doctor-group-wrapper').append(empty_doctor)
|
||||||
|
updateDoctorLabels();
|
||||||
|
$('#field-contact_id-'+uniqueDoctorId).select2({
|
||||||
|
|
||||||
|
width: '100%',
|
||||||
|
placeholder: '-- Select Doctor --'
|
||||||
|
});
|
||||||
|
preventDuplicateDoctors();
|
||||||
|
|
||||||
|
|
||||||
|
$('select[id^="execution-"]').select2({
|
||||||
|
width: '100%'
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
$('#field-legacy_code-' + uniqueDoctorId).prop('readonly', true);
|
||||||
|
$('#field-speciality-' + uniqueDoctorId).prop('readonly', true);
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if ($('.doctor-wrapper').length >= MAX_DOCTORS) {
|
||||||
|
$('#adddoctor-btn').hide();
|
||||||
|
} else {
|
||||||
|
if ($('.doctor-wrapper').length < MAX_DOCTORS) {
|
||||||
|
$('#adddoctor-btn').show();
|
||||||
|
}}
|
||||||
|
/*if ($('.doctor-wrapper').length >= MAX_DOCTORS) {
|
||||||
|
Swal.fire({
|
||||||
|
icon: 'warning',
|
||||||
|
title: 'Maximum Limit',
|
||||||
|
text: 'You can add maximum 15 doctors.'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
$('.btn-remove').unbind();
|
||||||
|
$('.btn-remove').click(function() {
|
||||||
|
$(this).closest('.doctor-wrapper').find('select').select2('destroy');
|
||||||
|
$(this).closest('.doctor-wrapper').remove();
|
||||||
|
numberOfSubmission--;
|
||||||
|
preventDuplicateDoctors();
|
||||||
|
updateDoctorLabels();
|
||||||
|
console.log("New Number of Submission : ",numberOfSubmission);
|
||||||
|
console.log("Number of doctors : ",doctor_count);
|
||||||
|
$('#adddoctor-btn').show();
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$('#field-user_id').change(function(){
|
||||||
|
let hierarchy = $('option:selected', this).attr('hierarchy');
|
||||||
|
$('#field-hierarchy_id').val(hierarchy)
|
||||||
|
event.preventDefault();
|
||||||
|
$('#pageloader').fadeIn();
|
||||||
|
$.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("legacy_code", itm.contact.legacy_code).attr("speciality", itm.contact.speciality));
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#field-contact_id').change(function() {
|
||||||
|
$('#field-legacy_code').val($('option:selected', this).attr('legacy_code'))
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#field-contact_id').change(function() {
|
||||||
|
$('#field-speciality').val($('option:selected', this).attr('speciality'))
|
||||||
|
})
|
||||||
|
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(hierarchy)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
$('#report-form').on('submit', function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
@if(!$id)
|
||||||
|
let totalDoctors = $('.doctor-wrapper').length;
|
||||||
|
|
||||||
|
if (totalDoctors < MIN_DOCTORS || totalDoctors > MAX_DOCTORS) {
|
||||||
|
|
||||||
|
Swal.fire({
|
||||||
|
icon: 'warning',
|
||||||
|
title: 'Doctor Limit',
|
||||||
|
text: `Minimum ${MIN_DOCTORS} and Maximum ${MAX_DOCTORS} doctors are required to submit. Currently added: ${totalDoctors}.`
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
@endif
|
||||||
|
|
||||||
|
$("#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'
|
||||||
|
}).then(() => {
|
||||||
|
location.reload(); // 🔥 page refresh here
|
||||||
|
});
|
||||||
|
$('#report-form').trigger("reset");
|
||||||
|
} else {
|
||||||
|
Swal.fire({
|
||||||
|
icon: 'error',
|
||||||
|
title: 'Data not submitted',
|
||||||
|
text: 'Something went wrong, please try again after some time!'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
Loading…
Reference in New Issue