<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--reference to main.css removed-->
<?php
include('../include/session.php');
?>

<?php
$maintenance_card_no=$_GET['maintenance_card_no'];
$store_register_id = 0;

$table_name = $_SESSION['db_prefix']."_maintenance_jobs";
$job_query = "SELECT * FROM $table_name WHERE maintenance_card_no = '".$maintenance_card_no."' ";
$job_result = mySQL_query($job_query);
$maintenance_no = mysql_result($job_result, 0, "maintenance_no");
$cycle_no = mysql_result($job_result, 0, "cycle_no");
$cust_id = mysql_result($job_result, 0, "cust_id");
$quote_note = mysql_result($job_result, 0, "quote_note");
$value = mysql_result($job_result, 0, "value");
$order_date = mysql_result($job_result, 0, "date");
$start_date = mysql_result($job_result, 0, "start_date");
$end_date = mysql_result($job_result, 0, "end_date");
$project_description = mysql_result($job_result, 0, "project_description");
$project = mysql_result($job_result, 0, "project");

$project_no = mysql_result($job_result, 0, "project_no");
$project_place = mysql_result($job_result, 0, "project_place");
$project_area = mysql_result($job_result, 0, "project_area");
$deliver_date = mysql_result($job_result, 0, "start_date");
$team = mysql_result($job_result, 0, "team");


//$captured = mysql_result($job_result, 0, "captured");
$compiled = mysql_result($job_result, 0, "compiled");
$invoiced = mysql_result($job_result, 0, "invoiced");
$completed = mysql_result($job_result, 0, "completed");


$table_name = $_SESSION['db_prefix']."_maintenance_job_lines";
$line_query = "SELECT *  FROM $table_name WHERE  maintenance_card_no =  '".$maintenance_card_no."' ";
$line_result = mySQL_query($line_query);
$line_num = mysql_num_rows($line_result);

$table_name = $_SESSION['db_prefix']."_maintenance_additional_supply_lines";
$line2_query = "SELECT *  FROM $table_name WHERE  maintenance_card_no =  '".$maintenance_card_no."' ";
$line2_result = mySQL_query($line2_query);
$line2_num = mysql_num_rows($line2_result);

$table_name = $_SESSION['db_prefix']."_maintenance_return_lines";
$line3_query = "SELECT *  FROM $table_name WHERE  maintenance_card_no =  '".$maintenance_card_no."' ";
$line3_result = mySQL_query($line3_query);
$line3_num = mysql_num_rows($line3_result);

$table_name4 = $_SESSION['db_prefix']."_survey_maintenance";
$survey_query = "SELECT * FROM $table_name4 WHERE maintenance_card_no = '".$maintenance_card_no."' ";
$survey_result = mySQL_query($survey_query);
$survey_num = mysql_num_rows($survey_result);
if ($survey_num>0) {
$result_1 = mysql_result($survey_result, 0, "result_1");
$result_2 = mysql_result($survey_result, 0, "result_2");
$result_3 = mysql_result($survey_result, 0, "result_3");
$result_4 = mysql_result($survey_result, 0, "result_4");

$survey_perc = (($result_1+$result_2+$result_3+$result_4)/8)*100;
}
else {
	$survey_perc = '';
}

?>
<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />

<!--jscript-->
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script>

</head>

<body>
<?php
include ("../navigation/header.php");
$page_name = "Maintenance-main";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/maintenance_sidebar.php");
?>
<div class="main_frame">
  <div class="page_head_frame">
          <table width="650" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="463"><label class="label_page_head">Maintenance card</label></td>
              <td width="120" align="center">Survey result:<br>
                <b>
                <?php  if ($survey_perc>='0') { ?>
                <a href="survey_maintenance_report.php?maintenance_card_no=<?php echo $maintenance_card_no ?>" onMouseover="ddrivetip('Click to view report', 150)"; onMouseout="hideddrivetip()"><?php echo number_format($survey_perc, 0, '.', ',').'%'; ?></a>
                <?php } else { echo '--';} ?>
              </b></td>
              <td width="67"><label class="label_quote_no"><?php echo $maintenance_card_no;  ?></label>
              </td>
            </tr>
          </table>
          </div>
          <div class="page_middle_frame">
