Minggu, 24 Februari 2019

transaksi.php.

<?php
if (!isset($_SESSION['nama_user'])) {
    header("location:login.php");
}
?>
            <!-- Basic Form Start -->
            <div class="basic-form-area mg-b-15">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="sparkline12-list shadow-reset mg-t-30">
                                <div class="sparkline12-hd">
                                    <div class="main-sparkline12-hd">
                                        <h1>Form Transaksi Penjualan
                                         <span class="pull-right"><?php echo date('d F Y'); ?></span></h1>
                                        <!-- <div class="sparkline12-outline-icon">
                                            <span class="sparkline12-collapse-link"><i class="fa fa-chevron-up"></i></span>
                                            <span class="sparkline12-collapse-close"><i class="fa fa-times"></i></span>
                                        </div> -->
                                    </div>
                                </div>
                                <div class="sparkline12-graph">
                                    <div class="basic-login-form-ad">
                                        <div class="row">
                                            <div class="col-lg-12">
                                                <div class="all-form-element-inner">
                                                    <form id="insert-to-cart" method="post">
                                                        <input type="hidden" name="data[jumlah]" value='1'>
                                                        <input type="hidden" name="tabel[tabel]" value="cart">
                                                        <?php
                                                        $a = 0;
                                                        foreach ($db->data("barang") as $kd_brg) {
                                                            $a++;
                                                        ?>
                                                            <input type="hidden" name="data[kd_barang<?php echo $a; ?>]" id="kd<?php echo $a; ?>" value="<?php echo $kd_brg['kd_barang']; ?>">
                                                        <?php
                                                        }
                                                        ?>
                                                        <div class="form-group-inner col-lg-6">
                                                          <h4 class="pull-left">Data Barang</h4>
                                                          <table id="table" data-toggle="table" data-pagination="true" data-search="true">
                                                            <thead>
                                                                <tr>
                                                                    <th>No</th>
                                                                    <th>Nama Barang</th>
                                                                    <th>Harga</th>
                                                                    <th>Add</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody id="brg">
                                                                <?php
                                                                if ($db->data("barang") != 0) {
                                                                    $no = 0;
                                                                    foreach ($db->data("barang") as $barang) {
                                                                        $no++;
                                                                ?> 
                                                                        <tr>
                                                                            <td><?php echo $no; ?></td>
                                                                            <td><?php echo $barang['nama_barang']; ?></td>
                                                                            <td><?php echo 'Rp '.number_format($barang['hrg_jual'],0,',','.').',-'; ?></td>
                                                                            <td><a name="insert_to_cart" id="insert_to_cart<?php echo $no; ?>" data-id="<?php echo $no ?>" class="btn btn-primary">ADD</a></td>
                                                                        </tr>
                                                                <?php
                                                                    }
                                                                }
                                                                ?>
                                                            </tbody>
                                                          </table>
                                                        </div>
                                                    </form>
                                                    <form method="post" action="proses/proses.php?aksi=transaksi">
                                                        <div class="col-lg-6">
                                                            <h4 class="pull-left">Cart Penjualan</h4>
                                                            <div class="sparkline12-graph">
                                                                <div class="static-table-list">
                                                                    <table class="table hover-table">
                                                                        <thead>
                                                                            <tr>
                                                                                <th>No</th>
                                                                                <th>Nama Barang</th>
                                                                                <th>Harga</th>
                                                                                <th>Jumlah</th>
                                                                                <th>Subtotal</th>
                                                                                <th></th>
                                                                            </tr>
                                                                        </thead>
                                                                        <tbody id="show_cart">
                                                                        </tbody>
                                                                    </table>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="form-group-inner col-lg-6">
                                                            <div class="row">
                                                                <div class="col-lg-3">
                                                                    <label class="login2 pull-right pull-right-pro">ID Pembeli</label>
                                                                </div>
                                                                <div class="col-lg-9">
                                                                    <select name="id_pembeli" class="form-control chosen-select">
                                                                        <?php
                                                                        if ($db->data("pembeli") != 0) {
                                                                            foreach ($db->data("pembeli") as $id) {
                                                                        ?>
                                                                                <option value="<?php echo $id['id_pembeli']; ?>"><?php echo $id['id_pembeli']." | ".$id['nama_pembeli']; ?></option>
                                                                        <?php
                                                                            }
                                                                        }
                                                                        ?>
                                                                    </select>
                                                                </div>
                                                                <a data-toggle="modal" data-target="#tambahpembeli" href="#">Belum jadi member?</a>
                                                            </div>
                                                        </div>
                                                        <div class="form-group-inner col-lg-6">
                                                            <div class="row">
                                                                <div class="col-lg-3">
                                                                    <label class="login2 pull-right pull-right-pro">PIC</label>
                                                                </div>
                                                                <div class="col-lg-9">
                                                                    <input type="text" class="form-control" name="pic" readonly="readonly" value="<?php echo $_SESSION['nama_user']; ?>" />
                                                                    <input type="hidden" name="no_nota" value="<?php echo 'N'.date('dm').'OT'.date('yhi').'A'.date('s'); ?>">
                                                                    <input type="hidden" name="tgl_transaksi" value="<?php echo date('d-m-Y'); ?>">
                                                                </div>

                                                                    <div class="col-lg-12">
                                                                        <div class="login-horizental cancel-wp">
                                                                            <button class="btn btn-sm btn-success login-submit-c pull-right pull-right-pro" type="submit">PAYMENT!</button>
                                                                        </div>
                                                                    </div>
                                                            </div>
                                                        </div>
                                                    </form>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

