<?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 a.coid,SUBSTRING(a.ddate, 1, 7) as ddate2,count(a.coid) as coid2,sum(a.dmoney) as dmoney,sum(a.dsky) as dsky,sum(a.dexpess) as dexpess,sum(a.p10) as p10,sum(a.p05) as p05,sum(a.p02) as p02,sum(a.p17) as p17,b.company_title FROM order_datamtmp as a,company as b where a.coid=b.coid AND a.ddate like '%s' group by a.coid,ddate2",$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 height="28" nowrap>商品廠商</th>
    <th nowrap>月份</th>
    <th nowrap>訂單數量</th>
    <th nowrap>商品金額加總</th>
    <th nowrap>退貨款金額加總</th>
    <th nowrap>使用點數加總</th>
    <th nowrap>物流費用加總</th>
    <th nowrap>營業稅加總</th>
    <th nowrap>平台抽成加總</th>
    <th nowrap>金流費用加總</th>
    <th nowrap>服務稅額總金額</th>
    <th nowrap>本期結算金額</th>
    <th nowrap>結算狀態</th>
    <th nowrap>結算日期</th>
    <th nowrap>備註</th>

  </tr>
    <tr>
    <td height="3" colspan="15" background="images/dot3.gif"></td>
  </tr>
  <?php 
 
  $i=0;
    do { 
   $i++;
  ?>
    <tr onMouseOver="this.style.backgroundColor='#2172A1';" onMouseOut=this.style.backgroundColor="#fff">
      <td height="27" align="center"><?= $row_Rt2['company_title'] ?></td>
      <td height="27" align="center">'<?= $row_Rt2['ddate2'] ?></td>
      <td align="center"><?= $row_Rt2['coid2'] ?></td>
      <td align="center"><?= $row_Rt2['dmoney'] ?></td>
      <td align="center">&nbsp;</td>
      <td align="center"><?= $row_Rt2['dsky'] ?></td>
      <td align="center" nowrap="nowrap"><?= $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">&nbsp;</td>
      <td align="center">&nbsp;</td>
      <td align="center">&nbsp;</td>
      <td align="center">&nbsp;</td>
 
    </tr>
  <tr>
    <td height="2" colspan="15" background="images/dot3.gif"></td>
  </tr>	
    <?php  } while ($row_Rt2 = mysql_fetch_assoc($Rt2)); ?>

  <tr>
   <td  colspan="15"  >&nbsp;</td>
  </tr>
</table>
  
         
    </body>
          </html> 
  <?php mysql_free_result($Rt2); ?>	