summaryrefslogtreecommitdiffstats
path: root/kmymoney2/mymoney/mymoneypayee.h
blob: f8112d4eb0335e81360aead8eb50d0cc11af0989 (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 <tqstring.h>
class TQStringList;

// ----------------------------------------------------------------------------
// 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
  TQString m_name;
  TQString m_address;
  TQString m_city;
  TQString m_state;
  TQString m_postcode;
  TQString m_telephone;
  TQString m_email;
  TQString 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.
   */
  TQString m_matchKey;

  // Category (account) matching fields
  TQString 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.
    */
  TQString m_reference;

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

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

  ~MyMoneyPayee();

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

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

  // Simple set operations
  void setName(const TQString& val)      { m_name = val; }
  void setAddress(const TQString& val)   { m_address = val; }
  void setCity(const TQString& val)      { m_city = val; }
  void setState(const TQString& val)     { m_state = val; }
  void setPostcode(const TQString& val)  { m_postcode = val; }
  void setTelephone(const TQString& val) { m_telephone = val; }
  void setEmail(const TQString& val)     { m_email = val; }
  void setNotes(const TQString& val)     { m_notes = val; }
  void setReference(const TQString& 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, TQStringList& 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 TQStringList& 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, TQString& 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 TQString& keys);


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

  // Copy constructors
  MyMoneyPayee(const MyMoneyPayee&);

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

  void writeXML(TQDomDocument& document, TQDomElement& 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 TQString& id) const;

  static MyMoneyPayee null;
};

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

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