index.php.


    <script type="text/javascript">
        $(document).ready(function(){
            //cart
            var row = document.getElementById("brg").rows.length;
            for(var i = 0; i <= row; i++){
                count = 0;
                $("#insert_to_cart"+i).click(function(){
                    var no = $(this).data("id");
                    count+=1;
                    var kd = $("#kd"+no).val();
                    var data = $('#insert-to-cart').serialize();
                    $.ajax({
                        type: 'POST',
                        url: 'proses/proses.php?aksi=cart&kd_barang='+kd,
                        data: data,
                        success: function(){
                            $('#show_cart').load('proses/cart.php');
                        }
                    });
                });
            }
        })
    </script>

proses_trans.php.


<?php
spl_autoload_register(function($class){
include"../class/".$class.".php";
});
$db = new class_function();
$id_pembeli=$_POST['id_pembeli'];
$no_nota=$_POST['no_nota'];
$tgl_transaksi=$_POST['tgl_transaksi'];
$pic=$_POST['pic'];
$total = $_POST['total'];
$query=mysql_query("insert into transaksi values('$no_nota','$id_pembeli','$tgl_transaksi',$total,'$pic')");

foreach ($_POST['count'] as $key => $hitung) {
$kd_barang=$_POST['kd_barang'.$hitung];
$jumlah=$_POST['jumlah'.$hitung];
$subtotal=$_POST['subtotal'.$hitung];
mysql_query("INSERT INTO detail_transaksi(no_nota,kd_barang,jumlah,total_harga) VALUES ('$no_nota','$kd_barang',$jumlah,$subtotal)");

mysql_query("UPDATE barang SET jumlah=jumlah-$jumlah WHERE kd_barang='$kd_barang'");

mysql_query("TRUNCATE TABLE cart");
}
header("location:invoice.php");
?>

cart.php.



