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

<div class="container">

  <div class="my-2 border-bottom">
    <h5 class="fw-semibold fs-5">LAPORAN ARUS KAS </h5>
  </div>

  <section class="content">
    <div class="row">
      <section class="col-lg-8">
         
        <div class="box box-info">
          <div class="box-header">
            <h6 class="box-title"></h6>
          </div>
          <div class="box-body">
            <?php 
            $tgl=date('Y-m-d') ;
            $bln = date('m');
            $bulan=($bln) ;
            $ket=$_SESSION['keter'];
            //////////////////////////////////////////////////////////////////////////// 
        $oleh = $_GET['toleh'];
        $tabel_tujuan = "nawal_".$oleh;
        $tabel_asal = "nawal";

        $tgl_d = $_GET['xtgl_d'];
        $tgl_s = $_GET['xtgl_s'];

        $tgl_ke_1 = date('2025-01-01');
        $tgl_p = strtotime("$tgl_d");
        $tgl_lalu = date('Y-m-d', strtotime("-1 day", $tgl_p));
            //////////////////////////////////////////////////////////////////////////// 
              ?>
              <div class="row">
                <div class="col-lg-8">
                  <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>S/d Tanggal </th>
                      <th>:</th>
                      <td><?php echo date('d-m-Y', strtotime($tgl_s)); ?></td>
                    </tr>
                    <tr>
                      <th>Menu Lain</th>
                      <th>:</th>
                      <td>
                        
                      <a href="lap_arus_kas_tgl_tgl_tenan_print.php?toleh=<?php echo $oleh ?>&xtgl_d=<?php echo $tgl_d ?>&xtgl_s=<?php echo $tgl_s ?>" target="_blank" class="btn btn-warning btn-sm"><i class="bi bi-printer"></i> &nbsp Print</a>                    
                      <a href="lap_arus_kas_tgl_tgl_tenan_pdf.php?toleh=<?php echo $oleh ?>&xtgl_d=<?php echo $tgl_d ?>&xtgl_s=<?php echo $tgl_s ?>" target="_blank" class="btn btn-info btn-sm"><i class="bi bi-file-earmark-pdf"></i> &nbsp Print PDF</a>
<!--                        
                      <a href="lap_arus_kas_tgl_tgl_tenan_excell.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-file-word"></i> &nbsp Excell</a>
