KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > gui > OrderFulfillPanel


1 package sellwin.gui;
2
3 import java.awt.*;
4 import java.awt.event.*;
5 import java.util.*;
6 import java.math.*;
7 import java.text.*;
8
9 import javax.swing.*;
10 import javax.swing.event.*;
11 import javax.swing.table.*;
12 import javax.swing.border.*;
13
14 import sellwin.domain.*;
15 import sellwin.utils.*;
16
17 // SellWin http://sourceforge.net/projects/sellwincrm
18
//Contact support@open-app.com for commercial help with SellWin
19
//This software is provided "AS IS", without a warranty of any kind.
20

21 /**
22  * This class implements the Order Fulfillment panel
23  * that a users sees when they press the 'Order' tab
24  * from the MainWindow GUI
25  */

26 public class OrderFulfillPanel extends javax.swing.JPanel JavaDoc {
27
28     private final static int TABLE_WIDTH = 560;
29     private final static int TABLE_HEIGHT = 100;
30
31     private JComboBox statusCombo = new JComboBox(Order.STATUS);
32
33     private Order currentOrder;
34     private double shippingHandling=0.00;
35     private static final int LABEL_WIDTH = 200;
36     private OrderFulfillPanel thisPanel = null;
37     private Whiteboard wb=null;
38     private OrderDetailTableModel detailsModel = null;
39     private OrderTableModel orderModel = null;
40
41     private JPanel bottomPanel;
42     private JPanel pmtPanel;
43     private JPanel subTotalPanel;
44     private JPanel shipPanel;
45     private JPanel taxPanel;
46     private JPanel totalPanel;
47
48     private JPanel buttonPanel;
49     private JButton applyButton;
50
51     private JScrollPane mainScrollPane;
52     private JPanel mainPanel;
53     private JTabbedPane tabbedPane = new JTabbedPane();
54     private AddressPanel billAddrPanel;
55     private AddressPanel shipAddrPanel;
56
57     private JComboBox paymentTypeCombo;
58
59     private JPanel detailsPanel = new JPanel();
60     private JScrollPane orderDetailsScrollPane;
61     private JTable orderDetailsTable;
62     private JLabel paymentTypeLabel;
63     private JTextField paymentField;
64     private JLabel subTotalLabel;
65     private JTextField subTotalField;
66     private JLabel shipLabel;
67     private JTextField shipField;
68     private JLabel totalLabel;
69     private JTextField totalField;
70     private JLabel taxLabel;
71     private JTextField taxField;
72
73     private JPanel ordersPanel;
74     private JScrollPane ordersScrollPane;
75     private JTable orderTable;
76
77
78     /**
79      * construct an order fullfillment panel
80      */

81     public OrderFulfillPanel() {
82         wb = MainWindow.getWhiteboard();
83         initComponents();
84         setColors();
85         setFonts();
86
87         setOrderDetails(new ArrayList());
88
89
90         thisPanel = this;
91
92         orderTable.setDefaultRenderer(Date.class, new DateRenderer());
93         orderTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
94         orderTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
95         orderTable.getSelectionModel().addListSelectionListener(
96             new ListSelectionListener() {
97                 public void valueChanged(ListSelectionEvent e) {
98                     if (e.getValueIsAdjusting()) return; //ignore these
99

100                     ListSelectionModel lsm = (ListSelectionModel)e.getSource();
101     
102                     if (!lsm.isSelectionEmpty()) {
103                         Order order = orderModel.getOrder(orderTable.getSelectedRow());
104                         setOrder(order);
105                     }
106                 }
107             }
108         );
109                     
110         applyButton.addActionListener(
111             new ActionListener() {
112                 public void actionPerformed(ActionEvent e) {
113                     ListSelectionModel m = orderTable.getSelectionModel();
114                     if (m.getLeadSelectionIndex() >= 0) {
115                         Order o = orderModel.getOrder(m.getLeadSelectionIndex());
116                         o.setPaymentForm((String JavaDoc)(paymentTypeCombo.getSelectedItem()));
117                         o.setShipAddress(shipAddrPanel.getAddress());
118                         o.setBillAddress(billAddrPanel.getAddress());
119                         //o.setSubmitDate(new java.util.Date());
120
o.setSubTotal(Double.parseDouble(subTotalField.getText()));
121                         o.setTax(Double.parseDouble(taxField.getText()));
122                         o.setShipping(Double.parseDouble(shipField.getText()));
123                         o.setTotal(Double.parseDouble(totalField.getText()));
124                         orderTable.tableChanged(new TableModelEvent(orderModel));
125                         try {
126                             wb.updateOrder(o);
127                             JOptionPane.showMessageDialog(
128                                 thisPanel,
129                                 "Update Successful",
130                                 "Update Successful",
131                                 JOptionPane.INFORMATION_MESSAGE);
132                         } catch (AngError f) {
133                             ErrorHandler.show(thisPanel, f);
134                         }
135                     }
136                 }
137             }
138         );
139
140         shipField.addFocusListener(
141             new FocusListener() {
142                 public void focusGained(FocusEvent e) { }
143                 public void focusLost(FocusEvent e) {
144                     computeTotal();
145                 }
146             }
147         );
148
149         statusCombo.addActionListener(
150             new ActionListener() {
151                 public void actionPerformed(ActionEvent e) {
152                     ListSelectionModel m = orderTable.getSelectionModel();
153                     if (m.getLeadSelectionIndex() >= 0) {
154                         Order row = orderModel.getOrder(m.getLeadSelectionIndex());
155                         row.setStatus((String JavaDoc)statusCombo.getSelectedItem());
156                     }
157                 }
158             }
159         );
160
161         orderModel = new OrderTableModel(new ArrayList());
162         orderTable.setModel(orderModel);
163         setLang();
164     }
165
166
167     /**
168      * initialize the panel's components
169      */

170     private final void initComponents() {
171         buttonPanel = new JPanel();
172         applyButton = new JButton();
173         mainScrollPane = new JScrollPane();
174         mainPanel = new JPanel();
175         billAddrPanel = new AddressPanel();
176         //billAddrPanel.setBorder(new TitledBorder("Bill-To Address"));
177
shipAddrPanel = new AddressPanel();
178         //shipAddrPanel.setBorder(new TitledBorder("Ship-To Address"));
179
paymentTypeCombo = new JComboBox();
180         subTotalField = new JTextField("0");
181         subTotalField.setEditable(false);
182         subTotalField.setEnabled(false);
183         taxField = new JTextField("0");
184         taxField.setEditable(false);
185         taxField.setEnabled(false);
186         shipField = new JTextField("0.00");
187         totalField = new JTextField();
188         totalField.setEditable(false);
189         totalField.setEnabled(false);
190         orderDetailsScrollPane = new JScrollPane();
191         orderDetailsTable = new JTable();
192         paymentTypeLabel = new JLabel();
193         taxLabel = new JLabel();
194         shipLabel = new JLabel();
195         totalLabel = new JLabel();
196         subTotalLabel = new JLabel();
197         ordersScrollPane = new JScrollPane();
198         orderTable = new JTable();
199         
200         setLayout(new java.awt.BorderLayout JavaDoc());
201         
202         applyButton.setText("Apply");
203         buttonPanel.add(applyButton);
204         
205         add(buttonPanel, java.awt.BorderLayout.SOUTH);
206
207         pmtPanel = new JPanel();
208         pmtPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
209         totalPanel = new JPanel();
210         totalPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
211         subTotalPanel = new JPanel();
212         subTotalPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
213         taxPanel = new JPanel();
214         taxPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
215         shipPanel = new JPanel();
216         shipPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
217
218         bottomPanel = new JPanel();
219         BoxLayout lay = new BoxLayout(bottomPanel, BoxLayout.Y_AXIS);
220         bottomPanel.setLayout(lay);
221         bottomPanel.add(pmtPanel);
222         bottomPanel.add(subTotalPanel);
223         bottomPanel.add(taxPanel);
224         bottomPanel.add(shipPanel);
225         bottomPanel.add(totalPanel);
226         
227         //mainScrollPane.setBorder(new javax.swing.border.EtchedBorder());
228
mainScrollPane.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
229         mainScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
230         mainPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
231         java.awt.GridBagConstraints JavaDoc gridBagConstraints1;
232       
233         tabbedPane.add(wb.getLang().getString("billAddress"), billAddrPanel);
234         tabbedPane.add(wb.getLang().getString("shipAddress"), shipAddrPanel);
235         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
236         gridBagConstraints1.gridx = 0;
237         gridBagConstraints1.gridy = 5;
238         gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
239         //mainPanel.add(billAddrPanel, gridBagConstraints1);
240
mainPanel.add(tabbedPane, gridBagConstraints1);
241         
242         java.awt.GridBagConstraints JavaDoc gridBagConstraints3;
243         
244         //gridBagConstraints1 = new java.awt.GridBagConstraints();
245
//gridBagConstraints1.gridx = 0;
246
//gridBagConstraints1.gridy = 6;
247
//gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
248
//mainPanel.add(shipAddrPanel, gridBagConstraints1);
249

250         paymentTypeCombo.setModel(
251             new DefaultComboBoxModel(Order.METHODS));
252        
253         //orderDetailsScrollPane.setBorder(new TitledBorder("Order Details"));
254
orderDetailsScrollPane.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
255         orderDetailsScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
256         orderDetailsScrollPane.setViewportView(orderDetailsTable);
257         orderDetailsScrollPane.setPreferredSize(new Dimension(TABLE_WIDTH,TABLE_HEIGHT));
258         orderDetailsScrollPane.setMaximumSize(new Dimension(TABLE_WIDTH,TABLE_HEIGHT));
259         orderDetailsScrollPane.setMinimumSize(new Dimension(TABLE_WIDTH,TABLE_HEIGHT));
260         
261         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
262         gridBagConstraints1.gridx = 0;
263         gridBagConstraints1.gridy = 3;
264         gridBagConstraints1.gridwidth = 2;
265         gridBagConstraints1.ipadx = 9;
266         gridBagConstraints1.ipady = 9;
267         gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
268         gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
269         detailsPanel.add(orderDetailsScrollPane);
270
271         mainPanel.add(detailsPanel, gridBagConstraints1);
272        
273         paymentTypeLabel.setText("Form of Payment");
274         paymentTypeLabel.setMinimumSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
275         paymentTypeLabel.setMaximumSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
276         paymentTypeLabel.setPreferredSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
277         paymentTypeLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
278         pmtPanel.add(paymentTypeLabel);
279         pmtPanel.add(paymentTypeCombo);
280
281         subTotalLabel.setText("sub total");
282         subTotalLabel.setMinimumSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
283         subTotalLabel.setMaximumSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
284         subTotalLabel.setPreferredSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
285         subTotalLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
286         subTotalPanel.add(subTotalLabel);
287         subTotalField.setMinimumSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
288         subTotalField.setMaximumSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
289         subTotalField.setPreferredSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
290         subTotalPanel.add(subTotalField);
291
292         taxLabel.setText("Tax");
293         taxLabel.setMinimumSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
294         taxLabel.setMaximumSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
295         taxLabel.setPreferredSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
296         taxLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
297         taxPanel.add(taxLabel);
298         taxField.setMinimumSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
299         taxField.setMaximumSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
300         taxField.setPreferredSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
301         taxPanel.add(taxField);
302
303         shipLabel.setText("Shipping/Handling");
304         shipLabel.setMinimumSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
305         shipLabel.setMaximumSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
306         shipLabel.setPreferredSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
307         shipLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
308         shipPanel.add(shipLabel);
309         shipField.setMinimumSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
310         shipField.setMaximumSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
311         shipField.setPreferredSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
312         shipPanel.add(shipField);
313
314         totalLabel.setText("Total");
315         totalLabel.setMinimumSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
316         totalLabel.setMaximumSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
317         totalLabel.setPreferredSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
318         totalLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
319         totalPanel.add(totalLabel);
320         totalField.setMinimumSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
321         totalField.setMaximumSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
322         totalField.setPreferredSize(new Dimension(LABEL_WIDTH, Prefs.FIELD_HEIGHT));
323         totalPanel.add(totalField);
324         
325         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
326         gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
327         gridBagConstraints1.gridx = 0;
328         gridBagConstraints1.gridy = 6;
329         mainPanel.add(bottomPanel, gridBagConstraints1);
330       
331         ordersPanel = new JPanel();
332         ordersPanel.setBorder(new TitledBorder("Orders"));
333  
334         //ordersScrollPane.setBorder(new TitledBorder("Orders"));
335
ordersScrollPane.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
336         ordersScrollPane.setViewportView(orderTable);
337         ordersScrollPane.setPreferredSize(new Dimension(TABLE_WIDTH,TABLE_HEIGHT));
338         ordersScrollPane.setMaximumSize(new Dimension(TABLE_WIDTH,TABLE_HEIGHT));
339         ordersScrollPane.setMinimumSize(new Dimension(TABLE_WIDTH,TABLE_HEIGHT));
340         
341         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
342         gridBagConstraints1.gridx = 0;
343         gridBagConstraints1.gridy = 1;
344         gridBagConstraints1.gridwidth = 2;
345         //gridBagConstraints1.ipadx = 9;
346
//gridBagConstraints1.ipady = 9;
347
gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
348         gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
349         ordersPanel.add(ordersScrollPane);
350         //mainPanel.add(ordersScrollPane, gridBagConstraints1);
351
mainPanel.add(ordersPanel, gridBagConstraints1);
352         
353         mainScrollPane.setViewportView(mainPanel);
354         
355         add(mainScrollPane, java.awt.BorderLayout.CENTER);
356     }
357
358    private final void setFonts() {
359         tabbedPane.setFont(MainWindow.LABEL_FONT);
360         applyButton.setFont(MainWindow.LABEL_FONT);
361         taxLabel.setFont(MainWindow.LABEL_FONT);
362         shipLabel.setFont(MainWindow.LABEL_FONT);
363         subTotalLabel.setFont(MainWindow.LABEL_FONT);
364         totalLabel.setFont(MainWindow.LABEL_FONT);
365         taxField.setFont(MainWindow.FIELD_FONT);
366         shipField.setFont(MainWindow.FIELD_FONT);
367         totalField.setFont(MainWindow.FIELD_FONT);
368         subTotalField.setFont(MainWindow.FIELD_FONT);
369         paymentTypeCombo.setFont(MainWindow.FIELD_FONT);
370         orderDetailsTable.setFont(MainWindow.FIELD_FONT);
371         paymentTypeLabel.setFont(MainWindow.LABEL_FONT);
372     }
373
374     /**
375      * set the panel's colors
376      */

377     private final void setColors() {
378         paymentTypeCombo.setBackground(Color.white);
379         paymentTypeLabel.setForeground(MainWindow.LETTERS);
380         shipLabel.setForeground(MainWindow.LETTERS);
381         taxLabel.setForeground(MainWindow.LETTERS);
382         totalLabel.setForeground(MainWindow.LETTERS);
383         subTotalLabel.setForeground(MainWindow.LETTERS);
384     }
385
386     /**
387      * set the panel to show the current opportunity
388      * data
389      */

390     public final void refreshOpportunity() {
391         Opportunity opp = wb.getCurrentOpportunity();
392         ArrayList orders = opp.getOrders();
393
394
395         if (orders != null) {
396             orderModel = new OrderTableModel(orders);
397             orderTable.setModel(orderModel);
398
399             ArrayList orderDetails = null;
400             if (orders.size() > 0) {
401                 orderTable.setRowSelectionInterval(0,0);
402                 Order order = (Order)(orders.get(0));
403                 setOrder(order);
404                 orderDetails = order.getQuote().getLines();
405             } else {
406                 setOrderDetails(new ArrayList());
407             }
408
409             orderDetailsTable.setDefaultRenderer(Double JavaDoc.class, new MoneyRenderer());
410             initTableColumns();
411         }
412     }
413
414     /**
415      * se the panel to a specific Order
416      * @param o the Order to show
417      */

418     public final void setSelectedOrder(Order o) {
419         Opportunity opp = wb.getCurrentOpportunity();
420         ArrayList orders = opp.getOrders();
421
422         //select the order in the order table
423
Order order;
424         for (int i=0;i < orders.size();i++) {
425             order = (Order)(orders.get(i));
426             if (order.getPK() == o.getPK()) {
427                 orderTable.setRowSelectionInterval(i, i);
428             }
429         }
430         
431     }
432
433     /**
434      * set the current Order
435      * @param o the Order to set with
436      */

437     private final void setOrder(Order o) {
438         try {
439             currentOrder = o;
440             setOrderAddresses(o);
441             setOrderDetails(o.getQuote().getLines());
442             paymentTypeCombo.setSelectedItem(o.getPaymentForm());
443             computeTotal();
444         } catch (NullPointerException JavaDoc e) {
445             ErrorHandler.show(thisPanel, e);
446         }
447     }
448
449     /**
450      * compute and set the total field
451      */

452      private final void computeTotal() {
453         double subTotal = currentOrder.getQuote().calcSubTotal();
454         //subTotalField.setText(Double.toString(subTotal));
455
subTotalField.setText(Prefs.money.format(subTotal));
456         double salesTax = calculateSalesTax(currentOrder);
457         DecimalFormat format = new DecimalFormat("0.00");
458         taxField.setText(format.format(salesTax));
459         double shippingHandling = Double.parseDouble(shipField.getText());
460         double total = salesTax + subTotal + shippingHandling;
461         totalField.setText(format.format(total));
462      }
463
464     /**
465      * set the order addresses
466      * @param order the order to show
467      */

468     private final void setOrderAddresses(Order order) {
469         Address shipAddress = order.getShipAddress();
470         Address billAddress = order.getBillAddress();
471         if (billAddress != null)
472             billAddrPanel.setAddress(billAddress);
473         if (shipAddress != null)
474             shipAddrPanel.setAddress(shipAddress);
475     }
476
477     /**
478      * set the order details
479      * @param quoteLines the QuoteLines to show
480      */

481     private final void setOrderDetails(ArrayList quoteLines) {
482         detailsModel = new OrderDetailTableModel(quoteLines);
483         orderDetailsTable.setModel(detailsModel);
484     }
485
486     /**
487      * clear the screen components
488      */

489     public final void clearOpportunity() {
490         ArrayList orders = new ArrayList();
491         orderModel = new OrderTableModel(orders);
492         orderTable.setModel(orderModel);
493         setOrderDetails(new ArrayList());
494         initTableColumns();
495     }
496
497     /**
498      * set the panel's language
499      */

500     public final void setLang() {
501         applyButton.setText(wb.getLang().getString("apply"));
502         paymentTypeLabel.setText(wb.getLang().getString("paymentForm"));
503         subTotalLabel.setText(wb.getLang().getString("subtotal"));
504         shipLabel.setText(wb.getLang().getString("shipHandling"));
505         taxLabel.setText(wb.getLang().getString("tax"));
506         totalLabel.setText(wb.getLang().getString("total"));
507         ordersPanel.setBorder(
508             new TitledBorder(
509                 null,
510                 wb.getLang().getString("orders"),
511                 TitledBorder.DEFAULT_JUSTIFICATION,
512                 TitledBorder.DEFAULT_POSITION,
513                 MainWindow.LABEL_FONT,
514                 MainWindow.LETTERS
515             )
516         );
517         detailsPanel.setBorder(
518             new TitledBorder(
519                 null,
520                 wb.getLang().getString("orderDetails"),
521                 TitledBorder.DEFAULT_JUSTIFICATION,
522                 TitledBorder.DEFAULT_POSITION,
523                 MainWindow.LABEL_FONT,
524                 MainWindow.LETTERS
525             )
526         );
527
528         tabbedPane.setTitleAt(0, wb.getLang().getString("billAddress"));
529         tabbedPane.setTitleAt(1, wb.getLang().getString("shipAddress"));
530
531         detailsModel.setLang();
532         orderModel.setLang();
533     }
534
535     /**
536      * calculate the sales tax for an order
537      * @param order the Order we are to calculate with
538      * @return the sales tax amount
539      */

540      private final double calculateSalesTax(Order order) {
541         ArrayList taxes=null;
542         double rate=0.00;
543
544         try {
545             taxes = wb.getStateTax(false);
546         } catch (AngError e) {
547             ErrorHandler.show(thisPanel, e);
548             return rate;
549         }
550
551         StateTax tax;
552
553         String JavaDoc stateCode = order.getShipAddress().getState();
554
555         for (int i=0;i<taxes.size();i++) {
556             tax = (StateTax)taxes.get(i);
557             if (tax.getCode().equals(stateCode)) {
558                 rate = tax.getRate();
559                 //System.out.println("found rate of " + rate);
560
break;
561             }
562         }
563
564         double subTotal = order.getQuote().calcSubTotal();
565         double totalTax = rate * subTotal;
566         BigDecimal uno = new BigDecimal(1.0);
567         BigDecimal tt = new BigDecimal(totalTax);
568         BigDecimal ttt = tt.divide(uno, 2, BigDecimal.ROUND_UP);
569         return ttt.doubleValue();
570      }
571
572     /**
573      * set the order and order details columns properties
574      */

575     private final void initTableColumns() {
576
577         //set up the order table column widths
578

579         TableColumn col = orderTable.getColumnModel().getColumn(0); //order number
580
col.setPreferredWidth(120);
581
582         //set up the order status combo box column
583
col = orderTable.getColumnModel().getColumn(1); //status
584
col.setPreferredWidth(120);
585         col.setCellEditor(new DefaultCellEditor(statusCombo));
586         DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
587         col.setCellRenderer(renderer);
588
589         col = orderTable.getColumnModel().getColumn(2); //quote name
590
col.setPreferredWidth(140);
591
592         col = orderTable.getColumnModel().getColumn(4); //created by
593
col.setPreferredWidth(120);
594
595         //set the order details column width defaults
596

597         col = orderDetailsTable.getColumnModel().getColumn(0); //prodname
598
col.setPreferredWidth(120);
599         col = orderDetailsTable.getColumnModel().getColumn(1); //qty
600
col.setPreferredWidth(40);
601         col = orderDetailsTable.getColumnModel().getColumn(2); //model
602
col.setPreferredWidth(100);
603         col = orderDetailsTable.getColumnModel().getColumn(3); //price
604
col.setPreferredWidth(80);
605         col = orderDetailsTable.getColumnModel().getColumn(4); //desc
606
col.setPreferredWidth(120);
607     }
608 }
609
Popular Tags