<form id="barangretur">
    <table class="table table-hover datatable" style="width: 100%" id="tabelku">
    <thead>
    <tr>
        <th>Kode Barang</th>
        <th>Nama Barang</th>
        <th>Jumlah Pembelian</th>
        <th>Jumlah Retur</th>
    </tr>
    </thead>
    <tbody>
    <?php
    $i=1;
    foreach ($databeli as $hasil) {
        ?>
        <tr>
            <td>
                <?php echo $hasil->kode_barang ?>
                <input type="hidden" value="<?php echo $hasil->kode_barang ?>" name="kdb<?php echo $i ?>" id="kdb<?php echo $i ?>"> 
            </td>
            <td><?php echo $hasil->barang ?></td>
            <td><?php echo $hasil->jumlah_diterima ?></td>
            <td>
                <input type="number" value="<?php echo @$arrretur[$hasil->kode_barang] ?>" name="retur<?php echo $i ?>" id="retur<?php echo $i ?>" class="form-control">
            </td>
        </tr>
        <?php
        $i++;
    }
    ?>
    </tbody>
    </table>
    <input type="hidden" name="nota" id="nota" value="<?php echo @$nota ?>">
</form>