<?php
session_start();
require "../model/configuration.php";
$gtot=0;
$price=0;
if(isset($_POST['vender']))
{
list($code,$pname) = explode("|", $_POST['product']);
$name=$pname;
$cod=$code;
$invdate=date("Y-m-d", strtotime($_POST['datepicker']));
$invno=$_POST['invno'];
$vender=$_POST['vender'];
$gsm=$_POST['gsm'];
$width=$_POST['width'];
$length=$_POST['length'];
$prce=$_POST['prce'];
$qty=$_POST['qty'];
$disc=$_POST['disc'];
$tax=$_POST['tax'];
$ppr=$_POST['paper'];
$sion=$_POST['sion'];
$endate=date("Y-m-d");
   
//$query="insert into temp_puechase(inno) values ('$pno')";
$query=$db->execute("insert into purchase_temp(vendr_id,invoice_date,invoice_no,product_code,product_name,gsm,width,length,price,quantity,discount,tax,permission,entrydate,paper) values ('$vender','$invdate','$invno','$cod','$name','$gsm','$width','$length','$prce','$qty','$disc','$tax','$sion','$endate','$ppr')");

	
if($query) {
	$c=0;
$selquery1=$db->execute("select * from purchase_temp where permission='$sion' order by id");
while($selrow1=$selquery1->fetch_assoc())
{
$c++;
$sl=$c;
$id=$selrow1['id'];	
}

//$pprce=($sprice/(100+$tax))*100;
//$uprice=round($pprce,2);
//$pricetot=$uprice+($uprice*$tax/100);
//$grandtotal=$pricetot*$quantity;



$pprce=($prce/(100+$tax))*100;
    $uprice=$pprce;
    $ntprce=$uprice*$qty;
    $netamount=$ntprce-$disc;//($ntprce*$disc);//$disc/100
    $taxamount=$netamount*$tax/100;
    $ttl=$netamount+($netamount*$tax/100);

	$ttl=round($ttl,2);


$my_id = $db->lastid();

echo '<tr id="item_'.$my_id.'">
<td width="7%">'.$sl.'</td>
<td width="10%">'.$cod.'</td>
<td width="12%">'.$name.'</td>
<td width="12%">'.$uprice.'</td>
<td width="12%">'.$qty.'</td>
<td width="11%">'.$disc.'</td>
<td width="11%">'.$tax.'</td>
<td width="11%">'.round($ttl,2).'</td>
<td width="9%" style="border-right:none;"><span class="delete_button"><a href="#" class="del_button" id="del-'.$my_id.'" title="Delete"><i class="fa fa-trash-o"></i></a></span></td>
</tr>';
 }
}
?>