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

121 lines
4.1 KiB
PHP

<?php
include_once('./_common.php');
auth_check($auth['998411'], "r");
// POST로 전달된 데이터 받기
$sql_common = isset($_POST['sql_common']) ? $_POST['sql_common'] : '';
$sort1 = isset($_POST['sort1']) ? $_POST['sort1'] : 'a.od_id';
$sort2 = isset($_POST['sort2']) ? $_POST['sort2'] : 'desc';
$file_name = "orderlist_".date("ymd")."_".date("His").".xls"; // 파일명지정
header("Content-Type: application/vnd.ms-excel");
header('Content-Type: application/vnd.ms-excel; charset=utf-8');
header("Content-Disposition: attachment; filename=$file_name");
header("Content-Description: PHP5 Generated Data");
$sql = " SELECT a.*,
(a.od_cart_coupon + a.od_coupon + a.od_send_coupon) as couponprice,
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
";
$sql= stripslashes($sql);
$result = sql_query($sql);
?>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<style type="text/css">
table { border-collapse: collapse;}
th, td { border: 1px solid #000; padding: 0px; text-align: center; }
th { background-color: #D3D3D3; font-weight: bold; text-align: center; }
tr.bg0 { background-color: #FFFFFF; }
tr.bg1 { background-color: #F0F0F0; }
.empty_table { text-align: center; }
tfoot tr { background-color: #E8E8E8; font-weight: bold; }
.number { mso-number-format:\#\,\#\#0; , text-align: right; }
</style>
<table cellspacing="0" cellpadding="0">
<caption>주문 내역 목록</caption>
<thead>
<tr>
<th style="width: 120px;">주문일</th>
<th style="width: 100px;">주문자</th>
<th style="width: 200px;">주문자전화</th>
<th style="width: 400px;">상품명</th>
<th style="width: 150px;">옵션</th>
<th style="width: 100px;">단가</th>
<th style="width: 100px;">주문수량</th>
<th style="width: 200px;">총금액</th>
</tr>
</thead>
<tbody>
<?php
$tot_ct_qty = 0;
$tot_orderprice = 0;
$prev_od_id = '';
$bg_class = 'bg0';
for ($i=0; $row=sql_fetch_array($result); $i++) {
// 같은 주문번호 중 첫 번째 행만 출력
if ($row['od_id'] != $prev_od_id) {
$order_date = substr($row['od_receipt_time'], 0, 10);
$order_name = get_text($row['od_name']);
$order_tel = add_hyphen(get_text($row['od_hp']));
// 주문번호가 바뀔 때마다 배경색 토글
$bg_class = ($bg_class === 'bg0') ? 'bg1' : 'bg0';
} else {
$order_date = '';
$order_name = '';
$order_tel = '';
}
$it_name = $row['it_name'];
$io_id = isset($row['io_id']) ? $row['io_id'] : '';
$unit_price = $row['io_price'] ? ($row['ct_price'] + $row['io_price']) : $row['ct_price'];
$qty = $row['ct_qty'];
$total_price = $unit_price * $qty;
$tot_ct_qty += $qty;
$tot_orderprice += $total_price;
$prev_od_id = $row['od_id'];
?>
<tr class="<?php echo $bg_class; ?>">
<td><?php echo $order_date; ?></td>
<td><?php echo $order_name; ?></td>
<td><?php echo $order_tel; ?></td>
<td><?php echo $it_name; ?></td>
<td><?php echo $io_id; ?></td>
<td class="number"> <?php echo number_format($unit_price); ?></td>
<td style="text-align: center;"> <?php echo $qty; ?></td>
<td class="number"> <?php echo number_format($total_price); ?></td>
</tr>
<?php
}
sql_free_result($result);
if ($i == 0)
echo '<tr class="bg0"><td colspan="8" class="empty_table">자료가 없습니다.</td></tr>';
?>
</tbody>
<tfoot>
<tr>
<th colspan="6" style="text-align: center;">합 계</th>
<th style="text-align: center;"><?php echo $tot_ct_qty; ?></th>
<th class="number"><?php echo number_format($tot_orderprice); ?></th>
</tr>
</tfoot>
</table>