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

$sql = "INSERT INTO mobileagency_stock_transfer_notes (tr_agency, tr_amount, tr_user,tr_date)
VALUES ('$agency', '$total_amount', '$user_id','$today')";

if ($conn->query($sql) === TRUE) {
	$last_id = $conn->insert_id;
	echo $last_id;
	$sql2 = "UPDATE mobileagency_stock SET stock_transfer_order='$last_id' WHERE stock_transfer_order=0 AND transfer_by='$user_id' AND agency_id='$agency' ";
	if ($conn->query($sql2) === TRUE) {
		//echo $last_id;
	}

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

$conn->close();

?>