• We just launched and are currently in beta. Join us as we build and grow the community.

Simple Ordering System with Cash as Method of Payment and Receipt Report

jotart

Application Environment Manager
J Rep
0
0
0
Rep
0
J Vouches
0
0
0
Vouches
0
Posts
162
Likes
135
Bits
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.

  1. <h2 align="center">Simple Ordering System with Cash as Method of Payment and Receipt Report</h2><hr>
  2. <form action="incoming.php" method="post" align="right">
  3. <input type="hidden" name="pt" value="<?php

    echo

    $_GET

    [

    'id'

    ]

    ;

    ?>

    " />
  4. <input type="hidden" name="invoice" value="<?php

    echo

    $_GET

    [

    'invoice'

    ]

    ;

    ?>

    " />
  5. <select name="product" style="width: 300px; height: 36px;">
  6. <?php
  7. include

    (

    '../connect.php'

    )

    ;
  8. $result

    =

    $db

    ->

    prepare

    (

    "SELECT * FROM products"

    )

    ;
  9. $result

    ->

    bindParam

    (

    ':userid'

    ,

    $res

    )

    ;
  10. $result

    ->

    execute

    (

    )

    ;
  11. for

    (

    $i

    =

    0

    ;

    $row

    =

    $result

    ->

    fetch

    (

    )

    ;

    $i

    ++

    )

    {
  12. ?>
  13. <option value="<?php

    echo

    $row

    [

    'product_code'

    ]

    ;

    ?>

    "><?php

    echo

    $row

    [

    'product_name'

    ]

    ;

    ?>

    </option>
  14. <?php
  15. }
  16. ?>
  17. </select>
  18. <input type="text" name="qty" value="" placeholder="Quantity" autocomplete="off" style="width: 68px; padding-top: 6px; padding-bottom: 6px; margin-right: 4px;" />
  19. <input type="text" name="discount" value="" placeholder="Discount" autocomplete="off" style="width: 68px; padding-top: 6px; padding-bottom: 6px; margin-right: 4px;" />
  20. <input type="submit" class="btn btn-primary" value="Save" />
  21. </form>
  22. <table id="resultTable" data-responsive="table" class="table table-hover">
  23. <thead>
  24. <tr>
  25. <th> Product Code </th>
  26. <th> Product Name </th>
  27. <th> Qty </th>
  28. <th> Price </th>
  29. <th> Discount </th>
  30. <th> Amount </th>
  31. <th> Action </th>
  32. </tr>
  33. </thead>
  34. <tbody>
  35. <?php
  36. $id

    =

    $_GET

    [

    'invoice'

    ]

    ;
  37. include

    (

    '../connect.php'

    )

    ;
  38. $result

    =

    $db

    ->

    prepare

    (

    "SELECT * FROM sales_order WHERE invoice= :userid"

    )

    ;
  39. $result

    ->

    bindParam

    (

    ':userid'

    ,

    $id

    )

    ;
  40. $result

    ->

    execute

    (

    )

    ;
  41. for

    (

    $i

    =

    0

    ;

    $row

    =

    $result

    ->

    fetch

    (

    )

    ;

    $i

    ++

    )

    {
  42. ?>
  43. <tr class="record">
  44. <td><?php

    echo

    $row

    [

    'product'

    ]

    ;

    ?>

    </td>
  45. <td><?php

    echo

    $row

    [

    'name'

    ]

    ;

    ?>

    </td>
  46. <td><?php

    echo

    $row

    [

    'qty'

    ]

    ;

    ?>

    </td>
  47. <td>
  48. <?php
  49. $ppp

    =

    $row

    [

    'price'

    ]

    ;
  50. echo

    formatMoney(

    $ppp

    ,

    true

    )

    ;
  51. ?>
  52. </td>
  53. <td>
  54. <?php
  55. $ddd

    =

    $row

    [

    'discount'

    ]

    ;
  56. echo

    formatMoney(

    $ddd

    ,

    true

    )

    ;
  57. ?>
  58. </td>
  59. <td>
  60. <?php
  61. $dfdf

    =

    $row

    [

    'amount'

    ]

    ;
  62. echo

    formatMoney(

    $dfdf

    ,

    true

    )

    ;
  63. ?>
  64. </td>
  65. <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>
  66. </tr>
  67. <?php
  68. }
  69. ?>
  70. <tr>
  71. <td colspan="5"><strong style="font-size: 20px; color: #222222;">Total:</strong></td>
  72. <td colspan="2"><strong style="font-size: 20px; color: #222222; background-color: bisque;">
  73. <?php
  74. function

    formatMoney(

    $number

    ,

    $fractional

    =

    false

    )

    {
  75. if

    (

    $fractional

    )

    {
  76. $number

    =

    sprintf

    (

    '%.2f'

    ,

    $number

    )

    ;
  77. }
  78. while

    (

    true

    )

    {
  79. $replaced

    =

    preg_replace

    (

    '/(-?\d+)(\d\d\d)/'

    ,

    '$1,$2'

    ,

    $number

    )

    ;
  80. if

    (

    $replaced

    !=

    $number

    )

    {
  81. $number

    =

    $replaced

    ;
  82. }

    else

    {
  83. break

    ;
  84. }
  85. }
  86. return

    $number

    ;
  87. }
  88. $sdsd

    =

    $_GET

    [

    'invoice'

    ]

    ;
  89. $resultas

    =

    $db

    ->

    prepare

    (

    "SELECT sum(amount) FROM sales_order WHERE invoice= :a"

    )

    ;
  90. $resultas

    ->

    bindParam

    (

    ':a'

    ,

    $sdsd

    )

    ;
  91. $resultas

    ->

    execute

    (

    )

    ;
  92. for

    (

    $i

    =

    0

    ;

    $rowas

    =

    $resultas

    ->

    fetch

    (

    )

    ;

    $i

    ++

    )

    {
  93. $fgfg

    =

    $rowas

    [

    'sum(amount)'

    ]

    ;
  94. echo

    formatMoney(

    $fgfg

    ,

    true

    )

    ;
  95. }
  96. ?>
  97. </strong></td>
  98. </tr>
  99. </tbody>
  100. </table><br>
  101. <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.

  1. <h2 align="center">Simple Ordering System with Cash as Method of Payment and Receipt Report</h2><hr>
  2. <form align="right">
  3. <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>
  4. </form>
  5. <table id="resultTable" data-responsive="table" class="table table-hover">
  6. <thead>
  7. <tr>
  8. <th> Code </th>
  9. <th> Name </th>
  10. <th> Cost </th>
  11. <th> Price </th>
  12. <th> Qty </th>
  13. <th> Action </th>
  14. </tr>
  15. </thead>
  16. <tbody>
  17. <?php
  18. function

    formatMoney(

    $number

    ,

    $fractional

    =

    false

    )

    {
  19. if

    (

    $fractional

    )

    {
  20. $number

    =

    sprintf

    (

    '%.2f'

    ,

    $number

    )

    ;
  21. }
  22. while

    (

    true

    )

    {
  23. $replaced

    =

    preg_replace

    (

    '/(-?\d+)(\d\d\d)/'

    ,

    '$1,$2'

    ,

    $number

    )

    ;
  24. if

    (

    $replaced

    !=

    $number

    )

    {
  25. $number

    =

    $replaced

    ;
  26. }

    else

    {
  27. break

    ;
  28. }
  29. }
  30. return

    $number

    ;
  31. }
  32. include

    (

    '../connect.php'

    )

    ;
  33. $result

    =

    $db

    ->

    prepare

    (

    "SELECT * FROM products ORDER BY product_id DESC"

    )

    ;
  34. $result

    ->

    execute

    (

    )

    ;
  35. for

    (

    $i

    =

    0

    ;

    $row

    =

    $result

    ->

    fetch

    (

    )

    ;

    $i

    ++

    )

    {
  36. ?>
  37. <tr class="record">
  38. <td><?php

    echo

    $row

    [

    'product_code'

    ]

    ;

    ?>

    </td>
  39. <td><?php

    echo

    $row

    [

    'product_name'

    ]

    ;

    ?>

    </td>
  40. <td><?php
  41. $pcost

    =

    $row

    [

    'cost'

    ]

    ;
  42. echo

    formatMoney(

    $pcost

    ,

    true

    )

    ;
  43. ?>

    </td>
  44. <td><?php
  45. $pprice

    =

    $row

    [

    'price'

    ]

    ;
  46. echo

    formatMoney(

    $pprice

    ,

    true

    )

    ;
  47. ?>

    </td>
  48. <td><?php

    echo

    $row

    [

    'qty'

    ]

    ;

    ?>

    </td>
  49. <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>
  50. </tr>
  51. <?php
  52. }
  53. ?>
  54. </tbody>
  55. </table>
  56. </div>
  57. <script type="text/javascript">
  58. $(function() {
  59. $(".delbutton").click(function(){
  60. var element = $(this);
  61. var del_id = element.attr("id");
  62. var info = 'id=' + del_id;
  63. if(confirm("Are you sure do you want to delete this product? There is no Undo."))
  64. {
  65. $.ajax({
  66. type: "GET",
  67. url: "deleteproduct.php",
  68. data: info,
  69. success: function(){
  70. }
  71. });
  72. $(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast")
  73. .animate({ opacity: "hide" }, "slow");
  74. }
  75. return false;
  76. });
  77. });
  78. </script>

2016-12-13_14_55_49-localhost_december_13_invent_main_sales.php_idcashinvoiceprod-078202.png

Preview.php - And this is for generating a report.

  1. <?php
  2. $id

    =

    $_GET

    [

    'invoice'

    ]

    ;
  3. $result

    =

    $db

    ->

    prepare

    (

    "SELECT * FROM sales_order WHERE invoice= :userid"

    )

    ;
  4. $result

    ->

    bindParam

    (

    ':userid'

    ,

    $id

    )

    ;
  5. $result

    ->

    execute

    (

    )

    ;
  6. for

    (

    $i

    =

    0

    ;

    $row

    =

    $result

    ->

    fetch

    (

    )

    ;

    $i

    ++

    )

    {
  7. ?>
  8. <tr class="record">
  9. <td><?php

    echo

    $row

    [

    'product'

    ]

    ;

    ?>

    </td>
  10. <td><?php

    echo

    $row

    [

    'name'

    ]

    ;

    ?>

    </td>
  11. <td><?php

    echo

    $row

    [

    'qty'

    ]

    ;

    ?>

    </td>
  12. <td>
  13. <?php
  14. $ppp

    =

    $row

    [

    'price'

    ]

    ;
  15. echo

    formatMoney(

    $ppp

    ,

    true

    )

    ;
  16. ?>
  17. </td>
  18. <td>
  19. <?php
  20. $ddd

    =

    $row

    [

    'discount'

    ]

    ;
  21. echo

    formatMoney(

    $ddd

    ,

    true

    )

    ;
  22. ?>
  23. </td>
  24. <td>
  25. <?php
  26. $dfdf

    =

    $row

    [

    'amount'

    ]

    ;
  27. echo

    formatMoney(

    $dfdf

    ,

    true

    )

    ;
  28. ?>
  29. </td>
  30. </tr>
  31. <?php
  32. }
  33. ?>
  34. <tr>
  35. <td colspan="5"><strong style="font-size: 12px; color: #222222;">Total:</strong></td>
  36. <td colspan="2"><strong style="font-size: 12px; color: #222222;">
  37. <?php
  38. $sdsd

    =

    $_GET

    [

    'invoice'

    ]

    ;
  39. $resultas

    =

    $db

    ->

    prepare

    (

    "SELECT sum(amount) FROM sales_order WHERE invoice= :a"

    )

    ;
  40. $resultas

    ->

    bindParam

    (

    ':a'

    ,

    $sdsd

    )

    ;
  41. $resultas

    ->

    execute

    (

    )

    ;
  42. for

    (

    $i

    =

    0

    ;

    $rowas

    =

    $resultas

    ->

    fetch

    (

    )

    ;

    $i

    ++

    )

    {
  43. $fgfg

    =

    $rowas

    [

    'sum(amount)'

    ]

    ;
  44. echo

    formatMoney(

    $fgfg

    ,

    true

    )

    ;
  45. }
  46. ?>
  47. </strong></td>
  48. </tr>
  49. <?php

    if

    (

    $pt

    ==

    'cash'

    )

    {
  50. ?>
  51. <tr>
  52. <td colspan="5"><strong style="font-size: 12px; color: #222222;">Cash Tendered:</strong></td>
  53. <td colspan="2"><strong style="font-size: 12px; color: #222222;">
  54. <?php
  55. echo

    formatMoney(

    $cash

    ,

    true

    )

    ;
  56. ?>
  57. </strong></td>
  58. </tr>
  59. <?php
  60. }
  61. ?>
  62. <tr>
  63. <td colspan="5"><strong style="font-size: 12px; color: #222222;">
  64. <?php
  65. if

    (

    $pt

    ==

    'cash'

    )

    {
  66. echo

    'Change:'

    ;
  67. }
  68. ?>
  69. </strong></td>
  70. <td colspan="2"><strong style="font-size: 12px; color: #222222;">
  71. <?php
  72. function

    formatMoney(

    $number

    ,

    $fractional

    =

    false

    )

    {
  73. if

    (

    $fractional

    )

    {
  74. $number

    =

    sprintf

    (

    '%.2f'

    ,

    $number

    )

    ;
  75. }
  76. while

    (

    true

    )

    {
  77. $replaced

    =

    preg_replace

    (

    '/(-?\d+)(\d\d\d)/'

    ,

    '$1,$2'

    ,

    $number

    )

    ;
  78. if

    (

    $replaced

    !=

    $number

    )

    {
  79. $number

    =

    $replaced

    ;
  80. }

    else

    {
  81. break

    ;
  82. }
  83. }
  84. return

    $number

    ;
  85. }
  86. if

    (

    $pt

    ==

    'credit'

    )

    {
  87. echo

    $cash

    ;
  88. }
  89. if

    (

    $pt

    ==

    'cash'

    )

    {
  90. echo

    formatMoney(

    $amount

    ,

    true

    )

    ;
  91. }
  92. ?>

And the script for printing the report.
  1. <script language

    =

    "javascript"

    >
  2. function

    Clickheretoprint(

    )
  3. {
  4. var

    disp_setting=

    "toolbar=yes,location=no,directories=yes,menubar=yes,"

    ;
  5. disp_setting+=

    "scrollbars=yes,width=800, height=400, left=100, top=25"

    ;
  6. var

    content_vlue =

    document.

    getElementById(

    "content"

    )

    .

    innerHTML;
  7. var

    docprint=

    window.

    open(

    ""

    ,

    ""

    ,

    disp_setting)

    ;
  8. docprint.

    document.

    open(

    )

    ;
  9. docprint.

    document.

    write(

    '</head><body onLoad="self.print()" style="width: 800px; font-size: 13px; font-family: arial;">'

    )

    ;
  10. docprint.

    document.

    write(

    content_vlue)

    ;
  11. docprint.

    document.

    close(

    )

    ;
  12. docprint.

    focus(

    )

    ;
  13. }
  14. </script>
  15. <

    div align=

    "center"

    >
  16. <

    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>
  17. </

    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.
 

452,496

335,402

335,410

Top