2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
8 import java
.util
.ArrayList
;
9 import javax
.swing
.JFileChooser
;
10 import javax
.swing
.JOptionPane
;
11 import javax
.swing
.filechooser
.FileFilter
;
12 import javax
.swing
.filechooser
.FileNameExtensionFilter
;
18 public class GenerateRaisedBillsDialog
extends javax
.swing
.JDialog
{
21 * Creates new form GenerateRaisedBillsDialog
23 public GenerateRaisedBillsDialog(java
.awt
.Frame parent
, boolean modal
) {
30 * This method is called from within the constructor to initialize the form.
31 * WARNING: Do NOT modify this code. The content of this method is always
32 * regenerated by the Form Editor.
34 @SuppressWarnings("unchecked")
35 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
36 private void initComponents() {
38 jLabel1
= new javax
.swing
.JLabel();
39 comboClients
= new javax
.swing
.JComboBox
<>();
40 buttonGenerate
= new javax
.swing
.JButton();
41 buttonClose
= new javax
.swing
.JButton();
42 buttonMarkAsAwaiting
= new javax
.swing
.JButton();
44 setDefaultCloseOperation(javax
.swing
.WindowConstants
.DISPOSE_ON_CLOSE
);
45 setTitle("Generate Raised Bills");
46 setLocationByPlatform(true);
48 jLabel1
.setText("For client");
50 buttonGenerate
.setMnemonic('g');
51 buttonGenerate
.setText("Generate");
52 buttonGenerate
.addActionListener(new java
.awt
.event
.ActionListener() {
53 public void actionPerformed(java
.awt
.event
.ActionEvent evt
) {
54 buttonGenerateActionPerformed(evt
);
58 buttonClose
.setMnemonic('C');
59 buttonClose
.setText("Close");
60 buttonClose
.addActionListener(new java
.awt
.event
.ActionListener() {
61 public void actionPerformed(java
.awt
.event
.ActionEvent evt
) {
62 buttonCloseActionPerformed(evt
);
66 buttonMarkAsAwaiting
.setMnemonic('M');
67 buttonMarkAsAwaiting
.setText("Mark Raised");
68 buttonMarkAsAwaiting
.addActionListener(new java
.awt
.event
.ActionListener() {
69 public void actionPerformed(java
.awt
.event
.ActionEvent evt
) {
70 buttonMarkAsAwaitingActionPerformed(evt
);
74 javax
.swing
.GroupLayout layout
= new javax
.swing
.GroupLayout(getContentPane());
75 getContentPane().setLayout(layout
);
76 layout
.setHorizontalGroup(
77 layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.LEADING
)
78 .addGroup(layout
.createSequentialGroup()
80 .addComponent(jLabel1
, javax
.swing
.GroupLayout
.PREFERRED_SIZE
, 113, javax
.swing
.GroupLayout
.PREFERRED_SIZE
)
82 .addGroup(layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.LEADING
)
83 .addComponent(comboClients
, 0, javax
.swing
.GroupLayout
.DEFAULT_SIZE
, Short
.MAX_VALUE
)
84 .addGroup(layout
.createSequentialGroup()
85 .addGap(0, 0, Short
.MAX_VALUE
)
86 .addComponent(buttonGenerate
, javax
.swing
.GroupLayout
.PREFERRED_SIZE
, 121, javax
.swing
.GroupLayout
.PREFERRED_SIZE
)
87 .addPreferredGap(javax
.swing
.LayoutStyle
.ComponentPlacement
.RELATED
)
88 .addComponent(buttonMarkAsAwaiting
, javax
.swing
.GroupLayout
.PREFERRED_SIZE
, 117, javax
.swing
.GroupLayout
.PREFERRED_SIZE
)
89 .addPreferredGap(javax
.swing
.LayoutStyle
.ComponentPlacement
.RELATED
)
90 .addComponent(buttonClose
, javax
.swing
.GroupLayout
.PREFERRED_SIZE
, 120, javax
.swing
.GroupLayout
.PREFERRED_SIZE
)))
93 layout
.setVerticalGroup(
94 layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.LEADING
)
95 .addGroup(layout
.createSequentialGroup()
97 .addGroup(layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.BASELINE
)
98 .addComponent(jLabel1
)
99 .addComponent(comboClients
, javax
.swing
.GroupLayout
.PREFERRED_SIZE
, javax
.swing
.GroupLayout
.DEFAULT_SIZE
, javax
.swing
.GroupLayout
.PREFERRED_SIZE
))
100 .addPreferredGap(javax
.swing
.LayoutStyle
.ComponentPlacement
.RELATED
, 45, Short
.MAX_VALUE
)
101 .addGroup(layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.BASELINE
)
102 .addComponent(buttonGenerate
)
103 .addComponent(buttonClose
)
104 .addComponent(buttonMarkAsAwaiting
))
109 }// </editor-fold>//GEN-END:initComponents
111 private void buttonCloseActionPerformed(java
.awt
.event
.ActionEvent evt
) {//GEN-FIRST:event_buttonCloseActionPerformed
112 // TODO add your handling code here:
114 }//GEN-LAST:event_buttonCloseActionPerformed
116 private void buttonGenerateActionPerformed(java
.awt
.event
.ActionEvent evt
) {//GEN-FIRST:event_buttonGenerateActionPerformed
117 // TODO add your handling code here:
118 DBItem selitem
= (DBItem
)comboClients
.getSelectedItem();
119 if (selitem
== null) return;
120 ArrayList
<Object
> client
= Utility
.getClientDetails(selitem
.getKey());
121 if (client
== null) {
122 JOptionPane
.showMessageDialog(this, ERROR_CLIENT_DETAILS
);
124 } else if (client
.isEmpty()) {
125 JOptionPane
.showMessageDialog(this, ERROR_CLIENT_DETAILS
);
128 ArrayList
<Object
> bills
= Utility
.getRaisedBills(selitem
.getKey());
130 JOptionPane
.showMessageDialog(this, ERROR_RAISED_BILLS
);
132 } else if (bills
.isEmpty()) {
133 JOptionPane
.showMessageDialog(this, ERROR_RAISED_BILLS
);
137 JFileChooser chooser
= new JFileChooser ();
138 FileFilter filter
= new FileNameExtensionFilter("Flat OpenDocument text", "fodt");
139 chooser
.setFileFilter(filter
);
140 int r
= chooser
.showSaveDialog(this);
141 if (r
== JFileChooser
.APPROVE_OPTION
) {
142 String filename
= chooser
.getSelectedFile().getAbsolutePath();
143 if (!filename
.endsWith(".fodt"))
144 filename
= filename
.concat(".fodt");
146 boolean rt
= Utility
.generateRaisedNoticesBill(filename
, (String
)client
.get(0),
147 (String
)client
.get(1), (String
)client
.get(2), bills
);
149 JOptionPane
.showMessageDialog(this, ERROR_WRITING_FILE
);
151 JOptionPane
.showMessageDialog(this, SUCCESSFULLY_GENERATED_BILL
);
153 }//GEN-LAST:event_buttonGenerateActionPerformed
155 private void buttonMarkAsAwaitingActionPerformed(java
.awt
.event
.ActionEvent evt
) {//GEN-FIRST:event_buttonMarkAsAwaitingActionPerformed
156 // TODO add your handling code here:
157 DBItem selitem
= (DBItem
)comboClients
.getSelectedItem();
158 if (selitem
== null) return;
159 ArrayList
<Object
> client
= Utility
.getClientDetails(selitem
.getKey());
160 if (client
== null) {
161 JOptionPane
.showMessageDialog(this, ERROR_CLIENT_DETAILS
);
163 } else if (client
.isEmpty()) {
164 JOptionPane
.showMessageDialog(this, ERROR_CLIENT_DETAILS
);
168 int conf
= JOptionPane
.showConfirmDialog(this, MARK_RAISED_CONFIRM
);
169 if (conf
== JOptionPane
.YES_OPTION
) {
170 boolean rt
= Utility
.updateNoticeBillStatus (selitem
.getKey(), "RAISED",
173 JOptionPane
.showMessageDialog(this, ERROR_UPDATING
);
175 JOptionPane
.showMessageDialog(this, UPDATED_SUCCESSFULLY
);
180 }//GEN-LAST:event_buttonMarkAsAwaitingActionPerformed
181 private static final String UPDATED_SUCCESSFULLY
= "Updated bill status successfully";
182 private static final String ERROR_UPDATING
= "Error in updating";
183 private static final String MARK_RAISED_CONFIRM
= "This will change the status of "
184 + "all raised bills for this client to 'awaiting payment' - are you sure?";
185 private static final String ERROR_WRITING_FILE
= "Error writing file";
186 private static final String SUCCESSFULLY_GENERATED_BILL
= "Successfully generated bill";
187 private static final String ERROR_RAISED_BILLS
= "Error getting raised "
188 + "bills or no raised bills found for this client";
189 private static final String ERROR_CLIENT_DETAILS
= "Error getting client details";
192 * @param args the command line arguments
194 public static void main(String args
[]) {
195 /* Set the Nimbus look and feel */
196 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
197 /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
198 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
201 for (javax
.swing
.UIManager
.LookAndFeelInfo info
: javax
.swing
.UIManager
.getInstalledLookAndFeels()) {
202 if ("Nimbus".equals(info
.getName())) {
203 javax
.swing
.UIManager
.setLookAndFeel(info
.getClassName());
207 } catch (ClassNotFoundException ex
) {
208 java
.util
.logging
.Logger
.getLogger(GenerateRaisedBillsDialog
.class.getName()).log(java
.util
.logging
.Level
.SEVERE
, null, ex
);
209 } catch (InstantiationException ex
) {
210 java
.util
.logging
.Logger
.getLogger(GenerateRaisedBillsDialog
.class.getName()).log(java
.util
.logging
.Level
.SEVERE
, null, ex
);
211 } catch (IllegalAccessException ex
) {
212 java
.util
.logging
.Logger
.getLogger(GenerateRaisedBillsDialog
.class.getName()).log(java
.util
.logging
.Level
.SEVERE
, null, ex
);
213 } catch (javax
.swing
.UnsupportedLookAndFeelException ex
) {
214 java
.util
.logging
.Logger
.getLogger(GenerateRaisedBillsDialog
.class.getName()).log(java
.util
.logging
.Level
.SEVERE
, null, ex
);
218 /* Create and display the dialog */
219 java
.awt
.EventQueue
.invokeLater(new Runnable() {
221 GenerateRaisedBillsDialog dialog
= new GenerateRaisedBillsDialog(new javax
.swing
.JFrame(), true);
222 dialog
.addWindowListener(new java
.awt
.event
.WindowAdapter() {
224 public void windowClosing(java
.awt
.event
.WindowEvent e
) {
228 dialog
.setVisible(true);
233 // Variables declaration - do not modify//GEN-BEGIN:variables
234 private javax
.swing
.JButton buttonClose
;
235 private javax
.swing
.JButton buttonGenerate
;
236 private javax
.swing
.JButton buttonMarkAsAwaiting
;
237 private javax
.swing
.JComboBox
<DBItem
> comboClients
;
238 private javax
.swing
.JLabel jLabel1
;
239 // End of variables declaration//GEN-END:variables
241 private void populateFields() {
242 comboClients
.removeAllItems();;
243 ArrayList
<Object
> clients
= Utility
.getClientsNameAndId();
244 if (clients
== null) return;
245 for (int i
= 0; i
< clients
.size(); i
+=2) {
246 comboClients
.addItem(new DBItem ((int)clients
.get(i
), (String
)clients
.get(i
+1)));