PageRenderTime 38ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/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
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.RevenuePanel;
  29. import mpv5.utils.images.MPIcon;
  30. import mpv5.utils.numberformat.FormatNumber;
  31. /**
  32. *
  33. *
  34. */
  35. public class Revenue extends DatabaseObject implements Formattable {
  36. public static int TYPE_REVENUE = 42;
  37. private String description = "";
  38. private BigDecimal netvalue = BigDecimal.ZERO;
  39. private BigDecimal taxpercentvalue = BigDecimal.ZERO;
  40. private BigDecimal brutvalue = BigDecimal.ZERO;
  41. private String cnumber;
  42. private int accountsids;
  43. private FormatHandler formatHandler;
  44. private Date dateend = new Date();
  45. private boolean ispaid;
  46. public Revenue() {
  47. setContext(Context.getRevenue());
  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 RevenuePanel.instanceOf();
  68. }
  69. @Override
  70. public mpv5.utils.images.MPIcon getIcon() {
  71. return new MPIcon("/mpv5/resources/images/22/1uparrow.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. @Override
  122. public FormatHandler getFormatHandler() {
  123. if (formatHandler == null) {
  124. formatHandler = new FormatHandler(this);
  125. }
  126. return formatHandler;
  127. }
  128. @Override
  129. public void ensureUniqueness() {
  130. setCnumber(getFormatHandler().next());
  131. setCname(__getCnumber());
  132. }
  133. /**
  134. * Create a table model's data from all revenues
  135. * @return
  136. * @throws NodataFoundException
  137. */
  138. public static Object[][] getRevenues() throws NodataFoundException {
  139. ArrayList<DatabaseObject> data = getObjects(Context.getRevenue());
  140. Object[][] obj = new Object[data.size()][];
  141. for (int i = 0; i < data.size(); i++) {
  142. Revenue e = (Revenue) data.get(i);
  143. obj[i] = e.toArray();
  144. }
  145. return obj;
  146. }
  147. /**
  148. * Turn this revenue into a table row
  149. * @return
  150. */
  151. public Object[] toArray() {
  152. Object[] o = new Object[5];
  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. return o;
  163. }
  164. /**
  165. * @return the cnumber
  166. */
  167. public String __getCnumber() {
  168. return cnumber;
  169. }
  170. /**
  171. * @param cnumber the cnumber to set
  172. */
  173. public void setCnumber(String cnumber) {
  174. this.cnumber = cnumber;
  175. }
  176. public void defineFormatHandler(FormatHandler handler) {
  177. formatHandler = handler;
  178. }
  179. /**
  180. * @return the dateend
  181. */
  182. public Date __getDateend() {
  183. return dateend;
  184. }
  185. /**
  186. * @param dateend the dateend to set
  187. */
  188. public void setDateend(Date dateend) {
  189. this.dateend = dateend;
  190. }
  191. /**
  192. * @return the ispaid
  193. */
  194. public boolean __getIspaid() {
  195. return ispaid;
  196. }
  197. /**
  198. * @param ispaid the ispaid to set
  199. */
  200. public void setIspaid(boolean ispaid) {
  201. this.ispaid = ispaid;
  202. }
  203. }