<?php
$table_name = $_SESSION['db_prefix']."_compiled_jobs";
$job_query = "SELECT * FROM $table_name WHERE job_card_no = '".$_SESSION['job_card_no']."' ";
$job_result = mySQL_query($job_query);

$cust_id = mysql_result($job_result, 0, "cust_id");
$order_date = mysql_result($job_result, 0, "date");
$project = mysql_result($job_result, 0, "project");


$quote='no';
$job_card_no = $_SESSION['job_card_no'];



$table_name = $_SESSION['db_prefix']."_mworks_job_return_lines_temp";
$line_query = "SELECT *  FROM $table_name WHERE  user_name =  '".$_SESSION['username']."' AND store_item_id>0";
$line_result = mySQL_query($line_query);
$line_num = mysql_num_rows($line_result);

?>

<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script> 
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
</head>
<?php include('../include/wait.php') ?>

<body onLoad="MM_showHideLayers('wait','','hide')" onFocus="MM_showHideLayers('wait','','hide');"  onBlur="MM_showHideLayers('wait','','hide');">

<div class="wizard_page_middle_frame">
<div class="wizard_frame">
<?php 
include('../include/customer_block.php');
echo '<br>';

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

<form id="feedbackform" method="get" action="mworks_returnWiz6.php" >
<div class="wizard_frame">
  <table width="650" id="table_display" >
          <tr>
            <td width="121" align="left" valign="top">Job card no:</td>
            <td width="191" align="left" valign="top"><?php echo $_SESSION['job_card_no'] ?></td>
            <td width="116" align="left" valign="top">Date:</td>
            <td width="222" align="left" valign="top"><?php echo date("d-m-Y", strtotime($_SESSION['issue_date'])) ?></td>
          </tr>
          <tr>
            <td align="left" valign="top">Issued to:</td>
            <td align="left" valign="top"><?php echo $_SESSION['issued_to'] ?></td>
            <td align="left" valign="top">Authorised by:</td>
            <td align="left" valign="top"><?php echo $_SESSION['authorised_by'] ?></td>
          </tr>
          <tr>
            <td colspan="4" align="left" valign="top"></td>
          </tr>
        </table><br>
<br>
<table width="650" id="table_display" >
          <tr>
            <td height="26" colspan="2" align="left" valign="top">Item</td>
            <td width="106" align="left" valign="top">Group</td>
            <td width="35" align="center" valign="top">Unit</td>
            <td width="77" align="center" valign="top">Qty</td>
            <td width="66" align="center" valign="top">Unit<br>
price</td>
            <td width="76" align="center" valign="top">Total</td>
            <td width="62" align="center" valign="top">Return <br>
            to stock</td>
            </tr>
          <?php
				$i=0;
				$sub_tot=0;
				$a5_total=0;
				 while ($i<$line_num){
					 $a0 = mysql_result($line_result, $i, "order_line_id");
					 $a1 = mysql_result($line_result, $i, "store_item_id");
					 $a10 = mysql_result($line_result, $i, "store_reg_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");
						$a11 = mysql_result($item_result, 0, "register");
						
					 $a2 = mysql_result($line_result, $i, "quantity");
					 $a3 = mysql_result($line_result, $i, "price");
					 
					$a5=$a2*$a3;
					$a5_total=$a5_total+$a5;
					$a6 = mysql_result($line_result, $i, "error");
					$a7 = mysql_result($line_result, $i, "to_return");
					$a10 = mysql_result($line_result, $i, "store_reg_id");
					
					$serial = '';
					if ($a11=='yes') {
					$table_name = $_SESSION['db_prefix']."_store_register";
					$register_query = "SELECT serial_number  FROM $table_name WHERE store_register_id = '".$a10."' ";
					$register_result = mySQL_query($register_query);
					$register_num = mysql_num_rows($register_result);
					if ($register_num!=0) {
					$serial = '&nbsp;&nbsp;('.mysql_result($register_result, 0, "serial_number").')';
					}
					else {
						$serial = '';
					}
					}			 
				 ?>
          <tr>
            <td colspan="2" valign="top"><?php echo $a1a ?><?php echo $serial ?></td>
            <td valign="top"><?php echo $a4a ?></td>
            <td valign="top"><?php echo $a3a ?></td>
            <td valign="top"><?php echo $a2 ?>
              <?php if ($a6==1) {?>
              <a href="" onMouseover="ddrivetip('The number returned is higher as number in possession. The returned qty is reduced.', 150)"; onMouseout="hideddrivetip()"> <img src="../images/exclamation_mark_red_small.png" width="10" height="16">
              <?php } ?>
            </a></td>
            <td align="right" valign="top"><?php echo $a3. "  /" .$a3a ?>&nbsp;</td>
            <td align="right" valign="top"><?php echo number_format($a5, 2, '.', ',')?></td>
            <td align="center" valign="top"><?php echo $a7 ?></td>
            </tr>
          <?php 
			   // $a6_total=$a6_total+$a6;
				$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">Total:</td>
            <td align="right" valign="top"><?php echo number_format($a5_total, 2, '.', ',') ?></td>
            <td align="right" valign="top">&nbsp;</td>
            </tr>
          </table>
</div>
<div class="wizard_frame">
      <input name="s" type="hidden" id="s" value="4" />
          <input name="p" type="hidden" id="p" value="4" />
          <label class="label_std">If you want to make changes use the 'Prev' button to go back. <br />
            Click 'New' to make a new entry or to finish the wizard click 'Finish'.</label>
        </div>
        <div class="wizard_frame">
      <table width="590" height="50" align="center" id="table_button_bar">
          <tr>
            <td width="117"><input type="button" name="lastprev_button" class="imagebutton" value="Prev" onClick="needToConfirm = false;   MM_showHideLayers('wait','','show'); MM_goToURL('parent','mworks_returnWizbase.php?s=&p=2');return document.MM_returnValue" /></td>
            <td width="115">&nbsp;</td>
            <td width="99"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="javascript:cancel_confirmation(1, '../store/store_main.php'); needToConfirm = false;" value="Cancel" /></td>
            <td width="125"><input type="submit" name="new_button" class="imagebutton" id="new_button" value="New" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');" /></td>
            <td width="110"><input  name="finish_button" type="submit" class="imagebutton" id="finish_button" value="Finish" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');"  /></td>
          </tr>
        </table>
        </div>
  
  
</form>
</div>