<?php
session_start();
if (!isset($_SESSION['nama_user'])) {
<?php
spl_autoload_register(function($class){
include"../class/".$class.".php";
});
$db = new class_function();
session_start();
if ($db->data("cart") != 0) {
    $no=0;
    $total=0;
    foreach ($db->data("cart") as $order) {
        $no++;
?>
        <tr>
            <td><?php echo $no; ?></td>
            <input type="hidden" name="count[]" value="<?php echo $no; ?>">
            <?php
            foreach ($db->datawhere("barang","kd_barang='".$order['kd_barang']."'") as $brg) {
            ?>
                <td><?php echo $brg['nama_barang']; ?></td>
                <input type="hidden" name="kd_barang<?php echo $no; ?>" value="<?php echo $brg['kd_barang']; ?>">
                <td><?php echo 'Rp '.number_format($brg['hrg_jual'],0,',','.'); ?></td>
            <td><?php echo $order['jumlah']; ?></td>
            <td>
                <?php 
                $subtotal = $order['jumlah']*$brg['hrg_jual'];
                echo 'Rp '.number_format($subtotal,0,',','.');
                $total +=$subtotal;
                ?>
            </td>
            <input type="hidden" name="jumlah<?php echo $no; ?>" value="<?php echo $order['jumlah']; ?>">
            <input type="hidden" name="subtotal<?php echo $no; ?>" value="<?php echo $subtotal; ?>">
            <input type="hidden" id="kode<?php echo $no; ?>" value="<?php echo $order['kd_barang']; ?>">
            <td><a id="hapus<?php echo $no; ?>" data-id="<?php echo $no ?>" class="hapus" title="hapus"><i class="fa fa-times"></i></a></td>
        </tr>
<?php
        }
    }
?>
        <tr>
            <td colspan="4">TOTAL</td>
            <td>
                <?php
                echo 'Rp '.number_format($total,0,',','.');
                ?>
            </td>
            <input type="hidden" name="total" value="<?php echo $total; ?>">
        </tr>
<?php
}
?>
    <!-- jquery
        ============================================ -->
    <script src="../js/vendor/jquery-2.1.1.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            //cart
            // $("#hapus").click(function() {
            //     var nilai = $("#kode").val();
            //     alert(nilai);
            // });

            //var row = document.getElementById("brg").rows.length;
            for(var x = 0; x <= 100; x++){
                counts = 0;
                $("#hapus"+x).click(function(){
                    var noe = $(this).data("id");
                    counts+=1;
                    var hps = $("#kode"+noe).val();
                    console.log(hps);
                    $.ajax({
                        type: 'POST',
                        url: 'proses/proses.php?aksi=hapuscart&kd='+hps,
                        success: function(){
                            $('#show_cart').load('proses/cart.php');
                        }
                    });
                });
            }
        })
    </script>


Update Data InLine With Ajax

barang.php.

                                            <tbody id="data_barang">
                                                <?php
                                                $no = 0;
                                                if ($db->data("barang") != 0) {
                                                    foreach ($db->data("barang") as $data) {
                                                        $no++;
                                                ?>
                                                <tr>
                                                    <td></td>
                                                    <td><?php echo $no; ?></td>
                                                    <td><?php echo $data['kd_barang']; ?></td>
                                                    <td data-name="nama_barang" class="nama_barang" data-type="text" data-pk="<?php echo $data['kd_barang']; ?>"><?php echo $data['nama_barang']; ?></td>
                                                    <td data-name="jenis" class="jenis" data-type="text" data-pk="<?php echo $data['kd_barang']; ?>"><?php echo $data['jenis']; ?></td>
                                                    <td data-name="jumlah" class="jumlah" data-type="text" data-pk="<?php echo $data['kd_barang']; ?>"><?php echo $data['jumlah']; ?></td>
                                                    <td data-name="hrg_beli" class="hrg_beli" data-type="text" data-pk="<?php echo $data['kd_barang']; ?>"><?php echo 'Rp '.number_format($data['hrg_beli'],0,',','.').',-'; ?></td>
                                                    <td data-name="hrg_jual" class="hrg_jual" data-type="text" data-pk="<?php echo $data['kd_barang']; ?>"><?php echo 'Rp '.number_format($data['hrg_jual'],0,',','.').',-'; ?></td>
                                                    <!-- <td><button class="Information Information-color mg-b-10 btn btn-info" data-toggle="modal" data-target="#tambahbarang"><i class="fa fa-edit"></i></button></td> -->
                                                </tr>
                                                <?php
                                                    }
                                                }
                                                ?>
                                            </tbody>


