booking/booking.php

385 lines
15 KiB
PHP
Executable File

<?php
require_once('fixed/config/go_con.php');
access(165); //23
$Select2 = true;
// if come with number
$number = $_GET['number'];
// if come with number end
// if come with booking_id
$booking_id = $_GET['booking_id'];
if (empty($booking_id)) {
$booking_id = 0;
} else {
if (!is_numeric($booking_id)) {
$booking_id = 0;
}
}
// if come with booking_id
$emp_id = $_GET['emp_id'];
$booking_day_date = $_GET['date'];
$booking_day_time = $_GET['time'];
$booking_branch_id = $_GET['branch'];
if (empty($booking_day_date) || empty($booking_day_time) || empty($booking_branch_id)) {
header('location:index.php');
}
$branch_name =''; // for view branch name in box
$Day = date('D', strtotime($booking_day_date));
function Day_ar()
{
global $Day;
$find = array("Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri");
$replace = array("السبت", "الأحد", "الإثنين", "الثلاثاء", "الأربعاء", "الخميس", "الجمعة");
$ar_day_format = $Day;
$Day_ar = str_replace($find, $replace, $ar_day_format);
return $Day_ar;
}
mysqli_query($db,
"INSERT INTO `table`(`day_date`, `day_time`, `notes`, `branch_id`, `emplyee_id`, `status_id`, `date_time`, `user_id`, `activation_id`)
VALUES ('$booking_day_date', '$booking_day_time', '', '$booking_branch_id', '$emp_id', '3', '$date_time', '$admin_id', '2')"
);
$get_emplyee_sql = mysqli_query($db, "SELECT `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`");
?>
<!DOCTYPE html>
<html lang="en" dir="rtl">
<?php require_once('fixed/head/go.php'); ?>
<body class="rtl">
<style>
.header-title {
color: #086367 !important;
font-weight: bold !important;
}
</style>
<?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">
<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" class="form-control clickfun1" type="number" value="" required>
</div>
<div class="col-4 col-sm-6 col-lg-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>
<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-4 col-lg-4 col-xl-4">
<label for="" class="col-form-label text-right">اسم الفني</label>
<select id="emp_name" style="font-family: system-ui;" class="form-control" name="booking_car_type">
<option value="0" selected>المرجو الاختيار</option>
<?php
while ($emplyee_row = mysqli_fetch_assoc($get_emplyee_sql)) {
?>
<option <?php if($emp_id == $emplyee_row['id']) {$branch_name = $emplyee_row['br_name']; echo 'selected';}?> value="<?= $emplyee_row['id'] ?>"><?= $emplyee_row['name'] ?></option>
<?php
}
?>
</select>
</div>
<div class="col-12 col-sm-12 col-md-4 col-lg-4 col-xl-4">
<label for="" class="col-form-label text-right">الخدمة المطلوبة</label>
<select id="theService" style="font-family: system-ui;" class="form-control">
</select>
</div>
<div class="col-12 col-sm-12 col-md-4 col-lg-4 col-xl-4">
<label for="send_sms" class="col-form-label text-right">ارسال رسالة</label>
<select id="send_sms" style="font-family: system-ui;" class="form-control">
<option value="1" selected>لا</option>
<option value="2">نعم</option>
</select>
</div>
<div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 bundle" style="display:none;">
<label for="bundle_name" class="col-form-label text-right">اسم الخدمات المجمعة</label>
<select id="bundle_name" style="font-family: system-ui;" class="form-control">
</select>
</div>
<div id="bundle_serv_id" class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 bundle" style="display:none;">
<label for="bundle_serv" class="col-form-label text-right">تفاصيل الخدمات المجمعة</label>
</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 class="form-control clickfun" type="text" value="<?=$booking_day_date?> <?= Day_ar() ?>" disabled>
</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 class="form-control clickfun" type="text" value="<?=$booking_day_time?>" disabled>
</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>
</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"> </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="add_booking">إضافة</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Container-fluid Ends-->
</div>
<?php require_once('fixed/footer/go.php'); ?>
</div>
</div>
<?php require_once('fixed/js/go.php'); ?>
<script>
$(".select2").select2({
width: '100%'
});
// for limit clicks
searchClick = 0;
click = 0;
// get services
$(function() {
var empName = <?= json_encode($emp_id) ?>;
$.post("work/order/ajax/get_services_ajax.php", {
empName: empName
}, function(theService) {
$("#theService").html(theService);
})
});
// if come with number
<?php
if (!empty($number)) {
?>
$("#number").val(<?=json_encode($number);?>);
search_tretment();
<?php
}
?>
// 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();
let branch_id = <?=json_encode($booking_branch_id);?>;
var emp_id = <?=json_encode($emp_id);?>;
var booking_day_date = <?=json_encode($booking_day_date);?>;
var booking_day_time = <?=json_encode($booking_day_time);?>;
if (searchClick == 0) {
searchClick++;
$.post("work/order/ajax/get_tretment_ajax.php", {
tretmentNumber,
branch_id,
emp_id,
booking_day_date,
booking_day_time,
}, function(get_tretment) {
$("#get_tretment").html(get_tretment);
})
} else {
swalfun("يرجى الانتظار","", "warning");
}
}
// add booking
$(function() {
$("#add_booking").click(function() {
add_booking();
});
});
$('.clickfun2').keypress(function (e) {
var key = e.which;
if(key == 13) {
add_booking();
}
});
function add_booking() {
tretment_id = $("[name='tretment_id']").val();
if (tretment_id == undefined) {
swalfun('حدث خطأ', 'يرجى تحديد العميل', 'error');
return false;
}
var tretmentName = $("#tretmentName").html();
var tretmentNumber = $("#number").val();
if (tretmentNumber.length !== 9) {
swalfun('حدث خطأ', 'رقم الجوال يجب أن يتكون من 9 أرقام وبدون 0 في البداية', 'error');
return false;
}
emp = $("#emp_name").val();
if (emp == 0) {
swalfun('حدث خطأ', 'يرجى اختيار الفني ', 'error');
return false;
}
theService = $("#theService").val();
if (theService < 0) {
swalfun('حدث خطأ', 'يرجى اختيار نوع الخدمة', 'error');
return false;
}
bundle_id = $("#bundle_name").val();
if (bundle_id == 0) {
swalfun('حدث خطأ', 'يرجى اختيار نوع الخدمات المجمعة', 'error');
return false;
}
booking_notes = $("[name='booking_notes']").val();
booking_id = <?=json_encode($booking_id);?>;
branch_id = <?=json_encode($booking_branch_id);?>;
emp_id = $("#emp_name").val();
emp_name = $("#emp_name").find(":selected").text();
booking_day_date = <?=json_encode($booking_day_date);?>;
booking_day_time = <?=json_encode($booking_day_time);?>;
send_sms = $("#send_sms").val();
if (click == 0) {
click++;
$.post("work/order/ajax/add_booking_ajax.php", {
tretment_id,
emp_name,
tretmentNumber,
tretmentName,
booking_id,
theService,
booking_notes,
branch_id,
bundle_id,
emp_id,
booking_day_date,
booking_day_time,
send_sms,
}, function(get_tretment) {
$("#get_tretment").html(get_tretment);
})
} else {
swalfun("يرجى الانتظار", "", "warning");
}
}
// get branch when change emplyee
$(function() {
$("#emp_name").change(function() {
var empName = $(this).val();
$.post("work/order/ajax/get_services_ajax.php", {
empName,
}, function(theService) {
$("#theService").html(theService);
})
$.post("work/order/ajax/get_branch_ajax.php", {
empName,
}, function(data) {
$("#branch_vv").val(data['val']);
})
});
});
// get bundle name when change Service
$(function() {
$("#theService").change(function() {
if($(this).val() == 0){
$(".bundle").show();
tretment_id = $("[name='tretment_id']").val();
emp = $("#emp_name").val();
if (tretment_id == undefined) {
swalfun('حدث خطأ', 'يرجى تحديد العميل', 'error');
return false;
} else if(emp == 0) {
swalfun('حدث خطأ', 'يرجى اختيار الفني ', 'error');
return false;
} else {
$.post("work/order/ajax/get_bundle_name_ajax.php", {
tretment_id,
emp,
}, function(bundleNames) {
$("#bundle_name").html(bundleNames);
})
}
} else {
$(".bundle").hide()
}
});
});
// get bundle Service when change bundle name
$(function() {
$("#bundle_name").change(function() {
if($(this).val() > 0){
bundle_name = $("#bundle_name").val();
if(bundle_name == 0) {
swalfun('حدث خطأ', 'يرجى الخدمات المجمعة المطلوبة', 'error');
return false;
} else {
$.post("work/order/ajax/get_bundle_services_has_services_ajax.php", {
bundle_name,
}, function(bundleServices) {
$("#bundle_serv_id").html(bundleServices);
$(".select2").select2({
width: '100%'
});
})
}
}
});
});
</script>
</body>
</html>