
<?php

if ($_SESSION['maintenance_card_no']=='') {
?>
<script language="javascript" type="text/javascript">
          needToConfirm = false;
          window.location="maintenance_no_return.php";
</script>
<?php
}
else {

$table_name = $_SESSION['db_prefix']."_maintenance_jobs";
$job_query = "SELECT * FROM $table_name WHERE maintenance_card_no = '".$_SESSION['maintenance_card_no']."' ";
$job_result = mySQL_query($job_query);

$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");
$maintenance_no = mysql_result($job_result, 0, "maintenance_no");
$cycle_no = mysql_result($job_result, 0, "cycle_no");
$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");


$table_name = $_SESSION['db_prefix']."_maintenance_jobs";
$charges_query = "SELECT maintenance_no, value, call_out_charge, call_out_charge_final,  additional_charge, additional_charge_final, compiled, invoiced FROM $table_name WHERE maintenance_card_no =  '".$_SESSION['maintenance_card_no']."' ";
$charges_result = mySQL_query($charges_query);
$charges_num = mysql_num_rows($charges_result);
$call_out_charge = mysql_result($charges_result, 0, "call_out_charge");
$additional_charge = mysql_result($charges_result, 0, "additional_charge");
$order_value = mysql_result($charges_result, 0, "value");
?>

</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="maintenance_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 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 $_SESSION['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="161" align="left" valign="top"><?php  echo date("d-m-Y", strtotime($order_date));  ?></td>
      <td width="151" align="left" valign="top"><?php  echo 'Job value'; ?></td>
      <td width="197" 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="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['a8tot'], 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">Call out charge:</td>
      <td align="right" valign="middle"><?php if ($call_out_charge!='') {echo number_format($call_out_charge, 2, '.', ',');} ?></td>
      <td align="right" valign="middle"><?php echo $_SESSION['call_out_adjust'] ?></td>
      <td align="right" valign="middle"><?php $call_out_dif = $_SESSION['call_out_adjust'] - $call_out_charge; ?>
        <?php echo number_format($call_out_dif, 2, '.', '')?></td>
    </tr>
    <tfoot>
      <tr>
        <td align="left" valign="middle">Additional charge:</td>
        <td align="right" valign="middle"><?php if ($call_out_charge!='') {echo number_format($additional_charge, 2, '.', ',');} ?></td>
        <td align="right" valign="middle"><?php echo $_SESSION['additional_adjust'] ?></td>
        <td align="right" valign="middle"><?php $additional_dif = $_SESSION['additional_adjust'] - $additional_charge; ?>
          <?php echo number_format($additional_dif, 2, '.', '')?></td>
      </tr>
      <tr>
        <td colspan="2" align="left" valign="middle">Adjustment:
          <?php echo $_SESSION['adjustment_text'] ?></td>
        <td align="right" valign="middle"><?php echo number_format($_SESSION['adjustment'], 2, '.', '') ?></td>
        <td align="right" valign="middle"><?php  echo $_SESSION['adjustment_dif']?></td>
      </tr>
      <tr>
        <td align="left" valign="middle"><?php $_SESSION['estimated_total'] = $_SESSION['a8tot']+$call_out_charge+$additional_charge?>
          <?php $_SESSION['invoiced_total'] = $_SESSION['a8tot']+$_SESSION['call_out_adjust']+$_SESSION['additional_adjust']+ $_SESSION['adjustment']?>
          <?php $dif_total = $_SESSION['a10tot']+$call_out_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"><?php echo number_format($_SESSION['total_dif'], 2, '.', '') ?></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:
          <?php echo number_format($order_value, 2, '.', ',') ?></td>
        <td align="right" valign="middle"><?php $est_prof = (($order_value / $_SESSION['estimated_total']) *100)-100; echo number_format($est_prof, 2, '.', ',').'%'; ?></td>
        <td align="right" valign="middle"><?php $act_prof = (($order_value / $_SESSION['invoiced_total']) *100)-100; ?>
          <?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','maintenance_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, '../maintenance/maintenance_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>

<?php
}
?>