Files
firstgarden-web-gnu/adm/fg_admin/orderlist_admin_sum.php
KWON d125d39965 파일을 직접수정하지 않고 hook을 사용해 관리자 메뉴 추가.
기존 shop_admin 에 포함되어있던 새 파일을 fg_admin 폴더 내부로 이동
관리자 월 정산용 페이지 오작동 문제 해결
2025-12-11 10:40:20 +09:00

254 lines
8.8 KiB
PHP

<?php
$sub_menu = '998413';
include_once('./_common.php');
auth_check($auth[$sub_menu], "r");
$g5['title'] = '월간 주문내역 합계';
include_once (G5_ADMIN_PATH.'/admin.head.php');
include_once(G5_PLUGIN_PATH.'/jquery-ui/datepicker.php');
$where = array();
// 퍼스트가든용
// $od_status = '입금'; //입금처리 된것만 출력한다.
// 특정 카테고리만 노출
#$ca_id = "30"; // 특정 카테고리 선택
#$sel_ca_id = " NOT ca_id = $ca_id "; // 특정 카테고리 노출만 하려면 NOT을 지운다.
$tot_ct_qty = 0;
// 기존: $where[] = "$sel_ca_id"; // 배열에 검색문을 넣어준다
// 변경: sel_ca_id가 비어있지 않을 때만 WHERE조건에 추가
if (!empty($sel_ca_id)) {
$where[] = $sel_ca_id;
}
//$od_status = '입금'; //입금처리 된것만 출력한다.
//$where[] = " a.od_status = '{$od_status}' ";
// 시작일이 설정되지 않았다면: 지난달 1일
if (!isset($fr_date)) {
$fr_date = date("Y-m-01", strtotime("first day of last month", G5_SERVER_TIME));
}
// 종료일이 설정되지 않았다면: 지난달 마지막 날
if (!isset($to_date)) {
$to_date = date("Y-m-t", strtotime("last month", G5_SERVER_TIME));
}
// 퍼스트가든용 끝
include_once ('orderlist_head.php');
$sql_search = "";
if ($search != "") {
if ($sel_field != "") {
$where[] = " $sel_field like '%$search%' ";
}
if ($save_search != $search) {
$page = 1;
}
}
// od_status가 입금, 완료인 것만 출력함
$where[] = " a.od_status IN('입금','완료') ";
/*
if ($od_settle_case) {
$where[] = " a.od_settle_case = '$od_settle_case' ";
}
if ($od_misu) {
$where[] = " a.od_misu != 0 ";
}
if ($od_cancel_price) {
$where[] = " a.od_cancel_price != 0 ";
}
if ($od_refund_price) {
$where[] = " a.od_refund_price != 0 ";
}
if ($od_receipt_point) {
$where[] = " a.od_receipt_point != 0 ";
}
if ($od_coupon) {
$where[] = " ( a.od_cart_coupon > 0 or a.od_coupon > 0 or a.od_send_coupon > 0 ) ";
}
if ($od_escrow) {
$where[] = " a.od_escrow = 1 ";
}
*/
if ($fr_date && $to_date) {
$where[] = " a.od_time between '$fr_date 00:00:00' AND '$to_date 23:59:59' ";
}
if ($where) {
$sql_search = ' WHERE '.implode(' AND ', $where);
}
if ( empty($sel_field) ) $sel_field = "a.od_id";
if ( empty($sort1) ) $sort1 = "a.od_id";
if ( empty($sort2) ) $sort2 = "desc";
// 상품명, 단가, 수량, 카테고리를 불러오기 위해 DB를 합친다
$sql_common = " FROM {$g5['g5_shop_order_table']} AS a
LEFT JOIN {$g5['g5_shop_cart_table']} AS b ON a.od_id = b.od_id
LEFT JOIN {$g5['g5_shop_item_table']} AS c ON b.it_id = c.it_id
LEFT JOIN {$g5['g5_shop_item_option_table']} AS d ON c.it_id = d.it_id AND b.io_id = d.io_id
";
$sql_common .= $sql_search;
// 기존: 페이징용 count 쿼리 및 LIMIT 처리로 인해 일부 결과만 집계되는 문제가 있어 전체 결과 조회로 변경
// $sql = " SELECT count(a.od_id) AS cnt " . $sql_common ;
// $row = sql_fetch($sql);
// $total_count = $row['cnt'];
// $rows = 100; // 페이지 당 출력 개수
// if( !isset($rows) ) $rows = $config['cf_page_rows'];
// $total_page = ceil($total_count / $rows); // 전체 페이지 계산
// if ($page < 1) { $page = 1; } // 페이지가 없으면 첫 페이지 (1 페이지)
// $from_record = ($page - 1) * $rows; // 시작 열을 구함
// 상품명, 수량, 단가, 카테고리를 가져옴
$sql = " SELECT a.od_id,
b.it_name,
b.ct_qty,
b.ct_price,
b.ct_option,
b.io_id,
c.ca_id,
c.it_1,
c.it_2,
d.io_price
$sql_common
ORDER BY $sort1 $sort2 ";
$result = sql_query($sql);
// qstr 생성부가 불완전하게 작성되어 있어 안전하게 재작성
$qarr = array(
'od_status' => $od_status,
'od_settle_case' => $od_settle_case,
'od_misu' => $od_misu,
'od_cancel_price' => $od_cancel_price,
'od_refund_price' => $od_refund_price,
'od_receipt_point' => $od_receipt_point,
'od_coupon' => $od_coupon,
'fr_date' => $fr_date,
'to_date' => $to_date,
'sel_field' => $sel_field,
'search' => $search,
'save_search' => $search
);
// http_build_query로 생성 후 HTML용으로 & -> &amp; 변환
$qstr1 = str_replace('&', '&amp;', http_build_query($qarr));
if($default['de_escrow_use'])
$qstr1 .= "&amp;od_escrow=$od_escrow";
$qstr = "$qstr1&amp;sort1=$sort1&amp;sort2=$sort2&amp;page=$page";
$listall = '<a href="'.$_SERVER['SCRIPT_NAME'].'" class="ov_listall">전체목록</a>';
?>
<!--
<form name="frmorderlist" class="local_sch01 local_sch">
<input type="hidden" name="doc" value="<?php echo $doc; ?>">
<input type="hidden" name="sort1" value="<?php echo $sort1; ?>">
<input type="hidden" name="sort2" value="<?php echo $sort2; ?>">
<input type="hidden" name="page" value="<?php echo $page; ?>">
<input type="hidden" name="save_search" value="<?php echo $search; ?>">
<label for="sel_field" class="sound_only">검색대상</label>
<select name="sel_field" id="sel_field">
<option value="od_tel" <?php echo get_selected($sel_field, 'od_tel'); ?> selected>연락처</option>
<option value="od_name" <?php echo get_selected($sel_field, 'od_name'); ?>>주문자</option>
<option value="od_id" <?php echo get_selected($sel_field, 'od_id'); ?>>주문번호</option>
</select>
<label for="search" class="sound_only">검색어<strong class="sound_only"> 필수</strong></label>
<input type="text" name="search" value="<?php echo $search; ?>" id="search" required class="required frm_input" autocomplete="off">
<input type="submit" value="검색" class="btn_submit">
</form>
-->
<form class="local_sch03 local_sch">
<div class="sch_last">
<strong>주문일자</strong>
<input type="text" id="fr_date" name="fr_date" value="<?php echo $fr_date; ?>" class="frm_input" size="10" maxlength="10"> ~
<input type="text" id="to_date" name="to_date" value="<?php echo $to_date; ?>" class="frm_input" size="10" maxlength="10">
<button type="button" onclick="javascript:set_date('오늘');">오늘</button>
<button type="button" onclick="javascript:set_date('어제');">어제</button>
<button type="button" onclick="javascript:set_date('이번주');">이번주</button>
<button type="button" onclick="javascript:set_date('이번달');">이번달</button>
<button type="button" onclick="javascript:set_date('지난주');">지난주</button>
<button type="button" onclick="javascript:set_date('지난달');">지난달</button>
<button type="button" onclick="javascript:set_date('전체');">전체</button>
<input type="submit" value="검색" class="btn_submit">
</div>
</form>
<form name="forderlist" id="forderlist" onsubmit="return forderlist_submit(this);" method="post" autocomplete="off">
<input type="hidden" name="search_od_status" value="<?php echo $od_status; ?>">
<?php
// 총 수량과 총 금액을 저장할 배열 초기화
$total_items = array();
while ($row = sql_fetch_array($result)) {
$item_name = $row['it_name'];
$item_option = $row['ct_option'];
if (!isset($total_items[$item_name][$item_option])) {
$total_items[$item_name][$item_option]['quantity'] = 0;
$total_items[$item_name][$item_option]['total_price'] = 0;
}
if ( !isset($total_items[$item_name][$item_option]['price'] ) ) $total_items[$item_name][$item_option]['price'] = $row['ct_price'] + $row['io_price'];
$total_items[$item_name][$item_option]['quantity'] += $row['ct_qty'];
$total_items[$item_name][$item_option]['total_price'] += $row['ct_qty'] * ($row['ct_price'] + $row['io_price']);
}
// PHP 코드 블록 종료
?>
<div class="tbl_head01 tbl_wrap">
<table id="sodr_list">
<!-- 합계 표 출력 -->
<tr>
<th>상품명</th>
<th>옵션</th>
<th>단가</th>
<th>총 수량</th>
<th>총 금액</th>
</tr>
<?php foreach ($total_items as $item_name => $options): ?>
<?php foreach ($options as $option => $totals): ?>
<tr>
<td><?php echo $item_name; ?></td>
<td><?php echo $option; ?></td>
<td class="td_num"><?php echo number_format( $totals['quantity'] ? ($totals['total_price'] / $totals['quantity']) : 0 ); ?></td>
<td class="th_odrcnt"><?php echo number_format($totals['quantity']); ?></td>
<td class="td_num td_numsum"><?php echo number_format($totals['total_price']); ?></td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</table>
</div>
<?php
include_once ('orderlist_tail.php');
include_once (G5_ADMIN_PATH.'/admin.tail.php');
?>