PageRenderTime 110ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/mpv5/db/objects/ActivityList.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 216 lines | 161 code | 28 blank | 27 comment | 13 complexity | e4e8c156ca942b870a61504ffabdd40b 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 enoa.handler.TableHandler;
  19. import enoa.handler.TemplateHandler;
  20. import java.math.BigDecimal;
  21. import java.text.DateFormat;
  22. import java.util.ArrayList;
  23. import java.util.Collections;
  24. import java.util.HashMap;
  25. import java.util.List;
  26. import java.util.Locale;
  27. import java.util.Vector;
  28. import javax.swing.JComponent;
  29. import mpv5.db.common.Context;
  30. import mpv5.db.common.DatabaseObject;
  31. import mpv5.db.common.Formattable;
  32. import mpv5.db.common.NodataFoundException;
  33. import mpv5.db.common.Templateable;
  34. import mpv5.globals.Constants;
  35. import mpv5.globals.GlobalSettings;
  36. import mpv5.globals.Messages;
  37. import mpv5.handler.FormatHandler;
  38. import mpv5.logging.Log;
  39. import mpv5.ui.panels.ActivityConfirmationPanel;
  40. import mpv5.utils.images.MPIcon;
  41. import mpv5.utils.numberformat.FormatNumber;
  42. import mpv5.utils.text.TypeConversion;
  43. /**
  44. *
  45. *
  46. */
  47. public class ActivityList extends DatabaseObject implements Formattable, Templateable {
  48. private static final long serialVersionUID = 1L;
  49. private String cnumber;
  50. private int contactsids;
  51. private int orderids;
  52. private BigDecimal totalamount = BigDecimal.ZERO;
  53. private FormatHandler formatHandler;
  54. public ActivityList() {
  55. setContext(Context.getActivityList());
  56. }
  57. @Override
  58. public JComponent getView() {
  59. return ActivityConfirmationPanel.instanceOf();
  60. }
  61. @Override
  62. public mpv5.utils.images.MPIcon getIcon() {
  63. return new MPIcon("/mpv5/resources/images/22/folder_documents.png");
  64. }
  65. @Override
  66. public boolean save(boolean b) {
  67. if (getCname().length() == 0) {
  68. setCname("<unnamed>");
  69. }
  70. return super.save(b);
  71. }
  72. public int __getContactsids() {
  73. return contactsids;
  74. }
  75. public void setContactsids(int contactsids) {
  76. this.contactsids = contactsids;
  77. }
  78. public int __getOrderids() {
  79. return orderids;
  80. }
  81. public void setOrderids(int orderids) {
  82. this.orderids = orderids;
  83. }
  84. public BigDecimal __getTotalamount() {
  85. return totalamount;
  86. }
  87. public void setTotalamount(BigDecimal totalamount) {
  88. this.totalamount = totalamount;
  89. }
  90. public String __getCNumber() {
  91. return cnumber;
  92. }
  93. public void setCNumber(String cnumber) {
  94. this.cnumber = cnumber;
  95. }
  96. /**
  97. * @return the formatHandler
  98. */
  99. public synchronized FormatHandler getFormatHandler() {
  100. if (formatHandler == null) {
  101. formatHandler = new FormatHandler(this);
  102. }
  103. return formatHandler;
  104. }
  105. public int templateType() {
  106. return Constants.TYPE_ACTIVITY;
  107. }
  108. public int templateGroupIds() {
  109. return __getGroupsids();
  110. }
  111. public void defineFormatHandler(FormatHandler handler) {
  112. formatHandler = handler;
  113. }
  114. @Override
  115. public void ensureUniqueness() {
  116. setCNumber(getFormatHandler().next());
  117. }
  118. @Override
  119. public HashMap<String, Object> resolveReferences(HashMap<String, Object> map) {
  120. Contact dbo;
  121. if (map.containsKey("contactsids")) {
  122. try {
  123. try {
  124. dbo = (Contact) DatabaseObject.getObject(Context.getContact(), Integer.valueOf(map.get("contactsids").toString()));
  125. map.put("contact", dbo);
  126. //map.putAll(dbo.getValues4());
  127. map.remove("contactsids");
  128. } catch (NodataFoundException ex) {
  129. map.put("contact", null);
  130. Log.Debug(this, ex.getMessage());
  131. }
  132. } catch (NumberFormatException numberFormatException) {
  133. //already resolved?
  134. }
  135. }
  136. List<ActivityListSubItem> data;
  137. List<String[]> data2;
  138. ArrayList<String[]> list = new ArrayList<String[]>();
  139. try {
  140. data = DatabaseObject.getReferencedObjects(this, Context.getActivityListItems(), new ActivityListSubItem());
  141. Collections.sort(data, ActivityListSubItem.ORDER_COMPARATOR);
  142. for (int i = 0; i < data.size(); i++) {
  143. ActivityListSubItem t = data.get(i);
  144. list.add(t.toStringArray(TemplateHandler.loadTemplate(this.templateGroupIds(), this.templateType())));
  145. if (GlobalSettings.getBooleanProperty("org.openyabs.exportproperty.pdftable", false)) {
  146. data2 = t.getValues3();
  147. for (int j = 0; j < data2.size(); j++) {
  148. String[] strings = data2.get(j);
  149. map.put("subactivity" + i + "." + strings[0].toLowerCase(), strings[1]);
  150. }
  151. }
  152. }
  153. } catch (NodataFoundException ex) {
  154. Log.Debug(this, ex.getMessage());
  155. }
  156. map.put(TableHandler.KEY_TABLE + "1", list);
  157. //date format localization
  158. if (mpv5.db.objects.User.getCurrentUser().getProperties().hasProperty("item.date.locale")) {
  159. Locale l = null;
  160. try {
  161. l = TypeConversion.stringToLocale(mpv5.db.objects.User.getCurrentUser().getProperties().getProperty("item.date.locale"));
  162. } catch (Exception e) {
  163. }
  164. if (l != null) {
  165. map.put("dateadded", DateFormat.getDateInstance(DateFormat.MEDIUM, l).format(__getDateadded()));
  166. } else {
  167. Log.Debug(this, "Error while using item.date.locale");
  168. }
  169. }
  170. map.put("grosvaluef", FormatNumber.formatLokalCurrency(__getTotalamount()));
  171. return super.resolveReferences(map);
  172. }
  173. public Object[] getDataForInvoice() {
  174. //"Internal ID", "ID", "Count", "Measure", "Description", "Netto Price", "Tax Value", "Total Price
  175. Object[] data = new Object[8];
  176. String defunit = "";
  177. if (mpv5.db.objects.User.getCurrentUser().getProperties().hasProperty("defunit")) {
  178. defunit = mpv5.db.objects.User.getCurrentUser().getProperties().getProperty("defunit");
  179. }
  180. data[2] = new BigDecimal("1.0");
  181. data[3] = defunit;
  182. data[4] = Messages.ActivityList_toSubItem.toString() + this.__getCname();
  183. data[5] = this.__getTotalamount();
  184. data[6] = new BigDecimal("0.0");
  185. data[7] = this.__getTotalamount();
  186. return data;
  187. }
  188. }