2025-03-24 19:02:58 +03:00

227 lines
7.3 KiB
PHP

<?php
require_once('/home/aqdamypanel/www/cp/fixed/config/go_con.php');
ini_set('memory_limit', '2048M');
set_time_limit(300);
require '/home/aqdamypanel/vendor/autoload.php';
$employee = $_GET['e'] ?? 9;
$query = <<<SQL
SELECT
MAX(book_details.id) as id,
emplyee.name as employee_name,
book_details.emplyee_id as employee_id,
book.tretment_id as client_id,
tretment.name as client_name,
tretment.number as client_phone,
COUNT(*) as count
FROM book_details
INNER JOIN book ON book.id = book_details.book_id
INNER JOIN tretment ON tretment.id = book.tretment_id
INNER JOIN emplyee ON emplyee.id = book_details.emplyee_id
WHERE
book_details.status_id IN (15, 16)
GROUP BY client_id
HAVING COUNT(DISTINCT employee_id) = 1 AND MAX(employee_id) = ?
ORDER BY count DESC
SQL;
$stmt = mysqli_prepare($db, $query);
$error = mysqli_error($db);
if (!empty($error)) {
var_dump($error);
die;
}
$stmt->bind_param('i', $employee);
$stmt->execute();
$queryResult = $stmt->get_result();
$queryResult = $queryResult->fetch_all(MYSQLI_ASSOC);
if (!empty($error)) {
var_dump($queryResult, $error);
die;
}
echo "<pre>" . var_export($queryResult, true) . "</pre>";
die;
const TIME_FORMAT = 'Y-m-d H:i:s';
$lastTableDate = null;
$dayDrinks = [];
$dayCount = 0;
$dayWater = 0;
$drinks = [];
$water = 0;
function printDayTotals(\DateTime $currentTableDate) {
global $lastTableDate;
global $dayDrinks;
global $dayCount;
global $dayWater;
if ($dayCount > 0) {
$print = <<<HTML
<tr class="day-totals">
<td colspan="2">عدد الطلبات:<p class="bold">$dayCount</p></td>
<td colspan="5">اجمالي طلبات الموية:<p class="bold">$dayWater</p></td>
<tr>
HTML;
foreach ($dayDrinks as $name => $count) {
$print .= <<<HTML
<tr class="day-totals">
<td colspan="7" class="bold">$name: $count</td>
<tr>
HTML;
}
} else {
$print = "";
}
$dayCount = 0;
$dayWater = 0;
$dayDrinks = [];
$lastTableDate = $currentTableDate;
echo $print;
}
function printTotals() {
global $queryResult;
global $drinks;
global $water;
$count = count($queryResult);
$print = <<<HTML
<tr class="totals">
<td colspan="2">اجمالي الطلبات في الفرع:<p class="bold">$count</p></td>
<td colspan="5">اجمالي طلبات الموية:<p class="bold">$water</p></td>
<tr>
HTML;
foreach ($drinks as $name => $count) {
$print .= <<<HTML
<tr class="totals">
<td colspan="7" class="bold">$name: $count</td>
<tr>
HTML;
}
echo $print;
}
?>
<style>
* {
font-family: 'Segoe UI';
}
th,
td {
border: 1px solid rgb(160 160 160);
padding: 8px 10px;
}
th[scope='col'] {
background-color: #505050;
color: #fff;
}
th[scope='row'] {
background-color: #d6ecd4;
}
td {
text-align: center;
}
tr:nth-of-type(even):not(.totals) {
background-color: #eee;
}
.day-totals {
background-color: #0FF;
color: #000;
}
.totals {
background-color: #0F0;
color: #000;
}
.bold {
font-weight: bold;
}
.sticky {
position: sticky;
position: -webkit-sticky;
top: 0;
}
table {
border-collapse: collapse;
border: 2px solid rgb(140 140 140);
font-family: sans-serif;
font-size: 0.8rem;
letter-spacing: 1px;
}
</style>
<pre>
<table dir="rtl">
<thead class="sticky">
<tr>
<th scope="col" rowspan="2">#</th>
<th scope="col" rowspan="2">رقم الطلب</th>
<th scope="col" rowspan="2">تاريخ ووقت الطلب</th>
<th scope="col" rowspan="2">الفرع</th>
<th scope="col" rowspan="2">اسم العميل</th>
<th scope="col" rowspan="2">المشروب</th>
<th scope="col" rowspan="2">الموية</th>
</tr>
</thead>
<?php foreach ($queryResult as $i => &$res): ?>
<?php
if (!$lastTableDate) {
$lastTableDate = \DateTime::createFromFormat(TIME_FORMAT, $res['time']);
}
$currentTableDate = \DateTime::createFromFormat(TIME_FORMAT, $res['time']);
$last = $lastTableDate->format("Y-m-d");
$current = $currentTableDate->format("Y-m-d");
$currentHour = $currentTableDate->format('H');
if ($currentTableDate->format('H') < 3) {
$currentTableDate->modify('-1 day');
$current = $currentTableDate->format('Y-m-d');
}
if ($last != $current) {
printDayTotals($currentTableDate);
}
$dayDrinks[$res['drink']] += 1;
$drinks[$res['drink']] += 1;
if (!empty($res['water'])) {
$dayWater += 1;
$water += 1;
}
$dayCount += 1;
?>
<tr>
<td rowspan="<?php echo $detailsCount ?>"><?php echo $i + 1 ?></td>
<td rowspan="<?php echo $detailsCount ?>"><?php echo $res['order_id'] ?></td>
<td rowspan="<?php echo $detailsCount ?>"><?php echo $res['time'] ?></td>
<td rowspan="<?php echo $detailsCount ?>"><?php echo $res['branch_name'] ?></td>
<td rowspan="<?php echo $detailsCount ?>"><?php echo $res['customer_name'] ?></td>
<td rowspan="<?php echo $detailsCount ?>"><?php echo $res['drink'] ?></td>
<td rowspan="<?php echo $detailsCount ?>"><?php echo $res['water'] ?></td>
</tr>
<?php endforeach; ?>
<?php
if (isset($currentTableDate)) {
printDayTotals($currentTableDate);
}
printTotals();
?>
</tbody>
</table>
</pre>