Persediaan atau Inventory sangat penting untuk dicatat dan dapat menjadi pekerjaan yang amat sulit apabila dihitung secara manual. Penghitungan inventory yang akurat sangat penting dan dapat menghemat banyak waktu dan biaya. Fungsi barcode adalah sebagai penyimpanan seluruh informasi data-data spesifik mengenai suatu produk atau berbagai barang yang telah mendapat label kode bar. Data-data spesifik yang tersimpan adalah seperti kode produksi, tanggal kadaluarsa, dan nomor identifikasi produk.
Membuat input barang dengan barcode !, tentulah menjadi solusi terbaik.
langkah awal :
- open xampp
- open sublime text
- donwload barcode php
buat folder penyimpanan file di htdoct
- file images
Buat sebuah database :
buat sebuah file konfigirasi.php
masukan script ini:
- <?php
- $host="localhost";
- $user="root";
- $password="";
- $koneksi=mysql_connect($host,$user,$password) or
- die("Gagal koneksi ..!");
- mysql_select_db("db_inventory_barang");
- ?>
kemudian :
buat sebuah Input Barcode Barang.php
- <!DOCTYPE html>
- <html>
- <head>
- <title>Input Barcode Barang</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">
- </head>
- <body>
- <div class="container col-md-6">
- <h5>Input Inventory</h5>
- <div class="card">
- <div class="card-header bg-success text-white">
- Input Barang
- </div>
- <div class="card-body">
- <form method="post" action="simpan_inventory.php" role="form">
- <div class="form-group">
- <label>Nama Barang</label>
- <input type="text" name="nama_barang" class="form-control" required="">
- </div>
- <div class="form-group">
- <label>Quantity</label>
- <input type="text" name="quantity" class="form-control" required="">
- </div>
- <div class="form-group">
- <label>Harga Satuan</label>
- <input type="text" name="harga_satuan" class="form-control" required="">
- </div>
- <div class="form-group">
- <label>kode Barcode</label>
- <input type="text" name="kode_barcode" class="form-control" required="">
- </div>
- <button type="submit" class="btn btn-primary" name="submit">Simpan data</button>
- </form>
- </div>
- </div>
- </div>
- </body>
- <script src="bootstrap-4.3.1/js/bootstrap.min.js"></script>
- </html>
buat sebuah file simpan_inventory.php
- <?php
- include('konfigurasi.php');
- if(isset($_POST['submit'])){
- $nama_barang = $_POST['nama_barang'];
- $quantity = $_POST['quantity'];
- $harga_satuan = $_POST['harga_satuan'];
- $kode_barcode = $_POST['kode_barcode'];
- //function untuk melakukan random kode unik
- function randomKodeBarcode($qtd) {
- $Caracteres = 'ABCDEFGHIJKLMOPQRSTUVXWYZ0123456789';
- $QuantidadeCaracteres = strlen($Caracteres);
- $QuantidadeCaracteres--;
- $Hash=NULL;
- for($x=1;$x<=$qtd;$x++){
- $Posicao = rand(0,$QuantidadeCaracteres);
- $Hash .= substr($Caracteres,$Posicao,1);
- }
- return $Hash;
- }
- //proses barcode
- $kode_barcode = 'BARANG-'.str_replace(' ', '_', $_POST['nama']).'-'.randomKodeBarcode(6);
- //proses generate gambar barcode dan simpan ke folder yg ditentukan
- $tempdir = "images/"; //nama folder nya
- $target_path = $tempdir . $kode_barcode . ".png";
- //cek apakah server menggunakan http atau https
- $protocol = stripos($_SERVER['SERVER_PROTOCOL'], 'https') === 0 ? 'https://' : 'http://';
- //url file image barcode
- $file_gambar = $protocol . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/barcode.php?text=" . $kode_barcode . "&print=true&size=65"; //size untuk atur ukuran gambar barcode nya
- //ambil gambar barcode dari url yg ditentukan lalu namanya ditampung ke $gambar_barcode
- $content = file_get_contents($file_gambar);
- file_put_contents($target_path, $content);
- $gambar_barcode = $kode_barcode.'.png';
- mysql_query("insert into inventory (nama_barang, quantity, harga_satuan, kode_barcode, img_barcode) VALUES ('$nama_barang', '$quantity', '$harga_satuan', '$kode_barcode', '$gambar_barcode')");
- echo"<script>alert('data berhasil disimpan!');window.location='Input_Barcode_Barang.php';</script>";
- }
- ?>
buat file view_inventory.php
- <!DOCTYPE html>
- <html>
- <head>
- <title>Data Inventory</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">
- </head>
- <body>
- <body>
- <div class="container col-md-6">
- <h5>Data Inventory</h5>
- <div class="card">
- <div class="card-header bg-success text-white">
- Data Barang <a href="input_barcode_barang.php" class="btn btn-sm btn-primary float-right">+ Tambah</a>
- </div>
- <div class="card-body">
- <table class="table table-bordered">
- <thead>
- <tr>
- <th>No</th>
- <th>Nama Barang</th>
- <th>Quantity</th>
- <th>Harga Satuan</th>
- <th>Kode Barcode</th>
- <th>Gambar Barcode</th>
- </tr>
- </thead>
- <tbody>
- <?php
- include('konfigurasi.php');
- $datas = mysql_query("select * from inventory");
- $no = 1;
- while($row = mysql_fetch_assoc($datas))
- {
- ?>
- <tr>
- <td><?= $no; ?></td>
- <td><?= $row['nama_barang']; ?></td>
- <td><?= $row['quantity']; ?></td>
- <td>Rp.<?= $row['harga_satuan']; ?></td>
- <td><?= $row['kode_barcode']; ?></td>
- <td><img src="images/<?= $row['img_barcode']; ?>" style="width: 220px;"/> <a href="images/<?= $row['img_barcode']; ?>" target="_blank">[lihat]</a> </td>
- </tr>
- <?php $no++; } ?>
- </tbody>
- </table>
- </div>
- </div>
- </div>
- </body>
- <script src="bootstrap-4.3.1/js/bootstrap.min.js"></script>
- </html>
kemudian buat print_barcode.php
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>print barcode</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">
- </head>
- <body>
- <div class="container col-md-6">
- <h5>Print Barcode</h5>
- <div class="card">
- <div class="card-header bg-success text-white">
- Barcode Barang
- </div>
- <div class="card-body">
- <table class="table table-bordered">
- <thead>
- <tr>
- <th>No</th>
- <th>Nama Barang</th>
- <th>Gambar Barcode</th>
- </tr>
- </thead>
- <tbody>
- <?php
- include('konfigurasi.php');
- $datas = mysql_query("select * from inventory");
- $no = 1;
- while($row = mysql_fetch_assoc($datas))
- {
- ?>
- <tr>
- <td><?= $no; ?></td>
- <td><?= $row['nama_barang']; ?></td>
- <td><img src="images/<?= $row['img_barcode']; ?>" style="width: 220px;"/></td>
- </tr>
- <?php $no++; } ?>
- </tbody>
- </table>
- </div>
- </div>
- </div>
- <script>
- window.print();
- </script>
- </body>
- <script src="bootstrap-4.3.1/js/bootstrap.min.js"></script>
- </html>
jalankan file tersebut.
- input barcode.