<!DOCTYPE html>

<?php 
	session_start();
	@ob_start();
	include "../../config/koneksi.php";
	include "../../config/fungsi_rupiah.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>
            DATA PIUTANG CUSTOMER
            <small>Data Piutang</small>
          </h1>
          <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">Customer</a></li>
            <li class="active">Data Piutang</li>
          </ol>
        </section>

        <!-- Main content -->
        <section class="content">
          <div class="row">
            <div class="col-xs-12">
              
              <div class="box">
                <div class="box-header">
                  <h3 class="box-title">List Piutang Customer</h3><br><br>
				  <a href="piutang.php?id=semen" class="btn btn-sm btn-info btn-flat pull-left">SEMEN</a><a href="piutang.php?id=pvc" class="btn btn-sm btn-info btn-flat pull-left">PVC</a><a href="piutang.php?id=slc" class="btn btn-sm btn-info btn-flat pull-left">SLC</a><a href="piutang.php?id=acp" class="btn btn-sm btn-info btn-flat pull-left">ACP</a>
				  <br><br>Note : <span class='label label-warning'>>=20%</span><span class='label label-danger'>0%</span><br>
				</div><!-- /.box-header -->
                <div class="box-body">
                  <table id="example1" class="table table-bordered table-striped">
                    <thead>
                      <tr>
                        <th>Customer</th>
                        <th>Limit</th>
                        <th>Total Otstg</th>
                        <th>Sisa Limit</th>
						<th>(%)</th>
						<th></th>
                      </tr>
                    </thead>
                    <tbody>
					<?php
						$id = $_GET['id'];
						$cat2 = "";
						if($id == "semen"){
							$cat ="1.SMN";
							$cat2 = " or jenis = '6.SMP' ";
						}elseif($id == "pvc"){
							$cat = "3.PVC";
						}elseif($id == "slc"){
							$cat = "4.SLC";
						}elseif($id == "acp"){
							$cat = "2.ACP";
						}
						$salesman = $_SESSION['nama'];
						$idd = $_SESSION['idm'];
						$super = mysql_result(mysql_query("select super from admins where pk = $idd"),0);
						if ($super == "Y"){
							$cek = mysql_query("Select * from  qpiutang where jenis = '$cat' $cat2 order by custname asc");
						}else{
							$cek = mysql_query("Select * from  qpiutang where salesman = '$salesman' and jenis = '$cat'  $cat2 order by custname asc");
						}
						while ($r=mysql_fetch_array($cek)){	
							$plaf = format_rupiah($r['plafond']);
							$pakai = format_rupiah($r['sisa']);
							//if ($r['sisa'] > $r['plafond']){
							//	$sisa2= "0";
							//	$persen = 0;
							//}else{
								$sisa = $r['plafond'] - $r['sisa'];
								$sisa2= format_rupiah($sisa);
								if ($r['plafond'] == 0){
									$persen = 0;
								}else{
									$persen = format_rupiah($sisa / $r['plafond'] * 100);
								}
								
							//}
							
							if ($persen > "20"){
								$warna = " ";
							}else{
								if ($persen > "0"){
									$warna = " class = 'warning'";
								}else{
									$warna = " class = 'danger'";
								}
							}	
							
							
							echo "<tr>
									<td $warna>$r[custname]</td>
									<td $warna>$plaf</td>
									<td $warna>$pakai</td>
									<td $warna>$sisa2</td>
									<td $warna>$persen</td>
									<td $warna><a href='piutangdetail.php?id=$r[custname]&jenis=$id'><span class='label label-success'>View</span></a> </td>
								  </tr>";
						}
					?>
                        
                     
                    </tbody>
                    <tfoot>
                      <tr>
                        <th>Customer</th>
                        <th>Limit</th>
                        <th>Total Otstg</th>
                        <th>Sisa Limit</th>
						<th>(%)</th>
                      </tr>
                    </tfoot>
                  </table>
                </div><!-- /.box-body -->
              </div><!-- /.box -->
            </div><!-- /.col -->
          </div><!-- /.row -->
        </section><!-- /.content -->
      </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 () {
        $("#example1").DataTable();
        $('#example2').DataTable({
          "paging": true,
          "lengthChange": false,
          "searching": false,
          "ordering": true,
          "info": true,
          "autoWidth": false
        });
      });
    </script>
  </body>
</html>
<?php 
	}
?>