<?php 
session_start();
$id=$_SESSION['id'];
$branch=$_SESSION['branch'];	

include('../dist/includes/dbcon.php');

	$cid = $_POST['cid'];
	$cat = $_POST['cat'];
	$name = $_POST['prod_name'];
	$qty = $_POST['qty'];
	$hh = $_POST['hh'];
	$ww = $_POST['ww'];
	$variation = $_POST['variation'];
	$colorb = $_POST['colorb'];
		
			
		$query=mysqli_query($con,"select prod_price,prod_price2,prod_desc,prod_price3,prod_id,cm,cmm from product where prod_id='$name'")or die(mysqli_error());
		$row=mysqli_fetch_array($query);
		$price=$row['prod_price'];
		$price2=$row['prod_price2'];
		$price3=$row['prod_price3'];
		$cm=$row['cm']?? null;
		$cmm=$row['cmm']?? null;
		$prod_desc=$row['prod_desc'];
		$prod_color=$row['prod_color']?? null;
		$colorko=$colorb;
		$query1=mysqli_query($con,"select * from temp_trans where prod_id='$name' and cust_id='$cid'")or die(mysqli_error());
		$count=mysqli_num_rows($query1);
		
		$game=$hh/$cm;
		$game1=$ww/$cmm;
		
		if($cat = 1){
			$newpeice=$price;
		}if($cat = 2){
			$newpeice=$price2;
		}if($cat = 3){
			$newpeice=$price3;
		}
		
		$total=$newpeice*$qty;
		$ann=$total * $game;
		$antotal=$ann * $game1;
		if ($count>0){
			mysqli_query($con,"update temp_trans set qty=qty+'$qty',price=price+'$total' where prod_id='$name' and branch_id='$branch'")or die(mysqli_error());
	
		}
		else{
			mysqli_query($con,"INSERT INTO temp_trans(prod_id,cust_id,qty,price,branch_id,hh,ww,variation,color) VALUES('$name','$cid','$qty','$antotal','$branch','$hh','$ww','$prod_desc','$colorko')")or die(mysqli_error($con));
		}

	
		echo "<script>document.location='cash_transaction.php?cid=$cid&cat=$cat'</script>";  
	
?>