<? if($_SESSION['page'] == '1' and $_SESSION['section'] == '4') { ?>
<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">Technicians Work 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 />
              <?
			  
	 if ($_POST['detailed'] <> '') {
			  
			  
				?><br />


	<?
				$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))); 
			
						for ($loop=1;$loop<=$plate_sum;$loop++)
						  		{	
									$total[$loop] = 0;
								}
							$total_all = 0;
?>
              
                  
                  <?
				  	$first_row = 0 ;
								  
				  
				  		$result = mysql_query("select * from p1_technitian where stop_technitian = 0 order by technitian"); 
						while($row = mysql_fetch_array($result)){ 
								$tid = $row['tid'];
									for ($i=1;$i<=$plate_sum;$i++) {
											$arr[$i] = 0;
										 }
								$test_count = 0;
								$result_loop = mysql_query("select count(p1_out_order.outid) total_order , Type1  from p1_out_order , p1_order_info where p1_out_order.oid=p1_order_info.oid and  p1_out_order.tid = $tid and p1_out_order.status = 4 and p1_out_order.status4_dt between '".$check_date." ".$time_from."' and '".$check_date." ".$time_to."' group by Type1");
								while($row1 = mysql_fetch_array($result_loop)){ 
										$arr[$row1['Type1']] = $row1['total_order'];
										
										$test_count = $test_count+$row1['total_order'];
								}
						//Number of technitian 
							$tic_num = mysql_num_rows($result);
						
						if ( $test_count  <> 0 ) {
				  ?>
                   <? if ($first_row == 0) { ?> 
              <table width="95%" border="0" align="center">
                  <tr bordercolor="#000000">
                    <td rowspan="2" class="Main_Text1_case">Date</td>
                    <td rowspan="2" class="Main_Text1_case">Technicians</td>
                    <td colspan="<? echo $plate_sum?>" 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 bordercolor="#000000">
                          <? for ($loop=1;$loop<=$plate_sum;$loop++)  	{	?>
                            <td class="Main_Text1_case"><? echo $plate_name[$loop];?></td>
                          <? } ?>
                  </tr>
                   <? }  ?>
                  <tr>
                 <? if ($first_row == 0) { ?>  <td  rowspan="<? echo $tic_num?>"class="Main_SText_case">&nbsp;<? echo $check_date?></td> <? }  ?>
                    <td class="Main_SText_case"><div align="center"><? echo $row['technitian'];?></div></td>
                    <? for ($loop=1;$loop<=$plate_sum;$loop++)  	{	?>
                    <td class="Main_SText_case"><div align="center"><? echo $arr[$loop];?></div></td>
                    
                    <? } ?>
                    <td class="Main_SText_case"><div align="center"><? echo $test_count;?></div></td>
                  </tr>
                  <?

							for ($loop=1;$loop<=$plate_sum;$loop++)  	{
								$total[$loop] = $total[$loop] +$arr[$loop];
							}
							$total_all = $total_all + $test_count;
							
							for ($loop=1;$loop<=$plate_sum;$loop++)  	{
				  				$total_a[$loop][$tid] = $total_a[$loop][$tid] +$arr[$loop];
							}

							
							
							$total_all_a[$tid] = $total_all_a[$tid] +  $test_count;
							
							// stop first  row
							$first_row = 1;
							
							// calc all total
							
							//$total_all_1[
							

						}
				  	}
					
					if ($total_all <> 0 ) {
					
				  ?>
                  <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 $total[$loop]?></div></td>
                    <? } ?>
                    <td class="Main_color1"><div align="center"><? echo $total_all?></div></td>
                  </tr>
                </table>
                <br />
               <? } ?>
               
                
             <? } ?>
             <hr/>
               <br />

                
                <table width="95%" border="0" align="center">
                  <tr bordercolor="#000000">
                    <td rowspan="2" class="Main_Text1_case">Technicians</td>
                    <td colspan="<? echo $plate_sum?>" 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 bordercolor="#000000">
                          <? for ($loop=1;$loop<=$plate_sum;$loop++)  	{	?>
                            <td class="Main_Text1_case"><? echo $plate_name[$loop];?></td>
                          <? } ?>
                  </tr>
                 <?
				  $result = mysql_query("select * from p1_technitian where stop_technitian = 0 order by technitian"); 
						while($row = mysql_fetch_array($result)){
						 $tid = $row['tid'];
						 $total_a_row = 0;
						 for ($loop=1;$loop<=$plate_sum;$loop++){ 
						 				$total_a_row = $total_a_row+$total_a[$loop][$tid];
							}
						
						
							if ($total_a_row <> 0 ){ 
						 ?>
                  <tr>
                    <td class="Main_SText_case"><div align="center"><? echo $row['technitian'];?></div></td>
                    <?  for ($loop=1;$loop<=$plate_sum;$loop++){ ?>
                    <td class="Main_SText_case"><div align="center"><? echo $total_a[$loop][$tid]; ?></div></td>

                    <? } ?>
                    <td class="Main_SText_case"><div align="center"><? echo $total_all_a[$tid]?></div></td>
                  </tr>
                 <? 
				 			 for ($loop=1;$loop<=$plate_sum;$loop++){ 
					 			 $total_of_alls[$loop] = $total_of_alls[$loop] +$total_a[$loop][$tid];	
								}
									
				 			 $total_of_all = $total_of_all +$total_all_a[$tid];	

							}
				 	}
				 ?>
                  <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 $total_of_alls[$loop]?></div></td>
                    <? } ?>

                    <td class="Main_color2"><div align="center"><? echo $total_of_all?></div></td>
                  </tr>
                </table>
            
	          <? 
			  /*---------------   else  -------------- */
			  
			  
			  }else {  ?>
              <br />


<?
				$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))); 
			
						for ($loop=1;$loop<=$plate_sum;$loop++)
						  		{	
									$total[$loop] = 0;
								}
							$total_all = 0;


?>
              
                  
                  <?
				  	$first_row = 0 ;
								  
				  
				  		$result = mysql_query("select * from p1_technitian where stop_technitian = 0 order by technitian"); 
						while($row = mysql_fetch_array($result)){ 
								$tid = $row['tid'];
									for ($i=1;$i<$plate_sum;$i++) {
											$arr[$i] = 0;
										 }
								$test_count = 0;
								$result_loop = mysql_query("select count(p1_out_order.outid) total_order , Type1  from p1_out_order , p1_order_info where p1_out_order.oid=p1_order_info.oid and  p1_out_order.tid = $tid and p1_out_order.status = 4 and p1_out_order.status4_dt between '".$check_date." ".$time_from."' and '".$check_date." ".$time_to."' group by Type1");
								while($row1 = mysql_fetch_array($result_loop)){ 
										$arr[$row1['Type1']] = $row1['total_order'];
										$test_count = $test_count+$row1['total_order'];
								}
						//Number of technitian 
							$tic_num = mysql_num_rows($result);
						
						if (  $test_count <> 0 ) {
				
				  		

							for ($loop=1;$loop<=$plate_sum;$loop++)  	{
				  				$total_a[$loop][$tid] = $total_a[$loop][$tid] +$arr[$loop];
							}
							
							$total_all_a[$tid] = $total_all_a[$tid] + $test_count ;
							
							// stop first  row
							$first_row = 1;
							
							// calc all total
							
							//$total_all_1[
							

						}
				  	}
					
				 } ?>
                
                <table width="95%" border="0" align="center">
                  <tr bordercolor="#000000">
                    <td rowspan="2" class="Main_Text1_case">Technicians</td>
                    <td colspan="<? echo $plate_sum?>" 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 bordercolor="#000000">
                          <? for ($loop=1;$loop<=$plate_sum;$loop++)  	{	?>
                            <td class="Main_Text1_case"><? echo $plate_name[$loop];?></td>
                          <? } ?>
                  </tr>
                 <?
				  $result = mysql_query("select * from p1_technitian where stop_technitian = 0 order by technitian"); 
						while($row = mysql_fetch_array($result)){
						 $tid = $row['tid'];
						 $total_a_row = 0;
						 for ($loop=1;$loop<=$plate_sum;$loop++){ 
						 				$total_a_row = $total_a_row+$total_a[$loop][$tid];
							}
						
						
							if ($total_a_row <> 0 ){ 
						 ?>
                  <tr>
                    <td class="Main_SText_case"><div align="center"><? echo $row['technitian'];?></div></td>
                    <?  for ($loop=1;$loop<=$plate_sum;$loop++){ ?>
                    <td class="Main_SText_case"><div align="center"><? echo $total_a[$loop][$tid]; ?></div></td>

                    <? } ?>
                    <td class="Main_SText_case"><div align="center"><? echo $total_all_a[$tid]?></div></td>
                  </tr>
                 <? 
				 			 for ($loop=1;$loop<=$plate_sum;$loop++){ 
					 			 $total_of_alls[$loop] = $total_of_alls[$loop] +$total_a[$loop][$tid];	
								}
									
				 			 $total_of_all = $total_of_all +$total_all_a[$tid];	

							}
				 	}
				 ?>
                  <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 $total_of_alls[$loop]?></div></td>
                    <? } ?>
                    <td class="Main_color2"><div align="center"><? echo $total_of_all?></div></td>
                  </tr>
                </table>
            
	          <?  } ?>
			 <? if ($_POST['pchart'] == '2') {?>
				       <script type="text/javascript">
                        
                                var chart;
                        
                                var chartData = [<?
								
								$first_row=0;
				  $result = mysql_query("select * from p1_technitian where stop_technitian = 0 order by technitian "); 
						while($row = mysql_fetch_array($result)){
						
						$tid = $row['tid'];
							if (($total_a1[$tid]+$total_a2[$tid]+$total_a3[$tid]+$total_a4[$tid]+$total_a5[$tid]+$total_a6[$tid]+$total_a7[$tid]) <> 0 ){ 
						 
						 if ($first_row == 1 ){ 
						 	 echo ",";
							   } 
								 $first_row=1;
								 
						 ?>{plate:"<? echo $row['technitian'];?>",income:<? echo $total_all_a[$tid]?>}<? } }
						 
						 ?>];
                        
                       
                                window.onload = function() {
                                    chart = new AmCharts.AmSerialChart();
                                    chart.dataProvider = chartData;
                                    chart.categoryField = "plate";
                                    chart.startDuration = 1;
                                    chart.marginTop = 25;
                                    chart.marginLeft = 100;
                                 	chart.rotate = true;
							
                                    var graph1 = new AmCharts.AmGraph();
                                    graph1.title = "Vehicles";
                                    graph1.valueField = "income";
                                    graph1.type = "column";
                                    graph1.lineAlpha = 0;
                                    graph1.fillColors = "#4F81BC";
                                    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>
<? } ?>
