PageRenderTime 38ms CodeModel.GetById 22ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
  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. */
  17. package mpv5.db.objects;
  18. import java.math.BigDecimal;
  19. import java.util.ArrayList;
  20. import java.util.Date;
  21. import javax.swing.JComponent;
  22. import mpv5.db.common.Context;
  23. import mpv5.db.common.DatabaseObject;
  24. import mpv5.db.common.Formattable;
  25. import mpv5.db.common.NodataFoundException;
  26. import mpv5.handler.FormatHandler;
  27. import mpv5.logging.Log;
  28. import mpv5.ui.panels.ExpensePanel;
  29. import mpv5.utils.images.MPIcon;
  30. import mpv5.utils.numberformat.FormatNumber;
  31. /**
  32. *
  33. *
  34. */
  35. public class Expense extends DatabaseObject implements Formattable {
  36. public static int TYPE_EXPENSE = 43;
  37. private String description = "";
  38. private BigDecimal netvalue;
  39. private BigDecimal taxpercentvalue;
  40. private BigDecimal brutvalue;
  41. private String cnumber;
  42. private int accountsids;
  43. private FormatHandler formatHandler;
  44. private Date dateend = new Date();
  45. private boolean ispaid;
  46. public Expense() {
  47. setContext(Context.getExpense());
  48. }
  49. /**
  50. * @return the description
  51. */
  52. public String __getDescription() {
  53. return description;
  54. }
  55. /**
  56. * @param description the description to set
  57. */
  58. public void setDescription(String description) {
  59. this.description = description;
  60. }
  61. @Override
  62. public String toString() {
  63. return __getCname();
  64. }
  65. @Override
  66. public JComponent getView() {
  67. return ExpensePanel.instanceOf();
  68. }
  69. @Override
  70. public mpv5.utils.images.MPIcon getIcon() {
  71. return new MPIcon("/mpv5/resources/images/22/1downarrow.png");
  72. }
  73. /**
  74. * @return the netvalue
  75. */
  76. public BigDecimal __getNetvalue() {
  77. return netvalue;
  78. }
  79. /**
  80. * @param netvalue the netvalue to set
  81. */
  82. public void setNetvalue(BigDecimal netvalue) {
  83. this.netvalue = netvalue;
  84. }
  85. /**
  86. * @return the taxpercentvalue
  87. */
  88. public BigDecimal __getTaxpercentvalue() {
  89. return taxpercentvalue;
  90. }
  91. /**
  92. * @param taxpercentvalue the taxpercentvalue to set
  93. */
  94. public void setTaxpercentvalue(BigDecimal taxpercentvalue) {
  95. this.taxpercentvalue = taxpercentvalue;
  96. }
  97. /**
  98. * @return the brutvalue
  99. */
  100. public BigDecimal __getBrutvalue() {
  101. return brutvalue;
  102. }
  103. /**
  104. * @param brutvalue the brutvalue to set
  105. */
  106. public void setBrutvalue(BigDecimal brutvalue) {
  107. this.brutvalue = brutvalue;
  108. }
  109. /**
  110. * @return the accountsids
  111. */
  112. public int __getAccountsids() {
  113. return accountsids;
  114. }
  115. /**
  116. * @param accountsids the accountsids to set
  117. */
  118. public void setAccountsids(int accountsids) {
  119. this.accountsids = accountsids;
  120. }
  121. public FormatHandler getFormatHandler() {
  122. if (formatHandler == null) {
  123. formatHandler = new FormatHandler(this);
  124. }
  125. return formatHandler;
  126. }
  127. @Override
  128. public void ensureUniqueness() {
  129. setCnumber(getFormatHandler().next());
  130. setCname(__getCnumber());
  131. }
  132. /**
  133. * Create a table model's data from all expenses
  134. * @return
  135. * @throws NodataFoundException
  136. */
  137. public static Object[][] getExpenses() throws NodataFoundException {
  138. ArrayList<DatabaseObject> data = getObjects(Context.getExpense());
  139. Object[][] obj = new Object[data.size()][];
  140. for (int i = 0; i < data.size(); i++) {
  141. Expense e = (Expense) data.get(i);
  142. obj[i] = e.toArray();
  143. }
  144. return obj;
  145. }
  146. /**
  147. * Turn this expense into a table row
  148. * @return
  149. */
  150. @Override
  151. public Object[] toArray() {
  152. Object[] o = new Object[6];
  153. o[0] = this;
  154. o[1] = description;
  155. try {
  156. o[2] = getObject(Context.getAccounts(), accountsids);
  157. } catch (NodataFoundException ex) {
  158. Log.Debug(this, ex.getMessage());
  159. }
  160. o[3] = FormatNumber.formatDezimal(brutvalue);
  161. o[4] = FormatNumber.formatPercent(taxpercentvalue);
  162. o[5] = ispaid;
  163. return o;
  164. }
  165. /**
  166. * @return the cnumber
  167. */
  168. public String __getCnumber() {
  169. return cnumber;
  170. }
  171. /**
  172. * @param cnumber the cnumber to set
  173. */
  174. public void setCnumber(String cnumber) {
  175. this.cnumber = cnumber;
  176. }
  177. public void defineFormatHandler(FormatHandler handler) {
  178. formatHandler = handler;
  179. }
  180. /**
  181. * @return the dateend
  182. */
  183. public Date __getDateend() {
  184. return dateend;
  185. }
  186. /**
  187. * @param dateend the dateend to set
  188. */
  189. public void setDateend(Date dateend) {
  190. this.dateend = dateend;
  191. }
  192. /**
  193. * @return the paid
  194. */
  195. public boolean __getIspaid() {
  196. return ispaid;
  197. }
  198. /**
  199. * @param paid the paid to set
  200. */
  201. public void setIspaid(boolean paid) {
  202. this.ispaid = paid;
  203. }
  204. }