<?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.pmoon,a.puid,a.pmoney,a.pnow,a.pall,d.scode,d.mem_user2,d.m_bankcode,d.m_bankname,d.m_bank,d.m_bank2 from order_permoon as a, member as d where a.pall<>0 AND a.puid=d.mem_auto AND a.pmoon='%s' group by a.puid ORDER BY a.puid",$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">
      <tr>
        <th width="38" height="28" nowrap class="font2">會員</th>
        <th width="76" nowrap class="font2">會員姓名</th>
        <th width="76" nowrap class="font2">上月餘額</th>
        <th width="76" nowrap class="font2">本月金額</th>
        <th width="76" nowrap class="font2">加總金額</th>
        <th width="76" nowrap class="font2">所得稅10%</th>
        <th width="76" nowrap class="font2">平台服務費5%</th>
        <th width="76" nowrap class="font2">金流服務費2.8%</th>
        <th width="76" nowrap class="font2">應發獎金</th>
        <th width="76" nowrap class="font2">月份</th>
        <th width="76" nowrap class="font2">匯款戶名</th>
        <th width="76" nowrap class="font2">匯款銀行</th>
        <th width="76" nowrap class="font2">銀行代碼</th>
        <th width="76" nowrap class="font2">匯款帳號</th>
        <th width="76" nowrap class="font2">證件資料</th>
      </tr>
      <?php 
   $pp1=array("",'推廣獎金','開發獎金','開發商首推獎金','商品未付餘額','開發商續推獎金','銷售獎金');
  $i=0;
   do { 
   $i++;
  ?>
      <tr>
        <td height="27">'<?= $row_Rt2['scode']; ?> </td>
        <td height="27"><?= $row_Rt2['mem_user2']; ?></td>
        <td align="center"><?= $row_Rt2['pmoney']; ?></td>
        <td align="center"><?= $row_Rt2['pnow']; ?></td>
        <td align="center"><?= $row_Rt2['pall']; ?></td>
        <td align="center"><?= ($row_Rt2['pall']>0)?($row_Rt2['pall']*0.10):'0'; ?></td>
        <td align="center"><?= ($row_Rt2['pall']>0)?($row_Rt2['pall']*0.05):'0'; ?></td>
        <td align="center"><?= ($row_Rt2['pall']>0)?($row_Rt2['pall']*0.028):'0'; ?></td>  
        <td align="center"><?= ($row_Rt2['pall']>0)? $row_Rt2['pall']-($row_Rt2['pall']*0.178):'0'; ?></td>                        
        <td align="center"><?= "'".$row_Rt2['pmoon']; ?></td>
        <td align="center"><?= $row_Rt2['m_bankname']; ?></td>
        <td align="center"><?= $row_Rt2['m_bank']; ?></td>
        <td align="center"><?= $row_Rt2['m_bank2']; ?></td>
        <td align="center"><?= $row_Rt2['m_bankcode']; ?></td>
        <td align="center"><a href="https://www.skybni.com/guest/profiledoc.php?id=<?= $row_Rt2['scode']; ?>">證件資料</a></td>
      </tr>

      <?php } while ($row_Rt2 = mysql_fetch_assoc($Rt2)); ?>
      <tr>
        <td colspan="11"></td>
      </tr>
    </table>
  
         
    </body>
          </html> 
  <?php mysql_free_result($Rt2); ?>	