summaryrefslogtreecommitdiffstats
path: root/kmymoney2/widgets/kmymoneyaccounttree.cpp
blob: c3a98954c0656f47d1c21414c6a3bcf625e3dc01 (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
/***************************************************************************
                         kmymoneyaccounttree.cpp  -  description
                            -------------------
   begin                : Sat Jan 1 2005
   copyright            : (C) 2005 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.                                   *
 *                                                                         *
 ***************************************************************************/

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

#include <tqpoint.h>
#include <tqevent.h>
#include <tqdragobject.h>
#include <tqtimer.h>
#include <tqcursor.h>
#include <tqheader.h>
#include <tqpainter.h>
#include <tqpixmap.h>
#include <tqstyle.h>

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

#include <kmessagebox.h>
#include <klocale.h>
#include <kglobal.h>
#include <kiconloader.h>
#include <kstandarddirs.h>

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

#include <kmymoney/mymoneyfile.h>
#include <kmymoney/kmymoneyaccounttree.h>
#include <kmymoney/kmymoneyglobalsettings.h>

#include <kmymoney/kmymoneyutils.h>

KMyMoneyAccountTree::KMyMoneyAccountTree(TQWidget* parent, const char *name) :
    KMyMoneyAccountTreeBase(parent,name)
{
  showType();

  m_taxReportColumn = addColumn(i18n("Column heading for category in tax report", "Tax"));
  setColumnWidthMode(m_taxReportColumn, TQListView::Manual);
  setColumnAlignment(m_taxReportColumn, TQt::AlignHCenter);

  m_vatCategoryColumn = addColumn(i18n("Column heading for VAT category", "VAT"));
  setColumnWidthMode(m_vatCategoryColumn, TQListView::Manual);
  setColumnAlignment(m_vatCategoryColumn, TQt::AlignHCenter);

  showValue();
}

KMyMoneyAccountTreeItem::KMyMoneyAccountTreeItem(KListView *parent, const MyMoneyAccount& account, const MyMoneySecurity& security , const TQString& name) :
    KMyMoneyAccountTreeBaseItem(parent,account,security,name),
    m_reconcileFlag(false)
{
  updateAccount();
}

KMyMoneyAccountTreeItem::KMyMoneyAccountTreeItem(KMyMoneyAccountTreeBaseItem *parent, const MyMoneyAccount& account, const TQValueList<MyMoneyPrice>& price, const MyMoneySecurity& security) :
    KMyMoneyAccountTreeBaseItem(parent,account,price,security),
    m_reconcileFlag(false)
{
  updateAccount();
}

KMyMoneyAccountTreeItem::KMyMoneyAccountTreeItem(KListView *parent, const MyMoneyInstitution& institution) :
    KMyMoneyAccountTreeBaseItem(parent,institution),
    m_reconcileFlag(false)
{
}

void KMyMoneyAccountTreeItem::fillColumns()
{
  KMyMoneyAccountTree* lv = dynamic_cast<KMyMoneyAccountTree*>(listView());
  if (!lv)
    return;
  KMyMoneyAccountTreeBaseItem::fillColumns();
  TQPixmap checkMark = TQPixmap(TDEGlobal::iconLoader()->loadIcon("ok", KIcon::Small));
  MyMoneyMoney vatRate;
  if (!isInstitution())
    setPixmap(lv->nameColumn(), m_account.accountPixmap(m_reconcileFlag, 22));
  switch(m_account.accountType()) {
    case MyMoneyAccount::Income:
    case MyMoneyAccount::Expense:
    case MyMoneyAccount::Asset:
    case MyMoneyAccount::Liability:
      if(m_account.value("Tax").lower() == "yes")
        setPixmap(lv->taxReportColumn(), checkMark);
      if(!m_account.value("VatAccount").isEmpty()) {
        setPixmap(lv->vatCategoryColumn(), checkMark);
      }
      if(!m_account.value("VatRate").isEmpty()) {
        vatRate = MyMoneyMoney(m_account.value("VatRate")) * MyMoneyMoney(100,1);
        setText(lv->vatCategoryColumn(), TQString("%1 %").arg(vatRate.formatMoney("", 1)));
      }
      break;
    default:
      break;
  }
}

void KMyMoneyAccountTreeItem::setReconciliation(bool on)
{
  if(m_reconcileFlag == on)
    return;
  m_reconcileFlag = on;
  updateAccount();
}

MyMoneyMoney KMyMoneyAccountTreeItem::balance() const
{
  MyMoneyMoney result;
  // account.balance() is not compatable with stock accounts
  if ( m_account.isInvest() )
    result = MyMoneyFile::instance()->balance(m_account.id());
  else
    result = m_account.balance();
  // for income and liability accounts, we reverse the sign
  switch(m_account.accountGroup()) {
    case MyMoneyAccount::Income:
    case MyMoneyAccount::Liability:
    case MyMoneyAccount::Equity:
        result = -result;
      break;

    default:
      break;
  }
  return result;
}


#include "kmymoneyaccounttree.moc"
// vim:cin:si:ai:et:ts=2:sw=2: