
<?php 
if ($_SESSION['job_card_no']=='') {
?>
<script language="javascript" type="text/javascript">
          needToConfirm = false;
          window.location="production_no_return.php";
</script>
<?php
}
else {
$table_name = $_SESSION['db_prefix']."_mworks_order_job_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);


$table_name = $_SESSION['db_prefix']."_mworks_order_job_lines_temp";
$line2_query = "SELECT *  FROM $table_name WHERE  user_name =  '".$_SESSION['username']."' AND store_item_id IS NULL";
$line2_result = mySQL_query($line2_query);
$line2_num = mysql_num_rows($line2_result);

$cust_id = $_SESSION['cust_id'];


$table_name = $_SESSION['db_prefix']."_mworks_job_components_temp";
$line3_query = "SELECT * FROM $table_name WHERE job_card_no = '".$_SESSION['job_card_no']."' AND  user_name = '".$_SESSION['username']."' ";  
$line3_result = mySQL_query($line3_query);
$line3_num = mysql_num_rows($line3_result);

?>


<!--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>
<?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">
<form id="feedbackform" method="get" action="m_compileJobWiz5.php" >
<div class="wizard_frame">
<?php 
include('../include/customer_block.php');
?>
</div> 
<div class="wizard_frame">
<table width="650" id="table_details_display">
    <tr>
      <td align="left" valign="top">Project:</td>
      <td colspan="2" align="left" valign="top"><?php  echo $_SESSION['project'];  ?></td>
      <td align="left" valign="top"><?php echo 'Job card no:&nbsp;&nbsp;'.$_SESSION['job_card_no'];  ?></td>
    </tr>
    <tr>
      <td align="left" valign="top">Project description:</td>
      <td colspan="3" align="left" valign="top"><?php  echo $_SESSION['project_description'];  ?></td>
      </tr>
    <tr>
      <td align="left" valign="top">Order date:</td>
      <td width="186" align="left" valign="top"><?php  echo date("d-m-Y", strtotime($_SESSION['order_date']));  ?></td>
      <td width="86" align="left" valign="top"></td>
      <td width="232" align="left" valign="top"></td>
    </tr>
    <tr>
      <td align="left" valign="top">Project period:</td>
      <td colspan="3" align="left" valign="top"> from: <?php  echo date("d-m-Y", strtotime($_SESSION['start_date']));?> to: <?php  echo date("d-m-Y", strtotime($_SESSION['end_date']));?> (inclusive)</td>
      </tr>
    <tr>
      <td width="126" align="left" valign="top">Project place:</td>
      <td colspan="3" align="left" valign="top"><?php echo $_SESSION['project_no'] ?>&nbsp;&nbsp;<?php echo $_SESSION['project_area']?>&nbsp;&nbsp;<?php echo $_SESSION['project_place']?></td>
      </tr>
    <tr>
      <td align="left" valign="top">Notes:</td>
      <td colspan="3" align="left" valign="top"><?php echo $_SESSION['quote_note'] ?>&nbsp;</td>
    </tr>
  </table>
</div>    
<div class="wizard_frame">
Project components:
  <table width="650" id="table_display">
        <?php
		
	  $i=0;
		while ($i<$line3_num) {
	       $component = mysql_result($line3_result, $i, "component");
		   $notes = mysql_result($line3_result, $i, "notes");
		   $quantity = mysql_result($line3_result, $i, "quantity");
		   
	  
		?>
  <tr>
    <td width="295"><?php echo $component ?></td>
    <td width="189"><?php echo $notes ?></td>
    <td width="90" align="center"><?php echo $quantity ?></td>
  </tr>
  <?php 
  $i++;
  }
  ?>
</table>
<br>
Project costs:
  <table width="650" id="table_display">
  <tr>
    <td width="295">Labor charges:</td>
    <td width="189">&nbsp;</td>
    <td width="90" align="right"><?php echo number_format($_SESSION['mworks_labour'], 2, '.', ',') ?></td>
  </tr>
</table>
<br>
Store items
<table width="650" id="table_display" >
          <tr>
            <td width="236" height="26" align="left" valign="top">Item</td>
            <td width="86" align="left" valign="top">Group</td>
            <td width="46" align="center" valign="top">Stock</td>
            <td width="36" align="center" valign="top">Unit</td>
            <td colspan="2" align="center" valign="top">Quantity</td>
            <td width="56" align="center" valign="top">Price</td>
            <td width="92" align="center" valign="top">Total</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");
					 if ($a1>100000) {
						$table_name = $_SESSION['db_prefix']."_store_items_special";
						$special_query = "SELECT item_name, quantity, price  FROM $table_name WHERE special_store_item_id = '".$a1."'  ";
						$special_result = mySQL_query($special_query);
						$a1a = mysql_result($special_result, 0, "item_name");
						$a7 = mysql_result($special_result, 0, "quantity");
						$a3 = mysql_result($special_result, 0, "price");
						$a3a='';
						$a4a='Special order';
						
					 }
					 if (($a1>0) AND ($a1<100000)) {
					 $table_name = $_SESSION['db_prefix']."_store_items";
						$item_query = "SELECT item_name, unit, subCategory, price, quantity, register FROM $table_name WHERE store_item_id = '".$a1."' ";
						$item_result = mySQL_query($item_query);
						$a1a = mysql_result($item_result, 0, "item_name");
						$a3 = mysql_result($item_result, 0, "price");
						$a3a = mysql_result($item_result, 0, "unit");
						$a7 = mysql_result($item_result, 0, "quantity");
						$a4a = mysql_result($item_result, 0, "subCategory");
						$unit = mysql_result($item_result, 0, "unit");
						$a20 = mysql_result($item_result, 0, "register");
						
					 }
					 
					 if ($a1==0) {
					   $a1a = mysql_result($line_result, $i, "item_name");
					   $a3 = mysql_result($line_result, $i, "price");
					   $a3a='';
					   $a4a = 'To order';
					   $a7='';
					   
					 }
					 
					 $a2 = mysql_result($line_result, $i, "quantity");
					 $a21='no';
					 if ($a20=='yes') { 
					   if ($a2>1) { 
					        $a2=1;
							$a21='yes';
							$table_name = $_SESSION['db_prefix']."_mworks_order_job_lines_temp";
							$correct_query = "UPDATE $table_name SET quantity = '1' WHERE user_name =  '".$_SESSION['username']."' AND store_item_id = '".$a1."'";
							execsql($correct_query);
							}
					 }
					 
					 
					$a5=$a2*$a3;
					$sub_total_2=$sub_total_2+$a5;
					
					if ($a2>$a7) {$no_stock='yes';} else {$no_stock='no';} 
				 ?>
          <tr>
            <td valign="top"><?php echo $a1a ?></td>
            <td valign="top"><?php echo $a4a ?></td>
            <td align="center" valign="top"><?php if ($a3a!='no') {if ($a7!='') { echo number_format($a7, 2, '.', ',');} }?></td>
            <td valign="top"><?php echo $a3a ?></td>
            <td width="36" align="center" valign="top"><?php if ($a3a!='no') {echo number_format($a2, 2, '.', ',');} else { echo number_format($a2, 0, '.', ','); } ?></td>
            <td width="26" align="center" valign="top"><?php if ($no_stock=='yes') { ?> <a href="" onMouseover="ddrivetip('Not sufficient stock available for this item.', 200)"; onMouseout="hideddrivetip()"><img src="../images/exclamation_mark_red_small.png" width="10" height="16"></a> 
            <?php } ?>
            <?php if ($a21=='yes') { ?>
              <a href="" onMouseover="ddrivetip('Maximum delivery for this item is 1 per line.<br>To supply multiple items, use a new line.', 220)"; onMouseout="hideddrivetip()"><img src="../images/exclamation_mark_red_small.png" width="10" height="16"></a>
              <?php } ?>
            &nbsp;</td>
            <td align="right" valign="top"><?php echo $a3?></td>
            <td align="right" valign="top"><?php echo number_format($a5, 2, '.', ',');?></td>
            </tr>
          <?php 
			   // $a6_total=$a6_total+$a6;
				$i++;
				 }
				 ?>
          <tr>
            <td colspan="7" align="left" valign="top">Sub total:</td>
            <td align="right" valign="top"><?php echo number_format($sub_total_2, 2, '.', ',') ?></td>
            </tr>
          </table>
        <br>
      <table width="650"  id="table_display" >
        <tr>
        <td width="184">M-works project total:&nbsp;<?php $_SESSION['all_total'] = $_SESSION['mworks_labour'] + $sub_total_2 ; ?></td>
        <td width="62" align="left">Estimated:</td>
        <td width="162" align="right"><?php echo number_format($_SESSION['mworks_charge'], 2, '.', ',')?></td>
        <td width="104" align="right"><?php if ($_SESSION['all_total'] > $_SESSION['mworks_charge']) {?>
          <a href=" " onMouseOver="ddrivetip('The value is higher than the order value.', 200)"; onMouseOut="hideddrivetip()"><img src="../images/exclamation_mark_red_small.png" width="10" height="16"></a>
          <?php } ?>Actual:</td>
        <td width="114" align="right"><?php echo number_format($_SESSION['all_total'], 2, '.', ',') ?></td>
      </tr>
</table>
      <p>&nbsp;</p>
</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 />
            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','m_compileJobWizbase.php?s=&p=3&preset=2&preset_list_name=');return document.MM_returnValue" /></td>
            <td width="115">&nbsp;</td>
            <td width="99">&nbsp;</td>
            <td width="125"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="javascript:cancel_confirmation(1, '../production/production_main.php'); needToConfirm = false;" value="Cancel" /></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>
</body>

<?php
}
?>