PageRenderTime 173ms CodeModel.GetById 81ms app.highlight 11ms RepoModel.GetById 79ms app.codeStats 0ms

/src/mpv5/db/objects/Expense.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 233 lines | 127 code | 29 blank | 77 comment | 3 complexity | 2b4feb07182007943c3460a1f3e75b07 MD5 | raw file
  1/*
  2 *  This file is part of YaBS.
  3 *
  4 *      YaBS is free software: you can redistribute it and/or modify
  5 *      it under the terms of the GNU General Public License as published by
  6 *      the Free Software Foundation, either version 3 of the License, or
  7 *      (at your option) any later version.
  8 *
  9 *      YaBS is distributed in the hope that it will be useful,
 10 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12 *      GNU General Public License for more details.
 13 *
 14 *      You should have received a copy of the GNU General Public License
 15 *      along with YaBS.  If not, see <http://www.gnu.org/licenses/>.
 16 */
 17package mpv5.db.objects;
 18
 19import java.math.BigDecimal;
 20import java.util.ArrayList;
 21import java.util.Date;
 22import javax.swing.JComponent;
 23import mpv5.db.common.Context;
 24import mpv5.db.common.DatabaseObject;
 25import mpv5.db.common.Formattable;
 26import mpv5.db.common.NodataFoundException;
 27import mpv5.handler.FormatHandler;
 28import mpv5.logging.Log;
 29import mpv5.ui.panels.ExpensePanel;
 30import mpv5.utils.images.MPIcon;
 31import mpv5.utils.numberformat.FormatNumber;
 32
 33/**
 34 *
 35 *  
 36 */
 37public class Expense extends DatabaseObject implements Formattable {
 38
 39    public static int TYPE_EXPENSE = 43;
 40    private String description = "";
 41    private BigDecimal netvalue;
 42    private BigDecimal taxpercentvalue;
 43    private BigDecimal brutvalue;
 44    private String cnumber;
 45    private int accountsids;
 46    private FormatHandler formatHandler;
 47    private Date dateend = new Date();
 48    private boolean ispaid;
 49
 50    public Expense() {
 51        setContext(Context.getExpense());
 52    }
 53
 54    /**
 55     * @return the description
 56     */
 57    public String __getDescription() {
 58        return description;
 59    }
 60
 61    /**
 62     * @param description the description to set
 63     */
 64    public void setDescription(String description) {
 65        this.description = description;
 66    }
 67
 68    @Override
 69    public String toString() {
 70        return __getCname();
 71    }
 72
 73    @Override
 74    public JComponent getView() {
 75        return ExpensePanel.instanceOf();
 76    }
 77
 78    @Override
 79    public mpv5.utils.images.MPIcon getIcon() {
 80        return new MPIcon("/mpv5/resources/images/22/1downarrow.png");
 81    }
 82
 83    /**
 84     * @return the netvalue
 85     */
 86    public BigDecimal __getNetvalue() {
 87        return netvalue;
 88    }
 89
 90    /**
 91     * @param netvalue the netvalue to set
 92     */
 93    public void setNetvalue(BigDecimal netvalue) {
 94        this.netvalue = netvalue;
 95    }
 96
 97    /**
 98     * @return the taxpercentvalue
 99     */
100    public BigDecimal __getTaxpercentvalue() {
101        return taxpercentvalue;
102    }
103
104    /**
105     * @param taxpercentvalue the taxpercentvalue to set
106     */
107    public void setTaxpercentvalue(BigDecimal taxpercentvalue) {
108        this.taxpercentvalue = taxpercentvalue;
109    }
110
111    /**
112     * @return the brutvalue
113     */
114    public BigDecimal __getBrutvalue() {
115        return brutvalue;
116    }
117
118    /**
119     * @param brutvalue the brutvalue to set
120     */
121    public void setBrutvalue(BigDecimal brutvalue) {
122        this.brutvalue = brutvalue;
123    }
124
125    /**
126     * @return the accountsids
127     */
128    public int __getAccountsids() {
129        return accountsids;
130    }
131
132    /**
133     * @param accountsids the accountsids to set
134     */
135    public void setAccountsids(int accountsids) {
136        this.accountsids = accountsids;
137    }
138
139    public FormatHandler getFormatHandler() {
140        if (formatHandler == null) {
141            formatHandler = new FormatHandler(this);
142        }
143        return formatHandler;
144    }
145
146    @Override
147    public void ensureUniqueness() {
148        setCnumber(getFormatHandler().next());
149        setCname(__getCnumber());
150    }
151
152    /**
153     * Create a table model's data from all expenses
154     * @return
155     * @throws NodataFoundException
156     */
157    public static Object[][] getExpenses() throws NodataFoundException {
158        ArrayList<DatabaseObject> data = getObjects(Context.getExpense());
159        Object[][] obj = new Object[data.size()][];
160        for (int i = 0; i < data.size(); i++) {
161            Expense e = (Expense) data.get(i);
162            obj[i] = e.toArray();
163        }
164        return obj;
165    }
166
167    /**
168     * Turn this expense into a table row
169     * @return
170     */
171    @Override
172    public Object[] toArray() {
173        Object[] o = new Object[6];
174        o[0] = this;
175        o[1] = description;
176        try {
177            o[2] = getObject(Context.getAccounts(), accountsids);
178        } catch (NodataFoundException ex) {
179            Log.Debug(this, ex.getMessage());
180        }
181        o[3] = FormatNumber.formatDezimal(brutvalue);
182        o[4] = FormatNumber.formatPercent(taxpercentvalue);
183        o[5] = ispaid;
184        return o;
185    }
186
187    /**
188     * @return the cnumber
189     */
190    public String __getCnumber() {
191        return cnumber;
192    }
193
194    /**
195     * @param cnumber the cnumber to set
196     */
197    public void setCnumber(String cnumber) {
198        this.cnumber = cnumber;
199    }
200
201
202    public void defineFormatHandler(FormatHandler handler) {
203        formatHandler = handler;
204    }
205
206    /**
207     * @return the dateend
208     */
209    public Date __getDateend() {
210        return dateend;
211    }
212
213    /**
214     * @param dateend the dateend to set
215     */
216    public void setDateend(Date dateend) {
217        this.dateend = dateend;
218    }
219
220    /**
221     * @return the paid
222     */
223    public boolean __getIspaid() {
224        return ispaid;
225    }
226
227    /**
228     * @param paid the paid to set
229     */
230    public void setIspaid(boolean paid) {
231        this.ispaid = paid;
232    }
233}