PageRenderTime 854ms CodeModel.GetById 181ms app.highlight 490ms RepoModel.GetById 174ms app.codeStats 0ms

/src/mpv5/ui/panels/RevenuePanel.java

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