  <?php require_once('../Connections/BE2.php'); ?>
<?php
include "../config.data.php"; 
$sqltext='';
/*
if (isset($_POST['s1'])){
	 if($_POST['s1']<>''){ $sqltext=sprintf(" AND order_check = '%s' ",$_POST['s1']); }
     if($_POST['s2']<>''){ $sqltext.=sprintf(" AND mem_name = '%s' ",$_POST['s2']); }
	 if($_POST['s3']<>''){ $sqltext.=sprintf(" AND order_num = '%s' ",$_POST['s3']); }
	 
	}
*/
 
$currentPage = "mysale1.html";//$_SERVER["PHP_SELF"];  
$maxRows_Rt2 = 10;
$pageNum_Rt2 = 0;
if (isset($_GET['pageNum_Rt2'])) {
  $pageNum_Rt2 = $_GET['pageNum_Rt2'];
}
$startRow_Rt2 = $pageNum_Rt2 * $maxRows_Rt2;
 
 
  
$colname_Rt2 = "-1";
if (isset( $_SESSION['login_memid']  )) {
  $colname_Rt2 =  $_SESSION['login_memid']  ;
}

$colname_Rt2=-1;
mysql_select_db($database_BE2, $BE2);
$query_Rt2 = sprintf("SELECT a.*,b.p_count,b.p_money,b.p_percent,c.p_title,c.p_num,d.scode as dscode,d.mem_name as dname FROM order_datam as a,order_datas as b,product_data as c,member as d WHERE a.dcode=b.dcode AND b.mem_auto=c.mem_auto AND c.company_num='%s' AND a.duser=d.mem_auto %s ORDER BY a.dcode DESC",$_SESSION['login_memid'],$sqltext); ;//,$colname_Rt2
 
//$query_Rt2 = sprintf("SELECT * FROM product_order_data WHERE company_num='%s' %s ORDER BY mem_auto DESC",$_SESSION['login_memid'],$sqltext);//,$colname_Rt2

$query_limit_Rt2 = sprintf("%s LIMIT %d, %d", $query_Rt2, $startRow_Rt2, $maxRows_Rt2);
$Rt2 = mysql_query($query_limit_Rt2, $BE2) or die(mysql_error());
$row_Rt2 = mysql_fetch_assoc($Rt2);

echo $query_Rt2;

if (isset($_GET['totalRows_Rt2'])) {
  $totalRows_Rt2 = $_GET['totalRows_Rt2'];
} else {
  $all_Rt2 = mysql_query($query_Rt2);
  $totalRows_Rt2 = mysql_num_rows($all_Rt2);
}
$totalPages_Rt2 = ceil($totalRows_Rt2/$maxRows_Rt2)-1;


$queryString_Rt2 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Rt2") == false && 
	//   stristr($param, "act") == false && 
        stristr($param, "totalRows_Rt2") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Rt2 = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_Rt2 = sprintf("&totalRows_Rt2=%d%s", $totalRows_Rt2, $queryString_Rt2);
?> 
					    
 <div class="main "> 
 
 <div class="row">
 <div class="col-lg-12">				    
<a style="cursor: pointer" ><b><font color="blue">產品資訊</font></b></a></p>
<a href="#" class="btn btn-3d btn-blue btn-md">新增產品資訊</a>
<a href="#" class="btn btn-3d btn-red btn-md" target="_blank">商品進銷存</a>
<? // echo $query_Rt21 ; ?>
 <div class="table-responsive">
<form action="mysale.html" method="POST" name="form2">
	<table class="table table-bordered table-hover">
		<tbody>
		<tr>
			<td>訂單狀態
			<select class="form-control select" name="s1" id="s1">
				<option value="">請選擇</option>
				<option value="訂購中">訂購中</option>
				<option value="未付款">未付款</option>
				<option value="付款成功">付款成功</option>
				<option value="付款失敗">付款失敗</option>
				<option value="取消訂單">取消訂單</option>
				<option value="已出貨">已出貨</option>
				<option value="訂單完成">訂單完成</option>
				<option value="退貨">退貨</option>
			</select>
			</td>
			<td>訂購人姓名<input name="s2" type="text" id="s2" class="form-control"></td>
			<td>訂單編號<input name="s3" type="text" id="s3" class="form-control"></td>
		  <td><br><input type="submit" name="Submit" value="搜尋" class="btn btn-3d btn-black btn-md"></td>
		</tr>
		</tbody>
	</table>
