<?php foreach($kontak as $kontak) :   endforeach; ?> 
<?php foreach($admin_login as $user) :   endforeach; ?> 
<?php 
            $username = $this->session->userdata("username");  
            $this->db->where('username',$username);
            $query = $this->db->get('tb_admin');
            $row = $query->row();
            $nama_admin = $row->nama_admin;
            $level = $row->level;

             ?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>List Pembelian</title>
  <link rel="stylesheet" type="text/css" href="<?php echo base_url().'assets/css/bootstrap.css'?>">
  <link rel="stylesheet" type="text/css" href="<?php echo base_url().'assets/css/jquery.dataTables.css'?>">
</head>
<body>
<div class="container">
   <h1 class="text-center">--== Selamat Berbelanja di <?php  echo $kontak->nama_toko;   ?> ==--</h1>
   <hr>
   <div class="row">
    <div class="col-md-5">
      
      <h2>Data  Keranjang  </h2>
      <table class="table  " id="mydata">
        <thead>
          <tr style="background: #c0dbed">
            <th>Kode</th>
            <th>Nama Barang</th>
            <th style="text-align:right;">Harga</th>
            <th style="text-align:center;">Jumlah</th>
            <th style="text-align:right;">T.Harga</th>
          </tr>
        </thead>
        <tbody id="show_data">

        </tbody>
        <tfoot>
          <th>
            <td colspan="3"><strong>Total</strong></td>
            <td style="text-align:right;"><strong id='show_data2'> </strong> 
            </th>
          </tfoot>
        </table>

       
    </div>
    <div class="col-md-7">
       <h2>Transaksi 3 Terakhir </h2>

       <table class="table " id="mydataa">
        <thead>
          <tr style="background: #aaadaf">

            <th>ID Transaksi</th>

            <th>Member</th>
            <th style="text-align: right;">ST</th>
            <th style="text-align: right;">Potongan</th>
            <th style="text-align: right;">Total</th>
            <th>Bayar</th>
            <th>Kembali</th>
            



          </tr>
        </thead>
        <tbody id="show_data3">

        </tbody>

      </table>
    </div>
   </div>
   <hr>
   <div class="row">
    <h3> Kasir :  <?php  echo $nama_admin;   ?> </h3>
  </div>
  <div class="row">
    <p> Tanggal   <?php echo tgl_indo(date('Y-m-d'));  ?> </p>
  </div>
  <!-- Page Heading -->
 
  
   

