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

331 lines
17 KiB
PHP

<?php
require_once('fixed/config/go_con.php');
// access(50);
$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)));
$frist_day = date('Y-m-d', strtotime($today));
$last_day = date("Y-m-t", strtotime($frist_day));
$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 = [
'times' => []
];
$get_emplyee_sql = mysqli_query($db, "SELECT `time` FROM `times` WHERE `time` LIKE '%:00:00'");
while ($get_emplyee = mysqli_fetch_assoc($get_emplyee_sql)) {
if($get_emplyee['time'] == "02:00:00" ||
$get_emplyee['time'] == "03:00:00" ||
$get_emplyee['time'] == "04:00:00" ||
$get_emplyee['time'] == "05:00:00" ||
$get_emplyee['time'] == "06:00:00" ||
$get_emplyee['time'] == "07:00:00" ||
$get_emplyee['time'] == "08:00:00") {
continue;
}
$data['times'][$get_emplyee['time']] = [
'all_free' => [],
'free' => [],
'books' => [],
];
}
// عدد المدلكين المتوفرين خلال الساعة
$get_emplyee_sql = mysqli_query($db, "SELECT
`e`.`id`,
`e`.`name`,
`hd`.`day`,
`e`.`branch_id`,
TIME(`wtt`.`from_date_time`) AS `fromTime`,
TIME(`wtt`.`to_date_time`) AS `toTime`
FROM `work_time_table` `wtt`
LEFT JOIN `emplyee` `e` ON `wtt`.`emplyee_id` = `e`.`id`
LEFT JOIN `branch` `b` ON `e`.`branch_id` = `b`.`id`
LEFT JOIN `holi_days` `hd` ON `e`.`holi_days_id` = `hd`.`id`
WHERE `e`.`branch_id` $branch_sql
-- AND `b`.`commercial_register_id` = 2
AND `wtt`.`activation_id` = 2
AND `e`.`occupation_id` = 2
AND DATE(`wtt`.`to_date_time`) > '$frist_day' AND DATE(`wtt`.`from_date_time`) < '$last_day'
");
while ($get_emplyee = mysqli_fetch_assoc($get_emplyee_sql)) {
foreach ($data['times'] as $key => $value) {
$givenTime = $key;
$fromDateTime = $get_emplyee['fromTime'];
$toDateTime = $get_emplyee['toTime'];
$fromDateTimeObj = new DateTime($fromDateTime);
$toDateTimeObj = new DateTime($toDateTime);
$givenTimeObj = new DateTime($givenTime);
if ($givenTimeObj >= $fromDateTimeObj && $givenTimeObj <= $toDateTimeObj) {
array_push($data['times'][$key]['all_free'], $get_emplyee);
$data['times'][$key]['free'][$get_emplyee['id']] += 1;
}
}
}
// عدد الجلسات المفعلة
$get_emplyee_sql = mysqli_query($db, "SELECT
`t1`.`day_time`,
IFNULL(COUNT(`t1`.`id`),0) AS `count`
FROM `book_details` AS `t1`
iNNER JOIN `branch` ON `branch`.`id` = `t1`.`branch_id`
iNNER JOIN `emplyee` ON `emplyee`.`id` = `t1`.`emplyee_id`
JOIN (
SELECT `book_id`, MAX(`id`) AS `max_id`
FROM `book_details`
GROUP BY `book_id`
) `t1_max`
ON `t1`.`book_id` = `t1_max`.`book_id` AND `t1`.`id` = `t1_max`.`max_id`
WHERE `status_id` IN (6,8,14,15)
AND (
(`t1`.`day_date` = '$frist_day' AND `t1`.`day_time` BETWEEN '09:00:00' AND '23:59:59')
OR (`t1`.`day_date` = '$last_day' AND `t1`.`day_time` <= '03:00:00')
)
AND `t1`.`branch_id` $branch_sql
-- AND `branch`.`commercial_register_id` = 2
AND `emplyee`.`occupation_id` = 2
GROUP BY `t1`.`day_time`
");
while ($get_emplyee = mysqli_fetch_assoc($get_emplyee_sql)) {
array_push($data['times'][$get_emplyee['day_time']]['books'], $get_emplyee['count']);
}
// while ($get_emplyee = mysqli_fetch_assoc($get_emplyee_sql)) {
// if (!array_key_exists($get_emplyee['id'], $data['emplyees'])) {
// $data['emplyees'][$get_emplyee['id']] = array(
// 'time_work' => array(),
// );
// }
// $from = $get_time_work['fromTime'][0] . $get_time_work['fromTime'][1];
// $to = $get_time_work['toTime'][0] . $get_time_work['toTime'][1];
// $ttx = 0;
// for ($from; $from <= $to; $from++) {
// $push_time_work = $from . ":00:00";
// if ($from < 10 && $ttx > 0) {
// $push_time_work = "0" . $from . ":00:00";
// }
// if ($Day == "Fri" && $push_time_work == '13:00:00') { // كل جمعه الساعه 1 خلية مقفل
// continue;
// }
// array_push($data['emplyees'][$get_time_work['emplyee_id']]['time_work'], $push_time_work);
// $ttx++;
// }
// }
?>
<!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">
<?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='custom_reports?s=42&date=<?= $today ?>&b=<?= $commercial_register['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>
نسبة الاشغال
<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="custom_reports?s=42&date=<?= $Previous ?>&b=<?= $branch_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="custom_reports?s=42&date=<?= $Next ?>&b=<?= $branch_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="card-body new-user order-list">
<div class="table-responsive">
<table class="table table-bordered text-center"
style="vertical-align: middle;">
<thead class="table-primary" style="vertical-align: middle;">
<tr>
<th scope="col">
الاوقات
</th>
<th scope="col">
المدلكين المتوفرين
</th>
<th scope="col">
عدد الجلسات المفعلة
</th>
<th scope="col">
النسية
</th>
</tr>
</thead>
<tbody>
<?php
$t1 = 0;
$t2 = 0;
$t3 = 0;
foreach ($data['times'] as $key => $value) {
$s1 = count($data['times'][$key]['free']);
$s2 = !empty($data['times'][$key]['books'][0]) ? $data['times'][$key]['books'][0] : 0;
if($s2 > 0 && $s1 == 0) {
$s1 = 1;
}
$s3 = $s1 == 0 && $s2 == 0 ? 0 : round($s2/$s1*100,2);
if($s2 > 0 && $s1 == 1) {
$s1 = 0;
}
$t1 += count($data['times'][$key]['free']);
$t2 += !empty($data['times'][$key]['books'][0]) ? $data['times'][$key]['books'][0] : 0;
?>
<tr>
<th scope="row">
<?= $key ?>
</th>
<td>
<?= $s1 ?>
</td>
<td>
<?= $s2 ?>
</td>
<td>
<?= $s3 ?>%
</td>
</tr>
<?php
}
?>
<tr>
<td>المجموع</td>
<td><?=$t1?></td>
<td><?=$t2?></td>
<td><?=$t1 == 0 && $t2 == 0 ? 0 : round($t2/$t1*100,2);?>%</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php require_once('fixed/footer/go.php'); ?>
</div>
</div>
<?php require_once('fixed/js/go.php'); ?>
<?php require_once('fixed/waiting_ajax/go.php'); ?>
<script>
$("#Select-date").change(function () {
var SelectedDate = $(this).val();
window.location = 'custom_reports?s=42&b=<?= $branch_id ?>&date=' + SelectedDate
});
</script>
</body>
</html>