<?php 
session_start();
//mysql_connect("localhost","root","vertrigo") or die("Error Connecting Server");
//mysql_select_db("sm") or die("Error Opening Database");
include 'dbc.php';

$userid=$_SESSION["userid"];
$today=date("d-m-Y");
$id=$_REQUEST["id"];
$sqll = "select * from customer where id='$id' and user_id='$userid'";
$data=mysql_query($sqll) or die ("Error:" . mysql_error());
$rows=mysql_num_rows($data);
$user_data=mysql_fetch_array($data);

  if($rows==0)
    {
	   $Message =  "This Record Cannot Deleted";
	    header("Location:dsr_del_process.php?Message={$Message}");
	  }
	  else
	  {
	  $sqlp3 = "select * from customer where id='$id' and user_id='$userid'";
 							$finishstock3=mysql_query($sqlp3) or die("Error : " . mysql_error());
   							$app3=mysql_fetch_array($finishstock3);
   							$msisdn=$app3["msisdn"];
   							$iccid=$app3["iccid"];
							$t_air_time=$app3["t_air_time"];
							$sale_type=$app3["sale_type"];
							
		if ($sale_type='New Sim')
		{
							$sql11 = "Insert into finishstock (id,date,pro_code,pro_name,pro_type,stock_in_hand,user_id)values (null,'$today','$iccid','$msisdn','SIM','1','$userid')";
mysql_query($sql11) or die("Error : " . mysql_error());
}

$sqlp5 = "select * from finishstock where pro_type='AIR TIME' and user_id='$userid'";
 							$finishstock4=mysql_query($sqlp5) or die("Error : " . mysql_error());
   							$app5=mysql_fetch_array($finishstock5);
							
   							$stock_in_hand=$app5["stock_in_hand"];
							$new_stock=$stock_in_hand + $t_air_time;
							
$sqlp4="update finishstock set stock_in_hand='$new_stock' where pro_type='AIR TIME' and user_id='$userid';";
mysql_query($sqlp4) or die("Error : " . mysql_error());

$sql = "delete from customer where id='$id' and user_id='$userid'";
mysql_query($sql) or die("Error : " . mysql_error());

$Message = "Record Saved";
    header("Location:dsr_del.php?Message={$Message}");
}
/*$sql="Select * from agents where userid='$user_id'";
$data=mysql_query($sql) or die ("Error:" . mysql_error());
$userdata=mysql_fetch_array($data);
$email=$userdata["e_mail"];
mail($email . ",info@lalburj.com","Candidate Information","Candidate Data Posted Successfully","Passport No:" . $app_pp_no . " of " . $app_name . "Has been Posted Successfully By:" . $_SESSION["userid"]);*/
?>
