Reporting Functionality - fixed generic reports
authorHarishankar <v.harishankar@gmail.com>
Thu, 2 Apr 2020 08:56:14 +0000 (14:26 +0530)
committerHarishankar <v.harishankar@gmail.com>
Thu, 2 Apr 2020 08:56:14 +0000 (14:26 +0530)
Fixed the functionality for report viewing for generic reports, rather
than a single report.

src/habeas/Habeas.java
src/habeas/MainFrame.form
src/habeas/MainFrame.java
src/habeas/ManageNoticesDialog.java
src/habeas/NoticesReportViewDialog.java
src/habeas/Utility.java

index 6c24189..2bfb038 100644 (file)
@@ -25,7 +25,7 @@ public class Habeas {
         Utility.retrieveStationerySettings();
         
         try {
         Utility.retrieveStationerySettings();
         
         try {
-            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
         } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
             Logger.getLogger(Habeas.class.getName()).log(Level.SEVERE, null, ex);
         }
         } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
             Logger.getLogger(Habeas.class.getName()).log(Level.SEVERE, null, ex);
         }
index d251e2f..3328dce 100644 (file)
                     <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="menuAwaitingPaymentActionPerformed"/>
                   </Events>
                 </MenuItem>
                     <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="menuAwaitingPaymentActionPerformed"/>
                   </Events>
                 </MenuItem>
+                <MenuItem class="javax.swing.JMenuItem" name="menuNoticesSentNotYetDelivered">
+                  <Properties>
+                    <Property name="mnemonic" type="int" value="115"/>
+                    <Property name="text" type="java.lang.String" value="Notices sent not yet delivered..."/>
+                  </Properties>
+                  <Events>
+                    <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="menuNoticesSentNotYetDeliveredActionPerformed"/>
+                  </Events>
+                </MenuItem>
               </SubComponents>
             </Menu>
           </SubComponents>
               </SubComponents>
             </Menu>
           </SubComponents>
index ec3ce33..3ff0418 100644 (file)
@@ -6,10 +6,7 @@
 package habeas;
 
 import java.util.ArrayList;
 package habeas;
 
 import java.util.ArrayList;
-import javax.swing.JFileChooser;
 import javax.swing.JOptionPane;
 import javax.swing.JOptionPane;
