Raised bills functionality - updating bill status
[habeas.git] / src / habeas / GenerateRaisedBillsDialog.java
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