<?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:120px;">Harga Satuan</td>
    <td class="tr" style="width:120px;">Qty</td>
    <td class="tr" style="width:150px;">Disc</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']." - ".$rsd['pm_code'];
	
	$qty = $rsd['pod_qty'];
	$pm_bprice = $rsd['pod_price'];
	$nett_price = $rsd['pod_nett_price'];
	$pm_disc = $rsd['pod_disc'];
	$pm_disctype = $rsd['pod_disctype'];
	$detail_subtotal = $qty * $nett_price;
	
	$po_expdate = dtostr($rsd['pod_expdate']);
	
	$pod_ums = $rsd['pod_ums'];
	$pm_autoid = $rsd['pm_autoid'];
	
	$ums = $_pm_ums[$pm_autoid];
	$umb = $_pm_umb[$pm_autoid];
?>
<tr>
	<td><?php echo $i+1?></td>
    <td>
		<input type="text" id="pm_barcode<?php echo $i?>" class="input" onchange="get_barcode('<?php echo $i?>')" value="<?php echo $rsd['pm_barcode']?>" autocomplete="off">
    </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="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="qty<?php echo $i?>" value="<?php echo $qty?>"
         name="qty<?php echo $i?>" style="width:100%" autocomplete="off">
    </td>
    <td class="tr">
    	<input type="text" class="input tr" style="width:70px"
         name="pm_disc<?php echo $i?>" id="pm_disc<?php echo $i?>" value="<?php echo $pm_disc?>"  onkeyup="calc_cb()" >
         
        <select name="pm_disctype<?php echo $i?>" id="pm_disctype<?php echo $i?>" class="input" style="width:50px"  onchange="calc_cb()" >
	        <option <?php if($pm_disctype=="P"){echo 'selected="selected"';}?> value="P">%</option>
	        <option <?php if($pm_disctype=="R"){echo 'selected="selected"';}?> value="R">Rp</option>
        </select>
        <input type="hidden" id="nett_price<?php echo $i?>" name="nett_price<?php echo $i?>" value="">
     </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">SUBTOTAL</td>
    <td class="tr">
        <input readonly class="input tr bold" name="subtotal" id="subtotal" value="<?php echo $subtotal?>">
    </td>
</tr>
<tr class="bold">
	<td style="width:80%" class="tr">CASH DISC <?php echo get_input_disctype($disctype)?></td>
    <td class="tr">
		<input type="text" class="input tr bold" name="cashdisc" id="cashdisc" onkeyup="calc_gtotal()" value="<?php echo $cashdisc?>">
    </td>	
</tr>
<tr class="bold">
	<td class="tr">TOTAL</td>
    <td class="tr">
		<input 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?>" />