jotart
Application Environment Manager
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
200 XP
In this tutorial we will show you how to create a Simple Ordering System with Cash as Method of Payment and Receipt Report. This simple system is created for ordering and adding a product. Every product that the admin created will be added to the system, and every product that the customer had been ordered has a discount. The system can also generate a receipt. This system is composed of PHP/MySQL, Bootstrap Framework and PDO Extension.
Sample Code
Sales.php - This script is for creating an order to the customer.
Product.php - And this is for the list of products and adding a product.
Preview.php - And this is for generating a report.
And the script for printing the report.
Hope that you learn in this tutorial. And for more updates and programming tutorials don't hesitate to ask and we will answer your questions and suggestions. Don't forget to LIKE & SHARE this website.
Download
Sample Code
Sales.php - This script is for creating an order to the customer.
- <h2 align="center">Simple Ordering System with Cash as Method of Payment and Receipt Report</h2><hr>
- <form action="incoming.php" method="post" align="right">
- <input type="hidden" name="pt" value="<?php
echo
$_GET
[
'id'
]
;
?>
" />
- <input type="hidden" name="invoice" value="<?php
echo
$_GET
[
'invoice'
]
;
?>
" />
- <select name="product" style="width: 300px; height: 36px;">
- <?php
- include
(
'../connect.php'
)
;
- $result
=
$db
->
prepare
(
"SELECT * FROM products"
)
;
- $result
->
bindParam
(
':userid'
,
$res
)
;
- $result
->
execute
(
)
;
- for
(
$i
=
0
;
$row
=
$result
->
fetch
(
)
;
$i
++
)
{
- ?>
- <option value="<?php
echo
$row
[
'product_code'
]
;
?>
"><?php
echo
$row
[
'product_name'
]
;
?>
</option>
- <?php
- }
- ?>
- </select>
- <input type="text" name="qty" value="" placeholder="Quantity" autocomplete="off" style="width: 68px; padding-top: 6px; padding-bottom: 6px; margin-right: 4px;" />
- <input type="text" name="discount" value="" placeholder="Discount" autocomplete="off" style="width: 68px; padding-top: 6px; padding-bottom: 6px; margin-right: 4px;" />
- <input type="submit" class="btn btn-primary" value="Save" />
- </form>
- <table id="resultTable" data-responsive="table" class="table table-hover">
- <thead>
- <tr>
- <th> Product Code </th>
- <th> Product Name </th>
- <th> Qty </th>
- <th> Price </th>
- <th> Discount </th>
- <th> Amount </th>
- <th> Action </th>
- </tr>
- </thead>
- <tbody>
- <?php
- $id
=
$_GET
[
'invoice'
]
;
- include
(
'../connect.php'
)
;
- $result
=
$db
->
prepare
(
"SELECT * FROM sales_order WHERE invoice= :userid"
)
;
- $result
->
bindParam
(
':userid'
,
$id
)
;
- $result
->
execute
(
)
;
- for
(
$i
=
0
;
$row
=
$result
->
fetch
(
)
;
$i
++
)
{
- ?>
- <tr class="record">
- <td><?php
echo
$row
[
'product'
]
;
?>
</td>
- <td><?php
echo
$row
[
'name'
]
;
?>
</td>
- <td><?php
echo
$row
[
'qty'
]
;
?>
</td>
- <td>
- <?php
- $ppp
=
$row
[
'price'
]
;
- echo
formatMoney(
$ppp
,
true
)
;
- ?>
- </td>
- <td>
- <?php
- $ddd
=
$row
[
'discount'
]
;
- echo
formatMoney(
$ddd
,
true
)
;
- ?>
- </td>
- <td>
- <?php
- $dfdf
=
$row
[
'amount'
]
;
- echo
formatMoney(
$dfdf
,
true
)
;
- ?>
- </td>
- <td><a href="delete.php?id=<?php
echo
$row
[
'transaction_id'
]
;
?>
&invoice=<?php
echo
$_GET
[
'invoice'
]
;
?>
&dle=<?php
echo
$_GET
[
'id'
]
;
?>
&qty=<?php
echo
$row
[
'qty'
]
;
?>
&code=<?php
echo
$row
[
'product'
]
;
?>
" class="btn btn-primary">Delete</a></td>
- </tr>
- <?php
- }
- ?>
- <tr>
- <td colspan="5"><strong style="font-size: 20px; color: #222222;">Total:</strong></td>
- <td colspan="2"><strong style="font-size: 20px; color: #222222; background-color: bisque;">
- <?php
- function
formatMoney(
$number
,
$fractional
=
false
)
{
- if
(
$fractional
)
{
- $number
=
sprintf
(
'%.2f'
,
$number
)
;
- }
- while
(
true
)
{
- $replaced
=
preg_replace
(
'/(-?\d+)(\d\d\d)/'
,
'$1,$2'
,
$number
)
;
- if
(
$replaced
!=
$number
)
{
- $number
=
$replaced
;
- }
else
{
- break
;
- }
- }
- return
$number
;
- }
- $sdsd
=
$_GET
[
'invoice'
]
;
- $resultas
=
$db
->
prepare
(
"SELECT sum(amount) FROM sales_order WHERE invoice= :a"
)
;
- $resultas
->
bindParam
(
':a'
,
$sdsd
)
;
- $resultas
->
execute
(
)
;
- for
(
$i
=
0
;
$rowas
=
$resultas
->
fetch
(
)
;
$i
++
)
{
- $fgfg
=
$rowas
[
'sum(amount)'
]
;
- echo
formatMoney(
$fgfg
,
true
)
;
- }
- ?>
- </strong></td>
- </tr>
- </tbody>
- </table><br>
- <a rel="facebox" id="cccc" href="checkout.php?pt=<?php
echo
$_GET
[
'id'
]
?>
&invoice=<?php
echo
$_GET
[
'invoice'
]
?>
&total=<?php
echo
$fgfg
?>
&cashier=<?php
echo
$_SESSION
[
'SESS_FIRST_NAME'
]
?>
" class="btn btn-primary">Check Out</a>
Product.php - And this is for the list of products and adding a product.
- <h2 align="center">Simple Ordering System with Cash as Method of Payment and Receipt Report</h2><hr>
- <form align="right">
- <input type="text" name="filter" value="" id="filter" placeholder="Search Product..." autocomplete="off" style="width: 250px; padding-top: 6px; padding-bottom: 6px; margin-right: 4px;"/><a rel="facebox" id="addd" href="addproduct.php" class="btn btn-primary">Add Product</a><br><br>
- </form>
- <table id="resultTable" data-responsive="table" class="table table-hover">
- <thead>
- <tr>
- <th> Code </th>
- <th> Name </th>
- <th> Cost </th>
- <th> Price </th>
- <th> Qty </th>
- <th> Action </th>
- </tr>
- </thead>
- <tbody>
- <?php
- function
formatMoney(
$number
,
$fractional
=
false
)
{
- if
(
$fractional
)
{
- $number
=
sprintf
(
'%.2f'
,
$number
)
;
- }
- while
(
true
)
{
- $replaced
=
preg_replace
(
'/(-?\d+)(\d\d\d)/'
,
'$1,$2'
,
$number
)
;
- if
(
$replaced
!=
$number
)
{
- $number
=
$replaced
;
- }
else
{
- break
;
- }
- }
- return
$number
;
- }
- include
(
'../connect.php'
)
;
- $result
=
$db
->
prepare
(
"SELECT * FROM products ORDER BY product_id DESC"
)
;
- $result
->
execute
(
)
;
- for
(
$i
=
0
;
$row
=
$result
->
fetch
(
)
;
$i
++
)
{
- ?>
- <tr class="record">
- <td><?php
echo
$row
[
'product_code'
]
;
?>
</td>
- <td><?php
echo
$row
[
'product_name'
]
;
?>
</td>
- <td><?php
- $pcost
=
$row
[
'cost'
]
;
- echo
formatMoney(
$pcost
,
true
)
;
- ?>
</td>
- <td><?php
- $pprice
=
$row
[
'price'
]
;
- echo
formatMoney(
$pprice
,
true
)
;
- ?>
</td>
- <td><?php
echo
$row
[
'qty'
]
;
?>
</td>
- <td><a rel="facebox" href="editproduct.php?id=<?php
echo
$row
[
'product_id'
]
;
?>
" class="btn btn-primary">Edit</a> <a href="#" id="<?php
echo
$row
[
'product_id'
]
;
?>
" class="delbutton" title="Click To Delete" style="margin-bottom: 0;border-radius: 4px;border: 1px solid transparent;padding: 6px 12px;display: inline-block;color: #fff; background-color: #337ab7; border-color: #2e6da4;">Delete</a></td>
- </tr>
- <?php
- }
- ?>
- </tbody>
- </table>
- </div>
- <script type="text/javascript">
- $(function() {
- $(".delbutton").click(function(){
- var element = $(this);
- var del_id = element.attr("id");
- var info = 'id=' + del_id;
- if(confirm("Are you sure do you want to delete this product? There is no Undo."))
- {
- $.ajax({
- type: "GET",
- url: "deleteproduct.php",
- data: info,
- success: function(){
- }
- });
- $(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast")
- .animate({ opacity: "hide" }, "slow");
- }
- return false;
- });
- });
- </script>

Preview.php - And this is for generating a report.
- <?php
- $id
=
$_GET
[
'invoice'
]
;
- $result
=
$db
->
prepare
(
"SELECT * FROM sales_order WHERE invoice= :userid"
)
;
- $result
->
bindParam
(
':userid'
,
$id
)
;
- $result
->
execute
(
)
;
- for
(
$i
=
0
;
$row
=
$result
->
fetch
(
)
;
$i
++
)
{
- ?>
- <tr class="record">
- <td><?php
echo
$row
[
'product'
]
;
?>
</td>
- <td><?php
echo
$row
[
'name'
]
;
?>
</td>
- <td><?php
echo
$row
[
'qty'
]
;
?>
</td>
- <td>
- <?php
- $ppp
=
$row
[
'price'
]
;
- echo
formatMoney(
$ppp
,
true
)
;
- ?>
- </td>
- <td>
- <?php
- $ddd
=
$row
[
'discount'
]
;
- echo
formatMoney(
$ddd
,
true
)
;
- ?>
- </td>
- <td>
- <?php
- $dfdf
=
$row
[
'amount'
]
;
- echo
formatMoney(
$dfdf
,
true
)
;
- ?>
- </td>
- </tr>
- <?php
- }
- ?>
- <tr>
- <td colspan="5"><strong style="font-size: 12px; color: #222222;">Total:</strong></td>
- <td colspan="2"><strong style="font-size: 12px; color: #222222;">
- <?php
- $sdsd
=
$_GET
[
'invoice'
]
;
- $resultas
=
$db
->
prepare
(
"SELECT sum(amount) FROM sales_order WHERE invoice= :a"
)
;
- $resultas
->
bindParam
(
':a'
,
$sdsd
)
;
- $resultas
->
execute
(
)
;
- for
(
$i
=
0
;
$rowas
=
$resultas
->
fetch
(
)
;
$i
++
)
{
- $fgfg
=
$rowas
[
'sum(amount)'
]
;
- echo
formatMoney(
$fgfg
,
true
)
;
- }
- ?>
- </strong></td>
- </tr>
- <?php
if
(
$pt
==
'cash'
)
{
- ?>
- <tr>
- <td colspan="5"><strong style="font-size: 12px; color: #222222;">Cash Tendered:</strong></td>
- <td colspan="2"><strong style="font-size: 12px; color: #222222;">
- <?php
- echo
formatMoney(
$cash
,
true
)
;
- ?>
- </strong></td>
- </tr>
- <?php
- }
- ?>
- <tr>
- <td colspan="5"><strong style="font-size: 12px; color: #222222;">
- <?php
- if
(
$pt
==
'cash'
)
{
- echo
'Change:'
;
- }
- ?>
- </strong></td>
- <td colspan="2"><strong style="font-size: 12px; color: #222222;">
- <?php
- function
formatMoney(
$number
,
$fractional
=
false
)
{
- if
(
$fractional
)
{
- $number
=
sprintf
(
'%.2f'
,
$number
)
;
- }
- while
(
true
)
{
- $replaced
=
preg_replace
(
'/(-?\d+)(\d\d\d)/'
,
'$1,$2'
,
$number
)
;
- if
(
$replaced
!=
$number
)
{
- $number
=
$replaced
;
- }
else
{
- break
;
- }
- }
- return
$number
;
- }
- if
(
$pt
==
'credit'
)
{
- echo
$cash
;
- }
- if
(
$pt
==
'cash'
)
{
- echo
formatMoney(
$amount
,
true
)
;
- }
- ?>
And the script for printing the report.
- <script language
=
"javascript"
>
- function
Clickheretoprint(
)
- {
- var
disp_setting=
"toolbar=yes,location=no,directories=yes,menubar=yes,"
;
- disp_setting+=
"scrollbars=yes,width=800, height=400, left=100, top=25"
;
- var
content_vlue =
document.
getElementById(
"content"
)
.
innerHTML;
- var
docprint=
window.
open(
""
,
""
,
disp_setting)
;
- docprint.
document.
open(
)
;
- docprint.
document.
write(
'</head><body onLoad="self.print()" style="width: 800px; font-size: 13px; font-family: arial;">'
)
;
- docprint.
document.
write(
content_vlue)
;
- docprint.
document.
close(
)
;
- docprint.
focus(
)
;
- }
- </script>
- <
div align=
"center"
>
- <
a href=
"javascript:Clickheretoprint()"
style=
"font-size:12px"
class
=
"btn btn-primary"
;>
Print</
a>
<
a href=
"index.php"
style=
"font-size:12px"
class
=
"btn btn-primary"
;>
Back</
a>
- </
div>
Hope that you learn in this tutorial. And for more updates and programming tutorials don't hesitate to ask and we will answer your questions and suggestions. Don't forget to LIKE & SHARE this website.
Download
You must upgrade your account or reply in the thread to view the hidden content.