<!DOCTYPE html>

<?php 
	session_start();
	@ob_start();
	include "../../config/koneksi.php";
	include "../../config/fungsi_rupiah.php";
	include "../../config/fungsi_indotgl.php";
	include "../head.php";

	
	if ($_SESSION['nama'] == ''){
		header('Location:index.php');
	}
	else{
?>
<html>

  <body class="hold-transition skin-blue sidebar-mini layout-boxed">
    <div class="wrapper">
		<?php include "../header.php";?>
      
		<?php include "../menu.php";?>
      

      <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            Laporan
            <small>Neraca</small>
          </h1>
          <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="neraca.php">Laporan</a></li>
            <li class="active"><a href="data.php"><u>Neraca</u></a></li>
          </ol>
        </section>

        <!-- Main content -->
        <section class="content">
          <div class="row">
            <div class="col-xs-12">
			<?php		
				$dt = strtotime('today GMT');
				$tglawal = $_GET['tglawal'];
				$tglakhir = $_GET['tglakhir'];
					
				if ($tglawal == ""){
					$tglawal = date('Y-m-01');
				}
				
				if ($tglakhir == ""){
					$tglakhir = date('Y-m-t'); 
				}		

				
				$sql = "";
				$cek5 = mysql_query("Select * from  qjurnaldetail where (billdate <= '$tglakhir') order by billdate asc");
				while ($r5=mysql_fetch_array($cek5)){
					$kasir = $_SESSION['nama'];
					$sql = $sql."('$kasir','$r5[jenis]','$r5[billdate]','$r5[cust]','$r5[custname]','$r5[dateadded]','$r5[debet]','$r5[kredit]','$r5[akun]'), ";
					
				}
				$sql = "Insert into qqjurnaldetail(kasir,jenis,billdate,cust,custname,dateadded,debet,kredit,akun) values ".substr($sql,0,(strlen($sql) - 2)).";";
				mysql_query("TRUNCATE  qqjurnaldetail");
				mysql_query("$sql");
			?>
              
              <div class="box">
                <div class="box-header">
                  <h3 class="box-title">Laporan Neraca</h3><br><br>
				  
				  <?php
						
						echo"
						<form method=POST action='aksisales.php?module=lap&act=neraca'>
								<table>
									<tr>
										<td>
												<div class='input-group'>
													<i class='fa fa-calendar'> From </i> <input value = '$tglawal' name ='awal' type = 'date'>
												</div>
										</td>
										<td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
										</td>
										<td>
												<div class='input-group'>
													<i class='fa fa-calendar'> To</i> <input value = '$tglakhir' name='akhir' type = 'date'>
												</div>
										</td>
										<td>
												<div class='input-group'>
													<button type='submit'> GO </button></form>
												</div>
										</td>
									</tr>
								</table><br>";

			
			
				?>
                </div><!-- /.box-header -->
                <div class="box-body">
					<div class="col-md-6">
						  <table id="example1" class="table table-bordered table-striped">
							<thead>
							  <tr>
								<th>AKTIVA</th>
								<th></th>
							  </tr>
							</thead>
							<tbody>
							<?php
								$aktiva = 0;
								$cek = mysql_query("Select * from akun_format where class = 1 order by id asc");
								while ($r=mysql_fetch_array($cek)){	
									echo"
									<tr>
										<td><u>$r[nama_format]</u></td>
										<td align='right'></td>
									</tr>";
									$cek2 = mysql_query("Select * from akun_master where format = $r[id] order by kode_rek asc");
									while ($r2=mysql_fetch_array($cek2)){	
										$namaakun = $r2['kode_rek']." - ".$r2['nama_rek'];
										$nilaiakun = mysql_result(mysql_query("select sum(debet - kredit) from qqjurnaldetail where (billdate <= '$tglakhir') and akun = $r2[id] "),0);
										$aktiva= $aktiva + $nilaiakun;
										$nilaiakun2 = number_format($nilaiakun,2);
										echo"
										<tr>
											<td>&nbsp;&nbsp;&nbsp;&nbsp;$namaakun</td>
											<td align='right'>$nilaiakun2</td>
										</tr>";
									}
								}
								
							?>
								
							 
							</tbody>
							
						  </table>
						  
						  <h3>Total AKTIVA : <?php $aktiva2 = number_format($aktiva); echo"$aktiva2"; ?></h3>
					</div>
					
					<div class="col-md-6">
						  <table id="example2" class="table table-bordered table-striped">
							<thead>
							  <tr>
								<th>PASSIVA</th>
								<th></th>
							  </tr>
							</thead>
							<tbody>
							<?php
								$pasiva= 0;
								$cek = mysql_query("Select * from akun_format where class = 2 order by id asc");
								while ($r=mysql_fetch_array($cek)){	
									echo"
									<tr>
										<td><u>$r[nama_format]</u></td>
										<td align='right'></td>
									</tr>";
									$cek2 = mysql_query("Select * from akun_master where format = $r[id] order by kode_rek asc");
									while ($r2=mysql_fetch_array($cek2)){	
										$namaakun = $r2['kode_rek']." - ".$r2['nama_rek'];
										$nilaiakun = mysql_result(mysql_query("select sum(debet - kredit) from qqjurnaldetail where (billdate <= '$tglakhir') and akun = $r2[id] "),0);
										$pasiva= $pasiva + $nilaiakun;
										$nilaiakun2 = number_format($nilaiakun,2);
										echo"
										<tr>
											<td>&nbsp;&nbsp;&nbsp;&nbsp;$namaakun</td>
											<td align='right'>$nilaiakun2</td>
										</tr>";
									}
								}
								
							?>
								
							 
							</tbody>
							
						  </table>
						  
						  <h3>Total PASSIVA : <?php $pasiva2 = number_format($pasiva); echo"$pasiva2"; ?></h3>
					</div>

                </div><!-- /.box-body -->
              </div><!-- /.box -->
            </div><!-- /.col -->
          </div><!-- /.row -->
        </section><!-- /.content -->
		
		<!-- Modal form-->
                <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                  <div class="modal-dialog ">
                    <div class="modal-content">
                      <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                        <h4 class="modal-title" id="myModalLabel"></h4>
                      </div>
                      <div class="modal-body" id="modal-bodyku">
                      </div>
                      <div class="modal-footer" id="modal-footerq">
                      </div>
                    </div>
                  </div>
                </div>
                <!-- end of modal ------------------------------>
		
		
      </div><!-- /.content-wrapper -->
		<?php include "../footer.php";?>
		

      <!-- Control Sidebar -->
      <aside class="control-sidebar control-sidebar-dark">

        <!-- Tab panes -->
        <div class="tab-content">
          <!-- Home tab content -->
          <div class="tab-pane" id="control-sidebar-home-tab">

          </div><!-- /.tab-pane -->

        </div>
      </aside><!-- /.control-sidebar -->
      <!-- Add the sidebar's background. This div must be placed
           immediately after the control sidebar -->
      <div class="control-sidebar-bg"></div>
    </div><!-- ./wrapper -->
	
	

    <!-- jQuery 2.1.4 -->
    <script src="../../plugins/jQuery/jQuery-2.1.4.min.js"></script>
    <!-- Bootstrap 3.3.5 -->
    <script src="../../bootstrap/js/bootstrap.min.js"></script>
    <!-- DataTables -->
    <script src="../../plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="../../plugins/datatables/dataTables.bootstrap.min.js"></script>
    <!-- SlimScroll -->
    <script src="../../plugins/slimScroll/jquery.slimscroll.min.js"></script>
    <!-- FastClick -->
    <script src="../../plugins/fastclick/fastclick.min.js"></script>
    <!-- AdminLTE App -->
    <script src="../../dist/js/app.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="../../dist/js/demo.js"></script>
    <!-- page script -->
    <script>
      $(function () {
        $('#example2').DataTable({
          "paging": false,
          "lengthChange": false,
          "searching": false,
          "ordering": false,
		  "order": [[ 0, "desc" ]],
          "info": false,
          "autoWidth": false
        });
        $('#example1').DataTable({
          "paging": false,
          "lengthChange": false,
          "searching": false,
          "ordering": false,
		  "order": [[ 0, "desc" ]],
          "info": false,
          "autoWidth": false
        });
      });
    </script>
	
	
  </body>
</html>
<?php 
	}
?>