index.php.


    <script type="text/javascript">
        $(document).ready(function(){
            //edit data barang
            $('#data_barang').editable({
                container: 'body',
                selector: 'td.nama_barang',
                url: "update.php?aksi=barang",
                title: 'Nama Barang',
                type: "POST",
                //dataType: 'json',
                validate: function(value){
                    if($.trim(value) == '') {
                        return 'This field is required';
                    }
                }
            });
        })
    </script>

update.php.


<?php
//update
if (!isset($_SESSION['nama_user'])) {
    header("location:login.php");
}
$connect = mysqli_connect("localhost", "root", "", "vaganza");
$aksi = $_GET['aksi'];
if ($aksi == 'barang') {
$query = "UPDATE barang SET ".$_POST["name"]." = '".$_POST["value"]."' WHERE kd_barang = '".$_POST["pk"]."'";
mysqli_query($connect, $query);
} elseif ($aksi == 'pembeli') {
$query = "UPDATE pembeli SET ".$_POST["name"]." = '".$_POST["value"]."' WHERE id_pembeli = '".$_POST["pk"]."'";
mysqli_query($connect, $query);
}
?>

Source Code CRUD PHP OOP

class_function.php.

<?php
class class_function{

//buka koneksi
public function __construct(){
mysql_connect('localhost', 'root', '') or die("gagal connect");
mysql_select_db("vaganza");
}

//show data

public function data($tabel) {
$data = mysql_query("select * from $tabel");
$row = mysql_num_rows($data);
while($d = mysql_fetch_array($data)) {
$hasil[] = $d;
}
if ($row >= 1) {
return $hasil;
}

}
public function datawhere($table,$where){
//print_r("SELECT * from ".$table." WHERE ".$where);
//die();
$query = mysql_query("SELECT * from ".$table." WHERE ".$where);
if ($query) {
$row = mysql_num_rows($query);
while($d = mysql_fetch_array($query)) {
$hasil[] = $d;
}
if ($row >= 1) {
return $hasil;
}
}else{
}
}

//insert
public function insert($tabel,$data){
$fields = "(";
$values = "(";
$index = 0;
foreach($data as $key=>$val) {
$fieldname = ($index < count($data)-1) ? $key . " , " : $key . ")";
$valuedata = ($index < count($data)-1) ? "'" .$val . "' , " : "'" . $val . "')";

$fields .= $fieldname;
$values .= $valuedata;
$index++;
}
$query = "insert into " . $tabel . "  " .$fields . " values " . $values . " ";
// print_r($query);
// die();
mysql_query($query);
}

//delete
public function hapus($tabel,$baris,$id){
$data = mysql_query("delete from $tabel where $baris='$id'");
}

//update
public function update($table , $data , $where){
foreach ( $data as $kolom => $row ){
$set[]= $kolom."='".$row."'" ;
}
$set = implode(',',$set);
$query1 = "UPDATE ".$table." SET ".$set." WHERE ".$where ;
mysql_query($query1);
}

//format tanggal

function tanggal($tanggal, $cetak_hari = false){
$hari = array (1=> 'Senin',
'Selasa',
'Rabu',
'Kamis',
'Jumat',
'Sabtu',
'Minggu'
);
$bulan = array (1=> 'Januari',
'Februari',
'Maret',
'April',
'Mei',
'Juni',
'Juli',
'Agustus',
'September',
'Oktober',
'November',
'Desember'
);
$split   = explode('/', $tanggal);
$tgl_indo = $split[2] . ' ' . $bulan[ (int)$split[1] ] . ' ' . $split[0];
if ($cetak_hari) {
$num = date('N', strtotime($tanggal));
return $hari[$num] . ', ' . $tgl_indo;
}
return $tgl_indo;
}

//Penghitungan rows

function sumrows($tabel,$where){
$query = mysql_query("SELECT * from ".$tabel." WHERE ".$where);
if ($query != "") {
$row = mysql_num_rows($query);
if ($row >= 1) {
return $row;
}else{
return $row;
}
}else{
echo 0;
}
}
function sumtbl($tabel){
$query = mysql_query("SELECT * from ".$tabel);
if ($query != "") {
$row = mysql_num_rows($query);
if ($row >= 1) {
return $row;
}else{
return $row;
}
}else{
echo 0;
}
}

//ecrypsi
function encryptIt( $q ) {
$cryptKey  = 'qJB0rGtIn5UB1xG03efyCp';
$qEncoded      = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), $q, MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ) );
return( $qEncoded );
}

