<?
require_once('functions.php');
   $dbc=mysqli_connect("localhost","root","","point_of_sale");

if($_POST['submitted']){
$id=$_POST['id'];
$user=$_SESSION['user'];
$status=$_POST['sure'];
if($id){
if($status=='Yes'){

$name=mysqli_real_escape_string($dbc,($_POST['name']));
$vt=mysqli_query($dbc,("select p_name,session,number,type from sales where sale_id='$id'"));
$by=mysqli_fetch_array($vt);
   $typ=$by['type'];
   $sess=$by['session'];
   $num=$by['number'];
      $nam=$by['p_name'];
	    if($typ=='INVOICE'){
			$fq="delete from ledgers where description='$nam' and invoice='$num' and session='$sess'";
			   $da=mysqli_query($dbc,$fq);
		}
$t="delete from sales where sale_id='$id'";
$tt=mysqli_query($dbc,$t);

}


}


$url='sale_r.php';
ob_end_clean();
header("Location: $url");
}
	$type='DELETE PRODUCTS';
						//if(Rights($_SESSION['user_id'],$type,$_SESSION['department'])){	

//require_once('conf.php');
$id = $_GET['id'];
$r=mysqli_query($dbc,("select * from sales where sale_id='$id'"));
$row=mysqli_fetch_array($r);
 echo '<form action="del_p.php"method="post">
 <h3>Product Name: ' . $row['p_name'] . '</h3>
 <p><b>Are you sure you want to Delete  This Transaction?<br />
 <input type="radio" name="sure"
value="Yes" /> Yes
 <input type="radio" name="sure" value=
"No" checked="checked" /> No</p>
 <p><input type="submit" name="submit"
value="Delete Transaction" /></p>
 <input type="hidden" name="submitted"
value="TRUE" />
 <input type="hidden" name="name" value="'
. $row['p_name'] . '" />
 <input type="hidden" name="id" value="'
. $id . '" />
 </form>';
 
//}else{
	//											   LackRights();
		//										   }


 ?>
 