359 lines
17 KiB
PHP
Executable File
359 lines
17 KiB
PHP
Executable File
<?php
|
|
require_once('../../../fixed/config/go_con.php');
|
|
|
|
$tretment_id = mysqli_real_escape_string($db, $_POST['tretment_id']);
|
|
|
|
$price = mysqli_real_escape_string($db, $_POST['price']);
|
|
$price_vat = mysqli_real_escape_string($db, $_POST['price_vat']);
|
|
$discount = mysqli_real_escape_string($db, $_POST['discount']);
|
|
$reason_for_discount = mysqli_real_escape_string($db, $_POST['reason_for_discount']);
|
|
$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']);
|
|
$tretment_id = mysqli_real_escape_string($db, $_POST['tretment_id']);
|
|
$services_id = mysqli_real_escape_string($db, $_POST['services_id']);
|
|
$booking_id = mysqli_real_escape_string($db, $_POST['booking_id']);
|
|
$day_date = mysqli_real_escape_string($db, $_POST['day_date']);
|
|
$fixedPrice = mysqli_real_escape_string($db, $_POST['fixedPrice']);
|
|
$reason_for_fixedPrice = mysqli_real_escape_string($db, $_POST['reason_for_fixedPrice']);
|
|
|
|
// 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 = $price + $price_vat;
|
|
$payments = $cash_pay + $card_pay;
|
|
|
|
$current_price_round = round($current_price,2);
|
|
|
|
$get_commercial_register_sql = mysqli_query($db, "SELECT `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) {
|
|
$row_commercial_register = mysqli_fetch_assoc($get_commercial_register_sql);
|
|
$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 (empty($discount) && empty($free) && empty($fixedPrice)) {
|
|
|
|
$discount = 0;
|
|
$fixedPrice = 0;
|
|
if ($current_price_round == $payments) {
|
|
|
|
if(mysqli_query(
|
|
$db,
|
|
"INSERT INTO `invoices`(`number`, `number_style`, `price`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$number','$number_style','$current_price_round','$date_time','$admin_id','2')"
|
|
)) {
|
|
$last_id = mysqli_insert_id($db);
|
|
|
|
if(mysqli_query($db,
|
|
"INSERT INTO `invoices_details`(`invoices_id`, `invoices_status_id`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$last_id','1','$date_time','$admin_id','2')"
|
|
)) {
|
|
$last_id_2 = mysqli_insert_id($db);
|
|
if (!empty($cash_pay)) {
|
|
mysqli_query($db,
|
|
"INSERT INTO `invoices_has_how_pay`(`invoices_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_has_how_pay`(`invoices_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')"
|
|
);
|
|
}
|
|
}
|
|
|
|
mysqli_query($db,
|
|
"INSERT INTO `invoices_has_book`(`invoices_id`, `book_id`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$last_id','$booking_id','$date_time','$admin_id','2')"
|
|
);
|
|
|
|
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` = '$booking_id'
|
|
AND `book_details`.`id` IN (SELECT MAX(`id`) FROM `book_details` WHERE `book_id` = '$booking_id')"
|
|
);
|
|
|
|
echo"
|
|
<script>
|
|
window.open('print.php?booking_id=".$booking_id."');
|
|
window.location.href = 'index.php?date=".$day_date."';
|
|
</script>
|
|
";
|
|
|
|
} else {
|
|
echo"
|
|
<script>
|
|
swalfun('LA030-7','','error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
}
|
|
|
|
} else {
|
|
echo"
|
|
<script>
|
|
swalfun('يرجى التحقق','مدخلات الدفع غير مطابقه المبلغ المستحق','info');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
}
|
|
|
|
} else if (!empty($discount) && empty($free) && empty($fixedPrice) && FALSE) {
|
|
|
|
$fixedPrice = 0;
|
|
$current_price = $price - $discount;
|
|
$price_vat = ($current_price*$vat)/100;
|
|
$current_price = $current_price + $price_vat;
|
|
|
|
if (!empty($reason_for_discount)) {
|
|
if ($current_price_round == $payments ) {
|
|
|
|
if(mysqli_query(
|
|
$db,
|
|
"INSERT INTO `invoices`(`number`, `number_style`, `price`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$number','$number_style','$current_price_round','$date_time','$admin_id','2')"
|
|
)) {
|
|
$last_id = mysqli_insert_id($db);
|
|
|
|
mysqli_query($db,
|
|
"INSERT INTO `invoices_details`(`invoices_id`, `invoices_status_id`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$last_id','1','$date_time','$admin_id','2')"
|
|
);
|
|
|
|
if (!empty($cash_pay)) {
|
|
mysqli_query($db,
|
|
"INSERT INTO `invoices_has_how_pay`(`invoices_id`, `how_pay_id`, `pay`, `notes`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$last_id','1','$cash_pay','$cash_note','$date_time','$admin_id','2')"
|
|
);
|
|
}
|
|
if (!empty($card_pay)) {
|
|
mysqli_query($db,
|
|
"INSERT INTO `invoices_has_how_pay`(`invoices_id`, `how_pay_id`, `pay`, `notes`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$last_id','2','$card_pay','$card_note','$date_time','$admin_id','2')"
|
|
);
|
|
}
|
|
|
|
mysqli_query($db,
|
|
"INSERT INTO `invoices_has_book`(`invoices_id`, `book_id`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$last_id','$booking_id','$date_time','$admin_id','2')"
|
|
);
|
|
|
|
} else {
|
|
echo"
|
|
<script>
|
|
swalfun('LA030-7','','error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
}
|
|
|
|
|
|
} else {
|
|
echo"
|
|
<script>
|
|
swalfun('يرجى التحقق','مدخلات الدفع غير مطابقه المبلغ المستحق','info');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
}
|
|
} else {
|
|
echo"
|
|
<script>
|
|
swalfun('تحقق من المدخلات','تأكد من كتابة سبب الخصم','info');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
}
|
|
} elseif (!empty($fixedPrice) && empty($free) && empty($discount) && FALSE) {
|
|
|
|
$current_price = ($price) - ($fixedPrice/$count_vat);
|
|
$discount = $current_price;
|
|
$current_price = $price - $discount;
|
|
$price_vat = ($current_price*$vat)/100;
|
|
|
|
$current_price = $current_price + $price_vat;
|
|
if (!empty($reason_for_fixedPrice)) {
|
|
if ($current_price_round == $payments ) {
|
|
|
|
if(mysqli_query(
|
|
$db,
|
|
"INSERT INTO `invoices`(`number`, `number_style`, `price`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$number','$number_style','$current_price_round','$date_time','$admin_id','2')"
|
|
)) {
|
|
$last_id = mysqli_insert_id($db);
|
|
|
|
mysqli_query($db,
|
|
"INSERT INTO `invoices_details`(`invoices_id`, `invoices_status_id`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$last_id','1','$date_time','$admin_id','2')"
|
|
);
|
|
|
|
if (!empty($cash_pay)) {
|
|
mysqli_query($db,
|
|
"INSERT INTO `invoices_has_how_pay`(`invoices_id`, `how_pay_id`, `pay`, `notes`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$last_id','1','$cash_pay','$cash_note','$date_time','$admin_id','2')"
|
|
);
|
|
}
|
|
if (!empty($card_pay)) {
|
|
mysqli_query($db,
|
|
"INSERT INTO `invoices_has_how_pay`(`invoices_id`, `how_pay_id`, `pay`, `notes`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$last_id','2','$card_pay','$card_note','$date_time','$admin_id','2')"
|
|
);
|
|
}
|
|
|
|
mysqli_query($db,
|
|
"INSERT INTO `invoices_has_book`(`invoices_id`, `book_id`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$last_id','$booking_id','$date_time','$admin_id','2')"
|
|
);
|
|
|
|
} else {
|
|
echo"
|
|
<script>
|
|
swalfun('LA030-7','','error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
}
|
|
|
|
} else {
|
|
echo"
|
|
<script>
|
|
swalfun('يرجى التحقق','مدخلات الدفع غير مطابقه المبلغ المستحق','info');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
}
|
|
} else {
|
|
echo"
|
|
<script>
|
|
swalfun('تحقق من المدخلات','تأكد من كتابة سبب الخصم','info');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
}
|
|
} else if (!empty($free) && empty($discount) && empty($fixedPrice) && FALSE) {
|
|
|
|
if (!empty($reason_for_free)) {
|
|
|
|
if(mysqli_query(
|
|
$db,
|
|
"INSERT INTO `invoices`(`number`, `number_style`, `price`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$number','$number_style','$current_price_round','$date_time','$admin_id','2')"
|
|
)) {
|
|
$last_id = mysqli_insert_id($db);
|
|
|
|
mysqli_query($db,
|
|
"INSERT INTO `invoices_details`(`invoices_id`, `invoices_status_id`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$last_id','1','$date_time','$admin_id','2')"
|
|
);
|
|
|
|
if (!empty($cash_pay)) {
|
|
mysqli_query($db,
|
|
"INSERT INTO `invoices_has_how_pay`(`invoices_id`, `how_pay_id`, `pay`, `notes`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$last_id','1','$cash_pay','$cash_note','$date_time','$admin_id','2')"
|
|
);
|
|
}
|
|
if (!empty($card_pay)) {
|
|
mysqli_query($db,
|
|
"INSERT INTO `invoices_has_how_pay`(`invoices_id`, `how_pay_id`, `pay`, `notes`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$last_id','2','$card_pay','$card_note','$date_time','$admin_id','2')"
|
|
);
|
|
}
|
|
|
|
mysqli_query($db,
|
|
"INSERT INTO `invoices_has_book`(`invoices_id`, `book_id`, `date_time`, `user_id`, `activation_id`)
|
|
VALUES ('$last_id','$booking_id','$date_time','$admin_id','2')"
|
|
);
|
|
|
|
} else {
|
|
echo"
|
|
<script>
|
|
swalfun('LA030-7','','error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
}
|
|
|
|
} else {
|
|
echo"
|
|
<script>
|
|
swalfun('تحقق من المدخلات','تأكد من كتابة سبب الخصم','info');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
}
|
|
|
|
} else {
|
|
echo"
|
|
<script>
|
|
swalfun('LI012-7','','error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
}
|
|
|
|
} else {
|
|
echo"
|
|
<script>
|
|
swalfun('LQ012-7','','error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
}
|
|
|
|
} else {
|
|
echo"
|
|
<script>
|
|
swalthen('تم سداد هذه الجلسة مسبقا','هل تريد الانتقال لصفحة الحجوزات؟','error','book.php');
|
|
</script>
|
|
";
|
|
}
|
|
|
|
?>
|
|
|