<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php
include('../include/session.php');
require_once('../include/tc_calendar.php');

$edit_date = date("Y-m-d");
$edit_date = strtotime($edit_date);
$d = date("d", $edit_date ) ;
$m = date("m", $edit_date ) ;
$y = date("Y", $edit_date ) ;

$void = $_GET['void'];

if ($void==1) {
	  $job_card_no = $_GET['job_card_no'];
}

if ($void==0) {	
$table_name = $_SESSION['db_prefix']."_mworks_jobs";
$jobQuery = "SELECT job_card_no, cust_id  FROM $table_name WHERE captured='yes' AND supplied IS NULL AND mworks = 'only' ORDER BY job_card_no DESC";
$jobResult = execsql($jobQuery);
$jobNum = mysql_num_rows($jobResult);
	$w = 0;
	$arrId4 = array ();
	$arrName4 = array ();
	while ($w < $jobNum) {
		$cust_id = mysql_result($jobResult, $w, "cust_id"); 
		$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT * FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$a1 = mysql_result($customer_result, 0, "account_type");
			if ($a1=="corporate") { 
				$cust_name = mysql_result($customer_result, 0, "comp_name"); 
			} 
			else {
				$cust_name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 			}
		
		
		
		$arrId4[$w] = mysql_result($jobResult, $w, 'job_card_no');
		$arrName4[$w] = mysql_result($jobResult, $w, 'job_card_no').' '.$cust_name;
		$w++;
	}
}


if ($void==1) {	
$table_name = $_SESSION['db_prefix']."_compiled_jobs";
$job_query = "SELECT cust_id, date, project, project_no, project_area, project_place, project_description, value, mworks FROM $table_name WHERE job_card_no = '".$job_card_no."' ";
$job_result = mySQL_query($job_query);
$cust_id = mysql_result($job_result, 0, "cust_id");
$date = mysql_result($job_result, 0, "date");
$project = mysql_result($job_result, 0, "project");
$project_no = mysql_result($job_result, 0, "project_no");
$project_area = mysql_result($job_result, 0, "project_area");
$project_place = mysql_result($job_result, 0, "project_place");
$project_description = mysql_result($job_result, 0, "project_description");
$value = mysql_result($job_result, 0, "value");
$mworks = mysql_result($job_result, 0, "mworks");


$table_name2 = $_SESSION['db_prefix']."_customer";
$customer_query = "SELECT account_type, title, name_2, comp_name FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
$customer_result = mySQL_query($customer_query);
$customer_num = mysql_num_rows($customer_result);	
$account_type = mysql_result($customer_result, 0, "account_type");
	if ($account_type=="corporate") { 
			$cust_name = mysql_result($customer_result, 0, "comp_name"); 
	} 
	else {
			$cust_name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 	}
	
$mworks_supply = 'no';
if ($mworks=='yes') {
		$table_name = $_SESSION['db_prefix']."_mworks_jobs";
		$mworks_query = "SELECT supplied FROM $table_name WHERE job_card_no = '".$job_card_no."'   ";
		$mworks_result = mySQL_query($mworks_query);
		$mworks_num = mysql_num_rows($mworks_result);
		$supplied = mysql_result($mworks_result, 0, "supplied");
		
		if (($supplied=='yes') OR ($supplied=='part')) {
			    $mworks_supply = 'yes';
		}
		else {
			$mworks_supply = 'no';
		}
}

}
?>


<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script>
<script type="text/javascript">
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
</script>
</head>

<body>
<?php
include ("../navigation/header.php");
$page_name = "Production-void job card";
include ("../navigation/access.php");
if ($permission_num==1) {
	include ("../navigation/orders_sidebar.php");
?>
<div class="main_frame">
<div class="page_head_frame">
        <table width="630" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="385"><label class="label_page_head">Void job card</label></td>
            <td align="right">&nbsp;</td>
          </tr>
        </table>
      </div>

<div class="page_middle_frame"><br />
<?php if ($void==0) { ?>
<div class="page_inside_frame">
  <label class="label_std" style="font-size:16px;">
 <div> <img src="../images/exclamation_mark_red_small.png" width="10" height="16"><label class="label_warning">Warning: voiding a job cannot be undone..</label></div> 
<br><div align="left">
<img src="../images/info_green.png" width="16" height="16">
<label class="label_info">Only jobs on which there are no deliveries can be voided.</label>          
</div>

<br>
  Select the job to void below:</label>
  <br />
  <br />
  <form action="" method="get">
    <select name="job_select" autofocus class="selectbox300" id="vehicle_select" onchange="window.location.href= this.form.job_select.options[this.form.job_select.selectedIndex].value"> 
      <option value=" " selected="selected" >&nbsp;</option>
      <?php
    	for ($j = 0; $j < count($arrId4); $j++) {
			echo "<option value=m_void_job_card.php?void=1&job_card_no=".$arrId4[$j].">".$arrName4[$j]."</option>";	
		}
     ?>
    </select>
  </form>
<br />
</div>
<?php } ?>


<?php if ($void==1) { ?>
<div class="page_inside_frame">
Job card to void:
  <table width="600" id="table_display" >
  <tr>
    <td width="143">Job card no:</td>
    <td width="457"><?php echo $job_card_no ?></td>
  </tr>
  <tr>
    <td>Customer:</td>
    <td><?php echo $cust_name ?></td>
  </tr>
  <tr>
    <td>Project:</td>
    <td><?php echo $project ?></td>
  </tr>
  <tr>
    <td>Address:</td>
    <td><?php echo $project_no.'  '.$project_area?></td>
  </tr>
  <tr>
    <td>Place</td>
    <td><?php echo $project_place ?></td>
  </tr>
  <tr>
    <td>Project description:</td>
    <td><?php echo $project_description ?>
  <tr>
    <td>M-works job attached:</td>
    <td><div><?php echo $mworks; if ($mworks_supply=='yes') {?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="../images/exclamation_mark_red_small.png" width="10" height="16"><label class="label_warning">Material has been supplied on this M-works job.</label></div> <?php } ?> </td>
  </tr>
  </table>

<?php if ($mworks_supply=='yes') { ?><br>
<br>

<div> <img src="../images/exclamation_mark_red_small.png" width="10" height="16"><label class="label_warning" style="font-size:14px; color:#F00; font-weight:bold;">
Material on the attached M-works job has been supplied. This job cannot be voided.
</label></div> 
<?php } ?>

<?php if ($mworks_supply=='no') { ?>
<br>
<br>
<?php if ($mworks=='yes') { ?>
<div> <img src="../images/exclamation_mark_red_small.png" width="10" height="16"><label class="label_warning" style="font-size:14px; color:#F00; font-weight:bold;">
The attached M-works job card will be voided too.
</label></div> 
<?php } ?>
<br>
Click the void button to void this job card: <input name="void_button" type="button" value="Void job card" class="imagebutton" onClick="cancel_confirmation(7, '../production/m_void_job_card_save.php?job_card_no=<?php echo $job_card_no ?>');">
<input type="hidden" name="job_card_no" id="job_card_no" value="<?php echo $job_card_no ?>">
&nbsp;&nbsp;&nbsp;
<input name="cancel_button" type="button" class="imagebutton" id="cancel_button" onClick="MM_goToURL('parent','production_main.php');return document.MM_returnValue"  value="Cancel &amp; close"/>

<?php } ?>
</div>
<?php } ?>


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


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

</body>
</html>