
<?php
    session_start();
    include 'header.php'; 
    $keter =$_GET['ket'];
    $_SESSION['keter'] = $keter;
?>

<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 
            //////////////////////////////////////////////////////////////////////////// 
            $kdc    =$_SESSION['kdc'];
            $oleh   =$_SESSION['id_kar'];
            
            $tabel_tujuan   = "nawal_".$oleh; 
            $tabel_asal     = "nawal";
            ////////////////////////////////////////////////////////////////////////////     
                $sql0 = mysqli_query($koneksi, "SELECT tgl_htg,tgl_sd FROM $tabel_tujuan ORDER BY tgl_sd DESC limit 1 ");
                list($tgl_htg,$tgl_sd) = mysqli_fetch_array($sql0); 
                
              $tgl_d    = $tgl_htg;
              $tgl_s    = $tgl_sd;
              
              $tgl_ke_1 =date('2025-01-01');        
              $tgl_p    =strtotime("$tgl_d");
              $tgl_lalu =date('Y-m-d', strtotime("-1 day", $tgl_p));
                if ($keter=='tgl_s/d_tgl') { ;
                    $jelase='Dari Tanggal s/d Tanggal';
                } else {
                    $jelase='Khusus Bulan';
                }
                $nol=0;
                $sql9 = mysqli_query($koneksi, "SELECT sum(awalk-awald) AS tshu_a_01,sum(mutasik-mutasid) AS tshu_mut_01,sum(akhirk-akhird) AS tshu_akhir_01 FROM $tabel_tujuan WHERE klp>'40' ");
                list($tshu_a_01,$tshu_mut_01,$tshu_akhir_01) = mysqli_fetch_array($sql9);             
                ///////////// 
                //echo $tshu_akhir_01 ;
                /////////////       ngisi SHU
                mysqli_query($koneksi, "UPDATE $tabel_tujuan SET ap='Y',awalk='$tshu_a_01',mutasik='$tshu_mut_01',akhirk='$tshu_akhir_01' WHERE noperk='34101' ")or die(mysqli_errno());  
                /////////////       ngisi SHU
                /// and kdu='02'
                $sql8 = mysqli_query($koneksi, "SELECT sum(awalk-awald) AS tshu_a_02,sum(mutasik-mutasid) AS tshu_mut_02,sum(akhirk-akhird) AS tshu_akhir_02 FROM $tabel_tujuan WHERE klp>'40' ");
                list($tshu_a_02,$tshu_mut_02,$tshu_akhir_02) = mysqli_fetch_array($sql8);             
                ///////////// 
                /////////////       ngisi SHU
                mysqli_query($koneksi, "UPDATE $tabel_tujuan SET ap='Y',awalk='$tshu_a_02',mutasik='$tshu_mut_02',akhirk='$tshu_akhir_02' WHERE noperk='34101' ")or die(mysqli_errno());  
                /////////////       ngisi SHU                        
              ?>
              <div class="row">
                <div class="col-lg-10">
                  <table class="table table-bordered">
                    <tr>
                      <th width="20%">MUTASI TERAKHIR DIHITUNG </th>
                      <th width="1%">:</th>
                      <td><?php echo $jelase; ?></td>
                    </tr>
                    <tr>
                      <th width="40%">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>Lanjutan </th>
                      <th>:</th>
                      <td>
                      <a href="lap_akunt_tgl_sd_tgl_print.php?toleh=<?php echo $oleh ?>" target="_blank" class="btn btn-warning btn-sm"><i class="bi bi-printer"></i> &nbsp Print</a>
                      <a href="lap_akunt_tgl_sd_tgl_excell.php?toleh=<?php echo $oleh ?>" class="btn btn-success btn-sm"><i class="bi bi-file-word"></i> &nbsp Excell</a>
                      <a href="lap_akunt_rl_tgl_tgl_tenan.php?toleh=<?php echo $oleh ?>&xtgl_d=<?php echo $tgl_d ?>&xtgl_s=<?php echo $tgl_s ?>" class="btn btn-info btn-sm"><i class="bi bi-bag-check"></i> &nbsp Kenaikan (Penurunan) Aset Bersih</a>
                      <a href="lap_akunt_nrc_tgl_tgl_tenan.php?toleh=<?php echo $oleh ?>" class="btn btn-secondary btn-sm"><i class="bi bi-award"></i> &nbsp Posisi Keuangan </a>
                      </td>                      
                    </tr>   
                    <tr>
                      <th></th>
                      <th>:</th>
                      <td>
                      <a href="lap_profil_kop_tgl_tgl_tenan.php?toleh=<?php echo $oleh ?>&xtgl_d=<?php echo $tgl_d ?>&xtgl_s=<?php echo $tgl_s ?>" class="btn btn-secondary btn-sm"><i class="bi bi-diagram-3-fill"></i> &nbsp PROFIL </a>    
                      <a href="lap_arus_kas_tgl_tgl_tenan.php?toleh=<?php echo $oleh ?>&xtgl_d=<?php echo $tgl_d ?>&xtgl_s=<?php echo $tgl_s ?>" class="btn btn-success btn-sm"><i class="bi bi-arrow-down-up"></i> &nbsp ARUS KAS </a>
                      <a href="lap_perubahan_modal_tgl_tgl_tenan.php?toleh=<?php echo $oleh ?>&xtgl_d=<?php echo $tgl_d ?>&xtgl_s=<?php echo $tgl_s ?>" class="btn btn-info btn-sm"><i class="bi bi-back"></i> &nbsp PERUBAHAN EKUITAS </a>
                      
                      <?php if ($jelase=='Dari Tanggal s/d Tanggal') { ;?>
                            <a href="lap_akunt_tgl_sd_tgl.php" class="btn btn-danger btn-sm"><i class="bi bi-arrow-repeat"></i> &nbsp HITUNG ULANG</a>
                      <?php } else { ;?>
                            <a href="lap_akunt_bulan_tahun.php" class="btn btn-primary btn-sm"><i class="bi bi-arrow-repeat"></i> &nbsp HITUNG ULANG</a>
                      <?php } ;?>
                      </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 (awald<>0 and awalk<>0 and mutasid<>0 and mutasik<>0) klp<'40' and 
            $data = mysqli_query($koneksi,"SELECT * FROM $tabel_tujuan WHERE ry<>'xx' and ap='Y' order by noperk ASC ");
            while($w = mysqli_fetch_array($data)){
                
              ?>
                          <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<>'xx' ");
                list($awald,$awalk,$tmutd,$tmutk,$takhird,$takhirk) = mysqli_fetch_array($sql2);
                
                
                $laba_rugi_a=($awald-$awalk);
                $laba_rugi_b=($tmutd-$tmutk);
                $laba_rugi_c=($takhird-$takhirk);
                $nol=0 ;
                $total_balance_a=($awalk+$laba_rugi_a);
                $total_balance_b=($tmutk+$laba_rugi_b);
                $total_balance_c=($takhirk+$laba_rugi_c);
            	        ?>						
							<tr>
						    	<td colspan="3" style="font-weight: bold;text-align: center;">Total </td>																																									
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$awald", 0, ",", "."); ?>
								</td>    
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$awalk", 0, ",", "."); ?>
								</td>								

								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$tmutd", 0, ",", "."); ?>
								</td>    
								<td align='right'><style="font-weight: bold;">
								    <?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>		
							</tr>             
<!--				
							<tr>
						    	<td colspan="3" style="font-weight: bold;text-align: center;">LABA (RUGI) </td>																																									
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$nol", 0, ",", "."); ?>
								</td>    
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$laba_rugi_a", 0, ",", "."); ?>
								</td>
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$nol", 0, ",", "."); ?>
								</td>    
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$laba_rugi_b", 0, ",", "."); ?>
								</td>
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$nol", 0, ",", "."); ?>
								</td>    
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$laba_rugi_c", 0, ",", "."); ?>
								</td>								
								<td>
								    <a data-toggle='tooltip' data-placement='top' title='Buka Akunt LABA (RUGI)' class="btn btn-danger btn-sm" href="lap_akunt_r_l_tgl_tgl.php?tgl_d=<?php echo $tgl_d ?>&tgl_s=<?php echo $tgl_s ?>"><i class="bi bi-emoji-sunglasses-fill"></i></a>
								</td>								
							</tr>
							
							<tr>
						    	<td colspan="3" style="font-weight: bold;text-align: center;">TOTAL BALANCE </td>																																									
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$awald", 0, ",", "."); ?>
								</td>    
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$total_balance_a", 0, ",", "."); ?>
								</td>
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$tmutd", 0, ",", "."); ?>
								</td>    
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$total_balance_b", 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("$total_balance_c", 0, ",", "."); ?>
								</td>								
							</tr>	
-->							
        </table>
              </div>

              <?php 

            ?>

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

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