<?php
session_start();
require("php_con.php");
require("check_user.php");

if(isset($_GET['bill_id'])&&isset($_GET['total_amount'])&&isset($_GET['payment'])){
	
	if($_GET['total_amount']==0){}
	else{
	
	if(mysqli_query($connation,"INSERT INTO sale_details(sale_details_billid, sale_details_payment, sale_details_user, sale_details_date, sale_details_time) VALUES ('$_GET[bill_id]','$_GET[payment]','$_COOKIE[user_id]','$current_date','$current_time')")){
		$sale_list_qury=mysqli_query($connation,"SELECT * FROM sale_list INNER JOIN product_details ON sale_list.sale_barcode=product_details.product_barcode WHERE sale_billid='$_GET[bill_id]'");
		while($sale_list_resalt=mysqli_fetch_array($sale_list_qury)){
			mysqli_query($connation,"INSERT INTO stock_details(stock_systemid, stock_qty, stock_type, stock_info, stock_addtime) VALUES ('$sale_list_resalt[product_systemid]','$sale_list_resalt[sale_qty]','0','POS update | Bill ID: $_GET[bill_id] | User: $current_user_resalt[user_fname]','$current_date $current_time')");
		}
	}
		
	}
		
}
?>