Reporting Functionality - Filter by Client
[habeas.git] / src / habeas / Utility.java
index c0379a0..89d06cf 100644 (file)
@@ -503,16 +503,28 @@ public class Utility {
         
     }
 
-    static ArrayList<Object> getPendingPaymentBills() {
+    static ArrayList<Object> getPendingPaymentBills(int clientid) {
         ArrayList<Object> data = new ArrayList<>();
         try {
             Connection conn = DriverManager.getConnection(JDBC + connectionURL);
-            Statement st = conn.createStatement();
-            ResultSet rs = st.executeQuery("SELECT ReferenceNumber, Description, "
+
+            // if no client ID is specified i.e. -1 get ll
+            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';");
-            
+            }
+            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=?;");
+                st.setInt (1, clientid);
+                rs = st.executeQuery();
+            }
             DateFormat fmt = new SimpleDateFormat ("dd/MM/yyyy");
             while (rs.next()) {
                 data.add (rs.getString("ReferenceNumber"));
@@ -535,13 +547,13 @@ public class Utility {
             FileWriter f = new FileWriter (filePath);
             for (int i = 0; i < reportCols.length; i ++) {
                 f.append (escapeQuote(reportCols[i]));
-                f.append (", ");
+                f.append (",");
             }
             f.append("\n");
             for (int i = 0; i < reportData.size(); i += reportCols.length) {
                 for (int j = 0; j < reportCols.length; j ++) {
                     f.append (escapeQuote(reportData.get(i+j)));
-                    f.append (", ");
+                    f.append (",");
                 }
                 f.append ("\n");
             }