<?php
$penjualan = $this->model_reseller->penjualan($this->session->id_reseller)->row_array();
$penjualan_1 = $this->model_reseller->penjualan_1()->row_array();
$penjualan_7 = $this->model_reseller->penjualan_7()->row_array();
$penjualan_30 = $this->model_reseller->penjualan_30()->row_array();
$penjualan_365 = $this->model_reseller->penjualan_365()->row_array();
?>






<a style='color:#000' href='#'>
  <div class="col-md-3 col-sm-6 col-xs-12">
    <div class="info-box">
      <span class="info-box-icon bg-red"><i class="glyphicon glyphicon-sound-5-1"></i></span>
      <div class="info-box-content">
        <span class="info-box-text">Pendapatan Hari Ini</span>
        <span class="info-box-number"><?php echo "Rp " . rupiah($penjualan_1['total']); ?></span>
      </div><!-- /.info-box-content -->
    </div><!-- /.info-box -->
  </div><!-- /.col -->
</a>

<a style='color:#000' href='#'>
  <div class="col-md-3 col-sm-6 col-xs-12">
    <div class="info-box">
      <span class="info-box-icon bg-red"><i class="glyphicon glyphicon-sound-6-1"></i></span>
      <div class="info-box-content">
        <span class="info-box-text">Pendapatan Minggu Ini</span>
        <span class="info-box-number"><?php echo "Rp " . rupiah($penjualan_7['total']); ?></span>
      </div><!-- /.info-box-content -->
    </div><!-- /.info-box -->
  </div><!-- /.col -->
</a>

<a style='color:#000' href='#'>
  <div class="col-md-3 col-sm-6 col-xs-12">
    <div class="info-box">
      <span class="info-box-icon bg-red"><i class="glyphicon glyphicon-sound-7-1"></i></span>
      <div class="info-box-content">
        <span class="info-box-text">Pendapatan bulan Ini</span>
        <span class="info-box-number"><?php echo "Rp " . rupiah($penjualan_30['total']); ?></span>
      </div><!-- /.info-box-content -->
    </div><!-- /.info-box -->
  </div><!-- /.col -->
</a>

<a style='color:#000' href='#'>
  <div class="col-md-3 col-sm-6 col-xs-12">
    <div class="info-box">
      <span class="info-box-icon bg-red"><i class="glyphicon glyphicon-copyright-mark"></i></span>
      <div class="info-box-content">
        <span class="info-box-text">Pendapatan tahun Ini</span>
        <span class="info-box-number"><?php echo "Rp " . rupiah($penjualan_365['total']); ?></span>
      </div><!-- /.info-box-content -->
    </div><!-- /.info-box -->
  </div><!-- /.col -->
</a>


<div class="col-xs-12">
  <div class="box">
    <div class="box-header">
      <h3 class="box-title">Data Transaksi Penjualan / Orderan Konsumen</h3>
      <a class='pull-right btn btn-primary btn-sm' href='<?php echo base_url(); ?>reseller/tambah_penjualan'>Tambah
        Penjualan</a>
    </div><!-- /.box-header -->
    <div class="box-body">
      <div class='table-responsive'>
        <table id="example1" class="table table-bordered table-striped table-condensed">
          <thead>
            <tr>
              <th style='width:40px'>No</th>
              <th>Kode Transaksi</th>
              <th>Nama Konsumen</th>
              <th>Kurir</th>
              <th>Status</th>
              <th>Total + Ongkir</th>
              <th></th>
            </tr>
          </thead>
          <tbody>
            <?php
            $no = 1;
            foreach ($record->result_array() as $row) {
              if ($row['proses'] == '0') {
                $proses = '<i class="text-danger">Pending</i>';
                $status = 'Proses';
                $icon = 'star-empty';
                $ubah = 1;
              } elseif ($row['proses'] == '1') {
                $proses = '<i class="text-success">Proses</i>';
                $status = 'Pending';
                $icon = 'star text-yellow';
                $ubah = 0;
              } elseif ($row['proses'] == '2') {
                $proses = '<i class="text-info">Konfirmasi</i>';
                $status = 'Proses';
                $icon = 'star';
                $ubah = 1;
              } elseif ($row['proses'] == '3') {
                $proses = '<i class="text-info">Selesai</i>';
                $status = 'Selesai';
                $icon = 'ok';
                $ubah = 1;
              }
              $total = $this->db->query("SELECT sum((a.harga_jual*a.jumlah)-a.diskon) as total FROM `rb_penjualan_detail` a where a.id_penjualan='$row[id_penjualan]'")->row_array();
              echo "<tr><td>$no</td>
                              <td>$row[kode_transaksi]</td>
                              <td><a href='" . base_url() . "reseller/detail_konsumen/$row[id_konsumen]'>$row[nama_lengkap]</a></td>
                              <td><span style='text-transform:uppercase'>$row[kurir]</span> - $row[service]</td>
                              <td>$proses</td>
                              <td style='color:red;'>Rp " . rupiah($total['total'] + $row['ongkir']) . "</td>
                              <td><center>
                                <a class='btn btn-success btn-xs' title='Detail Data' href='" . base_url() . "reseller/detail_penjualan/$row[id_penjualan]'><span class='glyphicon glyphicon-search'></span> Detail</a>";
              if ($row['proses'] == '2' || $row['proses'] == '1' || $row['proses'] == '0') {
                echo "  <a class='btn btn-primary btn-xs' title='$status Data' href='" . base_url() . "reseller/proses_penjualan/$row[id_penjualan]/$ubah' onclick=\"return confirm('Apa anda yakin untuk ubah status jadi $status?')\"><span class='glyphicon glyphicon-$icon'></span></a>";
              } elseif ($row['proses'] == '3') {
                echo "  <a class='btn btn-primary btn-xs' title='$status Data'><span class='glyphicon glyphicon-$icon'></span></a>";
              }
              echo "



                                <a class='btn btn-warning btn-xs' title='Edit Data' href='" . base_url() . "reseller/edit_penjualan/$row[id_penjualan]'><span class='glyphicon glyphicon-edit'></span></a>
                                <a class='btn btn-danger btn-xs' title='Delete Data' href='" . base_url() . "reseller/delete_penjualan/$row[id_penjualan]' onclick=\"return confirm('Apa anda yakin untuk hapus Data ini?')\"><span class='glyphicon glyphicon-remove'></span></a>
                              </center></td>
                          </tr>";
              $no++;
            }
            ?>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>