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

1318 lines
102 KiB
PHP

<?php
require_once('../../../fixed/config/go_con.php');
access(5);
$tretment_id = mysqli_real_escape_string($db, $_POST['tretment_id']);
$data['req_ids'] = $_POST['data'];
$get_services_sql = mysqli_query($db, "SELECT
`tretment`.`an_employee_offer_id`,
`tretment`.`name`,
`an_employee_offer`.`id` AS `emp_id`,
`an_employee_offer`.`name` AS `emp_name`,
`total_points`.`point`,
`tretment`.`date_time`,
`commercial_register`.`id` AS `br_id`,
(SELECT `name` FROM `ranks` WHERE `total_points`.`point` BETWEEN `start` AND `end`) AS `rank`
FROM `tretment`
LEFT JOIN `an_employee_offer` ON `tretment`.`an_employee_offer_id` = `an_employee_offer`.`id`
LEFT JOIN `commercial_register` ON `tretment`.`commercial_register_id` = `commercial_register`.`id`
LEFT JOIN `total_points` ON `total_points`.`tretment_id` = `tretment`.`id`
WHERE `tretment`.`id` = $tretment_id"
);
$row_services = mysqli_fetch_assoc($get_services_sql);
switch ($row_services['br_id']) {
case '2':
$br_id = 2;
break;
case '3':
$br_id = 5;
break;
default:
$br_id = 2;
break;
}
$emp_id = $row_services['emp_id'];
$an_employee_offer_id = $row_services['an_employee_offer_id'];
$tretment_date_time = $row_services['date_time'];
$tretment_points = $row_services['point'];
$name = $row_services['name'];
$emp_name = $row_services['emp_name'];
$tretment_rank = $row_services['rank'];
$price = $row_services['price'];
$price_vat = 0;
if (!empty($vat)) {
$price_vat = ($price*$vat)/100;
}
$show_price = $price + $price_vat;
?>
<div class="card">
<div class="card-body new-user order-list">
<div class="form-group row">
<div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12">
<div class="table-responsive">
<table class="table table-bordered text-center" style="vertical-align: middle;">
<thead class="table-primary">
<tr>
<th scope="col">العميل</th>
<td style ="background-color: #fff;" scope="col"><?= $name ?></td>
<th scope="col">جهه العمل</th>
<td style ="background-color: #fff;" scope="col"><?= $emp_name ?></td>
<th scope="col">العضوية</th>
<td style ="background-color: #fff;" scope="col"><?= $tretment_rank ?></td>
</tr>
</thead>
<thead class="table-primary">
<tr>
<th scope="col">#</th>
<th colspan="2" scope="col">الخدمات</th>
<th scope="col">الفرع</th>
<th scope="col">السعر</th>
</tr>
</thead>
<tbody>
<?php
$services_ids_sql = implode(', ',array_keys($data['req_ids']));
$get_book_details_sql = mysqli_query($db, "SELECT
`services`.`id`,
`services`.`name`,
`services`.`price`
FROM `services`
WHERE `services`.`id` IN ($services_ids_sql)
AND `services`.`activation_id` = 2
");
$count = 1;
$total = 0;
$total_w_vat = 0;
$services_ids = array();
if (mysqli_num_rows($get_book_details_sql) > 0) {
while ($row_book_details = mysqli_fetch_assoc($get_book_details_sql)) {
$price_temp = 0;
array_push($services_ids,
array(
'book_id' => $row_book_details['book_id'],
'book_time' => $row_book_details['day_time'],
'book_day' => $row_book_details['day_date'],
'id' => $row_book_details['id'],
'name' => $row_book_details['name'],
'price' => $row_book_details['price'],
'price_v' => round($row_book_details['price'] + ($row_book_details['price']*$vat)/100, 2)
)
);
$price_temp += $row_book_details['price'];
if (!empty($vat)) {
$price_temp = round($price_temp + ($price_temp*$vat)/100, 2);
}
?>
<tr>
<td scope="row"><?=$count?></td>
<td colspan="2"><?=$row_book_details['name']?></td>
<td><?=$row_book_details['branch_name']?></td>
<td><?=$price_temp?></td>
</tr>
<?php
$count++;
$total += $row_book_details['price'];
$total_w_vat += $price_temp;
}
} else {
?>
<!-- <script type='text/javascript'>
window.location.href = 'index.php'
</script> -->
<?php
}
//collect data
$data['serv'] = $services_ids;
$data['total'] = $total;
//collect data end
$show_price = $total_w_vat;
?>
</tbody>
<thead class="table-primary">
<tr>
<th colspan="4" scope="col">المجموع</th>
<th style ="background-color: #fff;" scope="col"><?=$total_w_vat?></th>
<th></th>
</tr>
</thead>
</table>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12">
<div class="table-responsive">
<table class="table table-bordered text-center" style="vertical-align: middle;">
<thead class="table-primary">
<tr>
<th colspan="6" scope="col">الخصومات</th>
</tr>
</thead>
<thead class="table-primary">
<tr>
<th scope="col">#</th>
<th scope="col">الخدمة</th>
<th scope="col">الخصم</th>
<th scope="col">سبب الخصم</th>
<th scope="col">مبلغ الخصم</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<?php
$offers = array();
$array_count_values = array();
for ($z=0; $z < count($services_ids); $z++) {
$serv_id_temp = $services_ids[$z]['id'];
$book_time = $services_ids[$z]['book_time'];
$book_day = $services_ids[$z]['book_day'];
$book_price = $services_ids[$z]['price'];
$book_day_time = $services_ids[$z]['book_day'] . ' ' . $services_ids[$z]['book_time'];
array_push($array_count_values,$serv_id_temp);
$serv_count = array_count_values($array_count_values);
$offers['s_'.$serv_id_temp.'_'.$serv_count[$serv_id_temp]] = array();
$stop_date_time_reg_tretment_offer = true;
// an employee offers
$get_an_employee_offer_has_services_sql = mysqli_query($db, "SELECT
(SELECT `id` FROM `db_tables` WHERE `name` = 'an_employee_offer') AS `db_id`,
`an_employee_offer_has_services`.`services_id`,
`services`.`name` AS `serv_name`,
`services`.`price`,
`an_employee_offer`.`id` AS `offer_id`,
`an_employee_offer`.`name`,
`an_employee_offer`.`discount`,
`an_employee_offer`.`type_discount_id`,
`an_employee_offer`.`does_discount_enters_id`
FROM `an_employee_offer_has_services`
LEFT JOIN `an_employee_offer` ON `an_employee_offer`.`id` = `an_employee_offer_has_services`.`an_employee_offer_id`
LEFT JOIN `services` ON `services`.`id` = `an_employee_offer_has_services`.`services_id`
WHERE `an_employee_offer_has_services`.`an_employee_offer_id` = $emp_id
AND `an_employee_offer_has_services`.`services_id` = $serv_id_temp
");
if (mysqli_num_rows($get_an_employee_offer_has_services_sql) > 0) {
while ($row_an_employee_offer_has_services = mysqli_fetch_assoc($get_an_employee_offer_has_services_sql)) {
$discount_p = '';
$discount_style = '';
switch ($row_an_employee_offer_has_services['type_discount_id']) {
case 2:
$discount_p = $row_an_employee_offer_has_services['discount'];
$discount_style = $row_an_employee_offer_has_services['discount'] . 'ريال';
break;
case 3:
$discount_p = ($row_an_employee_offer_has_services['discount']/100) * $row_an_employee_offer_has_services['price'];
$discount_style = $row_an_employee_offer_has_services['discount'] . '%';
break;
}
if ($an_employee_offer_id == 45) {
if (strtotime($book_day_time) >= strtotime('2022-01-01 00:00:00') && strtotime($book_day_time) < strtotime('2023-12-31 23:59:59') ) {
if ($serv_id_temp == 1 || $serv_id_temp == 2) {
$temp_des = $price - 100;
$discount_p = $temp_des;
$discount_style = $temp_des . 'ريال';
$stop_date_time_reg_tretment_offer = false;
} elseif ($serv_id_temp == 3) {
$temp_des = $price - 180;
$discount_p = $temp_des;
$discount_style = $temp_des . 'ريال';
$stop_date_time_reg_tretment_offer = false;
}
}
}
array_push($offers['s_'.$row_an_employee_offer_has_services['services_id'].'_'.$serv_count[$serv_id_temp]],
array(
'offer_id' => $row_an_employee_offer_has_services['offer_id'],
'serv_name' => $row_an_employee_offer_has_services['serv_name'],
'db_id' => $row_an_employee_offer_has_services['db_id'],
'discount_name' => $row_an_employee_offer_has_services['name'],
'discount' => $discount_p,
'discount_style' => $discount_style,
'services_id' => $row_an_employee_offer_has_services['services_id'],
'does_discount_enters_id' => $row_an_employee_offer_has_services['does_discount_enters_id']
)
);
}
}
// ranks offer
$get_ranks_offer_has_services_sql = mysqli_query($db, "SELECT
(SELECT `id` FROM `db_tables` WHERE `name` = 'ranks_offer') AS `db_id`,
`ranks_offer_has_services`.`services_id`,
`services`.`name` AS `serv_name`,
`services`.`price`,
`ranks_offer`.`id` AS `offer_id`,
`ranks_offer`.`name`,
`ranks_offer`.`discount`,
`ranks_offer`.`type_discount_id`,
`ranks_offer`.`does_discount_enters_id`
FROM `ranks_offer_has_services`
LEFT JOIN `ranks_offer` ON `ranks_offer`.`id` = `ranks_offer_has_services`.`ranks_offer_id`
LEFT JOIN `ranks` ON `ranks`.`id` = `ranks_offer`.`ranks_id`
LEFT JOIN `services` ON `services`.`id` = `ranks_offer_has_services`.`services_id`
WHERE '$tretment_points' BETWEEN `ranks`.`start` AND `ranks`.`end`
AND `ranks_offer_has_services`.`services_id` = $serv_id_temp
");
if (mysqli_num_rows($get_ranks_offer_has_services_sql) > 0) {
while ($row_ranks_offer_has_services = mysqli_fetch_assoc($get_ranks_offer_has_services_sql)) {
$discount_p = '';
$discount_style = '';
switch ($row_ranks_offer_has_services['type_discount_id']) {
case 2:
$discount_p = $row_ranks_offer_has_services['discount'];
$discount_style = $row_ranks_offer_has_services['discount'] . 'ريال';
break;
case 3:
$discount_p = ($row_ranks_offer_has_services['discount']/100) * $row_ranks_offer_has_services['price'];
$discount_style = $row_ranks_offer_has_services['discount'] . '%';
break;
}
array_push($offers['s_'.$row_ranks_offer_has_services['services_id'].'_'.$serv_count[$serv_id_temp]],
array(
'offer_id' => $row_ranks_offer_has_services['offer_id'],
'serv_name' => $row_ranks_offer_has_services['serv_name'],
'db_id' => $row_ranks_offer_has_services['db_id'],
'discount_name' => $row_ranks_offer_has_services['name'],
'discount' => $discount_p,
'discount_style' => $discount_style,
'services_id' => $row_ranks_offer_has_services['services_id'],
'does_discount_enters_id' => $row_ranks_offer_has_services['does_discount_enters_id']
)
);
}
}
// date time reg tretment_offer
$he_is_old = false;
if ($stop_date_time_reg_tretment_offer) {
$get_date_time_reg_tretment_offer_sql = mysqli_query($db, "SELECT
(SELECT `id` FROM `db_tables` WHERE `name` = 'date_time_reg_tretment_offer') AS `db_id`,
`date_time_reg_tretment_offer_has_services`.`services_id`,
`services`.`name` AS `serv_name`,
`services`.`price`,
`date_time_reg_tretment_offer`.`id` AS `offer_id`,
`date_time_reg_tretment_offer`.`name`,
`date_time_reg_tretment_offer`.`discount`,
`date_time_reg_tretment_offer`.`type_discount_id`,
`date_time_reg_tretment_offer`.`does_discount_enters_id`,
TIME(`date_time_reg_tretment_offer`.`from_date_time`) AS `fromTime`,
TIME(`date_time_reg_tretment_offer`.`to_date_time`) AS `toTime`
FROM `date_time_reg_tretment_offer_has_services`
LEFT JOIN `date_time_reg_tretment_offer` ON `date_time_reg_tretment_offer`.`id` = `date_time_reg_tretment_offer_has_services`.`date_time_reg_tretment_offer_id`
LEFT JOIN `services` ON `services`.`id` = `date_time_reg_tretment_offer_has_services`.`services_id`
WHERE `branch_id` = $br_id
AND '$tretment_date_time' BETWEEN `from_date_time` AND `to_date_time`
AND `date_time_reg_tretment_offer_has_services`.`services_id` = $serv_id_temp
AND `date_time_reg_tretment_offer`.`activation_id` = 2
");
if (mysqli_num_rows($get_date_time_reg_tretment_offer_sql) > 0) {
$he_is_old = true;
while ($row_date_time_reg_tretment_offer = mysqli_fetch_assoc($get_date_time_reg_tretment_offer_sql)) {
$offer_id = $row_date_time_reg_tretment_offer['offer_id'];
$discount_p = '';
$discount_style = '';
switch ($row_date_time_reg_tretment_offer['type_discount_id']) {
case 2:
$discount_p = $row_date_time_reg_tretment_offer['discount'];
$discount_style = $row_date_time_reg_tretment_offer['discount'] . ' ريال ';
break;
case 3:
$discount_p = ($row_date_time_reg_tretment_offer['discount']/100) * $row_date_time_reg_tretment_offer['price'];
$discount_style = $row_date_time_reg_tretment_offer['discount'] . '%';
break;
}
array_push($offers['s_'.$row_date_time_reg_tretment_offer['services_id'].'_'.$serv_count[$serv_id_temp]],
array(
'offer_id' => $row_date_time_reg_tretment_offer['offer_id'],
'serv_name' => $row_date_time_reg_tretment_offer['serv_name'],
'db_id' => $row_date_time_reg_tretment_offer['db_id'],
'discount_name' => $row_date_time_reg_tretment_offer['name'],
'discount' => $discount_p,
'discount_style' => $discount_style,
'services_id' => $row_date_time_reg_tretment_offer['services_id'],
'does_discount_enters_id' => $row_date_time_reg_tretment_offer['does_discount_enters_id']
)
);
}
}
}
$he_is_3_serv = false;
if (!$he_is_old) {
// after how many serv offer // not auto
$get_after_how_many_serv_offer_sql = mysqli_query($db, "SELECT `book`.`id`
FROM `tretment`
LEFT JOIN `book` ON `book`.`tretment_id` = `tretment`.`id`
LEFT JOIN `book_details` AS `dd` ON `book`.`id` = `dd`.`book_id`
WHERE `tretment`.`id` = $tretment_id
AND `dd`.`id` IN (SELECT MAX(`id`) FROM `book_details` WHERE `book_id` = `dd`.`book_id`)
AND `dd`.`services_id` IN (1,3,93,95)
AND `dd`.`status_id` IN (6,8,14,15)
");
if (mysqli_num_rows($get_after_how_many_serv_offer_sql) >= 3) {
$get_after_how_many_serv_offer_has_services_sql = mysqli_query($db, "SELECT
(SELECT `id` FROM `db_tables` WHERE `name` = 'after_how_many_serv_offer') AS `db_id`,
`after_how_many_serv_offer_has_services`.`services_id`,
`services`.`name` AS `serv_name`,
`services`.`price`,
`after_how_many_serv_offer`.`id` AS `offer_id`,
`after_how_many_serv_offer`.`name`,
`after_how_many_serv_offer`.`discount`,
`after_how_many_serv_offer`.`type_discount_id`,
`after_how_many_serv_offer`.`does_discount_enters_id`
FROM `after_how_many_serv_offer_has_services`
LEFT JOIN `after_how_many_serv_offer` ON `after_how_many_serv_offer`.`id` = `after_how_many_serv_offer_has_services`.`after_how_many_serv_offer_id`
LEFT JOIN `services` ON `services`.`id` = `after_how_many_serv_offer_has_services`.`services_id`
WHERE `after_how_many_serv_offer_has_services`.`after_how_many_serv_offer_id` = 1
AND `after_how_many_serv_offer_has_services`.`services_id` = $serv_id_temp
");
if (mysqli_num_rows($get_after_how_many_serv_offer_has_services_sql) > 0) {
$he_is_3_serv = true;
while ($row_after_how_many_serv_offer_has_services = mysqli_fetch_assoc($get_after_how_many_serv_offer_has_services_sql)) {
$discount_p = '';
$discount_style = '';
switch ($row_after_how_many_serv_offer_has_services['type_discount_id']) {
case 2:
$discount_p = $row_after_how_many_serv_offer_has_services['discount'];
$discount_style = $row_after_how_many_serv_offer_has_services['discount'] . 'ريال';
break;
case 3:
$discount_p = ($row_after_how_many_serv_offer_has_services['discount']/100) * $row_after_how_many_serv_offer_has_services['price'];
if ($he_is_old) {
$discount_p = ($row_after_how_many_serv_offer_has_services['discount']/100) * ($row_after_how_many_serv_offer_has_services['price']-50);
}
$discount_style = $row_after_how_many_serv_offer_has_services['discount'] . '%';
break;
}
array_push($offers['s_'.$row_after_how_many_serv_offer_has_services['services_id'].'_'.$serv_count[$serv_id_temp]],
array(
'offer_id' => $row_after_how_many_serv_offer_has_services['offer_id'],
'serv_name' => $row_after_how_many_serv_offer_has_services['serv_name'],
'db_id' => $row_after_how_many_serv_offer_has_services['db_id'],
'discount_name' => $row_after_how_many_serv_offer_has_services['name'],
'discount' => $discount_p,
'discount_style' => $discount_style,
'services_id' => $row_after_how_many_serv_offer_has_services['services_id'],
'does_discount_enters_id' => $row_after_how_many_serv_offer_has_services['does_discount_enters_id']
)
);
}
}
}
}
// from to offers
// $do_not_enter = false;
// $get_from_to_offers_sql = mysqli_query($db, "SELECT
// (SELECT `id` FROM `db_tables` WHERE `name` = 'from_to_offers') AS `db_id`,
// `from_to_offers_has_services`.`services_id`,
// `services`.`name` AS `serv_name`,
// `services`.`price`,
// `from_to_offers`.`id` AS `offer_id`,
// `from_to_offers`.`name`,
// `from_to_offers`.`discount`,
// `from_to_offers`.`type_discount_id`,
// `from_to_offers`.`does_discount_enters_id`,
// `from_to_offers`.`offer_does_have_dayoff_id`,
// TIME(`from_to_offers`.`from_date_time`) AS `fromTime`,
// TIME(`from_to_offers`.`to_date_time`) AS `toTime`
// FROM `from_to_offers_has_services`
// LEFT JOIN `from_to_offers` ON `from_to_offers`.`id` = `from_to_offers_has_services`.`from_to_offers_id`
// LEFT JOIN `services` ON `services`.`id` = `from_to_offers_has_services`.`services_id`
// WHERE `branch_id` = $br_id
// AND `to_date_time` >= '$book_day_time'
// AND `from_to_offers_has_services`.`services_id` = $serv_id_temp
// AND `from_to_offers`.`activation_id` = 2
// ");
// $do_not_enter_with_this_ids = array(12,13,14);
// if (mysqli_num_rows($get_from_to_offers_sql) > 0) {
// while ($row_from_to_offers = mysqli_fetch_assoc($get_from_to_offers_sql)) {
// $time_work = array();
// $from = $row_from_to_offers['fromTime'][0] . $row_from_to_offers['fromTime'][1];
// $to = $row_from_to_offers['toTime'][0] . $row_from_to_offers['toTime'][1];
// $skip_frist = 0;
// for ($from; $from <= $to; $from++) {
// $push_time_work = $from . ":00:00";
// if ($skip_frist != 0) {
// if ($from < 10) {
// $push_time_work = "0" . $from . ":00:00";
// }
// }
// array_push($time_work, $push_time_work);
// $skip_frist++;
// }
// $offer_id = $row_from_to_offers['offer_id'];
// if (in_array($offer_id, $do_not_enter_with_this_ids)) {
// $do_not_enter = true;
// }
// $go_flowerd_in_des = true;
// if ($row_from_to_offers['offer_does_have_dayoff_id'] == 2) {
// $get_from_to_offers_has_days_sql = mysqli_query($db, "SELECT
// `days`.`day`
// FROM `from_to_offers_has_days`
// LEFT JOIN `days` ON `days`.`id` = `from_to_offers_has_days`.`days_id`
// WHERE `from_to_offers_has_days`.`activation_id` = 2
// AND `from_to_offers_has_days`.`from_to_offers_id` = $offer_id
// ");
// $Days = array();
// if (mysqli_num_rows($get_from_to_offers_has_days_sql) > 0) {
// while ($row_from_to_offers_has_days = mysqli_fetch_assoc($get_from_to_offers_has_days_sql)) {
// array_push($Days, $row_from_to_offers_has_days['day']);
// }
// $Day = date('D', strtotime($book_day));
// if (!in_array($Day, $Days)) {
// $go_flowerd_in_des = false;
// }
// }
// }
// if (in_array($book_time, $time_work) && $go_flowerd_in_des) {
// $discount_p = '';
// $discount_style = '';
// switch ($row_from_to_offers['type_discount_id']) {
// case 2:
// $discount_p = $row_from_to_offers['discount'];
// $discount_style = $row_from_to_offers['discount'] . ' ريال ';
// break;
// case 3:
// $discount_p = ($row_from_to_offers['discount']/100) * $row_from_to_offers['price'];
// if (($he_is_old && $row_from_to_offers['services_id'] == 3)|| $he_is_3_serv) {
// $discount_p = ($row_from_to_offers['discount']/100) * ($row_from_to_offers['price']-50);
// }
// $discount_style = $row_from_to_offers['discount'] . '%';
// break;
// }
// array_push($offers['s_'.$row_from_to_offers['services_id'].'_'.$serv_count[$serv_id_temp]],
// array(
// 'offer_id' => $row_from_to_offers['offer_id'],
// 'serv_name' => $row_from_to_offers['serv_name'],
// 'db_id' => $row_from_to_offers['db_id'],
// 'discount_name' => $row_from_to_offers['name'],
// 'discount' => $discount_p,
// 'discount_style' => $discount_style,
// 'services_id' => $row_from_to_offers['services_id'],
// 'does_discount_enters_id' => $row_from_to_offers['does_discount_enters_id']
// )
// );
// }
// }
// }
// special offer
$get_an_employee_offer_sql = mysqli_query($db, "SELECT
`special_offer_id`
FROM `tretment_has_special_offer`
WHERE `tretment_has_special_offer`.`tretment_id` = $tretment_id
");
if (mysqli_num_rows($get_an_employee_offer_sql) > 0) {
while ($get_special_offer = mysqli_fetch_assoc($get_an_employee_offer_sql)) {
$special_offer_id = $get_special_offer['special_offer_id'];
$get_special_offer_sql = mysqli_query($db, "SELECT
(SELECT `id` FROM `db_tables` WHERE `name` = 'special_offer') AS `db_id`,
`special_offer_has_services`.`services_id`,
`services`.`name` AS `serv_name`,
`services`.`price`,
`special_offer`.`id` AS `offer_id`,
`special_offer`.`name`,
`special_offer`.`discount`,
`special_offer`.`type_discount_id`,
`special_offer`.`does_discount_enters_id`
FROM `special_offer_has_services`
LEFT JOIN `special_offer` ON `special_offer`.`id` = `special_offer_has_services`.`special_offer_id`
LEFT JOIN `services` ON `services`.`id` = `special_offer_has_services`.`services_id`
WHERE `special_offer_has_services`.`special_offer_id` = $special_offer_id
AND `special_offer_has_services`.`services_id` = $serv_id_temp
");
if (mysqli_num_rows($get_special_offer_sql) > 0) {
while ($row_special_offer = mysqli_fetch_assoc($get_special_offer_sql)) {
$discount_p = '';
$discount_style = '';
switch ($row_special_offer['type_discount_id']) {
case 2:
$discount_p = $row_special_offer['discount'];
$discount_style = $row_special_offer['discount'] . 'ريال';
break;
case 3:
$discount_p = ($row_special_offer['discount']/100) * $row_special_offer['price'];
if (($he_is_old || $he_is_3_serv) && $row_special_offer['services_id'] == 3) {
$discount_p = ($row_special_offer['discount']/100) * ($row_special_offer['price']-50);
}
$discount_style = $row_special_offer['discount'] . '%';
break;
}
array_push($offers['s_'.$row_special_offer['services_id'].'_'.$serv_count[$serv_id_temp]],
array(
'offer_id' => $row_special_offer['offer_id'],
'serv_name' => $row_special_offer['serv_name'],
'db_id' => $row_special_offer['db_id'],
'discount_name' => $row_special_offer['name'],
'discount' => $discount_p,
'discount_style' => $discount_style,
'services_id' => $row_special_offer['services_id'],
'does_discount_enters_id' => $row_special_offer['does_discount_enters_id']
)
);
}
}
}
}
// custom discount
$has_custom_discount = 0;
$get_an_employee_offer_has_services_sql = mysqli_query($db, "SELECT
`tretment_has_custom_discount`.`services_id`,
`services`.`name` AS `serv_name`,
`services`.`price`,
`tretment_has_custom_discount`.`id` AS `offer_id`,
`custom_discount`.`reason` AS `name`,
`tretment_has_custom_discount`.`discount`,
`tretment_has_custom_discount`.`type_discount_id`
FROM `tretment_has_custom_discount`
LEFT JOIN `custom_discount` ON `custom_discount`.`id` = `tretment_has_custom_discount`.`inv_table_id`
LEFT JOIN `services` ON `services`.`id` = `tretment_has_custom_discount`.`services_id`
WHERE `tretment_has_custom_discount`.`tretment_id` = $tretment_id
AND `tretment_has_custom_discount`.`done_id` = 1
AND `tretment_has_custom_discount`.`services_id` = $serv_id_temp
");
if (mysqli_num_rows($get_an_employee_offer_has_services_sql) > 0) {
while ($row_an_employee_offer_has_services = mysqli_fetch_assoc($get_an_employee_offer_has_services_sql)) {
$discount_p = '';
$discount_style = '';
switch ($row_an_employee_offer_has_services['type_discount_id']) {
case 2:
$discount_p = $row_an_employee_offer_has_services['discount'];
$discount_style = $row_an_employee_offer_has_services['discount'] . 'ريال';
break;
case 3:
$discount_p = ($row_an_employee_offer_has_services['discount']/100) * $row_an_employee_offer_has_services['price'];
$discount_style = $row_an_employee_offer_has_services['discount'] . '%';
break;
}
$has_custom_discount++;
array_push($offers['s_'.$row_an_employee_offer_has_services['services_id'].'_'.$serv_count[$serv_id_temp]],
array(
'offer_id' => $row_an_employee_offer_has_services['offer_id'],
'serv_name' => $row_an_employee_offer_has_services['serv_name'],
'db_id' => 18,
'discount_name' => $row_an_employee_offer_has_services['name'],
'discount' => $discount_p,
'discount_style' => $discount_style,
'services_id' => $row_an_employee_offer_has_services['services_id'],
'does_discount_enters_id' => 1
)
);
}
}
// coupon
$has_coupon = 0;
$get_does_he_use_it_sql = mysqli_query($db, "SELECT `isdtdshsdbts`.`invoices_discount_details_id`
FROM `invoices_discount_details_has_db_tables` AS `isdtdshsdbts`
LEFT JOIN `invoices_discount_details` AS `isdtds` ON `isdtds`.`id` = `isdtdshsdbts`.`invoices_discount_details_id`
LEFT JOIN `invoices_discount` AS `isdt` ON `isdtds`.`invoices_discount_id` = `isdt`.`id`
LEFT JOIN `invoices_details` AS `isds` ON `isdt`.`invoices_details_id` = `isds`.`id`
LEFT JOIN `invoices_has_book` AS `ishsbk` ON `isds`.`invoices_id` = `ishsbk`.`invoices_id`
LEFT JOIN `book` AS `bk` ON `bk`.`id` = `ishsbk`.`book_id`
WHERE `isdtdshsdbts`.`db_tables_id` = 21 AND `isdtdshsdbts`.`db_tables_id_to_id` IN (2,3,4,5)
AND bk.tretment_id = $tretment_id
");
if (mysqli_num_rows($get_does_he_use_it_sql) == 0 && $serv_id_temp == 1) {
$get_an_employee_offer_has_services_sql = mysqli_query($db, "SELECT
`tretment_has_coupons`.`coupons_id` AS `offer_id`,
`tretment_has_coupons`.`code` AS `name`,
`coupons`.`discount`,
`coupons`.`type_discount_id`
FROM `tretment_has_coupons`
INNER JOIN `coupons` ON `coupons`.`id` = `tretment_has_coupons`.`coupons_id`
WHERE `tretment_has_coupons`.`tretment_id` = $tretment_id
");
if (mysqli_num_rows($get_an_employee_offer_has_services_sql) > 0) {
while ($row_an_employee_offer_has_services = mysqli_fetch_assoc($get_an_employee_offer_has_services_sql)) {
$discount_p = '';
$discount_style = '';
switch ($row_an_employee_offer_has_services['type_discount_id']) {
case 2:
$discount_p = $row_an_employee_offer_has_services['discount'];
$discount_style = $row_an_employee_offer_has_services['discount'] . 'ريال';
break;
case 3:
$discount_p = ($row_an_employee_offer_has_services['discount']/100) * 200;
$discount_style = $row_an_employee_offer_has_services['discount'] . '%';
break;
}
$has_custom_discount++;
array_push($offers['s_1_'.$serv_count[$serv_id_temp]],
array(
'offer_id' => $row_an_employee_offer_has_services['offer_id'],
'serv_name' => 'تدليك الاقدام',
'db_id' => 21,
'discount_name' => $row_an_employee_offer_has_services['name'],
'discount' => $discount_p,
'discount_style' => $discount_style,
'services_id' => 1,
'does_discount_enters_id' => 1,
)
);
}
}
}
// custom offer
if(!$do_not_enter){
if ($has_custom_discount == 0 || $has_coupon == 0) {
$get_invoices_has_book_sql = mysqli_query($db, "SELECT
`invoices_id` FROM `invoices_has_book` WHERE `book_id` IN (
SELECT `id` FROM `book` WHERE `tretment_id` = $tretment_id
)
LIMIT 1
");
$get_does_he_use_it_sql = mysqli_query($db, "SELECT `isdtdshsdbts`.`invoices_discount_details_id`
FROM `invoices_discount_details_has_db_tables` AS `isdtdshsdbts`
LEFT JOIN `invoices_discount_details` AS `isdtds` ON `isdtds`.`id` = `isdtdshsdbts`.`invoices_discount_details_id`
LEFT JOIN `invoices_discount` AS `isdt` ON `isdtds`.`invoices_discount_id` = `isdt`.`id`
LEFT JOIN `invoices_details` AS `isds` ON `isdt`.`invoices_details_id` = `isds`.`id`
LEFT JOIN `invoices_has_book` AS `ishsbk` ON `isds`.`invoices_id` = `ishsbk`.`invoices_id`
LEFT JOIN `book` AS `bk` ON `bk`.`id` = `ishsbk`.`book_id`
WHERE `isdtdshsdbts`.`db_tables_id` = 7 AND `isdtdshsdbts`.`db_tables_id_to_id` = 1
AND bk.tretment_id = $tretment_id
");
if (mysqli_num_rows($get_invoices_has_book_sql) > 0 && mysqli_num_rows($get_does_he_use_it_sql) == 0) {
$get_custom_offer_sql = mysqli_query($db, "SELECT
(SELECT `id` FROM `db_tables` WHERE `name` = 'custom_offer') AS `db_id`,
`custom_offer_has_services`.`services_id`,
`services`.`name` AS `serv_name`,
`services`.`price`,
`custom_offer`.`id` AS `offer_id`,
`custom_offer`.`name`,
`custom_offer`.`discount`,
`custom_offer`.`type_discount_id`,
`custom_offer`.`does_discount_enters_id`
FROM `custom_offer_has_services`
LEFT JOIN `custom_offer` ON `custom_offer`.`id` = `custom_offer_has_services`.`custom_offer_id`
LEFT JOIN `services` ON `services`.`id` = `custom_offer_has_services`.`services_id`
WHERE `custom_offer_has_services`.`services_id` = $serv_id_temp
");
if (mysqli_num_rows($get_custom_offer_sql) > 0) {
while ($row_custom_offer = mysqli_fetch_assoc($get_custom_offer_sql)) {
$discount_p = '';
$discount_style = '';
switch ($row_custom_offer['type_discount_id']) {
case 2:
$discount_p = $row_custom_offer['discount'];
$discount_style = $row_custom_offer['discount'] . 'ريال';
break;
case 3:
$discount_p = ($row_custom_offer['discount']/100) * $row_custom_offer['price'];
$discount_style = $row_custom_offer['discount'] . '%';
break;
}
array_push($offers['s_'.$row_custom_offer['services_id'].'_'.$serv_count[$serv_id_temp]],
array(
'offer_id' => $row_custom_offer['offer_id'],
'serv_name' => $row_custom_offer['serv_name'],
'db_id' => $row_custom_offer['db_id'],
'discount_name' => $row_custom_offer['name'],
'discount' => $discount_p,
'discount_style' => $discount_style,
'services_id' => $row_custom_offer['services_id'],
'does_discount_enters_id' => $row_custom_offer['does_discount_enters_id']
)
);
}
}
}
}
}
}
// $sort_by_price = array();
// foreach ($offers as $key => $row)
// {
// $sort_by_price[$key] = $row['discount'];
// }
// array_multisort($sort_by_price, SORT_DESC, $offers);
$count_temp_2 = 1;
$move_flowerd = array_keys($offers);
$filter_offers = array_filter($offers);
if (count($filter_offers) == 0) {
?>
<tr>
<td colspan="6" scope="row">لا يتوفر اي خصم للعميل</td>
</tr>
</tbody>
<?php
} else {
for ($i=0; $i < count($offers); $i++) {
if (count($offers[$move_flowerd[$i]]) == 0) {
continue;
}
?>
<td rowspan="<?=count($offers[$move_flowerd[$i]])+1?>" scope="row"><?=$count_temp_2?></td>
<td rowspan="<?=count($offers[$move_flowerd[$i]])+1?>" scope="row"><?=$offers[$move_flowerd[$i]][0]['serv_name']?></td>
<?php
for ($z=0; $z < count($offers[$move_flowerd[$i]]); $z++) {
$one_singil_offer = $offers[$move_flowerd[$i]][$z];
if (!empty($vat)) {
$discount_temp = round($one_singil_offer['discount'] + ($one_singil_offer['discount']*$vat)/100, 2);
}
?>
<tr>
<td scope="row"><?=$one_singil_offer['discount_style']?></td>
<td scope="row"><?=$one_singil_offer['discount_name']?></td>
<td scope="row"><?=$discount_temp?></td>
<td scope="row">
<div class="form-check form-check-inline">
<div class="radio radio-primary get-data-radio">
<input type="radio" id="<?=$move_flowerd[$i].$z?>" name="<?php if ($one_singil_offer['does_discount_enters_id'] == 1){echo $move_flowerd[$i];}elseif($one_singil_offer['does_discount_enters_id'] == 2){echo $move_flowerd[$i].$z;}?>" data-when-call-all='<?=$move_flowerd[$i]?>' data-parsley-multiple="groups" data-parsley-mincheck="2"
data-offer-id='<?=$one_singil_offer["offer_id"]?>'
data-db-id='<?=$one_singil_offer["db_id"]?>'
data-discount='<?=$discount_temp?>'
data-why-discount='<?=$one_singil_offer['discount_name']?>'
data-discount-style='<?=$one_singil_offer["discount_style"]?>'
data-services-id='<?=$one_singil_offer["services_id"]?>'
data-does-discount-enters-id='<?=$one_singil_offer["does_discount_enters_id"]?>'>
<label class="mb-0" for="<?=$move_flowerd[$i].$z?>">تفعيل</label>
</div>
</div>
</td>
</tr>
<?php
}
$count_temp_2++;
}
?>
</tbody>
<thead class="table-primary">
<tr>
<th colspan="4" scope="col">المجموع</th>
<th style ="background-color: #fff;" scope="col" id='total_desc'><?=$total_discount_w_vat?></th>
<th></th>
</tr>
</thead>
<?php
}
?>
</table>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12">
<h2 class="text-center">
المبلغ المستحق
<span id='current_price' style="color:red"> <?= round($show_price, 2) ?> </span>
ريال
</h2>
</div>
</div>
<div class="form-group row">
<div class="col-12 col-sm-12 col-md-3 col-lg-3 col-xl-3">
<div class="table-responsive">
<table class="table table-bordered text-center">
<thead class="table-primary">
<tr>
<th colspan="2" scope="col">رصيد الخدمات</th>
</tr>
</thead>
<?php
$get_tretment_has_service_sql = mysqli_query($db,
"SELECT `services`.`id`, `services`.`name`, COUNT(`tretment_has_service`.`id`) AS `how_many`
FROM `tretment_has_service`
LEFT JOIN `services` ON `tretment_has_service`.`services_id` = `services`.`id`
WHERE `tretment_has_service`.`tretment_id` = $tretment_id
AND `tretment_has_service`.`done_id` = 1
AND `tretment_has_service`.`activation_id` = 2
GROUP BY `services`.`id`"
);
if (mysqli_num_rows($get_tretment_has_service_sql) > 0) {
?>
<thead class="table-primary">
<tr>
<th scope="col">الخدمة</th>
<th scope="col">العدد</th>
</tr>
</thead>
<tbody>
<?php
while ($row_tretment_has_service = mysqli_fetch_assoc($get_tretment_has_service_sql)) {
?>
<tr>
<th scope="row"><?=$row_tretment_has_service['name']?></th>
<th scope="row"><?=$row_tretment_has_service['how_many']?></th>
</tr>
<?php
}
?>
</tbody>
<?php
} else {
?>
<tbody>
<tr>
<th colspan="2" scope="row">غير متوفر</th>
</tr>
</tbody>
<?php
}
?>
</table>
</div>
</div>
<div class="col-12 col-sm-12 col-md-2 col-lg-2 col-xl-2">
<div class="table-responsive">
<table class="table table-bordered text-center">
<thead class="table-primary">
<tr>
<th scope="col" colspan="2">رصيد اموال</th>
</tr>
</thead>
<tbody>
<tr>
<?php
$get_v_tretment_money_sql = mysqli_query($db,
"SELECT `money` FROM `tretment_money` WHERE `tretment_id` = $tretment_id"
);
$static_money_stuck = 0;
if (mysqli_num_rows($get_v_tretment_money_sql) > 0) {
$row_v_tretment_money = mysqli_fetch_assoc($get_v_tretment_money_sql);
$static_money_stuck = $row_v_tretment_money['money'];
?>
<th scope="col">مدفوع</th>
<th scope="col"><?=$row_v_tretment_money['money']?> ريال</th>
<?php
} else {
?>
<th scope="col">مدفوع</th>
<th scope="col">0 ريال</th>
<?php
}
?>
</tr>
<tr>
<?php
$get_v_tretment_money_sql = mysqli_query($db,
"SELECT `money` FROM `tretment_money` WHERE `tretment_id` = $tretment_id"
);
if (mysqli_num_rows($get_v_tretment_money_sql) > 0 && 2 == 1) {
$row_v_tretment_money = mysqli_fetch_assoc($get_v_tretment_money_sql)
?>
<th scope="col">مجاني</th>
<th scope="col"><?=$row_v_tretment_money['money']?> ريال</th>
<?php
} else {
?>
<th scope="col">مجاني</th>
<th scope="col">0 ريال</th>
<?php
}
?>
</tr>
</tbody>
</table>
</div>
</div>
<div class="col-12 col-sm-12 col-md-2 col-lg-2 col-xl-2">
<div class="table-responsive">
<table class="table table-bordered text-center">
<thead class="table-primary">
<tr>
<th scope="col">رصيد نقاط</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="col">0 نقطة</th>
</tr>
</tbody>
</table>
</div>
</div>
<div class="col-12 col-sm-12 col-md-2 col-lg-2 col-xl-2">
<div class="table-responsive">
<table class="table table-bordered text-center">
<thead class="table-primary">
<tr>
<th colspan="2" scope="col">عرض مره وحدة</th>
</tr>
</thead>
<?php
if (false) {
?>
<thead class="table-primary">
<tr>
<th scope="col">الخدمة</th>
<th scope="col">العدد</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">#</th>
<th scope="row">#</th>
</tr>
</tbody>
<?php
} else {
?>
<tbody>
<tr>
<th colspan="2" scope="row">غير متوفر</th>
</tr>
</tbody>
<?php
}
?>
</table>
</div>
</div>
<div class="col-12 col-sm-12 col-md-3 col-lg-3 col-xl-3">
<div class="table-responsive">
<table class="table table-bordered text-center">
<thead class="table-primary">
<tr>
<th colspan="2" scope="col">خدمات مجانية</th>
</tr>
</thead>
<?php
$get_tretment_has_free_service_sql = mysqli_query($db,
"SELECT `services`.`id`, `services`.`name`, COUNT(`tretment_has_free_service`.`id`) AS `how_many`
FROM `tretment_has_free_service`
LEFT JOIN `services` ON `tretment_has_free_service`.`services_id` = `services`.`id`
WHERE `tretment_has_free_service`.`tretment_id` = $tretment_id
AND `tretment_has_free_service`.`done_id` = 1
AND `tretment_has_free_service`.`activation_id` = 2
GROUP BY `services`.`id`"
);
if (mysqli_num_rows($get_tretment_has_free_service_sql) > 0) {
?>
<thead class="table-primary">
<tr>
<th scope="col">الخدمة</th>
<th scope="col">العدد</th>
</tr>
</thead>
<tbody>
<?php
while ($row_tretment_has_free_service = mysqli_fetch_assoc($get_tretment_has_free_service_sql)) {
?>
<tr>
<th scope="row"><?=$row_tretment_has_free_service['name']?></th>
<th scope="row"><?=$row_tretment_has_free_service['how_many']?></th>
</tr>
<?php
}
?>
</tbody>
<?php
} else {
?>
<tbody>
<tr>
<th colspan="2" scope="row">غير متوفر</th>
</tr>
</tbody>
<?php
}
?>
</table>
</div>
</div>
</div>
</div>
</div>
<script>
data = <?=json_encode($data);?>;
inputTypes = [];
inputTypes_checked = [];
console.log(data);
$(function() {
$("#pay-action").click(function() {
$('.get-data-radio input[type=radio]').each(function(){
inputTypes.push($(this).attr('type'));
});
$('.get-data-radio input[type=radio]:checked').each(function(){
inputTypes_checked.push($(this).attr('type'));
});
//code();
if (inputTypes.length > 0) {
if (inputTypes_checked.length > 0) {
pay();
} else {
pay1();
}
} else {
pay();
}
});
});
click = 0;
curr_price = parseFloat($('#current_price').html());
serv_desc = 0
free_stack_descu = 0
stack_descu = 0
have_descount = 0;
money_stuck = 0;
static_money_stuck = parseFloat(<?=json_encode($static_money_stuck)?>);
$('.get-data-radio input[type=radio]').change(function() {
let radios = $('.get-data-radio input[type=radio]:checked');
let total = 0;
for (let i = 0; i < radios.length; i++) {
let oneRadio = radios[i];
let value = oneRadio.getAttribute("data-discount");
total += parseFloat(value);
}
$('#total_desc').html(total);
total = Math.round((total) * 100) / 100
serv_desc = total;
$("[name='cash_pay']").val(0)
$("[name='card_pay']").val(0)
})
$("[name='serv_c']").change(function() {
let radios = $('input[name="serv_c"]');
let descu = 0;
for (let i = 0; i < radios.length; i++) {
if (radios[i].checked == true) {
let oneRadio = radios[i];
let value = oneRadio.getAttribute("id");
let radios_temp_all = $('.get-data-radio input[data-when-call-all="'+value+'"]');
for (let o = 0; o < radios_temp_all.length; o++) {
radios_temp_all[o].checked = false
radios_temp_all[o].disabled = true
radios_temp_all[o].parentElement.setAttribute("class", radios_temp_all[o].parentElement.getAttribute("class") + " radio-primary-custom")
}
let free_serv_checkboxs = $('input[name="f_serv_c"]');
for (let o = 0; o < free_serv_checkboxs.length; o++) {
if (free_serv_checkboxs[o].getAttribute("id") == ('f_'+value)) {
free_serv_checkboxs[o].disabled = true;
break;
}
}
let price = oneRadio.getAttribute("data-price");
descu += parseFloat(price)
} else {
let oneRadio = radios[i];
let value = oneRadio.getAttribute("id");
let radios_temp_all = $('.get-data-radio input[data-when-call-all="'+value+'"]');
for (let o = 0; o < radios_temp_all.length; o++) {
radios_temp_all[o].disabled = false
radios_temp_all[o].parentElement.classList.remove('radio-primary-custom');
}
let free_serv_checkboxs = $('input[name="f_serv_c"]');
for (let o = 0; o < free_serv_checkboxs.length; o++) {
if (free_serv_checkboxs[o].getAttribute("id") == ('f_'+value)) {
free_serv_checkboxs[o].disabled = false;
break;
}
}
}
}
total = Math.round((parseFloat(descu)) * 100) / 100;
stack_descu = total;
$("[name='cash_pay']").val(0)
$("[name='card_pay']").val(0)
total = 0;
radios = $('.get-data-radio input[type=radio]:checked');
for (let i = 0; i < radios.length; i++) {
let oneRadio = radios[i];
let value = oneRadio.getAttribute("data-discount");
total += parseFloat(value);
}
$('#total_desc').html(total);
total = Math.round((total) * 100) / 100
serv_desc = total;
});
$("[name='f_serv_c']").change(function() {
let radios = $('input[name="f_serv_c"]');
let descu = 0;
for (let i = 0; i < radios.length; i++) {
if (radios[i].checked == true) {
let oneRadio = radios[i];
let value = oneRadio.getAttribute("id").slice(2);
// for radios
let radios_temp_all = $('.get-data-radio input[data-when-call-all="'+value+'"]');
for (let o = 0; o < radios_temp_all.length; o++) {
radios_temp_all[o].checked = false
radios_temp_all[o].disabled = true
radios_temp_all[o].parentElement.setAttribute("class", radios_temp_all[o].parentElement.getAttribute("class") + " radio-primary-custom")
}
// for radios
// for checkbox serv_c
let serv_checkboxs = $('input[name="serv_c"]');
for (let o = 0; o < serv_checkboxs.length; o++) {
if (serv_checkboxs[o].getAttribute("id") == (value)) {
serv_checkboxs[o].disabled = true;
break;
}
}
// for checkbox serv_c
let price = oneRadio.getAttribute("data-price");
descu += parseFloat(price)
} else {
let oneRadio = radios[i];
let value = oneRadio.getAttribute("id").slice(2);
// for radios
let radios_temp_all = $('.get-data-radio input[data-when-call-all="'+value+'"]');
for (let o = 0; o < radios_temp_all.length; o++) {
radios_temp_all[o].disabled = false
radios_temp_all[o].parentElement.classList.remove('radio-primary-custom');
}
// for radios
// for checkbox serv_c
let serv_checkboxs = $('input[name="serv_c"]');
for (let o = 0; o < serv_checkboxs.length; o++) {
if (serv_checkboxs[o].getAttribute("id") == (value)) {
serv_checkboxs[o].disabled = false;
break;
}
}
// for checkbox serv_c
}
}
total = Math.round((parseFloat(descu)) * 100) / 100;
free_stack_descu = total;
$("[name='cash_pay']").val(0)
$("[name='card_pay']").val(0)
total = 0;
radios = $('.get-data-radio input[type=radio]:checked');
for (let i = 0; i < radios.length; i++) {
let oneRadio = radios[i];
let value = oneRadio.getAttribute("data-discount");
total += parseFloat(value);
}
$('#total_desc').html(total);
total = Math.round((total) * 100) / 100
serv_desc = total;
});
$('input[type=radio]').change(function() {
$('#current_price').html(Math.round((curr_price - serv_desc - stack_descu - free_stack_descu - money_stuck) * 100) / 100)
})
$('input[type=checkbox]').change(function() {
$('#current_price').html(Math.round((curr_price - serv_desc - stack_descu - free_stack_descu - money_stuck) * 100) / 100)
})
</script>
</body>
</html>