226 lines
10 KiB
PHP
Executable File
226 lines
10 KiB
PHP
Executable File
<?php
|
|
require_once('../../../fixed/config/go_con.php');
|
|
|
|
$data = $_POST['data'];
|
|
$booking_id = $_POST['booking_id'];
|
|
$cash_pay = mysqli_real_escape_string($db, $_POST['cash_pay']);
|
|
$cash_note = mysqli_real_escape_string($db, $_POST['cash_note']);
|
|
$card_pay = mysqli_real_escape_string($db, $_POST['card_pay']);
|
|
$card_type = mysqli_real_escape_string($db, $_POST['card_type']);
|
|
$card_approval_number = mysqli_real_escape_string($db, $_POST['card_approval_number']);
|
|
if (empty($card_approval_number)) {
|
|
$card_approval_number = 0;
|
|
}
|
|
$card_note = mysqli_real_escape_string($db, $_POST['card_note']);
|
|
$free = mysqli_real_escape_string($db, $_POST['free']);
|
|
$reason_for_free = mysqli_real_escape_string($db, $_POST['reason_for_free']);
|
|
|
|
$day_date = mysqli_real_escape_string($db, $_POST['day_date']);
|
|
|
|
// fix values
|
|
if (empty($cash_pay)) {
|
|
$cash_pay = 0;
|
|
}
|
|
if (empty($card_pay)) {
|
|
$card_pay = 0;
|
|
}
|
|
// fix values
|
|
|
|
|
|
$get_invoices_sql = mysqli_query($db, "SELECT * FROM `invoices_has_book` WHERE `book_id`='$booking_id'");
|
|
|
|
if (mysqli_num_rows($get_invoices_sql) <= 0) {
|
|
$current_price = $data['total'] - $data['total_discount'];
|
|
if (!empty($vat)) {
|
|
$current_price = $current_price + ($current_price*$vat)/100;
|
|
}
|
|
|
|
$payments = round($cash_pay + $card_pay,2);
|
|
|
|
$current_price_round = round($current_price,2);
|
|
$branch_id = 0;
|
|
$get_commercial_register_sql = mysqli_query($db, "SELECT
|
|
`branch`.`id`,
|
|
`commercial_register`.`word_tag`
|
|
|
|
FROM `book_details`
|
|
LEFT JOIN `branch` ON `book_details`.`branch_id` = `branch`.`id`
|
|
LEFT JOIN `commercial_register` ON `branch`.`commercial_register_id` = `commercial_register`.`id`
|
|
|
|
WHERE `book_details`.`book_id` = '$booking_id'
|
|
AND `book_details`.`id` IN (SELECT MAX(`id`) FROM `book_details` WHERE `book_id` = '$booking_id')"
|
|
);
|
|
|
|
if (mysqli_num_rows($get_commercial_register_sql) > 0 && false) {
|
|
$row_commercial_register = mysqli_fetch_assoc($get_commercial_register_sql);
|
|
$branch_id = $row_commercial_register['id'];
|
|
$number_style = date('y', strtotime($date_time)) . $row_commercial_register['word_tag'];
|
|
$get_invoices_sql = mysqli_query($db, "SELECT
|
|
`number`,
|
|
`number_style`
|
|
FROM `invoices`
|
|
WHERE `number_style` LIKE '$number_style%'
|
|
AND `number` IN (SELECT MAX(`number`) FROM `invoices` WHERE `number_style` LIKE '$number_style%')"
|
|
);
|
|
$number = '';
|
|
if (mysqli_num_rows($get_invoices_sql) > 0) {
|
|
$row_invoices = mysqli_fetch_assoc($get_invoices_sql);
|
|
$number = $row_invoices['number'] + 1;
|
|
$number_style = date('y', strtotime($date_time)) . $row_commercial_register['word_tag'] . str_pad($number, 7, '0', STR_PAD_LEFT);
|
|
} else {
|
|
$number_style = date('y', strtotime($date_time)) . $row_commercial_register['word_tag'] . "0000001";
|
|
$number = 1;
|
|
}
|
|
|
|
if ($current_price_round == $payments) {
|
|
|
|
if(mysqli_query(
|
|
$db,
|
|
"INSERT INTO `invoices`(`number`, `number_style`, `price`,`price_cut`, `invoices_page_id`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$number','$number_style','$current_price_round','$current_price_round','1', '$date_time','$admin_id','2')"
|
|
)) {
|
|
$last_id = mysqli_insert_id($db);
|
|
|
|
if(mysqli_query($db,
|
|
"INSERT INTO `invoices_details`(`invoices_id`, `pay`, `branch_id`, `invoices_status_id`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$last_id','$current_price_round','$branch_id','1','$date_time','$admin_id','2')"
|
|
)) {
|
|
|
|
$last_id_2 = mysqli_insert_id($db);
|
|
$total_discount_temp = $data['total_discount'];
|
|
|
|
if(mysqli_query($db,
|
|
"INSERT INTO `invoices_discount`(`discount`, `invoices_details_id`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$total_discount_temp', '$last_id_2', '$date_time', '$admin_id', '2')"
|
|
)) {
|
|
$last_id_3 = mysqli_insert_id($db);
|
|
for ($i=0; $i < count($data['discount_status']); $i++) {
|
|
$name_temp = $data['discount_status'][$i]['name'];
|
|
$discount_temp = $data['discount_status'][$i]['discount'];
|
|
$s_id = $data['discount_status'][$i]['s_id'];
|
|
|
|
if(!mysqli_query($db,
|
|
"INSERT INTO `invoices_discount_details`(`discount`, `reason`, `invoices_discount_id`, `services_id`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$discount_temp', '$name_temp', '$last_id_3','$s_id', '$date_time', '$admin_id', '2')"
|
|
)) {
|
|
echo"
|
|
<script>
|
|
swalfun('LO425-7','','error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
exit;
|
|
}
|
|
}
|
|
|
|
} else {
|
|
echo"
|
|
<script>
|
|
swalfun('LR225-7','','error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
exit;
|
|
}
|
|
|
|
if (!empty($cash_pay)) {
|
|
mysqli_query($db,
|
|
"INSERT INTO `invoices_details_has_how_pay`(`invoices_details_id`, `how_pay_id`, `pay`, `notes`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$last_id_2','1','$cash_pay','$cash_note','$date_time','$admin_id','2')"
|
|
);
|
|
}
|
|
if (!empty($card_pay)) {
|
|
mysqli_query($db,
|
|
"INSERT INTO `invoices_details_has_how_pay`(`invoices_details_id`, `how_pay_id`, `pay`, `notes`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$last_id_2','2','$card_pay','$card_note','$date_time','$admin_id','2')"
|
|
);
|
|
}
|
|
|
|
} else {
|
|
echo"
|
|
<script>
|
|
swalfun('LR672-9','','error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
exit;
|
|
}
|
|
for ($i=0; $i < count($data['serv']); $i++) {
|
|
$book_id_temp = $data['serv'][$i]['book_id'];
|
|
|
|
if(!mysqli_query($db,
|
|
"INSERT INTO `invoices_has_book`(`invoices_id`, `book_id`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$last_id','$book_id_temp','$date_time','$admin_id','2')"
|
|
)) {
|
|
echo"
|
|
<script>
|
|
swalfun('LR220-7','','error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
exit;
|
|
}
|
|
if(!mysqli_query($db,
|
|
"INSERT INTO `book_details`(`day_date`, `day_time`, `services_id`, `branch_id`, `emplyee_id`, `status_id`, `book_id`, `date_time`, `user_id`, `activation_id`)
|
|
SELECT `book_details`.`day_date`, `book_details`.`day_time`, `book_details`.`services_id`, `book_details`.`branch_id`, `book_details`.`emplyee_id`, '6', `book_details`.`book_id`, '$date_time','$admin_id','2'
|
|
FROM `book_details`
|
|
|
|
WHERE `book_details`.`book_id` = '$book_id_temp'
|
|
AND `book_details`.`id` IN (SELECT MAX(`id`) FROM `book_details` WHERE `book_id` = '$book_id_temp')"
|
|
)) {
|
|
echo"
|
|
<script>
|
|
swalfun('LR210-7','','error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
exit;
|
|
}
|
|
}
|
|
echo"
|
|
<script>
|
|
window.open('print.php?inv_id=".$last_id."&p=1');
|
|
window.location.href = 'book.php?date=".$day_date."';
|
|
</script>
|
|
";
|
|
|
|
|
|
} else {
|
|
echo"
|
|
<script>
|
|
swalfun('LA030-7','','error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
exit;
|
|
}
|
|
|
|
} else {
|
|
echo"
|
|
<script>
|
|
swalfun('يرجى التحقق','مدخلات الدفع غير مطابقه المبلغ المستحق','info');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
}
|
|
|
|
|
|
} else {
|
|
echo"
|
|
<script>
|
|
swalfun('LQ012-7','','error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
}
|
|
|
|
} else {
|
|
echo"
|
|
<script>
|
|
swalthen('تم سداد هذه الجلسة مسبقا','هل تريد الانتقال لصفحة الحجوزات؟','error','book.php');
|
|
</script>
|
|
";
|
|
}
|
|
|
|
?>
|
|
|