PageRenderTime 73ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/src/mpv5/utils/export/DTAFile.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 146 lines | 108 code | 17 blank | 21 comment | 6 complexity | b5dafd496f50b6ee211df4d5aa45aede 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.utils.export;
  18. import java.io.File;
  19. import java.io.IOException;
  20. import java.math.BigDecimal;
  21. import java.math.RoundingMode;
  22. import java.text.DecimalFormat;
  23. import java.text.DecimalFormatSymbols;
  24. import java.util.ArrayList;
  25. import java.util.HashMap;
  26. import java.util.Iterator;
  27. import java.util.List;
  28. import java.util.Vector;
  29. import mpv5.db.common.Context;
  30. import mpv5.db.objects.Contact;
  31. import mpv5.db.objects.Item;
  32. import mpv5.db.objects.Tax;
  33. import mpv5.db.objects.User;
  34. import mpv5.globals.Messages;
  35. import mpv5.handler.VariablesHandler;
  36. import mpv5.logging.Log;
  37. import mpv5.ui.dialogs.Popup;
  38. import mpv5.ui.frames.MPView;
  39. import mpv5.utils.date.DateConverter;
  40. import dtaus.DTAus;
  41. import dtaus.Konto;
  42. import mpv5.utils.files.FileDirectoryHandler;
  43. import mpv5.utils.files.FileReaderWriter;
  44. import mpv5.utils.jobs.Waitable;
  45. /**
  46. *
  47. *
  48. */
  49. public class DTAFile extends Exportable implements Waitable {
  50. private DTAFile(String pathToFile) {
  51. super(pathToFile);
  52. if (!exists()) {
  53. try {
  54. createNewFile();
  55. } catch (IOException ex) {
  56. Log.Debug(ex);
  57. }
  58. }
  59. }
  60. public DTAFile(HashMap<String, Object> map) {
  61. this(FileDirectoryHandler.getTempFile("export-" + DateConverter.getTodayDBDate(), "dtaus").getAbsolutePath());
  62. setData(map);
  63. }
  64. @Override
  65. public void run() {
  66. try {
  67. Log.Debug(this, "run: ");
  68. mpv5.YabsViewProxy.instance().setWaiting(true);
  69. Log.Debug(this, "All fields:");
  70. HashMap<String, Object> datas = getData();
  71. DTAus dta = null;
  72. try {
  73. dta = new DTAus(User.getCurrentUser().getDTAAccount(), "lk");
  74. } catch (Exception e) {
  75. Popup.notice(Messages.DTAUS_NOT_SET);
  76. return;
  77. }
  78. List<String> control = new ArrayList<String>();
  79. for (Iterator<String> it = datas.keySet().iterator(); it.hasNext();) {
  80. Item dbo = (Item) datas.get(it.next());
  81. Contact c = (Contact) Item.getObject(Context.getContact(), dbo.__getContactsids());
  82. Konto k = new Konto(c.__getBankid(), c.__getBankaccount(), c.__getBankname());
  83. //
  84. DTAus.Transaction t = dta.new Transaction(k);
  85. List<String> usages = User.getCurrentUser().getDTAUsages();
  86. for (int i = 0; i < usages.size(); i++) {
  87. String string = usages.get(i);
  88. t.addUsage(VariablesHandler.parse(string, dbo));
  89. }
  90. String cid = "";
  91. if (c.__getCNumber().length() > 10) {
  92. cid = c.__getCNumber().substring(c.__getCNumber().length() - 10, c.__getCNumber().length());
  93. } else {
  94. cid = c.__getCNumber();
  95. }
  96. t.internalCustomerId = cid;
  97. BigDecimal value = null;
  98. value = //netvalue
  99. dbo.__getTaxvalue().add(dbo.__getNetvalue());
  100. if (value.doubleValue() > 0.15) {
  101. value.setScale(2, RoundingMode.HALF_UP);
  102. DecimalFormat f = new DecimalFormat("##,###0.00");
  103. DecimalFormatSymbols sym = new DecimalFormatSymbols();
  104. sym.setDecimalSeparator(',');
  105. sym.setGroupingSeparator('.');
  106. f.setDecimalFormatSymbols(sym);
  107. t.setValue(f.format(value.doubleValue()));
  108. dta.addEntry(t);
  109. control.add(c.__getCname() + "\t" + c.__getBankaccount() + "\t" + c.__getBankname() + "\t" + dbo.__getCnumber() + "\t" + value.toPlainString());
  110. }
  111. }
  112. FileReaderWriter w = new FileReaderWriter(this);
  113. w.writeOnce(dta.toDTAstring());
  114. Popup.notice(control, Messages.DTAUS_CREATED);
  115. } catch (Exception ex) {
  116. Log.Debug(ex);
  117. } finally {
  118. mpv5.YabsViewProxy.instance().setWaiting(false);
  119. }
  120. }
  121. public Exception waitFor() {
  122. try {
  123. new Thread(this).start();
  124. } catch (Exception e) {
  125. return e;
  126. }
  127. return null;
  128. }
  129. }