summaryrefslogtreecommitdiffstats
path: root/kmymoney2/widgets/selectedtransaction.cpp
blob: 102477b7926ae4a5cb518416cc10ca585e778f4b (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
/***************************************************************************
                          selectedtransaction.cpp  -  description
                             -------------------
    begin                : Fri Jun 2008
    copyright            : (C) 2000-2008 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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "selectedtransaction.h"

#include "register.h"
#include <kmymoney/mymoneysplit.h>
#include <kmymoney/mymoneyfile.h>

namespace KMyMoneyRegister {
  
int SelectedTransaction::warnLevel() const
{
  int warnLevel = 0;
  TQValueList<MyMoneySplit>::const_iterator it_s;
  for(it_s = transaction().splits().begin(); warnLevel < 2 && it_s != transaction().splits().end(); ++it_s) {
    const MyMoneyAccount& acc = MyMoneyFile::instance()->account((*it_s).accountId());
    if(acc.isClosed())
      warnLevel = 3;
    else if((*it_s).reconcileFlag() == MyMoneySplit::Frozen)
      warnLevel = 2;
    else if((*it_s).reconcileFlag() == MyMoneySplit::Reconciled && warnLevel < 1)
      warnLevel = 1;
  }
  return warnLevel;
}
  
SelectedTransactions::SelectedTransactions(const Register* r)
{
  r->selectedTransactions(*this);
}

int SelectedTransactions::warnLevel() const
{
  int warnLevel = 0;
  SelectedTransactions::const_iterator it_t;
  for(it_t = begin(); warnLevel < 3 && it_t != end(); ++it_t) {
    int thisLevel = (*it_t).warnLevel();
    if (thisLevel > warnLevel)
      warnLevel = thisLevel;
  }
  return warnLevel;
}

bool SelectedTransactions::canModify() const
{
  return warnLevel() < 2;
}

bool SelectedTransactions::canDuplicate() const
{
  return warnLevel() < 3;
}

} // namespace