Files
2026-06-11 18:47:38 +09:00

135 lines
4.6 KiB
PHP

<?php
$sub_menu = '400910'; // 임시 메뉴 코드
include_once('./_common.php');
auth_check_menu($auth, $sub_menu, "r");
$g5['title'] = '정산/통계 관리';
include_once(G5_ADMIN_PATH.'/admin.head.php');
// 검색 기간 설정 (기본값: 이번 달)
$fr_date = $_GET['fr_date'] ?? date('Y-m-01');
$to_date = $_GET['to_date'] ?? date('Y-m-d');
// 1. 일별 매출 통계
$sql = " SELECT
SUBSTRING(od_time, 1, 10) as od_date,
COUNT(*) as cnt,
SUM(od_receipt_price) as total_price,
SUM(od_cancel_price) as cancel_price
FROM {$g5['g5_shop_order_table']}
WHERE od_time BETWEEN '{$fr_date} 00:00:00' AND '{$to_date} 23:59:59'
AND od_status IN ('입금', '준비', '배송', '완료')
GROUP BY od_date
ORDER BY od_date DESC ";
$result = sql_query($sql);
$daily_data = [];
$total_sum = 0;
$total_cnt = 0;
while ($row = sql_fetch_array($result)) {
$daily_data[] = $row;
$total_sum += $row['total_price'];
$total_cnt += $row['cnt'];
}
// 2. 결제 수단별 통계
$sql_settle = " SELECT
od_settle_case,
COUNT(*) as cnt,
SUM(od_receipt_price) as total_price
FROM {$g5['g5_shop_order_table']}
WHERE od_time BETWEEN '{$fr_date} 00:00:00' AND '{$to_date} 23:59:59'
AND od_status IN ('입금', '준비', '배송', '완료')
GROUP BY od_settle_case ";
$result_settle = sql_query($sql_settle);
?>
<div class="local_sch01 local_sch">
<form name="fsearch" id="fsearch" class="local_sch_search" method="get">
<span class="sch_tit">기간</span>
<input type="text" name="fr_date" value="<?php echo $fr_date; ?>" id="fr_date" class="frm_input" size="11" maxlength="10">
~
<input type="text" name="to_date" value="<?php echo $to_date; ?>" id="to_date" class="frm_input" size="11" maxlength="10">
<input type="submit" value="검색" class="btn_submit">
</form>
</div>
<script>
$(function(){
$("#fr_date, #to_date").datepicker({ changeMonth: true, changeYear: true, dateFormat: "yy-mm-dd", showButtonPanel: true, yearRange: "c-99:c+99", maxDate: "+0d" });
});
</script>
<div class="tbl_head01 tbl_wrap">
<table>
<caption>일별 매출 현황</caption>
<thead>
<tr>
<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 ($daily_data as $row):
$net_sales = $row['total_price'] - $row['cancel_price'];
?>
<tr>
<td class="td_date"><?php echo $row['od_date']; ?></td>
<td class="td_num"><?php echo number_format($row['cnt']); ?>건</td>
<td class="td_numbig"><?php echo number_format($row['total_price']); ?>원</td>
<td class="td_numbig"><?php echo number_format($row['cancel_price']); ?>원</td>
<td class="td_numbig" style="font-weight:bold; color:#0056b3;"><?php echo number_format($net_sales); ?>원</td>
</tr>
<?php endforeach; ?>
<?php if (empty($daily_data)): ?>
<tr><td colspan="5" class="empty_table">데이터가 없습니다.</td></tr>
<?php else: ?>
<tr class="bg1">
<td class="td_date"><strong>합계</strong></td>
<td class="td_num"><strong><?php echo number_format($total_cnt); ?>건</strong></td>
<td class="td_numbig"><strong><?php echo number_format($total_sum); ?>원</strong></td>
<td class="td_numbig">-</td>
<td class="td_numbig"><strong><?php echo number_format($total_sum); ?>원</strong></td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
<div class="tbl_head01 tbl_wrap" style="margin-top:30px;">
<table>
<caption>결제 수단별 통계</caption>
<thead>
<tr>
<th scope="col">결제수단</th>
<th scope="col">건수</th>
<th scope="col">금액</th>
<th scope="col">비율</th>
</tr>
</thead>
<tbody>
<?php
while ($row = sql_fetch_array($result_settle)) {
$ratio = $total_sum > 0 ? round(($row['total_price'] / $total_sum) * 100, 1) : 0;
?>
<tr>
<td class="td_center"><?php echo $row['od_settle_case']; ?></td>
<td class="td_num"><?php echo number_format($row['cnt']); ?>건</td>
<td class="td_numbig"><?php echo number_format($row['total_price']); ?>원</td>
<td class="td_num"><?php echo $ratio; ?>%</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?php
include_once(G5_ADMIN_PATH.'/admin.tail.php');
?>