<?php
session_start();
require_once 'db_connection.php'; 
$total_amount = $_POST['total_amount'];
$cusname = $_POST['cusname'];
$branch_id = $_POST['branch_id'];
$user_id = $_SESSION['user_id'];
$today = date('Y-m-d H:i:s');

$sql = "INSERT INTO quotations (q_customer,q_amount, q_user, q_date)
VALUES ('$cusname','$total_amount', '$user_id', '$today')";

if ($conn->query($sql) === TRUE){
	$last_id = $conn->insert_id;
	echo $last_id;

	$sql = "INSERT INTO `tbl_quatation_other_details`(`quatition_other_id`, `q_id`, `branch_id`) VALUES (null,'$last_id','$branch_id')";
		if($conn->query($sql) === TRUE){
		  
			$sql2 = "UPDATE quotation_items SET qi_no='$last_id' WHERE qi_no=0 AND qi_user='$user_id'";
			if ($conn->query($sql2) === TRUE) {
				
			}

		}else{
		  echo "Error: " . $sql . "<br>" . $conn->error;
		}


	



} else {
	echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();

?>