Stationery Settings and Template for Bill
[habeas.git] / src / habeas / Utility.java
index 4a4042c..0dc4235 100644 (file)
@@ -16,8 +16,24 @@ 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 setConnectionURL(String text) {
+    static void saveConnectionURL(String text) {
         connectionURL = text;
         Preferences.userRoot().put("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) {
@@ -272,10 +291,113 @@ public class Utility {
             Date sqldate = new Date (date.getTime()/1000);
             return sqldate;
     }
+
+    static boolean updateNoticeBillDetails(int selid, String bill_status, 
+            java.util.Date bill_date, int bill_amount) {
+        try {
+            Connection conn = DriverManager.getConnection(JDBC + connectionURL);
+            PreparedStatement st = conn.prepareStatement("UPDATE legalnotices"
+                    + " SET BillStatus=?,BillDate=?,BillAmount=? WHERE id=?;");
+            st.setString (1, bill_status);
+            st.setDate(2, toSqlDate(bill_date));
+            st.setInt(3, bill_amount);
+            st.setInt(4, selid);
+            st.execute();
+            conn.close();
+            return true;
+        } catch (SQLException ex) {
+            Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex);
+            return false;
+        }
+        
+    }
+
+    static boolean createDatabase(String db_path) {
+        saveConnectionURL(db_path);
+        String tblClients = "CREATE TABLE IF NOT EXISTS \"clients\" (\n" +
+"      \"id\"  INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n" +
+"      \"ClientName\"  VARCHAR(255) NOT NULL UNIQUE,\n" +
+"      \"ClientAddress\"       TEXT,\n" +
+"      \"ContactPerson\"       TEXT,\n" +
+"      \"MailID\"      VARCHAR(255),\n" +
+"      \"ContactNumber\"       VARCHAR(30)\n" +
+"       );";
+        String tblNotices = "CREATE TABLE IF NOT EXISTS \"legalnotices\" (\n" +
+                "      \"id\"  INTEGER PRIMARY KEY AUTOINCREMENT,\n" +
+                "      \"ReferenceNumber\"     TEXT NOT NULL UNIQUE,\n" +
+                "      \"Description\" TEXT NOT NULL,\n" +
+                "      \"EntrustmentDate\"     INTEGER NOT NULL,\n" +
+                "      \"ClientId\"    INTEGER,\n" +
+                "      \"DraftCreated\"        INTEGER DEFAULT 0,\n" +
+                "      \"DraftApproved\"       INTEGER DEFAULT 0 CHECK(DraftApproved<=DraftCreated),\n" +
+                "      \"NoticeSent\"  INTEGER DEFAULT 0 CHECK(NoticeSent<=DraftApproved),\n" +
+                "      \"SentDate\"    INTEGER CHECK(SentDate>=EntrustmentDate),\n" +
+                "      \"RPADReference\"       TEXT,\n" +
+                "      \"NoticeDelivered\"     INTEGER DEFAULT 0 CHECK(NoticeDelivered<=NoticeSent),\n" +
+                "      \"DeliveryDate\"        INTEGER CHECK(DeliveryDate>=SentDate),\n" +
+                "      \"BillStatus\"  TEXT DEFAULT 'PENDING',\n" +
+                "      \"BillAmount\"  INTEGER DEFAULT 1000 CHECK(BillAmount>0),\n" +
+                "      \"BillDate\"    INTEGER CHECK(BillDate>=DeliveryDate),\n" +
+                "      \"ClarificationPending\"        INTEGER DEFAULT 0,\n" +
+                "      \"ClarificationRemarks\"        TEXT\n" +
+                ");";
+
+        try {
+            Connection conn = DriverManager.getConnection(JDBC + connectionURL);
+            Statement st1 = conn.createStatement();
+            st1.execute(tblClients);
+            st1.execute(tblNotices);
+            conn.close();
+            return true;
+        } catch (SQLException ex) {
+            Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex);
+            return false;
+        }
+
+    }
+
+    static boolean updateNoticeClarificationDetails(int selected_id, boolean 
+            clarification_pending, String clarification_remarks) {
+        try {
+            Connection conn = DriverManager.getConnection(JDBC + connectionURL);
+            PreparedStatement st = conn.prepareStatement ("UPDATE legalnotices"
+                    + " SET ClarificationPending=?, ClarificationRemarks=? "
+                    + "WHERE id=?;");
+            st.setBoolean(1, clarification_pending);
+            st.setString(2, clarification_remarks);
+            st.setInt (3, selected_id);
+            st.execute();
+            conn.close ();
+            return true;
+        } catch (SQLException ex) {
+            Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex);
+            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;
     
     /**
      *
@@ -300,7 +422,7 @@ public class Utility {
         
     }
     
-    public static void getConnectionURL () {
+    public static void retrieveConnectionURL () {
         connectionURL = Preferences.userRoot().get("ConnectionURL", "legaldb");
     }