<div id="detail">
<table class="table table-bordered" id="jt_table">
<thead>
<tr>
	<td colspan="5">
    <?php if($act=="add" || $act=="edit"){?>
    <a href="javascript:void(0)" onclick="add_detailrow()" class="btn btn-primary btn-sm">Tambah Baris Baru
    </a>
    <?php } ?>
    </td>
</tr>
<tr class="thead" style="background-color:#333;color:white">
	<td style="width:30px">No</td>
    <td class="tl" style="width:100px">Barcode</td>
	<td class="tc" style="width:350px">Nama Produk</td>
    <td class="tr" style="width:120px;">Qty</td>
    <td class="tc" style="width:100px">Satuan</td>
    <td class="tr" style="width:120px;">Harga (Sat Kecil)</td>
	<td class="tl" style="width:200px;">Catatan</td>
    <td class="tl" style="width:80px;">Stok</td>
</tr>
</thead>
<?php

$total = 0;

$i = 0;

$sqldetail = "SELECT * FROM invtransd  a, mst_product b where a.pm_autoid = b.pm_autoid AND a.invt_autoid = '$autoid' ORDER BY a.invtd_autoid";
$detail_con = $conn->query($sqldetail) or die($sqldetail);
while($rsd = $detail_con->fetch_assoc()){
	$pmdesc = $rsd['pm_name']." - ".$rsd['pm_code'];
	
	$qty 	= $rsd['invtd_qty'];
	$dnotes = $rsd['invtd_notes'];
	$price 	= $rsd['invtd_bprice'];
	$ums 	= $rsd['invtd_um'];

	$stok = get_stok_info($rsd['pm_autoid'],0,$conn);

?>
<tr>
	<td><?php echo $i+1?></td>
    <td>
        	<input type="text" id="pm_barcode<?php echo $i?>" class="input" value="<?php echo $rsd['pm_barcode']?>" onchange="get_barcode('<?php echo $i?>')" 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="qty<?php echo $i?>" value="<?php echo $qty?>"
         name="qty<?php echo $i?>" onkeydown="chk_coa('<?php echo $i?>')" style="width:100%" autocomplete="off">
    </td>
    <td class="tc">

    	<span id="pm_ums<?php echo $i?>">

        <select class="input w-100" name="um<?php echo $i?>">
	        <option <?php if($ums == strtoupper($rsd['pm_ums'])){echo 'selected="selected"';}?> value="<?php echo $rsd['pm_ums']?>"><?php echo $rsd['pm_ums']?></option>
			<option <?php if($ums == strtoupper($rsd['pm_umb'])){echo 'selected="selected"';}?> value="<?php echo $rsd['pm_umb']?>"><?php echo $rsd['pm_umb']?></option>
        </select>
        </span>
	</td>
    <td>
    	<input type="text" class="input tr" onkeyup="calc_cb()" id="price<?php echo $i?>"  value="<?php echo $price?>"
         name="price<?php echo $i?>" onkeydown="chk_coa('<?php echo $i?>')" style="width:100%" autocomplete="off">
    </td>
    <td>
    	<input type="text" class="input tl" id="dnotes<?php echo $i?>" value="<?php echo $dnotes?>" name="dnotes<?php echo $i?>" 
        onblur="chk_field('<?php echo $i?>')" style="width:100%"autocomplete="off">
    </td>
    <td><input readonly id="stok<?php echo $i?>" class="input bg bg-warning" value="<?php echo $stok?>"></td>
</tr>
<?php 
$i = $i + 1;
$total = $total + $qty;
}?>

<tfoot>
<tr class="bg-primary" style="color:#fff">
	<td colspan="3" class="tr">TOTAL</td>
    <td class="tr">
    	<span id="jmlcb"><?php echo number_format($total)?></span>
    </td>
    <td colspan="4">

    </td>
</tr>
</tfoot>
</table>
<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?>" />
</div>
<div id="chk" style="display:none"></div>