ohctech_p8/pending_appointment_updater.php
2024-10-16 19:18:52 +05:30

205 lines
6.6 KiB
PHP

<?php
error_reporting(E_ERROR | E_PARSE);
include ('includes/config/config.php');
include ('includes/functions.php');
include('log_entry.php');
?>
<script src="assets/js/jquery-2.1.4.min.js"></script>
<script>
function open_item(type,appointmentId) {
$.ajax({
url: 'select_app_data.php',
type: "POST",
data: {
'cityId': appointmentId,
},
dataType: 'json',
success: function(data) {
var app_id = data.id;
var link = '"'+data.app_root+'"';
var emailContent = "";
var status = '';
var sub_status = '';
if ($('#status').val() == 'BOOKED' && appointmentId=='') {
sub_status = 'pending';
status = "<font color=red>pending</font> ";
}else if ($('#status').val() == 'BOOKED' && appointmentId!='') {
sub_status = 'confirmed';
status = "<font color=green>confirmed</font> ";
} else if ($('#status').val() == 'DRP') {
sub_status = 'pending';
status = "<font color=red>Pending</font>";
} else if ($('#status').val() == 'DRA') {
sub_status = 'completed';
status = "<font color=green>completed</font> ";
} else if ($('#status').val() == 'CANCELLED') {
sub_status = 'cancelled';
status = " <font color=red>cancelled</font>";
}
if (data.app_type == 'FIT') {
data.app_type = 'Sickness/Fitness';
} else if (data.app_type == 'MED') {
data.app_type = 'Annual Medical Checkup';
}
var email_list_to = data.emp_mail;
var email_list_cc = data.doc_mail;
// var app_root = '<?php echo getConfigKey('APP_ROOT') ?>';
// var link = "" + app_root + "/opd_form_pdf.php?appointment_id_pdf=" + app_id;
ref_type = "Appointments Booked";
if(type=='del' ){
var subject = 'You missed your '+ data.app_type+' appointment in ' + data.ohc_type + ' OHC on ' + data
.date + '.';
emailContent +=
"<p>Dear Sir/Madam,</p><p>You have missed your " + data.app_type + " appointment in " + data.ohc_type + " OHC on " + data
.date + ".Request you to reschedule your appointment by clicking on below link.</p>"
}else if( $('#status').val() == 'CANCELLED'){
var subject = 'Your '+ data.app_type+' got ' + sub_status + ' in ' + data.ohc_type + ' OHC on ' + data
.date + '.';
emailContent +=
"<p>Dear Sir/Madam,</p><p>We regret to inform you that your " + data.app_type + " in " + data.ohc_type + " OHC got " +
status +
" due to administrativ reasons. Apologies for inconvenience caused.</p><br><p>Request you to reschedule your appointment by clicking on below link.</p>"
}else{
var subject = 'Your '+ data.app_type+' got ' + sub_status + ' in ' + data.ohc_type + ' OHC on ' + data
.date + '.';
emailContent +=
"<p>Dear Sir/Madam,</p><p>Your " + data.app_type + " in " + data.ohc_type + " ohc got " +
status +
".<br>Below are more details of your booking </p><br><table class=`table-bordered` width=`100%`>";
emailContent += "<tr><td>Date: " + data.date + "</td></tr><tr><td>Time: " + data.slot + '-' + data.slot_end +
"</td></tr><tr><td> Patient Name:" +
data.patient_name +
// "</td></tr><tr><td>Doc Name: " +
// data.doctor_name +
"</td></tr><tr><td>Appointment Type: " + data.app_type +
"</td></tr><tr><td>status: " + status +
"</td></tr><tr><td>Remarks:" + data.remarks + "</td></tr>";
emailContent +=
"</tbody></table>";
// emailContent += "<br><a href=`" + link +
// "`> Details</a> ";
}
if ($('#status').val() == 'CANCELLED' || type=='del') {
emailContent += "<br><a href=" + link + "> Book a appointment</a> ";
}
emailContent += "<p> Regards,</p><p> Team OHC</p>";
message = emailContent;
var id = appointmentId;
message = emailContent;
send_email(ref_type, appointmentId, email_list_to, email_list_cc, subject,
message,type);
},
error: function(data) {
alert('Error In Pulling Id');
return id;
}
});
}
function send_email(ref_type, ref_identifier, email_list_to, email_list_cc, subject, message, type) {
$.ajax({
url: 'send_email.php',
type: 'POST',
data: {
ref_type: ref_type,
ref_identifier: ref_identifier,
email_list_to: email_list_to,
email_list_cc: email_list_cc,
subject: subject,
message: message,
},
success: function(data) {
if (type == 'del') {
$.ajax({
url: 'delete_emp_appointment.php',
type: "POST",
data: {
flex_city_id:ref_identifier,
},
success: function(data) {
if (data.indexOf("SUCCESS") != -1) {
// alert('Employee Appointment Deleted Successfully.');
// $("#flex1").flexReload();
} else {
alert('Error Deleting Employee Appointment');
}
return;
},
error: function(data) {
alert('Error Deleting Complaint');
return;
}
});
}
},
error: function(data) {
alert('Error in sending mail');
return;
}
});
$('.close').click();
}
</script>
<?php
begin();
$query = "select * from appointment_details where status='BOOKED' and date(date)=DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY) ";
error_log("sql " . $query);
if (!$result = @mysqli_query($conn,$query)) {
rollback();
exit(mysqli_error($conn));
}
$data = array();
if(mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo "<script type='text/javascript'>open_item('del','".$row['id']."')</script>";
}
$data['status'] = "succes";
$data['message'] = "Assign menu done!";
}
else
{
$data['status'] = 200;
$data['message'] = "Data not found!";
}
commit();
echo json_encode($data);
?>