PageRenderTime 34ms CodeModel.GetById 13ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/src/mpv5/db/objects/Revenue.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 231 lines | 126 code | 28 blank | 77 comment | 3 complexity | 171dbe51a0ecf404e17d5aea93bfc998 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.RevenuePanel;
 30import mpv5.utils.images.MPIcon;
 31import mpv5.utils.numberformat.FormatNumber;
 32
 33/**
 34 *
 35 *  
 36 */
 37public class Revenue extends DatabaseObject implements Formattable {
 38
 39    public static int TYPE_REVENUE = 42;
 40    private String description = "";
 41    private BigDecimal netvalue = BigDecimal.ZERO;
 42    private BigDecimal taxpercentvalue = BigDecimal.ZERO;
 43    private BigDecimal brutvalue = BigDecimal.ZERO;
 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 Revenue() {
 51        setContext(Context.getRevenue());
 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 RevenuePanel.instanceOf();
 76    }
 77
 78    @Override
 79    public mpv5.utils.images.MPIcon getIcon() {
 80        return new MPIcon("/mpv5/resources/images/22/1uparrow.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    @Override
140    public FormatHandler getFormatHandler() {
141        if (formatHandler == null) {
142            formatHandler = new FormatHandler(this);
143        }
144        return formatHandler;
145    }
146
147    @Override
148    public void ensureUniqueness() {
149        setCnumber(getFormatHandler().next());
150        setCname(__getCnumber());
151    }
152
153    /**
154     * Create a table model's data from all revenues
155     * @return
156     * @throws NodataFoundException
157     */
158    public static Object[][] getRevenues() throws NodataFoundException {
159        ArrayList<DatabaseObject> data = getObjects(Context.getRevenue());
160        Object[][] obj = new Object[data.size()][];
161        for (int i = 0; i < data.size(); i++) {
162            Revenue e = (Revenue) data.get(i);
163            obj[i] = e.toArray();
164        }
165        return obj;
166    }
167
168    /**
169     * Turn this revenue into a table row
170     * @return
171     */
172    public Object[] toArray() {
173        Object[] o = new Object[5];
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        return o;
184    }
185
186    /**
187     * @return the cnumber
188     */
189    public String __getCnumber() {
190        return cnumber;
191    }
192
193    /**
194     * @param cnumber the cnumber to set
195     */
196    public void setCnumber(String cnumber) {
197        this.cnumber = cnumber;
198    }
199
200    public void defineFormatHandler(FormatHandler handler) {
201        formatHandler = handler;
202    }
203
204    /**
205     * @return the dateend
206     */
207    public Date __getDateend() {
208        return dateend;
209    }
210
211    /**
212     * @param dateend the dateend to set
213     */
214    public void setDateend(Date dateend) {
215        this.dateend = dateend;
216    }
217
218    /**
219     * @return the ispaid
220     */
221    public boolean __getIspaid() {
222        return ispaid;
223    }
224
225    /**
226     * @param ispaid the ispaid to set
227     */
228    public void setIspaid(boolean ispaid) {
229        this.ispaid = ispaid;
230    }
231}