</div>
 
 
<script type="text/javascript" src="<?php echo base_url().'assets/js/jquery.js'?>"></script>
<script type="text/javascript" src="<?php echo base_url().'assets/js/bootstrap.js'?>"></script>
<script type="text/javascript" src="<?php echo base_url().'assets/js/jquery.dataTables.js'?>"></script>
<script type="text/javascript">
 
  $(document).ready(function(){
    
    setInterval(function(){
    
      tampil_data_barang(),tampil_data_akhir(),tampil_totaldata_barang();
    }, 250);
    // setInterval(function(){
    
    //   tampil_data_akhir();
    // }, 250);
    // setInterval(function(){
    
    //   tampil_data_barang();
    // }, 250);
   
   
    //Menampilkan Data di tabel
    function formatRupiah(angka, prefix){
                var number_string = angka.replace(/[^,\d]/g, '').toString(),
                split           = number_string.split(','),
                sisa            = split[0].length % 3,
                rupiah          = split[0].substr(0, sisa),
                ribuan          = split[0].substr(sisa).match(/\d{3}/gi);

              // tambahkan titik jika yang di input sudah menjadi angka ribuan
              if(ribuan){
                separator = sisa ? '.' : '';
                rupiah += separator + ribuan.join('.');
              }

              rupiah = split[1] != undefined ? rupiah + ',' + split[1] : rupiah;
              return prefix == undefined ? rupiah : (rupiah ? 'Rp. ' + rupiah : '');
          } 

    //fungsi tampil barang
    function tampil_data_barang(){
        $.ajax({
            type  : 'ajax',
            url   : '<?php echo base_url()?>kasir/data_keranjang',
            async : false,
            dataType : 'json',
            success : function(data){
                var html = '';
                var i;
                for(i=0; i<data.length; i++){
                    html += '<tr>'+
                          '<td>'+data[i].id_barang+'</td>'+
                            '<td>'+data[i].nama_barang+'</td>'+
                            '<td style="text-align:right;">'+formatRupiah(data[i].harga_jual)+'</td>'+
                            '<td style="text-align:center;">'+formatRupiah(data[i].jumlah)+'</td>'+
                             '<td style="text-align:right;">'+formatRupiah(data[i].harga_total)+'</td>'+
                            '</tr>';
                }
                $('#show_data').html(html);
            }

        });
    }
    function tampil_data_akhir(){
        $.ajax({
            type  : 'ajax',
            url   : '<?php echo base_url()?>kasir/data_akhir_transaksi',
            async : false,
            dataType : 'json',
            success : function(data){
                var html = '';
                var i;
                for(i=0; i<data.length; i++){
                  html += '<tr>'+
                      '<td>'+data[i].id_transaksi+'</td>'+
                      '<td>'+data[i].nama_member+'</td>'+
                      '<td style="text-align:right;">'+formatRupiah(data[i].sub_total)+'</td>'+
                      '<td style="text-align:center;">'+formatRupiah(data[i].potongan)+'</td>'+
                      '<td style="text-align:right;">'+formatRupiah(data[i].total)+'</td>'+
                      '<td style="text-align:right;">'+formatRupiah(data[i].bayar)+'</td>'+
                      '<td style="text-align:right;">'+formatRupiah(data[i].kembali)+'</td>'+
                     
                     

                  '</tr>';
                }
                $('#show_data3').html(html);
            }

        });
    }
    function number_format2(number, decimals, decPoint, thousandsSep){
      decimals = decimals || 0;
      number = parseFloat(number);

      if(!decPoint || !thousandsSep){
        decPoint = '.';
        thousandsSep = ',';
      }

      var roundedNumber = Math.round( Math.abs( number ) * ('1e' + decimals) ) + '';
      var numbersString = decimals ? roundedNumber.slice(0, decimals * -1) : roundedNumber;
      var decimalsString = decimals ? roundedNumber.slice(decimals * -1) : '';
      var formattedNumber = "";

      while(numbersString.length > 3){
        formattedNumber += thousandsSep + numbersString.slice(-3)
        numbersString = numbersString.slice(0,-3);
      }

      return (number < 0 ? '-' : '') + numbersString + formattedNumber + (decimalsString ? (decPoint + decimalsString) : '');
    }
    //format ruapiah tapi tidak auto nol
    function formatNumber6(num) {
      return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')
    } 
    //format rupiah OK
    function number_format3 (number, decimals, dec_point, thousands_sep) {
      // Strip all characters but numerical ones.
      number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
      var n = !isFinite(+number) ? 0 : +number,
      prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
      sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
      dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
      s = '',
      toFixedFix = function (n, prec) {
        var k = Math.pow(10, prec);
        return '' + Math.round(n * k) / k;
      };
      // Fix for IE parseFloat(0.55).toFixed(0) = 0;
      s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
      if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
      }
      if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
      }
      return s.join(dec);
    }
    function tampil_totaldata_barang(){
        $.ajax({
            type  : 'ajax',
            url   : '<?php echo base_url()?>kasir/data_keranjang_total',
            async : false,
            dataType : 'json',
            success : function(data){
              // data += ' <center>'.number_format("+data.total_belanja+",2,",",".").'</center>';
                var html = '';
               
                for(i=0; i<data.length; i++){

                    html +=    number_format3(data[i].total_belanja) || 0;
                }
                $('#show_data2').html(html);
            }

        });
    }
    //  function tampil_total_data_barang(){
    //     $.ajax({
    //         type  : 'ajax',
    //         url   : '<?php echo base_url()?>kasir/total_data_keranjang',
    //         async : false,
    //         dataType : 'json',
    //         success : function(data){
    //             var html = '';
    //             var a;
    //             for(a=0; a<data2.length; a++){
    //                 html += ''+formatRupiah(data2[a].total_belanja)+;
    //             }
    //             $('#show_data2').html(html);
    //         }

    //     });
    // }

  });

</script>
<script type="text/javascript">
                
                     </script>
</body>
</html>