-->
                      <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">Keterangan</th>
                <th Style="text-align:center" colspan="1" bgcolor="#DCDCDC">Jumlah </th>
                <th Style="text-align:center" colspan="1" bgcolor="#DCDCDC">Opsi </th>
            </tr>     
                  </thead>
          <tbody>
            <?php
                $sqlx = mysqli_query($koneksi, "SELECT nama FROM n_arus_kas WHERE kd='10' limit 1 ");
                list($nama) = mysqli_fetch_array($sqlx);
            ?>
                <tr>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>
                    <td colspan="2" style="font-weight: bold;text-align: left;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo $nama ?></td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>                     
                </tr>
            <?php 
            $no=1;
            $nol=0;
            //
            $data = mysqli_query($koneksi,"SELECT * FROM n_arus_kas WHERE kd>'10' and kd<'49' order by kd ASC ");
            while($z = mysqli_fetch_array($data)){
            	$kdz=$z['kd'];
				$sql_11 = mysqli_query($koneksi, "SELECT sum(mutasik-mutasid) AS tmutasi_11 FROM $tabel_tujuan WHERE ry='11' ");
                	list($tmutasi_11) = mysqli_fetch_array($sql_11);
				$sql_12 = mysqli_query($koneksi, "SELECT sum(mutasik-mutasid) AS tmutasi_12 FROM $tabel_tujuan WHERE ry='12' ");
                	list($tmutasi_12) = mysqli_fetch_array($sql_12);
				$sql_13 = mysqli_query($koneksi, "SELECT sum(mutasik-mutasid) AS tmutasi_13 FROM $tabel_tujuan WHERE ry='13' ");
                	list($tmutasi_13) = mysqli_fetch_array($sql_13);  
				$sql_14 = mysqli_query($koneksi, "SELECT sum(mutasik-mutasid) AS tmutasi_14 FROM $tabel_tujuan WHERE ry='14' ");
                	list($tmutasi_14) = mysqli_fetch_array($sql_14);
				$sql_15 = mysqli_query($koneksi, "SELECT sum(mutasik-mutasid) AS tmutasi_15 FROM $tabel_tujuan WHERE ry='15' ");
                	list($tmutasi_15) = mysqli_fetch_array($sql_15);
                $sql_16 = mysqli_query($koneksi, "SELECT sum(mutasik-mutasid) AS tmutasi_16 FROM $tabel_tujuan WHERE ry='16' ");
                          list($tmutasi_16) = mysqli_fetch_array($sql_16);
                $sql_17 = mysqli_query($koneksi, "SELECT sum(mutasik-mutasid) AS tmutasi_17 FROM $tabel_tujuan WHERE ry='17' ");
                          list($tmutasi_17) = mysqli_fetch_array($sql_17);
                $sql_18 = mysqli_query($koneksi, "SELECT sum(mutasik-mutasid) AS tmutasi_18 FROM $tabel_tujuan WHERE ry='18' ");
                          list($tmutasi_18) = mysqli_fetch_array($sql_18);
                $sql_19 = mysqli_query($koneksi, "SELECT sum(mutasik-mutasid) AS tmutasi_19 FROM $tabel_tujuan WHERE ry='19' ");
                          list($tmutasi_19) = mysqli_fetch_array($sql_19);
                $sql_20 = mysqli_query($koneksi, "SELECT sum(mutasik-mutasid) AS tmutasi_20 FROM $tabel_tujuan WHERE ry='20' ");
                          list($tmutasi_20) = mysqli_fetch_array($sql_20);
                $sql_21 = mysqli_query($koneksi, "SELECT sum(mutasik-mutasid) AS tmutasi_21 FROM $tabel_tujuan WHERE ry='21' ");
                          list($tmutasi_21) = mysqli_fetch_array($sql_21);
                $sql_22 = mysqli_query($koneksi, "SELECT sum(mutasik-mutasid) AS tmutasi_22 FROM $tabel_tujuan WHERE ry='22' ");
                          list($tmutasi_22) = mysqli_fetch_array($sql_22);
                                            
                	if ($kdz=='11')	{
                		$jumlah=$tmutasi_11;		
                	} else if ($kdz=='12')	{
                		$jumlah=$tmutasi_12;
                	} else if ($kdz=='13')	{
                		$jumlah=$tmutasi_13 ;
                	} else if ($kdz=='14')	{
                		$jumlah=$tmutasi_14 ;
                	} else if ($kdz=='15')	{
                		$jumlah=$tmutasi_15 ;
                	} else if ($kdz=='16')	{
                		$jumlah=$tmutasi_16 ;
                	} else if ($kdz=='17')	{
                		$jumlah=$tmutasi_17 ;
                	} else if ($kdz=='18')	{
                		$jumlah=$tmutasi_18 ;
                  } else if ($kdz=='19')  {
                    $jumlah=$tmutasi_19 ;
                  } else if ($kdz=='20')  {
                    $jumlah=$tmutasi_20 ;
                  } else if ($kdz=='21')  {
                    $jumlah=$tmutasi_21 ;
                  } else if ($kdz=='22')  {
                    $jumlah=$tmutasi_22 ;                		                		
                	} else {
                		$jumlah=0 ;
                	}
                  $total_01=$tmutasi_11+($tmutasi_12)+$tmutasi_13+$tmutasi_14+($tmutasi_15)+$tmutasi_16+($tmutasi_17)+$tmutasi_18+$tmutasi_19+($tmutasi_20)+$tmutasi_21+$tmutasi_22 ; 
              ?>
                          <tr>
                            <td><?php echo $no++; ?></td>
                            <td style="text-align:left; font-size: 11pt; font-weight:normal;"><?php echo $z['kd'] ?></td>
                            <td style="text-align:left; font-size: 11pt; font-weight:normal;"><?php echo $z['nama']; ?></td>
                            <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$jumlah", 0, ",", "."); ?></td>
                            <td>    
                                <a data-toggle='tooltip' data-placement='top' title='Buka Data Akunt <?php echo $z['nama'] ?>' class="btn btn-primary btn-sm" href="!!_view_trans_per_kd_arus_kas.php?xid=<?php echo $z['kd'] ?>&toleh=<?php echo $oleh ?>&xtgl_d=<?php echo $tgl_d ?>&xtgl_s=<?php echo $tgl_s ?>"><i class="bi bi-eye"></i></a>
                            </td>                                
                            </tr>       
                        </div>
                      </div>
                    </div>
              <?php } ?>
          </tbody>

              <tr>
                <td colspan="2" style="font-weight: bold;text-align: center;background-color: #B0C4DE;"> </td>
                <td colspan="1" style="font-weight: bold;text-align: left;background-color: #B0C4DE;">Jumlah Arus Kas dari <?php echo $nama ?> </td>    
                <td style="font-weight: bold;text-align: right;background-color: #B0C4DE;"><?php echo "" . number_format("$total_01", 0, ",", "."); ?></td>
                <td colspan="1" style="font-weight: bold;text-align: center;background-color: #B0C4DE;"> </td>    
              </tr> 





          <tbody>
            <?php
                $sqlx = mysqli_query($koneksi, "SELECT nama FROM n_arus_kas WHERE kd='50' limit 1 ");
                list($nama) = mysqli_fetch_array($sqlx);
            ?>
                <tr>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>
                    <td colspan="2" style="font-weight: bold;text-align: left;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo $nama ?></td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>
                </tr>
            <?php 
            $no=1;
            $nol=0;
            //
            $data = mysqli_query($koneksi,"SELECT * FROM n_arus_kas WHERE kd>'50' and kd<'69' order by kd ASC ");
            while($z = mysqli_fetch_array($data)){
              $kdz=$z['kd'];
        $sql_51 = mysqli_query($koneksi, "SELECT sum(mutasid) AS tmutasi_51 FROM $tabel_tujuan WHERE ry='51' ");
                  list($tmutasi_51) = mysqli_fetch_array($sql_51);
        $sql_52 = mysqli_query($koneksi, "SELECT sum(mutasik) AS tmutasi_52 FROM $tabel_tujuan WHERE ry='51' ");
                  list($tmutasi_52) = mysqli_fetch_array($sql_52);
        $sql_53 = mysqli_query($koneksi, "SELECT sum(mutasid) AS tmutasi_53 FROM $tabel_tujuan WHERE ry='52' ");
                  list($tmutasi_53) = mysqli_fetch_array($sql_53);  
        $sql_54 = mysqli_query($koneksi, "SELECT sum(mutasik) AS tmutasi_54 FROM $tabel_tujuan WHERE ry='52' ");
                  list($tmutasi_54) = mysqli_fetch_array($sql_54);
        $sql_55 = mysqli_query($koneksi, "SELECT sum(mutasid) AS tmutasi_55 FROM $tabel_tujuan WHERE ry='55' ");
                  list($tmutasi_55) = mysqli_fetch_array($sql_55);

                                            
                  if ($kdz=='51') {
                    $jumlah=$tmutasi_51*-1;    
                  } else if ($kdz=='52')  {
                    $jumlah=$tmutasi_52*-1;
                  } else if ($kdz=='53')  {
                    $jumlah=$tmutasi_53 ;
                  } else if ($kdz=='54')  {
                    $jumlah=$tmutasi_54 ;
                  } else if ($kdz=='55')  {
                    $jumlah=$tmutasi_55*-1 ;
                  } else {
                    $jumlah=0 ;
                  }
                  $total_51=($tmutasi_51*-1)+($tmutasi_52*-1)+$tmutasi_53+$tmutasi_54+($tmutasi_55*-1)
              ?>
                          <tr>
                            <td><?php echo $no++; ?></td>
                            <td style="text-align:left; font-size: 11pt; font-weight:normal;"><?php echo $z['kd'] ?></td>
                            <td style="text-align:left; font-size: 11pt; font-weight:normal;"><?php echo $z['nama']; ?></td>
                            <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$jumlah", 0, ",", "."); ?></td>
                            <td>    
                                <a data-toggle='tooltip' data-placement='top' title='Buka Data Akunt <?php echo $z['nama'] ?>' class="btn btn-primary btn-sm" href="!!_view_trans_per_kd_arus_kas.php?xid=<?php echo $z['kd'] ?>&toleh=<?php echo $oleh ?>&xtgl_d=<?php echo $tgl_d ?>&xtgl_s=<?php echo $tgl_s ?>"><i class="bi bi-eye"></i></a>
                            </td>    
                            </tr>       
                        </div>
                      </div>
                    </div>
              <?php } ?>
          </tbody>

              <tr>
                <td colspan="2" style="font-weight: bold;text-align: center;background-color: #B0C4DE;"> </td>
                <td colspan="1" style="font-weight: bold;text-align: left;background-color: #B0C4DE;">Jumlah Arus Kas dari <?php echo $nama ?> </td>    
                <td style="font-weight: bold;text-align: right;background-color: #B0C4DE;"><?php echo "" . number_format("$total_51", 0, ",", "."); ?></td> 
                <td colspan="1" style="font-weight: bold;text-align: center;background-color: #B0C4DE;"> </td>    
              </tr> 






          <tbody>
            <?php
                $sqlx = mysqli_query($koneksi, "SELECT nama FROM n_arus_kas WHERE kd='70' limit 1 ");
                list($nama) = mysqli_fetch_array($sqlx);
            ?>
                <tr>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>
                    <td colspan="2" style="font-weight: bold;text-align: left;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo $nama ?></td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>
                </tr>
            <?php 
            $no=1;
            $nol=0;
            //
            $data = mysqli_query($koneksi,"SELECT * FROM n_arus_kas WHERE kd>'70' and kd<'89' order by kd ASC ");
            while($z = mysqli_fetch_array($data)){
              $kdz=$z['kd'];
        $sql_71 = mysqli_query($koneksi, "SELECT sum(mutasik) AS tmutasi_71 FROM $tabel_tujuan WHERE ry='71' ");
                  list($tmutasi_71) = mysqli_fetch_array($sql_71);
        $sql_72 = mysqli_query($koneksi, "SELECT sum(mutasid) AS tmutasi_72 FROM $tabel_tujuan WHERE ry='71' ");
                  list($tmutasi_72) = mysqli_fetch_array($sql_72);
        $sql_73 = mysqli_query($koneksi, "SELECT sum(mutasik) AS tmutasi_73 FROM $tabel_tujuan WHERE ry='73' ");
                  list($tmutasi_73) = mysqli_fetch_array($sql_73);  
        $sql_74 = mysqli_query($koneksi, "SELECT sum(mutasid) AS tmutasi_74 FROM $tabel_tujuan WHERE ry='73' ");
                  list($tmutasi_74) = mysqli_fetch_array($sql_74);
        $sql_75 = mysqli_query($koneksi, "SELECT sum(mutasik-mutasid) AS tmutasi_75 FROM $tabel_tujuan WHERE ry='75' ");
                  list($tmutasi_75) = mysqli_fetch_array($sql_75);

                  if ($kdz=='71') {
                    $jumlah=$tmutasi_71;    
                  } else if ($kdz=='72')  {
                    $jumlah=$tmutasi_72*-1;
                  } else if ($kdz=='73')  {
                    $jumlah=$tmutasi_73 ;
                  } else if ($kdz=='74')  {
                    $jumlah=$tmutasi_74*-1 ;
                  } else if ($kdz=='75')  {
                    $jumlah=$tmutasi_75 ;
                  } else {
                    $jumlah=0 ;
                  }
                  $total_71=$tmutasi_71+($tmutasi_72*-1)+$tmutasi_73+($tmutasi_74*-1)+$tmutasi_75 ;
              ?>
                          <tr>
                            <td><?php echo $no++; ?></td>
                            <td style="text-align:left; font-size: 11pt; font-weight:normal;"><?php echo $z['kd'] ?></td>
                            <td style="text-align:left; font-size: 11pt; font-weight:normal;"><?php echo $z['nama']; ?></td>
                            <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$jumlah", 0, ",", "."); ?></td>
                            <td>    
                                <a data-toggle='tooltip' data-placement='top' title='Buka Data Akunt <?php echo $z['nama'] ?>' class="btn btn-primary btn-sm" href="!!_view_trans_per_kd_arus_kas.php?xid=<?php echo $z['kd'] ?>&toleh=<?php echo $oleh ?>&xtgl_d=<?php echo $tgl_d ?>&xtgl_s=<?php echo $tgl_s ?>"><i class="bi bi-eye"></i></a>
                            </td>                                
                            </tr>       
                        </div>
                      </div>
                    </div>
              <?php } ?>
          </tbody>

              <tr>
                <td colspan="2" style="font-weight: bold;text-align: center;background-color: #B0C4DE;"> </td>
                <td colspan="1" style="font-weight: bold;text-align: left;background-color: #B0C4DE;">Jumlah Arus Kas dari <?php echo $nama ?> </td>    
                <td style="font-weight: bold;text-align: right;background-color: #B0C4DE;"><?php echo "" . number_format("$total_71", 0, ",", "."); ?></td> 
                <td colspan="1" style="font-weight: bold;text-align: center;background-color: #B0C4DE;"> </td>    
              </tr> 





          <tbody>
                <?php 
                  $naik_turun=$total_01+$total_51+$total_71 ;
                ?>
                <tr>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>
                    <td colspan="2" style="font-weight: bold;text-align: left;background-color: <?php echo$_SESSION['warna_bag']; ?>;">KENAIKAN (PENURUNAN)</td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo "" . number_format("$naik_turun", 0, ",", "."); ?></td>
                    <td> </td>
                </tr>

                <?php 
                  $sql_89 = mysqli_query($koneksi, "SELECT sum(awald) AS t_awald FROM $tabel_tujuan WHERE ry='00' ");
                  list($t_awald) = mysqli_fetch_array($sql_89);
                ?>
                <tr>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>
                    <td colspan="2" style="font-weight: bold;text-align: left;background-color: <?php echo$_SESSION['warna_bag']; ?>;">SALDO AWAL KAS</td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo "" . number_format("$t_awald", 0, ",", "."); ?></td>
                    <td>    
                        <a data-toggle='tooltip' data-placement='top' title='Buka Data Akunt <?php echo $z['nama'] ?>' class="btn btn-primary btn-sm" href="!!_view_trans_per_kd_arus_kas.php?xid=00&toleh=<?php echo $oleh ?>&xtgl_d=<?php echo $tgl_d ?>&xtgl_s=<?php echo $tgl_s ?>"><i class="bi bi-eye"></i></a>
                    </td>                        
                </tr>

                <?php 
                  $t_akhirnya=$naik_turun+$t_awald;
                ?>
                <tr>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>
                    <td colspan="2" style="font-weight: bold;text-align: left;background-color: <?php echo$_SESSION['warna_bag']; ?>;">SALDO AKHIR KAS</td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo "" . number_format("$t_akhirnya", 0, ",", "."); ?></td>
                    <td> </td>
                </tr>

                <?php 
                  $sql_99 = mysqli_query($koneksi, "SELECT sum(akhird) AS t_akhird FROM $tabel_tujuan WHERE ry='00' ");
                  list($t_akhird) = mysqli_fetch_array($sql_99);
                    $selisih=$t_akhird-$t_akhirnya;
                    if ($selisih<>0) { ;
                ?>
                <tr>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>
                    <td colspan="2" style="font-weight: bold;text-align: left;background-color: <?php echo$_SESSION['warna_bag']; ?>;">Kas Setara Kas Neraca Akhir</td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo "" . number_format("$t_akhird", 0, ",", "."); ?></td>
                </tr>                
                <tr>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo ""?></td>
                    <td colspan="2" style="font-weight: bold;text-align: left;background-color: <?php echo$_SESSION['warna_bag']; ?>;">Selisih</td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo "" . number_format("$selisih", 0, ",", "."); ?></td>
                </tr>
                <?php } ?>  










          </tbody>
        </table>
              </div>

              <?php 

            ?>

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

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