function decryptIt( $q ) {

$cryptKey  = 'qJB0rGtIn5UB1xG03efyCp';
$qDecoded      = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), base64_decode( $q ), MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ), "\0");
return( $qDecoded );
}

//chart
function jumlah($awal,$akhir,$table,$where){
$query = mysql_query("SELECT * from ".$table." where ".$where." BETWEEN  '".$awal."' AND  '".$akhir."'");
$rs = mysql_num_rows($query);
if($rs != 0){
while($rs){
return $rs;
}
} else {
$rs = 0;
return $rs;
}
}
function Total($tahun,$table,$where){
$data = array(
$this->jumlah($tahun.'-01-01',$tahun.'-01-31',$table,$where),
$this->jumlah($tahun.'-02-01',$tahun.'-02-31',$table,$where),
$this->jumlah($tahun.'-03-01',$tahun.'-03-31',$table,$where),
$this->jumlah($tahun.'-04-01',$tahun.'-04-31',$table,$where),
$this->jumlah($tahun.'-05-01',$tahun.'-05-31',$table,$where),
$this->jumlah($tahun.'-06-01',$tahun.'-06-31',$table,$where),
$this->jumlah($tahun.'-07-01',$tahun.'-07-31',$table,$where),
$this->jumlah($tahun.'-08-01',$tahun.'-08-31',$table,$where),
$this->jumlah($tahun.'-09-01',$tahun.'-09-31',$table,$where),
$this->jumlah($tahun.'-10-01',$tahun.'-10-31',$table,$where),
$this->jumlah($tahun.'-11-01',$tahun.'-11-31',$table,$where),
$this->jumlah($tahun.'-12-01',$tahun.'-12-31',$table,$where)
);
echo  $json_encode = json_encode($data);
}
function Sum($awal,$akhir,$table,$where){
$query = mysql_query("SELECT * from ".$table." where ".$where." BETWEEN  '".$awal."' AND  '".$akhir."'");
$rt = mysql_num_rows($query);
if($rt != 0){
while($rt){
return $rt;
}
} else {
$rt = 0;
return $rt;
}
}
function bulan($tahun,$table,$where,$bulan){
$a = array(
$this->Sum($tahun.'-'.$bulan.'-01 00:00:00',$tahun.'-'.$bulan.'-01 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-02 00:00:00',$tahun.'-'.$bulan.'-02 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-03 00:00:00',$tahun.'-'.$bulan.'-03 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-04 00:00:00',$tahun.'-'.$bulan.'-04 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-05 00:00:00',$tahun.'-'.$bulan.'-05 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-06 00:00:00',$tahun.'-'.$bulan.'-06 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-07 00:00:00',$tahun.'-'.$bulan.'-07 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-08 00:00:00',$tahun.'-'.$bulan.'-08 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-09 00:00:00',$tahun.'-'.$bulan.'-09 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-10 00:00:00',$tahun.'-'.$bulan.'-10 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-11 00:00:00',$tahun.'-'.$bulan.'-11 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-12 00:00:00',$tahun.'-'.$bulan.'-12 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-13 00:00:00',$tahun.'-'.$bulan.'-13 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-14 00:00:00',$tahun.'-'.$bulan.'-14 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-15 00:00:00',$tahun.'-'.$bulan.'-15 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-16 00:00:00',$tahun.'-'.$bulan.'-16 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-17 00:00:00',$tahun.'-'.$bulan.'-17 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-18 00:00:00',$tahun.'-'.$bulan.'-18 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-19 00:00:00',$tahun.'-'.$bulan.'-19 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-20 00:00:00',$tahun.'-'.$bulan.'-20 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-21 00:00:00',$tahun.'-'.$bulan.'-21 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-22 00:00:00',$tahun.'-'.$bulan.'-22 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-23 00:00:00',$tahun.'-'.$bulan.'-23 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-24 00:00:00',$tahun.'-'.$bulan.'-24 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-25 00:00:00',$tahun.'-'.$bulan.'-25 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-26 00:00:00',$tahun.'-'.$bulan.'-26 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-27 00:00:00',$tahun.'-'.$bulan.'-27 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-28 00:00:00',$tahun.'-'.$bulan.'-28 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-29 00:00:00',$tahun.'-'.$bulan.'-29 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-30 00:00:00',$tahun.'-'.$bulan.'-30 23:59:59',$table,$where),
$this->Sum($tahun.'-'.$bulan.'-31 00:00:00',$tahun.'-'.$bulan.'-31 23:59:59',$table,$where),
);
echo  $json_encode = json_encode($a);
}
function report($table,$where,$between){
$query = mysql_query("SELECT * from ".$table." where sn='".$where."' AND scan_date BETWEEN  '".$between."'");
$mesin = mysql_num_rows($query);
if($mesin != 0){
while($mesin){
return $mesin;
}
} else {
$mesin = 0;
return $mesin;
}
}
function mesin($table,$between){
foreach($this->data("device_app") as $d){
$a[] = $this->report($table,$d['sn'],$between);
}
$m = $a;
echo  $json_encode = json_encode($m);
}
function jumlah_inven($table,$kolom,$kolom2){
//print_r("SELECT SUM(".$kolom.") from ".$table." group by ".$kolom2);
//die();
$query = mysql_query("SELECT SUM(".$kolom.") from ".$table."group by ".$kolom2);
if ($query) {
$row = mysql_num_rows($query);
while($d = mysql_fetch_array($query)) {
$hasil[] = $d;
}
if ($row >= 1) {
return $hasil;
}
}else{
}
}
}
?>

