<?php foreach($kontak as $kontak) :   endforeach; ?>
<?php foreach($admin_login as $user) :   endforeach; ?> 
  <!-- Content Wrapper. Contains page content -->
  <?php  $level = $user->level;
  	if($level =='manager' or $level =='admin'){
  ?> 

  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0 text-dark">Dashboard Admin </h1>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="#">Home</a></li>
              <li class="breadcrumb-item active">Dashboard</li>
            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <!-- Small boxes (Stat box) -->
        <div class="row">
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-info">
              <div class="inner">
                <h3><?php
                    echo $this->db->query("SELECT * FROM tb_member where  ID_MEMBER !='1' ")->num_rows();
              ?></h3>

                <p>Member</p>
              </div>
              <div class="icon">
                <i class="fa fa-user-circle"></i>
              </div>
              <a href="<?php echo base_url('member');?>" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-success">
              <div class="inner">
                <h3><?php
                    echo $this->db->query("SELECT * FROM tb_barang  ")->num_rows();
              ?> </h3>

                <p>Data Barang</p>
              </div>
              <div class="icon">
                <i class="fa fa-archive"></i>
              </div>
              <a href="<?php echo base_url('barang');?>" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-warning">
              <div class="inner">
                <h3><?php
                    echo $this->db->query("SELECT * FROM tb_supliyer  ")->num_rows();
              ?></h3>

                <p>Data Supliyer</p>
              </div>
              <div class="icon">
                <i class="fa fa-truck"></i>
              </div>
              <a href="<?php echo base_url('supliyer');?>" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-danger">
              <div class="inner">
                <h3><?php
                    echo $this->db->query("SELECT * FROM tb_kantor  ")->num_rows();
              ?></h3>

                <p>Kantor Cabang</p>
              </div>
              <div class="icon">
                <i class="fa fa-home"></i>
              </div>
              <a href="#" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
            </div>
          </div>
          <!-- ./col -->
        </div>
        <!-- /.row -->

        <h5 class="mt-4 mb-2">Informasi Keuangan</h5>
        <div class="row">
          <div class="col-md-3 col-sm-6 col-12">
            <div class="info-box bg-info">
                <span class="info-box-icon"><i class="fas fa-money-check"></i></span>
              <div class="info-box-content">
                <span class="info-box-text">Modal </span>
                <span class="info-box-number" style="text-align: left;"> <?php 
                         date_default_timezone_get('Asia/Jakarta');
                        $sql_menu = "SELECT SUM(tb_stok.stok_aplikasi * tb_barang.harga_beli_ecer) AS total FROM tb_barang, tb_stok WHERE tb_barang.id = tb_stok.id_barang   ";
                            $main_menu = $this->db->query($sql_menu)->result();
                            foreach ($main_menu as $data) {
                           echo nominal($data->total);
                            }
                        
                        ?>    
								</span>

                <div class="progress">
                  <div class="progress-bar" style="width: 100%"></div>
                </div>
                <span class="progress-description">
                	Modal Usaha  
                </span>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          <!-- /.col -->
          <div class="col-md-3 col-sm-6 col-12">
            <div class="info-box bg-success">
                <span class="info-box-icon"><i class="fas fa-money-check"></i></span>
              <div class="info-box-content">
                <span class="info-box-text">Transaksi Harian</span>
                <span class="info-box-number"  style="text-align: left;"> <?php    
                    date_default_timezone_get('Asia/Jakarta');
                    $datass = $this->db->query("SELECT SUM(total) as total FROM tb_transaksi WHERE  DATE(tb_transaksi.date) = CURDATE()   ")->row();
                    echo nominal($datass->total);
                    ?></span>

                <div class="progress">
                  <div class="progress-bar" style="width: 100%"></div>
                </div>
                <span class="progress-description">
                   Hari ini,  <?php echo tanggal() ?>
                </span>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          <!-- /.col -->
          <div class="col-md-3 col-sm-6 col-12">
            <div class="info-box bg-warning">
                 <span class="info-box-icon"><i class="fas fa-money-check"></i></span>

              <div class="info-box-content">
                <span class="info-box-text">Transaksi Bulanan</span>
                <span class="info-box-number"  style="text-align: left;"> 
                        <?php    
                    date_default_timezone_get('Asia/Jakarta');
                     $bulan = Date('m');   $tahun = Date('Y');
                    $datass = $this->db->query("SELECT SUM(total) as total  FROM tb_transaksi WHERE month(tb_transaksi.date) = '$bulan'  and year(tb_transaksi.date) = '$tahun' ")->row();
                    echo nominal($datass->total);
                    ?>
                        </span>

                <div class="progress">
                  <div class="progress-bar" style="width: 100%"></div>
                </div>
                <span class="progress-description">
                    Bulan ini, <?php echo bulan() ?> <?php echo tahun() ?>
                </span>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          <!-- /.col -->
          <div class="col-md-3 col-sm-6 col-12">
            <div class="info-box bg-danger">
             
							  <span class="info-box-icon"><i class="fas fa-money-check"></i></span>
              <div class="info-box-content">
                <span class="info-box-text">Kerugian Tahunan</span>
                <span class="info-box-number"  style="text-align: left;"><?php 
                date_default_timezone_get('Asia/Jakarta');
                         $bulan = Date('m');   $tahun = Date('Y');
                        $sql_menu = "SELECT SUM(tb_history_barang_in_out.jumlah * tb_barang.harga_beli_ecer) as total 
                   FROM tb_history_barang_in_out, tb_barang WHERE
                    tb_history_barang_in_out.id_barang = tb_barang.id
                  AND tb_history_barang_in_out.keterangan ='BARANG RUSAK' OR 
                  tb_history_barang_in_out.keterangan ='BARANG HILANG'
                    and year(tb_history_barang_in_out.date) ='$tahun'";
                            $main_menu = $this->db->query($sql_menu)->result();
                            foreach ($main_menu as $data) {
                           echo nominal($data->total);
                            }
                        
                        ?></span>

                <div class="progress">
                  <div class="progress-bar" style="width: 100%"></div>
                </div>
                <span class="progress-description">
                    Tahun ini, <!-- <?php echo bulan() ?> --> <?php echo tahun() ?>
                </span>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
        <!-- Main row -->

        <div class="row">
          <!-- Left col -->
          <section class="col-lg-12 connectedSortable">
            <!-- Custom tabs (Charts with tabs)-->
            <div class="card">
              <div class="card-header">
                <h3 class="card-title">
                  <i class="fas fa-chart-pie mr-1"></i>
                  Komisi Grafik   <?php echo tahun() ?>
                </h3>
                <div class="card-tools">
                  <ul class="nav nav-pills ml-auto">
                    <li class="nav-item">
                      <a class="nav-link active" href="#revenue-bulan" data-toggle="tab">Bulan</a>
                    </li>
                    <li class="nav-item">
                      <a class="nav-link" href="#sales-tahun" data-toggle="tab">Tahun</a>
                    </li>
                  </ul>
                </div>
              </div><!-- /.card-header -->
              <div class="card-body">
                <div class="tab-content p-0">
                 
                 <!--  <script type="text/javascript" src="<?php echo base_url().'assets/chartjs/chart.min.js'?>"></script>
                  <div class="chart tab-pane active" id="revenue-bulan" style="position: relative; height: 300px;">
                  	<canvas id="canvas" width="1000" height="280"></canvas>
                  	<?php
                  	foreach($grafik_bulan as $data){
                  		$merk[] = $data->tanggal;
                  		$stok[] = (float) $data->jumlah;
                  	}
                  	?>
                   
                  	<script>

                  		var lineChartData = {
                  			labels : <?php echo json_encode($merk);?>,
                  			datasets : [

                  			{
                  				fillColor: "rgba(60,141,188,0.9)",
                  				strokeColor: "rgba(60,141,188,0.8)",
                  				pointColor: "#3b8bba",
                  				pointStrokeColor: "#fff",
                  				pointHighlightFill: "#fff",
                  				pointHighlightStroke: "rgba(152,235,239,1)",
                  				data : <?php echo json_encode($stok);?>
                  			}

                  			]

                  		}

                  		var myLine = new Chart(document.getElementById("canvas").getContext("2d")).Line(lineChartData);

                  	</script>                        
                  </div>
                  <div class="chart tab-pane" id="sales-tahun" style="position: relative; height: 300px;">
                      <canvas id="canvas2" width="1000" height="280"></canvas>
                  	<?php
                  	foreach($grafik_tahun as $datay){
                  		$bln[] = $datay->bulan;
                  		$jml[] = (float) $datay->jumlah;
                  	}
                  	?>
                   
                  
                  	<script>

                  		var lineChartData = {
                  			labels : <?php echo json_encode($bln);?>,
                  			datasets : [

                  			{
                  				fillColor: "rgba(60,141,188,0.9)",
                  				strokeColor: "rgba(60,141,188,0.8)",
                  				pointColor: "#3b8bba",
                  				pointStrokeColor: "#fff",
                  				pointHighlightFill: "#fff",
                  				pointHighlightStroke: "rgba(152,235,239,1)",
                  				data : <?php echo json_encode($jml);?>
                  			}

                  			]

                  		}

                  		var myLine = new Chart(document.getElementById("canvas2").getContext("2d")).Line(lineChartData);

                  	</script>                   
                  </div>   -->

                  <!-- Morris chart - Sales 
                  <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
                  -->
                   <script src="<?php echo base_url().'assets/js/chart.js'?>"></script>
                  <div class="chart tab-pane active" id="revenue-bulan" style="position: relative; height: 300px;">
                    <canvas id="myChart" width="1000" height="280"></canvas>

                    <?php
                    foreach($grafik_bulan as $data){
                      $merk[] = $data->tanggal;
                      $stok[] = (float) $data->jumlah;
                    }
                    ?>
                    <!--Load chart js-->
                  
                   <script type="text/javascript">
                    var ctx = document.getElementById('myChart').getContext('2d');
                    var chart = new Chart(ctx, {
                      type: 'bar',
                      data: {
                        labels: [
                          <?php
                          if (count($graphik)>0) {
                            foreach ($graphik as $data) {
                              echo "'" .$tanggal= $data->tanggal."',";
                            }
                          }
                          ?>
                          ],
                        datasets: [{
                          label: 'Komisi Harian',
                          backgroundColor: '#ADD8E6',
                          borderColor: '##93C3D2',
                          data: [
                            <?php
                            if (count($graphik)>0) {
                             foreach ($graphik as $data) {
                              echo $data->jumlah . ", ";
                            }
                          }
                          ?>
                          ]
                        }]
                      },
                    });

                  </script>
                                       
                  </div>
                  <div class="chart tab-pane" id="sales-tahun" style="position: relative; height: 300px;">
                      <canvas id="myChart2" width="1000" height="280"></canvas>
                    <script type="text/javascript">
                    var ctx = document.getElementById('myChart2').getContext('2d');
                    var chart = new Chart(ctx, {
                      type: 'bar',
                      data: {
                        labels: [
                          <?php
                          if (count($graphik2)>0) {
                            foreach ($graphik2 as $data2) {
                              echo "'" .'Bulan '.bulan_cetak($data2->bulan)."',";
                            }
                          }
                          ?>
                          ],
                        datasets: [{
                          label: 'Komisi Bulanan',
                          backgroundColor: '#ADD8E6',
                          borderColor: '##93C3D2',
                          data: [
                            <?php
                            if (count($graphik2)>0) {
                             foreach ($graphik2 as $data2) {
                              echo $data2->jumlah . ", ";
                            }
                          }
                          ?>
                          ]
                        }]
                      },
                    });

                  </script>              
                  </div>    
                </div>
              </div> 
            </div>
            <!-- /.card -->

             

            <!-- TO DO List -->
            <div class="card">
              <div class="card-header">
                <h3 class="card-title">
                  <i class="fa fa-calendar"></i>
                  Daftar Barang Expired 4 Bulan Kedepan
                </h3>
								<br>
								<br>
								<table class="table ">
									<thead>
										<tr>
											<th>No</th>
											<th>Nama Barang</th>
											<th>Kantor </th>
											<th>Expired</th>

										</tr>
									</thead>
									<tbody>
										<?php $no=1; foreach($barang_expired as $rows) : 

											$id_barang= $rows->id_barang;
											$this->db->where('id',$id_barang);
											$query = $this->db->get('tb_barang');
											$row = $query->row();
											$barcode_ecer = $row->barcode_ecer;
											$nama_barang = $row->nama_barang;
										 
						          //rak
										 
										?> 
										<tr>
											<td><?php echo $no; ?></td>
											<td><?php echo $nama_barang; ?></td>
											<td>
              							<?php 
			              				$id_kantor = $rows->id_kantor; 
			              				$sql_menu = "SELECT * FROM tb_kantor WHERE  id_kantor = '$id_kantor' ";
			              				$main_menu = $this->db->query($sql_menu)->result();
			              				foreach ($main_menu as $maink) {
			              				echo  $maink->nama_kantor;

			              				}
			              				?>
              					</td>
              				<td><?php echo $rows->expired_date;  ?></td>
										</tr>
										<?php $no++; endforeach; ?>
									</tbody>
								

								</table>
                
              </div>
              <!-- /.card-header -->
              <div class="card-body">
                
              </div>
              <!-- /.card-body -->
              
            </div>
            <!-- /.card -->
          </section>
        </div>
        <div class="row">
          <!-- Left col -->
         
          <!-- right col (We are only adding the ID to make the widgets sortable)-->
          <section class="col-lg-12 connectedSortable">
						<!-- TO DO List -->
            <div class="card">
              <div class="card-header">
                <h3 class="card-title">
                  <i class="fa fa-calendar"></i>
                  Daftar Barang Terlaris Bulan Sebelumnya
                </h3>
                <br>
								<table class="table ">
									<thead>
										<tr>
											<th>No</th>
											<th>Nama Barang</th>
											<th>Terjual</th>
										</tr>
									</thead>
									<tbody>
										<?php $no=1; foreach($barang_terjual as $rows) : ?>
										<tr>
											<td><?php echo $no; ?></td>
											<td><?php echo $rows->nama_barang;  ?></td>
											<td><?php echo $rows->total_terjual;  ?></td>
										</tr>
										<?php $no++; endforeach; ?>
									</tbody>
									

								</table>
                
              </div>
              <!-- /.card-header -->
              <div class="card-body">
                
              </div>
              <!-- /.card-body -->
              
            </div>
            
           
 
            <!-- /.card -->
          </section>
          <!-- right col -->
        </div>
        <!-- /.row (main row) -->
      </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
	
	<?php } else if($level =='kasir' ){ ?>

	 <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0 text-dark">Dashboard Admin </h1>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="#">Home</a></li>
              <li class="breadcrumb-item active">Dashboard</li>
            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <!-- Small boxes (Stat box) -->
        <div class="row">
          <div class="col-lg-6 col-6">
             	<img src="<?php echo base_url();?>/images/kasir.png">
              <h2><u>Informasi Kasir Cash Awal</u></h2>
              <?php

              $username = $this->session->userdata("username");  
              $this->db->where('username',$username);
              $query = $this->db->get('tb_admin');
              $row = $query->row();
             
              $id_admin = $row->id;

              $tanggal_sekarang = date('Ymd');

                 $sql_menuxx= "SELECT * FROM tb_kasir WHERE  id_admin = '$id_admin' and date(date)=' $tanggal_sekarang' and keterangan ='login-kasir'  ";
                        $main_menuxx = $this->db->query($sql_menuxx)->result();
                        foreach ($main_menuxx as $rows) {
                          
                         ?>

                    <p>Cash Money Awal : <?php echo nominal($rows->nominal);  ?> </p>
                         <?php

                        }  
                 

                 ?>


                    <hr>

              <h2><u>Informasi Kasir Cash End</u></h2>
              <?php

              $username = $this->session->userdata("username");  
              $this->db->where('username',$username);
              $query = $this->db->get('tb_admin');
              $row = $query->row();
             
              $id_admin = $row->id;

              $tanggal_sekarang = date('Ymd');

                 $sql_menuxx= "SELECT * FROM tb_kasir WHERE  id_admin = '$id_admin' and date(date)=' $tanggal_sekarang' and keterangan ='logout-kasir'  ";
                        $main_menuxx = $this->db->query($sql_menuxx)->result();
                        foreach ($main_menuxx as $rows) {
                          
                         ?>

                      <p>Awal cash Money  : <?php echo nominal($rows->awal_moneycash);  ?> </p>
                      <p>Total Transaksi : <?php echo nominal($rows->total_transaksi);  ?> </p>
                        <p>Setor : <?php echo nominal($rows->nominal);  ?> </p>
                        <p>Selisih  : <?php echo nominal($rows->selisih);  ?> </p>
                         <?php

                        }  
                 

                 ?>

          </div>
          
        </div>
        <!-- /.row -->
 
        <!-- /.row (main row) -->
      </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>


	<?php } ?>