<?php
ob_start();
?>
<?php
    include 'header.php'; 
    $id=$_GET['xid'];
?>

<div class="container">

  <div class="my-2 border-bottom">
    <h5 class="fw-semibold fs-5">Laporan Neraca Mutasi</h5>
  </div>

  <section class="content">
    <div class="row">
      <section class="col-lg-12">
         
        <div class="box box-info">
          <div class="box-header">
            <h6 class="box-title"></h6>
          </div>
          <div class="box-body">
            <?php 
            //////////////////////////////////////////////////////////////////////////// 
            $oleh           = $_GET['toleh'];
            $tabel_tujuan   = "nawal_".$oleh; 
            $tabel_asal     = "nawal";
            
            $tgl_d = $_GET['xtgl_d'];
            $tgl_s = $_GET['xtgl_s'];            
            ////////////////////////////////////////////////////////////////////////////     
              $tgl_p    =strtotime("$tgl_d");
              $tgl_lalu =date('Y-m-d', strtotime("-1 day", $tgl_p));
              
                $sql0 = mysqli_query($koneksi, "SELECT nama AS nama_kel FROM n_arus_kas WHERE kd='$id' limit 1 ");
                list($nama_kel) = mysqli_fetch_array($sql0); 
                
              ?>
              <div class="row">
                <div class="col-lg-10">
                  <table class="table table-bordered">
                    <tr>
                      <th width="20%">DARI TANGGAL</th>
                      <th width="1%">:</th>
                      <td><?php echo date('d-m-Y', strtotime($tgl_d)); ?></td>
                    </tr>
                    <tr>
                      <th>SAMPAI TANGGAL</th>
                      <th>:</th>
                      <td><?php echo date('d-m-Y', strtotime($tgl_s)); ?></td>
                    </tr>
                    <tr>
                      <th>Kelompok </th>
                      <th>:</th>
                      <td><?php echo $nama_kel; ?></td>
                    </tr>                    
                    <tr>
                      <th>Lanjutan </th>
                      <th>:</th>
                      <td>
                      		<a href="javascript:history.go(-1)" class="btn btn-primary btn-sm"><i class="bi bi-reply-all"></i> &nbsp Kembali</a> 
                      </td>
                    </tr>   
                  </table>
                </div>
              </div>

              <div class="table-responsive">
                <table class="table table-bordered table-striped" id="table-datatable1">
                  <thead>
              <thead>
              <tr>
                <th Style="text-align:center" colspan="3" bgcolor="#D3D3D3">Akunt Buku Besar</th>
                <th Style="text-align:center" colspan="2" bgcolor="#DCDCDC">Saldo s/d <?php echo date('d-m-Y', strtotime($tgl_lalu)); ?></th>
                <th Style="text-align:center" colspan="2" bgcolor="#DCDCDC">Mutasi <?php echo date('d-m-Y', strtotime($tgl_d)); ?> s/d <?php echo date('d-m-Y', strtotime($tgl_s)); ?></th>
                <th Style="text-align:center" colspan="2" bgcolor="#DCDCDC">Saldo <?php echo date('d-m-Y', strtotime($tgl_s)); ?></th>
                <th Style="text-align:center" colspan="1" bgcolor="#DCDCDC">Opsi</th>
            </tr>                 
            <tr>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">No</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Nomor</th>
              <th width="20%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Nama</th>
              <th width="10%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Debet</th>
              <th width="10%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Kredit</th>
              <th width="10%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Debet</th>
              <th width="10%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Kredit</th>
              <th width="10%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Debet</th>
              <th width="10%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Kredit</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Opsi</th>
            </tr>
                  </thead>
          <tbody>
            <?php 
            $no=1;
            $nol=0;
            //and ()
            $data = mysqli_query($koneksi,"SELECT * FROM $tabel_tujuan WHERE ry='$id' order by noperk ASC ");
            while($w = mysqli_fetch_array($data)){
            //    if (($w['awald']<>0) or ($w['awalk']<>0) or ($w['mutasid']<>0) or ($w['mutasik']<>0) or ($w['akhird']<>0) or ($w['akhirk']<>0)) {
              ?>
                          <tr>
                            <td><?php echo $no++; ?></td>
                            <td style="text-align:left; font-size: 11pt; font-weight:normal;"><?php echo $w['noperk'] ?></td>
                            <td style="text-align:left; font-size: 11pt; font-weight:normal;"><?php echo $w['perk']; ?></td>
                            <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$w[awald]", 0, ",", "."); ?></td>
                            <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$w[awalk]", 0, ",", "."); ?></td>
                            <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$w[mutasid]", 0, ",", "."); ?></td>
                            <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$w[mutasik]", 0, ",", "."); ?></td>
                            <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$w[akhird]", 0, ",", "."); ?></td>
                            <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$w[akhirk]", 0, ",", "."); ?></td>
                            <td>    
                                <a data-toggle='tooltip' data-placement='top' title='Buka Data Trans <?php echo $w['perk'] ?>' class="btn btn-primary btn-sm" href="!!_view_trans_per_akunt_tgl_tgl.php?id=<?php echo $w['noperk'] ?>&tgl_d=<?php echo $tgl_d ?>&tgl_s=<?php echo $tgl_s ?>"><i class="bi bi-eye"></i></a>
                            </td>           
                          </tr>    
                        </div>
                      </div>
                    </div>
              <?php } ?>
              
              
          </tbody>
                        <?php 
                $sql2 = mysqli_query($koneksi, "SELECT sum(awald) AS tawald,sum(awalk) AS tawalk,sum(mutasid) AS tmutd,sum(mutasik) AS tmutk,sum(akhird) AS takhird,sum(akhirk) AS takhirk FROM $tabel_tujuan WHERE ry='$id' ");
                list($tawald,$tawalk,$tmutd,$tmutk,$takhird,$takhirk) = mysqli_fetch_array($sql2);
            	        ?>				

						<tr>
			                <td align='right'><style="font-weight: bold;><?php echo "" ; ?></td>
			                <td align='right'><style="font-weight: bold;><?php echo "" ; ?></td>
						    <td colspan="1" style="font-weight: bold;text-align: center;">T O T A L </td>																																									
							<td align='right'><style="font-weight: bold;><?php echo "" . number_format("$tawald", 0, ",", "."); ?></td>    
							<td align='right'><style="font-weight: bold;><?php echo "" . number_format("$tawalk", 0, ",", "."); ?></td>    
							<td align='right' style="font-weight: bold; background-color: #FF8C00;">
							    <?php echo "" . number_format("$tmutd", 0, ",", "."); ?>
							</td>
							<td align='right' style="font-weight: bold; background-color: #6495ED;">
							    <?php echo "" . number_format("$tmutk", 0, ",", "."); ?>
							</td>   
							<td align='right'><style="font-weight: bold;><?php echo "" . number_format("$takhird", 0, ",", "."); ?></td>    
							<td align='right'><style="font-weight: bold;><?php echo "" . number_format("$takhirk", 0, ",", "."); ?></td>    
                			<td align='right'><style="font-weight: bold;><?php echo "" ; ?></td>    
                
						</tr>							
        </table>
              </div>

              <?php 

            ?>

          </div>
        </div>
      </section>
    </div>
  </section>

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