Rapport-Laravel/resources/views/form/rapport-emcurecd/1675171879-850cf63f-864d-42...

212 lines
11 KiB
PHP

<!DOCTYPE html>
<html lang="en">
<head>
@include('layouts.shared/title-meta', ['title' => "Form"])
@include('layouts.shared/head-css', ["mode" => $mode ?? '', "demo" => $demo ?? ''])
<link href="{{asset('assets/libs/sweetalert2/sweetalert2.min.css')}}" rel="stylesheet" type="text/css" />
</head>
<div id="pageloader">
<img src="http://cdnjs.cloudflare.com/ajax/libs/semantic-ui/0.16.1/images/loader-large.gif" alt="processing..." />
</div>
<body class="loading">
<div class="account-pages">
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8 col-lg-6 col-xl-5 p-0">
<div class="card bg-pattern">
<div class="card-body p-3 row">
@if(Session::has('error'))<div class="alert alert-danger">{{Session::get('error')}}</div>
<br>@endif
@if(session('success'))<div class=" alert alert-success">{{ session('success') }}
</div>
<br>@endif
<div class="col-8">
<h4 class="page-title">{{$form->title}}</h4>
</div>
@if(!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes' ) )
<div class="col-4">
@if($form->link_type == 'form')
<a href="/form/history" class="float-end pt-1">View History</a>
@else
<a href="{{url()->previous()}}" class="float-end pt-1">Back</a>
@endif
</div>
@endif
@php
$start = strtotime("1 May 2021");
$till = strtotime("now");
if( request()->get('record_date') ) {
$target = strtotime(request()->get('record_date'));
} else {
$target = strtotime("now");
}
$history = Formhelper::getMultiformData($form->partition, $form->form_id, $form->user_id, date("m-01-Y", $start) , date("m-t-Y", $target) );
$contacts = [];
if(sizeof($history->data->submissions) > 0) {
foreach($history->data->submissions as $sub){
$contacts[$sub->formdata->contact_id] = ['id' => $sub->id, 'launched' => $sub->formdata->launched, 'record_date' => $sub->formdata->record_date ];
}
}
//echo '<pre>';print_r($contacts);echo '</pre>';
@endphp
<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
<div class="col-md-12 mb-2">
<div class="table-responsive">
<table class="table table-borderless table-hover table-nowrap table-centered m-0">
<thead class="table-light">
<tr>
<th>Doctor Name</th>
<th>Launched</th>
<th>Launche Date</th>
</tr>
</thead>
<tbody>
@foreach($questions[0]->options as $doctor)
@if(sizeof($contacts) > 0 && isset($contacts[$doctor->display]) )
<input type="hidden" name="id[]" value="{{$contacts[$doctor->display]['id']}}">
@endif
<input type="hidden" name="contact_id[]" value="{{$doctor->value}}">
<tr>
<td>{{$doctor->display}}</td>
<td>
@if(sizeof($contacts) > 0 && isset($contacts[$doctor->display]) )
<select class="form-control launched-field" name="launched[]">
<option value=""> -- Select -- </option>
<option value="Yes" {{$contacts[$doctor->display]['launched']=='Yes'?'selected':''}}> Yes </option>
<option value="No" {{$contacts[$doctor->display]['launched']=='No'?'selected':''}}> No </option>
</select>
@else
<select class="form-control launched-field" name="launched[]">
<option value=""> -- Select -- </option>
<option value="Yes"> Yes </option>
<option value="No"> No </option>
</select>
@endif
</td>
<td>
@if(sizeof($contacts) > 0 && isset($contacts[$doctor->display]) )
<input type="date" name="record_date[]" class="form-control data-field" value="{{$contacts[$doctor->display]['record_date']}}">
@else
<input type="date" name="record_date[]" class="form-control data-field">
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@if(!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes' ) )
<div class="text-center d-grid mt-3">
<button class="btn btn-primary" type="submit" id="submit-btn"> Submit </button>
</div>
@endif
</form>
</div> <!-- end card-body -->
</div>
<!-- end card -->
<!-- end row -->
</div> <!-- end col -->
</div>
<!-- end row -->
</div>
<!-- end container -->
</div>
<!-- end page -->
<style type="text/css">
#pageloader {
background: rgba( 255, 255, 255, 0.8 );
display: none;
height: 100%;
position: fixed;
width: 100%;
z-index: 9999;
}
#pageloader img {
left: 50%;
margin-left: -32px;
margin-top: -32px;
position: absolute;
top: 50%;
}
</style>
@include('layouts.shared/footer-script')
<script src="{{asset('assets/libs/sweetalert2/sweetalert2.min.js')}}"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
$('#field-user_id').change(function(){
let hierarchy = $('option:selected', this).attr('hierarchy');
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)
})
$('.launched-field').change(function(){
if($(this).val() == 'Yes') {
$(this).parent().parent().find('.data-field').prop('required', true)
} else {
$(this).parent().parent().find('.data-field').removeAttr('required')
}
})
$('#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'
})
} else {
Swal.fire({
icon: 'error',
title: 'Data not submitted',
text: 'Something went wrong, please try again after some time!'
})
}
},
});
});
});
</script>
</body>
</html>