From: Harishankar Date: Wed, 1 Apr 2020 14:10:35 +0000 (+0530) Subject: Raised bills functionality - updating bill status X-Git-Url: https://harishankar.org/repos/?a=commitdiff_plain;h=02fd056bbcee3117ee1fad182f823159d2a25cff;p=habeas.git Raised bills functionality - updating bill status Added option in Generate raised bills dialog for marking raised bills as "awaiting payment" so that these bills are not raised in the future --- diff --git a/src/habeas/GenerateRaisedBillsDialog.form b/src/habeas/GenerateRaisedBillsDialog.form index 3fc7e02..3cf03b5 100644 --- a/src/habeas/GenerateRaisedBillsDialog.form +++ b/src/habeas/GenerateRaisedBillsDialog.form @@ -31,9 +31,12 @@ - + + - + + + @@ -53,6 +56,7 @@ + @@ -93,5 +97,14 @@ + + + + + + + + + diff --git a/src/habeas/GenerateRaisedBillsDialog.java b/src/habeas/GenerateRaisedBillsDialog.java index 2273353..0e1541d 100644 --- a/src/habeas/GenerateRaisedBillsDialog.java +++ b/src/habeas/GenerateRaisedBillsDialog.java @@ -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 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 comboClients; private javax.swing.JLabel jLabel1; // End of variables declaration//GEN-END:variables diff --git a/src/habeas/Habeas.java b/src/habeas/Habeas.java index 2bfb038..6c24189 100644 --- a/src/habeas/Habeas.java +++ b/src/habeas/Habeas.java @@ -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); } diff --git a/src/habeas/ManageNoticesDialog.java b/src/habeas/ManageNoticesDialog.java index 5ccdb15..6a0bba7 100644 --- a/src/habeas/ManageNoticesDialog.java +++ b/src/habeas/ManageNoticesDialog.java @@ -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); } /** diff --git a/src/habeas/Utility.java b/src/habeas/Utility.java index bc99932..d9a231b 100644 --- a/src/habeas/Utility.java +++ b/src/habeas/Utility.java @@ -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 () { }