<?php
ob_start();
include('includes/session.inc');
$Title = _('Create Invoice');
include('includes/SQL_CommonFunctions.inc');


	
//collect reasons for cancelation


	
	
if (isset($_GET['dispatchid'])) {
		$_SESSION['dispatchid'] = stripslashes($_GET['dispatchid']);
	}
	$dispatchid= $_SESSION['dispatchid'];


//first check whether this costing is approved or not
	$quotedated = date('Y-m-d');
		$quotedate = date('d-m-Y');
$yeardate = date('Y');
$monthdate =date('m');

					$userid = $_SESSION['UserID'];

include('includes/newheader.php');
echo '<p> </p> <p></p><p class="page_title_text"><img alt="" src="'.$RootPath.'/css/'.$Theme.
		'/images/printer.png" title="' .// Icon image.
		_('Confirmation on your jobs where it should be pulled to.  ') . '" /> ' .// Icon title.
		_('Confirmation on your jobs where it should be pulled to.') . '</p>';// Page title.
echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">';
	echo '<div class="col-sm-12">';// div class=?
	echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<table class="table">';


$SQL = "SELECT technician_worksheet.id,technician_worksheet.projectid,projectdetails.project_name
		FROM technician_worksheet
		INNER JOIN projectdetails on technician_worksheet.projectid = projectdetails.projectid
				
		ORDER BY id DESC";

$ErrMsg = _('The bank accounts could not be retrieved because');
$DbgMsg = _('The SQL used to retrieve the bank accounts was');
$AccountsResults = DB_query($SQL,$ErrMsg,$DbgMsg);


echo '
	<tr>
		<td>' . _('Technician Job') . ':</td>
		 <td><select name="techjob" required = "required">';


	
	while ($myrow=DB_fetch_array($AccountsResults)){
		/*list the bank account names */
	
			echo '<option value="' . $myrow['id'] . '">' . $myrow['id'].'-'. $myrow['projectid']. ' - ' . $myrow['project_name'] . '</option>';
		
	}
	echo '</select></td>
		</tr>';



echo '<input type="submit" name="reversal" value="' ._('Pull to Materials') . '" />
		</div></form>
		';



echo '</div>';

echo '</div>';

$reasons = $_POST['reason'];

if (isset($_POST['reversal'])){
	
	
	//before canceling this invoice unallocate invoices if there are any allocations
	
			
$SQL1 = "SELECT stockrequestitems.stockid,stockrequestitems.qtydelivered,stockmaster.description
					  
		          FROM  stockrequestitems
				  INNER JOIN stockmaster on stockmaster.stockid = stockrequestitems.stockid
				 WHERE dispatchid ='".$dispatchid."'";		  
				   

	$ErrMsg =_('The bank account name cannot be retrieved because');
	$result1= DB_query($SQL1,$ErrMsg);
	
while ($myrow1 = DB_fetch_array($result1)){
	
	
	 $query11 = "INSERT into technician_worksheet_materials set  id = '".$_POST['techjob']."',
			 									 stockrequest_id = '".$dispatchid."',
					  							 stockid= '".$myrow1['stockid']."',
												  narrative= '".$myrow1['description']."',
												 qty = '".$myrow1['qty']."'";
												
	
$result11= DB_query( $query11);
	
	
}

	
	
$message = "This request no:".$dispatchid."has been added to your material section.";
	echo "<script type='text/javascript'>alert('$message');</script>";
		echo "<script type='text/javascript'>javascript:history.go(-2)</script>"; 
	exit();


			
		
}
		
			
		

		
		
			    
		
	


//include('includes/footer.inc'); 

?>
