Create a Sales Form / POS – Tutorial Build Point Of Sale With PHP, PDO, MySQL And Jquery Part 5

How to create a sales transactions page with PHP, jquery, and adminLTE. We have been at the end of the tutorial create a point of sale system with PHP. This article was the initial goal of the tutorial create a point of sale with PHP and AdminLTE. In this article, I will discuss how to create a simple sales page. In addition, the complete source of this project will share on this part. Let’s follow the tutorial

For those of you who don’t follow the tutorial from the first, please read them in advance every part via the following URL links.

Sales form is used to manage sales transactions. Every sale transaction done will reduce stock items and print struck sales. This module is still very simple because it is only used as a learning process.

Tutorial Create a sales page with PHP, PDO, jquery and adminLTE

Database Preparation

Add 3 new tables in “pos” database: t_sale, t_sale_detail, temp_sale. To create 3 tables above please see the structure of the table in the following image:

Pos Structure Table

A little explanation of the table:

t_sale is used to store primary data on sales transactions. Table t_sale_detail to store details of items that are on sale transaction with the certain transaction code. And the temp_sale table is used to store temporary of detail items, and the data in the temp_sale will be deleted when the transaction is successfully saved and or at the beginning of login, all of the temp_sale data on the user will be emptied.

Please create 3 new store procedure: saveSale, deleteSale, restore_stock_sale

saveSale

saveSale store procedure is used to store transactions into the database.

deleteSale

deleteSale store procedure is used to remove sales transactions from the database. The sales transaction is not deleted with DELETE MySQL function but only UPDATE MySQL by changing the sts field to 0. Because in Information system security, a transaction history is very important.

restore_stock_sale

restore_stock_sale store procedure is used to restore stock items as they were when sales transactions were removed.

In this section, we will add 4 new files in the sales folder (pos/application/sales/) and edit the pos.php file to add a list of MySQL queries in the sales table. Copy the following code on each file

autocomplete_item.php

v_pos.php

Display the front end of the sales menu as shown below.

Point Of Sale With Php Front End Tutorial Create Pos Php

j_pos.js

c_pos.php

And add the following code in the pos.php file

Up to this point, the tutorial how to create a point of sale system with PHP, PDO, jquery and adminLTE has been completed. A brief explanation on the sales transaction page:

To add an item to the shopping cart grid, we use the jquery UI autocomplete. By typing the item name or item code in the text box field, jquery will display a list of items like the following picture

Autocomplete Item On Point Of Sale System Tutorial Build Point Of Sale In Php Pdo Jquery And Adminlte

Jquery ajax will call autocomplete function in autocomplete_item.php file

To add the number of items, the user can click on the item qty section and will display the modal dialog to change qty.

If the user selects the same item in the autocomplete box, it will automatically add qty item to the grid.

Add Item In Shoping Cart Grid Tutorial Pos With Php

process payment button will display the transaction payment modal dialog like the following picture:

Point Of Sale Layout Template

After the transaction has been processed, jquery will execute the redirect script to display the sales receipt on the new browser tab (in PDF format). For the tutorial create sales receipt with PDF, I will discuss in the bonus article

Javascript redirect is useful to replace form element in HTML. This script is very useful for me to send data using POST method without creating form element in HTML.

DONE!! The tutorial point of sale system with PHP has been completed. In accordance with my promise from the beginning, you can download the complete source code of this project on the download link below:

I hope this article is helpful for all of us. If you feel helped by this article, Please give me a donation or a gift. To keep me excited about creating articles. ;p

Bonus article php tutorial how to create pdf receipt note with fpdf php library

Thus tutorial about How To Create a Sales Form / POS – Tutorial Build Point Of Sale With PHP, PDO, MySQL And Jquery Part 5

The following two tabs change content below.
This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

