<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">
<p>
  <? if ($_GET['stat'] == '' ) { ?>
</p>
<form id="form1" name="form1" method="post" action="index.php?page=58&stat=moreinfo">
  <table width="50%" border="0">
    <tr>
      <td class="td1">From</td>
      <td class="td2"><span id="sprytextfield3">
      <input type="text" name="From" id="From" />
      <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span><span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></td>
    </tr>
    <tr>
      <td class="td1">TO</td>
      <td class="td2"><span id="sprytextfield4">
      <input type="text" name="To" id="To" />
      <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span><span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></td>
    </tr>
    <tr>
      <td class="td1">User</td>
      <td class="td2"><select name="uid" id="uid">
        <option value="0">All</option>
       
        <?
                        $result = mysql_query("SELECT * from p1_powers where stop_user = 0 "); 
                        while($row = mysql_fetch_array($result)){ 
      				?>
                     <option value="<? echo $row['uid'];?>"><? echo $row['fullname']?></option>
                    <? } ?>
      </select>      </td>
    </tr>
    <tr>
      <td class="td1">Only Total</td>
      <td class="td2"><label>
        <input name="only_total" type="checkbox" id="only_total" value="1" />
      </label></td>
    </tr>
  </table>
  <p>
    <input name="Submit" type="submit" class="Submit" id="Submit" value="    Create    " />
  </p>
</form>
 
<? } if ($_GET['stat'] == 'moreinfo' ) { ?>
  <br />
    <br />
    <span class="link">Appointments , VIP , Agent</span><br />
    <br />
    <table width="100%" border="0">
      <tr>
        <td rowspan="2" class="td1">ID</td>
        <td rowspan="2" class="td1">Date</td>
        <td rowspan="2" class="td1">Invoice No.</td>
        <td rowspan="2" class="td1">Plate No.</td>
        <td rowspan="2" class="td1">Type</td>
        <td colspan="2" class="td1">Size</td>
        <td rowspan="2" class="td1">urgency</td>
        <td rowspan="2" class="td1">price</td>
        <td rowspan="2" class="td1">Fixing new / screws</td>
        <td width="10%" rowspan="2" class="td1">Agent</td>
        <td width="10%" rowspan="2" class="td1">VIP</td>
      </tr>
      <tr >
        <td class="td1">Long</td>
        <td class="td1"><span class="td1">Short</span></td>
      </tr>
      <?
                        $date_From=$_POST['From'];
                        $date_To=$_POST['To'];
						$uid = $_POST['uid'];
						if ($uid  == "0" ) { 
           					 $result = mysql_query("select * from p1_order_info where Date_a between '".$date_From."' and '".$date_To."' and p1_order_info.stop1 = 0 order by Date_a");
						}else{
          					  $result = mysql_query("select * from p1_order_info where Date_a between '".$date_From."' and '".$date_To."' and uid = ".$uid." and p1_order_info.stop1 = 0 order by Date_a");
						}
            while($row = mysql_fetch_array($result)){ 
        
        ?>
      <tr <? if( $row['Type2'] == '1') { ?>class="td4" <? }else{ ?> class="td2" <? } ?>>
        <td><? echo $row['oid']; ?></td>
        <td><? echo $row['Date_a']; ?></td>
        <td><div align="center"><? 
		
				// Create invoice
						//Invoice No.
							$Inv_year  = $row['year'] -2000;
							if ($row['month'] < 10 ) {
								$Inv_month = '0'.$row['month'];
							}else{
								$Inv_month = $row['month'];
							}
							if ($row['serial'] < 10 ) {
								$Inv_serial = '0000'.$row['serial'];
							}elseif ($serial < 100 ) {
								$Inv_serial = '000'.$row['serial'];
							}elseif ($serial < 1000 ) {
								$Inv_serial = '00'.$row['serial'];
							}elseif ($serial < 10000 ) {
								$Inv_serial = '0'.$row['serial'];
							}elseif ($serial < 100000 ) {
								$Inv_serial = $row['serial'];
							}
							
							echo  $Inv_year.$Inv_month.'NV'.$Inv_serial;

		
		
		
		
		
		 ?></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>
        <td><? 
		$aid=$row['aid'];
		$query = mysql_query("select * from p1_agent , p1_agent_order where p1_agent.tid = p1_agent_order.tid and aid = $aid"); 		
		if (mysql_num_rows($query) <> "0")
				{
						echo mysql_result($query,0,"agent_name");
				}
		 ?></td>
        <td><? 
		$vid=$row['vid'];
		$query = mysql_query("select * from p1_vip , p1_vip_order where p1_vip.tid = p1_vip_order.tid and vid = $vid"); 		
		if (mysql_num_rows($query) <> "0")
				{
						echo mysql_result($query,0,"vip_name");
				}
		 ?></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>&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>
        <td class="td_print1">&nbsp;</td>
        <td class="td_print1">&nbsp;</td>
      </tr>
    </table>
  <br />
  <span class="link">Sales</span><br />
  <br />
    <table width="100%" border="0">
      <tr>
        <td class="td1"><div align="center">ID</div></td>
        <td colspan="2" class="td1"><div align="center">Black frame</div></td>
        <td colspan="2" class="td1"><div align="center">Silver frame</div></td>
        <td colspan="2" class="td1"><div align="center">White frame</div></td>
        <td class="td1"><div align="center">Fiber</div></td>
        <td class="td1"><div align="center">screws</div></td>
        <td class="td1"><div align="center">offside fixing</div></td>
        <td class="td1"><div align="center">Amount </div></td>
      </tr>
      <?
	  		$i=0;
	  
                        $date_From=$_POST['From'];
                        $date_To=$_POST['To'];
						$uid = $_POST['uid'];
						if ($uid  == "0" ) { 
			$result = mysql_query("select * from p1_sale where create_date between '".$date_From."' and '".$date_To."' and delete_uid = 0 order by create_date");
						}else{
			$result = mysql_query("select * from p1_sale where create_date between '".$date_From."' and '".$date_To."' and uid = ".$uid." and delete_uid = 0 order by create_date");
						}
			
			$total_bl = 0;
			$total_bs = 0;
			$total_sl = 0;
			$total_ss = 0;
			$total_wl = 0;
			$total_ws = 0;
			$total_fiber = 0;
			$total_screws = 0;
			$outsidefixing_t = 0;
			
            while($row = mysql_fetch_array($result)){ 
      $i=$i+1;
	  ?>
      <tr>
        <td class="td2"><div align="center"><? echo $i;?></div></td>
        <td class="td2"><div align="center"><? echo $row['bl'];?></div></td>
        <td class="td2"><div align="center"><? echo $row['bs'];?></div></td>
        <td class="td2"><div align="center"><? echo $row['sl'];?></div></td>
        <td class="td2"><div align="center"><? echo $row['ss'];?></div></td>
        <td class="td2"><div align="center"><? echo $row['wl'];?></div></td>
        <td class="td2"><div align="center"><? echo $row['ws'];?></div></td>
        <td class="td2"><div align="center"><? echo $row['fiber'];?></div></td>
        <td class="td2"><div align="center"><? echo $row['screws'];?></div></td>
        <td class="td2"><div align="center"><? echo $row['outsidefixing'];

		if ($row['outsidefixing'] == 1 ) 
			{	
				$outsidefixing = 10;
			}else{
				$outsidefixing = $row['outsidefixing']*5;
			}
		
		?></div></td>
        <td class="td2"><div align="center"><? echo $row['bl']*5+$row['bs']*5+$row['sl']*5+$row['ss']*5+$row['wl']*5+$row['ws']*5+$row['fiber']+$row['screws']+$outsidefixing;?></div></td>
      </tr>
      	<?
	  		$total_bl = $total_bl +$row['bl'];
	  		$total_bs = $total_bs +$row['bs'];
	  		$total_sl = $total_sl +$row['sl'];
			$total_ss = $total_ss +$row['ss'];
			$total_wl = $total_wl +$row['wl'];
			$total_ws = $total_ws +$row['ws'];
			$total_fiber = $total_fiber+$row['fiber'];
			$total_screws = $total_screws+$row['screws'];
			$outsidefixing_t = $outsidefixing_t+$outsidefixing;
			$total_t = $total_t + $row['bl']*5+$row['bs']*5+$row['sl']*5+$row['ss']*5+$row['wl']*5+$row['ws']*5+$row['fiber']+$row['screws']+$outsidefixing;

	   }?>
      <tr>
        <td>&nbsp;</td>
        <td class="td_print3">&nbsp;<? echo $total_bl?></td>
        <td class="td_print3">&nbsp;<? echo $total_bs?></td>
        <td class="td_print3">&nbsp;<? echo $total_sl?></td>
        <td class="td_print3">&nbsp;<? echo $total_ss?></td>
        <td class="td_print3">&nbsp;<? echo $total_wl?></td>
        <td class="td_print3">&nbsp;<? echo $total_ws?></td>
        <td class="td_print3">&nbsp;<? echo $total_fiber?></td>
        <td class="td_print3">&nbsp;<? echo $total_screws?></td>
        <td class="td_print3">&nbsp;<? echo $outsidefixing_t ?></td>
        <td class="td_print3">&nbsp;<? echo $total_t?></td>
      </tr>

    </table>
<br />
    <blockquote>
      <p><br />
          <br />
        <? } ?>
        
        </p>
    </blockquote>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</div>
<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "date", {format:"yyyy-mm-dd", useCharacterMasking:true});
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "date", {format:"yyyy-mm-dd", useCharacterMasking:true});
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "date", {useCharacterMasking:true, format:"yyyy-mm-dd"});
var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4", "date", {useCharacterMasking:true, format:"yyyy-mm-dd"});
//-->
</script>
