Raised bills functionality - updating bill status
authorHarishankar <v.harishankar@gmail.com>
Wed, 1 Apr 2020 14:10:35 +0000 (19:40 +0530)
committerHarishankar <v.harishankar@gmail.com>
Wed, 1 Apr 2020 14:10:35 +0000 (19:40 +0530)
Added option in Generate raised bills dialog for marking raised bills
as "awaiting payment" so that these bills are not raised in the future

src/habeas/GenerateRaisedBillsDialog.form
src/habeas/GenerateRaisedBillsDialog.java
src/habeas/Habeas.java
src/habeas/ManageNoticesDialog.java
src/habeas/Utility.java

index 3fc7e02..3cf03b5 100644 (file)
               <EmptySpace type="separate" max="-2" attributes="0"/>
               <Group type="103" groupAlignment="0" attributes="0">
                   <Component id="comboClients" max="32767" attributes="0"/>
-                  <Group type="102" attributes="0">
+                  <Group type="102" alignment="0" attributes="0">
+                      <EmptySpace min="0" pref="0" max="32767" attributes="0"/>
                       <Component id="buttonGenerate" min="-2" pref="121" max="-2" attributes="0"/>
-                      <EmptySpace pref="28" max="32767" attributes="0"/>
+                      <EmptySpace max="-2" attributes="0"/>
+                      <Component id="buttonMarkAsAwaiting" min="-2" pref="117" max="-2" attributes="0"/>
+                      <EmptySpace max="-2" attributes="0"/>
                       <Component id="buttonClose" min="-2" pref="120" max="-2" attributes="0"/>
                   </Group>
               </Group>
@@ -53,6 +56,7 @@
               <Group type="103" groupAlignment="3" attributes="0">
                   <Component id="buttonGenerate" alignment="3" min="-2" max="-2" attributes="0"/>
                   <Component id="buttonClose" alignment="3" min="-2" max="-2" attributes="0"/>
+                  <Component id="buttonMarkAsAwaiting" alignment="3" min="-2" max="-2" attributes="0"/>
               </Group>
               <EmptySpace max="-2" attributes="0"/>
           </Group>
         <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonCloseActionPerformed"/>
       </Events>
     </Component>
+    <Component class="javax.swing.JButton" name="buttonMarkAsAwaiting">
+      <Properties>
+        <Property name="mnemonic" type="int" value="77"/>
+        <Property name="text" type="java.lang.String" value="Mark Raised"/>
+      </Properties>
+      <Events>
+        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonMarkAsAwaitingActionPerformed"/>
+      </Events>
+    </Component>
   </SubComponents>
 </Form>
index 2273353..0e1541d 100644 (file)
@@ -39,6 +39,7 @@ public class GenerateRaisedBillsDialog extends javax.swing.JDialog {
         comboClients = new javax.swing.JComboBox<>();
         buttonGenerate = new javax.swing.JButton();
         buttonClose = new javax.swing.JButton();
+        buttonMarkAsAwaiting = new javax.swing.JButton();
 
         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
         setTitle("Generate Raised Bills");
@@ -62,6 +63,14 @@ public class GenerateRaisedBillsDialog extends javax.swing.JDialog {
             }
         });
 
+        buttonMarkAsAwaiting.setMnemonic('M');
+        buttonMarkAsAwaiting.setText("Mark Raised");
+        buttonMarkAsAwaiting.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                buttonMarkAsAwaitingActionPerformed(evt);
+            }
+        });
+
         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
         getContentPane().setLayout(layout);
         layout.setHorizontalGroup(
@@ -73,8 +82,11 @@ public class GenerateRaisedBillsDialog extends javax.swing.JDialog {
                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(comboClients, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                     .addGroup(layout.createSequentialGroup()
+                        .addGap(0, 0, Short.MAX_VALUE)
                         .addComponent(buttonGenerate, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
-                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
+                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                        .addComponent(buttonMarkAsAwaiting, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
+                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                         .addComponent(buttonClose, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)))
                 .addContainerGap())
         );
@@ -88,7 +100,8 @@ public class GenerateRaisedBillsDialog extends javax.swing.JDialog {
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE)
                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(buttonGenerate)
-                    .addComponent(buttonClose))
+                    .addComponent(buttonClose)
+                    .addComponent(buttonMarkAsAwaiting))
                 .addContainerGap())
         );
 
