<!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-header">
                  <h3 class="box-title"><b>SALES REPORT HARIAN <br> PERIODE :
				  <?php 
					$periode = date('M - Y'); 
					echo"$periode"; 
				  ?> 
				  
				  <br>DATA CURAH LCI</h3><br><br>
                </div><!-- /.box-header -->
                <div class="box-body">
					Note : <span class='label label-success'>Semen</span> <span class='label label-warning'>ACP</span><span class='label label-danger'>PVC</span><span class='label label-info'>SILICONE</span><br><br>
                  <table id="example1" class="table table-bordered table-striped">
                    <thead>
                      <tr>
						<th>TGL</th>
						<th>NAMA CUSTOMER</th>
						<th>TIPE </th>
						<th>QTY </th>
                        <th>HARGA</th>
						<th>TOTAL</th>
						<th>WARNA</th>
						<th>QTY</th>
						<th>HARGA</th>
						<th>TOTAL</th>
						<th>SIZE </th>
						<th>QTY </th>
                        <th>HARGA</th>
						<th>TOTAL</th>
						<th>TIPE</th>
						<th>QTY</th>
						<th>HARGA</th>
						<th>TOTAL</th>
                      </tr>
                    </thead>
                    <tbody>
					<?php
						$dt = strtotime('today GMT');
						$tglawal = date('Y-m-d', strtotime('first day of this month', $dt));
						$tglakhir = date('Y-m-d', strtotime('last day of this month', $dt));
						$tot1 = mysql_result(mysql_query("select sum(linetotal) from vorderdetails where (billdate >= '$tglawal' and billdate <= '$tglakhir') and (category = 1)  and batal = 0 and product in ('PCC  BULK','OPC BULK') order by billno desc"),0);
						$tot1a = format_rupiah($tot1);
						$tot2 = mysql_result(mysql_query("select sum(linetotal) from vorderdetails where (billdate >= '$tglawal' and billdate <= '$tglakhir') and category = 2 and pengangkutan <> '' and batal = 0 and kasir = '$marketing' order by billno desc"),0);
						$tot2a = format_rupiah($tot2);
						$tot3 = mysql_result(mysql_query("select sum(linetotal) from vorderdetails where (billdate >= '$tglawal' and billdate <= '$tglakhir') and category = 3 and pengangkutan <> '' and batal = 0 and kasir = '$marketing' order by billno desc"),0);
						$tot3a = format_rupiah($tot3);
						$tot4 = mysql_result(mysql_query("select sum(linetotal) from vorderdetails where (billdate >= '$tglawal' and billdate <= '$tglakhir') and category = '5' and pengangkutan <> '' and batal = 0 and kasir = '$marketing' order by billno desc"),0);
						$tot4a = format_rupiah($tot4);
						
						$target1 = mysql_result(mysql_query("select nominal from target2 where jenis = 'LCI' and bulan = '1' and tahun = '2018'"),0);
						$target1a = format_rupiah($target1);
						
						$target2 = mysql_result(mysql_query("select target from target where jenis = 2 and marketing = '$marketing'"),0);
						$target2a = format_rupiah($target2);
						
						$target3 = mysql_result(mysql_query("select target from target where jenis = 3 and marketing = '$marketing'"),0);
						$target3a = format_rupiah($target3);
						
						$target4 = mysql_result(mysql_query("select target from target where jenis = 5 and marketing = '$marketing'"),0);
						$target4a = format_rupiah($target4);
						
						
						if($target1 == 0){$persen1 = 0;}else{$persen1 = $tot1 / $target1 * 100;}
						$persen1a = number_format($persen1, 2, '.', '');
						
						if($target2 == 0){$persen2 = 0;}else{$persen2 = $tot2 / $target2 * 100;}
						$persen2a = number_format($persen2, 2, '.', '');
						
						if($target3 == 0){$persen3 = 0;}else{$persen3 = $tot3 / $target3 * 100;}
						$persen3a = number_format($persen3, 2, '.', '');
						
						if($target4 == 0){$persen4 = 0;}else{$persen4 = $tot4 / $target4 * 100;}
						$persen4a = number_format($persen4, 2, '.', '');
						
						$qty1 = mysql_result(mysql_query("select sum(qty) from vorderdetails where (billdate >= '$tglawal' and billdate <= '$tglakhir') and (category = 1 or category = 6)  and batal = 0 and product in ('PCC  BULK','OPC BULK') order by billno desc"),0);
						$qty2 = mysql_result(mysql_query("select sum(qty) from vorderdetails where (billdate >= '$tglawal' and billdate <= '$tglakhir') and category = '2' and pengangkutan <> '' and batal = 0 and kasir = '$marketing' order by billno desc"),0);
						$qty3 = mysql_result(mysql_query("select sum(qty) from vorderdetails where (billdate >= '$tglawal' and billdate <= '$tglakhir') and category = '3' and pengangkutan <> '' and batal = 0 and kasir = '$marketing' order by billno desc"),0);
						$qty4 = mysql_result(mysql_query("select sum(qty) from vorderdetails where (billdate >= '$tglawal' and billdate <= '$tglakhir') and category = '5' and pengangkutan <> '' and batal = 0 and kasir = '$marketing' order by billno desc"),0);
						
						
						echo" <tr>
								<td></td>
								<td>Nominal Objective</td>
								<td class='label-success'>$persen1a%</td>
								<td class='label-success'><br>$qty1</td>
								<td class='label-success'></td>
								<td align= 'right' class='label-success'>$target1a<br>$tot1a</td>
								<td class='label-warning'>$persen4a%</td>
								<td class='label-warning'><br>$qty4</td>
								<td class='label-warning'></td>
								<td align= 'right' class='label-warning'>$target4a<br>$tot4a</td>
								<td class='label-danger'>$persen2a%</td>
								<td class='label-danger'><br>$qty2</td>
								<td class='label-danger'></td>
								<td align= 'right' class='label-danger'>$target2a<br>$tot2a</td>
								<td class='label-info'>$persen3a%</td>
								<td class='label-info'><br>$qty3</td>
								<td class='label-info'></td>
								<td align= 'right' class='label-info'>$target3a<br>$tot3a</td>
							</tr>
						";
						
						$cek = mysql_query("Select billdate,customerid,customername,code,product,category,sum(qty) as qty, sum(linetotal) as linetotal from vorderdetails where  (billdate >= '$tglawal' and billdate <= '$tglakhir') and batal = 0 and product in ('PCC  BULK','OPC BULK') and category = 1 group by billdate,customerid,customername,code,product,category order by billno desc");
						while ($r=mysql_fetch_array($cek)){	
						
							$tgl=substr($r['billdate'],8,2).'-'.substr($r['billdate'],5,2);
							echo "
									<td>$tgl</td>
									<td>$r[customername]</td>";
							if($r['category'] == 1 or $r['category'] == 6){
								$price = format_rupiah($r['price']);
								$tot = format_rupiah($r['linetotal']);
								echo"
								<td class='label-success'>$r[product]</td>
								<td class='label-success'>$r[qty]</td>
								<td align= 'right' class='label-success'>$price</td>
								<td align= 'right' class='label-success'>$tot</td>";								
							}else{
								echo"
									<td class='label-success'></td>
									<td class='label-success'></td>
									<td class='label-success'></td>
									<td class='label-success'></td>";
							}
							if($r['category'] == 5){
								$price = format_rupiah($r['price']);
								$tot = format_rupiah($r['linetotal']);
								echo"
								<td class='label-warning'>$r[product]</td>
								<td class='label-warning'>$r[qty]</td>
								<td align= 'right' class='label-warning'>$price</td>
								<td align= 'right' class='label-warning'>$tot</td>";
								
							}else{
								echo"
									<td class='label-warning'></td>
									<td class='label-warning'></td>
									<td class='label-warning'></td>
									<td class='label-warning'></td>";
							}
							if($r['category'] == 2){
								$price = format_rupiah($r['price']);
								$tot = format_rupiah($r['linetotal']);
								echo"
								<td class='label-danger'>$r[product]</td>
								<td class='label-danger'>$r[qty]</td>
								<td align= 'right' class='label-danger'>$price</td>
								<td align= 'right' class='label-danger'>$tot</td>";
								
							}else{
								echo"
									<td class='label-danger'></td>
									<td class='label-danger'></td>
									<td class='label-danger'></td>
									<td class='label-danger'></td>";
							}
							if($r['category'] == 3){
								$price = format_rupiah($r['price']);
								$tot = format_rupiah($r['linetotal']);
								echo"
								<td class='label-info'>$r[product]</td>
								<td class='label-info'>$r[qty]</td>
								<td align= 'right' class='label-info'>$price</td>
								<td align= 'right' class='label-info'>$tot</td>";
								
							}else{
								echo"
									<td class='label-info'></td>
									<td class='label-info'></td>
									<td class='label-info'></td>
									<td class='label-info'></td>";
							}

								  echo"</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": [[ 0, "asc" ]],
          "info": true,
          "autoWidth":  false,
		  "scrollX": true
        });
      });
    </script>
  </body>
</html>
<?php 
	}
?>