<link href="wstyle.css" rel="stylesheet" type="text/css" />
<? if ($_GET['stat'] == '' ) { ?>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
						<p align="center" class="link">Total Car</p>
<form action="index.php?page=56&stat=print" method="post" name="form1" target="_blank" id="form1">
  <table width="80%" border="0" align="center">
    <tr>
      <td class="td1">From Date</td>
      <td class="td2"><span id="sprytextfield1">
      <label>
      <input type="text" name="from_date" id="from_date" />
      </label>
      <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">*</span></span>  YYYY-MM-DD</td>
    </tr>
    <tr>
      <td class="td1">To Date</td>
      <td class="td2"><span id="sprytextfield2">
      <label>
      <input type="text" name="to_date" id="to_date" />
      </label>
      <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">*</span></span>  YYYY-MM-DD</td>
    </tr>
  </table>
  <p align="center">
    <input name="Submit" type="submit" class="Submit" id="Submit" value="   Show   " />
  </p>
</form>
<? } if ($_GET['stat'] == 'print' ) { 
			$plate_count = 0;
            $result = mysql_query('SELECT *  FROM p1_plate_type',$db); 
            while($row = mysql_fetch_array($result)){ 
				$plate_count = $plate_count + 1;
				$plate_name[$plate_count] = $row['plate_type'];
				
			
			}
    		?>
						<p align="center" class="link">Total Car</p>
<table width="100%" border="1" align="center" bordercolor="#000000">
                          <tr>
                            <td rowspan="2" class="td_print1">Date</td>
                            <td colspan="2" rowspan="2" class="td_print1">Ordered Vs Delivered</td>
                            <td colspan="<? echo $plate_count?>" class="td_print1">Plate Color code</td>
                            <td rowspan="2" class="td_print1">Total</td>
                            <td rowspan="2" class="td_print1">Grand total</td>
                          </tr>
                          <tr>
                          <? for ($loop=1;$loop<=$plate_count;$loop++)
						  	{	
							?>
                            <td class="td_print1"><? echo $plate_name[$loop];?></td>
   
                            <? } ?>
                          </tr>
                        <?

							$result = mysql_query("select count(number_of_plate),Date_a from p1_order_info where Date_a between  '".$_POST['from_date']."' AND '".$_POST['to_date']."' and stop1=0 group by Date_a"); 
							$sum_nop = 0;
							while($row = mysql_fetch_array($result)){ 
						?>
                          <tr>
                            <td rowspan="4" class="td_print2"><? echo $row['Date_a'];?></td>
                            <td colspan="2" class="td2">ORDERED</td>
                         <? for ($loop=1;$loop<=$plate_count;$loop++) 	{	?>
                            <td class="td2"><? 
							
							$query1 = mysql_query("SELECT count(number_of_plate)  number_of_plate  FROM p1_order_info where Date_a = '".$row['Date_a']."' and type1 = ".$loop." and stop1 = 0"); 		
											if (mysql_result($query1,0,"number_of_plate") *1 > 0 )
												{								
													echo mysql_result($query1,0,"number_of_plate");	
												}else{
													echo 0;
												}
							?></td>
                            
                         <? } ?>
                         
                           
                            <td class="td2"><? echo $row['count(number_of_plate)'];?></td>
                            <td class="td2"><? echo $row['count(number_of_plate)'];?></td>
                          </tr>
                          <tr>
                            <td rowspan="3" class="td_print2">DELIVERED</td>
                            <td class="td_print2">OnSite</td>
                         <? 
						 $total_onsite= 0;
						 for ($loop=1;$loop<=$plate_count;$loop++) 	{	?>
                            <td class="td_print2">
                              <? 
									
									$query1 = mysql_query("SELECT p1_out_order.outid, p1_order_info.Type1  FROM p1_out_order INNER JOIN p1_order_info ON p1_out_order.oid = p1_order_info.oid WHERE (((p1_out_order.stop1)=1) and p1_out_order.status4_dt like '".$row['Date_a']."%' AND ((p1_out_order.status)=4) AND ((p1_order_info.Type1)=".$loop."))");


							 
							 	echo mysql_num_rows($query1);
								$total_onsite= $total_onsite+ mysql_num_rows($query1) ;
							?>                           </td>
                            <? } ?>
                         
                            <td class="td_print2"><? echo $total_onsite; ?></td>
                            <td rowspan="3" class="td_print2"><? //echo $total_onsite; ?></td>
                          </tr>
                          <tr>
                            <td class="td_print2">AGENT</td>
                         <? 
						 $AGENT_total= 0;
						 for ($loop=1;$loop<=$plate_count;$loop++) 	{	?>
                                                     
                            <td class="td_print2"><? 
							
							
							$query1 = mysql_query("SELECT count(number_of_plate)  number_of_plate  FROM p1_order_info where Date_a = '".$row['Date_a']."' and type1 = ".$loop." and stop1 = 0 and aid <> 0"); 		
											if (mysql_result($query1,0,"number_of_plate") *1 > 0 )
												{								
													echo mysql_result($query1,0,"number_of_plate");	
													$AGENT_total = $AGENT_total+mysql_result($query1,0,"number_of_plate");
												}else{
													echo 0;
												}
							?></td>
                            <? } ?>

                            <td class="td_print2"><? echo $AGENT_total?></td>
                          </tr>
                          <tr>
                            <td class="td_print2">VIPs</td>
                         <? 
						 $VIP_total= 0;
						 for ($loop=1;$loop<=$plate_count;$loop++) 	{	?>
                                                     
                            <td class="td_print2"><? 
							$query1 = mysql_query("SELECT count(number_of_plate)  number_of_plate  FROM p1_order_info where Date_a = '".$row['Date_a']."' and type1 = ".$loop." and stop1 = 0 and vid <> 0"); 		
											if (mysql_result($query1,0,"number_of_plate") *1 > 0 )
												{								
													echo mysql_result($query1,0,"number_of_plate");	
													$VIP_total = $VIP_total+mysql_result($query1,0,"number_of_plate");
												}else{
													echo 0;
												}
							?></td>
                        <? } ?>

                            <td class="td_print2"><? echo $VIP_total?></td>
                          </tr>
						<? 
						
								$sum_nop = $sum_nop + $row['count(number_of_plate)'];
						
							}
						?>
                          <tr>
                            <td height="23" class="p_c1"><div align="center"><strong>Total</strong></div></td>
                            <td class="p_c1">&nbsp;</td>
                            <td class="p_c1">&nbsp;</td>
                            <td class="p_c1">&nbsp;</td>
                            <? for ($loop=1;$loop<=$plate_count;$loop++) 	{	?>
                            <td class="p_c1">&nbsp;</td>

                            <? } ?>
                            <td class="p_c1"><div align="center"><strong><? echo $sum_nop ?></strong></div></td>
                          </tr>
                        </table>
						<p align="center">&nbsp;</p>


<? } ?>
<p>&nbsp;</p>
<div align="center">



</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", {useCharacterMasking:true, format:"yyyy-mm-dd"});
//-->
</script>