@@ -138,6 +151,37 @@ public class GenerateRaisedBillsDialog extends javax.swing.JDialog {
                 JOptionPane.showMessageDialog(this, SUCCESSFULLY_GENERATED_BILL);
         }
     }//GEN-LAST:event_buttonGenerateActionPerformed
+
+    private void buttonMarkAsAwaitingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMarkAsAwaitingActionPerformed
+        // TODO add your handling code here:
+        DBItem selitem = (DBItem)comboClients.getSelectedItem();
+        if (selitem == null) return;
+        ArrayList<Object> client = Utility.getClientDetails(selitem.getKey());
+        if (client == null) {
+            JOptionPane.showMessageDialog(this, ERROR_CLIENT_DETAILS);
+            return;
+        } else if (client.isEmpty()) {
+            JOptionPane.showMessageDialog(this, ERROR_CLIENT_DETAILS);
+            return;            
+        }
+        
+        int conf = JOptionPane.showConfirmDialog(this, MARK_RAISED_CONFIRM);
+        if (conf == JOptionPane.YES_OPTION) {
+            boolean rt = Utility.updateNoticeBillStatus (selitem.getKey(), "RAISED", 
+                    "AWAITING PAYMENT");
+            if (rt == false)
+                JOptionPane.showMessageDialog(this, ERROR_UPDATING);
+            else
+                JOptionPane.showMessageDialog(this, UPDATED_SUCCESSFULLY);
+            
+        }
+        
+        
+    }//GEN-LAST:event_buttonMarkAsAwaitingActionPerformed
+    private static final String UPDATED_SUCCESSFULLY = "Updated bill status successfully";
+    private static final String ERROR_UPDATING = "Error in updating";
+    private static final String MARK_RAISED_CONFIRM = "This will change the status of "
+            + "all raised bills for this client to 'awaiting payment' - are you sure?";
     private static final String ERROR_WRITING_FILE = "Error writing file";
     private static final String SUCCESSFULLY_GENERATED_BILL = "Successfully generated bill";
     private static final String ERROR_RAISED_BILLS = "Error getting raised "
@@ -189,6 +233,7 @@ public class GenerateRaisedBillsDialog extends javax.swing.JDialog {
     // Variables declaration - do not modify//GEN-BEGIN:variables
     private javax.swing.JButton buttonClose;
     private javax.swing.JButton buttonGenerate;
+    private javax.swing.JButton buttonMarkAsAwaiting;
     private javax.swing.JComboBox<DBItem> comboClients;
     private javax.swing.JLabel jLabel1;
     // End of variables declaration//GEN-END:variables
index 2bfb038..6c24189 100644 (file)
@@ -25,7 +25,7 @@ public class Habeas {
         Utility.retrieveStationerySettings();
         
         try {
-            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
+            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
         } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
             Logger.getLogger(Habeas.class.getName()).log(Level.SEVERE, null, ex);
         }
index 5ccdb15..6a0bba7 100644 (file)
@@ -26,15 +26,7 @@ public class ManageNoticesDialog extends javax.swing.JDialog {
         super(parent, modal);
         initComponents();
         populateNotices ();
-        tableNotices.addMouseListener(new MouseAdapter() {
-            @Override
-            public void mousePressed(MouseEvent arg0) {
-                if (arg0.isPopupTrigger()) {
-                    popMenu.show(arg0.getComponent(), arg0.getX(), arg0.getY());
-                }
-            }
-
-        });
+        tableNotices.setComponentPopupMenu(popMenu);
     }
 
     /**
index bc99932..d9a231b 100644 (file)
@@ -482,6 +482,25 @@ public class Utility {
             return null;
         }
     }
+
+    static boolean updateNoticeBillStatus(int client_id, String from_status, 
+            String to_status) {
+        try {
+            Connection conn = DriverManager.getConnection(JDBC + connectionURL);
+            PreparedStatement st = conn.prepareStatement("UPDATE legalnotices"
+                    + " SET BillStatus=? WHERE BillStatus=? AND ClientId=?;");
+            st.setString (1, to_status);
+            st.setString (2, from_status);
+            st.setInt (3, client_id);
+            st.execute();
+            conn.close();
+            return true;
+        } catch (SQLException ex) {
+            Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex);
+            return false;
+        }
+        
+    }
     public Utility () {
         
     }