Stationery Settings and Template for Bill
[habeas.git] / src / habeas / Utility.java
index f7fdae7..0dc4235 100644 (file)
@@ -16,6 +16,22 @@ import java.util.logging.Logger;
  * @author hari
  */
 public class Utility {
+    
+    static void saveStationerySettings (String left_header, 
+            String right_header, String signatory) {
+        leftLetterHeader = left_header;
+        rightLetterHeader = right_header;
+        signatoryName = signatory;
+        Preferences.userRoot().put ("LeftHeader", left_header);
+        Preferences.userRoot().put ("RightHeader", right_header);
+        Preferences.userRoot().put ("Signatory", signatory);
+    }
+    
+    static void retrieveStationerySettings () {
+        leftLetterHeader = Preferences.userRoot().get("LeftHeader", "Left Header");
+        rightLetterHeader = Preferences.userRoot().get ("RightHeader", "Right Header");
+        signatoryName = Preferences.userRoot().get ("Signatory", "Signatory Name");
+    }
 
     static void saveConnectionURL(String text) {
         connectionURL = text;
@@ -175,7 +191,9 @@ public class Utility {
         ArrayList<Object> notice = new ArrayList<>();
         try {
             Connection conn = DriverManager.getConnection(JDBC + connectionURL);
-            PreparedStatement st = conn.prepareStatement("SELECT * FROM legalnotices WHERE id=?;");
+            PreparedStatement st = conn.prepareStatement("SELECT legalnotices.*, clients.ClientName "
+                    + "FROM legalnotices "
+                    + "INNER JOIN clients WHERE ClientId=clients.id AND legalnotices.id=?;");
             st.setInt(1, selid);
             ResultSet rs = st.executeQuery();
             while (rs.next()) {
@@ -195,6 +213,7 @@ public class Utility {
                 notice.add (getValidDate (rs, "BillDate"));
                 notice.add (rs.getBoolean ("ClarificationPending"));
                 notice.add (rs.getString("ClarificationRemarks"));
+                notice.add (rs.getString("ClientName"));
             }
            return notice;
         } catch (SQLException ex) {
@@ -322,15 +341,10 @@ public class Utility {
                 "      \"ClarificationPending\"        INTEGER DEFAULT 0,\n" +
                 "      \"ClarificationRemarks\"        TEXT\n" +
                 ");";
-        String tblSettings = "CREATE TABLE IF NOT EXISTS \"settings\" (\n" +
-"      \"key\" TEXT UNIQUE,\n" +
-"      \"value\"       TEXT,\n" +
-"      PRIMARY KEY(\"key\")\n" +
-        ");"; 
+
         try {
             Connection conn = DriverManager.getConnection(JDBC + connectionURL);
             Statement st1 = conn.createStatement();
-            st1.execute(tblSettings);
             st1.execute(tblClients);
             st1.execute(tblNotices);
             conn.close();
@@ -360,11 +374,30 @@ public class Utility {
             return false;
         }
         
+    }
+
+    static boolean deleteNotice(int r) {
+        try {
+            Connection conn = DriverManager.getConnection(JDBC + connectionURL);
+            PreparedStatement st = conn.prepareStatement("DELETE FROM legalnotices"
+                    + " WHERE id=?;");
+            st.setInt(1, r);
+            st.execute();
+            conn.close();
+            return true;
+        } catch (SQLException ex) {
+            Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex);
+            return false;
+        }
+        
     }
     public Utility () {
         
     }
     public static String connectionURL ;
+    public static String leftLetterHeader; 
+    public static String rightLetterHeader;
+    public static String signatoryName;
     
     /**
      *