login.php.


<?php
spl_autoload_register(function($class){
include"class/".$class.".php";
});
$db = new class_function();
if(isset($_POST['submit'])){
if(empty($_POST['username']) || empty($_POST['password'])){
echo "error";
}
else{
$pass = $db->encryptIt($_POST['password']);
$user = $db->encryptIt($_POST['username']);
$pass = mysql_real_escape_string($pass);
$user = mysql_real_escape_string($user);
if ($db->datawhere("admin","password='".$pass."' AND binary username ='".$user."'") != "") {
foreach ($db->datawhere("admin","password='".$pass."' AND binary username ='".$user."'") as $a);
$_SESSION['nama_user'] = $a['nama'];
header('location:index.php');
exit();
}
}
}
?>

proses.php.


<?php
spl_autoload_register(function($class){
include "../class/".$class.".php";
});
$db = new class_function();
$data = $_POST['data'];
$tabel = $_POST['tabel'];
$aksi = $_GET['aksi'];

//umum
if($aksi=='tambah'){
$db->insert($tabel['tabel'],$data);
header("location:../index.php?menu=".$tabel['url']);
}
elseif($aksi == "update"){
  $db->update($tabel['tabel'],$data, $tabel['field']." = '". $tabel['val'] ."'");
  header("location:../index.php?menu=".$tabel['url']);
}

