693 lines
40 KiB
PHP
Executable File

<!--sidebar end-->
<!--main content start-->
<?php if($this->session->flashdata('feedback_error')){ ?>
<script>
Swal.fire({
position: 'center',
icon: 'error',
title: '<?php echo $this->session->flashdata('feedback_error'); ?>',
showConfirmButton: false,
timer: 3500
})
</script>
<?php unset($_SESSION['feedback_error']);} ?>
<?php if($this->session->flashdata('feedback_success')){ ?>
<script>
Swal.fire({
position: 'center',
icon: 'success',
title: '<?php echo $this->session->flashdata('feedback_success'); ?>',
showConfirmButton: false,
timer: 3500
})
</script>
<?php unset($_SESSION['feedback_success']);} ?>
<div class="app-content content">
<section class="content-wrapper">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<div class="col-md-12">
<h3 class="font-weight-bold">
<?php echo lang('Schedule of').' '.$caregiver->fname.' '.$caregiver->lname; ?>
</h3>
</div>
<div class="col-md-2">
<!-- <div class="dropdwn">
<select class="form-control input-lg" name="category">
<option value="all">Week</option>
<option value="">Month</option>
<option value="">Day</option>
</select>
</div> -->
</div>
</div>
<hr class="mt-0 mb-0" />
<div class="card-body">
<div class="row">
<div class="col-12">
<div class="row">
<div class="col-3 table-responsive">
<div id='calendar-view' class="Lft_calndr"></div>
<div class="dropdwn">
<div class="marker-available"><span></span> &nbsp;<p>Available Zone</p></div>
<div class="marker-patient-schedule"><span></span> &nbsp;<p>Patient Schedule</p></div>
</div>
</div>
<div class="col-8">
<div id='caregiver-calendar' class="rght_calndr"></div>
</div>
<div class="col-1">
<div class="align-items-center">
<a href="#" class="modal1 tooltip" data-toggle="modal" data-target="#exampleModal">
<span class="tooltiptext">Caregiver Availability</span>
<i class="la la-calendar-o"></i>
</a><br>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog2 modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true"><i class="la la-angle-right"></i></span>
</button>
<h5 class="modal-title" id="exampleModalLabel">Caregiver Availability</h5>
</div>
<div class="modal-body">
<div id="patient-Schedule">
<table class="table table-striped table-bordered dom-jQuery-events" cellspacing="0" width="100%">
<thead>
<tr>
<th><?php echo lang('Date'); ?></th>
<th><?php echo lang('From (Time)'); ?></th>
<th><?php echo lang('To (Time)'); ?></th>
<th><?php echo lang('Status'); ?></th>
<th><?php echo lang('Action'); ?></th>
</tr>
</thead>
<tbody>
<?php if(isset($AvailableSchedule)){ ?>
<?php foreach ($AvailableSchedule as $as) { ?>
<?php
if($as->status=='1'){
$status='Created';
$style='style="color: #4ac344;"';
}else{
$status='Removed';
$style='style="color: #de2066;"';
} ?>
<tr>
<td><?php echo date("Y/m/d",strtotime($as->start)); ?></td>
<td><?php echo date("g:i A",strtotime($as->start)); ?></td>
<td><?php echo date("g:i A",strtotime($as->end)); ?></td>
<td <?php echo $style; ?>><?php echo $status; ?></td>
<td>
<button class="btn btn-danger btn-sm btnDelete" id="btnDelete" data-id="<?php echo $as->id; ?>">Delete</button>
</td>
</tr>
<?php } ?>
<?php }else{ ?>
<tr><td colspan="4">No schedule</td></tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!--- second modal ---->
<a href="#" class="modal2 tooltip" data-toggle="modal" data-target="#exampleModal2">
<span class="tooltiptext">Patient Schedule</span>
<i class="la la-calendar-o"></i>
</a><br>
<div class="modal fade" id="exampleModal2" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog2 modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true"><i class="la la-angle-right"></i></span>
</button>
<h5 class="modal-title" id="exampleModalLabel">Patient Schedule</h5>
</div>
<div class="modal-body">
<div id="patient-Schedule">
<table class="table table-striped table-bordered dom-jQuery-events" cellspacing="0" width="100%">
<thead>
<tr>
<th><?php echo lang('Date'); ?></th>
<th><?php echo lang('From (Time)'); ?></th>
<th><?php echo lang('To (Time)'); ?></th>
<th><?php echo lang('Patient Name'); ?></th>
<th><?php echo lang('Status'); ?></th>
</tr>
</thead>
<tbody>
<?php if(isset($patientSchedule)){ ?>
<?php foreach ($patientSchedule as $ps) { ?>
<tr>
<td><?php echo date("Y/m/d",strtotime($ps->start)); ?></td>
<td><?php echo date("g:i A",strtotime($ps->start)); ?></td>
<td><?php echo date("g:i A",strtotime($ps->end)); ?></td>
<td><?php echo $ps->first_name.' '.$ps->last_name; ?></td>
<?php
if($ps->acceptance_status=='Unconfirmed'){
$style='style="color: #de2066;"';
}else if($ps->acceptance_status=='Accepted'){
$style='style="color: #4ac344;"';
}else if($ps->acceptance_status=='Declined'){
$style='style="color: #de2066;"';
}else if($ps->acceptance_status=='Reported'){
$style='style="color: #bb6e06;"';
}
?>
<td <?php echo $style; ?> ><?php echo $ps->acceptance_status; ?></td>
</tr>
<?php } ?>
<?php }else{ ?>
<tr><td colspan="4">No schedule</td></tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!--- third modal ---->
<a href="#" class="modal3 tooltip" data-toggle="modal" data-target="#exampleModal3">
<span class="tooltiptext">Previous Schedule</span>
<i class="la la-calendar-o"></i><br>
</a>
<div class="modal fade" id="exampleModal3" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog2 modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true"><i class="la la-angle-right"></i></span>
</button>
<h5 class="modal-title" id="exampleModalLabel">Previous Schedule of <?php echo $caregiver->fname.' '.$caregiver->lname; ?></h5>
</div>
<div class="modal-body">
<div id="Caregiver-Schedule2">
<table class="table table-striped table-bordered dom-jQuery-events" cellspacing="0" width="100%">
<thead>
<tr>
<th><?php echo lang('Date'); ?></th>
<th><?php echo lang('From (Time)'); ?></th>
<th><?php echo lang('To (Time)'); ?></th>
<th><?php echo lang('Patient Name'); ?></th>
<th><?php echo lang('Status'); ?></th>
</tr>
</thead>
<tbody>
<?php if(isset($previousSchedule)){ ?>
<?php foreach ($previousSchedule as $ps) { ?>
<?php
if($ps->acceptance_status=='Reported'){
$status='Done';
$style='style="color: #bb6e06;"';
}else{
$status='Not Done';
$style='style="color: #de2066;"';
}
?>
<tr>
<td><?php echo date("Y/m/d",strtotime($ps->start)); ?></td>
<td><?php echo date("g:i A",strtotime($ps->start)); ?></td>
<td><?php echo date("g:i A",strtotime($ps->end)); ?></td>
<td><?php echo $ps->first_name.' '.$ps->last_name; ?></td>
<td <?php echo $style; ?> ><?php echo $status; ?></td>
</tr>
<?php } ?>
<?php }else{ ?>
<tr><td colspan="4">No schedule</td></tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
<?php
$caregiver_preference_day = array();
$all = array();
foreach($schedulePreference as $val){
if($val['day'] == 1){
array_push($all,"everyday");
}elseif($val['day'] == 2){
array_push($caregiver_preference_day,"Sun");
}elseif($val['day'] == 3){
array_push($caregiver_preference_day,"Mon");
}elseif($val['day'] == 4){
array_push($caregiver_preference_day,"Tues");
}elseif($val['day'] == 5){
array_push($caregiver_preference_day,"Wed");
}elseif($val['day'] == 6){
array_push($caregiver_preference_day,"Thu");
}elseif($val['day'] == 7){
array_push($caregiver_preference_day,"Fri");
}elseif($val['day'] == 8){
array_push($caregiver_preference_day,"Sat");
}
}
// print_r($caregiver_preference_day);exit;
// if($schedulePreference->time){
// $time= explode(',',$schedulePreference->time);
// $from_time = $time[0];
// $to_time = $time[1];
// }elseif($schedulePreference->name){
// $name = $schedulePreference->name;
// $parts = explode(" ", $name);
// if(count($parts) > 1) {
// $lastname = array_pop($parts);
// $firstname = implode(" ", $parts);
// }
// else
// {
// $firstname = $name;
// $lastname = " ";
// }
// $time= explode('-',$lastname);
// $from_time = $time[0];
// $to_time = $time[1];
// }
?>
<!-- Add Availability Modal -->
<div class="modal fade" id="addAvailability" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-centered" role="document">
<div class="modal-content">
<form action="<?php echo base_url(); ?>CaregiversSchedule/saveAvailability" use="saveAvailabilityData" method="post">
<input type="hidden" name="caregiver_id" id="caregiver_id" value="">
<input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>" />
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Add Availability</h5>
<button type="button" class="close" onclick="modalClose()" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-12">
<div class="row">
<div class="form-group col-6">
<label for="exampleInputEmail1" class="required-field"><?php echo lang('Caregiver Name'); ?></label>
<input type="text" class="form-control" id="caregiver_fullName" value='<?php echo $caregiver->fname.' '.$caregiver->lname; ?>' readonly>
</div>
<div class="form-group col-6">
<label for="exampleInputEmail1" class="required-field"><?php echo lang('Date'); ?></label>
<input type="date" name="Sdate" id="Sdate" class="form-control" readonly>
</div>
<!-- <div class="form-group col-6">
<label for="exampleInputEmail1" class="required-field"><?php echo lang('Preference Time'); ?></label>
<input type="text" class="form-control" value="<?php echo $caregiver->preferred_time; ?> " readonly>
</div> -->
</div>
<div class="row" id="timediv">
<div class="form-group col-6">
<label for="exampleInputEmail1" class="required-field"><?php echo lang('From'); ?></label>
<input type="time" name="startTime" id="startTime" value="<?php echo $caregiver->preferred_start; ?>" class="form-control">
<div class="error alert alert-light text-danger" id="startError" style="display:none;"></div>
</div>
<div class="form-group col-6">
<label for="exampleInputEmail1" class="required-field"><?php echo lang('To'); ?></label>
<input type="time" name="endTime" id="endTime" value="<?php echo $caregiver->preferred_end; ?>" class="form-control">
<div class="error alert alert-light text-danger" id="endError" style="display:none;"></div>
</div>
</div>
<div class="row" id="OldScheduleInfo">
</div>
<div class="row error" id="saveError"></div>
<div class="row error" id="showmsg"></div>
<p id="test"></p>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" onclick="modalClose()" data-dismiss="modal">Close</button>
<button type="submit" id="SubmitsaveEvent" class="btn btn-primary" onclick="return check_conflict();">Save</button>
</div>
</form>
</div>
</div>
</div>
<input type="hidden" id="caregiver_name" value="<?php echo $caregiver->fname.' '.$caregiver->lname; ?>" >
<input type="hidden" id="caregiver_day" value="" >
<script>
function modalClose()
{
$("#showmsg").text('');
}
$(document).ready(function(){
var caregiverId=<?php echo $caregiver->id; ?>;
var today=new Date();
var calendar1=$('#calendar-view').fullCalendar({
defaultView:"month",
allDaySlot: false,
editable: false,
selectable: true,
droppable: false, // this allows things to be dropped onto the calendar
defaultDate: today,
dayNamesShort: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
select: function(info,start) {
var today=info.format('YYYY-MM-DD');
$("#caregiver-calendar").fullCalendar('changeView', 'agendaWeek')
$("#caregiver-calendar").fullCalendar('gotoDate', today);
}
});
var calendar=$('#caregiver-calendar').fullCalendar({
defaultView:"agendaWeek",
allDaySlot: false,
editable: false,
selectable: true,
droppable: false, // this allows things to be dropped onto the calendar
defaultDate: today,
columnHeaderFormat: 'D - ddd',
events: {
url: '<?php echo base_url(); ?>home/getSchedule/',
data: {caregiverId : caregiverId},
error: function() {
alert('error');
}
},
select: function(info,start) {
var scheduleDate=info.format('YYYY-MM-DD');
if(start.isBefore(moment())) {
$('#caregiver-calendar').fullCalendar('unselect');
console.log('Previous date');
return false;
}else{
if(info){
loadModal(caregiverId,scheduleDate);
}
}
},
});
});
function loadModal(caregiverId,scheduleDate)
{
var CaregiverName=$("#caregiver_name").val();
$(".Error").html('');
$('#caregiver_fullName').val(CaregiverName);
$('#Sdate').val(scheduleDate);
$('#caregiver_id').val(caregiverId);
var newDay=[];
var newAllDay=[];
$.ajax({ //create an ajax request to display.php
type: "GET",
url: "<?php echo base_url(); ?>CaregiversSchedule/getPreferenceDay",
dataType: 'json',
data: {
caregiver_id: caregiverId,
},
success: function(data){
//console.log(data[0]) ;
for(var i=0; i< data.length; i++){
// newDay.push( data[i].day);
if(data[i].day == 1){
newAllDay.push("everyday");
}else if(data[i].day == 2){
newDay.push("Sun");
}else if(data[i].day == 3){
newDay.push("Mon");
}else if(data[i].day == 4){
newDay.push("Tue");
}else if(data[i].day == 5){
newDay.push("Wed");
}else if(data[i].day == 6){
newDay.push("Thu");
}else if(data[i].day == 7){
newDay.push("Fri");
}else if(data[i].day == 8){
newDay.push("Sat");
}
}
// alert(newDay);
$('#caregiver_day').val(JSON.stringify(newDay));
const dateStr = scheduleDate,
getWeekday = s => {
const [yyyy, mm, dd] = s.split('-'),
date = new Date(yyyy, mm-1, dd)
return date.toLocaleDateString('en-US', {weekday: 'short'})
}
var dayName = getWeekday(dateStr);
if(dayName == "Sun"){
var day = 2;
}else if(dayName == "Mon"){
var day = 3;
}else if(dayName == "Tue"){
var day = 4;
}else if(dayName == "Wed"){
var day = 5;
}else if(dayName == "Thu"){
var day = 6;
}else if(dayName == "Fri"){
var day = 7;
}else if(dayName == "Sat"){
var day = 8;
}
// alert(dayName);
// alert($.inArray(dayName, newDay));alert(newAllDay.length);
if( ($.inArray(dayName, newDay) !== -1) || (newAllDay.length != 0) ) {
if(newAllDay.length != 0){
var allday = 1;
$.ajax({
type: "GET",
url: "<?php echo base_url(); ?>CaregiversSchedule/getCaregiverPreferenceDate",
dataType: 'json',
data: {
caregiver_id: caregiverId,
day: allday,
},
success: function(data){
if(data.time){
let array = (data.time).split(",");
$("#startTime").val(array[0]);
$("#endTime").val(array[1]);
console.log(array);
}else if(data.session){
var name = data.name;
var from_time = "";
var to_time = "";
var parts = (data.name).split(" ");
console.log(parts);
if(parts.length > 1) {
var lastname = parts.pop();
}
else
{
var lastname = " ";
}
var time= lastname.split("-");
from_time = time[0];
to_time = time[1];
var hours = parseInt(from_time.substr(0, 2));
if(from_time.indexOf('am') != -1 && hours == 12) {
from_time = from_time.replace('12', '00'+':00');
}
if(from_time.indexOf('pm') != -1 && hours < 12) {
from_time = from_time.replace(hours, (hours + 12)+':00');
}
if(from_time.indexOf('pm') != -1 && hours == 12) {
from_time = from_time.replace('12', '12'+':00');
}
var to_time_hours = parseInt(to_time.substr(0, 2));
if(to_time.indexOf('am') != -1 && to_time_hours == 12) {
to_time = to_time.replace('12', '00'+':00');
}
if(to_time.indexOf('pm') != -1 && to_time_hours < 12) {
to_time = to_time.replace(to_time_hours, (to_time_hours + 12)+':00');
}
if(to_time.indexOf('pm') != -1 && to_time_hours == 12) {
to_time = to_time.replace('12', '12'+':00');
}
// return to_time.replace(/(am|pm)/, '');
$("#startTime").val(from_time.replace(/(am|pm)/, ''));
$("#endTime").val(to_time.replace(/(am|pm)/, ''));
}
}
})
}else{
$.ajax({
type: "GET",
url: "<?php echo base_url(); ?>CaregiversSchedule/getCaregiverPreferenceDate",
dataType: 'json',
data: {
caregiver_id: caregiverId,
day: day,
},
success: function(data){
if(data.time){
let array = (data.time).split(",");
$("#startTime").val(array[0]);
$("#endTime").val(array[1]);
console.log(array);
}else if(data.session){
var name = data.name;
var from_time = "";
var to_time = "";
var parts = (data.name).split(" ");
console.log(parts);
if(parts.length > 1) {
var lastname = parts.pop();
}
else
{
var lastname = " ";
}
var time= lastname.split("-");
from_time = time[0];
to_time = time[1];
var hours = parseInt(from_time.substr(0, 2));
if(from_time.indexOf('am') != -1 && hours == 12) {
from_time = from_time.replace('12', '00'+':00');
}
if(from_time.indexOf('pm') != -1 && hours < 12) {
from_time = from_time.replace(hours, (hours + 12)+':00');
}
if(from_time.indexOf('pm') != -1 && hours == 12) {
from_time = from_time.replace('12', '12'+':00');
}
var to_time_hours = parseInt(to_time.substr(0, 2));
if(to_time.indexOf('am') != -1 && to_time_hours == 12) {
to_time = to_time.replace('12', '00'+':00');
}
if(to_time.indexOf('pm') != -1 && to_time_hours < 12) {
to_time = to_time.replace(to_time_hours, (to_time_hours + 12)+':00');
}
if(to_time.indexOf('pm') != -1 && to_time_hours == 12) {
to_time = to_time.replace('12', '12'+':00');
}
// return to_time.replace(/(am|pm)/, '');
$("#startTime").val(from_time.replace(/(am|pm)/, ''));
$("#endTime").val(to_time.replace(/(am|pm)/, ''));
}
}
})
}
$("#timediv").show();
$("#SubmitsaveEvent").show();
$("#showmsg").hide();
}else{
// alert("not found");
$("#timediv").hide();
$("#SubmitsaveEvent").hide();
$("#showmsg").append('<div class="alert alert-light text-danger col-12">Caregiver Not Available.</div>');
}
},
error: function(data){
// $("#test").html("ajax error");
}
});
$("#addAvailability").modal('show');
}
function check_conflict(){
var startTime=$("#startTime").val();
var endTime=$("#endTime").val();
var caregiver_id=$("#caregiver_id").val();
//var patient_id=$("#patient_id").val();
var scheduleDate=$("#Sdate").val();
$(".error").html('');
$("#startError").hide();
$("#endError").hide();
if(startTime==""){
$("#startError").html('Please Enter From Time.').show();
return false;
}else
if(endTime==""){
$("#endError").html('Please Enter To Time.').show();
return false;
}else
if(startTime>=endTime){
$("#saveError").append('<div class="alert alert-light text-danger col-12">To Time Must be Greater Then From Time.</div>');
return false;
}else{
$.get('<?php echo base_url(); ?>CaregiversSchedule/CheckAvailability',
{ caregiver_id:caregiver_id, scheduleDate:scheduleDate, startTime:startTime, endTime:endTime },
function(data){
console.log(data);
//return false;
if(data!=""){
$("#saveError").append('<div class="alert alert-light text-danger col-12">'+data+'</div>');
return false;
}else{
$(".error").html('');
$("form[use=saveAvailabilityData]").submit();
return true;
}
}
);
return false;
}
return false;
}
</script>
<script>
$("document").ready(function(){
// setTimeout(
// function()
// {
// $("#hambargar-menu").trigger("click");
// }, 500);
});
$(".btnDelete").on('click',function(){
// alert('test');
var id=$(this).attr('data-id');
if (confirm('Are you sure ?')) {
$.ajax({
url:"<?php echo base_url(); ?>CaregiversSchedule/deleteAvailability",
type:"GET",
data:{id:id},
//dataType:"json",
success:function(data){
//console.log(data);
location.reload();
}
});
}
// $("#addAvailability").modal('show');
// console.log(id);
});
</script>
<!--main content end-->
<!--footer start-->