PageRenderTime 206ms CodeModel.GetById 56ms app.highlight 112ms RepoModel.GetById 29ms app.codeStats 0ms

/src/mpv5/ui/panels/ExpensePanel.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 749 lines | 588 code | 85 blank | 76 comment | 18 complexity | 5531523e492596b01e7660ad3a5b3bcf MD5 | raw file
  1/*
  2This file is part of YaBS.
  3
  4YaBS is free software: you can redistribute it and/or modify
  5it under the terms of the GNU General Public License as published by
  6the Free Software Foundation, either version 3 of the License, or
  7(at your option) any later version.
  8
  9YaBS is distributed in the hope that it will be useful,
 10but WITHOUT ANY WARRANTY; without even the implied warranty of
 11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12GNU General Public License for more details.
 13
 14You should have received a copy of the GNU General Public License
 15along with YaBS.  If not, see <http://www.gnu.org/licenses/>.
 16 */
 17/*
 18 * ContactPanel.java
 19 *
 20 * Created on Nov 20, 2008, 8:17:28 AM
 21 */
 22package mpv5.ui.panels;
 23
 24import java.awt.BorderLayout;
 25import java.awt.Color;
 26import java.awt.Component;
 27import java.awt.event.ActionEvent;
 28import java.awt.event.ActionListener;
 29import java.awt.event.KeyEvent;
 30import java.awt.event.KeyListener;
 31import java.math.BigDecimal;
 32import java.math.RoundingMode;
 33import java.util.ArrayList;
 34import java.util.Date;
 35import javax.swing.JComponent;
 36import javax.swing.JFrame;
 37import javax.swing.JTabbedPane;
 38import javax.swing.JTable;
 39import javax.swing.JViewport;
 40import javax.swing.SwingUtilities;
 41import javax.swing.table.TableCellRenderer;
 42import mpv5.db.common.*;
 43import mpv5.db.objects.Account;
 44import mpv5.db.objects.Expense;
 45import mpv5.globals.Messages;
 46import mpv5.db.objects.Favourite;
 47import mpv5.db.objects.Tax;
 48import mpv5.db.objects.Template;
 49import mpv5.logging.Log;
 50import mpv5.ui.dialogs.Popup;
 51import mpv5.ui.toolbars.DataPanelTB;
 52import mpv5.db.objects.User;
 53import mpv5.globals.Constants;
 54import mpv5.globals.Headers;
 55import mpv5.ui.misc.MPTable;
 56import mpv5.utils.export.Exportable;
 57import mpv5.utils.models.MPComboBoxModelItem;
 58import mpv5.utils.models.MPTableModel;
 59import mpv5.utils.numberformat.FormatNumber;
 60import mpv5.ui.misc.TableViewPersistenceHandler;
 61import mpv5.utils.tables.TableFormat;
 62import mpv5.utils.ui.TextFieldUtils;
 63
 64/**
 65 *
 66 * 
 67 */
 68public class ExpensePanel extends javax.swing.JPanel implements DataPanel {
 69    
 70    private static final long serialVersionUID = 1L;
 71    private static ExpensePanel me;
 72    private ArrayList<DatabaseObject> accmod;
 73    private BigDecimal tax = BigDecimal.ZERO;
 74    private java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle();
 75
 76    /**
 77     * Singleton
 78     * @return
 79     */
 80    public static ExpensePanel instanceOf() {
 81        if (me == null) {
 82            me = new ExpensePanel();
 83        }
 84        me.refresh();
 85        return me;
 86    }
 87    private Expense dataOwner;
 88    private DataPanelTB tb;
 89
 90    /** Creates new form ContactPanel
 91     */
 92    public ExpensePanel() {
 93        initComponents();
 94        setName("expensepanel");
 95        tb = new mpv5.ui.toolbars.DataPanelTB(this);
 96        tb.disableButton(1);
 97        tb.disableButton(8);
 98        tb.disableButton(9);
 99        toolbarpane.add(tb, BorderLayout.CENTER);
100        dataOwner = new Expense();
101        
102        addedby.setText(mpv5.db.objects.User.getCurrentUser().getName());
103        
104        groupnameselect.setSearchEnabled(true);
105        groupnameselect.setContext(Context.getGroup());
106        taxrate.setSearchEnabled(true);
107        taxrate.setContext(Context.getTaxes());
108        
109        value.getTextField().addKeyListener(new KeyListener() {
110            
111            public void keyTyped(KeyEvent e) {
112                calculate();
113            }
114            
115            public void keyPressed(KeyEvent ek) {
116                calculate();
117            }
118            
119            public void keyReleased(KeyEvent e) {
120                calculate();
121            }
122        });
123        
124        taxrate.getComboBox().addActionListener(new ActionListener() {
125            
126            public void actionPerformed(ActionEvent e) {
127                getTaxRate();
128            }
129        });
130        getTaxRate();
131        taxrate.getComboBox().setEditable(false);
132        itemtable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
133        itemtable.setFillsViewportHeight(true);
134        ((MPTable) itemtable).setDefaultColumns(new Integer[]{100, 333, 100}, new Boolean[]{});
135        ((MPTable) itemtable).setPersistanceHandler(new TableViewPersistenceHandler((MPTable) itemtable, this));
136        
137    }
138    
139    private void calculate() {
140        try {
141            netvalue.setText(FormatNumber.formatLokalCurrency(FormatNumber.parseDezimal(value.getText()).divide((tax.divide(Constants.BD100, 9, RoundingMode.HALF_UP)).add(BigDecimal.ONE), 9, RoundingMode.HALF_UP)));
142        } catch (Exception e) {
143            Log.Debug(e);
144            netvalue.setText(FormatNumber.formatLokalCurrency(0d));
145        }
146    }
147    
148    @Override
149    public DatabaseObject getDataOwner() {
150        return dataOwner;
151    }
152    
153    @Override
154    public void setDataOwner(DatabaseObject object, boolean populate) {
155        dataOwner = (Expense) object;
156        if (populate) {
157            dataOwner.setPanelData(this);
158            
159            this.exposeData();
160            setTitle();
161            
162            tb.setFavourite(Favourite.isFavourite(object));
163            tb.setEditable(!object.isReadOnly());
164            
165            formatTable();
166            if (object.isReadOnly()) {
167                Popup.notice(Messages.LOCKED_BY);
168            }
169            
170            validate();
171        }
172    }
173    Exportable preloadedExportFile;
174    Template preloadedTemplate;
175    
176    private void setTitle() {
177        if (this.getParent() instanceof JViewport || this.getParent() instanceof JTabbedPane) {
178            JTabbedPane jTabbedPane = null;
179            String title1 = cname_;
180            //this->viewport->scrollpane->tabbedpane
181            if (this.getParent().getParent().getParent() instanceof JTabbedPane) {
182                jTabbedPane = (JTabbedPane) this.getParent().getParent().getParent();
183            } else {
184                try {
185                    jTabbedPane = (JTabbedPane) this.getParent();
186                } catch (Exception e) {
187                    //Free floating window
188                    ((JFrame) this.getRootPane().getParent()).setTitle(title1);
189                }
190            }
191            if (jTabbedPane != null) {
192                jTabbedPane.setTitleAt(jTabbedPane.getSelectedIndex(), title1);
193            }
194        }
195    }
196    
197    @Override
198    public void showRequiredFields() {
199        TextFieldUtils.blinkerRed(value);
200    }
201
202    /** This method is called from within the constructor to
203     * initialize the form.
204     * WARNING: Do NOT modify this code. The content of this method is
205     * always regenerated by the Form Editor.
206     */
207    @SuppressWarnings("unchecked")
208    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
209    private void initComponents() {
210
211        buttonGroup1 = new javax.swing.ButtonGroup();
212        rightpane = new javax.swing.JPanel();
213        jPanel1 = new javax.swing.JPanel();
214        number = new mpv5.ui.beans.LabeledTextField();
215        addedby = new javax.swing.JLabel();
216        jLabel4 = new javax.swing.JLabel();
217        accountselect = new mpv5.ui.beans.LabeledCombobox();
218        groupnameselect = new mpv5.ui.beans.MPCombobox();
219        jPanel2 = new javax.swing.JPanel();
220        value = new mpv5.ui.beans.LabeledTextField();
221        netvalue = new mpv5.ui.beans.LabeledTextField();
222        jLabel1 = new javax.swing.JLabel();
223        jScrollPane1 = new javax.swing.JScrollPane();
224        notes = new javax.swing.JEditorPane();
225        taxrate = new mpv5.ui.beans.LabeledCombobox();
226        path = new javax.swing.JLabel();
227        labeledDateChooser1 = new mpv5.ui.beans.LabeledDateChooser();
228        jCheckBox1 = new javax.swing.JCheckBox();
229        paydate = new mpv5.ui.beans.LabeledDateChooser();
230        jPanel4 = new javax.swing.JPanel();
231        jScrollPane3 = new javax.swing.JScrollPane();
232        itemtable = new  mpv5.ui.misc.MPTable(this) {
233            private static final long serialVersionUID = 1L;
234            public Component prepareRenderer(TableCellRenderer renderer,
235                int rowIndex, int vColIndex) {
236                Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
237                if (c instanceof JComponent) {
238                    JComponent jc = (JComponent)c;
239                    jc.setToolTipText(String.valueOf(getValueAt(rowIndex, vColIndex)));
240                }
241                return c;
242            }
243        };
244        toolbarpane = new javax.swing.JPanel();
245
246        setBackground(new java.awt.Color(176, 158, 158));
247        java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
248        setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ExpensePanel.border.title_1"))); // NOI18N
249        setName("Form"); // NOI18N
250        setOpaque(false);
251        setLayout(new java.awt.BorderLayout());
252
253        rightpane.setBorder(javax.swing.BorderFactory.createEtchedBorder());
254        rightpane.setName("rightpane"); // NOI18N
255
256        jPanel1.setBackground(new java.awt.Color(254, 254, 254));
257        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
258        jPanel1.setName("jPanel1"); // NOI18N
259
260        number.set_Label(bundle.getString("ExpensePanel.number._Label")); // NOI18N
261        number.setEnabled(false);
262        number.setFocusable(false);
263        number.setFont(number.getFont());
264        number.setName("number"); // NOI18N
265
266        addedby.setFont(addedby.getFont());
267        addedby.setText(bundle.getString("ExpensePanel.addedby.text")); // NOI18N
268        addedby.setToolTipText(bundle.getString("ExpensePanel.addedby.toolTipText")); // NOI18N
269        addedby.setBorder(javax.swing.BorderFactory.createEtchedBorder());
270        addedby.setEnabled(false);
271        addedby.setName("addedby"); // NOI18N
272
273        jLabel4.setFont(jLabel4.getFont());
274        jLabel4.setText(bundle.getString("ExpensePanel.jLabel4.text")); // NOI18N
275        jLabel4.setName("jLabel4"); // NOI18N
276
277        accountselect.set_Label(bundle.getString("ExpensePanel.accountselect._Label")); // NOI18N
278        accountselect.setName("accountselect"); // NOI18N
279        accountselect.setSearchOnEnterEnabled(false);
280
281        groupnameselect.setName("groupnameselect"); // NOI18N
282
283        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
284        jPanel2.setName("jPanel2"); // NOI18N
285
286        value.set_Label(bundle.getString("ExpensePanel.value._Label")); // NOI18N
287        value.set_Text(bundle.getString("ExpensePanel.value._Text")); // NOI18N
288        value.setName("value"); // NOI18N
289
290        netvalue.set_Label(bundle.getString("ExpensePanel.netvalue._Label")); // NOI18N
291        netvalue.set_Text(bundle.getString("ExpensePanel.netvalue._Text")); // NOI18N
292        netvalue.setEnabled(false);
293        netvalue.setName("netvalue"); // NOI18N
294
295        jLabel1.setText(bundle.getString("ExpensePanel.jLabel1.text")); // NOI18N
296        jLabel1.setName("jLabel1"); // NOI18N
297
298        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
299        jScrollPane1.setName("jScrollPane1"); // NOI18N
300
301        notes.setBackground(new java.awt.Color(254, 254, 254));
302        notes.setName("notes"); // NOI18N
303        jScrollPane1.setViewportView(notes);
304
305        taxrate.set_Label(bundle.getString("ExpensePanel.taxrate._Label")); // NOI18N
306        taxrate.setName("taxrate"); // NOI18N
307        taxrate.addMouseListener(new java.awt.event.MouseAdapter() {
308            public void mouseClicked(java.awt.event.MouseEvent evt) {
309                taxrateMouseClicked(evt);
310            }
311            public void mouseExited(java.awt.event.MouseEvent evt) {
312                taxrateMouseExited(evt);
313            }
314        });
315
316        path.setText(bundle.getString("ExpensePanel.path.text")); // NOI18N
317        path.setName("path"); // NOI18N
318
319        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
320        jPanel2.setLayout(jPanel2Layout);
321        jPanel2Layout.setHorizontalGroup(
322            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
323            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
324                .addContainerGap()
325                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
326                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)
327                    .addComponent(path, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 720, Short.MAX_VALUE)
328                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
329                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
330                        .addComponent(value, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
331                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
332                        .addComponent(taxrate, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
333                        .addGap(18, 18, 18)
334                        .addComponent(netvalue, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE)))
335                .addContainerGap())
336        );
337        jPanel2Layout.setVerticalGroup(
338            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
339            .addGroup(jPanel2Layout.createSequentialGroup()
340                .addContainerGap()
341                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
342                    .addComponent(value, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
343                    .addComponent(taxrate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
344                    .addComponent(netvalue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
345                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
346                .addComponent(jLabel1)
347                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
348                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
349                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
350                .addComponent(path, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
351                .addGap(0, 0, 0))
352        );
353
354        labeledDateChooser1.set_Label(bundle.getString("ExpensePanel.labeledDateChooser1._Label")); // NOI18N
355        labeledDateChooser1.setName("labeledDateChooser1"); // NOI18N
356
357        jCheckBox1.setText(bundle.getString("ExpensePanel.jCheckBox1.text")); // NOI18N
358        jCheckBox1.setMargin(new java.awt.Insets(2, 0, 2, 2));
359        jCheckBox1.setName("jCheckBox1"); // NOI18N
360        jCheckBox1.setOpaque(false);
361        jCheckBox1.addItemListener(new java.awt.event.ItemListener() {
362            public void itemStateChanged(java.awt.event.ItemEvent evt) {
363                jCheckBox1ItemStateChanged(evt);
364            }
365        });
366
367        paydate.set_Label(bundle.getString("ExpensePanel.paydate._Label")); // NOI18N
368        paydate.setName("paydate"); // NOI18N
369
370        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
371        jPanel1.setLayout(jPanel1Layout);
372        jPanel1Layout.setHorizontalGroup(
373            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
374            .addGroup(jPanel1Layout.createSequentialGroup()
375                .addContainerGap()
376                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
377                    .addGroup(jPanel1Layout.createSequentialGroup()
378                        .addComponent(number, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
379                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
380                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
381                            .addComponent(paydate, javax.swing.GroupLayout.PREFERRED_SIZE, 238, javax.swing.GroupLayout.PREFERRED_SIZE)
382                            .addComponent(labeledDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 238, javax.swing.GroupLayout.PREFERRED_SIZE)))
383                    .addComponent(accountselect, javax.swing.GroupLayout.PREFERRED_SIZE, 460, javax.swing.GroupLayout.PREFERRED_SIZE))
384                .addGap(38, 38, 38)
385                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
386                    .addComponent(jCheckBox1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
387                    .addGroup(jPanel1Layout.createSequentialGroup()
388                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
389                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
390                        .addComponent(addedby, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
391                    .addComponent(groupnameselect, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE))
392                .addContainerGap())
393            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
394        );
395        jPanel1Layout.setVerticalGroup(
396            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
397            .addGroup(jPanel1Layout.createSequentialGroup()
398                .addContainerGap()
399                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
400                    .addComponent(accountselect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
401                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
402                    .addComponent(addedby, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
403                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
404                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
405                    .addComponent(labeledDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
406                    .addComponent(number, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
407                    .addComponent(groupnameselect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
408                .addGap(10, 10, 10)
409                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
410                    .addComponent(jCheckBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
411                    .addComponent(paydate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
412                .addGap(8, 8, 8)
413                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
414        );
415
416        jPanel4.setBackground(new java.awt.Color(204, 204, 204));
417        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());
418        jPanel4.setName("jPanel4"); // NOI18N
419
420        jScrollPane3.setName("jScrollPane3"); // NOI18N
421
422        itemtable.setAutoCreateRowSorter(true);
423        itemtable.setModel(new javax.swing.table.DefaultTableModel(
424            new Object [][] {
425
426            },
427            new String [] {
428
429            }
430        ));
431        itemtable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
432        itemtable.setName("itemtable"); // NOI18N
433        itemtable.setSurrendersFocusOnKeystroke(true);
434        itemtable.addMouseListener(new java.awt.event.MouseAdapter() {
435            public void mouseClicked(java.awt.event.MouseEvent evt) {
436                itemtableMouseClicked(evt);
437            }
438        });
439        jScrollPane3.setViewportView(itemtable);
440
441        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
442        jPanel4.setLayout(jPanel4Layout);
443        jPanel4Layout.setHorizontalGroup(
444            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
445            .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 744, Short.MAX_VALUE)
446        );
447        jPanel4Layout.setVerticalGroup(
448            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
449            .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)
450        );
451
452        javax.swing.GroupLayout rightpaneLayout = new javax.swing.GroupLayout(rightpane);
453        rightpane.setLayout(rightpaneLayout);
454        rightpaneLayout.setHorizontalGroup(
455            rightpaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
456            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
457            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
458        );
459        rightpaneLayout.setVerticalGroup(
460            rightpaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
461            .addGroup(rightpaneLayout.createSequentialGroup()
462                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
463                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
464                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
465        );
466
467        add(rightpane, java.awt.BorderLayout.CENTER);
468
469        toolbarpane.setBorder(javax.swing.BorderFactory.createEtchedBorder());
470        toolbarpane.setName("toolbarpane"); // NOI18N
471        toolbarpane.setLayout(new java.awt.BorderLayout());
472        add(toolbarpane, java.awt.BorderLayout.NORTH);
473    }// </editor-fold>//GEN-END:initComponents
474
475    private void itemtableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_itemtableMouseClicked
476        try {
477            setDataOwner((DatabaseObject) itemtable.getModel().getValueAt(itemtable.getSelectedRow(), 0), true);
478        } catch (Exception e) {
479            Log.Debug(this, e.getMessage());
480        }
481    }//GEN-LAST:event_itemtableMouseClicked
482    
483    private void jCheckBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCheckBox1ItemStateChanged
484        if (jCheckBox1.isSelected()) {
485            paydate.setDate(new Date());
486        }
487    }//GEN-LAST:event_jCheckBox1ItemStateChanged
488    
489    private void taxrateMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_taxrateMouseExited
490        calculate();
491    }//GEN-LAST:event_taxrateMouseExited
492    
493    private void taxrateMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_taxrateMouseClicked
494        calculate();
495    }//GEN-LAST:event_taxrateMouseClicked
496    MPTableModel omodel = null;
497    // Variables declaration - do not modify//GEN-BEGIN:variables
498    private mpv5.ui.beans.LabeledCombobox accountselect;
499    private javax.swing.JLabel addedby;
500    private javax.swing.ButtonGroup buttonGroup1;
501    private mpv5.ui.beans.MPCombobox groupnameselect;
502    private javax.swing.JTable itemtable;
503    private javax.swing.JCheckBox jCheckBox1;
504    private javax.swing.JLabel jLabel1;
505    private javax.swing.JLabel jLabel4;
506    private javax.swing.JPanel jPanel1;
507    private javax.swing.JPanel jPanel2;
508    private javax.swing.JPanel jPanel4;
509    private javax.swing.JScrollPane jScrollPane1;
510    private javax.swing.JScrollPane jScrollPane3;
511    private mpv5.ui.beans.LabeledDateChooser labeledDateChooser1;
512    private mpv5.ui.beans.LabeledTextField netvalue;
513    private javax.swing.JEditorPane notes;
514    private mpv5.ui.beans.LabeledTextField number;
515    private javax.swing.JLabel path;
516    private mpv5.ui.beans.LabeledDateChooser paydate;
517    private javax.swing.JPanel rightpane;
518    private mpv5.ui.beans.LabeledCombobox taxrate;
519    private javax.swing.JPanel toolbarpane;
520    private mpv5.ui.beans.LabeledTextField value;
521    // End of variables declaration//GEN-END:variables
522    public String cname_;
523    public String description_;
524    public String cnumber_;
525    public int intaddedby_;
526    public int ids_;
527    public Date dateadded_;
528    public int groupsids_ = 1;
529    public BigDecimal netvalue_;
530    public BigDecimal taxpercentvalue_;
531    public BigDecimal brutvalue_;
532    public int accountsids_;
533    public boolean ispaid_;
534    public Date dateend_;
535    
536    @Override
537    public synchronized boolean collectData() {
538        calculate();
539        
540        try {
541            accountsids_ = Integer.valueOf(accountselect.getSelectedItem().getId());
542            mpv5.db.objects.User.getCurrentUser().getProperties().changeProperty(me, "accountselect", accountsids_);
543        } catch (Exception e) {
544            accountsids_ = 1;
545        }
546        
547        if (groupnameselect.getSelectedItem() != null) {
548            groupsids_ = Integer.valueOf(groupnameselect.getSelectedItem().getId());
549            Log.Debug(this, groupnameselect.getSelectedItem().getId());
550        } else {
551            groupsids_ = 1;
552        }
553        
554        dateadded_ = labeledDateChooser1.getDate();
555        dateend_ = paydate.getDate();
556        ispaid_ = jCheckBox1.isSelected();
557        
558        intaddedby_ = User.getUserId(addedby.getText());
559        description_ = notes.getText();
560        try {
561            netvalue_ = FormatNumber.parseDezimal(netvalue.getText());
562        } catch (Exception e) {
563            netvalue_ = BigDecimal.ZERO;
564        }
565        try {
566            brutvalue_ = FormatNumber.parseDezimal(value.getText());
567        } catch (Exception e) {
568            brutvalue_ = BigDecimal.ZERO;
569        }
570        try {
571            taxpercentvalue_ = Tax.getTaxValue(Integer.valueOf(taxrate.getSelectedItem().getId()));
572        } catch (Exception numberFormatException) {
573            taxpercentvalue_ = BigDecimal.ZERO;
574        }
575        return true;
576    }
577    
578    @Override
579    public void exposeData() {
580        number.setText(cname_);
581        notes.setText(description_);
582        value.setText(FormatNumber.formatDezimal(brutvalue_));
583        netvalue.setText(FormatNumber.formatDezimal(netvalue_));
584        try {
585            Account a = (Account) DatabaseObject.getObject(Context.getAccounts(), accountsids_);
586            accountselect.setSelectedItem(a.__getIDS());
587            path.setText(a.__getHierarchypath());
588        } catch (NodataFoundException ex) {
589            Log.Debug(this, ex.getMessage());
590        }
591        try {
592            groupnameselect.setModel(DatabaseObject.getObject(Context.getGroup(), groupsids_));
593        } catch (NodataFoundException ex) {
594            Log.Debug(this, ex.getMessage());
595        }
596        addedby.setText(User.getUsername(intaddedby_));
597        labeledDateChooser1.setDate(dateadded_);
598        taxrate.setSelectedItem(Tax.getTaxId(taxpercentvalue_));
599        paydate.setDate(dateend_);
600        jCheckBox1.setSelected(ispaid_);
601        getTaxRate();
602    }
603    
604    @Override
605    public void refresh() {
606        Runnable runnable = new Runnable() {
607            
608            @Override
609            public void run() {
610                
611                groupnameselect.triggerSearch();
612                taxrate.triggerSearch();
613                try {
614                    MPTableModel x = new MPTableModel(Expense.getExpenses(), Headers.EXPENSE);
615                    x.setTypes(String.class, String.class, String.class, String.class, String.class, Boolean.class);
616                    itemtable.setModel(x);
617                } catch (NodataFoundException e) {
618                    Log.Debug(this, e.getMessage());
619                }
620                try {
621                    accmod = DatabaseObject.getObjects(Context.getAccounts(), new QueryCriteria("intaccounttype", Account.EXPENSE));
622                    accountselect.setModel(accmod);
623                } catch (NodataFoundException e) {
624                    Log.Debug(this, e.getMessage());
625                }
626                try {
627                    accountselect.setSelectedItem(mpv5.db.objects.User.getCurrentUser().getProperties().getProperty(me, "accountselect", 1));
628                    formatTable();
629                } catch (Exception e) {
630                    Log.Debug(this, e.getMessage());
631                }
632                getTaxRate();
633            }
634        };
635        
636        SwingUtilities.invokeLater(runnable);
637    }
638
639    /**
640     * 
641     */
642    public void formatTable() {
643//        TableFormat.resizeCols(itemtable, new Integer[]{100, 333, 100}, false);
644    }
645    
646    @Override
647    public void paste(DatabaseObject... dbo) {
648        mpv5.YabsViewProxy.instance().addMessage(Messages.NOT_POSSIBLE.toString() + Messages.ACTION_PASTE.toString(), Color.RED);
649    }
650    
651    @Override
652    public void showSearchBar(boolean show) {
653    }
654    
655    @Override
656    public void actionAfterSave() {
657        Runnable runnable = new Runnable() {
658            
659            public void run() {
660                try {
661                    
662                    itemtable.setModel(new MPTableModel(Expense.getExpenses(), Headers.EXPENSE));
663                    formatTable();
664                    
665                } catch (NodataFoundException ex) {
666                }
667            }
668        };
669        SwingUtilities.invokeLater(runnable);
670    }
671    
672    @Override
673    public void actionAfterCreate() {
674        Runnable runnable = new Runnable() {
675            
676            public void run() {
677                try {
678                    
679                    itemtable.setModel(new MPTableModel(Expense.getExpenses(), Headers.EXPENSE));
680                    formatTable();
681                    
682                } catch (NodataFoundException ex) {
683                }
684            }
685        };
686        SwingUtilities.invokeLater(runnable);
687    }
688    
689    public void actionBeforeCreate() {
690    }
691    
692    public void actionBeforeSave() {
693    }
694    
695    public void mail() {
696    }
697    
698    public void print() {
699        mpv5.utils.export.Export.print(this);
700    }
701    
702    private void getTaxRate() {
703        try {
704            MPComboBoxModelItem t = taxrate.getValue();
705            if (t == null) {
706                tax = BigDecimal.ZERO;
707                taxrate.setSelectedIndex(-1);
708            } else {
709                tax = Tax.getTaxValue(Integer.valueOf(t.getId()));
710            }
711            Log.Debug(this, "Selected Taxrate: " + tax);
712        } catch (Exception ex) {
713            Log.Debug(this, "Reading Taxrate failed: Assuming Zero");
714            tax = BigDecimal.ZERO;
715        }
716        calculate();
717    }
718//    class calc extends Thread {
719//
720//        @Override
721//        public void run() {
722//            while (true) {
723//                while (isShowing()) {
724//                    BigDecimal tax = BigDecimal.ZERO;
725//                    try {
726//                        MPComboBoxModelItem t = taxrate.getValue();
727//                        tax = Tax.getTaxValue(Integer.valueOf(t.getId()));
728//                    } catch (Exception e) {
729//                        try {
730//                            tax = new BigDecimal(taxrate.getText());
731//                        } catch (NumberFormatException numberFormatException) {
732//                            tax = BigDecimal.ZERO;
733//                        }
734//                    }
735//
736//                    try {
737//                        netvalue.setText(FormatNumber.formatLokalCurrency(FormatNumber.parseDezimal(value.getText()).divide((tax.divide(Constants.BD100, 9, BigDecimal.ROUND_HALF_UP)).add(BigDecimal.ONE))));
738//                    } catch (Exception e) {
739//                        netvalue.setText(FormatNumber.formatLokalCurrency(0d));
740//                    }
741//                    try {
742//                        sleep(333);
743//                    } catch (InterruptedException ex) {
744//                    }
745//                }
746//            }
747//        }
748//    }
749}