<!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>
            DATA HASIL IKLAN
            <small>Data Hasil IKLAN</small>
          </h1>
          <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">BIAYA IKLAN</a></li>
            <li class="active">Data 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">
                  <a href = "data.php"> <i class='fa fa-home btn btn-info'></i> </a><h3 class="box-title">Data Hasil Iklan</h3><br>
				  
				  
					
                    


                    
				  
				  
				  <?php
					$id = $_GET[id];
					$dt = strtotime('today GMT');
					$tglawal = $_GET['tglawal'];
					$tglakhir = $_GET['tglakhir'];
					
						$nama = mysql_result(mysql_query("select nama from iklan where id = $id"),0);
						$kdsales = mysql_result(mysql_query("select sales from iklan where id = $id"),0);
						$sales = 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);
						$produkid = mysql_result(mysql_query("select produk 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);
					
					
					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>$namacs # $sales # $cat # $nama<br>$produk</h3><br>
						<form method=POST action='aksicust.php?module=lap&act=evaluasi&id=$id'>
								<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>";
						
						
						
								
								
								
								
						$idd = $_SESSION['idm'];
						if ($idd == $kdsales){
							echo"<a href='addev.php?id=$id' class='btn btn-sm btn-info btn-flat pull-left'>Data Baru</a> <br><br>";
						}
				  ?>
                </div><!-- /.box-header -->
                <div class="box-body">
                  <table id="example1" class="table table-bordered table-striped">
                    <thead>
                      <tr>
						<th>Tanggal</th>
                        <th>Cost</th>
                        <th>Tanya Tanya</th>
						<th>Totalan</th>
						<th>Lead</th>
						<th>Cost/Lead</th>
						<th>Bonus</th>
						<th>Remarks</th>
						<th></th>
                      </tr>
                    </thead>
                    <tbody>
					<?php
						$cek = mysql_query("Select * from  iklanhasil where (tanggal >= '$tglawal' and tanggal <= '$tglakhir') and iklan = $id 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);
							$tanya = mysql_result(mysql_query("select count(pk) from iklanprospek where status ='Tanya Tanya' and tanggal = '$r[tanggal]' and iklan = $_GET[id]"),0);
							$totalan = mysql_result(mysql_query("select count(pk) from iklanprospek where status ='Totalan' and tanggal = '$r[tanggal]' and iklan = $_GET[id]"),0);;
							$lead = mysql_result(mysql_query("select count(pk) from iklanprospek where tanggal = '$r[tanggal]' and iklan = $_GET[id]"),0);;
							$hariini = $r['tanggal'];
							
							//$saleshariini = format_rupiah(mysql_result(mysql_query("select sum(qty) from jualcsdetail inner join jualcs on jualcs.billno = jualcsdetail.billno and (billdate = '$hariini' and jualcs.billdate in (select tanggal from iklanhasil where iklan=$_GET[id] and tanggal = '$hariini')) and jualcs.iklan = $_GET[id] and jualcsdetail.produk = $produkid "),0));
							
							$saleshariini = mysql_result(mysql_query("select sum(qty * unit_tp) from qiklan2 where pk =$cust"),0);
							
							$profitperproduk = mysql_result(mysql_query("select unit_tp from produk where id =$produkid"),0);
							
							$bonus = format_rupiah($saleshariini / 100);
							
						
							$cost = format_rupiah($r['cost']);
							if($r['cost'] == 0 || $lead == 0){
								$costperlead = 0;
							}else{
								$costperlead = format_rupiah($r['cost'] / $lead);
							}
							$tgl = tgl_ind($r['tanggal']);
							
							echo "<tr>
									<td>$tgl</td>
									<td>$cost</td>
									<td>$tanya</td>
									<td>$totalan</td>
									<td>$lead</td>
									<td>$costperlead</td>
									<td>$bonus</td>
									<td>$r[remarks]</td>";
									if ($idd == $kdsales){
										echo"
										<td><a href='editev.php?id=$cust&iklan=$id'><span class='label label-success'>Edit</span></a><a href='aksicust.php?id=$cust&iklan=$id&module=cust&act=delhasil'><span class='label label-danger'>Delete</span></a>  </td>";
									}else{
										echo"
										<td> </td>";
									}
							echo"
								  </tr>";
						}
					?>
                        
                     
                    </tbody>
                    <tfoot>
                      <tr>
                        <th>Tanggal</th>
                        <th>Cost</th>
                        <th>Tanya Tanya</th>
						<th>Totalan</th>
						<th>Lead</th>
						<th>Cost/Lead</th>
						<th>Bonus</th>
						<th>Remarks</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 
	}
?>