<div class="page_inside_frame">
<?php 
include('../include/customer_block.php');
?>
</div>    
<div class="page_inside_frame">
<table width="650" id="table_details_display">
    <tr>
      <td align="left" valign="top">Project:</td>
      <td align="left" valign="top"><?php  echo $project;  ?></td>
      <td align="left" valign="top"><?php echo 'Maintenance card no:'; ?></td>
      <td align="left" valign="top"><?php echo $maintenance_card_no;  ?></td>
    </tr>
    <?php if ($project=='Monthly maintenance') { ?>
    <tr>
      <td align="left" valign="top">Cycle number:</td>
      <td align="left" valign="top"><?php echo $cycle_no ?></td>
      <td align="left" valign="top">Maintenance contract no:</td>
      <td align="left" valign="top"><?php echo $maintenance_no ?></td>
    </tr>
    <?php } ?>
    <tr>
      <td align="left" valign="top">Maintenance team:</td>
      <td align="left" valign="top"><?php echo $team ?></td>
      <td align="left" valign="top">&nbsp;</td>
      <td align="left" valign="top">&nbsp;</td>
    </tr>
    <tr>
      <td align="left" valign="top"><?php  echo 'Order date:';?></td>
      <td width="193" align="left" valign="top"><?php  echo date("d-m-Y", strtotime($order_date));  ?></td>
      <td width="156" align="left" valign="top"><?php  echo 'Job value'; ?></td>
      <td width="160" align="left" valign="top"><?php   echo number_format($value, 2, '.', ','); ?></td>
    </tr>
    <tr>
      <td align="left" valign="top">Project period:</td>
      <td colspan="3" align="left" valign="top"><?php if ($deliver_date!='') {?>from: <?php echo date("d-m-Y", strtotime($deliver_date));  ?> to: <?php echo date("d-m-Y", strtotime($end_date));  ?><?php } ?> </td>
      </tr>
    <tr>
      <td width="121" align="left" valign="top">Project place:</td>
      <td colspan="3" align="left" valign="top"><?php echo $project_no?>&nbsp;&nbsp;<?php echo $project_area?>&nbsp;&nbsp;<?php echo $project_place?></td>
      </tr>
    <tr>
      <td align="left" valign="top">Notes:</td>
      <td colspan="3" align="left" valign="top"><?php echo $quote_note ?></td>
    </tr>
  </table>
</div>  

