<link href="wstyle.css" rel="stylesheet" type="text/css" />
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationSelect.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css">
<link href="SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css" />
<div align="center">
<? if ($_GET['stat'] == '' ) { ?>
<table width="80%" border="0">
    <tr>
      <td class="td3"><div align="center">Date</div></td>
      <td class="td3"><div align="center">Max</div></td>
      <td class="td3"><div align="center">Reserved</div></td>
      <td class="td3">Remaining</td>
      <td class="td3">Report</td>
    </tr>
				<?	
                        $uid=$_SESSION['Login_uid'];
                        $result = mysql_query('select * from p1_date where date_stop =0 '); 
                        while($row = mysql_fetch_array($result)){ 
                ?>	
    <tr>
      <td class="td2"><? echo $row['date_name']?></td>
      <td class="td2"><?
	  	$did = $row['did'];
      	$query = mysql_query("select sum(max_number) as max1 from p1_default_time , p1_time_date where p1_default_time.tid =  p1_time_date.tid and did = $did");
		echo mysql_result($query,0,"max1");
		
		$max = mysql_result($query,0,"max1");
	  ?></td>
      <td class="td2"><? 
	 	$did = $row['did'];
		
      	$query = mysql_query("select count(*) as max1 from p1_order_info where did = $did and stop1=0 ");
		echo mysql_result($query,0,"max1");
		$max1 = mysql_result($query,0,"max1");

	  ?></td>
      <td class="td2"><? echo $max - $max1;?></td>
      <td class="td2"><a href="index.php?page=23&stat=show&did=<? echo $row['did'] ?>&date_name=<? echo $row['date_name']?>" class="td2">Report</a></td>
    </tr>
				<?
                    }
                ?>
  </table>
<? } if ($_GET['stat'] == 'show' ) { ?>
<table width="40%" border="0">
  <tr>
    <td class="td1">Date</td>
    <td class="td2"><? echo $_GET['date_name'];?></td>
  </tr>
</table>
<br />
<table width="80%" border="0">
    <tr>
      <td class="td3"><div align="center">Full Name</div></td>
      <td class="td3"><div align="center">Total Sales of Plates (BD)*</div></td>
      <td class="td3"><div align="center">Total Sales of screws (BD)*</div></td>
      <td class="td3">More info</td>
    </tr>
				<?	
                        $date_name=$_GET['date_name'];
                        $result = mysql_query("SELECT p1_order_info.Date_a, Sum(plate_price*number_of_plate) AS total1, Sum(BD1+Fiber+frame) AS total2, p1_order_info.uid, p1_powers.fullname FROM p1_powers INNER JOIN (p1_order_info INNER JOIN p1_plate_type ON p1_order_info.Type1 = p1_plate_type.tyid) ON p1_powers.uid = p1_order_info.uid where Date_a = '".$date_name."' and p1_order_info.stop1 = 0  GROUP BY p1_order_info.Date_a, p1_order_info.uid, p1_powers.fullname"); 
                        while($row = mysql_fetch_array($result)){ 
                ?>	
    <tr>
      <td class="td2"><? echo $row['fullname']?></td>
      <td class="td2"><? echo $row['total1']?></td>
      <td class="td2"><? echo $row['total2']?></td>
      <td class="td2"><a href="index.php?page=23&stat=moreinfo&date_name=<? echo $date_name?>&uid=<? echo $row['uid']?>" class="text1">More info</a></td>
    </tr>
				<?
				
						$total1 = $total1 +  $row['total1'];
						$total2 = $total2 +  $row['total2'];
				
                    }
                ?>
    <tr>
      <td></td>
      <td class="td3"><? echo $total1 ?></td>
      <td class="td3"><? echo $total2?></td>
      <td class="td3">&nbsp;</td>
    </tr>
  </table>

<? } if ($_GET['stat'] == 'moreinfo' ) { ?>
    <table width="100%" border="0">
      <tr>
        <td class="td1">ID</td>
        <td class="td1">Time</td>
        <td class="td1">Plate No.</td>
        <td class="td1">Type</td>
        <td colspan="2" class="td1">Size</td>
        <td class="td1">urgency</td>
        <td class="td1">price</td>
        <td class="td1">Fixing new / screws</td>
      </tr>
      <?
                        $date_name=$_GET['date_name'];
						$uid = $_GET['uid'];
            $result = mysql_query("select * from p1_order_info where Date_a = '".$date_name."' and uid = ".$uid." and p1_order_info.stop1 = 0");
            while($row = mysql_fetch_array($result)){ 
        
        ?>
      <tr <? if( $row['Type2'] == '1') { ?>class="td4" <? }else{ ?> class="td2" <? } ?>>
        <td><? echo $row['oid']; ?></td>
        <td><div align="center"><? echo $row['Time_a']; ?></div></td>
        <td><div align="center"><? echo $row['Plate']; ?></div></td>
        <td><div align="center">
          <div align="center" class="p_c<? echo $row['Type1']?>">
              <?	
                        $result1 = mysql_query('select * from p1_plate_type where tyid = '.$row['Type1']); 
                        while($row1 = mysql_fetch_array($result1)){ 
                				echo $row1['plate_type'] ;
								$plate_price = $row1['plate_price'];
            
					}
				?>
            </div>
        </div></td>
        <td><div align="center"><? echo $row['Size1']; ?></div></td>
        <td><div align="center"><? echo $row['Size2']; ?></div></td>
        <td><? if( $row['Type2'] == '1') { ?>
          Yes
            <? }else{ ?>
          No
          <? } ?></td>
        <td><? echo $plate_price * $row['number_of_plate']?></td>
        <td><? echo $row['BD1']?></td>
      </tr>
      <?
	  
	  $total_price = $total_price +$plate_price* $row['number_of_plate'];
	  $BD1 = $BD1 + $row['BD1'];
			}
		
		?>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td class="td_print1">Total</td>
        <td class="td_print1">&nbsp;<? echo $total_price ?></td>
        <td class="td_print1">&nbsp;<? echo  $BD1 ?></td>
      </tr>
    </table>
    <? } ?>
  
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</div>