72 lines
2.9 KiB
PHP
Executable File
72 lines
2.9 KiB
PHP
Executable File
<?php
|
|
require_once('../../../fixed/config/go_con.php');
|
|
|
|
$data = $_POST['data'];
|
|
$user_resone = mysqli_real_escape_string($db, $_POST['user_resone']);
|
|
$tretment_id = mysqli_real_escape_string($db, $_POST['tretment_id']);
|
|
|
|
|
|
if (!empty($tretment_id) && !empty($user_resone)) {
|
|
|
|
if (mysqli_query(
|
|
$db,
|
|
"INSERT INTO `custom_discount`(`reason`, `tretment_id`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$user_resone','$tretment_id','$date_time','$admin_id','2')"
|
|
)) {
|
|
$last_id = mysqli_insert_id($db);
|
|
$value_sql = "";
|
|
foreach ($data as $key => $value) {
|
|
$how_many = $data[$key]['how_many'];
|
|
$type = $data[$key]['type'];
|
|
$discount = $data[$key]['discount'];
|
|
for ($i=0; $i < $how_many; $i++) {
|
|
mysqli_query(
|
|
$db,
|
|
"INSERT INTO `tretment_has_custom_discount`(`discount`, `tretment_id`, `services_id`, `inv_from_db_tables_id`, `inv_table_id`, `type_discount_id`, `done_id`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$discount','$tretment_id','$key','17', '$last_id', '$type', '1', '$date_time','$admin_id','2')"
|
|
);
|
|
}
|
|
$value_sql .= "('$last_id','$key','$how_many','$discount', '$type', '$date_time','$admin_id','2'),";
|
|
}
|
|
$value_sql = rtrim($value_sql, ',');
|
|
if(!mysqli_query(
|
|
$db,
|
|
"INSERT INTO `custom_discount_has_services` (`custom_discount_id`, `services_id`, `how_many`, `discount`, `type_discount_id`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES $value_sql"
|
|
)){
|
|
echo "
|
|
<script>
|
|
swalfun('RY-1112','', 'error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
}
|
|
|
|
} else {
|
|
echo "
|
|
<script>
|
|
swalfun('RY-1122','', 'error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
}
|
|
echo "
|
|
<script>
|
|
swalfun('تم إضافة الخصم بنجاح','', 'success');
|
|
click = 0;
|
|
location.reload();
|
|
// window.location.href = 'book';
|
|
</script>
|
|
";
|
|
|
|
} else {
|
|
echo "
|
|
<script>
|
|
swalfun('حدث خطأ', 'يرجى ادخال جميع الحقول', 'error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
}
|
|
|
|
?>
|