elseif ($aksi == 'tambah_barang') {
if ($db->datawhere("barang","kd_barang='".$data['kd_barang']."'") == 0) {
$db->insert($tabel['tabel'],$data);
header("location:../index.php?menu=".$tabel['url']."&success");
} else {
mysql_query("UPDATE barang SET jumlah = jumlah + '".$data['jumlah']."' where kd_barang='".$data['kd_barang']."'");
header("location:../index.php?menu=".$tabel['url']."&success");
}
}

elseif ($aksi == 'tambah_pembeli') {
if ($db->datawhere("pembeli","id_pembeli='".$data['id_pembeli']."'") == 0) {
$db->insert($tabel['tabel'],$data);
header("location:../index.php?menu=".$tabel['url']."&success");
} else {
header("location:../index.php?menu=".$tabel['url']."&failed");
}
}

//checkbox
elseif (isset($_POST['hapuscheck'])) {
$check = $_POST['dipilih'];
$jml_check = count($check);
for ($i=0; $i < $jml_check; $i++) { 
$db->hapus($tabel['tabel'],$tabel['field'],$check[$i]);
}
if ($_POST['jrs'] = "jurusan") {
header("location:../pages/admin/?page=".$tabel['url']."&jurusan=".$data['idj']."&kls=".$data['tingkatan']."&p_del");
}else{
header("location:../pages/admin/?page=".$tabel['url']."&p_del");
}
}
elseif($aksi == "hapuscheck"){
$check = $_POST['dipilih'];
$jml_check = count($check);
for($i=0; $i < $jml_check; $i++) { 
$db->hapus($tabel['tabel'],$tabel['field'],$check[$i]);
}
}

//cart
else if($aksi == 'cart'){
if ($db->datawhere("cart","kd_barang='".$_GET['kd_barang']."'") == 0) {
$ary = array("kd_barang"=>$_GET['kd_barang'],"jumlah"=>$data['jumlah']);
$db->insert("cart",$ary);
} else {
mysql_query("UPDATE cart SET jumlah = jumlah + 1 where kd_barang='$_GET[kd_barang]'");
}
}
else if ($aksi == 'hapuscart') {
mysql_query("DELETE FROM cart WHERE kd_barang='".$_GET['kd']."'");
}

//transaksi
else if ($aksi == 'transaksi') {
$id_pembeli=$_POST['id_pembeli'];
$no_nota=$_POST['no_nota'];
$tgl_transaksi=$_POST['tgl_transaksi'];
$pic=$_POST['pic'];
$total = $_POST['total'];
$query=mysql_query("insert into transaksi values('$no_nota','$id_pembeli','$tgl_transaksi',$total,'$pic')");

foreach ($_POST['count'] as $key => $hitung) {
$kd_barang=$_POST['kd_barang'.$hitung];
$jumlah=$_POST['jumlah'.$hitung];
$subtotal=$_POST['subtotal'.$hitung];
mysql_query("INSERT INTO detail_transaksi(no_nota,kd_barang,jumlah,total_harga) VALUES ('$no_nota','$kd_barang',$jumlah,$subtotal)");
mysql_query("UPDATE barang SET jumlah=jumlah-$jumlah WHERE kd_barang='$kd_barang'");
mysql_query("TRUNCATE TABLE cart");
}
header("location:invoice.php");
}
?>

index.php.



-- atas --
<?php
session_start();
if (!isset($_SESSION['nama_user'])) {
    header("location:login.php");
}
spl_autoload_register(function($class){
    include "class/".$class.".php";
});
$db = new class_function();

?>
-- tengah --
<?php
            if (isset($_GET['menu'])) {
                $menu=$_GET['menu'];
                switch ($menu) {
                    case 'dashboard':
                        include 'dashboard.php';
                        break;
                    case 'barang':
                        include 'barang.php';
                        break;
                    case 'pembeli':
                        include 'pembeli.php';
                        break;
                    case 'transaksi':
                        include 'transaksi.php';
                        break;
                    case 'laporan':
                        include 'laporan.php';
                        break;
                    default:
                        include 'dashboard.php';
                        break;
                }
            } else {
                include 'dashboard.php';
            }            
            ?>