Rapport-Laravel/resources/views/form/1653655221-724ec5b4-fccb-4a...

187 lines
9.9 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 Jan 2023");
$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", $target) , 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, 'units' => isset($sub->formdata->units) ? $sub->formdata->units : 0 ];
}
}
//echo '<pre>';print_r($history);print_r($contacts);echo '</pre>';
@endphp
<form method="POST" action="/form/submitmultiple" id="report-form">
<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">
<label for="field-date" class="form-label">Date<span class="text-danger">*</span></label>
<input type="date" id="field-date" name="date" class="form-control" required value="{{ (sizeof($contacts) > 0 ) ? $history->data->submissions[1]->formdata->date : '' }}">
</div>
<div class="col-md-12 mb-2">
<label for="field-record_date" class="form-label">Month<span class="text-danger">*</span></label>
<select id="field-record_date" name="record_date" class="form-control" required>
@while ($start < $till)
<option value="{{ date("M Y", $start) }}" {{ date("M Y", $target)==date("M Y", $start)?'selected':'' }} >{{ date("M Y", $start) }}</option>
{{ $start = $start = $start + 60*60*24*(date("t", $start)) }}
@endwhile
</select>
</div>
<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>HCP Name</th>
<th>Units</th>
<th>Brand</th>
<th>Speciality</th>
<th>Hospital</th>
<th>City</th>
</tr>
</thead>
<tbody>
@foreach($questions[2]->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}}">
<input type="hidden" name="brand[]" value="{{isset($doctor->contact->brand) ? $doctor->contact->brand : ''}}">
<tr>
<td>{{$doctor->display}}</td>
<td style="min-width: 100px;">
<input type="number" id="" name="units[]" class="form-control" required value="{{ (sizeof($contacts)>0 && isset($contacts[$doctor->display]) ) ? $contacts[$doctor->display]['units'] : '0' }}">
</td>
<td>{{isset($doctor->contact->brand) ? $doctor->contact->brand : ''}}</td>
<td>{{isset($doctor->contact->speciality) ? $doctor->contact->speciality : ''}}</td>
<td>{{isset($doctor->contact->hospital) ? $doctor->contact->hospital : ''}}</td>
<td>{{isset($doctor->contact->city) ? $doctor->contact->city : ''}}</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($){
$('#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!'
})
}
},
});
});
$('#field-record_date').change(function(){
window.location.href = window.location.href.split('?')[0] + '?record_date=' + $(this).val()
})
});
</script>
</body>
</html>