Files
firstgarden-web-gnu/adm/shop_admin/orderprintresult.php

383 lines
14 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?
$sub_menu = '500120';
include_once('./_common.php');
auth_check($auth[$sub_menu], "r");
//print_r2($_GET); exit;
/*
function multibyte_digit($source)
{
$search = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
$replace = array("","","","","","","","","","");
return str_replace($search, $replace, (string)$source);
}
*/
function conv_telno($t)
{
// 숫자만 있고 0으로 시작하는 전화번호
if (!preg_match("/[^0-9]/", $t) && preg_match("/^0/", $t)) {
if (preg_match("/^01/", $t)) {
$t = preg_replace("/([0-9]{3})(.*)([0-9]{4})/", "\\1-\\2-\\3", $t);
} else if (preg_match("/^02/", $t)) {
$t = preg_replace("/([0-9]{2})(.*)([0-9]{4})/", "\\1-\\2-\\3", $t);
} else {
$t = preg_replace("/([0-9]{3})(.*)([0-9]{4})/", "\\1-\\2-\\3", $t);
}
}
return $t;
}
// 1.04.01
// MS엑셀 CSV 데이터로 다운로드 받음
if ($csv == 'csv')
{
$fr_date = date_conv($fr_date);
$to_date = date_conv($to_date);
$sql = " SELECT od_b_zip1, od_b_zip2, od_b_addr1, od_b_addr2, od_b_name, od_b_tel, od_b_hp, it_name, ct_qty, b.it_id, a.od_id, od_memo, od_invoice
FROM {$g4['shop_order_table']} a, {$g4['shop_cart_table']} b, {$g4['shop_item_table']} c
where a.uq_id = b.uq_id
and b.it_id = c.it_id ";
if ($case == 1) // 출력기간
$sql .= " and a.od_time between '$fr_date 00:00:00' and '$to_date 23:59:59' ";
else // 주문번호구간
$sql .= " and a.od_id between '$fr_od_id' and '$to_od_id' ";
if ($ct_status)
$sql .= " and b.ct_status = '$ct_status' ";
$sql .=" order by od_time asc ";
$result = sql_query($sql);
$cnt = @mysql_num_rows($result);
if (!$cnt)
alert("출력할 내역이 없습니다.");
//header('Content-Type: text/x-csv');
header("Content-charset=utf-8");
header('Content-Type: doesn/matter');
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Content-Disposition: attachment; filename="' . date("ymd", time()) . '.csv"');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
//echo "우편번호,주소,이름,전화1,전화2,상품명,수량,비고,전하실말씀\n";
echo "우편번호,주소,이름,전화1,전화2,상품명,수량,상품코드,주문번호,운송장번호,전하실말씀\n";
for ($i=0; $row=mysql_fetch_array($result); $i++)
{
echo '"' . $row['od_b_zip1'] . '-' . $row['od_b_zip2'] . '"' . ',';
echo '"' . $row['od_b_addr1'] . ' ' . $row['od_b_addr2'] . '"' . ',';
echo '"' . $row['od_b_name'] . '"' . ',';
//echo '"' . multibyte_digit((string)$row[od_b_tel]) . '"' . ',';
//echo '"' . multibyte_digit((string)$row[od_b_hp]) . '"' . ',';
echo '"' . conv_telno($row['od_b_tel']) . '"' . ',';
echo '"' . conv_telno($row['od_b_hp']) . '"' . ',';
echo '"' . preg_replace("/\"/", "&#034;", $row['it_name']) . '"' . ',';
echo '"' . $row['ct_qty'] . '"' . ',';
echo '"\'' . $row['it_id'] . '\'"' . ',';
echo '"\'' . $row['od_id'] . '\'"' . ',';
echo '"' . $row['od_invoice'] . '"' . ',';
//echo '"' . preg_replace("/\"/", "&#034;", preg_replace("/\n/", "", $row[od_memo])) . '"';
echo '"' . preg_replace("/\"/", "&#034;", $row['od_memo']) . '"';
echo "\n";
}
if ($i == 0)
echo "자료가 없습니다.\n";
exit;
}
// MS엑셀 XLS 데이터로 다운로드 받음
if ($csv == 'xls')
{
$fr_date = date_conv($fr_date);
$to_date = date_conv($to_date);
$sql = " SELECT od_b_zip1, od_b_zip2, od_b_addr1, od_b_addr2, od_b_name, od_b_tel, od_b_hp, it_name, ct_qty, b.it_id, a.od_id, od_memo, od_invoice, b.it_opt1, b.it_opt2, b.it_opt3, b.it_opt4, b.it_opt5, b.it_opt6
FROM {$g4['shop_order_table']} a, {$g4['shop_cart_table']} b, {$g4['shop_item_table']} c
where a.uq_id = b.uq_id
and b.it_id = c.it_id ";
if ($case == 1) // 출력기간
$sql .= " and a.od_time between '$fr_date 00:00:00' and '$to_date 23:59:59' ";
else // 주문번호구간
$sql .= " and a.od_id between '$fr_od_id' and '$to_od_id' ";
if ($ct_status)
$sql .= " and b.ct_status = '$ct_status' ";
$sql .=" order by od_time asc ";
$result = sql_query($sql);
$cnt = @mysql_num_rows($result);
if (!$cnt)
alert("출력할 내역이 없습니다.");
header("Content-charset=utf-8");
header('Content-Type: application/vnd.ms-excel');
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Content-Disposition: attachment; filename="' . date("ymd", time()) . '.xls"');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
echo "<html>";
echo "<head>";
echo "<title>xls</title>";
echo "<style>.txt {mso-number-format:'\\@';}</style>";
echo "</head>";
echo "<body>";
echo '<table class="frm_tbl">';
echo "<tr>";
echo "<td>우편번호</td>";
echo "<td>주소</td>";
echo "<td>이름</td>";
echo "<td>전화1</td>";
echo "<td>전화2</td>";
echo "<td>상품명</td>";
echo "<td>수량</td>";
echo "<td>상품코드</td>";
echo "<td>주문번호</td>";
echo "<td>운송장번호</td>";
echo "<td>전하실말씀</td>";
echo "</tr>";
for ($i=0; $row=mysql_fetch_array($result); $i++)
{
$it_name = stripslashes($row['it_name']) . "<br />";
$it_name .= print_item_options($row['it_id'], $row['it_opt1'], $row['it_opt2'], $row['it_opt3'], $row['it_opt4'], $row['it_opt5'], $row['it_opt6']);
echo "<tr>";
echo "<td>" . $row['od_b_zip1'] . '-' . $row['od_b_zip2'] . "</td>";
echo "<td>" . $row['od_b_addr1'] . ' ' . $row['od_b_addr2'] . "</td>";
echo "<td>" . $row['od_b_name'] . "</td>";
echo "<td class='txt'>" . $row['od_b_tel'] . "</td>";
echo "<td class='txt'>" . $row['od_b_hp'] . "</td>";
echo "<td>" . $it_name . "</td>";
echo "<td>" . $row['ct_qty'] . "</td>";
echo "<td class='txt'>" . $row['it_id'] . "</td>";
echo "<td class='txt'>'" . urlencode($row['od_id']) . "'</td>";
echo "<td class='txt'>" . $row['od_invoice'] . "</td>";
echo "<td>" . $row['od_memo'] . "</td>";
echo "</tr>";
}
if ($i == 0)
echo '<tr><td colspan="11">자료가 없습니다.</td></tr>';
echo "</table>";
echo "</body>";
echo "</html>";
exit;
}
function get_order($uq_id)
{
global $g4;
$sql = " select * from {$g4['shop_order_table']} where uq_id = '$uq_id' ";
return sql_fetch($sql);
}
$g4['title'] = "주문내역";
include_once(G4_PATH.'/head.sub.php');
if ($case == 1)
{
$fr_date = date_conv($fr_date);
$to_date = date_conv($to_date);
$sql = " SELECT DISTINCT a.uq_id FROM {$g4['shop_order_table']} a, {$g4['shop_cart_table']} b
where a.uq_id = b.uq_id
and a.od_time between '$fr_date 00:00:00' and '$to_date 23:59:59' ";
}
else
{
$sql = " SELECT DISTINCT a.uq_id FROM {$g4['shop_order_table']} a, {$g4['shop_cart_table']} b
where a.uq_id = b.uq_id
and a.od_id between '$fr_od_id' and '$to_od_id' ";
}
if ($ct_status)
$sql .= " and b.ct_status = '$ct_status' ";
$sql .= " order by a.od_id ";
$result = sql_query($sql);
if (mysql_num_rows($result) == 0)
{
echo "<script>alert('출력할 내역이 없습니다.'); window.close();</script>";
exit;
}
?>
<style type="text/css">
#orderprint{width:900px}
</style>
<section id="orderprint" class="cbox">
<h2>
<?
if ($case == 1)
echo "[ $fr_date - $to_date $ct_status 내역 ]";
else
echo "[ $fr_od_id - $to_od_id $ct_status 내역 ]";
?>
</h2>
<table class="frm_tbl">
<colgroup>
<col class="grid_3">
<col class="grid_2">
<col class="grid_5">
<col class="grid_2">
<col class="grid_2">
</colgroup>
<tbody>
<tr>
<th scope="row" rowspan="2">주문번호</th>
<td>보낸분</td>
<td>주소</td>
<td>전화번호</td>
<td>핸드폰</td>
</tr>
<tr>
<td>받는분</td>
<td>주소</td>
<td>전화번호</td>
<td>핸드폰</td>
</tr>
<?
$mod = 10;
$tot_total_amount = 0;
for ($i=0; $row=sql_fetch_array($result); $i++)
{
$sql1 = " select * from {$g4['shop_order_table']} where uq_id = '{$row['uq_id']}' ";
$row1 = sql_fetch($sql1);
// 1.03.02
$row1['od_addr'] = "(".$row1['od_zip1']."-".$row1['od_zip2'].") ".$row1['od_addr1']." ".$row1['od_addr2'];
$row1['od_b_addr'] = "(".$row1['od_b_zip1']."-".$row1['od_b_zip2'].") ".$row1['od_b_addr1']." ".$row1['od_b_addr2'];
$row1['od_addr'] = ($row1['od_addr']) ? $row1['od_addr'] : "&nbsp;";
$row1['od_tel'] = ($row1['od_tel']) ? $row1['od_tel'] : "&nbsp;";
$row1['od_hp'] = ($row1['od_hp']) ? $row1['od_hp'] : "&nbsp;";
$row1['od_b_tel'] = ($row1['od_b_tel']) ? $row1['od_b_tel'] : "&nbsp;";
$row1['od_b_hp'] = ($row1['od_b_hp']) ? $row1['od_b_hp'] : "&nbsp;";
if ($row1['od_name'] == $row1['od_b_name']) $row1['od_b_name'] = '"';
if ($row1['od_addr'] == $row1['od_b_addr']) $row1['od_b_addr'] = '"';
if ($row1['od_tel'] == $row1['od_b_tel']) $row1['od_b_tel'] = '"';
if ($row1['od_hp'] == $row1['od_b_hp'] && $row1['od_hp'] != "&nbsp;") $row1['od_b_hp'] = '"';
$od_memo = ($row1['od_memo']) ? stripslashes($row1['od_memo']) : "";
$od_shop_memo = ($row1['od_shop_memo']) ? stripslashes($row1['od_shop_memo']) : "";
?>
<tr>
<th scope="row" rowspan="3"><?=$row1[od_id]?></th>
<td><?=$row1['od_name']?></td>
<td><?=$row1['od_addr']?></td>
<td><?=$row1['od_tel']?></td>
<td><?=$row1['od_hp']?></td>
</tr>
<tr>
<td><?=$row1['od_b_name']?></td>
<td><?=$row1['od_b_addr']?></td>
<td><?=$row1['od_b_tel']?></td>
<td><?=$row1['od_b_hp']?></td>
</tr>
<?
$sql2 = " select a.*,
b.it_opt1_subject,
b.it_opt2_subject,
b.it_opt3_subject,
b.it_opt4_subject,
b.it_opt5_subject,
b.it_opt6_subject,
b.it_name
from {$g4['shop_cart_table']} a, {$g4['shop_item_table']} b
where a.it_id = b.it_id
and a.uq_id = '{$row['uq_id']}' ";
if ($ct_status)
$sql2 .= " and a.ct_status = '$ct_status' ";
$sql2 .= " order by a.ct_id ";
$res2 = sql_query($sql2);
$cnt = $sub_tot_qty = $sub_tot_amount = 0;
while ($row2 = sql_fetch_array($res2))
{
$row2_tot_amount = $row2['ct_amount'] * $row2['ct_qty'];
$sub_tot_qty += $row2['ct_qty'];
$sub_tot_amount += $row2_tot_amount;
$it_name = stripslashes($row2['it_name']);
$it_name = "$it_name ($row2[it_id])";
$str_split = "";
for ($k=1; $k<=6; $k++)
{
if ($row2["it_opt{$k}"] == "") continue;
$it_name .= $str_split;
$it_opt_subject = $row2["it_opt{$k}_subject"];
$opt = explode( ";", trim($row2["it_opt{$k}"]) );
$it_name .= "&nbsp;&nbsp; $it_opt_subject = $opt[0]";
if ($opt[1] != 0)
{
$it_name .= " (";
//if (ereg("[+]", $opt[1]) == true)
if (preg_match("/[+]/", $opt[1]) == true)
$it_name .= "+";
// 금액을 전화문의 표시로
$it_name .= display_amount($opt[1]) . ")";
}
$str_split = "<br />";
}
$it_name .= "";
$fontqty1 = $fontqty2 = "";
if ($row2['ct_qty'] >= 2)
{
$fontqty1 = "";
$fontqty2 = "";
}
?>
<tr>
<td><?=$it_name?></td>
<td><?=number_format($row2['ct_amount'])?></td>
<td><?=$fontqty1?><?=number_format($row2['ct_qty'])?><?=$fontqty2?></td>
<td><?=number_format($row2_tot_amount)?></td>
</tr>
<?
$cnt++;
}
if ($cnt >= 2)
{
?>
<tr>
<th scope="row" colspan="3"><b>합 계</b></th>
<td><?=number_format($sub_tot_qty)?></td>
<td><?=number_format($sub_tot_amount)?></td>
</tr>
<?
}
$tot_tot_qty += $sub_tot_qty;
$tot_tot_amount += $sub_tot_amount;
if ($od_memo) $od_memo = "비고 : $od_memo";
if ($od_shop_memo) $od_shop_memo = "<br />상점메모 : $od_shop_memo";
echo "
$od_memo
$od_shop_memo
";
}
?>
<tr>
<th scope="row" colspan="3">전 체 합 계</th>
<td><?=number_format($tot_tot_qty)?></td>
<td><?=number_format($tot_tot_amount)?></td>
</tr>
</tbody>
</table>
<p>&lt;끝&gt;</p>
</section>
</body>
</html>