<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 Jual</th>
        <th>Jumlah Retur</th>
        <th>Satuan</th>
    </tr>
    </thead>
    <tbody>
    <?php
    $i=1;
    foreach ($datajual as $hasil) {
        ?>
        <tr>
            <td>
                <?php echo $hasil->kode_barang ?>
                <input type="hidden" value="<?php echo $hasil->id_penjualanmeta ?>" name="idmeta<?php echo $i ?>" id="idmeta<?php echo $i ?>"> 
            </td>
            <td>
                <?php echo $hasil->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->jumlah_jual.' '.$hasil->satuan_jual ?></td>
            <td>
                <input type="number" max="<?php echo $hasil->jumlah_jual ?>" value="<?php echo @$arrretur[$hasil->kode_barang] ?>" name="retur<?php echo $i ?>" id="retur<?php echo $i ?>" class="form-control">
            </td>
            <td>
                <select class="form-control" name="satuan<?php echo $i ?>" id="satuan<?php echo $i ?>">
                    <?php
                    if (@$arrsatuan[$hasil->kode_barang]) {
                        foreach ($arrsatuan[$hasil->kode_barang] as $key => $value) {
                            ?>
                            <option value="<?php echo $value ?>" <?php if ($hasil->satuan_jual==$value) echo 'selected' ?>><?php echo $value ?></option>
                            <?php
                        }
                    }
                    ?>
                </select>
            </td>
        </tr>
        <?php
        $i++;
    }
    ?>
    </tbody>
    </table>
    <input type="hidden" name="nota" id="nota" value="<?php echo @$nota ?>">
</form>