Files
sam-kd/juilcarlog/usage_purpose_stats.php
hskwon aca1767eb9 초기 커밋: 5130 레거시 시스템
- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경
- DB 연결 하드코딩 → .env 기반으로 변경
- MySQL strict mode DATE 오류 수정
2025-12-10 20:14:31 +09:00

50 lines
1.5 KiB
PHP

<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
$pdo = db_connect();
$vehicle = $_POST['vehicle'] ?? '';
$user = $_POST['user'] ?? '';
$fromdate = $_POST['fromdate'] ?? '';
$todate = $_POST['todate'] ?? '';
$usage_purposes = ['출근', '퇴근', '현장', '비업무용'];
$stats = [];
foreach ($usage_purposes as $purpose) {
$sql = "SELECT COUNT(*) as cnt, IFNULL(SUM(driving_distance),0) as total_distance
FROM juilcarlog
WHERE car_number = :vehicle
AND caruser_name = :user
AND usage_purpose = :purpose
AND use_date BETWEEN :fromdate AND :todate
AND is_deleted = 0";
$stmh = $pdo->prepare($sql);
$stmh->execute([
':vehicle' => $vehicle,
':user' => $user,
':purpose' => $purpose,
':fromdate' => $fromdate,
':todate' => $todate
]);
$row = $stmh->fetch(PDO::FETCH_ASSOC);
$stats[$purpose] = $row;
}
?>
<table class="table table-bordered">
<thead>
<tr>
<th>사용목적</th>
<th>횟수</th>
<th>총 주행거리 (km)</th>
</tr>
</thead>
<tbody>
<?php foreach ($usage_purposes as $purpose): ?>
<tr>
<td><?= htmlspecialchars($purpose) ?></td>
<td><?= $stats[$purpose]['cnt'] ?></td>
<td><?= number_format($stats[$purpose]['total_distance']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>