<?php 
session_start();
if(empty($_SESSION['id'])):
header('Location:../index.php');
endif;
include('../dist/includes/dbcon.php');

date_default_timezone_set('Asia/Manila');
	$myid = $_SESSION['id'];
	$cid = $_POST['cid'];	
	$sid = $_POST['myssid'];
	$void = $_POST['void'];
	$balance = $_POST['balance'];
	date_default_timezone_set("Asia/Manila"); 
	$date = date("Y-m-d");
	$id = $_SESSION['id'];
	$date1 = date("Y-m-d H:i:s");
	$query2=mysqli_query($con,"select * from user where user_id='6' ")or die(mysqli_error($con));
    $row2=mysqli_fetch_array($query2);	
	$gamevoid=$row2['void'];
	
	$query3=mysqli_query($con,"select * from user where user_id='9'")or die(mysqli_error($con));
    $row3=mysqli_fetch_array($query3);	
	$gamevoid2=$row3['void'];
	
	if($void == $gamevoid){

	$query1=mysqli_query($con,"select * from sales where sales_id='$sid'")or die(mysqli_error($con));
    $row1=mysqli_fetch_array($query1);	
	$mypayment=$row1['partial1']; 

mysqli_query($con,"UPDATE customer SET balance=balance+'$mypayment' where cust_id='$cid'") or die(mysqli_error($con)); 

$result=mysqli_query($con,"DELETE FROM sales WHERE sales_id ='$sid'")
	or die(mysqli_error());
$result=mysqli_query($con,"DELETE FROM payment WHERE sales_id ='$sid'")
	or die(mysqli_error());
	$result=mysqli_query($con,"DELETE FROM sales_details WHERE sales_id ='$sid'")
	or die(mysqli_error());
		$name="WALKIN";
		$remarks="Delete payment of $mypayment  trans ID $sid for $name";  
	
		mysqli_query($con,"INSERT INTO history_log(user_id,action,date) VALUES('$id','$remarks','$date')")or die(mysqli_error($con));
		echo "<script type='text/javascript'>alert('Successfully added payment!');</script>";
		echo "<script>document.location='account_summary.php?cid=$cid'</script>";
	}else if ($void == $gamevoid2){
		$query1=mysqli_query($con,"select * from sales where sales_id='$sid'")or die(mysqli_error($con));
    $row1=mysqli_fetch_array($query1);	
	$mypayment=$row1['partial1']; 

mysqli_query($con,"UPDATE customer SET balance=balance+'$mypayment' where cust_id='$cid'") or die(mysqli_error($con)); 

$result=mysqli_query($con,"DELETE FROM sales WHERE sales_id ='$sid'")
	or die(mysqli_error());
$result=mysqli_query($con,"DELETE FROM payment WHERE sales_id ='$sid'")
	or die(mysqli_error());
	$result=mysqli_query($con,"DELETE FROM sales_details WHERE sales_id ='$sid'")
	or die(mysqli_error());
		$name="WALKIN";
		$remarks="Delete payment of $mypayment  trans ID $sid for $name";  
	
		mysqli_query($con,"INSERT INTO history_log(user_id,action,date) VALUES('$id','$remarks','$date')")or die(mysqli_error($con));
		echo "<script type='text/javascript'>alert('Successfully added payment!');</script>";
		echo "<script>document.location='account_summary.php?cid=$cid'</script>";

		
	}else{	
	
echo "<script type='text/javascript'>alert('ADMIN VOID CODE ERROR!');</script>";
		echo "<script>document.location='account_summary.php?cid=$cid'</script>";
	}		
				
    						
   
	
?>