313 lines
15 KiB
PHP
313 lines
15 KiB
PHP
<?php
|
|
require_once('../../../fixed/config/go_con.php');
|
|
|
|
|
|
$booking_id = mysqli_real_escape_string($db, $_POST['booking_id']);
|
|
$tretment_id = mysqli_real_escape_string($db, $_POST['tretment_id']);
|
|
$booking_the_service = mysqli_real_escape_string($db, $_POST['theService']);
|
|
$booking_notes = mysqli_real_escape_string($db, $_POST['booking_notes']);
|
|
$emp_id = mysqli_real_escape_string($db, $_POST['emp_id']);
|
|
$booking_day_date = mysqli_real_escape_string($db, $_POST['booking_day_date']);
|
|
$booking_day_time = mysqli_real_escape_string($db, $_POST['booking_day_time']);
|
|
$branch_id = mysqli_real_escape_string($db, $_POST['branch_id']);
|
|
$status_id = mysqli_real_escape_string($db, $_POST['status_id']);
|
|
|
|
|
|
|
|
if (!empty($tretment_id)) {
|
|
if (!in_array(65, $rolls)) {
|
|
if ((strtotime($date_time) - (3600*14)) > strtotime($booking_day_date .' '. $booking_day_time) || in_array(65, $rolls)) {
|
|
echo "
|
|
<script>
|
|
swalfun('حدث خطأ', 'لا يمكن التعديل لوقت سابق', 'error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
exit;
|
|
}
|
|
}
|
|
$check_tretment = mysqli_query(
|
|
$db,
|
|
"SELECT
|
|
`bd`.`day_date`,
|
|
`bd`.`day_time`,
|
|
`bd`.`notes`,
|
|
`bd`.`services_id`,
|
|
`bd`.`branch_id`,
|
|
`bd`.`emplyee_id`,
|
|
`bd`.`status_id`,
|
|
`book`.`tretment_id`
|
|
FROM `book_details` AS `bd`
|
|
LEFT JOIN `book` ON `bd`.`book_id` = `book`.`id`
|
|
WHERE `bd`.`book_id` = $booking_id
|
|
ORDER BY `bd`.`id` DESC
|
|
LIMIT 1"
|
|
);
|
|
$check_tretment_res = mysqli_fetch_assoc($check_tretment);
|
|
|
|
if ($booking_day_date != $check_tretment_res['day_date']
|
|
|| $booking_day_time != $check_tretment_res['day_time']
|
|
|| $emp_id != $check_tretment_res['emplyee_id'])
|
|
{
|
|
$check_booking = mysqli_query(
|
|
$db,
|
|
"SELECT `id` FROM `book_details`
|
|
WHERE `day_date` = '$booking_day_date'
|
|
AND `day_time` = '$booking_day_time'
|
|
AND `branch_id` = '$branch_id'
|
|
AND `emplyee_id` = '$emp_id'
|
|
AND `status_id` BETWEEN 3 AND 19
|
|
AND `book_details`.`id` IN (
|
|
SELECT MAX(`tb`.`id`) FROM `book_details` AS `tb`
|
|
WHERE `tb`.`day_date` = '$booking_day_date'
|
|
AND `tb`.`day_time` = '$booking_day_time'
|
|
)
|
|
LIMIT 1"
|
|
);
|
|
//if (mysqli_num_rows($check_booking) != 0) {
|
|
// echo "
|
|
// <script>
|
|
// swalfun('تنبية', 'يوجد حجز لعميل على نفس التاريخ والوقت', 'warning');
|
|
// click = 0;
|
|
// </script>
|
|
// ";
|
|
// exit;
|
|
//}
|
|
}
|
|
//start
|
|
if ($tretment_id != $check_tretment_res['tretment_id']) {
|
|
$day_date_t = $check_tretment_res['day_date'];
|
|
$day_time_t = $check_tretment_res['day_time'];
|
|
$notes_t = '-- ملغى بتعديل --';
|
|
$services_id_t = $check_tretment_res['services_id'];
|
|
$branch_id_t = $check_tretment_res['branch_id'];
|
|
$emplyee_id_t = $check_tretment_res['emplyee_id'];
|
|
if(!mysqli_query(
|
|
$db,
|
|
"INSERT INTO `book_details`(`day_date`, `day_time`, `services_id`, `branch_id`, `emplyee_id`, `notes`, `status_id`, `user_id`, `date_time`, `book_id`, `activation_id`)
|
|
VALUES ('$day_date_t','$day_time_t','$services_id_t','$branch_id_t','$emplyee_id_t','$notes_t','25','$admin_id','$date_time','$booking_id', '2')"
|
|
)) {
|
|
echo "
|
|
<script>
|
|
swalfun('LA235-8','','error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
} else {
|
|
$check_timer = mysqli_query(
|
|
$db,
|
|
"SELECT `maxmum` FROM `services`
|
|
WHERE `id` = '$booking_the_service'
|
|
LIMIT 1"
|
|
);
|
|
if (mysqli_num_rows($check_timer) > 0) {
|
|
$check_timer_res = mysqli_fetch_assoc($check_timer);
|
|
if ($check_timer_res['maxmum'] > 60) {
|
|
$timestamp = strtotime($booking_day_time) + 60*60;
|
|
$booking_day_time_temp = date('H:i:s', $timestamp);
|
|
$check_booking_timer = mysqli_query(
|
|
$db,
|
|
"SELECT `id` FROM `book_details`
|
|
WHERE `day_date` = '$booking_day_date'
|
|
AND `day_time` = '$booking_day_time_temp'
|
|
AND `branch_id` = '$branch_id'
|
|
AND `emplyee_id` = '$emp_id'
|
|
AND `status_id` BETWEEN 3 AND 15
|
|
AND `book_details`.`id` IN (
|
|
SELECT MAX(`tb`.`id`) FROM `book_details` AS `tb`
|
|
WHERE `tb`.`day_date` = '$booking_day_date'
|
|
AND `tb`.`emplyee_id` = '$emp_id'
|
|
GROUP BY `tb`.`day_time`
|
|
)
|
|
LIMIT 1"
|
|
);
|
|
if (mysqli_num_rows($check_booking_timer) == 0) {
|
|
if (mysqli_query(
|
|
$db,
|
|
"INSERT INTO `book`(`tretment_id`, `notes`, `user_id`, `date_time`, `activation_id`)
|
|
VALUES ('$tretment_id', '$booking_notes', '$admin_id', '$date_time', '2')"
|
|
)) {
|
|
|
|
$last_id = mysqli_insert_id($db);
|
|
if(!mysqli_query(
|
|
$db,
|
|
"INSERT INTO `book_details`(`day_date`, `day_time`, `services_id`, `branch_id`, `emplyee_id`, `notes`, `status_id`, `user_id`, `date_time`, `book_id`, `activation_id`)
|
|
VALUES ('$booking_day_date','$booking_day_time','$booking_the_service','$branch_id','$emp_id','$booking_notes','4','$admin_id','$date_time','$last_id', '2')"
|
|
)) {
|
|
echo "
|
|
<script>
|
|
swalfun('AZ127-8','','error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
} else {
|
|
require_once('add_to_book_temp_ajax.php');
|
|
echo "
|
|
<script type='text/javascript'>
|
|
window.location.href = 'book.php?branch=$branch_id&date=$booking_day_date';
|
|
</script>
|
|
";
|
|
}
|
|
} else {
|
|
echo "
|
|
<script>
|
|
swalfun('LU233-1','','error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
}
|
|
} else {
|
|
echo "
|
|
<script>
|
|
swalfun('', 'لا يمكن حجز هاذه الخدمة بسبب مدتها', 'warning');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
exit;
|
|
}
|
|
} else {
|
|
if (mysqli_query(
|
|
$db,
|
|
"INSERT INTO `book`(`tretment_id`, `notes`, `user_id`, `date_time`, `activation_id`)
|
|
VALUES ('$tretment_id', '$booking_notes', '$admin_id', '$date_time', '2')"
|
|
)) {
|
|
$last_id = mysqli_insert_id($db);
|
|
if(!mysqli_query(
|
|
$db,
|
|
"INSERT INTO `book_details`(`day_date`, `day_time`, `services_id`, `branch_id`, `emplyee_id`, `notes`, `status_id`, `user_id`, `date_time`, `book_id`, `activation_id`)
|
|
VALUES ('$booking_day_date','$booking_day_time','$booking_the_service','$branch_id','$emp_id','$booking_notes','4','$admin_id','$date_time','$last_id', '2')"
|
|
)) {
|
|
echo "
|
|
<script>
|
|
swalfun('AZ127-8','','error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
} else {
|
|
require_once('add_to_book_temp_ajax.php');
|
|
echo "
|
|
<script type='text/javascript'>
|
|
window.location.href = 'book.php?branch=$branch_id&date=$booking_day_date';
|
|
</script>
|
|
";
|
|
}
|
|
} else {
|
|
echo "
|
|
<script>
|
|
swalfun('LU233-1','','error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
|
|
$check_timer = mysqli_query(
|
|
$db,
|
|
"SELECT `maxmum` FROM `services`
|
|
WHERE `id` = '$booking_the_service'
|
|
LIMIT 1"
|
|
);
|
|
if (mysqli_num_rows($check_timer) > 0) {
|
|
$check_timer_res = mysqli_fetch_assoc($check_timer);
|
|
if ($check_timer_res['maxmum'] > 60) {
|
|
$timestamp = strtotime($booking_day_time) + 60*60;
|
|
$booking_day_time_temp = date('H:i:s', $timestamp);
|
|
$check_booking_timer = mysqli_query(
|
|
$db,
|
|
"SELECT `id` FROM `book_details`
|
|
WHERE `day_date` = '$booking_day_date'
|
|
AND `day_time` = '$booking_day_time_temp'
|
|
AND `branch_id` = '$branch_id'
|
|
AND `emplyee_id` = '$emp_id'
|
|
AND `status_id` BETWEEN 3 AND 15
|
|
AND `book_details`.`id` IN (
|
|
SELECT MAX(`tb`.`id`) FROM `book_details` AS `tb`
|
|
WHERE `tb`.`day_date` = '$booking_day_date'
|
|
AND `tb`.`emplyee_id` = '$emp_id'
|
|
GROUP BY `tb`.`day_time`
|
|
)
|
|
LIMIT 1"
|
|
);
|
|
if (mysqli_num_rows($check_booking_timer) == 0 || true) {
|
|
if (!mysqli_query(
|
|
$db,
|
|
"INSERT INTO `book_details`(`day_date`, `day_time`, `services_id`, `branch_id`, `emplyee_id`, `notes`, `status_id`, `user_id`, `date_time`, `book_id`, `activation_id`)
|
|
VALUES ('$booking_day_date','$booking_day_time','$booking_the_service','$branch_id','$emp_id','$booking_notes','$status_id','$admin_id','$date_time','$booking_id', '2')"
|
|
)) {
|
|
echo"
|
|
<script>
|
|
swalfun('TF735-7','','error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
} else {
|
|
mysqli_query(
|
|
$db,
|
|
"UPDATE `book` SET `notes`='$booking_notes' WHERE `id` = '$booking_id'"
|
|
);
|
|
require_once('add_to_book_temp_ajax.php');
|
|
echo "
|
|
<script type='text/javascript'>
|
|
window.location.href = 'book.php?branch=$branch_id&date=$booking_day_date';
|
|
</script>
|
|
";
|
|
}
|
|
|
|
} else {
|
|
echo "
|
|
<script>
|
|
swalfun('', 'لا يمكن التعديل لهذه الخدمة بسبب مدتها', 'warning');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
exit;
|
|
} //finish
|
|
} else {
|
|
if (!mysqli_query(
|
|
$db,
|
|
"INSERT INTO `book_details`(`day_date`, `day_time`, `services_id`, `branch_id`, `emplyee_id`, `notes`, `status_id`, `user_id`, `date_time`, `book_id`, `activation_id`)
|
|
VALUES ('$booking_day_date','$booking_day_time','$booking_the_service','$branch_id','$emp_id','$booking_notes','$status_id','$admin_id','$date_time','$booking_id', '2')"
|
|
)) {
|
|
echo "
|
|
<script>
|
|
swalfun('TF235-7','','error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
} else {
|
|
mysqli_query(
|
|
$db,
|
|
"UPDATE `book` SET `notes`='$booking_notes' WHERE `id` = '$booking_id'"
|
|
);
|
|
require_once('add_to_book_temp_ajax.php');
|
|
echo "
|
|
<script type='text/javascript'>
|
|
window.location.href = 'book.php?branch=$branch_id&date=$booking_day_date';
|
|
</script>
|
|
";
|
|
} //finish
|
|
} //finish
|
|
} else {
|
|
echo"
|
|
<script>
|
|
swalfun('LF245-7','','error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
} //finish
|
|
} //finish
|
|
//end
|
|
} else {
|
|
echo "
|
|
<script>
|
|
swalfun('حدث خطأ', 'يرجى تحديد العميل', 'error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
}
|
|
|
|
|
|
?>
|