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

include('../dist/includes/dbcon.php');
	//$result=mysqli_query($con,"DELETE FROM stockout WHERE stockout_id ='$id'")or die(mysqli_error());
$salesid = $_POST['salesid'];
	$total =$_POST['total'];
	
	$amount_due =$_POST['amount_due'];
	$discount =$_POST['discount'];
	$tendered =$_POST['tendered'];
	$change =$_POST['changeko'];
	$custid =$_POST['custid'];
	$myidcust =$_POST['myidcust'];
	$query1=mysqli_query($con,"select * from sales where sales_id='$salesid'")or die(mysqli_error());
	$row4=mysqli_fetch_array($query1);
	if($row4['cash_change'] < 0){
		
		$jamjam=$row4['cash_change'];
	}else{
		$jamjam= 0;
	}
	$gake= $jamjam * -1;

	mysqli_query($con,"update sales set modeofpayment='partial', partial1='$tendered', status='today', user_id='$myidcust' where sales_id='$salesid'")or die(mysqli_error());
	mysqli_query($con,"update payment set status='paid', user_id='$myidcust' where sales_id='$salesid'")or die(mysqli_error());
	mysqli_query($con,"update customer set balance=balance+'$gake' where cust_id='$custid'")or die(mysqli_error());
	
	
	
	//09503677571
	
	echo "<script>document.location='receiptfinal.php?sales_id=$salesid'</script>";  

	
?>