booking/edit_booking.php
2025-03-24 19:02:58 +03:00

329 lines
14 KiB
PHP

<?php
require_once('fixed/config/go_con.php');
access(43);
$DatePicker = true;
$booking_id = mysqli_real_escape_string($db, $_GET['booking_id']);
if (!is_numeric($booking_id) || $booking_id <= 0) {
echo "
<script>
alert('حدث خطا');
window.location.href = 'index.php';
</script>
";
}
$get_book_sql = mysqli_query($db, "SELECT
`bd`.`day_date`,
`bd`.`day_time`,
`tretment`.`name` AS `tr_name`,
`tretment`.`number`,
`services`.`id` AS `serv_id`,
`emplyee`.`id`,
`emplyee`.`name`,
`book`.`notes`,
`branch`.`branch_name`,
`bd`.`status_id`
FROM `book_details` AS `bd`
LEFT JOIN `book` ON `bd`.`book_id` = `book`.`id`
LEFT JOIN `tretment` ON `book`.`tretment_id` = `tretment`.`id`
LEFT JOIN `user` ON `book`.`user_id` = `user`.`id`
LEFT JOIN `services` ON `bd`.`services_id` = `services`.`id`
LEFT JOIN `emplyee` ON `bd`.`emplyee_id` = `emplyee`.`id`
LEFT JOIN `branch` ON `bd`.`emplyee_id` = `branch`.`id`
WHERE `book`.`id`='$booking_id'
AND `bd`.`id` IN (SELECT MAX(`book_details`.`id`) FROM `book_details` WHERE `book_details`.`book_id`='$booking_id' GROUP BY `book_details`.`book_id`)
LIMIT 1"
);
$get_emplyee_sql = mysqli_query($db, "SELECT `branch`.`id` AS `br_id`, `branch`.`branch_name` AS `br_name`, `emplyee`.`id`,`emplyee`.`name` FROM `occupation`
LEFT JOIN `emplyee` ON `emplyee`.`occupation_id` = `occupation`.`id`
LEFT JOIN `branch` ON `emplyee`.`branch_id` = `branch`.`id`
WHERE `occupation`.`show_in_table_id` = 2
AND `branch`.`commercial_register_id` = $commercial_register_id
AND `emplyee`.`activation_id` = 2
ORDER BY `branch`.`id`, `emplyee`.`name`");
$get_book = mysqli_fetch_assoc($get_book_sql);
$go_out = array(1,2,3,12,13,14,15,16,17,18,19,20,21,22,23,24,25);
if (mysqli_num_rows($get_book_sql) != 1 || in_array($get_book['status_id'], $go_out)) {
echo "
<script type='text/javascript'>
window.location.href = 'index.php';
</script>
";
}
if ((strtotime($today)) > strtotime($get_book['day_date'])) {
echo "
<script type='text/javascript'>
alert('error EQ-7489')
</script>
";
}
?>
<!DOCTYPE html>
<html lang="en" dir="rtl">
<?php require_once('fixed/head/go.php'); ?>
<body class="rtl">
<?php require_once('fixed/loader/go.php'); ?>
<!-- page-wrapper Start-->
<div class="page-wrapper" id="pageWrapper">
<?php require_once('fixed/header/go.php'); ?>
<!-- Page Body Start-->
<div class="page-body-wrapper">
<?php require_once('fixed/sidebar/go.php'); ?>
<div class="page-body">
<!-- Container-fluid starts-->
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body new-user order-list">
<form action="" method="post" enctype="multipart/form-data">
<h6 class="mt-0 header-title">البحث</h6>
<div class="form-group row">
<div class="col-8 col-sm-6 col-lg-3 p-r-0">
<label for="" class="col-form-label text-right">رقم الجوال</label>
<input id="number" name="tretment_number" class="form-control clickfun1" type="number" value="<?=$get_book['number']?>" required disabled>
</div>
<?php
if ($booking_row['state'] > 14) {
?>
<div class="col-4 col-sm-6 col-md-1 col-lg-1 col-xl-1">
</div>
<?php
} else {
?>
<div id="search_tretment-frame" style="display:none;" class="col-4 col-sm-6 col-md-1 col-lg-1 col-xl-1 p-l-0">
<label style="visibility: hidden;" for="" class="col-form-label text-right">..</label>
<div class="form-control" style="background-color: #086367; color:white; text-align:center; cursor: pointer;" id="search_tretment">بحث</div>
</div>
<div id="change-frame" class="col-4 col-sm-6 col-md-1 col-lg-1 col-xl-1 p-l-0">
<label style="visibility: hidden;" for="" class="col-form-label text-right">..</label>
<div class="form-control" style="background-color: #086367; color:white; text-align:center; cursor: pointer;" id="change">تعديل</div>
</div>
<?php
}
?>
</div>
<div id="get_tretment">
</div>
<hr>
<h6 class="mt-0 header-title">معلومات الحجز</h6>
<div class="form-group row">
<div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-6">
<label for="" class="col-form-label text-right">اسم الفني</label>
<select id="emp_name" style="font-family: system-ui;" class="form-control">
<option value="0" selected>المرجو الاختيار</option>
<?php
while ($emplyee_row = mysqli_fetch_assoc($get_emplyee_sql)) {
?>
<option <?php if($get_book['id'] == $emplyee_row['id']) {$branch_name = $emplyee_row['br_name']; $br_id = $emplyee_row['br_id']; echo 'selected';}?> value="<?= $emplyee_row['id'] ?>"><?= $emplyee_row['name'] ?></option>
<?php
}
?>
</select>
</div>
<div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-6">
<label for="" class="col-form-label text-right">الخدمة المطلوبة</label>
<select id="theService" style="font-family: system-ui;" class="form-control" name="booking_the_service">
</select>
</div>
<div class="col-12 col-sm-12 col-md-6 col-lg-4 col-xl-4">
<label for="booking_day_date" class="col-form-label text-right">التاريخ</label>
<input id="booking_day_date" style="text-align: center;" type="text" class="datepicker-here form-control digits clickfun" data-language="ar" name="datestart" value="<?=$get_book['day_date']?>"/>
</div>
<div class="col-12 col-sm-12 col-md-6 col-lg-4 col-xl-4">
<label for="booking_day_time" class="col-form-label text-right">الوقت</label>
<select id="booking_day_time" style="font-family: system-ui;" class="form-control">
<?php
$get_times_sql = mysqli_query($db, "SELECT `id`, `name`,`time` FROM `times` WHERE ((`time` BETWEEN '05:00:00' AND '23:00:00') OR `time` IN ('00:00:00', '01:00:00')) AND `time` LIKE '%00:00' ORDER BY `id` = 3 ASC, `id` = 1 ASC, `times`.`time` ASC");
while ($times_row = mysqli_fetch_assoc($get_times_sql)) {
?>
<option <?php if($get_book['day_time'] == $times_row['time']) {echo 'selected';}?> value="<?= $times_row['time'] ?>"><?= $times_row['name'] ?></option>
<?php
}
?>
</select>
</div>
<div class="col-12 col-sm-12 col-md-6 col-lg-4 col-xl-4">
<label for="" class="col-form-label text-right">الفرع</label>
<input id="branch_vv" class="form-control clickfun" type="text" value="<?=$branch_name?>" disabled>
<input id="branch_id" type="number" value="<?=$br_id?>" style="display:none">
</div>
<div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12">
<label for="" class="col-form-label text-right">ملاحظات</label>
<textarea row="4" name="booking_notes" class="form-control" type="text"><?=$get_book['notes']?></textarea>
</div>
</div>
<hr>
<div class="form-group row">
<div class="col-lg-12">
<div class="form-control" style="background-color: #086367; color:white; text-align:center; cursor: pointer;" id="edit_booking">تعديل</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- Container-fluid Ends-->
</div>
<?php require_once('fixed/footer/go.php'); ?>
</div>
</div>
<div id="get_data"></div>
<?php require_once('fixed/js/go.php'); ?>
<script>
// for limit clicks
searchClick = 0;
click = 0;
// get services
$(function() {
var empName = <?= json_encode($get_book['id']) ?>;
var servid = <?= json_encode($get_book['serv_id'])?>;
$.post("work/order/ajax/get_services_ajax.php", {
servid,
empName
}, function(theService) {
$("#theService").html(theService);
})
});
// search for tretment
$(function() {
$("#search_tretment").click(function() {
search_tretment();
});
});
$('.clickfun1').keypress(function (e) {
var key = e.which;
if(key == 13) {
search_tretment();
}
});
function search_tretment() {
if ($("#number").val().length !== 9) {
swalfun('حدث خطأ', 'رقم الجوال يجب أن يتكون من 9 أرقام وبدون 0 في البداية', 'error');
return false;
}
var tretmentNumber = $("#number").val();
if (searchClick == 0) {
searchClick++;
$.post("work/order/ajax/get_tretment_ajax.php", {
tretmentNumber,
}, function(get_tretment) {
$("#get_tretment").html(get_tretment);
})
} else {
swalfun("يرجى الانتظار","", "warning");
}
}
// edit booking
$(function() {
$("#edit_booking").click(function() {
add_booking();
});
});
$('.clickfun2').keypress(function (e) {
var key = e.which;
if(key == 13) {
add_booking();
}
});
function add_booking() {
let booking_day_date = $("#booking_day_date").val();
let booking_day_time = $("#booking_day_time").val();
let branch_id = $("#branch_id").val();
let booking_id = <?=json_encode($booking_id)?>;
let status_id = <?=json_encode($get_book['status_id'])?>;
let tretment_id = $("[name='tretment_id']").val();
if (tretment_id == undefined) {
swalfun('حدث خطأ', 'يرجى تحديد العميل', 'error');
return false;
}
let emp = $("#emp_name").val();
if (emp == 0) {
swalfun('حدث خطأ', 'يرجى اختيار الفني ', 'error');
return false;
}
let theService = $("#theService").val();
if (theService == 0) {
swalfun('حدث خطأ', 'يرجى اختيار نوع الخدمة', 'error');
return false;
} else if (theService != <?=json_encode($get_book['serv_id'])?> && 6 == <?=json_encode($get_book['status_id'])?>) {
swalfun('حدث خطأ', 'لا يمكن تعديل الخدمة من هنا (حاليا) الى اشعار آخر', 'error');
return false;
}
let booking_notes = $("[name='booking_notes']").val();
let emp_id = $("#emp_name").val();
if (click == 0) {
click++;
$.post("work/order/ajax/edit_booking_ajax.php", {
booking_id,
tretment_id,
theService,
booking_notes,
branch_id,
emp_id,
booking_day_date,
booking_day_time,
status_id
}, function(get_tretment) {
$("#get_data").html(get_tretment);
})
} else {
swalfun("يرجى الانتظار", "", "warning");
}
}
// get branch when change emplyee
$(function() {
$("#emp_name").change(function() {
var servid = <?= json_encode($get_book['serv_id'])?>;
var empName = $(this).val();
$.post("work/order/ajax/get_services_ajax.php", {
servid,
empName
}, function(theService) {
$("#theService").html(theService);
})
$.post("work/order/ajax/get_branch_ajax.php", {
empName,
}, function(data) {
$("#branch_vv").val(data['val']);
$("#branch_id").val(data['id']);
})
});
});
// change tretment
$(function() {
$("#change").click(function() {
$("#change-frame").hide();
$("#name-frame").hide();
$("#number").prop( "disabled", false );
$("#search_tretment-frame").show();
});
});
search_tretment()
</script>
</body>
</html>