summaryrefslogtreecommitdiffstats
path: root/kmymoney2/dialogs/tdeconfirmmanualenterdlg.cpp
blob: 84609a01369f955b7f7d9e1b1c265fd7bbd14c2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/***************************************************************************
                          tdeconfirmmanualenterdlg.cpp
                             -------------------
    begin                : Mon Apr  9 2007
    copyright            : (C) 2007 by Thomas Baumgart
    email                : Thomas Baumgart <ipwizard@users.sourceforge.net>
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

// ----------------------------------------------------------------------------
// QT Includes

#include <tqradiobutton.h>

// ----------------------------------------------------------------------------
// KDE Includes

#include <tdelocale.h>
#include <ktextedit.h>
#include <kpushbutton.h>
#include <kstdguiitem.h>
#include <tdemessagebox.h>

// ----------------------------------------------------------------------------
// Project Includes

#include <kmymoney/mymoneyfile.h>
#include <kmymoney/kmymoneyutils.h>
#include "tdeconfirmmanualenterdlg.h"

KConfirmManualEnterDlg::KConfirmManualEnterDlg(const MyMoneySchedule& schedule, TQWidget* parent, const char* name) :
  KConfirmManualEnterDlgDecl(parent, name)
{
  buttonOk->setGuiItem(KStdGuiItem::ok());
  buttonCancel->setGuiItem(KStdGuiItem::cancel());
  m_onceRadio->setChecked(true);
  m_onceRadio->setFocus();

  if(schedule.type() == MyMoneySchedule::TYPE_LOANPAYMENT) {
    m_setRadio->setEnabled(false);
    m_discardRadio->setEnabled(false);
  }
  
}

void KConfirmManualEnterDlg::loadTransactions(const MyMoneyTransaction& to, const MyMoneyTransaction& tn)
{
  TQString messageDetail("<qt>");
  MyMoneyFile* file = MyMoneyFile::instance();
  int noItemsChanged=0;

#if 0
  // if no schedule is present, we cannot enter it
  if(m_schedule.id().isEmpty())
    return false;

  if (m_fromAccountId == m_toAccountId)
  {
    KMessageBox::error(this, i18n("Account and transfer account are the same.  Please change one."));
    m_from->setFocus();
    return false;
  }

  if (!checkDateInPeriod(m_date->date()))
    return false;
#endif

  try
  {
    TQString po, pn;
    if(to.splits()[0].payeeId())
      po = file->payee(to.splits()[0].payeeId()).name();
    if(tn.splits()[0].payeeId())
      pn = file->payee(tn.splits()[0].payeeId()).name();

    if (po != pn) {
      noItemsChanged++;
      messageDetail += i18n("Payee changed.<br>&nbsp;&nbsp;&nbsp;Old: <b>%1</b>, New: <b>%2</b><p>").arg(po).arg(pn);
    }
#if 0
    if (  (m_schedule.type() == MyMoneySchedule::TYPE_TRANSFER ||
          m_schedule.type() == MyMoneySchedule::TYPE_BILL) &&
          m_from->currentText() != m_schedule.account().name())
    {
      noItemsChanged++;
      messageDetail += i18n("Account changed.  Old: \"%1\", New: \"%2\"")
        .arg(m_schedule.account().name()).arg(m_from->currentText()) + TQString("\n");
    }

    if (  m_schedule.type() == MyMoneySchedule::TYPE_DEPOSIT &&
          m_to->currentText() != m_schedule.account().name())
    {
      noItemsChanged++;
      messageDetail += i18n("Account changed.  Old: \"%1\", New: \"%2\"")
        .arg(m_schedule.account().name()).arg(m_to->currentText()) + TQString("\n");
    }
#endif

    if(to.splits()[0].accountId() != tn.splits()[0].accountId()) {
      noItemsChanged++;
      messageDetail += i18n("Account changed.<br>&nbsp;&nbsp;&nbsp;Old: <b>%1</b>, New: <b>%2</b><p>")
        .arg(file->account(to.splits()[0].accountId()).name())
        .arg(file->account(tn.splits()[0].accountId()).name());
    }

    if(file->isTransfer(to) && file->isTransfer(tn)) {
      if(to.splits()[1].accountId() != tn.splits()[1].accountId()) {
        noItemsChanged++;
        messageDetail += i18n("Transfer account changed.<br>&nbsp;&nbsp;&nbsp;Old: <b>%1</b>, New: <b>%2</b><p>")
          .arg(file->account(to.splits()[1].accountId()).name())
          .arg(file->account(tn.splits()[1].accountId()).name());
      }
    } else {
      TQString co, cn;
      switch(to.splitCount()) {
        default:
          co = i18n("Split transaction (category replacement)", "Split transaction");
          break;
        case 2:
          co = file->accountToCategory(to.splits()[1].accountId());
        case 1:
          break;
      }

      switch(tn.splitCount()) {
        default:
          cn = i18n("Split transaction (category replacement)", "Split transaction");
          break;
        case 2:
          cn = file->accountToCategory(tn.splits()[1].accountId());
        case 1:
          break;
      }
      if (co != cn)
      {
        noItemsChanged++;
        messageDetail += i18n("Category changed.<br>&nbsp;&nbsp;&nbsp;Old: <b>%1</b>, New: <b>%2</b><p>").arg(co).arg(cn);
      }
    }

    TQString mo, mn;
    mo = to.splits()[0].memo();
    mn = tn.splits()[0].memo();
    if(mo.isEmpty())
       mo = TQString("<i>")+i18n("empty")+TQString("</i>");
    if(mn.isEmpty())
       mn = TQString("<i>")+i18n("empty")+TQString("</i>");
    if (mo != mn)
    {
      noItemsChanged++;
      messageDetail += i18n("Memo changed.<br>&nbsp;&nbsp;&nbsp;Old: <b>%1</b>, New: <b>%2</b><p>").arg(mo).arg(mn);
    }

    const MyMoneySecurity& sec = MyMoneyFile::instance()->security(to.commodity());
    MyMoneyMoney ao, an;
    ao = to.splits()[0].value();
    an = tn.splits()[0].value();
    if (ao != an) {
      noItemsChanged++;
      messageDetail += i18n("Amount changed.<br>&nbsp;&nbsp;&nbsp;Old: <b>%1</b>, New: <b>%2</b><p>")
        .arg(ao.formatMoney(sec.smallestAccountFraction())).arg(an.formatMoney(sec.smallestAccountFraction()));
    }

    MyMoneySplit::reconcileFlagE fo, fn;
    fo = to.splits()[0].reconcileFlag();
    fn = tn.splits()[0].reconcileFlag();
    if(fo != fn) {
      noItemsChanged++;
      messageDetail += i18n("Reconciliation flag changed.<br>&nbsp;&nbsp;&nbsp;Old: <b>%1</b>, New: <b>%2</b><p>")
        .arg(KMyMoneyUtils::reconcileStateToString(fo, true))
        .arg(KMyMoneyUtils::reconcileStateToString(fn, true));
    }
  }
  catch (MyMoneyException *e)
  {
    KMessageBox::error(this, i18n("Fatal error in determining data: ") + e->what());
    delete e;
  }

  messageDetail += "</qt>";
  m_details->setText(messageDetail);
  return;
}

KConfirmManualEnterDlg::Action KConfirmManualEnterDlg::action(void) const
{
  if(m_discardRadio->isChecked())
    return UseOriginal;
  if(m_setRadio->isChecked())
    return ModifyAlways;
  return ModifyOnce;
}

#include "tdeconfirmmanualenterdlg.moc"