booking/work/order/ajax/get_tretment_ajax.php
2025-03-24 19:02:58 +03:00

276 lines
13 KiB
PHP

<?php
require_once('../../../fixed/config/go_con.php');
// require
$tretment_number = mysqli_real_escape_string($db, $_POST['tretmentNumber']);
// just for more actions
$emp_id = mysqli_real_escape_string($db, $_POST['emp_id']);
$branch_id = mysqli_real_escape_string($db, $_POST['branch_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']);
// just for more actions end
if (!empty($tretment_number)) {
$result = mysqli_query($db, "SELECT
`tretment`.`id`,
`tretment`.`name`,
DATE_FORMAT(`tretment`.`date_time`,'%d-%m-%Y') AS `datetime` ,
`an_employee_offer`.`name` AS `an_name`,
`tretment`.`black_list`,
`total_points`.`point`,
`total_walla_points`.`point` AS `point_w`,
`royality_tretment`.`total_pays`,
(SELECT `name` FROM `ranks` WHERE `total_points`.`point` BETWEEN `start` AND `end`) AS `rank`
FROM `tretment`
LEFT JOIN `an_employee_offer` ON `an_employee_offer`.`id` = `tretment`.`an_employee_offer_id`
LEFT JOIN `total_points` ON `total_points`.`tretment_id` = `tretment`.`id`
LEFT JOIN `total_walla_points` ON `total_walla_points`.`tretment_id` = `tretment`.`id`
LEFT JOIN `royality_tretment` ON `royality_tretment`.`id` = `tretment`.`id`
WHERE `tretment`.`commercial_register_id` = $commercial_register_id
AND `tretment`.`number`='$tretment_number'");
if (mysqli_num_rows($result) == 1) {
$row = mysqli_fetch_array($result);
if($row['black_list'] == 2) {
?>
<script>
swalfun('في القائمة السوداء','لا يمكن الحجز للعميل','info');
searchClick = 0;
</script>
<?php
exit;
}
$tretment_id = $row['id'];
$total_pays = $row['total_pays'];
$tretment_services_sql = mysqli_query($db, "SELECT `name`, `how_many` FROM `tretment_services` WHERE `commercial_register_id` = $commercial_register_id AND `tretment_id` = $tretment_id");
$tretment_free_services_sql = mysqli_query($db, "SELECT `name`, `how_many` FROM `tretment_free_services` WHERE `commercial_register_id` = $commercial_register_id AND `tretment_id` = $tretment_id");
$tretment_money_sql = mysqli_query($db, "SELECT `money` FROM `tretment_money` WHERE `tretment_id` = $tretment_id");
$tretment_money = mysqli_fetch_array($tretment_money_sql);
$tretment_free_money_sql = mysqli_query($db, "SELECT `money` FROM `tretment_free_money` WHERE `tretment_id` = $tretment_id");
$tretment_walla_sql = mysqli_query($db, "SELECT `id` FROM `walla_answers` WHERE `tretment_id` = $tretment_id");
?>
<input name="tretment_id" style="display: none;" value="<?= $row['id'] ?>">
<hr>
<h6 class="mt-0 header-title">معلومات العميل</h6>
<div class="form-group row">
<div class="col-12 col-sm-12 col-md-8 col-lg-8 col-xl-8">
<div class="table-responsive">
<table class="table table-bordered middle text-align-center">
<tbody>
<tr>
<th scope="col" class="bg-primary">الاسم</th>
<td id="tretmentName"><?= $row['name'] ?></td>
<th scope="col" class="bg-primary">جهه العمل</th>
<td><?= $row['an_name'] ?></td>
</tr>
<tr>
<th scope="col" class="bg-primary">العضوية</th>
<td><?= $row['rank'] ?></td>
<th scope="col" class="bg-primary w-1">مجموع نقاط العضوية</th>
<td><?= $row['point'] ?></td>
</tr>
<tr>
<th scope="col" class="bg-primary">هل العميل مسجل في ولاء ؟</th>
<td><?php if(mysqli_num_rows($tretment_walla_sql) > 0){echo"نعم";}else{echo"لا";}?></td>
<th scope="col" class="bg-primary w-1">مجموع نقاط ولاء</th>
<td><?php if(!empty($row['point_w'])) {echo $row['point_w'];}else{echo 0;}?></td>
</tr>
<tr>
<th scope="col" class="bg-primary w-12">هل يوجد لدية رصيد</th>
<td <?php if(mysqli_num_rows($tretment_services_sql) > 0){echo"style='background: yellow;'";}?>><?php if(mysqli_num_rows($tretment_services_sql) > 0){echo"نعم";}else{echo"لا";}?></td>
<th scope="col" class="bg-primary w-12">هل يوجد لدية رصيد مجاني</th>
<td <?php if(mysqli_num_rows($tretment_free_services_sql) > 0){echo"style='background: yellow;'";}?>><?php if(mysqli_num_rows($tretment_free_services_sql) > 0){echo"نعم";}else{echo"لا";}?></td>
</tr>
<tr>
<th scope="col" class="bg-primary w-12">رصيد اموال مدفوع</th>
<td <?php if(mysqli_num_rows($tretment_money_sql) > 0){ if($tretment_money['money'] > 0) { echo"style='background: #00FF00;'"; }else if($tretment_money['money'] < 0){ echo"style='background: red;'";};}?>><?php if(mysqli_num_rows($tretment_money_sql) > 0){echo $tretment_money['money'] . ' ريال';}else{echo"0 ريال";}?></td>
<th scope="col" class="bg-primary w-12">رصيد اموال مجاني</th>
<td <?php if(mysqli_num_rows($tretment_free_money_sql) > 0){echo"style='background: #00FF00;'";}?>><?php if(mysqli_num_rows($tretment_free_money_sql) > 0){echo mysqli_fetch_assoc($tretment_free_money_sql)['money'] . ' ريال';}else{echo"0 ريال";}?></td>
</tr>
<tr>
<th scope="col" class="bg-primary">تاريخ التسجيل</th>
<td><?= $row['datetime'] ?></td>
<th scope="col" class="bg-primary">هل العميل ماسي مستحق</th>
<td <?php if($total_pays > 0){echo"style='background: #00FF00;'";}?>><?php if($total_pays > 0){echo"نعم";}else{echo"لا";}?></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="col-12 col-sm-12 col-md-4 col-lg-4 col-xl-4">
<div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
<a class="nav-link active" id="v-none-tab" data-bs-toggle="pill" href="#v-none" role="tab" aria-controls="v-none" aria-selected="true">اخفاء التفاصيل</a>
<a class="nav-link" id="v-last-book-tab" data-bs-toggle="pill" href="#v-last-book" role="tab" aria-controls="v-last-book" aria-selected="false">عرض آخر 5 حجوزات</a>
<a class="nav-link" id="v-last-visit-tab" data-bs-toggle="pill" href="#v-last-visit" role="tab" aria-controls="v-last-visit" aria-selected="false">عرض آخر 5 زيارات</a>
<a class="nav-link" id="v-serv-have-tab" data-bs-toggle="pill" href="#v-serv-have" role="tab" aria-controls="v-serv-have" aria-selected="false">عرض رصيد العميل</a>
<a class="nav-link" id="v-free-serv-have-tab" data-bs-toggle="pill" href="#v-free-serv-have" role="tab" aria-controls="v-free-serv-have" aria-selected="false">عرض رصيد العميل المجاني</a>
</div>
</div>
</div>
<div class="form-group row">
<div class="tab-content" id="v-pills-tabContent">
<div class="tab-pane fade show active" id="v-none" role="tabpanel" aria-labelledby="v-none-tab">
</div>
<div class="tab-pane fade" id="v-last-book" role="tabpanel" aria-labelledby="v-last-book-tab">
<div class="table-responsive">
<table class="table table-bordered middle text-align-center">
<thead>
<tr>
<th scope="col" class="bg-primary">#</th>
<th scope="col" class="bg-primary">التاريخ</th>
<th scope="col" class="bg-primary">الوقت</th>
<th scope="col" class="bg-primary">الفني</th>
<th scope="col" class="bg-primary">الخدمة</th>
<th scope="col" class="bg-primary">الحالة</th>
</tr>
</thead>
<tbody>
<?php
$last_book_sql = mysqli_query($db, "SELECT
`book_details`.`day_date`,
`book_details`.`day_time`,
`book`.`notes`,
`emplyee`.`his_img`,
`emplyee`.`name`AS `emp_name`,
`services`.`name`,
`status`.`name` AS `state_string`
FROM `tretment`
LEFT JOIN `book` ON `book`.`tretment_id` = `tretment`.`id`
LEFT JOIN `book_details` ON `book`.`id` = `book_details`.`book_id`
LEFT JOIN `services` ON `book_details`.`services_id` = `services`.`id`
LEFT JOIN `emplyee` ON `book_details`.`emplyee_id` = `emplyee`.`id`
LEFT JOIN `status` ON `book_details`.`status_id` = `status`.`id`
WHERE `tretment`.`number` = '$tretment_number' AND `tretment`.`commercial_register_id` = $commercial_register_id AND `book_details`.`id` IN (SELECT MAX(`book_details`.`id`) FROM `book_details` GROUP BY `book_details`.`book_id`)
ORDER BY `book_details`.`id` DESC
LIMIT 5"
);
$count = 1;
if (mysqli_num_rows($last_book_sql) > 0) {
while ($get_last_book = mysqli_fetch_array($last_book_sql)) {
?>
<tr>
<td><?=$count?></td>
<td><?=$get_last_book['day_date']?></td>
<td><?=$get_last_book['day_time']?></td>
<td><?=$get_last_book['emp_name']?></td>
<td><?=$get_last_book['name']?></td>
<td><?=$get_last_book['state_string']?></td>
</tr>
<?php
$count++;
}
} else {
?>
<tr>
<td colspan="6" style="text-align: center;">لا يوجد اي معلومات</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<div class="tab-pane fade" id="v-last-visit" role="tabpanel" aria-labelledby="v-last-visit-tab">
قريبا
</div>
<div class="tab-pane fade" id="v-serv-have" role="tabpanel" aria-labelledby="v-serv-have-tab">
<div class="table-responsive">
<table class="table table-bordered middle text-align-center">
<thead>
<tr>
<th scope="col" class="bg-primary">#</th>
<th scope="col" class="bg-primary">الخدمة</th>
<th scope="col" class="bg-primary">عددها</th>
</tr>
</thead>
<tbody>
<?php
$count = 1;
if (mysqli_num_rows($tretment_services_sql) > 0) {
while ($get_tretment_services = mysqli_fetch_array($tretment_services_sql)) {
?>
<tr>
<td><?=$count?></td>
<td><?=$get_tretment_services['name']?></td>
<td><?=$get_tretment_services['how_many']?></td>
</tr>
<?php
$count++;
}
} else {
?>
<tr>
<td colspan="6" style="text-align: center;">لا يوجد اي معلومات</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<div class="tab-pane fade" id="v-free-serv-have" role="tabpanel" aria-labelledby="v-free-serv-have-tab">
<div class="table-responsive">
<table class="table table-bordered middle text-align-center">
<thead>
<tr>
<th scope="col" class="bg-primary">#</th>
<th scope="col" class="bg-primary">الخدمة</th>
<th scope="col" class="bg-primary">عددها</th>
</tr>
</thead>
<tbody>
<?php
$count = 1;
if (mysqli_num_rows($tretment_free_services_sql) > 0) {
while ($get_tretment_services = mysqli_fetch_array($tretment_free_services_sql)) {
?>
<tr>
<td><?=$count?></td>
<td><?=$get_tretment_services['name']?></td>
<td><?=$get_tretment_services['how_many']?></td>
</tr>
<?php
$count++;
}
} else {
?>
<tr>
<td colspan="6" style="text-align: center;">لا يوجد اي معلومات</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script>
searchClick = 0;
</script>
<?php
} else {
?>
<script>
swalthen('العميل غير مسجل','هل ترغب بتسجيل العميل ؟','info','add_tretment.php?emp_id=<?=$emp_id?>&date=<?=$booking_day_date?>&time=<?=$booking_day_time?>&branch=<?=$branch_id?>&number=<?=$tretment_number?>');
searchClick = 0;
</script>
<?php
}
}
?>