PageRenderTime 681ms CodeModel.GetById 663ms RepoModel.GetById 0ms app.codeStats 0ms

/src/mpv5/db/objects/Item.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 839 lines | 536 code | 92 blank | 211 comment | 56 complexity | d43f24f91e1fd6001ee136c5951e70d0 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.awt.Color;
  21. import java.math.BigDecimal;
  22. import java.text.DateFormat;
  23. import java.text.SimpleDateFormat;
  24. import java.util.ArrayList;
  25. import java.util.Collections;
  26. import java.util.Date;
  27. import java.util.HashMap;
  28. import java.util.List;
  29. import java.util.Locale;
  30. import javax.swing.JComponent;
  31. import mpv5.YabsViewProxy;
  32. import mpv5.db.common.Context;
  33. import mpv5.db.common.DatabaseObject;
  34. import mpv5.db.common.Formattable;
  35. import mpv5.db.common.NodataFoundException;
  36. import mpv5.db.common.Templateable;
  37. import mpv5.globals.GlobalSettings;
  38. import mpv5.globals.Messages;
  39. import mpv5.handler.FormatHandler;
  40. import mpv5.handler.MPEnum;
  41. import mpv5.logging.Log;
  42. import mpv5.ui.panels.ItemPanel;
  43. import mpv5.utils.export.Export;
  44. import mpv5.utils.images.MPIcon;
  45. import mpv5.utils.jobs.Job;
  46. import mpv5.utils.numberformat.FormatNumber;
  47. import mpv5.utils.text.TypeConversion;
  48. /**
  49. *
  50. *
  51. */
  52. public class Item extends DatabaseObject implements Formattable, Templateable {
  53. private static final long serialVersionUID = 1L;
  54. /**
  55. * Returns a localized string representation of the given item status
  56. *
  57. * @param status
  58. * @return
  59. */
  60. public static String getStatusString(int status) {
  61. switch (status) {
  62. case (STATUS_QUEUED):
  63. return Messages.STATUS_QUEUED.toString();
  64. case (STATUS_IN_PROGRESS):
  65. return Messages.STATUS_IN_PROGRESS.toString();
  66. case (STATUS_PAUSED):
  67. return Messages.STATUS_PAUSED.toString();
  68. case (STATUS_FINISHED):
  69. return Messages.STATUS_FINISHED.toString();
  70. case (STATUS_PAID):
  71. return Messages.STATUS_PAID.toString();
  72. case (STATUS_CANCELLED):
  73. return Messages.STATUS_CANCELLED.toString();
  74. }
  75. return Messages.NA.toString();
  76. }
  77. /**
  78. * Returns all possible status messages
  79. *
  80. * @return
  81. */
  82. public static MPEnum[] getStatusStrings() {
  83. MPEnum[] en = new MPEnum[6];
  84. en[0] = new MPEnum() {
  85. @Override
  86. public Integer getId() {
  87. return new Integer(STATUS_QUEUED);
  88. }
  89. @Override
  90. public String getName() {
  91. return getStatusString(getId());
  92. }
  93. };
  94. en[1] = new MPEnum() {
  95. @Override
  96. public Integer getId() {
  97. return new Integer(STATUS_IN_PROGRESS);
  98. }
  99. @Override
  100. public String getName() {
  101. return getStatusString(getId());
  102. }
  103. };
  104. en[2] = new MPEnum() {
  105. @Override
  106. public Integer getId() {
  107. return new Integer(STATUS_PAUSED);
  108. }
  109. @Override
  110. public String getName() {
  111. return getStatusString(getId());
  112. }
  113. };
  114. en[3] = new MPEnum() {
  115. @Override
  116. public Integer getId() {
  117. return new Integer(STATUS_FINISHED);
  118. }
  119. @Override
  120. public String getName() {
  121. return getStatusString(getId());
  122. }
  123. };
  124. en[4] = new MPEnum() {
  125. @Override
  126. public Integer getId() {
  127. return new Integer(STATUS_PAID);
  128. }
  129. @Override
  130. public String getName() {
  131. return getStatusString(getId());
  132. }
  133. };
  134. en[5] = new MPEnum() {
  135. @Override
  136. public Integer getId() {
  137. return new Integer(STATUS_CANCELLED);
  138. }
  139. @Override
  140. public String getName() {
  141. return getStatusString(getId());
  142. }
  143. };
  144. return en;
  145. }
  146. /**
  147. * Returns a localized string represenation of the given item type
  148. *
  149. * @param type
  150. * @return
  151. */
  152. public static String getTypeString(int type) {
  153. switch (type) {
  154. case (TYPE_BILL):
  155. return Messages.TYPE_BILL.toString();
  156. case (TYPE_OFFER):
  157. return Messages.TYPE_OFFER.toString();
  158. case (TYPE_ORDER):
  159. return Messages.TYPE_ORDER.toString();
  160. // case (TYPE_DELIVERY_NOTE):
  161. // return Messages.TYPE_DELIVERY.toString();
  162. // case (TYPE_ORDER_CONFIRMATION):
  163. // return Messages.TYPE_CONFIRMATION.toString();
  164. }
  165. return "";
  166. }
  167. public static MPEnum[] getItemEnum() {
  168. MPEnum[] en = new MPEnum[4];
  169. en[0] = new MPEnum() {
  170. @Override
  171. public Integer getId() {
  172. return new Integer(-1);
  173. }
  174. @Override
  175. public String getName() {
  176. return Messages.ALL.toString();
  177. }
  178. };
  179. en[1] = new MPEnum() {
  180. @Override
  181. public Integer getId() {
  182. return new Integer(TYPE_BILL);
  183. }
  184. @Override
  185. public String getName() {
  186. return getTypeString(TYPE_BILL);
  187. }
  188. };
  189. en[2] = new MPEnum() {
  190. @Override
  191. public Integer getId() {
  192. return new Integer(TYPE_OFFER);
  193. }
  194. @Override
  195. public String getName() {
  196. return getTypeString(TYPE_OFFER);
  197. }
  198. };
  199. en[3] = new MPEnum() {
  200. @Override
  201. public Integer getId() {
  202. return new Integer(TYPE_ORDER);
  203. }
  204. @Override
  205. public String getName() {
  206. return getTypeString(TYPE_ORDER);
  207. }
  208. };
  209. // en[4] = new MPEnum() {
  210. //
  211. // @Override
  212. // public Integer getId() {
  213. // return new Integer(3);
  214. // }
  215. //
  216. // @Override
  217. // public String getName() {
  218. // return getTypeString(3);
  219. // }
  220. // };
  221. // en[5] = new MPEnum() {
  222. //
  223. // @Override
  224. // public Integer getId() {
  225. // return new Integer(4);
  226. // }
  227. //
  228. // @Override
  229. // public String getName() {
  230. // return getTypeString(4);
  231. // }
  232. // };
  233. return en;
  234. }
  235. private int contactsids;
  236. private int accountsids;
  237. private BigDecimal netvalue = BigDecimal.ZERO;
  238. private BigDecimal taxvalue = BigDecimal.ZERO;
  239. private BigDecimal discountvalue = BigDecimal.ZERO;
  240. private Date datetodo;
  241. private Date dateend;
  242. private int intreminders;
  243. private int intstatus;
  244. private int inttype;
  245. private String description = "";
  246. private String cnumber = "";
  247. public static final int STATUS_QUEUED = 0;
  248. public static final int STATUS_IN_PROGRESS = 1;
  249. public static final int STATUS_PAUSED = 2;
  250. public static final int STATUS_FINISHED = 3;
  251. public static final int STATUS_PAID = 4;
  252. public static final int STATUS_CANCELLED = 5;
  253. // public static final int TYPE_BILL = 0;
  254. // public static final int TYPE_ORDER = 1;
  255. // public static final int TYPE_OFFER = 2;
  256. // public static final int TYPE_DELIVERY_NOTE = 3;
  257. // public static final int TYPE_ORDER_CONFIRMATION = 4;
  258. private FormatHandler formatHandler;
  259. public Item() {
  260. setContext(Context.getItem());
  261. }
  262. /**
  263. * @return the contactsids
  264. */
  265. public int __getContactsids() {
  266. return contactsids;
  267. }
  268. /**
  269. * @param contactsids the contactsids to set
  270. */
  271. public void setContactsids(int contactsids) {
  272. this.contactsids = contactsids;
  273. }
  274. /**
  275. * @return the taxvalue
  276. */
  277. public BigDecimal __getTaxvalue() {
  278. return taxvalue;
  279. }
  280. /**
  281. * @param taxvalue the taxvalue to set
  282. */
  283. public void setTaxvalue(BigDecimal taxvalue) {
  284. this.taxvalue = taxvalue;
  285. }
  286. /**
  287. * @return the Discountvalue
  288. */
  289. public BigDecimal __getDiscountvalue() {
  290. return discountvalue;
  291. }
  292. /**
  293. * @param the discountvalue to set
  294. */
  295. public void setDiscountvalue(BigDecimal discountvalue) {
  296. this.discountvalue = discountvalue;
  297. }
  298. /**
  299. * @return the datetodo
  300. */
  301. public Date __getDatetodo() {
  302. return datetodo;
  303. }
  304. /**
  305. * @param datetodo the datetodo to set
  306. */
  307. public void setDatetodo(Date datetodo) {
  308. this.datetodo = datetodo;
  309. }
  310. /**
  311. * @return the intreminders
  312. */
  313. public int __getIntreminders() {
  314. return intreminders;
  315. }
  316. /**
  317. * @param intreminders the intreminders to set
  318. */
  319. public void setIntreminders(int intreminders) {
  320. this.intreminders = intreminders;
  321. }
  322. // /**
  323. // * @return the groupname
  324. // */
  325. //// public String __getGroupname() {
  326. // return groupname;
  327. // }
  328. //
  329. // /**
  330. // * @param groupname the groupname to set
  331. // */
  332. // public void setGroupname(String groupname) {
  333. // this.groupname = groupname;
  334. // }
  335. /**
  336. * @return the dateend
  337. */
  338. public Date __getDateend() {
  339. return dateend;
  340. }
  341. /**
  342. * @param dateend the dateend to set
  343. */
  344. public void setDateend(Date dateend) {
  345. this.dateend = dateend;
  346. }
  347. @Override
  348. public JComponent getView() {
  349. ItemPanel p = new ItemPanel(Context.getItem(), __getInttype());
  350. return p;
  351. }
  352. /**
  353. * @return the defaultaccountsids
  354. */
  355. public int __getAccountsids() {
  356. return accountsids;
  357. }
  358. /**
  359. * @param defaultaccountsids the defaultaccountsids to set
  360. */
  361. public void setAccountsids(int defaultaccountsids) {
  362. this.accountsids = defaultaccountsids;
  363. }
  364. /**
  365. * @return the description
  366. */
  367. public String __getDescription() {
  368. return description;
  369. }
  370. /**
  371. * @param description the description to set
  372. */
  373. public void setDescription(String description) {
  374. this.description = description;
  375. }
  376. /**
  377. * <li>QUEUED = 0; <li>IN_PROGRESS= 1; <li>PAUSED = 2; <li>FINNISHED= 3;
  378. *
  379. * @return the intstatus
  380. */
  381. public int __getIntstatus() {
  382. return intstatus;
  383. }
  384. /**
  385. * <li>QUEUED = 0; <li>IN_PROGRESS= 1; <li>PAUSED = 2; <li>FINNISHED= 3;
  386. *
  387. * @param intstatus the intstatus to set
  388. */
  389. public void setIntstatus(int intstatus) {
  390. this.intstatus = intstatus;
  391. }
  392. /**
  393. * <li>TYPE_BILL = 0; <li>TYPE_ORDER = 1; <li>TYPE_OFFER = 2;
  394. *
  395. * @return the inttype
  396. */
  397. public int __getInttype() {
  398. return inttype;
  399. }
  400. /**
  401. * <li>TYPE_BILL = 0; <li>TYPE_ORDER = 1; <li>TYPE_OFFER = 2;
  402. *
  403. * @param inttype the inttype to set
  404. */
  405. public void setInttype(int inttype) {
  406. this.inttype = inttype;
  407. }
  408. /**
  409. * @return the netvalue
  410. */
  411. public BigDecimal __getNetvalue() {
  412. return netvalue;
  413. }
  414. /**
  415. * @param netvalue the netvalue to set
  416. */
  417. public void setNetvalue(BigDecimal netvalue) {
  418. this.netvalue = netvalue;
  419. }
  420. @Override
  421. public mpv5.utils.images.MPIcon getIcon() {
  422. if (__getIntstatus() == STATUS_QUEUED) {
  423. return new MPIcon("/mpv5/resources/images/22/kontact_mail.png");
  424. } else if (__getIntstatus() == STATUS_IN_PROGRESS) {
  425. return new MPIcon("/mpv5/resources/images/22/run.png");
  426. } else if (__getIntstatus() == STATUS_PAUSED) {
  427. return new MPIcon("/mpv5/resources/images/22/kalarm.png");
  428. } else if (__getIntstatus() == STATUS_FINISHED) {
  429. return new MPIcon("/mpv5/resources/images/22/knewstuff.png");
  430. } else if (__getIntstatus() == STATUS_PAID) {
  431. return new MPIcon("/mpv5/resources/images/22/ok.png");
  432. } else if (__getIntstatus() == STATUS_CANCELLED) {
  433. return new MPIcon("/mpv5/resources/images/22/file_temporary.png");
  434. } else {
  435. return new MPIcon("/mpv5/resources/images/22/kontact_mail.png");
  436. }
  437. }
  438. /**
  439. * @return the formatHandler
  440. */
  441. public synchronized FormatHandler getFormatHandler() {
  442. if (formatHandler == null) {
  443. formatHandler = new FormatHandler(this);
  444. }
  445. return formatHandler;
  446. }
  447. @Override
  448. public synchronized void ensureUniqueness() {
  449. Log.Debug(this, "In ensureUniqueness for " + this.getClass());
  450. setCnumber(getFormatHandler().next());
  451. setCname(__getCnumber());
  452. Log.Debug(this, "ensureUniqueness result: " + __getCnumber());
  453. }
  454. /**
  455. * Fetches all related {@link Subitem}s to this {@link Item}<br/> If no
  456. * subitems are assigned, returns an empty default list of default subitems
  457. *
  458. * @return
  459. */
  460. public SubItem[] getSubitems() {
  461. List<DatabaseObject> data = new ArrayList<DatabaseObject>();
  462. try {
  463. data = DatabaseObject.getReferencedObjects(this, Context.getSubItem(), DatabaseObject.getObject(Context.getSubItem()), false);
  464. } catch (NodataFoundException ex) {
  465. for (int i = 0; i < 6; i++) {
  466. data.add(SubItem.getDefaultItem());
  467. }
  468. }
  469. // SubItem[] t = new SubItem[data.size()];
  470. // for (int i = 0; i < data.size(); i++) {
  471. // t[i] = (SubItem) data.get(i);
  472. // }
  473. return data.toArray(new SubItem[]{});
  474. }
  475. /**
  476. * @return the cnumber
  477. */
  478. public String __getCnumber() {
  479. return cnumber;
  480. }
  481. /**
  482. * @param cnumber the cnumber to set
  483. */
  484. public void setCnumber(String cnumber) {
  485. this.cnumber = cnumber;
  486. }
  487. @Override
  488. public HashMap<String, Object> resolveReferences(HashMap<String, Object> map) {
  489. resolveValueProperties(map);
  490. try {
  491. if (map.containsKey("intstatus")) {
  492. map.put("status", getStatusString(Integer.valueOf(map.get("intstatus").toString())));
  493. }
  494. } catch (Exception numberFormatException) {
  495. //already resolved?
  496. }
  497. try {
  498. if (map.containsKey("inttype")) {
  499. map.put("type", getTypeString(Integer.valueOf(map.get("inttype").toString())));
  500. map.remove("inttype");
  501. }
  502. } catch (Exception numberFormatException) {
  503. //already resolved?
  504. }
  505. if (map.containsKey("defaultaccountsids")) {
  506. try {
  507. try {
  508. map.put("account", DatabaseObject.getObject(Context.getAccounts(), Integer.valueOf(map.get("defaultaccountsids").toString())));
  509. map.remove("defaultaccountsids");
  510. } catch (NodataFoundException ex) {
  511. map.put("account", null);
  512. Log.Debug(this, ex.getMessage());
  513. }
  514. } catch (NumberFormatException numberFormatException) {
  515. //already resolved?
  516. }
  517. }
  518. if (map.containsKey("contactsids")) {
  519. try {
  520. try {
  521. map.put("contact", DatabaseObject.getObject(Context.getContact(), Integer.valueOf(map.get("contactsids").toString())));
  522. map.remove("contactsids");
  523. } catch (NodataFoundException ex) {
  524. map.put("contact", null);
  525. Log.Debug(this, ex.getMessage());
  526. }
  527. } catch (NumberFormatException numberFormatException) {
  528. //already resolved?
  529. }
  530. }
  531. if (map.containsKey("taxids")) {
  532. try {
  533. map.put("tax", FormatNumber.formatPercent(Tax.getTaxValue(Integer.valueOf(map.get("taxids").toString()))));
  534. map.remove("taxids");
  535. } catch (NumberFormatException numberFormatException) {
  536. Log.Debug(numberFormatException);
  537. }
  538. }
  539. List<SubItem> data;
  540. List<String[]> data2;
  541. ArrayList<String[]> list = new ArrayList<String[]>();
  542. try {
  543. data = DatabaseObject.getReferencedObjects(this, Context.getSubItem(), new SubItem(), false);
  544. Collections.sort(data, SubItem.ORDER_COMPARATOR);
  545. for (int i = 0; i < data.size(); i++) {
  546. SubItem t = data.get(i);
  547. list.add(t.toStringArray());
  548. if (GlobalSettings.getBooleanProperty("org.openyabs.exportproperty.pdftable", false)) {
  549. data2 = t.getValues3();
  550. for (int j = 0; j < data2.size(); j++) {
  551. String[] strings = data2.get(j);
  552. map.put("subitem" + i + "." + strings[0].toLowerCase(), strings[1]);
  553. }
  554. }
  555. }
  556. if (GlobalSettings.getBooleanProperty("org.openyabs.exportproperty.hidecountfortext", true)) {
  557. int skipcount = 0;
  558. for (int i = 0; i < data.size(); i++) {
  559. SubItem t = data.get(i);
  560. if (t.getInttype() == SubItem.TYPE_TEXT) {
  561. skipcount--;
  562. Log.Debug(this, "Skipping text subitem..");
  563. } else {
  564. list.get(i)[0] = String.valueOf(Integer.valueOf(list.get(i)[0]) + skipcount);
  565. }
  566. }
  567. }
  568. } catch (NodataFoundException ex) {
  569. Log.Debug(this, ex.getMessage());
  570. }
  571. map.put(TableHandler.KEY_TABLE + "1", list);
  572. //values
  573. map.put("netvalue", FormatNumber.formatDezimal(__getNetvalue()));
  574. map.put("taxvalue", FormatNumber.formatDezimal(__getTaxvalue()));
  575. map.put("grosvalue", FormatNumber.formatDezimal(__getTaxvalue().add(__getNetvalue())));
  576. map.put("discountvalue", FormatNumber.formatDezimal(__getDiscountvalue()));
  577. map.put("netvaluef", FormatNumber.formatLokalCurrency(__getNetvalue()));
  578. map.put("taxvaluef", FormatNumber.formatLokalCurrency(__getTaxvalue()));
  579. map.put("grosvaluef", FormatNumber.formatLokalCurrency(__getTaxvalue().add(__getNetvalue())));
  580. map.put("discountvaluef", FormatNumber.formatPercent(__getDiscountvalue()));
  581. Locale l = Locale.getDefault();
  582. if (mpv5.db.objects.User.getCurrentUser().getProperties().hasProperty("item.date.locale")) {
  583. try {
  584. l = TypeConversion.stringToLocale(mpv5.db.objects.User.getCurrentUser().getProperties().getProperty("item.date.locale"));
  585. } catch (Exception e) {
  586. }
  587. if (l != null) {
  588. } else {
  589. Log.Debug(this, "Error while using item.date.locale");
  590. }
  591. }
  592. DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, l);
  593. if (mpv5.db.objects.User.getCurrentUser().getProperties().hasProperty("org.openyabs.exportproperty.dateformat")) {
  594. String dd = mpv5.db.objects.User.getCurrentUser().getProperties().getProperty("org.openyabs.exportproperty.dateformat");
  595. try {
  596. df = new SimpleDateFormat(dd, l);
  597. } catch (Exception e) {
  598. Log.Debug(this, "Error while using default.date.format: " + e);
  599. }
  600. }
  601. map.put("dateend", df.format(__getDateend()));
  602. map.put("datetodo", df.format(__getDatetodo()));
  603. return super.resolveReferences(map);
  604. }
  605. public void defineFormatHandler(FormatHandler handler) {
  606. formatHandler = handler;
  607. }
  608. /**
  609. * Create a revenue entry out of this item
  610. */
  611. public void createRevenue() {
  612. Revenue r = new Revenue();
  613. r.setAccountsids(accountsids);
  614. r.setNetvalue(netvalue);
  615. // r.setTaxpercentvalue(taxvalue);
  616. r.setBrutvalue(netvalue.add(taxvalue).subtract(discountvalue));
  617. if (description != null && description.length() > 0) {
  618. r.setDescription(description);
  619. } else {
  620. r.setDescription(Messages.AUTO_GENERATED_VALUE + " " + cnumber);
  621. }
  622. r.save();
  623. }
  624. @Override
  625. public boolean save(boolean silent) {
  626. boolean saved = super.save(silent);
  627. if (saved) {
  628. if (mpv5.db.objects.User.getCurrentUser().getProperty("org.openyabs.property", "autocreatepdf")) {
  629. if (TemplateHandler.isLoaded(this)) {
  630. new Job(Export.createFile(this.getFormatHandler().toUserString(), TemplateHandler.loadTemplate(this), this), Export.wait(User.getSaveDir(this))).execute();
  631. } else {
  632. YabsViewProxy.instance().addMessage(Messages.NO_TEMPLATE_LOADED + " (" + mpv5.db.objects.User.getCurrentUser() + ")", Color.YELLOW);
  633. }
  634. }
  635. if (mpv5.db.objects.User.getCurrentUser().getProperty("org.openyabs.property", "autocreateodt")) {
  636. if (TemplateHandler.isLoaded(this)) {
  637. new Job(Export.sourceFile(this.getFormatHandler().toUserString(), TemplateHandler.loadTemplate(this), this), Export.wait(User.getSaveDir(this))).execute();
  638. } else {
  639. YabsViewProxy.instance().addMessage(Messages.NO_TEMPLATE_LOADED + " (" + mpv5.db.objects.User.getCurrentUser() + ")", Color.YELLOW);
  640. }
  641. }
  642. }
  643. return saved;
  644. }
  645. @Override
  646. public String toString() {
  647. try {
  648. return ((Contact) getObject(Context.getContact(), contactsids)).__getCname() + "-" + getCname();
  649. } catch (NodataFoundException ex) {
  650. return super.toString();
  651. }
  652. }
  653. @Override
  654. public boolean reset() {
  655. if (ids > 0) {
  656. SubItem[] data = getSubitems();
  657. for (int i = 0; i < data.length; i++) {
  658. SubItem subItem = data[i];
  659. SubItem.removeFromDeletionQueue(subItem.__getIDS());
  660. }
  661. }
  662. return super.reset();
  663. }
  664. /**
  665. * Fetches all properties for this item from the db
  666. *
  667. * @return A (possibly empty) list of {@link ValueProperty}s
  668. */
  669. public List<ValueProperty> getProperties() {
  670. return ValueProperty.getProperties(this);
  671. }
  672. @Override
  673. public boolean delete() {
  674. SubItem[] it = getSubitems();
  675. for (int i = 0; i < it.length; i++) {
  676. it[i].delete();
  677. }
  678. setCnumber(FormatHandler.DELETED_IDENTIFIER + __getCnumber());
  679. setCname(__getCnumber());
  680. save(true);
  681. return super.delete();
  682. }
  683. @Override
  684. public boolean undelete() {
  685. List<DatabaseObject> data = new ArrayList<DatabaseObject>();
  686. try {
  687. data = DatabaseObject.getReferencedObjects(this, Context.getSubItem(), DatabaseObject.getObject(Context.getSubItem()), true);
  688. for (int i = 0; i < data.size(); i++) {
  689. data.get(i).undelete();
  690. }
  691. } catch (NodataFoundException ex) {
  692. Log.Debug(this, ex.getMessage());
  693. }
  694. setCnumber(__getCnumber().replaceFirst(FormatHandler.DELETED_IDENTIFIER, ""));
  695. setCname(__getCnumber());
  696. return super.undelete();
  697. }
  698. @Override
  699. public int templateType() {
  700. return __getInttype();
  701. }
  702. /**
  703. *
  704. * @return
  705. */
  706. @Override
  707. public int templateGroupIds() {
  708. return __getGroupsids();
  709. }
  710. /**
  711. * @return the contact
  712. */
  713. @Persistable(false)/*
  714. * is persisting via contactsids
  715. */
  716. public Contact getContact() throws NodataFoundException {
  717. return (Contact) getObject(Context.getContact(), contactsids);
  718. }
  719. /**
  720. * @param contact the contact to set
  721. */
  722. @Persistable(false)
  723. public void setContact(Contact contact) {
  724. setContactsids(contact.__getIDS());
  725. }
  726. /**
  727. * @return the account
  728. */
  729. @Persistable(false)
  730. public Account getAccount() throws NodataFoundException {
  731. return (Account) getObject(Context.getAccounts(), accountsids);
  732. }
  733. /**
  734. * @param account the account to set
  735. */
  736. @Persistable(false)
  737. public void setAccount(Account account) {
  738. setAccountsids(account.__getIDS());
  739. }
  740. /**
  741. * @return the status
  742. */
  743. @Persistable(false)
  744. public String getStatus() {
  745. return getStatusString(intstatus);
  746. }
  747. }