private void placeNewOrderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_placeNewOrderButtonActionPerformed
        // TODO add your handling code here:
        // When place order button is pushed
        
        // Check if subtotal and totals have been changed 
        if (!"£0.00".equals(subTotLabel.getText()) && !"£0.00".equals(totalLabel.getText()))
        {
            // if subtotal and total fields have been updated - place order
             ArrayList<String[]> suppliers = new ArrayList<>();
                
            for (int x = 0; x < orderTable.getRowCount(); x++ )
            {
                if (orderTable.getValueAt(x, 5) != null) {
                String[] orderInfo = {orderTable.getValueAt(x, 5).toString(),orderTable.getValueAt(x, 0).toString(),orderTable.getValueAt(x, 4).toString()};
                suppliers.add(orderInfo);
                //showMessageDialog(null, orderLines.get(x)); - DEBUG
                }
            
            }
        
               
            Comparator<String[]> arrayCompare = new Comparator<String[]>() {
            public int compare(String[] first, String[] second) {
                return first[0].compareTo(second[0]);
            }
        };
        
        suppliers.sort(arrayCompare);
       
       int currentOrder = -1;
       String lastSupplier = "";
       Helper.openConnection();
       for (String[] supply: suppliers)
       {
           // create order if needed
           if(!supply[0].equals(lastSupplier) )
           {
               
               String query = "insert into torder Values(default,now(),'Raised','" + loginID + "',(select supplier_id from tsupplier where name ='" + supply[0] + "'),'')";
               Helper.updateDatabase(query);
               String selectQuery = "select last_insert_id()";
               ResultSet rs = Helper.selectFromDatabase(selectQuery);
               try
               {
                    while (rs.next())
                    {
                        currentOrder = rs.getInt(1);
                    }
               }
               catch (Exception ex)
               {
                   
               }
               
           }
           //set current supplier to last supplier
           lastSupplier = supply[0];
           
           //Insert orderline
           String query = "insert into torder_line Values (" + currentOrder + ",'" + supply[1] + "'," + Integer.parseInt(supply[2]) + ")";
           Helper.updateDatabase(query);
           
           
           
       }
       Helper.closeConnection();
        showMessageDialog(null, "New Order Created.");
        // return to and update notifications 
       //Clear order form
            // Create defaultTableModel object
            DefaultTableModel dm = (DefaultTableModel)orderTable.getModel();
            // Clear displayed table of contents
            dm.getDataVector().removeAllElements();
        
            // set row count back to 100
            dm.setRowCount(100); 
            // Update table
            dm.fireTableDataChanged();
            
            // clear results table
            //Create an empty string to query database so all products are displayed when order form is reopened
            //open connection to database
            Helper.openConnection();
            String value = "";
            ResultSet rs = Helper.searchAllByKey(value);
            // populate results table to show search results
            Helper.populateTable(resultsTable, rs); 
            // close connection to database
            Helper.closeConnection();
            
            // clear search field
            orderSearchText.setText("");
            
            // Return user to the notifications screen.
            newOrderPanel.setVisible(false);
            pendingOrderPanel.setVisible(false);
            reportPanel.setVisible(false);
            searchProductPanel.setVisible(false);
            notificationPanel.setVisible(true);
            adminPanel.setVisible(false);
            passwordPanel.setVisible(false);
            updateNotifications();       
        }
        // else advise user that they need to add an item to order before it can be placed.
        else 
        {
            showMessageDialog(null, "You must add a product to the order before placing the order!");
        }
        
        
        
        
    }//GEN-LAST:event_placeNewOrderButtonActionPerformed