Files
firstgarden-web-gnu/adm/fg_admin/orderlist_admin_sum.php

228 lines
7.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 = "10"; // 특정 카테고리 선택
$sel_ca_id = " NOT ca_id = $ca_id "; // 특정 카테고리 노출만 하려면 NOT을 지운다.
$where[] = "$sel_ca_id"; // 배열에 검색문을 넣어준다
$tot_ct_qty = 0;
// 퍼스트가든용 끝
include_once (G5_ADMIN_PATH.'/fg_admin/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;
$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
LIMIT $from_record, $rows ";
$result = sql_query($sql);
$qstr1 = "od_status=".urlencode($od_status)."&amp;
od_settle_case=".urlencode($od_settle_case)."&amp;
od_misu=$od_misu&amp
;od_cancel_price=$od_cancel_price&amp;
od_refund_price=$od_refund_price&amp;
od_receipt_point=$od_receipt_point&amp;
od_coupon=$od_coupon&amp;
fr_date=$fr_date&amp;
to_date=$to_date&amp;
sel_field=$sel_field&amp;
search=$search&amp;
save_search=$search";
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['total_price'] / $totals['quantity']); ?></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 (G5_ADMIN_PATH.'/fg_admin/orderlist.tail.php');
include_once (G5_ADMIN_PATH.'/admin.tail.php');
?>