Membuat Antrian Dengan CodeIgniter dan Bootstrap (Part 4) Pengambilan Antrian

Assalamu’alaikum wr. wb.

Membuat Antrian Dengan CodeIgniter dan Bootstrap (Part 4) Pengambilan Antrian

buat table baru dengan nama “ambil_antrian”

Kemudian buat controller baru dengan nama “Ambil_antrian.php”

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Ambil_antrian extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
    $this->load->model('M_ambil');
    }	
  
  public function index(){
    $data = array(
      'nomor' => $this->get_nomor(),
    );
    //$data['nomor'] = $this->get_nomor();
    $this->load->view('ambil_antrian/v_ambil',$data);
  }
  
    public function get_nomor(){
            $date = date("Y-m-d");
            $query = $this->db->query("SELECT MAX(a_nomor) as max_id FROM ambil_antrian WHERE a_tgl='$date' ");
            $row = $query->row_array();
            $max_id = $row['max_id'];
            $max_id1 =(int) substr($max_id,0,3);
            $kode_antri = $max_id1 +1;
            $maxkode = sprintf("%03s",$kode_antri);
            return $maxkode;
    }

  public function tambah(){
    $data = array(
      'a_nomor' => $this->get_nomor(),
      'a_tgl'	  => date('Y-m-d'),
    );
    $this->M_ambil->insert($data);
    redirect(site_url('ambil_antrian/cetak'));		
  }

  //11 03 2019

  public function cetak(){
    $row = $this->M_ambil->data_cetak();
    if($row){
      $data = array(
        'row' => $row,
      );
      $this->load->view('ambil_antrian/v_cetak',$data);
    }else{
      redirect(site_url('ambil_antrian/index'));
    }
  }


}

Kemudian buat model baru dengan nama “M_ambil.php”

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class M_ambil extends CI_Model
{
    function __construct()
    {
        parent::__construct();
    }

    function insert($data)
    {
        $this->db->insert('ambil_antrian', $data);
    }

    //11-03-2019
    function data_cetak(){
    return $this->db->query("SELECT * FROM ambil_antrian ORDER BY a_id DESC LIMIT 0,1")->row();
  }
  
}

selanjutnya buat folder baru didalam folder views dengan nama “ambil_antrian” selanjutnya buat nama file “v_ambil.php” dan “v_cetak.php”

v_ambil.php

<html>
<head>
  <title>Sistem Antrian</title>
  <link rel="stylesheet" href="<?php echo base_url();?>bootstrap/css/bootstrap.min.css">
</head>
<body>
<div class="container">
  <div class="row">
    <div class="col-md-4"></div>
    <div class="col-md-4">
      <form action="<?php echo base_url('ambil_antrian/tambah');?>" method="post">
        <input type="hidden" name="a_nomor" value="<?php echo $nomor;?>" >
        <button type="submit" class="btn btn-danger" style="height: 300px;font-size: 30px;">KLIK DISINI UNTUK PENGAMBILAN ANTRIAN<br/>
        Nomor Antrian<br/>
        <?php echo $nomor;?>
        </button>
      </form>
    </div>
    <div class="col-md-4"></div>
  </div>
</div>
</body>
</html>

Kemudian v_cetak.php

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="2; url=<?php echo base_url('ambil_antrian');?>">
<textarea id="printing-css" style="display:none;">.no-print{display:none}</textarea>
<iframe id="printing-frame" name="print_frame" src="about:blank" style="display:none;"></iframe>
<script type="text/javascript">
 window.focus();
 window.print();
//}
</script>
</head>
<body>
<div id="print_antrian">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<center>
<table style="width:300px;">
<tr>
<td class="text-center">
<div class="container text-center">
  <div class="row">
    <div class="col-md bg-success" style="padding:10px;text-align:center">
      <div style="border-top:1px solid gray;width: 230px;margin-left: auto;margin-right: auto;"></div>
      <div style="padding:5px;font-weight:bold;font-size:15px;">ANTRIAN</div>			
      <div style="font-size:50px;font-weight:bold;padding:5px;">
        <?php echo $row->a_nomor;?>
      </div>
      <div style="padding-top:5px;font-size:13px;">
      <?php echo date('d-m-Y H:i:s'); ?>
      </div>
      <hr/>
      </div>
  </div>
</div>	
</td>
</tr>
</table>
</center>
</div>
</body>
</html>

Recommended For You

About the Author: adyrhs

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *