<?php  require('system/login.php');  ?>
<?php require_once('../Connections/BE2.php'); ?>

<?php
 
 $sdate=date('Y-m');
 
 if (isset($_GET['sdate'])) {
  $sdate = $_GET['sdate'];
 }
 $sdate0=$sdate.'-15';
 $y=substr($sdate0,0,4);
 $m=substr($sdate0,5,2);
 $sdatex=date("Y-m", mktime(0,0,0,$m-1,1,$y));
 //$sdate2=date("Y-m-d", mktime(0,0,0,$m-1,31,$y));
 
 $query_Rt2 =  sprintf("SELECT * FROM order_datamtmp  where ddate like '%s' order by ddate desc",$sdate.'%') ; 
 mysql_select_db($database_BE2, $BE2);
 $Rt2 = mysql_query($query_Rt2, $BE2) or die(mysql_error());
 $row_Rt2 = mysql_fetch_assoc($Rt2);

 

  header('Content-type:application/vnd.ms-excel');  //宣告網頁格式
  header('Content-Disposition: attachment; filename='.$sdate.'交易詳細結算總表.xls');  //設定檔案名稱

?>
<html>
    <head>
        <meta charset="UTF-8">
    </head>
    <body>
   <?  echo '交易日期為: '.$sdate .'月份'; ?>
    <table border="0" cellpadding="2" cellspacing="2" style="font-size:14px">
  <tr>
    <th width="60" height="28" nowrap>使用點數</th>
    <th width="60" nowrap>物流費用</th>
    <th width="45" nowrap>營業稅</th>
    <th width="60" nowrap>平台抽成</th>
    <th width="60" nowrap>金流費用</th>
    <th width="90" nowrap>服務稅額加總</th>
    <th width="45" nowrap>總金額</th>
    <th width="60" nowrap>付款模式</th>
    <th width="60" nowrap>交易完成</th>
    <th width="60" nowrap>訂單狀態</th>
    <th width="60" nowrap>發票號碼</th>
    <th width="67" nowrap>卡片末5碼</th>
    <th width="60" nowrap>發放獎金</th>
    <th width="60" nowrap>發放點數</th>
    <th width="60" nowrap>結算狀態</th>
    <th width="90" nowrap>本期結算金額</th>
    <th width="60" nowrap>結算日期</th>
    <th width="30" nowrap>備註</th>
  </tr>
    <tr>
    <td height="3" colspan="18" background="images/dot3.gif"></td>
  </tr>
  <?php 
   $pay_ar=array("","信用卡線上刷卡","超商取貨付款","臨櫃匯款","ATM轉帳"); //dpay
   $pp1=array("",'推廣獎金','開發獎金','開發商首推獎金','商品未付餘額','開發商續推獎金','銷售獎金');
  $i=0;
    do { 
   $i++;
  ?>
    <tr onMouseOver="this.style.backgroundColor='#2172A1';" onMouseOut=this.style.backgroundColor="#fff">
      <td height="27" align="center"><?= $row_Rt2['dsky'] ?></td>
      <td height="27" align="center"><?= $row_Rt2['dexpess'] ?></td>
      <td align="center"><?= $row_Rt2['p10'] ?></td>
      <td align="center"><?= $row_Rt2['p05'] ?></td>
      <td align="center"><?= $row_Rt2['p02'] ?></td>
      <td align="center"><?= $row_Rt2['p17'] ?></td>
      <td align="center"><?= $row_Rt2['dall'] ?></td>
      <td align="center" nowrap="nowrap"><?= $pay_ar[$row_Rt2['dpay']] ?></td>
      <td align="center"><?= $row_Rt2['dflag'] ?></td>
      <td align="center">&nbsp;</td>
      <td align="center"><?= $row_Rt2['billcode'] ?></td>
      <td align="center">&nbsp;</td>
      <td align="center"><?= $row_Rt2['pmoney'] ?></td>
      <td align="center"><?= $row_Rt2['ival'] ?></td>
      <td align="center">&nbsp;</td>
      <td align="center">&nbsp;</td>
      <td align="center">&nbsp;</td>
      <td align="center">&nbsp;</td>
    </tr>
  <tr>
    <td height="2" colspan="18" background="images/dot3.gif"></td>
  </tr>	
    <?php   } while ($row_Rt2 = mysql_fetch_assoc($Rt2)); ?>

  <tr>
  <td  colspan="18"  >

   </td>
  </tr>
</table>
  
         
    </body>
          </html> 
  <?php mysql_free_result($Rt2); ?>	