18 Comments

 Add your comment
  1. Hi,
    I find this tutorial very interesting.
    Can you share the bonus article to create the PDF file.
    Thanks and best regards,
    Greg

  2. Hi,
    This is a very great concept for learning CRUD. The problem is I’m more familiar with mysqli (I have never done a project in mysqli) and I’m finding it really hard to convert or rewrite the whole module in mysqli (from PDO). Could there by any chance you have done one with mysqli and share. I will really appreciate it if I get to learn more.
    I hope to hear from you soon.

  3. I think that’s the only available way. I, however have a couple of questions. I am trying to rewrite the pos codes using mysqli but I’m getting errors.

    1. How do I keep the session for the uniquid active for a particular sale, mine keeps on changing every time a product is saved in the temp_sale table.

    2. About method getdata: Once I have written my query

    , I fetch the results and try to loop one record after another. I get an error Invalid argument supplied for foreach().

    The following is the full code snippet:

    3. Still on getting data method, I don’t see you calling the item_name, what’s the magic? 😉

    4. While inserting or selecting record, I get confused on the part about encoding using json. For instance, after selecting sum of subtotal, I wanted to store it in $result[‘subtotal’]=(int)$row[‘total’]; Am I correct by doing that?

    5. In pdo, I see that you have used both fetchall and fetch assoc in the same line. What’s the equivalent of mysqli for that?

    6. On the success callback of json, how do we know what array index of the argument data to call? I’m asking specifically for $data.subtotal.

    7. Lastly, I’m getting the error – DataTables warning: table id=table_transaction – Invalid JSON response – what I’m I missing out?

    • Dear Hagler,

      Thank you for contacting me :), I will try to help you as much as I can

      1. In the example application I applied, I did not provide an example of how to hold a transaction on a temporary table for a particular sale. If you want to save certain transactions on the temporary table, please create a new table to store the transaction you want to hold. temp_sale table is only used to store transaction details on the POS menu display

      2. Try checking your mysql query using command

      See the error 🙂

      3. isn’t magic, see the code

      the item_name in the t.*

      4. I do not understand the question number 4 🙂
      5. Learn mysqli fetch all here https://www.w3schools.com/php/func_mysqli_fetch_all.asp
      6. To cheack callback of json, please push F12 to the browser and find the Network tab and find url callback from your json and push the response tab. follow the image below https://seegatesite.com/json-response/
      7. Please follow the answer number 6 to know your mysql error from response tab 🙂

      Hope my English can be understood 🙂

      Thank you for asking me 🙂

  4. Dear Sigit,

    Many thanks for getting back to me. Your English is ok, I got every sentence that you typed. Don’t mind about question 4, I did some research and found out that I was doing it the wrong way.

    I was able to handle much of the questions but 2. I still don’t get it how you are able to keep the uniqid for a particular sales detail and have another uniqid for another sale. In your code, I see that you defined the session such that every time a user logs in, it is created. I however did not see how it changes when make another sale. Does it get destroyed after a sale and we get redirected?

    Another thing that still gets on my nerve is the fact that I get an error after doing an autocomplete search and a product details gets saved in the temp sale table, my dataTable does not display the details. It gives me the following error: DataTables warning: table id=table_transaction – Invalid JSON response

    • I was able to handle much of the questions but 2. I still don’t get it how you are able to keep the uniqid for a particular sales detail and have another uniqid for another sale. In your code, I see that you defined the session such that every time a user logs in, it is created. I however did not see how it changes when make another sale. Does it get destroyed after a sale and we get redirected?

      Each user has a unique code to define their sales details. Each time a sales transaction is completed, the system will delete / resubmit the sales details in the temp_sale table for that user based on that unique code

      Another thing that still gets on my nerve is the fact that I get an error after doing an autocomplete search and a product details gets saved in the temp sale table, my dataTable does not display the details. It gives me the following error: DataTables warning: table id=table_transaction – Invalid JSON response

      Usually the error is caused by mysql query. To see the error you have to check through the network tab like the image I have given to you 🙂

      null

  5. Hi Sigit,
    First of all thank you very much for sharing such a great article. Sigit, i have observed that you have skipped some of the DB scripts or table etc ? because when i try to execute a sale transaction with sample data i get following error:
    “Syntax error or access violation: 1305 PROCEDURE pos.saveSale does not exist”,”xsale_id”:null}”

    waiting for your prompt response. Thanks

    • Hii cloud,

      your error is “Syntax error or access violation: 1305 PROCEDURE pos.saveSale does not exist”,”xsale_id”:null}”

      you skipped saveSale store procedure in your database, please check again the above article, I have written the saveSale the store procedure 🙂

  6. Hi
    Nice and good tutorial but i didn’t see about nota_jual.php file. Can you please list that also

  7. Thank you for your prompt reply where is this nota_tempo.php file

Leave a Comment

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.