Lompat ke konten Lompat ke sidebar Lompat ke footer

Membuat Modul yang dibutuhkan untuk aplikasi POS (Point Of Sales)

Setelah membuat desain database pada materi sebelumnya  tahap selanjutnya adalah membuat modul yang dibutuhkan untuk aplikasi POS yang akan kita buat. modul tersebut berisi perintah-perintah yang dibutuhkan agar aplikasi dapat bekerja dengan baik. berikut adalah file-file yang akan kita buat :

Membuat Coding untuk Edit data Barang

Tambahkan folder pada project sebelumnya seperti pada gambar diatas. pada file edit.php tambahkan coding seperti berikut : 
<?php
session_start();

require '../../config.php';
if (!empty($_GET['pengaturan'])) {
    $nama = htmlentities($_POST['namatoko']);
    $alamat = htmlentities($_POST['alamat']);
    $kontak = htmlentities($_POST['kontak']);
    $pemilik = htmlentities($_POST['pemilik']);
    $id = '1';

    $data[] = $nama;
    $data[] = $alamat;
    $data[] = $kontak;
    $data[] = $pemilik;
    $data[] = $id;
    $sql = 'UPDATE toko SET nama_toko=?, alamat_toko=?, tlp=?, nama_pemilik=? WHERE id_toko = ?';
    $row = $config->prepare($sql);
    $row->execute($data);
    echo '<script>window.location="../../index.php?page=pengaturan&success=edit-data"</script>';
}

if (!empty($_GET['kategori'])) {
    $nama = htmlentities($_POST['kategori']);
    $id = htmlentities($_POST['id']);
    $data[] = $nama;
    $data[] = $id;
    $sql = 'UPDATE kategori SET  nama_kategori=? WHERE id_kategori=?';
    $row = $config->prepare($sql);
    $row->execute($data);
    echo '<script>window.location="../../index.php?page=kategori&uid=' . $id . '&success-edit=edit-data"</script>';
}

if (!empty($_GET['stok'])) {
    $restok = htmlentities($_POST['restok']);
    $id = htmlentities($_POST['id']);
    $dataS[] = $id;
    $sqlS = 'select*from barang WHERE id_barang=?';
    $rowS = $config->prepare($sqlS);
    $rowS->execute($dataS);
    $hasil = $rowS->fetch();

    $stok = $restok + $hasil['stok'];

    $data[] = $stok;
    $data[] = $id;
    $sql = 'UPDATE barang SET stok=? WHERE id_barang=?';
    $row = $config->prepare($sql);
    $row->execute($data);
    echo '<script>window.location="../../index.php?page=barang&success-stok=stok-data"</script>';
}

if (!empty($_GET['barang'])) {
    $id = htmlentities($_POST['id']);
    $kategori = htmlentities($_POST['kategori']);
    $nama = htmlentities($_POST['nama']);
    $merk = htmlentities($_POST['merk']);
    $beli = htmlentities($_POST['beli']);
    $jual = htmlentities($_POST['jual']);
    $satuan = htmlentities($_POST['satuan']);
    $stok = htmlentities($_POST['stok']);
    $tgl = htmlentities($_POST['tgl']);

    $data[] = $kategori;
    $data[] = $nama;
    $data[] = $merk;
    $data[] = $beli;
    $data[] = $jual;
    $data[] = $satuan;
    $data[] = $stok;
    $data[] = $tgl;
    $data[] = $id;
    $sql = 'UPDATE barang SET id_kategori=?, nama_barang=?, merk=?, 
				harga_beli=?, harga_jual=?, satuan_barang=?, stok=?, tgl_update=?  WHERE id_barang=?';
    $row = $config->prepare($sql);
    $row->execute($data);
    echo '<script>window.location="../../index.php?page=barang/edit&barang=' . $id . '&success=edit-data"</script>';
}

if (!empty($_GET['gambar'])) {
    $id = htmlentities($_POST['id']);
    set_time_limit(0);
    $allowedImageType = array("image/gif",   "image/JPG",   "image/jpeg",   "image/pjpeg",   "image/png",   "image/x-png");

    if ($_FILES['foto']["error"] > 0) {
        $output['error'] = "Error in File";
    } elseif (!in_array($_FILES['foto']["type"], $allowedImageType)) {
        // echo "You can only upload JPG, PNG and GIF file";
        // echo "<font face='Verdana' size='2' ><BR><BR><BR>
        // 		<a href='../../index.php?page=user'>Back to upform</a><BR>";
        echo '<script>alert("You can only upload JPG, PNG and GIF file");window.location="../../index.php?page=user"</script>';
    } elseif (round($_FILES['foto']["size"] / 1024) > 4096) {
        // echo "WARNING !!! Besar Gambar Tidak Boleh Lebih Dari 4 MB";
        // echo "<font face='Verdana' size='2' ><BR><BR><BR>
        // 		<a href='../../index.php?page=user'>Back to upform</a><BR>";
        echo '<script>alert("WARNING !!! Besar Gambar Tidak Boleh Lebih Dari 4 MB");window.location="../../index.php?page=user"</script>';
    } else {
        $dir = '../../assets/img/user/';
        $tmp_name = $_FILES['foto']['tmp_name'];
        $name = time() . basename($_FILES['foto']['name']);
        if (move_uploaded_file($tmp_name, $dir . $name)) {
            //post foto lama
            $foto2 = $_POST['foto2'];
            //remove foto di direktori
            unlink('../../assets/img/user/' . $foto2 . '');
            //input foto
            $id = $_POST['id'];
            $data[] = $name;
            $data[] = $id;
            $sql = 'UPDATE member SET gambar=?  WHERE member.id_member=?';
            $row = $config->prepare($sql);
            $row->execute($data);
            echo '<script>window.location="../../index.php?page=user&success=edit-data"</script>';
        } else {
            echo '<script>alert("Masukan Gambar !");window.location="../../index.php?page=user"</script>';
        }
    }
}

if (!empty($_GET['profil'])) {
    $id = htmlentities($_POST['id']);
    $nama = htmlentities($_POST['nama']);
    $alamat = htmlentities($_POST['alamat']);
    $tlp = htmlentities($_POST['tlp']);
    $email = htmlentities($_POST['email']);
    $nik = htmlentities($_POST['nik']);

    $data[] = $nama;
    $data[] = $alamat;
    $data[] = $tlp;
    $data[] = $email;
    $data[] = $nik;
    $data[] = $id;
    $sql = 'UPDATE member SET nm_member=?,alamat_member=?,telepon=?,email=?,NIK=? WHERE id_member=?';
    $row = $config->prepare($sql);
    $row->execute($data);
    echo '<script>window.location="../../index.php?page=user&success=edit-data"</script>';
}

if (!empty($_GET['pass'])) {
    $id = htmlentities($_POST['id']);
    $user = htmlentities($_POST['user']);
    $pass = htmlentities($_POST['pass']);

    $data[] = $user;
    $data[] = $pass;
    $data[] = $id;
    $sql = 'UPDATE login SET user=?,pass=md5(?) WHERE id_member=?';
    $row = $config->prepare($sql);
    $row->execute($data);
    echo '<script>window.location="../../index.php?page=user&success=edit-data"</script>';
}

if (!empty($_GET['jual'])) {
    $id = htmlentities($_POST['id']);
    $id_barang = htmlentities($_POST['id_barang']);
    $jumlah = htmlentities($_POST['jumlah']);

    $sql_tampil = "select *from barang where barang.id_barang=?";
    $row_tampil = $config->prepare($sql_tampil);
    $row_tampil->execute(array($id_barang));
    $hasil = $row_tampil->fetch();

    if ($hasil['stok'] > $jumlah) {
        $jual = $hasil['harga_jual'];
        $total = $jual * $jumlah;
        $data1[] = $jumlah;
        $data1[] = $total;
        $data1[] = $id;
        $sql1 = 'UPDATE penjualan SET jumlah=?,total=? WHERE id_penjualan=?';
        $row1 = $config->prepare($sql1);
        $row1->execute($data1);
        echo '<script>window.location="../../index.php?page=jual#keranjang"</script>';
    } else {
        echo '<script>alert("Keranjang Melebihi Stok Barang Anda !");
					window.location="../../index.php?page=jual#keranjang"</script>';
    }
}

if (!empty($_GET['cari_barang'])) {
    $cari = trim(strip_tags($_POST['keyword']));
    if ($cari == '') {
    } else {
        $sql = "select barang.*, kategori.id_kategori, kategori.nama_kategori
					from barang inner join kategori on barang.id_kategori = kategori.id_kategori
					where barang.id_barang like '%$cari%' or barang.nama_barang like '%$cari%' or barang.merk like '%$cari%'";
        $row = $config->prepare($sql);
        $row->execute();
        $hasil1 = $row->fetchAll();
?>
        <table class="table table-stripped" width="100%" id="example2">
            <tr>
                <th>ID Barang</th>
                <th>Nama Barang</th>
                <th>Merk</th>
                <th>Harga Jual</th>
                <th>Aksi</th>
            </tr>
            <?php foreach ($hasil1 as $hasil) { ?>
                <tr>
                    <td><?php echo $hasil['id_barang']; ?></td>
                    <td><?php echo $hasil['nama_barang']; ?></td>
                    <td><?php echo $hasil['merk']; ?></td>
                    <td><?php echo $hasil['harga_jual']; ?></td>
                    <td>
                        <a href="fungsi/tambah/tambah.php?jual=jual&id=<?php echo $hasil['id_barang']; ?>" class="btn btn-success">
                            <i class="fa fa-shopping-cart"></i></a>
                    </td>
                </tr>
            <?php } ?>
        </table>
<?php
    }
}

Membuat Coding untuk Edit Hapus Barang,Penjualan dan Kategori

untuk melakukan hapus barang tambahkan coding berikut pada file hapus.php
<?php

session_start();
require '../../config.php';
if (!empty($_GET['kategori'])) {
    $id = $_GET['id'];
    $data[] = $id;
    $sql = 'DELETE FROM kategori WHERE id_kategori=?';
    $row = $config->prepare($sql);
    $row->execute($data);
    echo '<script>window.location="../../index.php?page=kategori&&remove=hapus-data"</script>';
}

if (!empty($_GET['barang'])) {
    $id = $_GET['id'];
    $data[] = $id;
    $sql = 'DELETE FROM barang WHERE id_barang=?';
    $row = $config->prepare($sql);
    $row->execute($data);
    echo '<script>window.location="../../index.php?page=barang&&remove=hapus-data"</script>';
}

if (!empty($_GET['jual'])) {
    $dataI[] = $_GET['brg'];
    $sqlI = 'select*from barang where id_barang=?';
    $rowI = $config->prepare($sqlI);
    $rowI->execute($dataI);
    $hasil = $rowI->fetch();

    /*$jml = $_GET['jml'] + $hasil['stok'];

        $dataU[] = $jml;
        $dataU[] = $_GET['brg'];
        $sqlU = 'UPDATE barang SET stok =? where id_barang=?';
        $rowU = $config -> prepare($sqlU);
        $rowU -> execute($dataU);*/

    $id = $_GET['id'];
    $data[] = $id;
    $sql = 'DELETE FROM penjualan WHERE id_penjualan=?';
    $row = $config->prepare($sql);
    $row->execute($data);
    echo '<script>window.location="../../index.php?page=jual"</script>';
}

if (!empty($_GET['penjualan'])) {
    $sql = 'DELETE FROM penjualan';
    $row = $config->prepare($sql);
    $row->execute();
    echo '<script>window.location="../../index.php?page=jual"</script>';
}

if (!empty($_GET['laporan'])) {
    $sql = 'DELETE FROM nota';
    $row = $config->prepare($sql);
    $row->execute();
    echo '<script>window.location="../../index.php?page=laporan&remove=hapus"</script>';
}

Membuat Coding untuk Edit Tambah Barang,Penjualan dan Kategori

untuk melakukan tambah barang,penjualan dan kategori tambahkan coding berikut pada file tambah.php
<?php

session_start();

require '../../config.php';
if (!empty($_GET['kategori'])) {
    $nama = $_POST['kategori'];
    $tgl = date("j F Y, G:i");
    $data[] = $nama;
    $data[] = $tgl;
    $sql = 'INSERT INTO kategori (nama_kategori,tgl_input) VALUES(?,?)';
    $row = $config->prepare($sql);
    $row->execute($data);
    echo '<script>window.location="../../index.php?page=kategori&&success=tambah-data"</script>';
}

if (!empty($_GET['barang'])) {
    $id = $_POST['id'];
    $kategori = $_POST['kategori'];
    $nama = $_POST['nama'];
    $merk = $_POST['merk'];
    $beli = $_POST['beli'];
    $jual = $_POST['jual'];
    $satuan = $_POST['satuan'];
    $stok = $_POST['stok'];
    $tgl = $_POST['tgl'];

    $data[] = $id;
    $data[] = $kategori;
    $data[] = $nama;
    $data[] = $merk;
    $data[] = $beli;
    $data[] = $jual;
    $data[] = $satuan;
    $data[] = $stok;
    $data[] = $tgl;
    $sql = 'INSERT INTO barang (id_barang,id_kategori,nama_barang,merk,harga_beli,harga_jual,satuan_barang,stok,tgl_input) 
			    VALUES (?,?,?,?,?,?,?,?,?) ';
    $row = $config->prepare($sql);
    $row->execute($data);
    echo '<script>window.location="../../index.php?page=barang&success=tambah-data"</script>';
}

if (!empty($_GET['jual_detail'])) {
    $id = $_GET['id'];

    // get tabel barang id_barang
    $sql = 'SELECT * FROM barang WHERE id_barang = ?';
    $row = $config->prepare($sql);
    $row->execute(array($id));
    $hsl = $row->fetch();

    if ($hsl['stok'] > 0) {
        $jumlah = 1;
        $total = $hsl['harga_jual'];
        $tgl = date("j F Y, G:i");

        $data1[] = $id;
        $data1[] = $jumlah;
        $data1[] = $total;
        $data1[] = $tgl;

        $sql_simpan_barang = 'INSERT INTO penjualan (id_barang,jumlah,total,tanggal_input) VALUES (?,?,?,?)';
        $row1 = $config->prepare($sql_simpan_barang);
        $row1->execute($data1);

        echo '<script>window.location="../../index.php?page=jual&success=tambah-data"</script>';
    } else {
        echo '<script>alert("Stok Barang Anda Telah Habis !");
					window.location="../../index.php?page=jual#keranjang"</script>';
    }
}



if (!empty($_GET['jual_master'])) {
    $id = $_GET['id'];
    //-----------------------------
    $today = date('ymdhis');
    $char = 'TR' . $today;
    $newId = $char . sprintf("%04s", $no);
    //-----------------------------
    $notransaksi=$newId;
    $tgl = date("j F Y, G:i");

    $data1[] = $newId;
    $data1[] = $tgl;
    $data1[] = 0;
    $data1[] = 0;
    $data1[] = 0;
    $sql_simpan_transaksi_baru = 'INSERT INTO penjualan_master (notransaksi,tanggal,bayar,kembali,status) VALUES (?,?,?,?,?)';
    $row1 = $config->prepare($sql_simpan_transaksi_baru);
    $row1->execute($data1);

    echo '<script>window.location="../../index.php?page=jual&success=tambah-data"</script>';
} else {
    echo '<script>alert("Stok Barang Anda Telah Habis !");
					window.location="../../index.php?page=jual#keranjang"</script>';
}
Jika sudah selesai pembuatan modul diatas pada materi berikutnya kita akan membuat desain tampilan transaksi penjualan menggunakan template AdminLte

Posting Komentar untuk "Membuat Modul yang dibutuhkan untuk aplikasi POS (Point Of Sales)"