


<?php 
    session_start();
    include 'header.php'; 

    $kdj    = $_GET['kdj'];
    $ao     = $_GET['ao'];
    $tgl_d  = $_GET['tgl_d'];
    $tgl_s  = $_GET['tgl_s'];
    
    $kdc    =$_SESSION['kdc'];
    $oleh   =$_SESSION['id_kar'];
    
    $nawal = mysqli_query($koneksi,"select * from nawal where noperk='$kdj'");
        $n = mysqli_fetch_assoc($nawal);    
    $perk = str_replace('Pend. ', '', $n['perk']);    
    
    $kary = mysqli_query($koneksi,"select * from karyawan where id='$ao'");
        $k = mysqli_fetch_assoc($kary);    
?>            
<div class="container">

  <div class="my-4 border-bottom">
    <h4 class="fw-semibold fs-4">Daftar Transaksi <?php echo $perk; ?>
    </h4>  
  </div>
  <section class="content">
    <div class="row">
      <section class="col-lg-14">
        <div class="box box-info">
          <div class="box-header">
          <div class="box-body">
            <form method="get" action="">

            </form>
          </div>
        </div>
        
        <div class="box box-info">
          <div class="box-header">
            <h6 class="box-title"></h6>
          </div>
          <div class="box-body">

              <div class="row">
                <div class="col-lg-10">
                  <table class="table table-bordered">
                    <tr>
                      <th width="30%">Dari Tgl s/d Tgl</th>
                      <th width="1%">:</th>
                      <td><?php echo date('d-m-Y', strtotime($tgl_d)); ?> s/d <?php echo date('d-m-Y', strtotime($tgl_s)); ?></td>
                    </tr>
                    <tr>
                      <th width="30%">Petugas</th>
                      <th width="1%">:</th>
                      <td><?php echo $k['nama']; ?> , Jabatan : <?php echo $k['jabatan']; ?></td>
                    </tr>
                <?php 
                    $sql_2 = mysqli_query($koneksi, "SELECT sum(masuk-keluar) AS tjsaldo4 FROM anggota_trans_ao WHERE kdj='$kdj' and tanggal BETWEEN '$tgl_d' AND '$tgl_s' and ao='$ao' and hapus<>'HAPUS' and notrans=0 ");
                    list($tjsaldo4) = mysqli_fetch_array($sql_2);
                    echo $tjsaldo4;
            	?>	                        
                    <tr>
                      <th>Lanjutan </th>
                      <th>:</th>
                      <td>
                        <?php if ($tjsaldo4>0) { ;?>
                          <button type="button" class="btn btn-primary btn-sm align-self-end" data-bs-toggle="modal" data-bs-target="#exampleModal">
                          <i class="bi bi-save2"></i> Membukukan Trans ini
                          </button>  
                        <?php } ;?>  
                          
                          <button onclick="window.history.back()" class="btn btn-info btn-sm pull-right"><i class="bi bi-reply"></i>&nbsp; Kembali</button>  
                          <a href="index.php" class="btn btn-secondary btn-sm pull-right"><i class="bi bi-bank"></i> &nbsp; Home</a> 
                      </td>
                    </tr>                       
                  </table>
                </div>
              </div>
        </div>
      <!-- Modal -->
      <form action="tugas_membuku_kolekting_act.php" method="post">
        <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <h1 class="modal-title fs-5" id="exampleModalLabel">Membukuan Transaksi Donasi Kolektif</h1>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
              </div>
              <div class="modal-body">

<div style="background-color: <?php echo$_SESSION['warna_bag']; ?>; padding: 15px; border-radius: 15px; box-shadow: 0 0 15px <?php echo$_SESSION['warna_bag']; ?>;">                  
         
                <div class="form-group" style="width:100%">
                  <label>Nama Petugas </label>
                    <input type="hidden" name="tkdc" required="required" class="form-control" value=<?php echo $kdc; ?> readonly required >
                    <input type="hidden" name="tkdj" required="required" class="form-control" value=<?php echo $kdj; ?> readonly required >
                    <input type="hidden" name="toleh" required="required" class="form-control" value=<?php echo $oleh; ?> readonly required > 
                    <input type="hidden" name="tao" required="required" class="form-control" value=<?php echo $ao; ?> readonly required > 
                    <input type="hidden" name="ttgl_d" required="required" class="form-control" value=<?php echo $tgl_d; ?> readonly required > 
                    <input type="hidden" name="ttgl_s" required="required" class="form-control" value=<?php echo $tgl_s; ?> readonly required > 
                  <input type="text" class="form-control" name="tnama" readonly="readonly" style="background-color: transparent;" value="<?php echo $k['nama']; ?>">
                </div> 
<div class="form-group" style="width:100%">
  <label>Jenis </label>
  <input type="text" class="form-control" id="jenis" name="tjenis" readonly="readonly" style="background-color: transparent;" value="<?php echo $perk; ?>">
