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


	
//collect reasons for cancelation


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

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

//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.
		_('Reasons for Cancellation .  ') . '" /> ' .// Icon title.
		_('Please this process needs to be done by your manager') . '</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">';



echo '<tr>
			<td>' ._('Enter Reasons'). ':</td>
			<td><input tabindex="'.$j.'" type="text" maxlength="10" size="15" required="required" name="reason"  /></td>
		</tr>';

echo '</td>';

echo '<input type="submit" name="reversal" value="' ._('Process Reversal') . '" />
		</div>
		';



echo '</div>';

echo '</div>';

$reasons = $_POST['reason'];

if (isset($_POST['reversal']) && ($_POST['reason'] == $reasons )){
$sql40 =  "UPDATE debtortrans set cancelled ='1', cancelled_by = '" . $userid. "',cancel_reason = '" . $reasons. "'
				WHERE transno = '" . $InvoiceNo. "'";

	$ErrMsg = _('This customer could not be added because');
			$result40 = DB_query($sql40,$ErrMsg);



	$sql41 =  "UPDATE salesorders set cancelled ='1', cancelled_by = '" . $userid. "',cancel_reason = '" . $reasons. "'
				WHERE orderno = '" . $orderno. "'";

	$ErrMsg = _('This customer could not be added because');
			$result41 = DB_query($sql41,$ErrMsg);
		
// reverse entries in debtortrans, debtortrans tax and gl entries 

$message = "This invoice has been cancelled!";
	echo "<script type='text/javascript'>alert('$message');</script>";
		echo "<script type='text/javascript'>javascript:history.go(-2)</script>"; 
	exit();


			
		
}
		
			
		

		
		
			    
		
	


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

?>
