| Server IP : 188.114.96.3 / Your IP : 216.73.216.143 Web Server : Apache System : Linux sv058.home.net.pl 6.8.2 husak_dirty_pages_fix #1 SMP PREEMPT_DYNAMIC Tue Apr 2 22:06:51 CEST 2024 x86_64 User : ( 3194769) PHP Version : 8.5.12 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /polana/admin/ |
Upload File : |
<?php
declare(strict_types=1);require_once dirname(__DIR__).'/includes/functions.php';require_login();$user=admin_user();if(!$user||!in_array((string)$user['role'],operations_month_roles(),true)){http_response_code(403);exit('Raport jest dostępny dla managera i administratora.');}ensure_operations_schema();ensure_schedule_schema();ensure_tips_schema();$month=trim((string)($_GET['month']??date('Y-m')));if(!preg_match('/^\d{4}-\d{2}$/',$month))$month=date('Y-m');$from=$month.'-01';$to=(new DateTimeImmutable($from))->modify('last day of this month')->format('Y-m-d');
$q=db()->prepare("SELECT COUNT(*) cnt,COALESCE(SUM(guests),0) guests,COALESCE(SUM(status='no_show'),0) no_show FROM reservations WHERE reservation_date BETWEEN ? AND ? AND status NOT IN ('rejected','cancelled')");$q->execute([$from,$to]);$res=$q->fetch()?:[];$q=db()->prepare("SELECT COUNT(*) days,COALESCE(SUM(cash_amount+card_amount+other_amount),0) total FROM tip_pools WHERE tip_date BETWEEN ? AND ?");$q->execute([$from,$to]);$tips=$q->fetch()?:[];$tipDays=(int)($tips['days']??0);$avg=$tipDays?((float)$tips['total']/$tipDays):0;
$q=db()->prepare("SELECT u.id,u.name,u.username,u.role,COUNT(s.id) work_days,COALESCE(SUM(CASE WHEN s.start_time IS NULL OR s.end_time IS NULL THEN 0 WHEN s.end_time>=s.start_time THEN TIME_TO_SEC(TIMEDIFF(s.end_time,s.start_time))/3600 ELSE (86400+TIME_TO_SEC(s.end_time)-TIME_TO_SEC(s.start_time))/3600 END),0) work_hours FROM users u LEFT JOIN staff_schedule s ON s.user_id=u.id AND s.work_date BETWEEN ? AND ? WHERE u.role IN ('waiter','kitchen') GROUP BY u.id,u.name,u.username,u.role ORDER BY FIELD(u.role,'waiter','kitchen'),COALESCE(u.name,u.username)");$q->execute([$from,$to]);$staff=$q->fetchAll();$tipPeople=[];foreach(tip_person_month_summary($month) as $p)$tipPeople[(int)$p['user_id']]=$p;render_admin_header('Raport '.$month); ?>
<div class="admin-title-row"><div><h1>Raport miesiąca</h1><p>Obsada, rezerwacje i napiwki.</p></div><form method="get"><input type="month" name="month" value="<?= e($month) ?>" onchange="this.form.submit()"></form></div><div class="grid-cards"><div class="card"><h3>Rezerwacje</h3><div class="stat"><?= (int)($res['cnt']??0) ?></div></div><div class="card"><h3>Goście</h3><div class="stat"><?= (int)($res['guests']??0) ?></div></div><div class="card"><h3>No-show</h3><div class="stat"><?= (int)($res['no_show']??0) ?></div></div><div class="card"><h3>Napiwki</h3><div class="stat tip-stat-money"><?= e(tip_money((float)($tips['total']??0))) ?></div></div><div class="card"><h3>Średnio / dzień</h3><div class="stat tip-stat-money"><?= e(tip_money($avg)) ?></div></div></div><section class="card" style="margin-top:20px"><h2>Zespół</h2><div class="table-wrap"><table class="admin-table"><thead><tr><th>Osoba</th><th>Rola</th><th>Dni pracy</th><th>Godziny</th><th>Napiwki</th><th>Wypłacone</th></tr></thead><tbody><?php foreach($staff as $p):$t=$tipPeople[(int)$p['id']]??null;?><tr><td><strong><?= e($p['name']?:$p['username']) ?></strong></td><td><?= e($p['role']==='kitchen'?'Kuchnia':'Kelner') ?></td><td><?= (int)$p['work_days'] ?></td><td><?= e(number_format((float)$p['work_hours'],1,',',' ')) ?></td><td><?= e(tip_money((float)($t['share_total']??0))) ?></td><td><?= e(tip_money((float)($t['paid_total']??0))) ?></td></tr><?php endforeach; ?></tbody></table></div></section><?php render_admin_footer(); ?>