</div>              
                <div class="form-group" style="width:100%">
                  <label>Jumlah </label>
                  <input type="text" class="form-control nilai rupiah" id="nilai" name="tjumlah" style="background-color: transparent;" value=<?php echo "" . number_format("$tjsaldo4", 0, ",", "."); ?> readonly required > 
                </div>   
            	<div class="form-group">
                    <label class="form-label"><font color="#000fff">Akunt Lawan </font><font color='#ff0000'><i>(Pilih Akunt ke mana kolekting diserahkan)</i></font color></label>
                    <select class="form-control" name="takunt" required="required">
                      <option value="">- Pilih Akunt -</option>
                      <?php 
                      $ua = mysqli_query($koneksi,"select * from nawal WHERE nosub<'113' ORDER BY noperk ASC ");
                      while($a = mysqli_fetch_array($ua)){
                        ?>
                        <option value="<?php echo $a['noperk'] ?>"><?php echo $a['noperk'] ?> - <?php echo $a['perk'] ?></option>
                        <?php 
                      }
                      ?>
                    </select>
            	</div>            	
                          <div class="form-group" style="width:100%">
                            <label class="form-label"><font color="#000fff">Tanggal Masuk</font></label> 
                            <input type="date" class="form-control" name="ttanggal" required="required" value="<?php echo date('d/m/Y', strtotime($d['tglmasuk'])); ?>">
                          </div>                                
                </div>  
                </div>              
              <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
                <button type="submit" class="btn btn-primary">Simpan</button>
              </div>
            </div>
          </div>
        </div>
        
        
              <div class="table-responsive">
                <table class="table table-bordered table-striped" id="table-datatable">
          <thead>
            <tr>
              <th width="1%" class="text-center" style="text-align:Center; font-size: 10pt; font-weight:normal;">Urt</th>
              <th width="1%" class="text-center" style="text-align:Center; font-size: 10pt; font-weight:normal;">Tanggal</th>
              <th width="10%" class="text-center" style="text-align:Center; font-size: 10pt; font-weight:normal;">Nama</th>
              <th width="20%" class="text-center" style="text-align:Center; font-size: 10pt; font-weight:normal;">Alamat</th>
              <th width="1%" class="text-center" style="text-align:Center; font-size: 10pt; font-weight:normal;">Jumlah</th>
              <th width="1%" class="text-center" style="text-align:Center; font-size: 10pt; font-weight:normal;">Dibukukan</th>
              <th width="1%" class="text-center"></th>
            </tr>
          </thead>
          <tbody>
            <?php 
            $no=1;
            $data = mysqli_query($koneksi,"SELECT * FROM anggota_trans_ao WHERE kdj='$kdj' and tanggal BETWEEN '$tgl_d' AND '$tgl_s' and ao='$ao' and hapus<>'HAPUS' order by id ASC");
            while($t = mysqli_fetch_array($data)){
                if ($t[notrans]<=0) {
                    $ket='Belum';
                } else {
                    $ket='Sudah No '.$t['notrans'].'';
                }
                $noang  =$t['angg_no'] ;
                $anggota = mysqli_query($koneksi,"select * from anggota where angg_no='$noang'");
                $a = mysqli_fetch_assoc($anggota);
                //target="_blank"
              ?>
              <tr>
                <td  style="text-align:center; font-size: 9pt; font-weight:normal;"><?php echo $no++; ?></td>
                <td style="text-align:center; font-size: 10pt; font-weight:normal;"><?php echo date('d-m-Y', strtotime($t[tanggal])); ?></td>
                <td style="text-align:left; font-size: 10pt; font-weight:normal;"><?php echo $a['nama']; ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $a['alamat']; ?> <?php echo $a['rt']; ?> <?php echo $a['rw']; ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$t[masuk]", 0, ",", "."); ?></td>
                <td  style="text-align:center; font-size: 9pt; font-weight:normal;"><?php echo $ket; ?></td>
                <td>
                    <a data-toggle='tooltip' data-placement='top' title='Cetak kuitansi <?php echo $t['notrans'] ?> a/n <?php echo $a['nama']; ?>' style='margin-right:3px' class="btn btn-success btn-sm" href="tugas_trans_kuitansi.php?tid=<?php echo $t['id'] ?>&angg_no=<?php echo $noang ?>" ><i class="bi bi-printer-fill"></i></a>                    
                </td>                
              </tr>
              <?php 
            }
            ?>
          </tbody>
                <?php 
                    $sql_2 = mysqli_query($koneksi, "SELECT sum(masuk-keluar) AS tjsaldo2 FROM anggota_trans_ao WHERE kdj='$kdj' and tanggal BETWEEN '$tgl_d' AND '$tgl_s' and ao='$ao' and hapus<>'HAPUS' ");
                    list($tjsaldo2) = mysqli_fetch_array($sql_2);
            	?>	
							<tr>
						    	<td colspan="4" style="font-weight: bold;text-align: right ;">Total <?php echo $perk; ?> </td>																																									
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$tjsaldo2", 0, ",", "."); ?>
								</td>
							</tr>         
                <?php 
                    $sql_2 = mysqli_query($koneksi, "SELECT sum(masuk-keluar) AS tjsaldo3 FROM anggota_trans_ao WHERE kdj='$kdj' and tanggal BETWEEN '$tgl_d' AND '$tgl_s' and ao='$ao' and hapus<>'HAPUS' and notrans>=1 ");
                    list($tjsaldo3) = mysqli_fetch_array($sql_2);
            	?>	
							<tr>
						    	<td colspan="4" style="font-weight: bold;text-align: right;">Total <?php echo $perk; ?> yg sudah dibukukan </td>																																									
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$tjsaldo3", 0, ",", "."); ?>
								</td>
							</tr>   
                <?php 
                    $sql_2 = mysqli_query($koneksi, "SELECT sum(masuk-keluar) AS tjsaldo4 FROM anggota_trans_ao WHERE kdj='$kdj' and tanggal BETWEEN '$tgl_d' AND '$tgl_s' and ao='$ao' and hapus<>'HAPUS' and notrans<=0 ");
                    list($tjsaldo4) = mysqli_fetch_array($sql_2);
            	?>	
							<tr>
						    	<td colspan="4" style="font-weight: bold;text-align: right;">Total <?php echo $perk; ?> yg belum dibukukan </td>																																									
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$tjsaldo4", 0, ",", "."); ?>
								</td>
							</tr>   							
        </table>
              </div>
          </div>
        </div>
      </section>
    </div>
  </section>

</div>
<?php include 'footer.php'; ?>