<? if($_SESSION['page'] == '1' and $_SESSION['section'] == '1') { ?>
<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">General Transactions  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"><span id="sprytextfield1">
                    <label>
                    <input name="From" type="text" id="From" />
                    <span class="textfieldInvalidFormatMsg">*</span><span class="textfieldRequiredMsg">*</span></label>
                  </span></td>
                  <td width="15%" class="Main_Text1_case">Date To</td>
                  <td class="text_row1"><span id="sprytextfield2">
                  <input type="text" name="To" id="To" />
                  <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">*</span></span></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"><span id="sprytextfield3">
                  <label>
                  <input name="time_from" type="text" id="time_from" value="00:00" />
                  </label>
                  <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
                  <td class="Main_Text1_case">Time To</td>
                  <td class="text_row1"><span id="sprytextfield4">
                  <label>
                  <input name="time_to" type="text" id="time_to" value="23:59" />
                  </label>
                  <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
                  </tr>
                <tr>
                  <td class="Main_Text1_case">Detailed</td>
                  <td class="text_row1"><label>
                    <input name="detailed" type="checkbox" id="detailed" value="1" />
                  </label></td>
                  <td class="Main_Text1_case">Mode</td>
                  <td class="text_row1"><input name="mode_print" type="checkbox" id="mode_print" value="1" />
                    Print</td>
                  </tr>
              </table>
            
                <br />
              </form>
              <div align="center">
                <? } if ($_GET['stat'] == 'show' ) { 
			  
?>
                <br />
               
                <? if ($_POST['detailed'] == '') {
						  		$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 />
              </div>
              <table width="60%"  border="0" align="center">
                          <tr>
                            <td rowspan="2" class="Main_Text1_case"><div align="center">General Transactions</div></td>
                            <td colspan="2" class="Main_Text1_case"><div align="center">Quantity</div></td>
                          </tr>
                          <tr>
                            <td class="Main_Text1_case"><div align="center">Vehicles</div></td>
                            <td class="Main_Text1_case"><div align="center">Each</div></td>
                          </tr>
                          <?
						  		$query = mysql_query("select count(*) Vehicles,sum(number_of_plate) number_of_plate , sum(BD1) BD1 from p1_order_info where stop1 = 0 and Date_a between '".$From."' and '".$To."' and Time_a between '".$time_from."' and '".$time_to."'");
						  ?>
                          <tr>
                            <td class="Main_SText"> Plates Ordered </td>
                            <td class="Main_SText"><div align="center"><? echo mysql_result($query,0,"Vehicles");?></div></td>
                            <td class="Main_SText"><div align="center"><? echo mysql_result($query,0,"number_of_plate");?></div></td>
                          </tr>
                          <?

						  		$query1 = mysql_query("select count(*) Vehicles,sum(number_of_plate) number_of_plate from p1_order_info where stop1 = 0 and Date_a between '".$From."' and '".$To."' and Time_a between '".$time_from."' and '".$time_to."' and ( aid <> 0 or vid <> 0 )");
								
								$query2 = mysql_query("select count(p1_out_order.oid) Vehicles , sum(p1_order_info.number_of_plate) number_of_plate from p1_out_order,p1_order_info where p1_out_order.oid = p1_order_info.oid and p1_out_order.status = 4 and p1_out_order.stop1 = 1 and  p1_out_order.status0_dt between '".$From." ".$time_from."' and '".$To." ".$time_to."'");
								
						  ?>
                          <tr>
                            <td class="Main_SText">Plates Delivered </td>
                            <td class="Main_SText"><div align="center"><? echo mysql_result($query1,0,"Vehicles")+mysql_result($query2,0,"Vehicles");?></div></td>
                            <td class="Main_SText"><div align="center"><? echo mysql_result($query1,0,"number_of_plate")+mysql_result($query2,0,"number_of_plate");?></div></td>
                          </tr>
                        <?
							 $query3 = mysql_query("select sum(plate_no_s+plate_no_l)  number_of_damage from p1_damage where create_date between '".$From."' and '".$To."' and create_time between '".$time_from."' and '".$time_to."'");
                          ?>
                          <tr>
                            <td class="Main_SText"> Plates Damaged </td>
                            <td class="Main_SText"><div align="center">0</div></td>
                            <td class="Main_SText"><div align="center"><? echo mysql_result($query3,0,"number_of_damage");?></div></td>
                          </tr>
                        <?
							 $query4 = mysql_query("select sum(screws) screws , sum(fiber) fiber , sum(bs+bl+ss+sl+ws+wl) frames from p1_sale where create_date between '".$From."' and '".$To."' and create_time between '".$time_from."' and '".$time_to."'");
                          ?>
                          <tr>
                            <td class="Main_SText">New Vehicle Fix / Screws</td>
                            <td class="Main_SText"><div align="center"><? echo mysql_result($query,0,"BD1")+mysql_result($query4,0,"screws");?></div></td>
                            <td class="Main_SText"><div align="center">0</div></td>
                          </tr>
                          <tr>
                            <td class="Main_SText">Frames Sold</td>
                            <td class="Main_SText"><div align="center">0</div></td>
                            <td class="Main_SText"><div align="center"><? echo mysql_result($query4,0,"frames");?></div></td>
                          </tr>
                          <tr>
                            <td class="Main_SText">Fibers Sold</td>
                            <td class="Main_SText"><div align="center">0</div></td>
                            <td class="Main_SText"><div align="center"><? echo mysql_result($query4,0,"fiber");?></div></td>
                          </tr>
   			  </table>
              		<? } else {
						  		$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 />
                      	<div align="center">
                        
                        	<table width="60%" border="0">
                              <tr>
                                <td width="15%" rowspan="2" class="Main_Text1_case"><div align="center">Date</div></td>
                                <td width="40%" rowspan="2" class="Main_Text1_case"><div align="center">General Transactions</div></td>
                                <td colspan="2" class="Main_Text1_case"><div align="center">Quantity</div></td>
                              </tr>
                              <tr>
                                <td width="22%" class="Main_Text1_case"><div align="center">Vehicles</div></td>
                                <td class="Main_Text1_case"><div align="center">Each</div></td>
                              </tr>
                             <?
							 	$start_date = $_POST["From"];
								$check_date =date ("Y-m-d", strtotime ("-1 day", strtotime($start_date))); 
								$end_date = $_POST["To"];
								
								$i = 0; 
								
								while ($check_date != $end_date) { 
							 		 $check_date = date ("Y-m-d", strtotime ("+1 day", strtotime($check_date))); 
							
									$query = mysql_query("select count(*) Vehicles,sum(number_of_plate) number_of_plate , sum(BD1) BD1 from p1_order_info where stop1 = 0 and Date_a = '".$check_date."' and Time_a between '".$time_from."' and '".$time_to."'");
							
							
							 ?> 
                              <tr>
                                <td rowspan="6" class="Main_SText_case"><? echo $check_date; ?></td>
                                <td class="Main_SText"> Plates Ordered </td>
                                <td class="Main_SText"><div align="center"><? echo mysql_result($query,0,"Vehicles");?></div></td>
                                <td class="Main_SText"><div align="center"><? echo mysql_result($query,0,"number_of_plate");?></div></td>
                              </tr>
                              <?

						  		$query1 = mysql_query("select count(*) Vehicles,sum(number_of_plate) number_of_plate from p1_order_info where stop1 = 0 and Date_a = '".$check_date."' and Time_a between '".$time_from."' and '".$time_to."' and ( aid <> 0 or vid <> 0 )");
								
								$query2 = mysql_query("select count(p1_out_order.oid) Vehicles , sum(p1_order_info.number_of_plate) number_of_plate from p1_out_order,p1_order_info where p1_out_order.oid = p1_order_info.oid and p1_out_order.status = 4 and p1_out_order.stop1 = 1 and  p1_out_order.status0_dt between '".$check_date." ".$time_from."' and '".$check_date." ".$time_to."'");
								
						  ?>
                          <tr>
                            <td class="Main_SText">Plates Delivered </td>
                            <td class="Main_SText"><div align="center"><? echo mysql_result($query1,0,"Vehicles")+mysql_result($query2,0,"Vehicles");?></div></td>
                            <td class="Main_SText"><div align="center"><? echo mysql_result($query1,0,"number_of_plate")+mysql_result($query2,0,"number_of_plate");?></div></td>
                          </tr>
                              <?
							 $query3 = mysql_query("select count(*) number_of_damage from p1_damage where create_date = '".$check_date."' and create_time between '".$time_from."' and '".$time_to."'");
                          ?>
                          <tr>
                            <td class="Main_SText"> Plates Damaged </td>
                            <td class="Main_SText"><div align="center">0</div></td>
                            <td class="Main_SText"><div align="center"><? echo mysql_result($query3,0,"number_of_damage");?></div></td>
                          </tr>
                           <?
							 $query4 = mysql_query("select sum(screws) screws , sum(fiber) fiber , sum(bs+bl+ss+sl+ws+wl) frames from p1_sale where create_date = '".$check_date."' and create_time between '".$time_from."' and '".$time_to."'");
                          ?>
                          <tr>
                            <td class="Main_SText">New Vehicle Fix / Screws</td>
                            <td class="Main_SText"><div align="center"><? echo mysql_result($query,0,"BD1")+mysql_result($query4,0,"screws");?></div></td>
                            <td class="Main_SText"><div align="center">0</div></td>
                          </tr>
                          <tr>
                            <td class="Main_SText">Frames Sold</td>
                            <td class="Main_SText"><div align="center">0</div></td>
                            <td class="Main_SText"><div align="center"><? echo mysql_result($query4,0,"frames");?></div></td>
                          </tr>
                          <tr>
                            <td class="Main_SText">Fibers Sold</td>
                            <td class="Main_SText"><div align="center">0</div></td>
                            <td class="Main_SText"><div align="center"><? echo mysql_result($query4,0,"fiber");?></div></td>
                          </tr>
                              <?
							   $i++;
							   
							   		$Plates_Ordered_1  = $Plates_Ordered_1 + mysql_result($query,0,"Vehicles");;
									$Plates_Ordered_2  = $Plates_Ordered_2 + mysql_result($query,0,"number_of_plate");
									$Plates_Delivered_1 = $Plates_Delivered_1 + mysql_result($query1,0,"Vehicles")+mysql_result($query2,0,"Vehicles");
									$Plates_Delivered_2 = $Plates_Delivered_2 + mysql_result($query1,0,"number_of_plate")+mysql_result($query2,0,"number_of_plate");
									$Plates_Damaged = $Plates_Damaged + mysql_result($query3,0,"number_of_damage") ;
									$Screws	= $Screws + mysql_result($query,0,"BD1")+mysql_result($query4,0,"screws");
									$Frames = $Frames + mysql_result($query4,0,"frames");
									$Fibers = $Fibers + mysql_result($query4,0,"fiber");

							  	}  
								?>
							  
                          </table>
                        	<table width="60%" border="0">
                              <tr>
                                <td width="15%" rowspan="6" class="text_row1">Total</td>
                                <td width="40%" class="text_row1"> Plates Ordered </td>
                                <td width="22%" class="text_row1"><div align="center"><? echo $Plates_Ordered_1?></div></td>
                                <td class="text_row1"><div align="center"><? echo $Plates_Ordered_2?></div></td>
                              </tr>
                              <tr>
                                <td class="text_row1">Plates Delivered </td>
                                <td width="22%" class="text_row1"><div align="center"><? echo $Plates_Delivered_1?></div></td>
                                <td class="text_row1"><div align="center"><? echo $Plates_Delivered_2?></div></td>
                              </tr>
                              <tr>
                                <td class="text_row1"> Plates Damaged </td>
                                <td class="text_row1"><div align="center">0</div></td>
                                <td class="text_row1"><div align="center"><? echo $Plates_Damaged?></div></td>
                              </tr>
                              <tr>
                                <td class="text_row1">New Vehicle Fix / Screws</td>
                                <td class="text_row1"><div align="center"><? echo $Screws;?></div></td>
                                <td class="text_row1"><div align="center">0</div></td>
                              </tr>
                              <tr>
                                <td class="text_row1">Frames Sold</td>
                                <td class="text_row1"><div align="center">0</div></td>
                                <td class="text_row1"><div align="center"><? echo $Frames?></div></td>
                              </tr>
                              <tr>
                                <td class="text_row1">Fibers Sold</td>
                                <td class="text_row1"><div align="center">0</div></td>
                                <td class="text_row1"><div align="center"><? echo $Fibers?></div></td>
                              </tr>
                            </table>
                        	<p>&nbsp;</p>
              </div>
                      
    				<? } ?>
	          <br />
	          <? } ?>
            </td>
          </tr>
        </table></td>
      </tr>
</table>
<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>
<? } ?>
