<?php require_once('../Connections/BE2.php'); ?>
<?php
   if (!isset($_SESSION)){ session_start(); }

$sdate='-1';
 if (isset($_GET['sdate'])) {
  $sdate = $_GET['sdate'];
 }
 
  header('Content-type:application/vnd.ms-excel');  //宣告網頁格式
  header('Content-Disposition: attachment; filename='.$sdate.'會員獎金報表.xls');  //設定檔案名稱
 

mysql_select_db($database_BE2, $BE2);

$query_Rt2 = sprintf("SELECT a.*,b.dcode,b.p_money,b.p_count,c.p_title from order_percent as a, order_datas as b,product_data as c where a.ccid=b.ccid AND b.mem_auto=c.mem_auto AND a.pdate like '%s' AND a.puid='%s' ORDER BY a.pdate DESC",$sdate.'%',$_SESSION['login_memid']); 
$Rt2 = mysql_query($query_Rt2, $BE2) or die(mysql_error());
$row_Rt2 = mysql_fetch_assoc($Rt2);
$totalRows_Rt2=mysql_num_rows($Rt2);
 
 
?>	
		<!-- start: Content -->
		<div class="main ">

			<div class="row">	
				<div class="col-md-12">
					<div class="panel panel-default">
						<div class="panel-heading">
							<h2><i class="fa fa-list red"></i><span class="break"></span><strong><?= $sdate?>月份 奨金記錄清單</strong></h2>
						</div>


						<div class="panel-body">

					<h3 class="panel-title">&nbsp;</h3>
					            <div class="clearfix"></div>  
     
     
                     <div style="overflow:scroll;">
				 <table class="table table-striped table-bordered bootstrap-datatable" style="min-width:700px;">
 
						<thead>
							<tr class="replace-inputs">
                                 <th class="center">#</th>
                                 <th align="center" nowrap="nowrap">訂單號</th>
								 <th align="center">訂單日期</th>
						         <th align="center">商品說明</th>
								 <th align="center">商品金額</th>
								 <th align="center">數量</th>
								 <th align="center">推廣/開發</th>
								 <th align="center">金額</th>
								 <th align="center">未繳商品餘額</th>
								<? /* <th align="center">已申請</th> */ ?>
                                 
							</tr>
						</thead>
						<tbody>
                           <?php 
						   //              1         2         3          4            5              6
						   $pp1=array("",'推廣獎金','經銷獎金','開發商首推獎金','商品未付餘額','開發商續推獎金','銷售獎金');
						    // ($row_Rt2['pkid']==2)?'開發獎金':'推廣獎金'
						    $pmoney=0;
							$demoney=0;
							if($totalRows_Rt2>0){
							$i=0;	
							
						 do { $i++;
						    
						     $pmoney = $pmoney+$row_Rt2['pmoney'];
							 $demoney = $demoney+$row_Rt2['depmoney'];  
						   ?>
							<tr>
                             <td class="center"><?= $i ?></td>
						     <td>'<?= $row_Rt2['dcode'] ?></td>
						     <td><?= $row_Rt2['pdate'];?></td>
						     <td><?= $row_Rt2['p_title'];?></td>
						     <td align="right"><?= $row_Rt2['p_money'];?></td>
						     <td align="right"><?= $row_Rt2['p_count'];?></td>
						     <td align="right"><?= $pp1[$row_Rt2['pkid']] ;?></td>
						     <td align="right"><?= $row_Rt2['pmoney']; ?></td>
						     <td align="right"><?= $row_Rt2['depmoney']; ?></td>
				 
							</tr>
						
                        <?php } while ($row_Rt2 = mysql_fetch_assoc($Rt2)); ?>
							
							<tr>
                             <td class="center">&nbsp;</td>
						     <td>本頁累計</td>
						     <td>&nbsp;</td>
						     <td>&nbsp;</td>
						     <td align="right">&nbsp;</td>
						     <td align="right">&nbsp;</td>
						     <td align="right">&nbsp;</td>
						     <td align="right"><?= $pmoney; ?></td>
						     <td align="right"><?= $demoney ?></td>
					 
							</tr>
						<?	}
						  	?></tbody>
                       
					</table>
                     <div class="form-group form-actions col-md-6 ">
                    
                    發放推廣獎金申請，根據申請當下幾月，會在下一個月15號錢匯入指定帳戶(例如1月申請，在1月底的時候會有總表出來，在2月15之前會匯入指定帳戶)
                    </div>
				  <? /* if($pmoney<0){?>	
                    <div class="form-group form-actions col-md-5 ">
						 
				        <input type="button" name="Sub1" value="申請提領獎金" class="btn btn-3d btn-black btn-md" onclick="location.href='percent2cash.html'">        
                                </div>
                   <div class="form-group form-actions col-md-5">
						 <input type="button" name="Sub2" value="獎金轉入雲點數" class="btn btn-3d btn-black btn-md" onclick="location.href='percent2point.html'">
				                轉為雲點數將無法再轉為獎金</div>  
                 <?  } */ ?>                          		      
                   

                   </div>



					  </div>
					</div>
				</div><!--/col-->
			
			</div><!--/row-->

    
		</div>
		 
		<!-- end: Content -->
 