440 lines
12 KiB
PHP
440 lines
12 KiB
PHP
<?php
|
||
|
||
$inv_id = $_GET['inv_id'];
|
||
if (empty($inv_id)) {
|
||
$booking_id = $_GET['book_id'];
|
||
$get_invoices_has_book_sql = mysqli_query(
|
||
$db,
|
||
"SELECT `invoices_id` FROM `invoices_has_book` WHERE `book_id` = $booking_id LIMIT 1"
|
||
);
|
||
if (mysqli_num_rows($get_invoices_has_book_sql) > 0) {
|
||
$invoices_has_book_row = mysqli_fetch_assoc($get_invoices_has_book_sql);
|
||
$inv_id = $invoices_has_book_row['invoices_id'];
|
||
} else {
|
||
?>
|
||
<script>window.location.replace("index");</script>
|
||
<?php
|
||
}
|
||
} else {
|
||
?>
|
||
<script>window.location.replace("index");</script>
|
||
<?php
|
||
}
|
||
|
||
$get_invoices_sql = mysqli_query(
|
||
$db,
|
||
"SELECT
|
||
`invoices`.`id`,
|
||
`invoices`.`number_style`,
|
||
`branch`.`branch_name`,
|
||
`branch`.`pu_name`,
|
||
`branch`.`commercial_register_number_10`,
|
||
`invoices`.`price`,
|
||
`invoices`.`date_time`,
|
||
`user`.`name` AS `user_name`
|
||
|
||
FROM `invoices`
|
||
LEFT JOIN `user` ON `invoices`.`user_id` = `user`.`id`
|
||
LEFT JOIN `emplyee` ON `user`.`emplyee_id` = `emplyee`.`id`
|
||
LEFT JOIN `branch` ON `emplyee`.`branch_id` = `branch`.`id`
|
||
|
||
WHERE `invoices`.`id` = $inv_id"
|
||
);
|
||
$invoices_row = mysqli_fetch_assoc($get_invoices_sql);
|
||
|
||
$get_book_id_sql = mysqli_query(
|
||
$db,
|
||
"SELECT `book_id` FROM `invoices_has_book` WHERE `invoices_id` = $inv_id LIMIT 1"
|
||
);
|
||
$book_id_row = mysqli_fetch_assoc($get_book_id_sql);
|
||
$book_id = $book_id_row['book_id'];
|
||
|
||
$get_tretment_sql = mysqli_query(
|
||
$db,
|
||
"SELECT
|
||
`tretment`.`name`,
|
||
`tretment`.`number`
|
||
|
||
FROM `book`
|
||
LEFT JOIN `tretment` ON `book`.`tretment_id` = `tretment`.`id`
|
||
WHERE `book`.`id` = $book_id"
|
||
);
|
||
$tretment_row = mysqli_fetch_assoc($get_tretment_sql);
|
||
|
||
$get_invoices_has_book_sql = mysqli_query(
|
||
$db,
|
||
"SELECT
|
||
`invoices_details_has_how_pay`.`pay`,
|
||
`invoices_details_has_how_pay`.`how_pay_id`
|
||
|
||
FROM `invoices_details`
|
||
INNER JOIN `invoices_details_has_how_pay` ON `invoices_details_has_how_pay`.`invoices_details_id` = `invoices_details`.`id`
|
||
WHERE `invoices_details`.`invoices_id` = $inv_id"
|
||
);
|
||
$how_pay_arr = array();
|
||
while ($invoices_has_book_row = mysqli_fetch_assoc($get_invoices_has_book_sql)) {
|
||
$how_pay_arr[$invoices_has_book_row['how_pay_id']] = $invoices_has_book_row['pay'];
|
||
}
|
||
|
||
?>
|
||
<!DOCTYPE html>
|
||
<html lang="en">
|
||
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<title>طباعة الفاتورة</title>
|
||
|
||
<!-- Normalize or reset CSS with your favorite library -->
|
||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/7.0.0/normalize.min.css">
|
||
|
||
<!-- Custom styles for this document -->
|
||
<link href="https://fonts.googleapis.com/css?family=Tangerine:700" rel="stylesheet" type="text/css">
|
||
|
||
<style>
|
||
@media print {
|
||
@page {
|
||
scroll-margin: 0;
|
||
margin: 0;
|
||
}
|
||
|
||
body {
|
||
font-size: 10pt;
|
||
font-weight: 700;
|
||
margin: 0;
|
||
font-family: 'Cairo', sans-serif !important;
|
||
}
|
||
|
||
.mo_border {
|
||
/* border: 1px; */
|
||
border: #000 solid 1px;
|
||
padding: 10px 10px;
|
||
/* margin-bottom: 15px; */
|
||
}
|
||
}
|
||
</style>
|
||
</head>
|
||
|
||
|
||
|
||
<body onload="print_f()" class="A4" dir="rtl">
|
||
|
||
<section style="margin: 0 25px;">
|
||
<article>
|
||
<div style="text-align: center;">
|
||
<h1>إشعار دائن للفاتورة الضريبية المبسطة</h1>
|
||
</div>
|
||
<div style="text-align: center;">
|
||
<h3>
|
||
رقم الإشعار:
|
||
<?= $invoices_row['number_style'] ?>
|
||
</h3>
|
||
</div>
|
||
<div style="text-align: center;">
|
||
<h3>
|
||
رقم الفاتورة:
|
||
<?= $invoices_row['number_style'] ?>
|
||
</h3>
|
||
</div>
|
||
<div style="text-align: center;">
|
||
<h2>مركز أقدامي الرياضي</h2>
|
||
</div>
|
||
<div style="text-align: center;">
|
||
<h4>العنوان: الرياض،الريان،الامير ماجد بن عبدالعزيز،14212</h4>
|
||
<h4>عنوان الفرع:
|
||
<?= $invoices_row['pu_name'] ?>
|
||
</h4>
|
||
</div>
|
||
|
||
<div style="display: flex;">
|
||
<div style="text-align: right; flex-grow: 1;">
|
||
<h5>
|
||
تاريخ:
|
||
<?= date('Y-m-d', strtotime($invoices_row['date_time'])) ?>
|
||
</h5>
|
||
</div>
|
||
<div style="text-align: left; flex-grow: 1;">
|
||
<h5>
|
||
الوقت:
|
||
<?= date('H:i:s', strtotime($invoices_row['date_time'])) ?>
|
||
</h5>
|
||
</div>
|
||
</div>
|
||
<div style="text-align: right;">
|
||
<h5>
|
||
رقم تسجيل ضريبة القيمة المضافة:
|
||
<?= $campany_info['vat_number'] ?>
|
||
</h5>
|
||
</div>
|
||
<div style="text-align: right;">
|
||
<h5>
|
||
رقم السجل التجاري:
|
||
<?= $campany_info['commercial_register_number_10'] ?>
|
||
</h5>
|
||
</div>
|
||
|
||
<div style="text-align: right;">
|
||
<h5>طريقة السداد:
|
||
<?php
|
||
if ($how_pay_arr['1'] > 0) {
|
||
?>
|
||
كاش: <?= $how_pay_arr['1'] ?>
|
||
<?php
|
||
}
|
||
|
||
if ($how_pay_arr['2'] > 0) {
|
||
?>
|
||
شبكة: <?= $how_pay_arr['2'] ?>
|
||
<?php
|
||
}
|
||
|
||
if ($how_pay_arr['3'] > 0 || $how_pay_arr['4'] > 0) {
|
||
?>
|
||
رصيد: <?= $how_pay_arr['3'] + $how_pay_arr['4'] ?>
|
||
<?php
|
||
}
|
||
?>
|
||
</h5>
|
||
</div>
|
||
|
||
|
||
<table width="100%" border="0" style="vertical-align: middle;" cellspacing="0" cellpadding="0">
|
||
<tbody>
|
||
|
||
<tr>
|
||
<td class="mo_border" style="width:150px"><b>الخدمات</b></td>
|
||
<td class="mo_border" style="text-align: center;"><b>سعر الخدمة</b></td>
|
||
<td class="mo_border" style="text-align: center;"><b>ضريبة القيمة المضافة</b></td>
|
||
<td class="mo_border" style="text-align: center;"><b>السعر شامل ضريبة القيمة المضافة</b></td>
|
||
</tr>
|
||
<?php
|
||
$invoices_details_id = 0;
|
||
$get_invoices_has_book_sql = mysqli_query(
|
||
$db,
|
||
"SELECT
|
||
`invoices_details`.`id`,
|
||
`services`.`name`,
|
||
`services`.`price`
|
||
|
||
FROM `invoices_has_book`
|
||
LEFT JOIN `book` ON `invoices_has_book`.`book_id` = `book`.`id`
|
||
LEFT JOIN `book_details` ON `book_details`.`book_id` = `book`.`id`
|
||
LEFT JOIN `services` ON `book_details`.`services_id` = `services`.`id`
|
||
LEFT JOIN `invoices_details` ON `invoices_details`.`invoices_id` = `invoices_has_book`.`invoices_id`
|
||
WHERE `invoices_has_book`.`invoices_id` = $inv_id
|
||
AND `book_details`.`id` IN (SELECT MAX(`id`) FROM `book_details` GROUP BY `book_details`.`book_id`)
|
||
AND `invoices_details`.`id` IN (SELECT MAX(`id`) FROM `invoices_details` GROUP BY `invoices_details`.`invoices_id`)"
|
||
);
|
||
$total = 0;
|
||
while ($invoices_has_book_row = mysqli_fetch_assoc($get_invoices_has_book_sql)) {
|
||
$invoices_details_id = $invoices_has_book_row['id'];
|
||
?>
|
||
<tr>
|
||
<td class="mo_border">
|
||
<b>
|
||
<?= $invoices_has_book_row['name'] ?>
|
||
</b>
|
||
</td>
|
||
<td class="mo_border" style="text-align: center;">
|
||
<?= number_format((float) round($invoices_has_book_row['price'], 2), 2, '.', ''); ?>
|
||
</td>
|
||
<td class="mo_border" style="text-align: center;">
|
||
<?= number_format((float) round(($invoices_has_book_row['price'] * $vat / 100), 2), 2, '.', ''); ?>
|
||
</td>
|
||
<td class="mo_border" style="text-align: center;">
|
||
<?= number_format((float) round($invoices_has_book_row['price'] + ($invoices_has_book_row['price'] * $vat / 100), 2), 2, '.', ''); ?>
|
||
</td>
|
||
</tr>
|
||
<?php
|
||
$total += $invoices_has_book_row['price'];
|
||
}
|
||
$get_invoices_discount_sql = mysqli_query(
|
||
$db,
|
||
"SELECT `discount` FROM `invoices_discount` WHERE `invoices_details_id` = $invoices_details_id "
|
||
);
|
||
$total_des = 0;
|
||
if (mysqli_num_rows($get_invoices_discount_sql) > 0) {
|
||
while ($invoices_discount_row = mysqli_fetch_assoc($get_invoices_discount_sql)) {
|
||
$total_des += $invoices_discount_row['discount'];
|
||
}
|
||
}
|
||
?>
|
||
|
||
<tr>
|
||
<td colspan="3" class="mo_border" style="text-align: right;">
|
||
<b>
|
||
اجمالي المبلغ الخاضع للضريبة
|
||
</b>
|
||
</td>
|
||
<td colspan="1" class="mo_border" style="text-align: left;">
|
||
<b>
|
||
<?= number_format((float) round($total, 2), 2, '.', ''); ?>
|
||
</b>
|
||
</td>
|
||
</tr>
|
||
|
||
|
||
|
||
<?php
|
||
if ($total_des > 0) {
|
||
?>
|
||
<tr>
|
||
<td colspan="3" class="mo_border" style="text-align: right;">
|
||
<b>
|
||
الخصم
|
||
</b>
|
||
</td>
|
||
<td colspan="1" class="mo_border" style="text-align: left;">
|
||
<b>
|
||
<?= number_format((float) round($total_des, 2), 2, '.', ''); ?>
|
||
</b>
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td colspan="3" class="mo_border" style="text-align: right;">
|
||
<b>
|
||
المجموع قبل الضريبة
|
||
</b>
|
||
</td>
|
||
<td colspan="1" class="mo_border" style="text-align: left;">
|
||
<b>
|
||
<?= number_format((float) round(round($total, 2) - round($total_des, 2), 2), 2, '.', ''); ?>
|
||
</b>
|
||
</td>
|
||
</tr>
|
||
|
||
|
||
<?php
|
||
|
||
}
|
||
?>
|
||
|
||
<tr>
|
||
<td colspan="3" class="mo_border" style="text-align: right;">
|
||
<b>
|
||
ضريبة القيمة المضافة (15%)
|
||
</b>
|
||
</td>
|
||
<td colspan="1" class="mo_border" style="text-align: left;">
|
||
<b>
|
||
<?= number_format((float) round(($total - $total_des) * $vat / 100, 2), 2, '.', ''); ?>
|
||
</b>
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td colspan="3" class="mo_border" style="text-align: right;">
|
||
<b>
|
||
المجموع مع الضريبة (15%)
|
||
</b>
|
||
</td>
|
||
<td colspan="1" class="mo_border" style="text-align: left;">
|
||
<b>
|
||
<?= number_format((float) round(($total - $total_des) + (($total - $total_des) * $vat / 100), 2), 2, '.', ''); ?>
|
||
</b>
|
||
</td>
|
||
</tr>
|
||
|
||
</tbody>
|
||
</table>
|
||
|
||
|
||
<div style="text-align: center;">
|
||
<h3>
|
||
--- <?= $invoices_row['branch_name'] ?> ---
|
||
</h3>
|
||
<h3>
|
||
الرقم الموحد
|
||
<br />
|
||
011521112
|
||
</h3>
|
||
</div>
|
||
|
||
<?php
|
||
// QR code genratior
|
||
function __getLength($value)
|
||
{
|
||
return strlen($value);
|
||
}
|
||
function __toHex($value)
|
||
{
|
||
return pack("H*", sprintf("%02X", $value));
|
||
}
|
||
function __toString($__tag, $__value, $__length)
|
||
{
|
||
$value = (string) $__value;
|
||
return __toHex($__tag) . __toHex($__length) . $value;
|
||
}
|
||
function __getTLV($dataToEncode)
|
||
{
|
||
$__TLVS = '';
|
||
for ($i = 0; $i < count($dataToEncode); $i++) {
|
||
$__tag = $dataToEncode[$i][0];
|
||
$__value = $dataToEncode[$i][1];
|
||
$__length = __getLength($__value);
|
||
$__TLVS .= __toString($__tag, $__value, $__length);
|
||
}
|
||
|
||
return $__TLVS;
|
||
}
|
||
$dataToEncode = [
|
||
[1, 'مركز أقدامي الرياضي'],
|
||
[2, $campany_info['vat_number']],
|
||
[3, date("Y-m-d\TH:i:s", strtotime($invoices_row['date_time']))],
|
||
[4, number_format((float) round(($total - $total_des) + (($total - $total_des) * $vat / 100), 2), 2, '.', '')],
|
||
[5, number_format((float) round((($total - $total_des) * $vat / 100), 2), 2, '.', '')]
|
||
];
|
||
$__TLV = __getTLV($dataToEncode);
|
||
$__QR = base64_encode($__TLV);
|
||
require_once '../../vendor/autoload.php';
|
||
use chillerlan\QRCode\QRCode;
|
||
use chillerlan\QRCode\QROptions;
|
||
|
||
$data = $__QR;
|
||
$options = new QROptions([
|
||
'version' => 8, // Adjust if necessary
|
||
'outputType' => QRCode::OUTPUT_IMAGE_PNG,
|
||
'eccLevel' => QRCode::ECC_L,
|
||
'scale' => 3, // Scale factor, adjust as needed
|
||
'imageBase64' => true, // Output as base64
|
||
]);
|
||
$qrcode = new QRCode($options);
|
||
$qrCodeBase64 = $qrcode->render($data);
|
||
?>
|
||
|
||
|
||
<div style="text-align: center;">
|
||
<img src="<?= $qrCodeBase64 ?>" width="130" height="130">
|
||
|
||
</div>
|
||
|
||
<div style="text-align: center;">
|
||
<h3>شكراً على زيارتكم</h3>
|
||
</div>
|
||
<div style="text-align: center;">
|
||
<h3>
|
||
<?= $campany_info['link'] ?>
|
||
</h3>
|
||
</div>
|
||
|
||
|
||
</article>
|
||
</section>
|
||
|
||
<script type="text/javascript">
|
||
window.onafterprint = function (e) {
|
||
closePrintView();
|
||
};
|
||
|
||
function print_f() {
|
||
window.print();
|
||
}
|
||
|
||
function closePrintView() {
|
||
window.close();
|
||
}
|
||
</script>
|
||
|
||
</body>
|
||
|
||
</html>
|