<link rel="stylesheet" href="data_table/css/bootstrap.css">
<link rel="stylesheet" href="data_table/css/dataTables.bootstrap4.min.css">
<link rel="stylesheet" href="icon/css/font-awesome.css">
<link rel="stylesheet" href="icon/css/font-awesome.min.css">
<?php 

require("php_con.php");

if(isset($_GET['remove'])){
	mysqli_query($connation,"DELETE FROM supp_bill_list WHERE supp_bill_id='$_GET[remove]'");
}


if(isset($_GET['supp_bill_system_id'])&&isset($_GET['supp_bill_product_id'])&&isset($_GET['supp_bill_badge_id'])&&isset($_GET['supp_bill_buy_price'])&&isset($_GET['supp_bill_sale_price'])&&isset($_GET['supp_bill_wholesale'])&&isset($_GET['supp_bill_discount_price'])&&isset($_GET['supp_bill_qty'])){
	if(empty($_GET['supp_bill_product_id'])||empty($_GET['supp_bill_badge_id'])){}else{
	$supp_bill_system_id=mysqli_real_escape_string($connation,$_GET['supp_bill_system_id']);
	$supp_bill_product_id=mysqli_real_escape_string($connation,$_GET['supp_bill_product_id']);
	$supp_bill_badge_id=mysqli_real_escape_string($connation,$_GET['supp_bill_badge_id']);
	$supp_bill_buy_price=mysqli_real_escape_string($connation,$_GET['supp_bill_buy_price']);
	$supp_bill_sale_price=mysqli_real_escape_string($connation,$_GET['supp_bill_sale_price']);
	$supp_bill_wholesale=mysqli_real_escape_string($connation,$_GET['supp_bill_wholesale']);
	$supp_bill_discount_price=mysqli_real_escape_string($connation,$_GET['supp_bill_discount_price']);
	$supp_bill_qty=mysqli_real_escape_string($connation,$_GET['supp_bill_qty']);
	mysqli_query($connation,"INSERT INTO
	supp_bill_list (supp_bill_id, supp_bill_system_id, supp_bill_product_id, supp_bill_badge_id, supp_bill_buy_price, supp_bill_sale_price, supp_bill_wholesale, supp_bill_discount_price, supp_bill_qty)
	VALUES (NULL, '$supp_bill_system_id', '$supp_bill_product_id', '$supp_bill_badge_id', '$supp_bill_buy_price', '$supp_bill_sale_price', '$supp_bill_wholesale', '$supp_bill_discount_price', '$supp_bill_qty')");
	mysqli_error($connation);
	}
}
?>
<style>
	.table tr td{
		padding: 2px;
		font-size: 14px;
	}
</style>
<table class="table table-bordered">
  <tbody>
    <tr>
      <td>Product</td>
      <td align="right">Rate</td>
      <td align="right">QTY</td>
      <td align="right">Amount</td>
		<?php if(!isset($_GET['view'])){ ?><td style="width: 20px;">&nbsp;</td><?php } ?>
    </tr>

<?php
$total_amount=0;
if(isset($_GET['supp_bill_system_id'])){
	
$list_qury=mysqli_query($connation,"SELECT *
FROM supp_bill_list sbl LEFT JOIN product_details pd ON sbl.supp_bill_product_id=pd.product_id
WHERE sbl.supp_bill_system_id='$_GET[supp_bill_system_id]' ORDER BY sbl.supp_bill_id DESC");
while($list_resalt=mysqli_fetch_array($list_qury)){
?>

<tr valign="middle">
<td><?php if($list_resalt['product_name']==""){echo "Not Found";}else{ echo $list_resalt['product_name']; } ?></td>
<td align="right"><?php echo number_format($list_resalt['supp_bill_buy_price'],2); ?></td>
<td align="right"><?php echo number_format($list_resalt['supp_bill_qty'],3); ?></td>
<td align="right"><?php $amount=$list_resalt['supp_bill_buy_price']*$list_resalt['supp_bill_qty']; echo number_format($amount,2); ?></td>
<?php if(!isset($_GET['view'])){ ?><td align="center"><a href="suppler_bill_item_list.php?supp_bill_system_id=<?php echo $_GET['supp_bill_system_id']; ?>&remove=<?php echo $list_resalt['supp_bill_id']; ?>" class="text-danger" onClick="JavaScript:return confirm('Are your sure remove this item?');"><i class="fa fa-trash"></i></a></td><?php } ?>
</tr>
	  
<?php
$total_amount=$total_amount+$amount;
}
}
else{ ?>
<tr><td colspan="5" align="center">Data not found</td></tr>
<?php } ?>
  <tbody>
	<tr style="font-weight: bold;">
	<td colspan="3" align="right">Total Amount</td>
	<td align="right"><?php echo number_format($total_amount,2); ?></td>
	<?php if(!isset($_GET['view'])){ ?><td>&nbsp;</td><?php } ?>
	</tr>
  </tbody>
</table>