<?php
    include '../../config/koneksi.php';

    $tgl_transaksi=$_POST['tgl_transaksi'];
    $idSiswa=$_POST['idSiswa'];

    echo '<option disabled selected value="">- Pilih No. Referensi -</option>';

    $trx_pembayaran_bulanan =mysqli_query($koneksi,"SELECT * FROM tagihan_bulanan WHERE idSiswa='$idSiswa' AND DATE(tglBayar)='$tgl_transaksi' GROUP BY noRefrensi");
    $trx_pembayaran_bebas =mysqli_query($koneksi,"SELECT tagihan_bebas_bayar.*, tagihan_bebas.* FROM tagihan_bebas_bayar LEFT JOIN tagihan_bebas ON tagihan_bebas_bayar.idTagihanBebas = tagihan_bebas.idTagihanBebas WHERE tagihan_bebas.idSiswa='$idSiswa' AND DATE(tagihan_bebas_bayar.tglBayar)='$tgl_transaksi' GROUP BY tagihan_bebas_bayar.noRefrensi");

    if (mysqli_num_rows($trx_pembayaran_bulanan) == 0){
        while ($trx = mysqli_fetch_array($trx_pembayaran_bebas)) {
            echo '<option value="'.$trx['noRefrensi'].'">'.$trx['noRefrensi'].'</option>';
        }
    }elseif (mysqli_num_rows($trx_pembayaran_bebas) == 0){
        while ($trx = mysqli_fetch_array($trx_pembayaran_bulanan)) {
            echo '<option value="'.$trx['noRefrensi'].'">'.$trx['noRefrensi'].'</option>';
        }
    }else{
        while ($trx_bbs = mysqli_fetch_array($trx_pembayaran_bebas)) {
            while ($trx_bln = mysqli_fetch_array($trx_pembayaran_bulanan)) {
                if ($trx_bln['noRefrensi'] == $trx_bbs['noRefrensi']){
                    echo '<option value="'.$trx_bln['noRefrensi'].'">'.$trx_bln['noRefrensi'].'</option>';
                }else{
                    echo '<option value="'.$trx_bln['noRefrensi'].'">'.$trx_bln['noRefrensi'].'</option>';
                    
                }
            }
            echo '<option value="'.$trx_bbs['noRefrensi'].'">'.$trx_bbs['noRefrensi'].'</option>';
        }
    }


    


    
?>
  