From: Harishankar Date: Thu, 2 Apr 2020 08:56:14 +0000 (+0530) Subject: Reporting Functionality - fixed generic reports X-Git-Url: https://harishankar.org/repos/?a=commitdiff_plain;h=020bf95644b2f26d9c81d66d2a752e55bcd3ad5b;p=habeas.git Reporting Functionality - fixed generic reports Fixed the functionality for report viewing for generic reports, rather than a single report. --- diff --git a/src/habeas/Habeas.java b/src/habeas/Habeas.java index 6c24189..2bfb038 100644 --- a/src/habeas/Habeas.java +++ b/src/habeas/Habeas.java @@ -25,7 +25,7 @@ public class Habeas { 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); } diff --git a/src/habeas/MainFrame.form b/src/habeas/MainFrame.form index d251e2f..3328dce 100644 --- a/src/habeas/MainFrame.form +++ b/src/habeas/MainFrame.form @@ -71,6 +71,15 @@ + + + + + + + + + diff --git a/src/habeas/MainFrame.java b/src/habeas/MainFrame.java index ec3ce33..3ff0418 100644 --- a/src/habeas/MainFrame.java +++ b/src/habeas/MainFrame.java @@ -6,10 +6,7 @@ package habeas; import java.util.ArrayList; -import javax.swing.JFileChooser; 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(); + menuNoticesSentNotYetDelivered = 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); + 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); @@ -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"}; - ArrayList data = Utility.getPendingPaymentBills (-1); + int rep = 0; + ArrayList data = Utility.getReportData(rep, -1); 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 - 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 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 @@ -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 menuNoticesSentNotYetDelivered; private javax.swing.JMenu menuSettings; private javax.swing.JMenuItem menuStationery; // End of variables declaration//GEN-END:variables diff --git a/src/habeas/ManageNoticesDialog.java b/src/habeas/ManageNoticesDialog.java index 6a0bba7..67f0a06 100644 --- a/src/habeas/ManageNoticesDialog.java +++ b/src/habeas/ManageNoticesDialog.java @@ -6,8 +6,6 @@ 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; diff --git a/src/habeas/NoticesReportViewDialog.java b/src/habeas/NoticesReportViewDialog.java index 64f5536..f9d7a8f 100644 --- a/src/habeas/NoticesReportViewDialog.java +++ b/src/habeas/NoticesReportViewDialog.java @@ -8,11 +8,9 @@ package habeas; 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.table.TableModel; /** * @@ -20,6 +18,7 @@ import javax.swing.table.TableModel; */ public class NoticesReportViewDialog extends javax.swing.JDialog { + private int currentReport; private String reportTitle; private String[] reportCols; private ArrayList 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()) { - 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(); - reportData = Utility.getPendingPaymentBills(selid); + reportData = Utility.getReportData(currentReport, selid); 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 - public void setupReportTable(String title, String[] columns, + public void setupReportTable(int reportNum, String title, String[] columns, ArrayList data) { + currentReport = reportNum; reportTitle = title; reportCols = columns; reportData = data; diff --git a/src/habeas/Utility.java b/src/habeas/Utility.java index 89d06cf..8795204 100644 --- a/src/habeas/Utility.java +++ b/src/habeas/Utility.java @@ -5,7 +5,6 @@ */ package habeas; -import java.io.FileNotFoundException; 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.util.Arrays; import java.util.logging.Level; import java.util.logging.Logger; -import jdk.dynalink.linker.support.Guards; /** * * @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) { @@ -503,7 +519,7 @@ public class Utility { } - static ArrayList getPendingPaymentBills(int clientid) { + static ArrayList getReportData(int report_num, int clientid) { ArrayList 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(); - 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 { - 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(); } - DateFormat fmt = new SimpleDateFormat ("dd/MM/yyyy"); + 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; @@ -578,6 +592,8 @@ public class Utility { else return String.format("\"%s\"", bareStr.toString()); } + + public Utility () { }