-import javax.swing.filechooser.FileFilter;
-import javax.swing.filechooser.FileNameExtensionFilter;
 
 /**
  *
 
 /**
  *
@@ -43,6 +40,7 @@ public class MainFrame extends javax.swing.JFrame {
         menuGenerateRaisedBills = new javax.swing.JMenuItem();
         menuNoticesReports = new javax.swing.JMenu();
         menuAwaitingPayment = new javax.swing.JMenuItem();
         menuGenerateRaisedBills = new javax.swing.JMenuItem();
         menuNoticesReports = new javax.swing.JMenu();
         menuAwaitingPayment = new javax.swing.JMenuItem();
+        menuNoticesSentNotYetDelivered = new javax.swing.JMenuItem();
         menuSettings = new javax.swing.JMenu();
         menuDatabaseSettings = new javax.swing.JMenuItem();
         menuStationery = new javax.swing.JMenuItem();
         menuSettings = new javax.swing.JMenu();
         menuDatabaseSettings = new javax.swing.JMenuItem();
         menuStationery = new javax.swing.JMenuItem();
@@ -108,6 +106,15 @@ public class MainFrame extends javax.swing.JFrame {
         });
         menuNoticesReports.add(menuAwaitingPayment);
 
         });
         menuNoticesReports.add(menuAwaitingPayment);
 
+        menuNoticesSentNotYetDelivered.setMnemonic('s');
+        menuNoticesSentNotYetDelivered.setText("Notices sent not yet delivered...");
+        menuNoticesSentNotYetDelivered.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                menuNoticesSentNotYetDeliveredActionPerformed(evt);
+            }
+        });
+        menuNoticesReports.add(menuNoticesSentNotYetDelivered);
+
         menuLawyerNotices.add(menuNoticesReports);
 
         jMenuBar1.add(menuLawyerNotices);
         menuLawyerNotices.add(menuNoticesReports);
 
         jMenuBar1.add(menuLawyerNotices);
@@ -192,16 +199,32 @@ public class MainFrame extends javax.swing.JFrame {
         // TODO add your handling code here:
         NoticesReportViewDialog frm = new NoticesReportViewDialog(this, false);
         String [] cols = {"Reference Number", "Description", "Bill Date", "Bill Amount", "Client"};
         // TODO add your handling code here:
         NoticesReportViewDialog frm = new NoticesReportViewDialog(this, false);
         String [] cols = {"Reference Number", "Description", "Bill Date", "Bill Amount", "Client"};
-        ArrayList<Object> data = Utility.getPendingPaymentBills (-1);
+        int rep = 0;
+        ArrayList<Object> data = Utility.getReportData(rep, -1);
         if (data == null) {
             JOptionPane.showMessageDialog(this, ERROR_DISPLAYING_REPORT);
             return;
         }
         if (data == null) {
             JOptionPane.showMessageDialog(this, ERROR_DISPLAYING_REPORT);
             return;
         }
-        frm.setupReportTable(REPORT_TITLE_BILLS_AWAITING_PAYMENT, cols, data);
+        frm.setupReportTable(rep, REPORT_TITLE_BILLS_AWAITING_PAYMENT, cols, data);
         frm.setVisible(true);
     }//GEN-LAST:event_menuAwaitingPaymentActionPerformed
         frm.setVisible(true);
     }//GEN-LAST:event_menuAwaitingPaymentActionPerformed
-    private static final String ERROR_DISPLAYING_REPORT = "Error displaying report";
-    private static final String REPORT_TITLE_BILLS_AWAITING_PAYMENT = "Bills Awaiting Payment";
+
+    private void menuNoticesSentNotYetDeliveredActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuNoticesSentNotYetDeliveredActionPerformed
+        // TODO add your handling code here:
+        NoticesReportViewDialog frm = new NoticesReportViewDialog(this, false);
+        String[] cols = {"Reference Number", "Description", "Sent Date", "RPAD Reference", "Client"};
+        int rep = 1;
+        ArrayList<Object> data = Utility.getReportData (rep, -1);
+        if (data == null) {
+            JOptionPane.showMessageDialog(this, ERROR_DISPLAYING_REPORT);
+            return;
+        }
+        frm.setupReportTable(rep, REPORT_TITLE_NOTICES_SENT_NOT_DELIVERED, cols, data);
+        frm.setVisible (true);
+    }//GEN-LAST:event_menuNoticesSentNotYetDeliveredActionPerformed
+    public static final String REPORT_TITLE_NOTICES_SENT_NOT_DELIVERED = "Notices Sent Not Yet Delivered";
+    public static final String ERROR_DISPLAYING_REPORT = "Error displaying report";
+    public static final String REPORT_TITLE_BILLS_AWAITING_PAYMENT = "Bills Awaiting Payment";
 
     /**
      * @param args the command line arguments
 
     /**
      * @param args the command line arguments
@@ -250,6 +273,7 @@ public class MainFrame extends javax.swing.JFrame {
     private javax.swing.JMenuItem menuManageNotices;
     private javax.swing.JMenu menuMaster;
     private javax.swing.JMenu menuNoticesReports;
     private javax.swing.JMenuItem menuManageNotices;
     private javax.swing.JMenu menuMaster;
     private javax.swing.JMenu menuNoticesReports;
+    private javax.swing.JMenuItem menuNoticesSentNotYetDelivered;
     private javax.swing.JMenu menuSettings;
     private javax.swing.JMenuItem menuStationery;
     // End of variables declaration//GEN-END:variables
     private javax.swing.JMenu menuSettings;
     private javax.swing.JMenuItem menuStationery;
     // End of variables declaration//GEN-END:variables
index 6a0bba7..67f0a06 100644 (file)
@@ -6,8 +6,6 @@
 package habeas;
 
 import java.awt.Frame;
 package habeas;
 
 import java.awt.Frame;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
 import java.util.ArrayList;
 import java.util.Date;
 import javax.swing.JOptionPane;
 import java.util.ArrayList;
 import java.util.Date;
 import javax.swing.JOptionPane;
index 64f5536..f9d7a8f 100644 (file)
@@ -8,11 +8,9 @@ package habeas;
 import java.util.ArrayList;
 import javax.swing.JFileChooser;
 import javax.swing.JOptionPane;
 import java.util.ArrayList;
 import javax.swing.JFileChooser;
 import javax.swing.JOptionPane;
-import javax.swing.JTable;
 import javax.swing.filechooser.FileFilter;
 import javax.swing.filechooser.FileNameExtensionFilter;
 import javax.swing.table.DefaultTableModel;
 import javax.swing.filechooser.FileFilter;
 import javax.swing.filechooser.FileNameExtensionFilter;
 import javax.swing.table.DefaultTableModel;
-import javax.swing.table.TableModel;
 
 /**
  *
 
 /**
  *
@@ -20,6 +18,7 @@ import javax.swing.table.TableModel;
  */
 public class NoticesReportViewDialog extends javax.swing.JDialog {
 
  */
 public class NoticesReportViewDialog extends javax.swing.JDialog {
 
+    private int currentReport;
     private String reportTitle;
     private String[] reportCols;
     private ArrayList<Object> reportData;
     private String reportTitle;
     private String[] reportCols;
     private ArrayList<Object> reportData;
@@ -144,15 +143,16 @@ public class NoticesReportViewDialog extends javax.swing.JDialog {
     private void buttonApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonApplyActionPerformed
         // TODO add your handling code here:
         if (! checkFilterByClient.isSelected()) {
     private void buttonApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonApplyActionPerformed
         // TODO add your handling code here:
         if (! checkFilterByClient.isSelected()) {
-            reportData = Utility.getPendingPaymentBills(-1);
-            if (reportData != null)
+            reportData = Utility.getReportData(currentReport, -1);
+                        
+           if (reportData != null)
                 populateReport();
         } else {
             DBItem db = (DBItem)comboClients.getSelectedItem();
             if (db == null)
                 return;
             int selid = db.getKey();
                 populateReport();
         } else {
             DBItem db = (DBItem)comboClients.getSelectedItem();
             if (db == null)
                 return;
             int selid = db.getKey();
-            reportData = Utility.getPendingPaymentBills(selid);
+            reportData = Utility.getReportData(currentReport, selid);
             if (reportData != null)
                 populateReport();
         }
             if (reportData != null)
                 populateReport();
         }
@@ -214,8 +214,9 @@ public class NoticesReportViewDialog extends javax.swing.JDialog {
     private javax.swing.JTable tableReport;
     // End of variables declaration//GEN-END:variables
 
     private javax.swing.JTable tableReport;
     // End of variables declaration//GEN-END:variables
 
-    public void setupReportTable(String title, String[] columns, 
+    public void setupReportTable(int reportNum, String title, String[] columns, 
             ArrayList<Object> data) {
             ArrayList<Object> data) {
+        currentReport = reportNum;
         reportTitle = title;
         reportCols = columns;
         reportData = data;
         reportTitle = title;
         reportCols = columns;
         reportData = data;
index 89d06cf..8795204 100644 (file)
@@ -5,7 +5,6 @@
  */
 package habeas;
 
  */
 package habeas;
 
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
@@ -16,16 +15,33 @@ import java.sql.*;
 import java.text.DateFormat;
 import java.text.MessageFormat;
 import java.text.SimpleDateFormat;
 import java.text.DateFormat;
 import java.text.MessageFormat;
 import java.text.SimpleDateFormat;
-import java.util.Arrays;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import jdk.dynalink.linker.support.Guards;
 
 /**
  *
  * @author hari
  */
 public class Utility {
 
 /**
  *
  * @author hari
  */
 public class Utility {
+
+    private static final String[] REPORTS_UNFILTERED = { "SELECT ReferenceNumber, Description"
+            + ", BillDate, BillAmount, ClientName FROM legalnotices INNER JOIN "
+            + "clients ON ClientId=clients.id WHERE BillStatus='AWAITING PAYMENT';", 
+    
+            "SELECT ReferenceNumber, Description, SentDate, RPADReference, "
+            + "ClientName FROM legalnotices INNER JOIN clients ON ClientId=clients.id"
+            + " WHERE NoticeSent=1 AND NoticeDelivered=0;"
+    } ;
+
+    private static final String[] REPORTS_FILTERED = { "SELECT ReferenceNumber, Description"
+            + ", BillDate, BillAmount, ClientName FROM legalnotices INNER JOIN "
+            + "clients ON ClientId=clients.id WHERE BillStatus='AWAITING PAYMENT' "
+            + "AND ClientId=?;", 
+    
+            "SELECT ReferenceNumber, Description, SentDate, RPADReference, "
+            + "ClientName FROM legalnotices INNER JOIN clients ON ClientId=clients.id"
+            + " WHERE NoticeSent=1 AND NoticeDelivered=0 AND ClientId=?;"
+    } ;    
     
     static void saveStationerySettings (String left_header, 
             String right_header, String signatory) {
     
     static void saveStationerySettings (String left_header, 
             String right_header, String signatory) {
@@ -503,7 +519,7 @@ public class Utility {
         
     }
 
         
     }
 
-    static ArrayList<Object> getPendingPaymentBills(int clientid) {
+    static ArrayList<Object> getReportData(int report_num, int clientid) {
         ArrayList<Object> data = new ArrayList<>();
         try {
             Connection conn = DriverManager.getConnection(JDBC + connectionURL);
         ArrayList<Object> data = new ArrayList<>();
         try {
             Connection conn = DriverManager.getConnection(JDBC + connectionURL);
@@ -512,26 +528,24 @@ public class Utility {
             ResultSet rs;
             if (clientid == -1) {
                 Statement st = conn.createStatement();                
             ResultSet rs;
             if (clientid == -1) {
                 Statement st = conn.createStatement();                
-                rs = st.executeQuery("SELECT ReferenceNumber, Description, "
-                    + "BillDate, BillAmount, ClientName"
-                    + " FROM legalnotices INNER JOIN clients ON ClientId=clients.id "
-                    + "WHERE BillStatus='AWAITING PAYMENT';");
+                rs = st.executeQuery(REPORTS_UNFILTERED[report_num]);
             }
             else {
             }
             else {
-                PreparedStatement st = conn.prepareStatement("SELECT ReferenceNumber, "
-                        + "Description, BillDate, BillAmount, ClientName"
-                    + " FROM legalnotices INNER JOIN clients ON ClientId=clients.id "
-                    + "WHERE BillStatus='AWAITING PAYMENT' AND ClientId=?;");
+                PreparedStatement st = conn.prepareStatement(REPORTS_FILTERED[report_num]);
                 st.setInt (1, clientid);
                 rs = st.executeQuery();
             }
                 st.setInt (1, clientid);
                 rs = st.executeQuery();
             }
-            DateFormat fmt = new SimpleDateFormat ("dd/MM/yyyy");
+
             while (rs.next()) {
             while (rs.next()) {
-                data.add (rs.getString("ReferenceNumber"));
-                data.add (rs.getString("Description"));
-                data.add (fmt.format (getValidDate(rs, "BillDate")));
-                data.add (rs.getInt ("BillAmount"));
-                data.add (rs.getString("ClientName"));
+                ResultSetMetaData md =  rs.getMetaData();
+                SimpleDateFormat fmt = new SimpleDateFormat ("dd MMM yyyy");
+                for (int i = 1; i <= md.getColumnCount(); i ++ ) {
+                    // for INTEGER Columns which are date alone, handle separately
+                    if (md.getColumnName(i).contains("Date"))
+                        data.add (fmt.format(getValidDate(rs, md.getColumnName(i))));
+                    else
+                        data.add (rs.getObject (i));
+                }
             }
             conn.close ();
             return data;
             }
             conn.close ();
             return data;
@@ -578,6 +592,8 @@ public class Utility {
         else
             return String.format("\"%s\"", bareStr.toString());
     }
         else
             return String.format("\"%s\"", bareStr.toString());
     }
+
+
     public Utility () {
         
     }
     public Utility () {
         
     }