<? if($_SESSION['page'] == '2' and $_SESSION['section'] == '2') { ?>
<link href="../admin.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
			window.addEvent('domready', function() { 
				new vlaDatePicker('From', { style: 'adobe_cs3',separator: '-', format: 'y/m/d'});
				new vlaDatePicker('To', { style: 'adobe_cs3',separator: '-', format: 'y/m/d'});
			});	
		</script>
        
        
        
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
    <table width="95%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#F7D782">
    <tr>
      <td>
        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#EFB412">
          <tr>
            <td class="Main_Text">Undelivered Vehicles Report</td>
            <td width="10%" class="Main_Text"><div align="right"><img src="image/more_info.gif" width="32" height="32" border="0" /></a></div></td>
          </tr>
          <tr>
            <td colspan="2">
              <? if ($_GET['stat'] == '' ) {  ?>

              <form action="index.php?stat=show" method="post" name="form1" id="form1">
                <br />
                <table width="95%" border="0" align="center">
                <tr>
                  <td width="15%" class="Main_Text1_case">Date From</td>
                  <td class="text_row1"><div align="center"><span id="sprytextfield1">
                    <input name="From" type="text" id="From" />
                    <span class="textfieldInvalidFormatMsg">*</span>
                    <span class="textfieldRequiredMsg">*</span>
                  </span></div></td>
                  <td width="15%" class="Main_Text1_case">Date To</td>
                  <td class="text_row1"><div align="center"><span id="sprytextfield2">
                    <input type="text" name="To" id="To" />
                  <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">*</span></span></div></td>
                  <td width="150" rowspan="3"><div align="center">
                    <input name="Submit" type="submit" class="Button1" id="Submit" value="   Create   " />
                  </div></td>
                </tr>
                <tr>
                  <td class="Main_Text1_case">Time From</td>
                  <td class="text_row1"><div align="center"><span id="sprytextfield3">
                    <input name="time_from" type="text" id="time_from" value="00:00" />
                  <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></div></td>
                  <td class="Main_Text1_case">Time To</td>
                  <td class="text_row1"><div align="center"><span id="sprytextfield4">
                    <input name="time_to" type="text" id="time_to" value="23:59" />
                  <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></div></td>
                  </tr>
                <tr>
                  <td class="Main_Text1_case">Detailed</td>
                  <td class="text_row1"><div align="center">
                    <input name="detailed" type="checkbox" id="detailed" value="1" />
                  </div></td>
                  <td class="Main_Text1_case">Chart</td>
                  <td class="text_row1"><input name="pchart" type="radio" id="radio" value="0" checked="checked" />
                    No chart&nbsp;&nbsp;
  <input type="radio" name="pchart" id="radio3" value="2" />
  &nbsp;Column Chart</td>
                </tr>
                <tr>
                  <td class="Main_Text1_case">Mode</td>
                  <td class="text_row1"><input name="mode_print" type="checkbox" id="mode_print" value="1" />
                    Print</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
              </table>
            
                <br />
              </form>
           
           
    <? } if ($_GET['stat'] == 'show' ) { 
	
	
					$plate_sum = 0;
					$result = mysql_query('SELECT *  FROM p1_plate_type',$db); 
					while($row = mysql_fetch_array($result)){ 
						$plate_sum = $plate_sum + 1;
						$plate_name[$plate_sum] = $row['plate_type'];
						
					
					}
	
								$From = $_POST["From"];
						  		$To = $_POST["To"];
						  		$time_from = $_POST["time_from"];
						  		$time_to = $_POST["time_to"];
		?>
                                      <br />
                        <table width="60%" border="0" align="center">
                          <tr>
                            <td class="Main_Text1">Date</td>
                            <td class="text_row1"><div align="center">From </div></td>
                            <td class="text_box_textarea"><div align="center"><? echo $From;?></div></td>
                            <td class="text_row1"><div align="center">to</div></td>
                            <td class="text_box_textarea"><div align="center"><? echo $To;?></div></td>
                          </tr>
                          <tr>
                            <td class="Main_Text1">Time</td>
                            <td class="text_row1"><div align="center">From </div></td>
                            <td class="text_box_textarea"><div align="center"><? echo $time_from;?></div></td>
                            <td class="text_row1"> <div align="center">to</div></td>
                            <td class="text_box_textarea"><div align="center"><? echo $time_to;?></div></td>
                          </tr>
                        </table>
    <br />
              <?
	
								
								
								
				// Type of plate 
					 	$number_of_plate_type = 0 ;
						$result1 = mysql_query('select * from p1_plate_type'); 
                        while($row1 = mysql_fetch_array($result1)){ 
								$plate_price[$row1['tyid']] = $row1['plate_price'];    
								$number_of_plate_type = $number_of_plate_type + 1;
								
					  	}
						
			  	// Select all Date 
					  
						$start_date = $_POST["From"];
						$check_date =date ("Y-m-d", strtotime ("-1 day", strtotime($start_date))); 
						$end_date = $_POST["To"];
				//	all data on site
								for ($i=1;$i<=$number_of_plate_type;$i++){
									$plate_count_all[$i] = 0; 
								}
								$plate_total_all = 0;
								
			// Start Detailed
			  
				 if ($_POST['detailed'] <> '') {
				 
						$i = 0; 
						while ($check_date != $end_date) { 
							$check_date = date ("Y-m-d", strtotime ("+1 day", strtotime($check_date))); 
							$first_row = 0;
				// ****** Calc OnSite  ***** //
							
							$onsite_result = mysql_query("select count(number_of_plate) number_of_plate , type1 from p1_order_info where delivered = 0 and stop1 = 0 and add_dt between '".$check_date." ".$time_from."' and '".$check_date." ".$time_to."' and aid = 0 and vid = 0 group by type1");

							//	row data on site
								for ($i=1;$i<=$number_of_plate_type;$i++){
									$plate_count_row[$i] = 0; 
								}
								$plate_total_row = 0;
							// 
								while($row_onsite = mysql_fetch_array($onsite_result)){ 
									$plate_count_row[$row_onsite['type1']] =  $row_onsite['number_of_plate'];
									$plate_total_row = $plate_total_row+$row_onsite['number_of_plate'];
									$plate_count_all[$row_onsite['type1']] =$plate_count_all[$row_onsite['type1']]+$row_onsite['number_of_plate'];
								}
							$plate_total_all = $plate_total_all+$plate_total_row;
							
							if ( $plate_total_row <> 0  ) { 
				 	?>
                    	<br />

                    
                        <table width="95%" border="0" align="center">
                          <tr>
                            <td width="10%" rowspan="2" class="Main_Text1_case"><div align="center">Date</div></td>
                            <td colspan="2" rowspan="2" class="Main_Text1_case"><div align="center">PLATES TYPE</div></td>
                            <td colspan="<? echo $plate_sum?>" bordercolor="#000000" class="Main_Text1_case"><div align="center">Plate Color code</div></td>
                            <td rowspan="2" class="Main_Text1_case"><div align="center">Total</div></td>
                          </tr>
                          <tr>
							<? for ($loop=1;$loop<=$plate_sum;$loop++)  	{	?>
                            <td bordercolor="#000000" class="Main_Text1_case"><div align="center"><? echo $plate_name[$loop];?></div></td>
                            <? } ?>
                          </tr>
                          <tr>
                            <td rowspan="4" class="Main_SText"><div align="center"><? echo $check_date?></div></td>
                            <td width="10%" rowspan="4" class="Main_color1"><div align="center">UNDELIVERED</div></td>
                            <td width="10%" class="Main_SText_case"><div align="center">ONSITE</div></td>
                            <? for ($loop=1;$loop<=$plate_sum;$loop++)  	{	?>
                            <td class="Main_SText_case"><div align="center"><? echo $plate_count_row[$loop];?></div></td>
                            <? } ?>
                            <td class="Main_SText_case"><div align="center"><? echo $plate_total_row?></div></td>
                          </tr>
                          <tr>
                            <td class="Main_SText_case"><div align="center">AGENTS</div></td>
                            <? for ($loop=1;$loop<=$plate_sum;$loop++)  	{	?>                            
                            <td class="Main_SText_case"><div align="center">0</div></td>
                            <? } ?>
                            <td class="Main_SText_case"><div align="center">0</div></td>
                          </tr>
                          <tr>
                            <td class="Main_SText_case"><div align="center">VIPs</div></td>
                            <? for ($loop=1;$loop<=$plate_sum;$loop++)  	{	?>
                            <td class="Main_SText_case"><div align="center">0</div></td>
                            <? } ?>
                            <td class="Main_SText_case"><div align="center">0</div></td>
                          </tr>
                          <tr>
                            <td class="Main_color2"><div align="center">TOTAL</div></td>
                            <? for ($loop=1;$loop<=$plate_sum;$loop++)  	{	?>
                            <td class="Main_color2"><div align="center"><? echo $plate_count_row[$loop];?></div></td>
                            <? } ?>
                            <td class="Main_color2"><div align="center"><? echo $plate_total_row?></div></td>
                          </tr>
                        </table>
                        <?
						// stop  show
							}
						// Stop loop	
						}
						?>
                        
                      <p align="center">&nbsp;</p>
                    
                        <table width="95%" border="0" align="center">
                          <tr>
                            <td width="10%" rowspan="2" class="Main_Text1_case"><div align="center">Date</div></td>
                            <td colspan="2" rowspan="2" class="Main_Text1_case"><div align="center">PLATES TYPE</div></td>
                            <td colspan="<? echo $plate_sum?>" bordercolor="#000000" class="Main_Text1_case"><div align="center">Plate Color code</div></td>
                            <td rowspan="2" class="Main_Text1_case"><div align="center">Total</div></td>
                          </tr>
                          <tr>
							<? for ($loop=1;$loop<=$plate_sum;$loop++)  	{	?>
                            <td bordercolor="#000000" class="Main_Text1_case"><div align="center"><? echo $plate_name[$loop];?></div></td>
                            <? } ?>
                          </tr>
                          <tr>
                            <td rowspan="4" class="Main_SText"><div align="center">All Date</div></td>
                            <td width="10%" rowspan="4" class="Main_color1"><div align="center">UNDELIVERED</div></td>
                            <td width="10%" class="Main_SText_case"><div align="center">ONSITE</div></td>
                            <? for ($loop=1;$loop<=$plate_sum;$loop++)  	{	?>
                            <td class="Main_SText_case"><div align="center"><? echo $plate_count_all[$loop];?></div></td>
                            <? } ?>
                            <td class="Main_SText_case"><div align="center"><? echo $plate_total_all?></div></td>
                          </tr>
                          <tr>
                            <td class="Main_SText_case"><div align="center">AGENTS</div></td>
                            <? for ($loop=1;$loop<=$plate_sum;$loop++)  	{	?>
                            <td class="Main_SText_case"><div align="center">0</div></td>
                            <? } ?>
                            <td class="Main_SText_case"><div align="center">0</div></td>
                          </tr>
                          <tr>
                            <td class="Main_SText_case"><div align="center">VIPs</div></td>
                            <? for ($loop=1;$loop<=$plate_sum;$loop++)  	{	?>
                            <td class="Main_SText_case"><div align="center">0</div></td>
                            <? } ?>
                             <td class="Main_SText_case"><div align="center">0</div></td>
                          </tr>
                          <tr>
                            <td class="Main_color1"><div align="center">TOTAL</div></td>
                            <? for ($loop=1;$loop<=$plate_sum;$loop++)  	{	?>
                            <td class="Main_color1"><div align="center"><? echo $plate_count_all[$loop];?></div></td>

                            <? } ?>
                            <td class="Main_color1"><div align="center"><? echo $plate_total_all?></div></td>
                          </tr>
                        </table>

                        
                        <?
			
		/*------------------------------   else  ------------------------------*/
				 }else { 
				 	$i = 0; 
						while ($check_date != $end_date) { 
							$check_date = date ("Y-m-d", strtotime ("+1 day", strtotime($check_date))); 
							$first_row = 0;
				// ****** Calc OnSite  ***** //
							
							$onsite_result = mysql_query("select count(number_of_plate) number_of_plate , type1 from p1_order_info where delivered = 0 and stop1 = 0 and add_dt between '".$check_date." ".$time_from."' and '".$check_date." ".$time_to."' and aid = 0 and vid = 0 group by type1");

							//	row data on site
								for ($i=1;$i<=$number_of_plate_type;$i++){
									$plate_count_row[$i] = 0; 
								}
								$plate_total_row = 0;
							// 
								while($row_onsite = mysql_fetch_array($onsite_result)){ 
									$plate_count_row[$row_onsite['type1']] =  $row_onsite['number_of_plate'];
									$plate_total_row = $plate_total_row+$row_onsite['number_of_plate'];
									$plate_count_all[$row_onsite['type1']] =$plate_count_all[$row_onsite['type1']]+$row_onsite['number_of_plate'];
								}
							$plate_total_all = $plate_total_all+$plate_total_row;
							
							
						// Stop loop	
						}
						?>
                        
                      <p align="center">&nbsp;</p>
                    
                        <table width="95%" border="0" align="center">
                          <tr>
                            <td width="10%" rowspan="2" class="Main_Text1_case"><div align="center">Date</div></td>
                            <td colspan="2" rowspan="2" class="Main_Text1_case"><div align="center">PLATES TYPE</div></td>
                            <td colspan="<? echo plate_sum?>" bordercolor="#000000" class="Main_Text1_case"><div align="center">Plate Color code</div></td>
                            <td rowspan="2" class="Main_Text1_case"><div align="center">Total</div></td>
                          </tr>
                          <tr>
							<? for ($loop=1;$loop<=$plate_sum;$loop++)  	{	?>
                            <td bordercolor="#000000" class="Main_Text1_case"><div align="center"><? echo $plate_name[$loop];?></div></td>
                            <? } ?>
                          </tr>
                          <tr>
                            <td rowspan="4" class="Main_SText"><div align="center">All Date</div></td>
                            <td width="10%" rowspan="4" class="Main_color1"><div align="center">UNDELIVERED</div></td>
                            <td width="10%" class="Main_SText_case"><div align="center">ONSITE</div></td>
                            <? for ($loop=1;$loop<=$plate_sum;$loop++)  	{	?>
                            <td class="Main_SText_case"><div align="center"><? echo $plate_count_all[$loop];?></div></td>
                            <? } ?>
                            <td class="Main_SText_case"><div align="center"><? echo $plate_total_all?></div></td>
                          </tr>
                          <tr>
                            <td class="Main_SText_case"><div align="center">AGENTS</div></td>
                            <? for ($loop=1;$loop<=$plate_sum;$loop++)  	{	?>
                            <td class="Main_SText_case"><div align="center">0</div></td>
                            <? } ?>
                            <td class="Main_SText_case"><div align="center">0</div></td>
                          </tr>
                          <tr>
                            <td class="Main_SText_case"><div align="center">VIPs</div></td>
                            <? for ($loop=1;$loop<=$plate_sum;$loop++)  	{	?>
                            <td class="Main_SText_case"><div align="center">0</div></td>
                            <? } ?>
                            <td class="Main_SText_case"><div align="center">0</div></td>
                          </tr>
                          <tr>
                            <td class="Main_color1"><div align="center">TOTAL</div></td>
                            <? for ($loop=1;$loop<=$plate_sum;$loop++)  	{	?>
                            <td class="Main_color1"><div align="center"><? echo $plate_count_all[$loop];?></div></td>
                            <? } ?>
                            <td class="Main_color1"><div align="center"><? echo $plate_total_all?></div></td>
                          </tr>
                        </table>

                        
                        <?		} ?>
		      <? if ($_POST['pchart'] == '2') {?>
				       <script type="text/javascript">
                        
                                var chart;
                        
                                var chartData = [{plate:"Private",income:<? echo $plate_count_all[1];?>},
								{plate:"Orange",income:<? echo $plate_count_all[2];?>},
								{plate:"Police",income:<? echo $plate_count_all[3];?>},
								{plate:"CD",income:<? echo $plate_count_all[4];?>},
								{plate:"M/Cycle",income:<? echo $plate_count_all[5];?>},
								{plate:"Yellow",income:<? echo $plate_count_all[6];?>},
								{plate:"RC",income:<? echo $plate_count_all[7];?>}
								
								
								];
                        
                       
                                window.onload = function() {
                                    chart = new AmCharts.AmSerialChart();
                                    chart.dataProvider = chartData;
                                    chart.categoryField = "plate";
                                    chart.startDuration = 1;
                                    chart.marginTop = 25;
                                    chart.marginLeft = 120;
                                 //	chart.rotate = true;
							
                                    var graph1 = new AmCharts.AmGraph();
                                    graph1.title = "Vehicles";
                                    graph1.valueField = "income";
                                    graph1.type = "column";
                                    graph1.lineAlpha = 0;
                                    graph1.fillColors = "#6633CC";
                                    graph1.fillAlphas = 1;
                                    chart.addGraph(graph1);
                        
                                 
                        
                                    var catAxis = chart.categoryAxis;
                                    catAxis.gridPosition = "start";
                                    catAxis.dashLength = 5;
                        
                                    var valAxis = new AmCharts.ValueAxis();
                                    valAxis.dashLength = 5;
                                    chart.addValueAxis(valAxis);
                        
                                    var valAxis2 = new AmCharts.ValueAxis();
                                    valAxis2.position = "top";
                                    chart.addValueAxis(valAxis2);
                                    
                                    var legend = new AmCharts.AmLegend();
                                    legend.marginLeft = 50;
                                    chart.addLegend(legend);
                        
                                    chart.write("chartdiv1");
                                }
                        
                        
                                </script>
                    
                    
		                  <div align="center"><div id="chartdiv1" style="width: 90%; height: 600px;"></div></div>
                    <? } ?>                   

  <?   } ?>
            </td>
          </tr>
        </table><br />

<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "date", {format:"yyyy-mm-dd"});
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "date", {format:"yyyy-mm-dd"});
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "time");
var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4", "time");
//-->
</script>
<? } ?>
