app.DCReportsTab.java Source code

Java tutorial

Introduction

Here is the source code for app.DCReportsTab.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package app;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.font.TextAttribute;
import java.io.*;
import java.sql.*;
import java.util.*;
import java.util.Date;

import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import ca.odell.glazedlists.GlazedLists;
import ca.odell.glazedlists.swing.AutoCompleteSupport;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.SwingConstants;
import javax.swing.JButton;

/**
 *
 * @author Abby
 */
public class DCReportsTab extends javax.swing.JFrame {

    String msgAD = "Administrator";
    String msgDC = "Documentation Clerk";
    String prevPage;
    private List<String> selectList = new ArrayList<String>();
    private String[] ty = { "Books", "Delivery Receipt", "Outlets", "Purchase Order", "Returns" };
    private JComboBox typeComboBox = new JComboBox(ty);
    private String[] se;
    private String[] ti = { "This Week", "Last 2 Weeks", "This Month", "Last Month", "Last 3 Months" };

    /**
     * Creates new form DCIncompleteDeliveryReceiptsTab
     * @wbp.parser.constructor
     */
    public DCReportsTab(String page) {

        initComponents(msgDC);
        /**if (page.equals("")){
           initComponents(msgDC);
        }
        else if (page.equals("ad")){
           initComponents(msgAD);
        } **/

        this.setExtendedState(MAXIMIZED_BOTH);
        navbarPanel.setAlignmentX(MAXIMIZED_HORIZ);
        prevPage = page;

        Color x = new Color(32, 55, 73);
        this.getContentPane().setBackground(x);

        signOutButton.addMouseListener(new java.awt.event.MouseAdapter() {
            Font originalFont = null;

            public void mouseEntered(java.awt.event.MouseEvent evt) {
                originalFont = signOutButton.getFont();
                Map attributes = originalFont.getAttributes();
                attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
                signOutButton.setFont(originalFont.deriveFont(attributes));
            }

            public void mouseExited(java.awt.event.MouseEvent evt) {
                signOutButton.setFont(originalFont);
            }
        });

        typeComboBox.setSelectedIndex(-1);
        typeComboBox.setEditable(false);
        selectComboBox.setMaximumRowCount(5);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents(String message) {

        logoLabel = new javax.swing.JLabel();
        tablePanel = new javax.swing.JPanel();
        titleLabel1 = new javax.swing.JLabel();
        copyrightLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        deliveryReceiptsTable = new javax.swing.JTable();
        navbarPanel = new javax.swing.JPanel();
        homeButton = new javax.swing.JButton();
        exportButton = new javax.swing.JButton();
        greetingLabel = new javax.swing.JLabel();
        signOutButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Incomplete Delivery Receipts");

        logoLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/VS2.1.png"))); // NOI18N

        tablePanel.setBackground(new java.awt.Color(255, 255, 255));
        tablePanel.setAlignmentX(0.0F);
        tablePanel.setAlignmentY(0.0F);

        titleLabel1.setFont(new Font("Cambria Math", Font.PLAIN, 22)); // NOI18N
        titleLabel1.setForeground(new java.awt.Color(32, 55, 73));
        titleLabel1.setText("REPORT");

        copyrightLabel1.setFont(new java.awt.Font("Calibri", 0, 8)); // NOI18N
        copyrightLabel1.setForeground(new java.awt.Color(32, 55, 73));
        copyrightLabel1
                .setText(" 2016 PSICOM Inventory Mgt. System Powered by VIPE Solutions. All Rights Reserved. ");

        deliveryReceiptsTable.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        deliveryReceiptsTable.setForeground(new java.awt.Color(255, 255, 255));

        deliveryReceiptsTable.setToolTipText("");
        deliveryReceiptsTable.setCellSelectionEnabled(true);
        deliveryReceiptsTable.setGridColor(new java.awt.Color(204, 204, 255));
        deliveryReceiptsTable.setRequestFocusEnabled(false);
        deliveryReceiptsTable.setRowHeight(18);
        deliveryReceiptsTable.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(deliveryReceiptsTable);

        typeComboBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                int typeSelected = typeComboBox.getSelectedIndex();

                if (typeSelected == 0) {

                    getBooksList();
                    se = new String[selectList.size()];
                    selectList.toArray(se);
                    AutoCompleteSupport.install(selectComboBox, GlazedLists.eventListOf(se));
                    typeComboBox.setEnabled(false);
                } else if (typeSelected == 2) {
                    getOutletList();
                    se = new String[selectList.size()];
                    selectList.toArray(se);
                    AutoCompleteSupport.install(selectComboBox, GlazedLists.eventListOf(se));
                    selectComboBox.setMaximumRowCount(5);
                    typeComboBox.setEnabled(false);
                } else if (typeSelected == 1 || typeSelected == 3 || typeSelected == 4) {
                    typeComboBox.setEnabled(false);
                    selectComboBox.setEnabled(false);
                }
            }
        });

        javax.swing.GroupLayout tablePanelLayout = new javax.swing.GroupLayout(tablePanel);
        tablePanelLayout.setHorizontalGroup(tablePanelLayout.createParallelGroup(Alignment.LEADING)
                .addGroup(tablePanelLayout.createSequentialGroup()
                        .addGroup(tablePanelLayout.createParallelGroup(Alignment.LEADING)
                                .addGroup(tablePanelLayout.createSequentialGroup().addGap(18)
                                        .addGroup(tablePanelLayout.createParallelGroup(Alignment.LEADING)
                                                .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 1103,
                                                        GroupLayout.PREFERRED_SIZE)
                                                .addComponent(copyrightLabel1)))
                                .addGroup(tablePanelLayout.createSequentialGroup().addGap(486)
                                        .addComponent(titleLabel1)))
                        .addContainerGap(32, Short.MAX_VALUE)));
        tablePanelLayout.setVerticalGroup(tablePanelLayout.createParallelGroup(Alignment.TRAILING)
                .addGroup(tablePanelLayout.createSequentialGroup().addGap(23).addComponent(titleLabel1).addGap(33)
                        .addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 491, Short.MAX_VALUE)
                        .addPreferredGap(ComponentPlacement.UNRELATED)
                        .addComponent(copyrightLabel1, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
                        .addGap(7)));
        tablePanel.setLayout(tablePanelLayout);

        navbarPanel.setBackground(new java.awt.Color(227, 234, 245));

        homeButton.setBackground(new java.awt.Color(255, 255, 255));
        homeButton.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        homeButton.setForeground(new java.awt.Color(255, 255, 255));
        homeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/button_home.png"))); // NOI18N
        homeButton.setAlignmentY(0.0F);
        homeButton.setBorder(null);
        homeButton.setBorderPainted(false);
        homeButton.setContentAreaFilled(false);
        homeButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        homeButton.setIconTextGap(0);
        homeButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        homeButton.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/images/button_home2.png"))); // NOI18N
        homeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                homeButtonActionPerformed(evt);
            }
        });

        exportButton.setBackground(new java.awt.Color(255, 255, 255));
        exportButton.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        exportButton.setForeground(new java.awt.Color(255, 255, 255));
        exportButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/button_export.png"))); // NOI18N
        exportButton.setAlignmentY(0.0F);
        exportButton.setBorder(null);
        exportButton.setBorderPainted(false);
        exportButton.setContentAreaFilled(false);
        exportButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        exportButton.setIconTextGap(0);
        exportButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        exportButton
                .setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/images/button_export2.png"))); // NOI18N
        exportButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exportButtonActionPerformed(evt);
            }
        });

        JLabel typeLabel = new JLabel("Type:");
        typeLabel.setFont(new Font("Calibri", Font.PLAIN, 15));

        selectLabel = new JLabel("Select:");
        selectLabel.setHorizontalAlignment(SwingConstants.LEFT);
        selectLabel.setFont(new Font("Calibri", Font.PLAIN, 15));

        selectComboBox = new JComboBox();

        lblDate = new JLabel("Timeframe:");
        lblDate.setHorizontalAlignment(SwingConstants.LEFT);
        lblDate.setFont(new Font("Calibri", Font.PLAIN, 15));

        timeComboBox = new JComboBox(ti);

        JButton searchButton = new JButton("Search");
        searchButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int type = typeComboBox.getSelectedIndex();
                String selected = "";
                if (selectComboBox.getSelectedIndex() != -1) {
                    selected = selectComboBox.getSelectedItem().toString();
                }
                int time = timeComboBox.getSelectedIndex();
                displayAll(type, selected, time);

            }
        });

        javax.swing.GroupLayout navbarPanelLayout = new javax.swing.GroupLayout(navbarPanel);
        navbarPanelLayout.setHorizontalGroup(navbarPanelLayout.createParallelGroup(Alignment.TRAILING)
                .addGroup(navbarPanelLayout.createSequentialGroup()
                        .addGroup(navbarPanelLayout.createParallelGroup(Alignment.LEADING)
                                .addGroup(navbarPanelLayout.createSequentialGroup().addContainerGap()
                                        .addGroup(navbarPanelLayout.createParallelGroup(Alignment.LEADING)
                                                .addComponent(homeButton, GroupLayout.DEFAULT_SIZE,
                                                        GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(exportButton, GroupLayout.DEFAULT_SIZE,
                                                        GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                .addGroup(navbarPanelLayout.createSequentialGroup().addGap(23)
                                        .addGroup(navbarPanelLayout.createParallelGroup(Alignment.LEADING, false)
                                                .addComponent(typeLabel)
                                                .addComponent(typeComboBox, GroupLayout.PREFERRED_SIZE, 166,
                                                        GroupLayout.PREFERRED_SIZE)
                                                .addComponent(selectComboBox, GroupLayout.PREFERRED_SIZE, 166,
                                                        GroupLayout.PREFERRED_SIZE)
                                                .addComponent(selectLabel, GroupLayout.PREFERRED_SIZE, 61,
                                                        GroupLayout.PREFERRED_SIZE)))
                                .addGroup(Alignment.TRAILING,
                                        navbarPanelLayout.createSequentialGroup().addGap(23)
                                                .addComponent(lblDate, GroupLayout.PREFERRED_SIZE, 96,
                                                        GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(ComponentPlacement.RELATED, 70, Short.MAX_VALUE))
                                .addGroup(navbarPanelLayout.createSequentialGroup().addGap(23)
                                        .addComponent(timeComboBox, GroupLayout.PREFERRED_SIZE, 166,
                                                GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(ComponentPlacement.RELATED, 10, Short.MAX_VALUE))
                                .addGroup(Alignment.TRAILING,
                                        navbarPanelLayout.createSequentialGroup().addGap(23)
                                                .addComponent(searchButton, GroupLayout.PREFERRED_SIZE, 166,
                                                        GroupLayout.PREFERRED_SIZE)
                                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap()));
        navbarPanelLayout.setVerticalGroup(navbarPanelLayout.createParallelGroup(Alignment.TRAILING)
                .addGroup(navbarPanelLayout.createSequentialGroup().addGap(49).addComponent(typeLabel)
                        .addPreferredGap(ComponentPlacement.RELATED)
                        .addComponent(typeComboBox, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)
                        .addGap(32)
                        .addComponent(selectLabel, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(ComponentPlacement.RELATED)
                        .addComponent(selectComboBox, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)
                        .addGap(34)
                        .addComponent(lblDate, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(ComponentPlacement.RELATED)
                        .addComponent(timeComboBox, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)
                        .addGap(46).addComponent(searchButton)
                        .addPreferredGap(ComponentPlacement.RELATED, 130, Short.MAX_VALUE)
                        .addComponent(exportButton, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(ComponentPlacement.UNRELATED)
                        .addComponent(homeButton, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
                        .addGap(60)));
        navbarPanel.setLayout(navbarPanelLayout);

        greetingLabel.setFont(new java.awt.Font("Calibri", 1, 14)); // NOI18N
        greetingLabel.setForeground(new java.awt.Color(255, 255, 255));
        greetingLabel.setText("Hello, " + message + " | ");

        signOutButton.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        signOutButton.setForeground(new java.awt.Color(255, 255, 255));
        signOutButton.setText("Sign Out");
        signOutButton.setBorder(null);
        signOutButton.setBorderPainted(false);
        signOutButton.setContentAreaFilled(false);
        signOutButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        signOutButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                signOutButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                        .addComponent(tablePanel, GroupLayout.PREFERRED_SIZE, 1153, GroupLayout.PREFERRED_SIZE)
                        .addGap(2).addComponent(navbarPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE))
                .addGroup(layout.createSequentialGroup().addComponent(logoLabel)
                        .addPreferredGap(ComponentPlacement.RELATED, 863, Short.MAX_VALUE)
                        .addComponent(greetingLabel).addPreferredGap(ComponentPlacement.RELATED)
                        .addComponent(signOutButton).addGap(20)));
        layout.setVerticalGroup(layout.createParallelGroup(Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(logoLabel))
                                .addGroup(layout.createSequentialGroup().addGap(25)
                                        .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                                                .addComponent(signOutButton).addComponent(greetingLabel))))
                        .addGap(33)
                        .addGroup(layout.createParallelGroup(Alignment.LEADING)
                                .addComponent(navbarPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE)
                                .addComponent(tablePanel, GroupLayout.PREFERRED_SIZE, 594,
                                        GroupLayout.PREFERRED_SIZE))
                        .addContainerGap()));
        getContentPane().setLayout(layout);

    }// </editor-fold>//GEN-END:initComponents

    private void homeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_homeButtonActionPerformed
        if (prevPage.equals("ad")) {
            this.dispose();
            ADHomeScreen a = new ADHomeScreen();
            a.setVisible(true);
        } else {
            this.dispose();
            DCHomeScreen a = new DCHomeScreen();
            a.setVisible(true);
        }
    }//GEN-LAST:event_homeButtonActionPerformed

    private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed

        //Blank workbook
        XSSFWorkbook workbook = new XSSFWorkbook();

        //Create a blank sheet
        XSSFSheet sheet = workbook.createSheet("Employee Data");

        //This data needs to be written (Object[])
        Map<String, Object[]> data = new TreeMap<String, Object[]>();

        PreparedStatement pst;
        Connection con;

        String drNumber = "";
        String dateToday = "";
        String outlet = "";
        String quantity = "";
        String deliveryDate = "";
        String totalAmount = "";

        TableModel model = deliveryReceiptsTable.getModel(); //Table model
        if (model.getRowCount() != 0) {
            Row row = sheet.createRow(2);

            Row headerRow = sheet.createRow(0); //Create row at line 0
            for (int headings = 0; headings < model.getColumnCount(); headings++) { //For each column
                headerRow.createCell(headings).setCellValue(model.getColumnName(headings));//Write column name
            }

            for (int rows = 0; rows < model.getRowCount(); rows++) { //For each table row
                for (int cols = 0; cols < deliveryReceiptsTable.getColumnCount(); cols++) { //For each table column
                    row.createCell(cols).setCellValue(model.getValueAt(rows, cols).toString()); //Write value
                }

                //Set the row to the next one in the sequence 
                row = sheet.createRow((rows + 3));
            }
            try {
                //Write the workbook in file system
                java.util.Date date = new java.util.Date();
                FileOutputStream out = new FileOutputStream(
                        new File("C:/Users/Jenelle/Desktop/Report" + date.getTime() + ".xlsx"));
                workbook.write(out);
                out.close();
                System.out.println("Written successfully on disk.");
                JOptionPane.showMessageDialog(null, "Export success!", "Success", JOptionPane.PLAIN_MESSAGE);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {

            JOptionPane.showMessageDialog(null, "Please input data to table.", "Error", JOptionPane.ERROR_MESSAGE);
        }

    }//GEN-LAST:event_exportButtonActionPerformed

    private void signOutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_signOutButtonActionPerformed
        if (prevPage.equals("ad")) {
            this.dispose();
            ADLogInScreen a = new ADLogInScreen();
            a.setVisible(true);
        } else {
            this.dispose();
            DCLogInScreen a = new DCLogInScreen();
            a.setVisible(true);
        }
    }//GEN-LAST:event_signOutButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(DCReportsTab.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(DCReportsTab.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(DCReportsTab.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(DCReportsTab.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new DCReportsTab("").setVisible(true);
            }
        });
    }

    private javax.swing.JLabel copyrightLabel1;
    private static javax.swing.JTable deliveryReceiptsTable;
    private javax.swing.JButton exportButton;
    private javax.swing.JLabel greetingLabel;
    private javax.swing.JButton homeButton;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel logoLabel;
    private javax.swing.JPanel navbarPanel;
    private javax.swing.JButton signOutButton;
    private javax.swing.JPanel tablePanel;
    private javax.swing.JLabel titleLabel1;
    private JLabel selectLabel;
    private JComboBox selectComboBox;
    private JLabel lblDate;
    private JComboBox timeComboBox;
    // End of variables declaration//GEN-END:variables

    public void displayAll(int type1, String selected1, int time1) {
        DefaultTableModel model = new DefaultTableModel() {
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };

        String selectStatement = "";
        String whereAndStatement = "";
        String whereTimeStatement = "";
        String fromStatement = "";
        String[] columnNames = null;
        if (type1 == 0) {
            columnNames = new String[] { "DATE", "DR NUMBER", "ITEM CODE", "TITLE", "PRICE", "QUANTITY", "OUTLET" };
            selectStatement = "date_today,  item_code, title,  price, specific_dr.quantity, outlet, delivery_receipt_number";
            whereAndStatement = "item_code=book_id AND delivery_receipt_number=dr_id AND title = '" + selected1
                    + "'";
            fromStatement = "psicomims.specific_dr, psicomims.delivery_receipt, psicomims.book";

        }

        if (type1 == 1) {
            columnNames = new String[] { "DATE", "NUMBER", "TITLE", "DR NUMBER", "OUTLET", "SRP", "ITEM CODE",
                    "QUANTITY", "SALES PRICE", "AMOUNT" };
            selectStatement = "date_today,  specific_dr.id,  title,  delivery_receipt_number, outlet, price, item_code, specific_dr.quantity, total_amount";
            whereAndStatement = "item_code=book_id AND delivery_receipt_number=dr_id";
            fromStatement = "psicomims.specific_dr, psicomims.delivery_receipt, psicomims.book";

        }

        model.setColumnIdentifiers(columnNames);
        if (time1 == 0) {
            whereTimeStatement = "date_today BETWEEN DATE_ADD(CURDATE(), INTERVAL 1-DAYOFWEEK(CURDATE()) DAY) AND DATE_ADD(CURDATE(), INTERVAL 7-DAYOFWEEK(CURDATE()) DAY)";
        }

        PreparedStatement pst;
        Connection con;

        String drNumber = "";
        String dateToday = "";
        String outlet = "";
        String quantity = "";
        String title = "";
        String itemCode = "";
        String price = "";

        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/psicomims", "root", "root");
            pst = con.prepareStatement("SELECT " + selectStatement + " FROM " + fromStatement + " WHERE "
                    + whereTimeStatement + " AND " + whereAndStatement + " ORDER BY date_today ASC");
            ResultSet rs = pst.executeQuery();

            int i = 0;
            while (rs.next()) {
                drNumber = rs.getString("delivery_receipt_number");
                dateToday = rs.getString("date_today");
                title = rs.getString("title");
                itemCode = rs.getString("item_code");
                outlet = rs.getString("outlet");
                quantity = rs.getString("quantity");
                price = rs.getString("price");
                model.addRow(new Object[] { dateToday, drNumber, itemCode, title, price, quantity, outlet });
                i++;
            }

            if (i < 1) {
                JOptionPane.showMessageDialog(null, "No Record Found", "Error", JOptionPane.ERROR_MESSAGE);
            }

            if (i == 1) {
                System.out.println(i + " Record Found");
            }

            else {
                System.out.println(i + " Records Found");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        deliveryReceiptsTable.setModel(model);
        deliveryReceiptsTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
        deliveryReceiptsTable.setForeground(Color.BLACK);
    }

    public void getOutletList() {
        PreparedStatement pst;
        Connection con;

        try {

            Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/psicomims", "root", "root");
            pst = (PreparedStatement) con.prepareStatement("SELECT outlet_name FROM outlet");
            ResultSet rs = pst.executeQuery();
            Set<String> outletSet = new HashSet();
            while (rs.next()) {
                if (!rs.getString("outlet_name").equals(null)) {
                    outletSet.add(rs.getString("outlet_name"));
                }
            }
            selectList = new ArrayList();
            selectList.addAll(outletSet);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public void getBooksList() {
        PreparedStatement pst;
        Connection con;

        try {

            Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/psicomims", "root", "root");
            pst = (PreparedStatement) con.prepareStatement("SELECT title FROM book");
            ResultSet rs = pst.executeQuery();
            Set<String> outletSet = new HashSet();
            while (rs.next()) {
                if (!rs.getString("title").equals(null)) {
                    outletSet.add(rs.getString("title"));
                }
            }
            selectList.addAll(outletSet);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}