Program Kasir Sederhana Php
Program Kasir Sederhana Php - sebenarnya kalau untuk membuat program kasir, kita tidak usah menggunakan bahasa php, soalnya php itu untuk web, dikhususkan ke web. bagusan pake java atau c++. Namun, kali ini kita membuatnya untuk tujuan pembelajaran, bukan yang lain, jadi ga pa pa la.Pada program ini tidak menggunakan session, jadi dari kasirUtama.php bisa langsung loncat ke kasir2.php nanti kita akan update programnya yang menggunakan session setelah kita buat artikel mengenai session
Program Kasir Sederhana PHP
#Tampilan
header.html:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Belajar Php</title>
<link rel="stylesheet" type="text/css" href="style.css" /> <!Memanggil style css>
</head>
<body>
<div id="sampul"> <!div id= membuat class css dengan nama header>
<div id="header">
<center><h2>Belajar PHP</h2></center>
<div id="linkHeader">
<h4><a href="index.php">Beranda</a></h4>
</div>
</div>
<div id="body">
<div id="SidebarKiri">
</div>
<div id="isi">
</body>
</html>
footer.html:
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
<body>
</div>
<div id="SidebarKanan">
</div>
</div>
<div id="footer">
<h2>Java Kita</h2>
</div>
</div>
</body>
</html>
style.css:
/*
Document : style
Created on : Sep 13, 2013, 3:27:50 PM
Author : Razaq
Description:
Purpose of the stylesheet follows.
*/
body{
background-color: #999999;
margin: 0px;
padding: 0px;
}
#sampul{ /*membuat class sampul di css */
margin: auto;
width: 900px;
clear: both; /*berhubungan dengan posisi text pada isi nanti */
text-align: center;
/*kita gunakan sampul supaya semuanya otomatis di tengah*/
}
#header{
height: 197px;
background-color: #0066ff;
padding: 20px;
text-align: left;
}
#linkHeader{
margin-top: 140px;
margin-left: 0;
text-align: left;
}
#body{
background-color: #cc0099;
clear: both;
display: table-row;
}
#SidebarKiri{
float: left;
width: 200px;
margin:0;
padding:10px;
border: 0;
clear: both;
background-color: #cc0099;
}
#isi{
float: left;
width: 440px;
margin:0;
padding:10px;
border: 0;
background-color: #cc00cc;
text-align: justify;
}
#SidebarKanan{
float: right;
width: 200px;
margin:0;
padding:10px;
border: 0;
background-color: #cc0099;
}
#footer{
height: 120px;
border: 0;
clear:both;
background-color: #9900cc;
padding: 20px;
}
#Program
kasirUtama.php:
<?php
session_start();
include 'header.html';
?>
<center><h2>Program Kasir</h2></center>
<br/>
<h3>Menu Makanan</h3>
<ol>
<li>Nasi Padang + Ayam</li>
<li>Nasi Padang + Telur</li>
<li>Nasi Padang + Ikan</li>
</ol>
<br/>
<form method="POST">
<table>
<tr>
<td>Pilih Menu Makanan Nomer: </td>
<td><input type="text" name="makanan" size="15" /></td>
</tr>
<tr>
<td>Banyak Porsi : </td>
<td><input type="text" name="porsi" size="15" /></td>
</tr>
<tr>
<td><input type="submit" name="proses" value="Proses" /></td>
</tr>
</table>
</form>
<?php
if(isset($_POST['proses'])){
$NoMakanan = isset($_POST['makanan'])? $_POST['makanan']:NULL;
$porsi = isset($_POST['porsi'])? $_POST['porsi']:NULL;
if(empty($NoMakanan) || empty($porsi)){
include 'footer.html';
echo "<script>alert('Maaf, Cek kembali pilihan makanan Anda ! ');</script>";
return;
}
if($NoMakanan == 1){
$hargaMakan = '12000';
$totalMakan = $hargaMakan*$porsi;
$makan = 'Nasi Ayam';
}else if($NoMakanan == 2){
$hargaMakan = '8000';
$totalMakan = $hargaMakan*$porsi;
$makan = 'Nasi Telur';
}else if($NoMakanan == 3){
$hargaMakan = '10000';
$totalMakan = $hargaMakan*$porsi;
$makan = 'Nasi Ikan';
}else{
include 'footer.html';
echo "<script>alert('Maaf, Cek kembali pilihan makanan Anda ! ');</script>";
return;
}
$_SESSION['makan'] = $makan;
$_SESSION['totalMakan'] = $totalMakan;
$_SESSION['hargaMakan'] = $hargaMakan;
$_SESSION['porsiMakan'] = $porsi;
echo"<script>document.location='kasir2.php'</script>";
}
?>
<?php
include 'footer.html';
?>
kasir2.php:
<?php
session_start();
include 'header.html';
?>
<center><h2>Program Kasir</h2></center>
<br/>
<h3>Menu Minuman</h3>
<ol>
<li>Teh Anget/ Dingin</li>
<li>Kopi</li>
<li>Jus jeruk </li>
<li>Jus advokat</li>
</ol>
<br/>
<form method="POST">
<table>
<tr>
<td>Pilih Menu Minuman Nomer: </td>
<td><input type="text" name="minuman" size="15" /></td>
</tr>
<tr>
<td>Banyak Porsi : </td>
<td><input type="text" name="porsi" size="15" /></td>
</tr>
<tr>
<td><input type="submit" name="proses" value="Proses" /></td>
</tr>
</table>
</form>
<?php
if(isset($_POST['proses'])){
$NoMinuman = isset($_POST['minuman'])? $_POST['minuman']:NULL;
$porsi = isset($_POST['porsi'])? $_POST['porsi']:NULL;
if(empty($NoMinuman) || empty($porsi)){
include 'footer.html';
echo "<script>alert('Maaf, Cek kembali pilihan minuman Anda ! ');</script>";
return;
}
if($NoMinuman == 1){
$hargaMinum = '3000';
$totalMinum = $hargaMinum*$porsi;
$minum = 'teh';
}else if($NoMinuman == 2){
$hargaMinum= '4000';
$totalMinum = $hargaMinum*$porsi;
$minum = 'kopi';
}else if($NoMinuman == 3){
$hargaMinum = '8000';
$totalMinum = $hargaMinum*$porsi;
$minum = 'Jus jeruk';
}else if($NoMinuman == 4){
$hargaMinum = '10000';
$totalMinum = $hargaMinum*$porsi;
$minum = 'Jus Advokat';
}else{
include 'footer.html';
echo "<script>alert('Maaf, Cek kembali pilihan minuman Anda ! ');</script>";
return;
}
$_SESSION['totalMinum'] = $totalMinum;
$_SESSION['minum'] = $minum;
$_SESSION['hargaMinum'] = $hargaMinum;
$_SESSION['porsiMinum'] = $porsi;
echo"<script>document.location='kasir3.php'</script>";
}
?>
<?php
include 'footer.html';
?>
session_start();
include 'header.html';
?>
<center><h2>Program Kasir</h2></center>
<br/>
<h3>Menu Minuman</h3>
<ol>
<li>Teh Anget/ Dingin</li>
<li>Kopi</li>
<li>Jus jeruk </li>
<li>Jus advokat</li>
</ol>
<br/>
<form method="POST">
<table>
<tr>
<td>Pilih Menu Minuman Nomer: </td>
<td><input type="text" name="minuman" size="15" /></td>
</tr>
<tr>
<td>Banyak Porsi : </td>
<td><input type="text" name="porsi" size="15" /></td>
</tr>
<tr>
<td><input type="submit" name="proses" value="Proses" /></td>
</tr>
</table>
</form>
<?php
if(isset($_POST['proses'])){
$NoMinuman = isset($_POST['minuman'])? $_POST['minuman']:NULL;
$porsi = isset($_POST['porsi'])? $_POST['porsi']:NULL;
if(empty($NoMinuman) || empty($porsi)){
include 'footer.html';
echo "<script>alert('Maaf, Cek kembali pilihan minuman Anda ! ');</script>";
return;
}
if($NoMinuman == 1){
$hargaMinum = '3000';
$totalMinum = $hargaMinum*$porsi;
$minum = 'teh';
}else if($NoMinuman == 2){
$hargaMinum= '4000';
$totalMinum = $hargaMinum*$porsi;
$minum = 'kopi';
}else if($NoMinuman == 3){
$hargaMinum = '8000';
$totalMinum = $hargaMinum*$porsi;
$minum = 'Jus jeruk';
}else if($NoMinuman == 4){
$hargaMinum = '10000';
$totalMinum = $hargaMinum*$porsi;
$minum = 'Jus Advokat';
}else{
include 'footer.html';
echo "<script>alert('Maaf, Cek kembali pilihan minuman Anda ! ');</script>";
return;
}
$_SESSION['totalMinum'] = $totalMinum;
$_SESSION['minum'] = $minum;
$_SESSION['hargaMinum'] = $hargaMinum;
$_SESSION['porsiMinum'] = $porsi;
echo"<script>document.location='kasir3.php'</script>";
}
?>
<?php
include 'footer.html';
?>
kasir3.php:
<?php
session_start();
include 'header.html';
?>
<center><h2>Program Kasir</h2></center>
<?php
$totalmakan = $_SESSION['totalMakan'];
$totalminum = $_SESSION['totalMinum'];
$makan = $_SESSION['makan'];
$minum = $_SESSION['minum'];
$porsiMakan = $_SESSION['porsiMakan'];
$porsiMinum = $_SESSION['porsiMinum'];
$total = $totalmakan + $totalminum;
echo '<h4>Total semuanya = Rp. ' . $total . "</h4>";
?>
<form method='post'>
<table>
<tr>
<td>Bayar: </td>
<td><input type='text'size='15' name ='bayar' /></td>
<td><input type='submit' name='proses' value='Proses' /></td>
</tr>
</table>
</form>
<?php
if (isset($_POST['proses'])) {
$bayar = isset($_POST['bayar']) ? $_POST['bayar'] : NULL;
$kembalian = $bayar - $total;
if ($bayar < $total) {
echo '<h3>Maaf, Uang anda tidak cukup ' . $kembalian . '</h3>';
include'footer.html';
return;
}
echo '<h2> Rincian </h2>';
echo '~ Makanan: '.$makan.' x '.$porsiMakan.' = Rp. '.$totalmakan.'<br/>';
echo '~ Minuman: '.$minum.' x '.$porsiMinum.' = Rp. '.$totalminum.'<br/>';
echo '~ Total = Rp. '.$total.'<br/><br/>';
echo 'Bayar = Rp. '.$bayar.'<br/>';
echo 'Kembalian = Rp. '.$kembalian.'<br/>';
echo '<center><h4>Terimakasih</h4></center><br/>';
echo '<center><a href="kasirUtama.php">Klik untuk kembali ke menu utama !</a></center>';
}
?>
<?php
include 'footer.html';
?>
session_start();
include 'header.html';
?>
<center><h2>Program Kasir</h2></center>
<?php
$totalmakan = $_SESSION['totalMakan'];
$totalminum = $_SESSION['totalMinum'];
$makan = $_SESSION['makan'];
$minum = $_SESSION['minum'];
$porsiMakan = $_SESSION['porsiMakan'];
$porsiMinum = $_SESSION['porsiMinum'];
$total = $totalmakan + $totalminum;
echo '<h4>Total semuanya = Rp. ' . $total . "</h4>";
?>
<form method='post'>
<table>
<tr>
<td>Bayar: </td>
<td><input type='text'size='15' name ='bayar' /></td>
<td><input type='submit' name='proses' value='Proses' /></td>
</tr>
</table>
</form>
<?php
if (isset($_POST['proses'])) {
$bayar = isset($_POST['bayar']) ? $_POST['bayar'] : NULL;
$kembalian = $bayar - $total;
if ($bayar < $total) {
echo '<h3>Maaf, Uang anda tidak cukup ' . $kembalian . '</h3>';
include'footer.html';
return;
}
echo '<h2> Rincian </h2>';
echo '~ Makanan: '.$makan.' x '.$porsiMakan.' = Rp. '.$totalmakan.'<br/>';
echo '~ Minuman: '.$minum.' x '.$porsiMinum.' = Rp. '.$totalminum.'<br/>';
echo '~ Total = Rp. '.$total.'<br/><br/>';
echo 'Bayar = Rp. '.$bayar.'<br/>';
echo 'Kembalian = Rp. '.$kembalian.'<br/>';
echo '<center><h4>Terimakasih</h4></center><br/>';
echo '<center><a href="kasirUtama.php">Klik untuk kembali ke menu utama !</a></center>';
}
?>
<?php
include 'footer.html';
?>
Output
Sipp... Semoga bermanfaat