<?php if($act=="add" || $act=="edit"){?>
<div class="py-3 pl-1">
	<a href="javascript:void(0)" onclick="add_detailrow()" class="btn btn-primary btn-sm">Tambah Baris Baru
	</a>
</div>
<?php } ?>

<div id="detail" style="overflow-y:scroll;height:350px;">
<table class="table table-bordered" id="jt_table">
<thead>
<tr class="thead" style="background-color:#333;color:white">
	<td style="width:30px">No</td>
	<td class="tc" style="width:300px">Nama / Kode Produk</td>
    <td class="tr" style="width:100px;">Qty</td>
    <td class="tr" style="width:50px;">Satuan</td>
    <td class="tr" style="width:120px;">Harga Satuan</td>
    <td class="tr" style="width:150px;">Subtotal</td>
</tr>
</thead>
<?php

$subtotal = 0;

$i = 0;

$sqldetail = "SELECT * FROM podetail a, mst_product b 
				WHERE a.pm_autoid = b.pm_autoid AND a.po_autoid = '$autoid' ORDER BY a.pod_autoid";
$detail_con = $conn->query($sqldetail) or die($sqldetail);
while($rsd = $detail_con->fetch_assoc()){
	$pmdesc = $rsd['pm_name'];
	
	$qty = $rsd['pod_qty'];
	$pm_bprice = $rsd['pod_price'];


	$detail_subtotal = $qty * $pm_bprice;
	

	
	$pm_autoid = $rsd['pm_autoid'];
?>
<tr>
	<td><?php echo $i+1?></td>
	<td>
    	<input type="text" id="pm<?php echo $i?>" class="input" value="<?php echo $pmdesc?>" autocomplete="off" style="width:100%" onfocus="pm_auto_complete('<?php echo $i?>')">
        <input type="hidden" id="pm_autoid<?php echo $i?>"  autocomplete="off" name="pm_autoid<?php echo $i?>" value="<?php echo $rsd['pm_autoid']?>">
    </td>

    <td>
    	<input type="text" class="input tr" onkeyup="calc_cb()" id="qty<?php echo $i?>" value="<?php echo $qty?>"
         name="qty<?php echo $i?>" style="width:100%" autocomplete="off">
    </td>
    <td class="tc">KG</td>
    <td>
    	<input type="text" class="input tr" onkeyup="calc_cb()" id="pm_bprice<?php echo $i?>" value="<?php echo $pm_bprice?>"
         name="pm_bprice<?php echo $i?>" style="width:100%" autocomplete="off">
    </td>
    <td>
    	<input type="text" class="input tr" onkeyup="calc_cb()" id="subtotal<?php echo $i?>" value="<?php echo $detail_subtotal?>"
         name="subtotal<?php echo $i?>" style="width:100%" autocomplete="off"   onblur="chk_field('<?php echo $i?>')">
    </td>

</tr>
<?php 
$i = $i + 1;
$subtotal = $subtotal + $detail_subtotal;
}?>

</table>
</div>
<script>
</script>
<div style="border-top:1px solid black;">
<table class="table table-bordered">
<tr class="bold">
	<td style="width:80%" class="tr">TOTAL</td>
    <td class="tr">
        <input readonly class="input tr bold" name="subtotal" id="subtotal" value="<?php echo $subtotal?>">
		<input  style="display:none" type="text" class="input tr bold" name="cashdisc" id="cashdisc" onkeyup="calc_gtotal()" value="<?php echo $cashdisc?>">
		<input  style="display:none" type="text" class="input tr bold" 
		value="<?php echo $gtotal?>" name="gtotal" id="gtotal">    
    </td>
</tr>

</table>
</div>
<div id="chk" style="display:none"></div>

							<input type="hidden" id="totalcb" name="totalcb" value="<?php echo $total?>" autocomplete="off">
							<input type="hidden" id="row" autocomplete="off" name="row" value="<?php echo $i?>" />