<!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>
            LAPORAN SALES HARIAN SEMEN LCI & MP
            <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>LAPORAN SALES HARIAN SEMEN LCI & MP</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>LAPORAN SALES HARIAN SEMEN LCI & MP <br> PERIODE :
				  <?php 
					$periode = date('M - Y'); 
					$day = date('w');
					$week_start = date('Y-m-d', strtotime('-'.$day.' days'));
					$week_end = date('Y-m-d', strtotime('+'.(6-$day).' days'));
					echo"$periode - $week_start - $week_end";  
				  ?> 
				  
				 <br><br>
                </div><!-- /.box-header -->
                <div class="box-body">
				<!-- 
					View : <span class='label label-success'>Week 1</span> <span class='label label-warning'>Week 2</span><span class='label label-danger'>Week 3</span><span class='label label-info'>Week 4</span><br><br>
                  -->
				  <table id="example1" class="table table-bordered table-striped">
                    <thead>
                      <tr>
						<td rowspan="2" style="vertical-align: middle;">NO</td>
						<td rowspan="2" style="vertical-align: middle;">NAMA CUSTOMER</td>
						<td rowspan="2" style="vertical-align: middle;">MKTG </td>
						<?php
							 

							$begin = strtotime(date('Y-m-d', strtotime('-'.$day.' days')));
							$tgl_terakhir = date('Y-m-d', strtotime('+'.(6-$day).' days'));
							$end   = strtotime($tgl_terakhir);

							for($i = $begin; $i <= $end; $i = $i + 86400){
								$tgl2 = date('d-M', $i );
								echo "<td colspan='2'>$tgl2</td>";
							}
							
							echo "<td colspan='2'>TOTAL</td>";
						?>
						
                      </tr>
					  <tr>
						
						<?php

							for($i = $begin; $i <= $end; $i = $i + 86400){
								echo "<td>LCI</td><td>MP</td>";
							}
							echo "<td>LCI</td><td>MP</td>";
						?>
                      </tr>
                    </thead>
					<tbody>
						<?php
						$cal = 0;
						
						$aa = date('Y-m-d', strtotime('-'.$day.' days'));
					     $bb = date('Y-m-d', strtotime('+'.(6-$day).' days'));
						$cek = mysql_query("Select customername,kasir from dailydetail where  billdate BETWEEN '$aa' AND '$bb' and kasir in ('ALG','WIL','EDR','ANDY') group by customername,kasir  order by customername asc");
						while ($r=mysql_fetch_array($cek)){	
							$lsam = 0;
							$msam = 0;
							$cal = $cal + 1;
							echo"<tr> 
									<td>$cal</td>
									<td>$r[customername]</td>
									<td>$r[kasir]</td>";
							for($i = $begin; $i <= $end; $i = $i + 86400){
								$tgl2 = date('Y-m-d', $i );
								$lci = 0;
								$lci = mysql_result(mysql_query("select ifnull(sum(qty),0) from dailydetail where category = '1' and kasir in ('ALG','WIL','EDR','ANDY') and customername = '$r[customername]' and billdate = '$tgl2'"),0);
								$lci2 = format_rupiah($lci);
								$lsam = $lsam + $lci;
								
								$mp = 0;
								$mp = mysql_result(mysql_query("select ifnull(sum(qty),0) from dailydetail where category = '6'  and kasir in ('ALG','WIL','EDR','ANDY') and customername = '$r[customername]' and billdate = '$tgl2'"),0);
								$mp = format_rupiah($mp);
								$msam = $msam + $mp;
								echo "<td class='label-success'>$lci2</td><td class='label-danger'>$mp</td>";
							}	
							
							echo "<td class='label-info'>$lsam</td><td class='label-warning'>$msam</td>";
							echo"</tr>";
							
							
						}
						?>
                    </tbody>
					<?php
						echo "<tr><td colspan ='3'>T O T A L</td>";
						for($i = $begin; $i <= $end; $i = $i + 86400){
							$tgl2 = date('Y-m-d', $i );
								$lci = 0;
								$lci = mysql_result(mysql_query("select ifnull(sum(qty),0) from dailydetail where kasir in ('ALG','WIL','EDR','ANDY') and  category = '1' and billdate = '$tgl2'"),0);
								$lsam = $lsam + $lci;
								$lci2 = format_rupiah($lci);
								
								
								$mp = 0;
								$mp = mysql_result(mysql_query("select ifnull(sum(qty),0) from dailydetail where kasir in ('ALG','WIL','EDR','ANDY') and category = '6' and billdate = '$tgl2'"),0);
								$msam = $msam + $mp;
								$mp = format_rupiah($mp);
								
							echo "<td class='label-info'>$lci2</td><td class='label-warning'>$mp</td>";
						}
						echo "<td class='label-info'>$lsam</td><td class='label-warning'>$msam</td>";
						echo"</tr>";
					?>
                  </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 
	}
?>