418 lines
20 KiB
PHP
Executable File

<?php
$page_name = "custom_reports?s=46&";
$page_title = "نسب المدلكين الجديد";
$today = date("Y-m");
if (!empty($_GET['date'])) {
$today = $_GET['date'];
if (DateTime::createFromFormat('Y-m', $today) == false) {
$today = date("Y-m");
}
}
$Next = date('Y-m', strtotime('+1 month', strtotime($today)));
$Previous = date('Y-m', strtotime('-1 month', strtotime($today)));
$c_r_id = $_GET['c'];
if (!empty($_GET['c'])) {
$c_r_id = $_GET['c'];
if (!is_numeric($c_r_id)) {
$c_r_id = 1;
}
} else {
$c_r_id = 1;
}
$c_r_id_sql = '=' . $c_r_id;
if ($c_r_id == 1) {
$c_r_id_sql = '<>' . $c_r_id;
}
$branch_id = $_GET['b'];
if (!empty($_GET['b'])) {
$branch_id = $_GET['b'];
if (!is_numeric($branch_id)) {
$branch_id = 1;
}
} else {
$branch_id = 1;
}
$branch_sql = '=' . $branch_id;
if ($branch_id == 1) {
$branch_sql = '<>' . $branch_id;
}
$data = [];
$query = <<<SQL
SELECT
`bd`.`day_date`,
`book`.`id` AS `book_id`,
`book`.`tretment_id`,
`emplyee`.`id` AS `emplyee_id`,
`emplyee`.`name` AS `emplyee_name`,
`bd`.`status_id`,
`services`.`id` AS `serv_id`,
`services`.`point` AS `point`
FROM `book_details` AS `bd`
LEFT JOIN `book` ON `bd`.`book_id` = `book`.`id`
LEFT JOIN `services` ON `bd`.`services_id` = `services`.`id`
LEFT JOIN `emplyee` ON `bd`.`emplyee_id` = `emplyee`.`id`
JOIN (
SELECT `book_id`, MAX(`id`) AS `max_id`
FROM `book_details`
GROUP BY `book_id`
) `t1_max`
ON `bd`.`book_id` = `t1_max`.`book_id` AND `bd`.`id` = `t1_max`.`max_id`
WHERE DATE_FORMAT(`bd`.`day_date`, '%Y-%m') = '{$today}'
AND `emplyee`.`occupation_id` = 2
AND `bd`.`status_id` IN (6,8,12,13,14,15)
SQL;
$get_book_details_sql = mysqli_query($db,$query);
while ($get_book_details = mysqli_fetch_assoc($get_book_details_sql)) {
if (!array_key_exists($get_book_details['emplyee_id'], $data)) {
$data[$get_book_details['emplyee_id']]['info']['name'] = $get_book_details['emplyee_name'];
$data[$get_book_details['emplyee_id']]['data']['all_tretment_visits'] = [];
$data[$get_book_details['emplyee_id']]['data']['tr_visits_total'] = 0;
$data[$get_book_details['emplyee_id']]['data']['tr_visits_foot'] = 0;
$data[$get_book_details['emplyee_id']]['data']['tr_visits_body'] = 0;
$data[$get_book_details['emplyee_id']]['data']['tr_visits_full'] = 0;
$data[$get_book_details['emplyee_id']]['data']['tr_visits_else'] = 0;
$data[$get_book_details['emplyee_id']]['data']['points'] = 0;
}
$data[$get_book_details['emplyee_id']]['data']['all_tretment_visits'][$get_book_details['day_date']][$get_book_details['tretment_id']] = 1;
$data[$get_book_details['emplyee_id']]['data']['points'] += $get_book_details['point'];
switch ($get_book_details['serv_id']) {
case '1':
case '179':
case '198':
case '30':
case '183': // قدم
$data[$get_book_details['emplyee_id']]['data']['tr_visits_foot'] += 1;
if ($serv_id == 179) { // اول عميل بالزيارة
$data[$get_book_details['emplyee_id']]['data']['tr_visits_foot'] += 1;
}
$data[$get_book_details['emplyee_id']]['data']['tr_visits_total'] += 1;
break;
case '2':
case '180':
case '197':
case '31':
case '184': // جسم
$data[$get_book_details['emplyee_id']]['data']['tr_visits_body'] += 1;
if ($serv_id == 180) { // اول عميل بالزيارة
$data[$get_book_details['emplyee_id']]['data']['tr_visits_body'] += 1;
}
$data[$get_book_details['emplyee_id']]['data']['tr_visits_total'] += 1;
break;
case '3':
case '181':
case '196':
case '32':
case '185': // كامل
$data[$get_book_details['emplyee_id']]['data']['tr_visits_full'] += 1;
if ($serv_id == 181) { // اول عميل بالزيارة
$data[$get_book_details['emplyee_id']]['data']['tr_visits_full'] += 1;
}
$data[$get_book_details['emplyee_id']]['data']['tr_visits_total'] += 1;
break;
default:
$data[$get_book_details['emplyee_id']]['data']['tr_visits_else'] += 1;
$data[$get_book_details['emplyee_id']]['data']['tr_visits_total'] += 1;
break;
}
}
$count = 1;
?>
<!DOCTYPE html>
<html lang="en" dir="rtl">
<?php require_once('fixed/head/go.php'); ?>
<body class="rtl">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@mdi/font@6.5.95/css/materialdesignicons.min.css">
<style>
a.active {
background-color: #e6edef;
}
h1 {
background: #24695c;
padding-right: 10px;
color: white;
margin-left: 10px;
font-weight: bold;
}
</style>
<?php require_once('fixed/loader/go.php'); ?>
<div class="page-wrapper" id="pageWrapper">
<?php require_once('fixed/header/go.php'); ?>
<div class="page-body-wrapper">
<?php require_once('fixed/sidebar/go.php'); ?>
<div class="page-body">
<div class="container-fluid">
<div class="email-wrap bookmark-wrap">
<div class="row">
<div class="col-12 col-sm-12 col-md-12 col-lg-2 col-xl-2">
<div class="card">
<div class="card-body new-user order-list profile-nav">
<div class="nav flex-column nav-pills" id="profile-tab" aria-orientation="vertical">
<a class="nav-link mb-0 <?php if ($c_r_id == 1) {
echo 'active';
} ?> ?>" data-toggle="pill" href="#cr_1" aria-selected="false"
onclick="window.location='<?= $page_name ?>t=<?= $r_type ?>&date=<?= $today ?>&b=<?= $branch_id ?>&c=1&f=1'">الكل</a>
<a class="nav-link mb-0 <?php if ($c_r_id == 2) {
echo 'active';
} ?> ?>" data-toggle="pill" href="#cr_2" aria-selected="false"
onclick="window.location='<?= $page_name ?>t=<?= $r_type ?>&date=<?= $today ?>&b=<?= $branch_id ?>&c=2&f=1'">القسم
الرجالي</a>
<a class="nav-link mb-0 <?php if ($c_r_id == 3) {
echo 'active';
} ?> ?>" data-toggle="pill" href="#cr_3" aria-selected="false"
onclick="window.location='<?= $page_name ?>t=<?= $r_type ?>&date=<?= $today ?>&b=<?= $branch_id ?>&c=3&f=1'">القسم
النسائي</a>
<a class="nav-link mb-0 <?php if ($c_r_id == 4) {
echo 'active';
} ?> ?>" data-toggle="pill" href="#cr_4" aria-selected="false"
onclick="window.location='<?= $page_name ?>t=<?= $r_type ?>&date=<?= $today ?>&b=<?= $branch_id ?>&c=4&f=1'">القسم
الزيارات</a>
<a class="nav-link mb-0 <?php if ($c_r_id == 5) {
echo 'active';
} ?> ?>" data-toggle="pill" href="#cr_5" aria-selected="false"
onclick="window.location='<?= $page_name ?>t=<?= $r_type ?>&date=<?= $today ?>&b=<?= $branch_id ?>&c=5&f=1'">القسم
الطبيعي</a>
</div>
</div>
</div>
<div class="card">
<div class="card-body new-user order-list profile-nav">
<div class="nav flex-column nav-pills" id="profile-tab" aria-orientation="vertical">
<?php
$commercial_register_sql = mysqli_query(
$db,
"SELECT `branch`.`branch_name`, `branch`.`id`
FROM `commercial_register`
LEFT JOIN `branch` ON `commercial_register`.`id` = `branch`.`commercial_register_id`"
);
while ($commercial_register = mysqli_fetch_assoc($commercial_register_sql)) {
?>
<a class="nav-link mb-0 <?php if ($branch_id == $commercial_register['id']) {
echo 'active';
} ?> ?>" data-toggle="pill" href="#branch-<?= $commercial_register['id'] ?>"
aria-selected="false"
onclick="window.location='<?=$page_name?>b=<?= $commercial_register['id'] ?>&c=<?= $c_r_id ?>'"><?= $commercial_register['branch_name'] ?></a>
<?php
}
?>
</div>
</div>
</div>
</div>
<div class="col-12 col-sm-12 col-md-12 col-lg-10 col-xl-10">
<div class="card">
<div class="tab-content" id="profile-tabContent">
<div class="tab-pane fade show active" id="all">
<div class="card-body new-user order-list text-center">
<div class="row">
<div class="col-12 col-sm-12 col-md-3 col-lg-4 col-xl-4">
</div>
<div class="page-title mb-3 col-12 col-sm-12 col-md-6 col-lg-4 col-xl-4">
<i class="mdi mdi-monitor mr-2">
</i>
<h4>
<?= $page_title ?>
<br />
<?= $today ?>
</h4>
</div>
<div class="col-12 col-sm-12 col-md-3 col-lg-4 col-xl-4">
</div>
</div>
<div class="row">
<div class="col-12 col-sm-12 col-md-2 col-lg-3 col-xl-3">
</div>
<div class="col-2 col-sm-2 col-md-1 col-lg-1 col-xl-1">
<a class="btn btn-danger btn-round waves-effect waves-light col-12" href="<?=$page_name?>date=<?= $Previous ?>&b=<?= $branch_id ?>&c=<?= $c_r_id ?>"
style="padding: 0.375rem 0.75rem;">-</a>
</div>
<div class="col-8 col-sm-8 col-md-6 col-lg-4 col-xl-4">
<input id="Select-date" class="form-control" type="date" value=""
style="text-align: center !important;">
</div>
<div class="col-2 col-sm-2 col-md-1 col-lg-1 col-xl-1">
<a class="btn btn-primary btn-round waves-effect waves-light col-12" href="<?=$page_name?>date=<?= $Next ?>&b=<?= $branch_id ?>&c=<?= $c_r_id ?>"
style="padding: 0.375rem 0.75rem;">+</a>
</div>
<div class="col-12 col-sm-12 col-md-2 col-lg-3 col-xl-3">
</div>
</div>
</div>
<div class="tab-content">
<div class="tab-pane p-3 active" id="tab<?= $tabs ?>" role="tabpanel">
<div class="card-body new-user order-list">
<div class="table-responsive">
<table id="employee_data" class="table table-bordered text-center"
style="vertical-align: middle;">
<thead class="table-primary" style="vertical-align: middle;">
<tr>
<th rowspan="3" scope="col">#</th>
<th rowspan="3" scope="col">اسم الموظف</th>
<th rowspan="3" scope="col">عدد العملاء</th>
<th rowspan="3" scope="col">عدد النقاط</th>
<th colspan="9" scope="col">الخدمات المقدمة</th>
<th colspan="3" scope="col">المستحقات</th>
</tr>
<tr>
<th scope="col">المجموع</th>
<th colspan="2" scope="col">تدليك أقدام</th>
<th colspan="2" scope="col">تدليك جسم</th>
<th colspan="2" scope="col">تدليك كامل</th>
<th colspan="2" scope="col">اخرى</th>
<th rowspan="2" scope="col">النقاط</th>
<th rowspan="2" scope="col">المكافئة</th>
<th rowspan="2" scope="col">الاجمالي</th>
</tr>
<tr>
<th scope="col">العدد</th>
<th scope="col">العدد</th>
<th scope="col">النسبة</th>
<th scope="col">العدد</th>
<th scope="col">النسبة</th>
<th scope="col">العدد</th>
<th scope="col">النسبة</th>
<th scope="col">العدد</th>
<th scope="col">النسبة</th>
</tr>
</thead>
<tbody>
<?php
foreach ($data as $key => $value) {
$all_tretment_visits = 0;
$points = $data[$key]['data']['points'];
$tr_visits_total = $data[$key]['data']['tr_visits_total'];
$tr_visits_foot = $data[$key]['data']['tr_visits_foot'];
$tr_visits_foot_per = round(($data[$key]['data']['tr_visits_foot'] / $data[$key]['data']['tr_visits_total']) * 100, 2) ;
$tr_visits_body = $data[$key]['data']['tr_visits_body'];
$tr_visits_body_per = round(($data[$key]['data']['tr_visits_body'] / $data[$key]['data']['tr_visits_total']) * 100, 2) ;
$tr_visits_full = $data[$key]['data']['tr_visits_full'];
$tr_visits_full_per = round(($data[$key]['data']['tr_visits_full'] / $data[$key]['data']['tr_visits_total']) * 100, 2) ;
$tr_visits_else = $data[$key]['data']['tr_visits_else'];
$tr_visits_else_per = round(($data[$key]['data']['tr_visits_else'] / $data[$key]['data']['tr_visits_total']) * 100, 2) ;
$gift = 0;
?>
<tr>
<th scope="row"><?= $count ?></th>
<td><a
href="emp_points_d.php?id=<?= $key ?>&date=<?= $today ?>"><?= $data[$key]['info']['name'] ?></a>
</td>
<?php
foreach($data[$key]['data']['all_tretment_visits'] as $key2 => $value2) {
$all_tretment_visits += count($data[$key]['data']['all_tretment_visits'][$key2]);
}
?>
<td><?= $all_tretment_visits ?></td>
<td><?= $points?></td>
<td><?= $tr_visits_total ?></td>
<td><?= $tr_visits_foot ?></td>
<td><?= $tr_visits_foot_per ?>%</td>
<td><?= $tr_visits_body ?></td>
<td><?= $tr_visits_body_per ?>%</td>
<td><?= $tr_visits_full ?></td>
<td><?= $tr_visits_full_per ?>%</td>
<td><?= $tr_visits_else ?></td>
<td><?= $tr_visits_else_per ?>%</td>
<td><?= $data[$key]['data']['points'] * 15 ?></td>
<?php
if($tr_visits_foot_per > 24 && $tr_visits_body_per > 24 && $tr_visits_full_per > 24) {
if($all_tretment_visits >= 130 && $all_tretment_visits < 156) {
$gift = 500;
} else if($all_tretment_visits >= 156 && $all_tretment_visits < 182) {
$gift = 1000;
} else if($all_tretment_visits >= 182 && $all_tretment_visits < 208) {
$gift = 2000;
} else if($all_tretment_visits >= 208 && $all_tretment_visits < 234) {
$gift = 3000;
} else if($all_tretment_visits >= 234 && $all_tretment_visits < 260) {
$gift = 4000;
} else if($all_tretment_visits >= 260) {
$gift = 5000;
}
}
?>
<td><?= $gift ?></td>
<td><?= ($data[$key]['data']['points'] * 15) + $gift ?></td>
</tr>
<?php
$count ++;
}
?>
<tr>
<td colspan="2">المجموع</td>
<td>%</td>
</tr>
</tbody>
</table>
<button type="button" id="export_button" class="btn btn-success btn-sm">ملف excel</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php require_once('fixed/footer/go.php'); ?>
</div>
</div>
<div id="get_data"></div>
<?php require_once('fixed/js/go.php'); ?>
<script type="text/javascript" src="https://unpkg.com/xlsx@0.15.1/dist/xlsx.full.min.js"></script>
<script>
$("#Select-date").change(function () {
var SelectedDate = $(this).val();
window.location ='<?=$page_name?>b=<?= $branch_id ?>&date=' + SelectedDate
});
function html_table_to_excel(type) {
var data = document.getElementById('employee_data');
var file = XLSX.utils.table_to_book(data, { sheet: "sheet1" });
XLSX.write(file, { bookType: type, bookSST: true, type: 'base64' });
XLSX.writeFile(file, 'النقاط.' + type);
}
const export_button = document.getElementById('export_button');
export_button.addEventListener('click', () => {
html_table_to_excel('xlsx');
});
</script>
<?php require_once('fixed/waiting_ajax/go.php'); ?>
</body>
</html>