<?php
session_start();
include 'dbc.php';


$userid=$_SESSION["userid"];
$today=date("Y-m-d");
$inv_no=$_POST["inv_no"];
$username=$_POST["username"];
$item_name=$_POST["statelist"];
$qty=$_POST["qty"];


  
 $sql1 = "SELECT * FROM items where item_name='$item_name' and  user_id='$userid'";
$result1=$conn->query($sql1);
$row2 = $result1->fetch_assoc();
$id=$row2['id'] ;
$item_no=$row2['item_no'] ;
$srate=$row2['retail_price'] ;
$prate=$row2['cost_price'] ;
$type_name=$row2['type_name'] ;
$barcode=$row2['rfid'] ;
$totalamount=$qty * $srate;
$totalpamount=$qty * $prate;
$totaldiff=$totalamount - $totalpamount;
$sql2 = "SELECT * FROM dorder where id = '$inv_no'";
$result2=$conn->query($sql2);
$row2 = $result2->fetch_assoc();
$netamount=$row2['netamount'] ;
$tnetamount=$netamount + $totalamount;
		$sql = "Insert into dorder_details (id,date,inv_no,item_no,barcode,type_name,item_name,srate,qty,amount,username,user_id,itemcode,prate,pamount,diff)values (null,'$today','$inv_no','$sno','$barcode','$type_name','$item_name','$srate','$qty','$totalamount','$username','$userid','$id','$prate','$totalpamount','$totaldiff')";
$conn->query($sql);

$sql3 = "UPDATE dorder SET netamount='$tnetamount' WHERE id='$inv_no'";
$conn->query($sql3);

$Message = "$inv_no";
    header("Location:Add_Do_Item1.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"]);*/

?>


                                                                     