<div class="page_inside_frame">
Store items
<table width="650" id="table_display" >
          <tr>
            <td height="26" colspan="2" align="left" valign="top">Item</td>
            <td width="112" align="left" valign="top">Group</td>
            <td width="60" align="center" valign="top">Unit</td>
            <td width="106" align="center" valign="top">Quantity<br>
              supplied</td>
            <td width="100" align="center" valign="top">Remarks</td>
        </tr>
          <?php
				$i=0;
				$sub_total_2=0;
				while ($i<$line_num){
					 $a0 = mysql_result($line_result, $i, "order_line_id");
					 $a1 = mysql_result($line_result, $i, "store_item_id");
					 
					
					 $table_name = $_SESSION['db_prefix']."_store_items";
						$item_query = "SELECT item_name, unit, subCategory, register FROM $table_name WHERE store_item_id = '".$a1."' ";
						$item_result = mySQL_query($item_query);
						$a1a = mysql_result($item_result, 0, "item_name");
						$a3a = mysql_result($item_result, 0, "unit");
						$a4a = mysql_result($item_result, 0, "subCategory");
						$register = mysql_result($item_result, 0, "register");
					
					 $a2 = mysql_result($line_result, $i, "quantity");
					 $a3 = mysql_result($line_result, $i, "delivered");
					 $a5 = mysql_result($line_result, $i, "store_reg_id");
					
					$a8 = '';
				if ($register=='yes') {
					
				  	$table_name = $_SESSION['db_prefix']."_store_register";
					$register_query = "SELECT serial_number  FROM $table_name WHERE store_register_id = '".$a5."' ";
					$register_result = mySQL_query($register_query);
					$register_num = mysql_num_rows($register_result);
					$serial = mysql_result($register_result, 0, "serial_number");
					
				}
					 
				 ?>
          <tr>
            <td colspan="2" valign="top"><?php echo $a1a ?>&nbsp;
            <?php if ($register=='yes') { echo 'serial no: '.$serial ; }?></td>
            <td valign="top"><?php echo $a4a ?></td>
            <td align="center" valign="top"><?php echo $a3a ?></td>
            <td align="center" valign="top"><?php if (($a3!='') AND ($a3!='0.00')) { if ($a3a!='no') {echo number_format($a3, 2, '.', ',');} else { echo number_format($a3, 0, '.', ','); } }?></td>
            <td align="center" valign="top"><?php echo $a8 ?></td>
        </tr>
          <?php 
			  $i++;
				 }
				 ?>
          <tr>
		  <?php
				$i=0;
				$sub_total_2=0;
				while ($i<$line2_num){
					 $a0 = mysql_result($line2_result, $i, "order_line_id");
					 $a1 = mysql_result($line2_result, $i, "store_item_id");
					 
					
					 $table_name = $_SESSION['db_prefix']."_store_items";
						$item_query = "SELECT item_name, unit, subCategory, register FROM $table_name WHERE store_item_id = '".$a1."' ";
						$item_result = mySQL_query($item_query);
						$a1a = mysql_result($item_result, 0, "item_name");
						$a3a = mysql_result($item_result, 0, "unit");
						$a4a = mysql_result($item_result, 0, "subCategory");
						$register = mysql_result($item_result, 0, "register");
					
					 $a2 = mysql_result($line2_result, $i, "quantity");
					 $a3 = mysql_result($line2_result, $i, "quantity");
					 $a5 = mysql_result($line2_result, $i, "store_reg_id");
					
					//$a8 = mysql_result($line2_result, $i, "misc");
					$a8='Additional';
					
				if ($register=='yes') {
					
				  	$table_name = $_SESSION['db_prefix']."_store_register";
					$register_query = "SELECT serial_number  FROM $table_name WHERE store_register_id = '".$a5."' ";
					$register_result = mySQL_query($register_query);
					$register_num = mysql_num_rows($register_result);
					$serial = mysql_result($register_result, 0, "serial_number");
					
				}
					
					 
				 ?>
          <tr>
            <td colspan="2" valign="top"><?php echo $a1a ?>&nbsp;
            <?php if ($register=='yes') { echo 'serial no: '.$serial ; }?></td>
            <td valign="top"><?php echo $a4a ?></td>
            <td align="center" valign="top"><?php echo $a3a ?></td>
            <td align="center" valign="top"><?php if (($a3!='') AND ($a3!='0.00')) { if ($a3a!='no') {echo number_format($a3, 2, '.', ',');} else { echo number_format($a3, 0, '.', ','); } }?></td>
            <td align="center" valign="top"><?php echo $a8 ?></td>
        </tr>
          <?php 
			  $i++;
				 }
				 ?>
                 
         <?php
				$i=0;
				$sub_total_2=0;
				while ($i<$line3_num){
					 $a0 = mysql_result($line3_result, $i, "maintenance_return_id");
					 $a1 = mysql_result($line3_result, $i, "store_item_id");
					 
					
					 $table_name = $_SESSION['db_prefix']."_store_items";
						$item_query = "SELECT item_name, unit, subCategory, register FROM $table_name WHERE store_item_id = '".$a1."' ";
						$item_result = mySQL_query($item_query);
						$a1a = mysql_result($item_result, 0, "item_name");
						$a3a = mysql_result($item_result, 0, "unit");
						$a4a = mysql_result($item_result, 0, "subCategory");
						$register = mysql_result($item_result, 0, "register");
					
					 $a2 = mysql_result($line3_result, $i, "quantity");
					 $a3 = mysql_result($line3_result, $i, "quantity");
					 $a5 = mysql_result($line3_result, $i, "store_reg_id");
					
					//$a8 = mysql_result($line2_result, $i, "misc");
					$a8='Return';
					
				if ($register=='yes') {
						
				  	$table_name = $_SESSION['db_prefix']."_store_register";
					$register_query = "SELECT serial_number  FROM $table_name WHERE store_register_id = '".$a5."' ";
					$register_result = mySQL_query($register_query);
					$register_num = mysql_num_rows($register_result);
					$serial = mysql_result($register_result, 0, "serial_number");
					}
					
					 
				 ?>
          <tr>
            <td colspan="2" valign="top"><?php echo $a1a ?>&nbsp;
            <?php if ($register=='yes') { echo 'serial no: '.$serial ; }?></td>
            <td valign="top"><?php echo $a4a ?></td>
            <td align="center" valign="top"><?php echo $a3a ?></td>
            <td align="center" valign="top"><?php if (($a3!='') AND ($a3!='0.00')) { if ($a3a!='no') {echo number_format($a3, 2, '.', ',');} else { echo number_format($a3, 0, '.', ','); } }?></td>
            <td align="center" valign="top"><?php echo $a8 ?></td>
        </tr>
          <?php 
			  $i++;
				 }
				 ?>        
                 
          <tr>
            <td colspan="2" align="left" valign="top">&nbsp;</td>
            <td align="left" valign="top">&nbsp;</td>
            <td align="left" valign="top">&nbsp;</td>
            <td align="left" valign="top">&nbsp;</td>
            <td align="left" valign="top">&nbsp;</td>
        </tr>
      </table>
        <br>
<br>
<a href="maintenance_card_print.php?maintenance_card_no=<?php echo $maintenance_card_no ?>" target="_blank"><input name="print_button" type="button" value="Print maintenance card" class="imagebutton"></a>
<a href="supply_maintenance_job_print.php?maintenance_card_no=<?php echo $maintenance_card_no ?>" target="_blank"><input name="print_button" type="button" value="Print store supply" class="imagebutton"></a>
</div>      



   
</div>  
</div>
<?php include ('../navigation/side_bar.php'); ?>


<?php } else {
$_SESSION['denied_return'] = "maintenance/maintenance_main.php";	
include ("../navigation/maintenance_sidebar.php");?>
<body onLoad="accessdenied(); return false">
<?php include ('../navigation/side_bar.php'); ?>
</body>
<?php }
?>
</body>
</html>