Home Java Pizza Ordering System in Java with Print Receipt

Pizza Ordering System in Java with Print Receipt

9 min read
0
1
7,681

The Pizza Ordering System Inventory Management System is developed using Java and mysql.java best practice is must if you interested in java. The project is built to manage sales and transactions. To make a new transaction, fields such as: Pizza type, qty,price and payment needs to be selected. If you like to learn point of sales systems step by step, this is the right place to learn from the beginning.

In this tutorial, you will learn  jasper reports step by step and designing the java print receipt.java coding practices is very important  for us to grow the knowledge in java day by day.how to be a good programmer in the future. Let go and learn the java mini projects step by step.i have attached the complete project video also how the flow works step by step below.

In order to create the system we have used NetBeans IDE and Mysql database as a backend.

Features of the Project

  • Point of Sales
  • Stock Management
  • Java Receipt

Learn how to make this System Step by step

Step 1: Create the database named with “pizza“. then established the database connection to download the mysql connector in order to connect Java & mysql. if you don’t you  have an idea about download the mysql connector you can follow this link.

To connect the database please refer the following code. To create the method name connect (); paste the below code inside the Connect () method.

DefaultTableModel model;
String item;
int price;
Connection con;
PreparedStatement pst;
PreparedStatement pst1;
public void Connect()
    {
        try {
            Class.forName("com.mysql.jdbc.Driver"); // Register the mysql driver
            con = DriverManager.getConnection("jdbc:mysql://localhost/pizza","root","");    
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (SQLException ex) {
           ex.printStackTrace();
        }
    }

The system shall be able to select the relevant Pizza type.

Add the Product details into the JTable

After selected the  relavent pizza type the user has the option to add the qty by clicking the add button to see all Products details which will be shown in the below table.

Paste this code inside the add button

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        if(lblsmall.isSelected() == true)
        {
            item = "Small";
            price = 200;
 
        }
        else if(lblmed.isSelected() == true)
        {
            item = "Medium";
            price = 300;
 
        }
           else if(lbllarge.isSelected() == true)
        {
            item = "Large";
            price = 400;
 
        }
         else if(lblexlarge.isSelected() == true)
        {
            item = "ExLarge";
            price = 700;
 
        }
        
        int qty = Integer.parseInt(txtqty.getValue().toString());
        int tot = qty * price;
        
        model = (DefaultTableModel)jTable1.getModel();
        
        model.addRow(new Object[]
                
        {
            item,
            price,
            qty,
            tot
            
        });
        int sum = 0;
        
        for(int a=0; a<jTable1.getRowCount(); a++)
        {
            sum = sum + Integer.parseInt(jTable1.getValueAt(a, 3).toString()); 
        }
        txttotal.setText(Integer.toString(sum)); 
        
}

Calculating the Total and balance

After that  create the method Sales().we have to create two different tables to store data into the database.we also have to create the following tables from database.
sales tables consist of following colums – id,subtotal,pay,balance.
sales_products tables consist of following colums –id,sales_id,prodname,price,qty,total

    public void sales()
    {
        int lastid =0;
        try {
            String total = txttotal.getText();
            String bal = txtbal.getText();
            String pay = txtpay.getText(); 
            String query = "insert into sales(subtotal,pay,bal)values(?,?,?)";
            pst = con.prepareStatement(query,Statement.RETURN_GENERATED_KEYS);
            pst.setString(1, total);
            pst.setString(2, pay); 
             pst.setString(3, bal);
             pst.executeUpdate();
             ResultSet rs = pst.getGeneratedKeys();
            
            if(rs.next())
            {
                lastid = rs.getInt(1);
            }
            int row = jTable1.getRowCount();
            String query1 = "insert into sales_product(sales_id,prodname,price,qty,total)values(?,?,?,?,?)";
            pst1 = con.prepareStatement(query1);
            
            String prodname = "";
            int price;
            int qty;
            int tot = 0;

            for(int i=0; i<jTable1.getRowCount(); i++)
                    {
                        prodname = (String)jTable1.getValueAt(i, 0);
                         price = (int)jTable1.getValueAt(i, 1);
                         qty = (int)jTable1.getValueAt(i, 2);
                         tot = (int)jTable1.getValueAt(i, 3);
                         
                         pst1.setInt(1,lastid);
                          pst1.setString(2,prodname);
                          pst1.setInt(3,price);
                          pst1.setInt(4,qty);
                          pst1.setInt(5,tot);
                          pst1.executeUpdate();
                        
                    }
            
            JOptionPane.showMessageDialog(this, "Saless Completeeeeddddddd");
            HashMap a = new HashMap();
            a.put("invo", lastid);

            try {
                JasperDesign jdesign = JRXmlLoader.load("C:\\Users\\kobinath\\Documents\\NetBeansProjects\\Pizza\\src\\Pizza\\report1.jrxml");
                JasperReport jreport = JasperCompileManager.compileReport(jdesign);
                
                JasperPrint jprint = JasperFillManager.fillReport(jreport, a, con);
                JasperViewer.viewReport(jprint);

            } catch (JRException ex) {
                Logger.getLogger(pizza.class.getName()).log(Level.SEVERE, null, ex);
            }

        } catch (SQLException ex) {
            Logger.getLogger(pizza.class.getName()).log(Level.SEVERE, null, ex);
        }   
        
    }

Call the Sales() method inside the Print Invoice button. after calculating the total Print receipt will be released. This print receipt is design by Jsper Reporting.

Paste this code inside the Print Invoice button

 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        
        int tot = Integer.parseInt(txttotal.getText());
        int pay = Integer.parseInt(txtpay.getText());
        
        int bal = pay - tot;
        
        txtbal.setText(String.valueOf(bal));
        
        
        sales();
        
        
    }

if you want remove items from the jtable. select the row of table which item wants to. then click delete button

Remove Button

Paste this code inside the remove button

  private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        model.removeRow(jTable1.getSelectedRow());
         int sum = 0;
         for(int a=0; a<jTable1.getRowCount(); a++)
        {
            
            sum = sum + Integer.parseInt(jTable1.getValueAt(a, 3).toString());
            
        }
        txttotal.setText(Integer.toString(sum));
        
    }

Print Recipt

I have attached the video tutorial below it will help you  to do this  step by step.java projects with source codes will help you to learn java.

 

 

 

 

 

Load More Related Articles
Load More By admin
Load More In Java

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also

Employee Working Hours Calculation System using C#.net

Initialize the employee number, Hourswork,and Hoursrate to calculate a grosswage use the f…