<!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>
            PROSPEK
            <small>Data Hasil IKLAN</small>
          </h1>
          <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">IKLAN</a></li>
            <li class="active">Prospek Hasil Iklan</li>
          </ol>
        </section>

        <!-- Main content -->
        <section class="content">
          <div class="row">
            <div class="col-xs-12">
              
              <div class="box">
                <div class="box-header">
				 
				  <?php
					$st = $_GET['status'];
					$filterst = "";
					if ($st == ""){	$st = "ALL";}
					if($st == "" || $st == "ALL"){
						
					}else{
						$filterst = " status = '$st' and ";
					}
					
					$dt = strtotime('today GMT');
					$tglawal = $_GET['tglawal'];
					$tglakhir = $_GET['tglakhir'];
					
					if ($tglawal == ""){
						$tglawal = date('Y-m-d', strtotime('first day of this month', $dt));
					}
					
					if ($tglakhir == ""){
						$tglakhir = date('Y-m-d', strtotime('last day of this month', $dt)); 
					}
					
					echo"<h3 class='box-title'>Data Prospek ($st)</h3><br>
				 
				  <a href='prospekdetails.php?status=ALL&tglawal=$tglawal&tglakhir=$tglakhir' class='btn btn-sm btn-info btn-flat pull-left'>All</a>  
				  <a href='prospekdetails.php?status=Tanya Tanya&tglawal=$tglawal&tglakhir=$tglakhir' class='btn btn-sm btn-info btn-flat pull-left'>Tanya Tanya</a> 
				  <a href='prospekdetails.php?status=Totalan&tglawal=$tglawal&tglakhir=$tglakhir' class='btn btn-sm btn-info btn-flat pull-left'>Totalan</a> 
				  <a href='prospekdetails.php?status=Belanja&tglawal=$tglawal&tglakhir=$tglakhir' class='btn btn-sm btn-info btn-flat pull-left'>Belanja</a> 
				  <a href='prospekdetails.php?status=Close&tglawal=$tglawal&tglakhir=$tglakhir' class='btn btn-sm btn-info btn-flat pull-left'>Close</a> <br>";
				   ?>
 
				  <?php
					
					
					
					
						
					
						
						echo"<br>
								<table>
									<tr>
										<td>
												<form method=POST action='aksicust.php?module=cust&act=filter&status=$_GET[status]'>
												<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>
												</div>
										</td>
									</tr>
								</table>
					<div  class='box-body'><a href='addprospek2.php' class='btn btn-sm btn-info btn-flat pull-left'>Data Baru</a></div> ";
				  ?>
                </div><!-- /.box-header -->
                <div class="box-body">
                  <table id="example2" class="table table-bordered table-striped">
                    <thead>
                      <tr>
						<th>Tanggal</th>
						<th>Iklan</th>
                        <th>Nama</th>
                        <th>Status</th>
						<th>Keterangan</th>
						<th>CS</th>
						<th></th>
                      </tr>
                    </thead>
                    <tbody>
					<?php
						$kasir = $_SESSION['nama'];
						$idd = $_SESSION['idm'];
						$leader = mysql_result(mysql_query("select leader from admins where pk = $idd"),0);
						if($leader == "N"){
							$cek = mysql_query("Select * from  iklanprospek where  tanggal BETWEEN '$tglawal' AND '$tglakhir' and kasir = '$kasir' and aktif = 'Y' order by dateadded desc");
						}else{
							$cek = mysql_query("Select * from  iklanprospek where $filterst tanggal BETWEEN '$tglawal' AND '$tglakhir' and  aktif = 'Y' order by dateadded desc");
						}
	
						while ($r=mysql_fetch_array($cek)){	
		
							$cust = $r['pk'];
							$cat = mysql_result(mysql_query("select category from iklancat where pk = $r[category]"),0);
							$sales = 0;
							$profit = 0;
							$gross = 0;
							$cost = format_rupiah($r['cost']);
							$tgl = tgl_ind($r['tanggal']);
							
							
								$id = $r['iklan'];
								$nama = mysql_result(mysql_query("select nama from iklan where id = $id"),0);
								$salesnm = mysql_result(mysql_query("select userid from admins where pk = (select sales from iklan where id = $id)"),0);
								$namacs = mysql_result(mysql_query("select userid from admins where pk = (select cs from iklan where id = $id)"),0);
								$cat = mysql_result(mysql_query("select category from iklancat where pk = (select category from iklan where id = $id)"),0);
								$produk = mysql_result(mysql_query("select produk from produk where id = (select produk from iklan where id = $id)"),0);
								
								$iklan = $namacs." # ".$salesnm." # ".$cat." # ".$nama."<br>".$produk;
							
							echo "<tr>
									<td>$tgl</td>
									<td>$iklan</td>
									<td>$r[nama]</td>";
									
							if($kasir == $r['kasir']){
								echo"	<td><a href = 'aksicust.php?module=cust&act=prospekup&id=$cust'><i class='fa fa-upload text-success'> </i></a> &nbsp;&nbsp;<a href = 'aksicust.php?module=cust&act=prospekdown&id=$cust'><i class='fa fa-download text-danger'> </i></a>&nbsp;&nbsp;$r[status]</td>";
							}else{
								echo"<td>$r[status]</td>";
							}
									
							echo"		<td>$r[remarks]</td><td>$r[kasir]</td>";
							if($kasir == $r['kasir']){
								echo"		<td><a href='aksicust.php?id=$cust&module=cust&act=delprospek'><span class='label label-danger'>Delete</span></a>  </td>
											</tr>";
							}else{
								echo"		<td> </td>
											</tr>";
							}
						}
					?>
                        
                     
                    </tbody>
                    <tfoot>
                      <tr>
                        <th>Tanggal</th>
						<th>Iklan</th>
                        <th>Nama</th>
                        <th>Status</th>
						<th>Keterangan</th>
						<th>CS</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": true,
          "searching": true,
          "ordering": true,
		  "order": [[ 6, "asc" ]],
          "info": true,
          "autoWidth": false
        });
      });
    </script>
  </body>
</html>
<?php 
	}
?>