
<?php
$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_jobs";
$charges_query = "SELECT value, labour_charge, labour_charge_final,  mworks_charge, mworks_charge_final, captured, compiled, invoiced     FROM $table_name WHERE job_card_no =  '".$_SESSION['job_card_no']."' ";
$charges_result = mySQL_query($charges_query);
$charges_num = mysql_num_rows($charges_result);
$labour_charge = mysql_result($charges_result, 0, "labour_charge");
$mworks_charge = mysql_result($charges_result, 0, "mworks_charge");
$order_value = mysql_result($charges_result, 0, "value");
?>

<!--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_completeJobWiz5.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">Delivery date:</td>
      <td colspan="3" align="left" valign="top"><?php  echo date("d-m-Y", strtotime($_SESSION['deliver_date']));  ?></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"><br>
  <table width="650" id="table_display" >
    <tr>
      <td height="26" align="left" valign="middle">Expense</td>
      <td width="116" align="center" valign="middle">Estimated</td>
      <td width="106" align="center" valign="middle">Actual</td>
      <td width="100" align="center" valign="middle">+/-</td>
    </tr>
    <tr>
      <td valign="middle">Parts costs:</td>
      <td align="right" valign="middle"><?php echo number_format($_SESSION['a4tot'], 2, '.', ',') ?></td>
      <td align="right" valign="middle"><?php echo $_SESSION['a8tot'] ?></td>
      <td align="right" valign="middle"><?php echo number_format($_SESSION['a10tot'], 2, '.', '') ?></td>
    </tr>
    <tr>
      <td valign="middle">M-works labour:</td>
      <td align="right" valign="middle"><?php if ($labour_charge!='') {echo number_format($labour_charge, 2, '.', ',');} ?></td>
      <td align="right" valign="middle"><?php echo $_SESSION['labour_adjust'] ?></td>
      <td align="right" valign="middle"><?php $labour_charge_dif = $_SESSION['labour_adjust'] - $labour_charge; ?>
        <input type="text" name="labour_charge_dif_text" id="labour_charge_dif_text" value="<?php echo number_format($labour_charge_dif, 2, '.', '')?>" readonly style="text-align:right; border:hidden;" ></td>
    </tr>
    <tfoot>
      <tr>
        <td colspan="2" align="left" valign="middle">Adjustment:&nbsp;&nbsp;<?php echo $_SESSION['adjustment_text'] ?></td>
        <td align="right" valign="middle"><?php echo number_format($_SESSION['adjustment'], 2, '.', '') ?></td>
        <td align="right" valign="middle"><input type="text" name="adjustment_dif_text" id="adjustment_dif_text"   value="<?php echo $_SESSION['adjustment_dif'] ?>" class="text100" readonly style="text-align:right; border:hidden; " ></td>
      </tr>
      <tr>
        <td align="left" valign="middle"><?php $_SESSION['estimated_total'] = $_SESSION['a4tot']+$labour_charge?>
          <?php // $_SESSION['invoiced_total'] = $_SESSION['a8tot']+$_SESSION['labour']+$_SESSION['travel']+$_SESSION['accomodation']+$_SESSION['mworks_charge']?>
          <?php $dif_total = $_SESSION['a10tot']+$labour_charge_dif?></td>
        <td align="left" valign="middle">&nbsp;</td>
        <td align="left" valign="middle">&nbsp;</td>
        <td align="right" valign="middle">&nbsp;</td>
      </tr>
      <tr>
        <td align="left" valign="middle">Totals:</td>
        <td align="right" valign="middle"><?php echo number_format($_SESSION['estimated_total'], 2, '.', ',') ?></td>
        <td align="right" valign="middle"><?php echo number_format($_SESSION['invoiced_total'], 2, '.', '') ?></td>
        <td align="right" valign="middle"><input type="text" name="total_dif_text" id="total_dif_text" class="text100"  value="<?php echo $_SESSION['total_dif'] ?>" readonly style="text-align:right; border:hidden;"></td>
      </tr>
      <tr>
        <td align="left" valign="middle">&nbsp;</td>
        <td align="right" valign="middle">&nbsp;</td>
        <td align="right" valign="middle">&nbsp;</td>
        <td align="right" valign="middle">&nbsp;</td>
      </tr>
      <tr>
        <td align="left" valign="middle">Order value:
          <input type="hidden" name="order_value_text" id="order_value_text" value="<?php echo $order_value ?>">
          <?php echo number_format($order_value, 2, '.', ',') ?></td>
        <td align="right" valign="middle"><?php if ($_SESSION['estimated_total']>0) {$est_prof = (($order_value / $_SESSION['estimated_total']) *100)-100;} else {$est_prof=0;} echo number_format($est_prof, 2, '.', ',').'%'; ?></td>
        <td align="right" valign="middle"><?php if($_SESSION['invoiced_total']>0) {$act_prof = (($order_value / $_SESSION['invoiced_total']) *100)-100;} else {$act_prof=0;} ?><?php echo number_format($act_prof, 2, '.', ',')?></td>
        <td align="left" valign="middle">%</td>
      </tr>
    </tfoot>
  </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 />
            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_completeJobWizbase.php?s=&p=3');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>