Contoh membuat Aplikasi penjualan dengan menggunakan PHP
Scrip Daftar barang
<h1> Tambah Data Barang</h1>
<form name="form1" method="post" action="">
Id Barang<br/>
<input type="text" name="idbarang"><br/>
Nama Barang<br/>
<input type="text" name="namabarang"><br/>
Jml Barang<br/>
<input type="text" name="jumlahbarang"><br/>
Harga/Item<br/>
<input type="text" name="hargabarang"><br/>
<input name="tambah" type="submit" value="Tambah">
</form>
<?php
include('adodb/adodb.inc.php');
$databasetype = 'mysql';
$server = 'localhost';
$user = 'root';
$password = '';
$database = 'responsi';
$db = ADONewConnection($databasetype);
$db->debug = false;
$db->Connect($server, $user, $password, $database);
if(isset($_POST['idbarang'])){
$idbarang = $_POST['idbarang'];
$namabarang = $_POST['namabarang'];
$jumlahbarang = $_POST['jumlahbarang'];
$hargabarang = $_POST['hargabarang'];
$db->Execute("INSERT INTO barang (idbarang,namabarang,jumlahbarang,hargabarang)
VALUES('$idbarang','$namabarang','$jumlahbarang','$hargabarang')");
}
$rs = $db->Execute('select idbarang, namabarang,jumlahbarang,hargabarang from barang ORDER BY idbarang');
$data = $rs->GetRows();
?>
<p> </p>
<table width="75%" border="1">
<tr>
<td bgcolor="#00cccc"><font color="#000000">No</font></td>
<td bgcolor="#00cccc"><font color="#000000">Id Barang</font></td>
<td bgcolor="#00cccc"><font color="#000000">Nama Barang</font></td>
<td bgcolor="#00cccc"><font color="#000000">Jml Stok</font></td>
<td bgcolor="#00cccc"><font color="#000000">Harga/Item</font></td>
<td bgcolor="#00cccc"><font color="#000000">Action</font></td>
</tr>
<?php $i = 1; ?>
<?php foreach($data as $dt){ ?>
<tr>
<td><?php echo $i ?></td>
<td><?php echo $dt['idbarang']; ?></td>
<td><?php echo $dt['namabarang']; ?></td>
<td><?php echo $dt['jumlahbarang']; ?></td>
<td><?php echo $dt['hargabarang']; ?></td>
<td><a href="edit.php?idbarang=<?php echo $dt['idbarang'];?>">Update</a> | <a href="del.php?idbarang=<?php echo $dt['idbarang'];?>">Delete</a></td>
</tr>
<?php $i++ ; ?>
<?php } ?>
</table>
Transaksi
<h1> Data Transaksi</h1>
<strong>Isikan Kode Pembelian</strong>
<form name="form1" method="post" action="">
Id Barang<br/>
<input type="text" name="idbarang"><br/>
Jml Barang<br/>
<input type="text" name="jumlahbarang"><br/>
<input name="Beli" type="submit" value="Beli">
</form>
<?php
include('adodb/adodb.inc.php');
$databasetype = 'mysql';
$server = 'localhost';
$user = 'root';
$password = '';
$database = 'responsi';
$db = ADONewConnection($databasetype);
$db->debug = false;
$db->Connect($server, $user, $password, $database);
if(isset($_POST['idbarang'])){
$idbarang = $_POST['idbarang'];
$jumlahbarang = $_POST['jumlahbarang'];
$rs = $db->Execute('SELECT jumlahbarang, hargabarang FROM barang where idbarang='.$idbarang);
$data = $rs->GetRows();
$jumlahbaris = $rs->RecordCount();
if ($jumlahbaris == 1) {
foreach($data as $dt){
$stok = $dt['jumlahbarang'];
$hargabarang = $dt['hargabarang'];
}
$hargatotal = $jumlahbarang * $hargabarang;
if (($stok > 0) && ($stok >= $jumlahbarang)) {
$db->Execute("INSERT INTO transaksi (idbarang,jumlahitem,hargatotal)
VALUES('$idbarang','$jumlahbarang','$hargatotal')");
$stok=$stok-$jumlahbarang;
$db->Execute("UPDATE barang SET jumlahbarang = $stok
WHERE idbarang =$idbarang");
}
}
else echo 'Barang Tidak Tersedia';
}
$rs = $db->Execute('SELECT transaksi.idbarang, barang.namabarang, transaksi.jumlahitem, barang.hargabarang, transaksi.hargatotal, barang.jumlahbarang FROM transaksi JOIN barang ON (barang.idbarang = transaksi.idbarang)');
$data = $rs->GetRows();
?>
<p> </p>
<table width="75%" border="1">
<tr>
<td bgcolor="#00ccff"><font color="#000000">No</font></td>
<td bgcolor="#00ccff"><font color="#000000">Id Barang</font></td>
<td bgcolor="#00ccff"><font color="#000000">Nama Barang</font></td>
<td bgcolor="#00ccff"><font color="#000000">Jml Item</font></td>
<td bgcolor="#00ccff"><font color="#000000">Sub Harga</font></td>
<td bgcolor="#00ccff"><font color="#000000">Harga</font></td>
</tr>
<?php $i = 1; ?>
<?php foreach($data as $dt){ ?>
<tr>
<td><?php echo $i ?></td>
<td><?php echo $dt['idbarang']; ?></td>
<td><?php echo $dt['namabarang']; ?></td>
<td><?php echo $dt['jumlahitem']; ?></td>
<td><?php echo $dt['jumlahitem']; ?> X <?php echo $dt['hargabarang']; ?></td>
<td><?php echo $dt['hargatotal'] ?></td>
</tr>
<?php $i++ ; ?>
<?php } ?>
</table>
Delete
<?php
include('adodb/adodb.inc.php');
$databasetype = 'mysql';
$server = 'localhost';
$user = 'root';
$password = '';
$database = 'responsi';
$db = ADONewConnection($databasetype);
$db->debug = false;
$db->Connect($server, $user, $password, $database);
$idbarang = $_GET['idbarang'];
$sql = "delete from barang where idbarang = ' " . $idbarang . " ' " ;
$db->Execute($sql);
echo 'Data Berhasil di Hapus | ';
echo '<a href=StokBarang.php> Lihat Data</a>';
//header("location: StokBarang.php");
?>
Edit
<?php
include('adodb/adodb.inc.php');
$databasetype = 'mysql';
$server = 'localhost';
$user = 'root';
$password = '';
$database = 'responsi';
$db = ADONewConnection($databasetype);
$db->debug = false;
$db->Connect($server, $user, $password, $database);
$idbarang= $_GET['idbarang'];
$rs = $db->Execute('select idbarang, namabarang,jumlahbarang,hargabarang from barang WHERE idbarang='.$idbarang);
$data = $rs->GetRows();
$a = $data[0];
?>
<h1> Edit Data Barang</h1>
<form name="form1" method="post" action="">
Id Barang : <strong><?php echo $a['idbarang']; ?></strong><br/>
Nama Barang<br/>
<input type="text" name="namabarang" value="<?php echo $a['namabarang']; ?>"><br/>
Jml Barang<br/>
<input type="text" name="jumlahbarang" value="<?php echo $a['jumlahbarang']; ?>"><br/>
Harga/Item<br/>
<input type="text" name="hargabarang" value="<?php echo $a['hargabarang']; ?>"><br/>
<input name="Update" type="submit" value="Update">
</form>
<?php
if(isset($_POST['namabarang'])){
$namabarang = $_POST['namabarang'];
$jumlahbarang = $_POST['jumlahbarang'];
$hargabarang = $_POST['hargabarang'];
$db->Execute("UPDATE barang SET namabarang = '".$namabarang."',jumlahbarang = '".$jumlahbarang."',hargabarang = '".$hargabarang."'WHERE idbarang =".$idbarang);
//header("location:StokBarang.php");
}
?>
HalamanDepan
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table width="207" height="124" border="2">
<tr>
<th scope="row"><p><a href=Transaksi.php>Transaksi Penjualan</a></p>
<p> <a href=StokBarang.php>Stok Barang</a></p></th>
</tr>
</table>
</body>
</html>
0 komentar:
Posting Komentar