</form>
</div>
<div style="overflow:scroll;">
<table class="table table-bordered table-striped table-condensed table-hover" style="min-width:2000px;">
	<thead>
		<tr>
			<th width="65" rowspan="2">訂單日期</th>
			<th colspan="2">訂購人</th>
			<th width="65" rowspan="2">訂單編號</th>
			<th width="65" rowspan="2">商品名稱</th>
			<th width="65" rowspan="2">商品貨號</th>
			<th width="19" rowspan="2">數量</th>
			<th width="19" rowspan="2">單價</th>
			<th width="19" rowspan="2">金額</th>
			<th width="19" rowspan="2">物流</th>
			<th width="19" rowspan="2">總金額</th>
			<th width="19" rowspan="2">結存</th>
			<th width="15" rowspan="2">交易完成</th>
			<th width="15" rowspan="2">入帳日</th>
			<th width="15" rowspan="2">入帳銀行</th>
			<th width="16" rowspan="2" nowrap="nowrap">付款模式</th>
			<th width="65" rowspan="2">金流費用</th>
			<th width="65" rowspan="2">回饋金</th>
			<th width="19" rowspan="2">抽成獎金</th>
			<th width="19" rowspan="2">匯費</th>
			<th width="65" rowspan="2">人帳金額</th>
			<th width="105" rowspan="2">物流費用 </th>
            <th width="104" rowspan="2">單筆利潤 </th>
			<th width="111" rowspan="2">管理</th>
		</tr>
		<tr>
		  <th width="65">會員編號</th>
		  <th width="68">會員姓名</th>
		  </tr>
	</thead>
	<tbody>
    <?php 
	if($totalRows_Rt2>0){
	do {   ?>
  <tr>
    <td><?= $row_Rt2['ddate'];?></td>
    <td><?= $row_Rt2['dscode'];?></td>
    <td><?= $row_Rt2['dname'] ;?></td>
    <td><?= $row_Rt2['dcode'];?></td>
    <td><?= $row_Rt2['p_title'];?></td>
    <td><?= $row_Rt2['p_num'];?></td>
    <td><?= $row_Rt2['p_count'];?></td>
    <td><?= $row_Rt2['p_money'];?></td>
    <td><?= $row_Rt2['p_count']*$row_Rt2['p_money'] ;?></td>
    <td><?= $row_Rt2['dexpess'];?></td>
    <td><?= $row_Rt2['dmoney'];?></td>
    <td>&nbsp;</td>
    <td><?= $row_Rt2['dflag'];?></td>
    <td><?= $row_Rt2['dpaydate'];?></td>
    <td><?= $row_Rt2['dbank'];?></td>
    <td><?= $pay_ar[$row_Rt2['dpay']];?></td>
    <td>&nbsp;</td>
    
    
    
    <td>&nbsp;</td>
    <td><?= $row_Rt2['p_percent'];?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><a href="#" target="_self">訂單明細</a>
        <a href="#" target="_self">編輯訂</a>
        <a href="#" target="_self">刪除</a>
    </td>
  </tr>
    <?php } while ($row_Rt2 = mysql_fetch_assoc($Rt2));
	}
	 ?>
    <tbody>
</table>

</div>

 </div>
 <ul class="pagination">
                    <?   
                     if( $totalPages_Rt2 >1){	 
						    //分頁程式
if($totalPages_Rt2<5){
		 $start=0;
		 $end=$totalPages_Rt2;
		}else{  
	    $start=$pageNum_Rt2-5;
		$end=$pageNum_Rt2+5;
        if ($start<0){
		 $start=0;
		 $end=10; } 
		 else { $end=$start+10 ;}
		 if ($end>$totalPages_Rt2){ 
		   $start = $end-$totalPages_Rt2-5;
		   $end=$totalPages_Rt2;
		   }
		 if ($end-$start>10){ 
		   $start = $end-10;
		   }  
		 } ?> 
                     <?php if ($pageNum_Rt2 > 0) { // Show if not first page ?>
                     <li><a href="<?php printf("%s?pageNum_Rt2=%d%s", $currentPage, max(0, $pageNum_Rt2 - 1), $queryString_Rt2); ?>">上一頁</a></li><?php } // Show if not first page ?>
                    	<?	   
		for($i=$start;$i<=$end;$i++){
		if($i==$pageNum_Rt2){ echo '<li class="active"><a href="#">'.($i+1).'</a></li>';} else {?>
            <li><a href="<?php printf("%s?pageNum_Rt2=%d%s", $currentPage, min($totalPages_Rt2, $i), $queryString_Rt2); ?>"><? echo $i+1 ;?></a></li>
                 
                        <?	}   }  ?>

                      <?php if ($pageNum_Rt2 < $totalPages_Rt2) { // Show if not last page ?>
                          <li><a href="<?php printf("%s?pageNum_Rt2=%d%s", $currentPage, min($totalPages_Rt2, $pageNum_Rt2 + 1), $queryString_Rt2); ?>">下一頁</a></li>
                        <?php }  
						             } ?>
								
						  </ul>
   </div> 
		</div>
<?php
mysql_free_result($Rt2);
  
?>        
        
 