summaryrefslogtreecommitdiffstats
path: root/kmymoney2/mymoney/mymoneypayee.h
blob: c2c711b3c293786dd6df80acda4d84251abe5816 (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
/***************************************************************************
                          mymoneypayee.h
                             -------------------
    copyright            : (C) 2000 by Michael Edwardes
                               2005 by Thomas Baumgart
    email                : mte@users.sourceforge.net
                           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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef MYMONEYPAYEE_H
#define MYMONEYPAYEE_H

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

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

#include <qstring.h>
class QStringList;

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

#include <kmymoney/export.h>
#include <kmymoney/mymoneyobject.h>

/**
  * This class represents a payee or receiver within the MyMoney engine.
  * Since it is not payee-specific, it is also used as a generic address
  * book entry.
  *
  * @author Thomas Baumgart
  */
class KMYMONEY_EXPORT MyMoneyPayee : public MyMoneyObject
{
private:
  // Simple fields
  QString m_name;
  QString m_address;
  QString m_city;
  QString m_state;
  QString m_postcode;
  QString m_telephone;
  QString m_email;
  QString m_notes;

  // Transaction matching fields
  bool m_matchingEnabled;      //< Whether this payee should be matched at all
  bool m_usingMatchKey;        //< If so, whether a m_matchKey list is used (true), or just m_name is used (false)
  bool m_matchKeyIgnoreCase;   //< Whether to ignore the case of the match key or name

  /**
   * Semicolon separated list of matching keys used when trying to find a suitable
   * payee for imported transactions.
   */
  QString m_matchKey;

  // Category (account) matching fields
  QString m_defaultAccountId;

  /**
    * This member keeps a reference to an external database
    * (e.g. kaddressbook). It is the responsability of the
    * application to format the reference string
    * (e.g. encoding the name of the external database into the
    * reference string).
    * If no external database is available it should be kept
    * empty by the application.
    */
  QString m_reference;

public:
  typedef enum {
    matchDisabled = 0,
    matchName,
    matchKey
  } payeeMatchType;

  MyMoneyPayee();
  MyMoneyPayee(const QString& id, const MyMoneyPayee& payee);
  MyMoneyPayee(const QString& name,
          const QString& address=QString::null,
          const QString& city=QString::null,
          const QString& state=QString::null,
          const QString& postcode=QString::null,
          const QString& telephone=QString::null,
          const QString& email=QString::null);
  /**
    * This is the constructor for a payee that is described by a
    * QDomElement (e.g. from a file).
    *
    * @param el const reference to the QDomElement from which to
    *           create the object
    */
  MyMoneyPayee(const QDomElement& el);

  ~MyMoneyPayee();

  // Simple get operations
  QString name(void) const            { return m_name; }
  QString address(void) const         { return m_address; }
  QString city(void) const            { return m_city; }
  QString state(void) const           { return m_state; }
  QString postcode(void) const        { return m_postcode; }
  QString telephone(void) const       { return m_telephone; }
  QString email(void) const           { return m_email; }
  QString notes(void) const           { return m_notes; }

  const QString id(void) const        { return m_id; };
  const QString reference(void) const { return m_reference; };

  // Simple set operations
  void setName(const QString& val)      { m_name = val; }
  void setAddress(const QString& val)   { m_address = val; }
  void setCity(const QString& val)      { m_city = val; }
  void setState(const QString& val)     { m_state = val; }
  void setPostcode(const QString& val)  { m_postcode = val; }
  void setTelephone(const QString& val) { m_telephone = val; }
  void setEmail(const QString& val)     { m_email = val; }
  void setNotes(const QString& val)     { m_notes = val; }
  void setReference(const QString& ref) { m_reference = ref; }

  /**
   * Get all match data in one call
   *
   * @param ignorecase Bool which will be replaced to indicate whether the match is
   * case-sensitive (false) or case-insensitive (true)
   * @param keys List of strings which will be replaced by the match key to use for this payee
   *
   * @return the matching type (see payeeMatchType for details)
   */
  payeeMatchType matchData(bool& ignorecase, QStringList& keys) const;

  /**
   * Set all match data in one call
   *
   * @param type matching type (see payeeMatchType for details)
   * @param ignorecase Whether case should be ignored for the key/name match
   * @param keys A list of keys themselves, if applicable
   */
  void setMatchData(payeeMatchType type, bool ignorecase, const QStringList& keys);

  /**
   * Get all match data in one call (overloaded version for database module)
   *
   * @param ignorecase Bool which will be replaced to indicate whether the match is
   * case-sensitive (false) or case-insensitive (true)
   * @param keyString A list of keys in single-string format, if applicable
   *
   * @return the matching type (see payeeMatchType for details)
   */
  payeeMatchType matchData(bool& ignorecase, QString& keyString) const;

  /**
   * Set all match data in one call (overloaded version for database module)
   *
   * @param type matching type (see payeeMatchType for details)
   * @param ignorecase Whether case should be ignored for the key/name match
   * @param keys A list of keys in single-string format, if applicable
   */
  void setMatchData(payeeMatchType type, bool ignorecase, const QString& keys);


  bool defaultAccountEnabled() const { return !m_defaultAccountId.isEmpty(); }
  const QString& defaultAccountId() const { return m_defaultAccountId; }
  void setDefaultAccountId(const QString& id = QString()) {
    m_defaultAccountId = id;
  }

  // Copy constructors
  MyMoneyPayee(const MyMoneyPayee&);

  // Equality operator
  bool operator == (const MyMoneyPayee &) const;

  void writeXML(QDomDocument& document, QDomElement& parent) const;

  /**
    * This method checks if a reference to the given object exists. It returns,
    * a @p true if the object is referencing the one requested by the
    * parameter @p id. If it does not, this method returns @p false.
    *
    * @param id id of the object to be checked for references
    * @retval true This object references object with id @p id.
    * @retval false This object does not reference the object with id @p id.
    */
  virtual bool hasReferenceTo(const QString& id) const;

  static MyMoneyPayee null;
};

inline bool operator==(const MyMoneyPayee& lhs, const QString& rhs) { return lhs.id() == rhs; }

#endif
// vim:cin:si:ai:et:ts=2:sw=2: