<!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>
            SALES REPORT HARIAN
            <small></small>
          </h1>
          <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="data.php">HARIAN</a></li>
            <li class="active"><a href="data.php"><u>SALES REPORT</u></a></li>
          </ol>
        </section>

        <!-- Main content -->
        <section class="content">
          <div class="row">
            <div class="col-xs-12">
              
              <div class="box">
                
                <div class="box-body">
					<div class="box-header">
                  <h3 class="box-title"><b>SALES REPORT HARIAN 
				  
				  <br>MARKETING : <?php $marketing = $_GET['id']; echo"$marketing"; ?></h3><br><br>
                </div><!-- /.box-header -->
				  
				  <table id="example1" class="table table-bordered table-striped">
                    <thead>
                      <tr>
						<th>JENIS BARANG</th>
						<th>BULAN</th>
						<th>QTY </th>
						<th>ACHIEVEMENT </th>

                      </tr>
                    </thead>
                    <tbody>
					<?php
					
						$bln1 = strtoupper(date("M", strtotime("-3 months")));
						$bln2 = strtoupper(date("M", strtotime("-2 months")));
						$bln3 = strtoupper(date("M", strtotime("-1 months")));
						
						
						$from1 =  date("Y-m-1", strtotime("-3 month") ) ;
						$to1 = date("Y-m-t", strtotime("-3 month") ) ;
						
						$from2 =  date("Y-m-1", strtotime("-2 month") ) ;
						$to2 = date("Y-m-t", strtotime("-2 month") ) ;
						
						$from3 =  date("Y-m-1", strtotime("-1 month") ) ;
						$to3 = date("Y-m-t", strtotime("-1 month") ) ;

						$tot1a = mysql_result(mysql_query("select sum(total) from icslm where (tglsj >= '$from1' and tglsj <= '$to1') and xfrom = 'pvc' and salesname = '$marketing' order by nosj desc"),0);
						$tot1aa = format_rupiah($tot1a);
						$tot1b = mysql_result(mysql_query("select sum(total) from icslm where (tglsj >= '$from2' and tglsj <= '$to2') and xfrom = 'pvc' and salesname = '$marketing' order by nosj desc"),0);
						$tot1bb = format_rupiah($tot1b);
						$tot1c = mysql_result(mysql_query("select sum(total) from icslm where (tglsj >= '$from3' and tglsj <= '$to3') and xfrom = 'pvc' and salesname = '$marketing' order by nosj desc"),0);
						$tot1cc = format_rupiah($tot1c);
						
						
						$tot2a = mysql_result(mysql_query("select sum(total) from icslm where (tglsj >= '$from1' and tglsj <= '$to1') and xfrom = 'acp' and salesname = '$marketing' order by nosj desc"),0);
						$tot2aa = format_rupiah($tot2a);
						$tot2b = mysql_result(mysql_query("select sum(total) from icslm where (tglsj >= '$from2' and tglsj <= '$to2') and xfrom = 'acp' and salesname = '$marketing' order by nosj desc"),0);
						$tot2bb = format_rupiah($tot2b);
						$tot2c = mysql_result(mysql_query("select sum(total) from icslm where (tglsj >= '$from3' and tglsj <= '$to3') and xfrom = 'acp' and salesname = '$marketing' order by nosj desc"),0);
						$tot2cc = format_rupiah($tot2c);
						
						
						$tot3a = mysql_result(mysql_query("select sum(total) from icslm where (tglsj >= '$from1' and tglsj <= '$to1') and xfrom = 'slc' and salesname = '$marketing' order by nosj desc"),0);
						$tot3aa = format_rupiah($tot3a);
						$tot3b = mysql_result(mysql_query("select sum(total) from icslm where (tglsj >= '$from2' and tglsj <= '$to2') and xfrom = 'slc' and salesname = '$marketing' order by nosj desc"),0);
						$tot3bb = format_rupiah($tot3b);
						$tot3c = mysql_result(mysql_query("select sum(total) from icslm where (tglsj >= '$from3' and tglsj <= '$to3') and xfrom = 'slc' and salesname = '$marketing' order by nosj desc"),0);
						$tot3cc = format_rupiah($tot3c);

						
						
						
						$bln1 =  date("m", strtotime("-3 month") ) ;
						$thn1 = date("Y", strtotime("-3 month") ) ;
						
						$bln2 =  date("m", strtotime("-2 month") ) ;
						$thn2 = date("Y", strtotime("-2 month") ) ;
						
						$bln3 =  date("m", strtotime("-1 month") ) ;
						$thn3 = date("Y", strtotime("-1 month") ) ;
						
						$target1 = mysql_result(mysql_query("select nominal from target2 where tahun = '$thn1' and bulan = '$bln1' and  jenis = 'PVC' and salesname = '$marketing'"),0);
						$target1a = format_rupiah($target1);
						
						$target11 = mysql_result(mysql_query("select nominal from target2 where tahun = '$thn2' and bulan = '$bln2' and  jenis = 'PVC' and salesname = '$marketing'"),0);
						$target1aa = format_rupiah($target11);
						
						$target111 = mysql_result(mysql_query("select nominal from target2 where tahun = '$thn3' and bulan = '$bln3' and  jenis = 'PVC' and salesname = '$marketing'"),0);
						$target1aaa = format_rupiah($target111);
						
						$target2 = mysql_result(mysql_query("select nominal from target2 where tahun = '$thn1' and bulan = '$bln1' and  jenis = 'ACP' and salesname = '$marketing'"),0);
						$target2a = format_rupiah($target2);
						
						$target22 = mysql_result(mysql_query("select nominal from target2 where tahun = '$thn2' and bulan = '$bln2' and  jenis = 'ACP' and salesname = '$marketing'"),0);
						$target2aa = format_rupiah($target22);
						
						$target222 = mysql_result(mysql_query("select nominal from target2 where tahun = '$thn3' and bulan = '$bln3' and  jenis = 'ACP' and salesname = '$marketing'"),0);
						$target2aaa = format_rupiah($target222);
						
						$target3 = mysql_result(mysql_query("select nominal from target2 where tahun = '$thn1' and bulan = '$bln1' and  jenis = 'SLC' and salesname = '$marketing'"),0);
						$target3a = format_rupiah($target3);
						
						$target33 = mysql_result(mysql_query("select nominal from target2 where tahun = '$thn2' and bulan = '$bln2' and  jenis = 'SLC' and salesname = '$marketing'"),0);
						$target3aa = format_rupiah($target33);
						
						$target333 = mysql_result(mysql_query("select nominal from target2 where tahun = '$thn3' and bulan = '$bln3' and  jenis = 'SLC' and salesname = '$marketing'"),0);
						$target3aaa = format_rupiah($target333);

						
						
						if($target1 == 0){$persen1a = 0;}else{$persen1a = $tot1a / $target1 * 100;}
						$persen1aa = number_format($persen1a, 2, '.', '');
						
						if($target11 == 0){$persen1b = 0;}else{$persen1b = $tot1b / $target11 * 100;}
						$persen1bb = number_format($persen1b, 2, '.', '');
						
						if($target111== 0){$persen1c = 0;}else{$persen1c = $tot1c / $target111 * 100;}
						$persen1cc = number_format($persen1c, 2, '.', '');
						
						
						
						if($target2 == 0){$persen2a = 0;}else{$persen2a = $tot2a / $target2 * 100;}
						$persen2aa = number_format($persen2a, 2, '.', '');
						
						if($target22 == 0){$persen2b = 0;}else{$persen2b = $tot2b / $target22 * 100;}
						$persen2bb = number_format($persen2b, 2, '.', '');
						
						if($target222 == 0){$persen2c = 0;}else{$persen2c = $tot2c / $target222 * 100;}
						$persen2cc = number_format($persen2c, 2, '.', '');
							
						
						
						if($target3 == 0){$persen3a = 0;}else{$persen3a = $tot3a / $target3 * 100;}
						$persen3aa = number_format($persen3a, 2, '.', '');
						
						if($target33 == 0){$persen3b = 0;}else{$persen3b = $tot3b / $target33 * 100;}
						$persen3bb = number_format($persen3b, 2, '.', '');
						
						if($target333 == 0){$persen3c = 0;}else{$persen3c = $tot3c / $target333 * 100;}
						$persen3cc = number_format($persen3c, 2, '.', '');

						

						
						$qty1a = mysql_result(mysql_query("select sum(qty) from vorderdetails where (billdate >= '$from1' and billdate <= '$to1') and category = '2' and pengangkutan <> '' and batal = 0 and kasir = '$marketing' order by billno desc"),0);
						$qty1b = mysql_result(mysql_query("select sum(qty) from vorderdetails where (billdate >= '$from2' and billdate <= '$to2') and category = '2' and pengangkutan <> '' and batal = 0 and kasir = '$marketing' order by billno desc"),0);
						$qty1c = mysql_result(mysql_query("select sum(qty) from vorderdetails where (billdate >= '$from3' and billdate <= '$to3') and category = '2' and pengangkutan <> '' and batal = 0 and kasir = '$marketing' order by billno desc"),0);
						
						
						$qty2a = mysql_result(mysql_query("select sum(qty) from vorderdetails where (billdate >= '$from1' and billdate <= '$to1') and category = '5' and pengangkutan <> '' and batal = 0 and kasir = '$marketing' order by billno desc"),0);
						$qty2b = mysql_result(mysql_query("select sum(qty) from vorderdetails where (billdate >= '$from2' and billdate <= '$to2') and category = '5' and pengangkutan <> '' and batal = 0 and kasir = '$marketing' order by billno desc"),0);
						$qty2c = mysql_result(mysql_query("select sum(qty) from vorderdetails where (billdate >= '$from3' and billdate <= '$to3') and category = '5' and pengangkutan <> '' and batal = 0 and kasir = '$marketing' order by billno desc"),0);
						
						
						$qty3a = mysql_result(mysql_query("select sum(qty) from vorderdetails where (billdate >= '$from1' and billdate <= '$to1') and category = '3' and pengangkutan <> '' and batal = 0 and kasir = '$marketing' order by billno desc"),0);
						$qty3b = mysql_result(mysql_query("select sum(qty) from vorderdetails where (billdate >= '$from2' and billdate <= '$to2') and category = '3' and pengangkutan <> '' and batal = 0 and kasir = '$marketing' order by billno desc"),0);
						$qty3c = mysql_result(mysql_query("select sum(qty) from vorderdetails where (billdate >= '$from3' and billdate <= '$to3') and category = '3' and pengangkutan <> '' and batal = 0 and kasir = '$marketing' order by billno desc"),0);
						
						
						echo" <tr>
								<td>PVC</td>
								<td>$bln1</td>
								<td>$qty1a</td>
								<td>
									Target : $target1a <br>
									Achievement : $tot1aa
									
									<div class='progress' >
									  <div class='progress-bar progress-bar-danger progress-bar-striped' role='progressbar'
									  aria-valuenow='$persen1aa' aria-valuemin='0' aria-valuemax='100' style='width:$persen1aa%;-webkit-print-color-adjust: exact;'>
										$persen1aa% Complete
									  </div>
									</div>
								</td>

							</tr>
						";
						
						echo" <tr>
								<td></td>
								<td>$bln2</td>
								<td>$qty1b</td>
								<td>
									Target : $target1aa <br>
									Achievement : $tot1bb
								<div class='progress'>
									  <div class='progress-bar progress-bar-danger progress-bar-striped' role='progressbar'
									  aria-valuenow='$persen1bb' aria-valuemin='0' aria-valuemax='100' style='width:$persen1bb%'>
										$persen1bb% Complete
									  </div>
									</div>
								</td>

							</tr>
						";
						
						echo" <tr>
								<td></td>
								<td>$bln3</td>
								<td>$qty1c</td>
								<td> Target : $target1aaa <br>
									Achievement : $tot1cc
								<div class='progress'>
									  <div class='progress-bar progress-bar-danger progress-bar-striped' role='progressbar'
									  aria-valuenow='$persen1cc' aria-valuemin='0' aria-valuemax='100' style='width:$persen1cc%'>
										$persen1cc% Complete
									  </div>
									</div>
								</td>

							</tr>
						";
						
						
						
						
						//acp
						echo" <tr>
								<td>ACP</td>
								<td>$bln1</td>
								<td>$qty2a</td>
								<td>
									Target : $target2a <br>
									Achievement : $tot2aa
									
									<div class='progress'>
									  <div class='progress-bar progress-bar-warning progress-bar-striped' role='progressbar'
									  aria-valuenow='$persen2aa' aria-valuemin='0' aria-valuemax='100' style='width:$persen2aa%'>
										$persen2aa% Complete
									  </div>
									</div>
								</td>

							</tr>
						";
						
						echo" <tr>
								<td></td>
								<td>$bln2</td>
								<td>$qty2b</td>
								<td>
									Target : $target2aa <br>
									Achievement : $tot2bb
								<div class='progress'>
									  <div class='progress-bar progress-bar-warning progress-bar-striped' role='progressbar'
									  aria-valuenow='$persen2bb' aria-valuemin='0' aria-valuemax='100' style='width:$persen2bb%'>
										$persen2bb% Complete
									  </div>
									</div>
								</td>

							</tr>
						";
						
						echo" <tr>
								<td></td>
								<td>$bln3</td>
								<td>$qty2c</td>
								<td> Target : $target2aaa <br>
									Achievement : $tot2cc
								<div class='progress'>
									  <div class='progress-bar progress-bar-warning progress-bar-striped' role='progressbar'
									  aria-valuenow='$persen2cc' aria-valuemin='0' aria-valuemax='100' style='width:$persen2cc%'>
										$persen2cc% Complete
									  </div>
									</div>
								</td>

							</tr>
						";
						
						
						//slc
						echo" <tr>
								<td>SLC</td>
								<td>$bln1</td>
								<td>$qty3a</td>
								<td>
									Target : $target3a <br>
									Achievement : $tot3aa
									
									<div class='progress'>
									  <div class='progress-bar progress-bar-info progress-bar-striped' role='progressbar'
									  aria-valuenow='$persen3aa' aria-valuemin='0' aria-valuemax='100' style='width:$persen3aa%'>
										$persen3aa% Complete
									  </div>
									</div>
								</td>

							</tr>
						";
						
						echo" <tr>
								<td></td>
								<td>$bln2</td>
								<td>$qty3b</td>
								<td>
									Target : $target3aa <br>
									Achievement : $tot3bb
								<div class='progress'>
									  <div class='progress-bar progress-bar-info progress-bar-striped' role='progressbar'
									  aria-valuenow='$persen3bb' aria-valuemin='0' aria-valuemax='100' style='width:$persen3bb%'>
										$persen3bb% Complete
									  </div>
									</div>
								</td>

							</tr>
						";
						
						echo" <tr>
								<td></td>
								<td>$bln3</td>
								<td>$qty3c</td>
								<td> Target : $target3aaa <br>
									Achievement : $tot3cc
								<div class='progress'>
									  <div class='progress-bar progress-bar-info progress-bar-striped' role='progressbar'
									  aria-valuenow='$persen3cc' aria-valuemin='0' aria-valuemax='100' style='width:$persen3cc%'>
										$persen3cc% Complete
									  </div>
									</div>
								</td>

							</tr>
						";
						
					?>
                        
                     
                    </tbody>
                   
                  </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 () {
        $("#example2").DataTable();
        $('#example1').DataTable({
          "paging": true,
          "lengthChange": true,
          "searching": true,
          "order": false,
          "info": true,
          "autoWidth":  false,
		  "scrollX": true
        });
      });
    </script>
  </body>
</html>
<?php 
	}
?>