<?php
	//Connects to your Database
	include "../db_connection/db_connection.php";
	include "../config/config.php";		
	
	$guest_id	=	base64_decode(base64_decode(base64_decode($_GET['guest_id'])));
		
	$SLCT_sk = "SELECT COUNT(party_det_id) as max_ids FROM party_det ORDER BY party_det_id ASC";
	$QURY_sk = mysqli_query($connect,$SLCT_sk);  
	$FTCH_sk = mysqli_fetch_object($QURY_sk);
	$max_id_p = $FTCH_sk->max_ids + 1;
	
	$p_code = sprintf("D-"."%03d",$max_id_p);
		
	$SLCT = "SELECT * FROM guest_user WHERE guest_id = '$guest_id'";
	$QURY = mysqli_query($connect,$SLCT);
	$FTCH = mysqli_fetch_object($QURY);
	
	$INSRT		= "INSERT INTO party_det(`party_code`, `cmp_name`, `con_pers_1`,`con_no_1`, `con_ln_no_1`,`com_addr`,`email_id_1`,`post_dt`) VALUES
	 ('$p_code','$FTCH->cmp_name','$FTCH->con_pers_1','$FTCH->con_no_1','$FTCH->con_ln_no_1','$FTCH->com_addr','$FTCH->email_id_1','$cur_time')";
	$QURY		= mysqli_query($connect,$INSRT);
	
	$SLCT_sk = "SELECT MAX(party_det_id) as max_ids FROM party_det ORDER BY party_det_id ASC";
	$QURY_sk = mysqli_query($connect,$SLCT_sk);  
	$FTCH_sk = mysqli_fetch_object($QURY_sk);
	$max_id = $FTCH_sk->max_ids;
	
	
	$SLCTc = "SELECT  * FROM master_cat ORDER BY master_cat_id ASC";
	$QURYc = mysqli_query($connect,$SLCTc);
	while($FTCHc = mysqli_fetch_object($QURYc))
	{						
		$INSRT_d	= "INSERT INTO party_cost_det(`party_det_id`, `master_cat_id`,`post_dt`) VALUES('$max_id','$FTCHc->master_cat_id','$cur_time')";		
		$QURY_d		= mysqli_query($connect,$INSRT_d);
	}
	
	$UPDATE_dt = "UPDATE guest_user SET `party_det_id`='$max_id',`update_dt` = '$cur_time' WHERE guest_id = '$guest_id'";
	$QRY_dt    = mysqli_query($connect,$UPDATE_dt);
	
	/*$SLCT1 = "SELECT * FROM po_entry ORDER BY po_entry_id ASC";
	//echo $SLCT;
	$QURY1 = mysqli_query($connect,$SLCT1);
	if(mysqli_num_rows($QURY1)> 0)
	{
		$SLCT_sk1 = "SELECT COUNT(po_entry_id) as max_ids FROM po_entry WHERE statu_s = 'active' ORDER BY po_entry_id ASC";
		$QURY_sk1 = mysqli_query($connect,$SLCT_sk1);  
		$FTCH_sk1 = mysqli_fetch_object($QURY_sk1);
		$max_id1 = $FTCH_sk1->max_ids + 1;
		$po_no = "PO-".$max_id1;
	}
	else
	{
		$max_id1 = 1;
		$po_no = "PO-".$max_id1;
	}
	
	$INSRT_po = "INSERT INTO po_entry(`party_det_id`, `po_no`, `po_date`,`post_dt`)VALUES('$max_id','$po_no','$FTCH->entry_date','$cur_time')";
	//echo $INSRT_po."<br />";
	$QURY_po  = mysqli_query($connect,$INSRT_po);
	
	$SLCT_po = "SELECT MAX(po_entry_id) as max_po FROM po_entry ORDER BY po_entry_id ASC";
	$QURY_po = mysqli_query($connect,$SLCT_po);  
	$FTCH_po = mysqli_fetch_object($QURY_po);
	$max_po = $FTCH_po->max_po;
	
	$SLCT2 = "SELECT * FROM guest_user_details WHERE guest_user_id = '$guest_id'";
	//echo $SLCT2;
	$QURY2 = mysqli_query($connect,$SLCT2);
	while($FTCH2 = mysqli_fetch_object($QURY2))
	{	
		$INSRT_po_det = "INSERT INTO po_entry_det(`po_entry_id`, `master_cat_id`, `design_det_id`, `remark_s`, `post_dt`)VALUES('$max_po','$FTCH2->master_cat_id','$FTCH2->design_det_id','','$cur_time')";
		//echo $INSRT_po_det."<br />";
		$QURY_po_det  = mysqli_query($connect,$INSRT_po_det);
	}*/
	$party_id	=	base64_encode(base64_encode(base64_encode($max_id)));
		
?>
		<script type="text/javascript">
            //alert("Data inserted successfully");
            //history.back();
            window.location='../party_update.php?party_id=<?php echo $party_id ?>';
        </script>
<?php

