1 /*
2 * Copyright 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
3 * Copyright 2019 Thomas Baumgart <tbaumgart@kde.org>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "mymoneystoragenames.h"
20
21 #include <QMap>
22
23 #include "mymoneyenums.h"
24
tagName(Tag tagID)25 QString tagName(Tag tagID)
26 {
27 static const QHash<Tag, QString> tagNames {
28 {Tag::Institutions, QStringLiteral("INSTITUTIONS")},
29 {Tag::Payees, QStringLiteral("PAYEES")},
30 {Tag::CostCenters, QStringLiteral("COSTCENTERS")},
31 {Tag::Tags, QStringLiteral("TAGS")},
32 {Tag::Accounts, QStringLiteral("ACCOUNTS")},
33 {Tag::Transactions, QStringLiteral("TRANSACTIONS")},
34 {Tag::Schedules, QStringLiteral("SCHEDULES")},
35 {Tag::Securities, QStringLiteral("SECURITIES")},
36 {Tag::Currencies, QStringLiteral("CURRENCIES")},
37 {Tag::Prices, QStringLiteral("PRICES")},
38 {Tag::Reports, QStringLiteral("REPORTS")},
39 {Tag::Budgets, QStringLiteral("BUDGETS")},
40 {Tag::OnlineJobs, QStringLiteral("ONLINEJOBS")},
41 {Tag::KMMFile, QStringLiteral("KMYMONEY-FILE")},
42 {Tag::FileInfo, QStringLiteral("FILEINFO")},
43 {Tag::User, QStringLiteral("USER")}
44 };
45 return tagNames.value(tagID);
46 }
47
qHash(const Tag key,uint seed)48 uint qHash(const Tag key, uint seed) { return ::qHash(static_cast<uint>(key), seed); }
49
nodeName(Node nodeID)50 QString nodeName(Node nodeID)
51 {
52 static const QHash<Node, QString> nodeNames {
53 {Node::Institution, QStringLiteral("INSTITUTION")},
54 {Node::Payee, QStringLiteral("PAYEE")},
55 {Node::CostCenter, QStringLiteral("COSTCENTER")},
56 {Node::Tag, QStringLiteral("TAG")},
57 {Node::Account, QStringLiteral("ACCOUNT")},
58 {Node::Transaction, QStringLiteral("TRANSACTION")},
59 {Node::Split, QStringLiteral("SPLIT")},
60 {Node::ScheduleTX, QStringLiteral("SCHEDULED_TX")},
61 {Node::Security, QStringLiteral("SECURITY")},
62 {Node::Currency, QStringLiteral("CURRENCY")},
63 {Node::Price, QStringLiteral("PRICE")},
64 {Node::PricePair, QStringLiteral("PRICEPAIR")},
65 {Node::Report, QStringLiteral("REPORT")},
66 {Node::Budget, QStringLiteral("BUDGET")},
67 {Node::OnlineJob, QStringLiteral("ONLINEJOB")},
68 {Node::KeyValuePairs, QStringLiteral("KEYVALUEPAIRS")},
69 {Node::Equity, QStringLiteral("EQUITY")},
70 };
71 return nodeNames.value(nodeID);
72 }
73
qHash(const Node key,uint seed)74 uint qHash(const Node key, uint seed) { return ::qHash(static_cast<uint>(key), seed); }
75
76 namespace Element {
qHash(const General key,uint seed)77 uint qHash(const General key, uint seed) { return ::qHash(static_cast<uint>(key), seed); }
qHash(const Transaction key,uint seed)78 uint qHash(const Transaction key, uint seed) { return ::qHash(static_cast<uint>(key), seed); }
qHash(const Account key,uint seed)79 uint qHash(const Account key, uint seed) { return ::qHash(static_cast<uint>(key), seed); }
qHash(const Payee key,uint seed)80 uint qHash(const Payee key, uint seed) { return ::qHash(static_cast<uint>(key), seed); }
qHash(const KVP key,uint seed)81 uint qHash(const KVP key, uint seed) { return ::qHash(static_cast<uint>(key), seed); }
qHash(const Institution key,uint seed)82 uint qHash(const Institution key, uint seed) { return ::qHash(static_cast<uint>(key), seed); }
qHash(const Schedule key,uint seed)83 uint qHash(const Schedule key, uint seed) { return ::qHash(static_cast<uint>(key), seed); }
qHash(const OnlineJob key,uint seed)84 uint qHash(const OnlineJob key, uint seed) { return ::qHash(static_cast<uint>(key), seed); }
85 }
86
87 namespace Attribute {
qHash(const General key,uint seed)88 uint qHash(const General key, uint seed) { Q_UNUSED(seed); return ::qHash(static_cast<uint>(key), 0); }
qHash(const Transaction key,uint seed)89 uint qHash(const Transaction key, uint seed) { Q_UNUSED(seed); return ::qHash(static_cast<uint>(key), 0); }
qHash(const Account key,uint seed)90 uint qHash(const Account key, uint seed) { Q_UNUSED(seed); return ::qHash(static_cast<uint>(key), 0); }
qHash(const Payee key,uint seed)91 uint qHash(const Payee key, uint seed) { Q_UNUSED(seed); return ::qHash(static_cast<uint>(key), 0); }
qHash(const Tag key,uint seed)92 uint qHash(const Tag key, uint seed) { Q_UNUSED(seed); return ::qHash(static_cast<uint>(key), 0); }
qHash(const Security key,uint seed)93 uint qHash(const Security key, uint seed) { Q_UNUSED(seed); return ::qHash(static_cast<uint>(key), 0); }
qHash(const KVP key,uint seed)94 uint qHash(const KVP key, uint seed) { Q_UNUSED(seed); return ::qHash(static_cast<uint>(key), 0); }
qHash(const Institution key,uint seed)95 uint qHash(const Institution key, uint seed) { Q_UNUSED(seed); return ::qHash(static_cast<uint>(key), 0); }
qHash(const Schedule key,uint seed)96 uint qHash(const Schedule key, uint seed) { Q_UNUSED(seed); return ::qHash(static_cast<uint>(key), 0); }
qHash(const OnlineJob key,uint seed)97 uint qHash(const OnlineJob key, uint seed) { Q_UNUSED(seed); return ::qHash(static_cast<uint>(key), 0); }
98 }
99
elementName(Element::General elementID)100 QString elementName(Element::General elementID)
101 {
102 static const QMap<Element::General, QString> elementNames {
103 {Element::General::Address, QStringLiteral("ADDRESS")},
104 {Element::General::CreationDate, QStringLiteral("CREATION_DATE")},
105 {Element::General::LastModifiedDate, QStringLiteral("LAST_MODIFIED_DATE")},
106 {Element::General::Version, QStringLiteral("VERSION")},
107 {Element::General::FixVersion, QStringLiteral("FIXVERSION")},
108 {Element::General::Pair, QStringLiteral("PAIR")}
109 };
110 return elementNames.value(elementID);
111 }
112
attributeName(Attribute::General attributeID)113 QString attributeName(Attribute::General attributeID)
114 {
115 static const QMap<Attribute::General, QString> attributeNames {
116 {Attribute::General::ID, QStringLiteral("id")},
117 {Attribute::General::Date, QStringLiteral("date")},
118 {Attribute::General::Count, QStringLiteral("count")},
119 {Attribute::General::From, QStringLiteral("from")},
120 {Attribute::General::To, QStringLiteral("to")},
121 {Attribute::General::Source, QStringLiteral("source")},
122 {Attribute::General::Key, QStringLiteral("key")},
123 {Attribute::General::Value, QStringLiteral("value")},
124 {Attribute::General::Price, QStringLiteral("price")},
125 {Attribute::General::Name, QStringLiteral("name")},
126 {Attribute::General::Email, QStringLiteral("email")},
127 {Attribute::General::Country, QStringLiteral("county")},
128 {Attribute::General::City, QStringLiteral("city")},
129 {Attribute::General::ZipCode, QStringLiteral("zipcode")},
130 {Attribute::General::Street, QStringLiteral("street")},
131 {Attribute::General::Telephone, QStringLiteral("telephone")}
132 };
133 return attributeNames.value(attributeID);
134 }
135
elementName(Element::Transaction elementID)136 QString elementName(Element::Transaction elementID)
137 {
138 static const QMap<Element::Transaction, QString> elementNames {
139 {Element::Transaction::Split, QStringLiteral("SPLIT")},
140 {Element::Transaction::Splits, QStringLiteral("SPLITS")}
141 };
142 return elementNames.value(elementID);
143 }
144
attributeName(Attribute::Transaction attributeID)145 QString attributeName(Attribute::Transaction attributeID)
146 {
147 static const QMap<Attribute::Transaction, QString> attributeNames {
148 {Attribute::Transaction::Name, QStringLiteral("name")},
149 {Attribute::Transaction::Type, QStringLiteral("type")},
150 {Attribute::Transaction::PostDate, QStringLiteral("postdate")},
151 {Attribute::Transaction::Memo, QStringLiteral("memo")},
152 {Attribute::Transaction::EntryDate, QStringLiteral("entrydate")},
153 {Attribute::Transaction::Commodity, QStringLiteral("commodity")},
154 {Attribute::Transaction::BankID, QStringLiteral("bankid")},
155 };
156 return attributeNames.value(attributeID);
157 }
158
elementName(Element::Split elementID)159 QString elementName(Element::Split elementID)
160 {
161 static const QMap<Element::Split, QString> elementNames {
162 {Element::Split::Split, QStringLiteral("SPLIT")},
163 {Element::Split::Tag, QStringLiteral("TAG")},
164 {Element::Split::Match, QStringLiteral("MATCH")},
165 {Element::Split::Container, QStringLiteral("CONTAINER")},
166 {Element::Split::KeyValuePairs, QStringLiteral("KEYVALUEPAIRS")}
167 };
168 return elementNames.value(elementID);
169 }
170
attributeName(Attribute::Split attributeID)171 QString attributeName(Attribute::Split attributeID)
172 {
173 static const QMap<Attribute::Split, QString> attributeNames {
174 {Attribute::Split::ID, QStringLiteral("id")},
175 {Attribute::Split::BankID, QStringLiteral("bankid")},
176 {Attribute::Split::Account, QStringLiteral("account")},
177 {Attribute::Split::Payee, QStringLiteral("payee")},
178 {Attribute::Split::Tag, QStringLiteral("tag")},
179 {Attribute::Split::Number, QStringLiteral("number")},
180 {Attribute::Split::Action, QStringLiteral("action")},
181 {Attribute::Split::Value, QStringLiteral("value")},
182 {Attribute::Split::Shares, QStringLiteral("shares")},
183 {Attribute::Split::Price, QStringLiteral("price")},
184 {Attribute::Split::Memo, QStringLiteral("memo")},
185 {Attribute::Split::CostCenter, QStringLiteral("costcenter")},
186 {Attribute::Split::ReconcileDate, QStringLiteral("reconciledate")},
187 {Attribute::Split::ReconcileFlag, QStringLiteral("reconcileflag")},
188 {Attribute::Split::KMMatchedTx, QStringLiteral("kmm-matched-tx")}
189 };
190 return attributeNames.value(attributeID);
191 }
192
elementName(Element::Account elementID)193 QString elementName(Element::Account elementID)
194 {
195 static const QMap<Element::Account, QString> elementNames {
196 {Element::Account::SubAccount, QStringLiteral("SUBACCOUNT")},
197 {Element::Account::SubAccounts, QStringLiteral("SUBACCOUNTS")},
198 {Element::Account::OnlineBanking, QStringLiteral("ONLINEBANKING")}
199 };
200 return elementNames.value(elementID);
201 }
202
attributeName(Attribute::Account attributeID)203 QString attributeName(Attribute::Account attributeID)
204 {
205 static const QHash<Attribute::Account, QString> attributeNames {
206 {Attribute::Account::ID, QStringLiteral("id")},
207 {Attribute::Account::Name, QStringLiteral("name")},
208 {Attribute::Account::Type, QStringLiteral("type")},
209 {Attribute::Account::ParentAccount, QStringLiteral("parentaccount")},
210 {Attribute::Account::LastReconciled, QStringLiteral("lastreconciled")},
211 {Attribute::Account::LastModified, QStringLiteral("lastmodified")},
212 {Attribute::Account::Institution, QStringLiteral("institution")},
213 {Attribute::Account::Opened, QStringLiteral("opened")},
214 {Attribute::Account::Number, QStringLiteral("number")},
215 {Attribute::Account::Type, QStringLiteral("type")},
216 {Attribute::Account::Description, QStringLiteral("description")},
217 {Attribute::Account::Currency, QStringLiteral("currency")},
218 {Attribute::Account::OpeningBalance, QStringLiteral("openingbalance")},
219 {Attribute::Account::IBAN, QStringLiteral("iban")},
220 {Attribute::Account::BIC, QStringLiteral("bic")},
221 };
222 return attributeNames.value(attributeID);
223 }
224
elementName(Element::Payee elementID)225 QString elementName(Element::Payee elementID)
226 {
227 static const QMap<Element::Payee, QString> elementNames {
228 {Element::Payee::Address, QStringLiteral("ADDRESS")},
229 {Element::Payee::Identifier, QStringLiteral("payeeIdentifier")}
230 };
231 return elementNames.value(elementID);
232 }
233
attributeName(Attribute::Payee attributeID)234 QString attributeName(Attribute::Payee attributeID)
235 {
236 static const QMap<Attribute::Payee, QString> attributeNames {
237 {Attribute::Payee::ID, QStringLiteral("id")},
238 {Attribute::Payee::Name, QStringLiteral("name")},
239 {Attribute::Payee::Type, QStringLiteral("type")},
240 {Attribute::Payee::Reference, QStringLiteral("reference")},
241 {Attribute::Payee::Notes, QStringLiteral("notes")},
242 {Attribute::Payee::MatchingEnabled, QStringLiteral("matchingenabled")},
243 {Attribute::Payee::UsingMatchKey, QStringLiteral("usingmatchkey")},
244 {Attribute::Payee::MatchIgnoreCase, QStringLiteral("matchignorecase")},
245 {Attribute::Payee::MatchKey, QStringLiteral("matchkey")},
246 {Attribute::Payee::DefaultAccountID, QStringLiteral("defaultaccountid")},
247 {Attribute::Payee::Street, QStringLiteral("street")},
248 {Attribute::Payee::City, QStringLiteral("city")},
249 {Attribute::Payee::PostCode, QStringLiteral("postcode")},
250 {Attribute::Payee::Email, QStringLiteral("email")},
251 {Attribute::Payee::State, QStringLiteral("state")},
252 {Attribute::Payee::Telephone, QStringLiteral("telephone")},
253 {Attribute::Payee::IBAN, QStringLiteral("iban")},
254 {Attribute::Payee::BIC, QStringLiteral("bic")},
255 {Attribute::Payee::OwnerVer1, QStringLiteral("ownerName")}, // for IBANBIC number
256 {Attribute::Payee::OwnerVer2, QStringLiteral("ownername")}, // for NationaAccount number
257 {Attribute::Payee::AccountNumber, QStringLiteral("accountnumber")},
258 {Attribute::Payee::BankCode, QStringLiteral("bankcode")},
259 {Attribute::Payee::Country, QStringLiteral("country")},
260 };
261 return attributeNames.value(attributeID);
262 }
263
attributeName(Attribute::Tag attributeID)264 QString attributeName(Attribute::Tag attributeID)
265 {
266 static const QMap<Attribute::Tag, QString> attributeNames {
267 {Attribute::Tag::Name, QStringLiteral("name")},
268 {Attribute::Tag::Type, QStringLiteral("type")},
269 {Attribute::Tag::TagColor, QStringLiteral("tagcolor")},
270 {Attribute::Tag::Closed, QStringLiteral("closed")},
271 {Attribute::Tag::Notes, QStringLiteral("notes")},
272 };
273 return attributeNames.value(attributeID);
274 }
275
attributeName(Attribute::Security attributeID)276 QString attributeName(Attribute::Security attributeID)
277 {
278 static const QMap<Attribute::Security, QString> attributeNames {
279 {Attribute::Security::Name, QStringLiteral("name")},
280 {Attribute::Security::Symbol, QStringLiteral("symbol")},
281 {Attribute::Security::Type, QStringLiteral("type")},
282 {Attribute::Security::RoundingMethod, QStringLiteral("rounding-method")},
283 {Attribute::Security::SAF, QStringLiteral("saf")},
284 {Attribute::Security::PP, QStringLiteral("pp")},
285 {Attribute::Security::SCF, QStringLiteral("scf")},
286 {Attribute::Security::TradingCurrency, QStringLiteral("trading-currency")},
287 {Attribute::Security::TradingMarket, QStringLiteral("trading-market")}
288 };
289 return attributeNames.value(attributeID);
290 }
291
elementName(Element::KVP elementID)292 QString elementName(Element::KVP elementID)
293 {
294 static const QMap<Element::KVP, QString> elementNames {
295 {Element::KVP::Pair, QStringLiteral("PAIR")}
296 };
297 return elementNames.value(elementID);
298 }
299
attributeName(Attribute::KVP attributeID)300 QString attributeName(Attribute::KVP attributeID)
301 {
302 static const QMap<Attribute::KVP, QString> attributeNames {
303 {Attribute::KVP::Key, QStringLiteral("key")},
304 {Attribute::KVP::Value, QStringLiteral("value")}
305 };
306 return attributeNames.value(attributeID);
307 }
308
elementName(Element::Institution elementID)309 QString elementName(Element::Institution elementID)
310 {
311 static const QMap<Element::Institution, QString> elementNames {
312 {Element::Institution::AccountID, QStringLiteral("ACCOUNTID")},
313 {Element::Institution::AccountIDS, QStringLiteral("ACCOUNTIDS")},
314 {Element::Institution::Address, QStringLiteral("ADDRESS")}
315 };
316 return elementNames.value(elementID);
317 }
318
attributeName(Attribute::Institution attributeID)319 QString attributeName(Attribute::Institution attributeID)
320 {
321 static const QMap<Attribute::Institution, QString> attributeNames {
322 {Attribute::Institution::ID, QStringLiteral("id")},
323 {Attribute::Institution::Name, QStringLiteral("name")},
324 {Attribute::Institution::Manager, QStringLiteral("manager")},
325 {Attribute::Institution::SortCode, QStringLiteral("sortcode")},
326 {Attribute::Institution::Street, QStringLiteral("street")},
327 {Attribute::Institution::City, QStringLiteral("city")},
328 {Attribute::Institution::Zip, QStringLiteral("zip")},
329 {Attribute::Institution::Telephone, QStringLiteral("telephone")}
330 };
331 return attributeNames.value(attributeID);
332 }
333
elementName(Element::Schedule elementID)334 QString elementName(Element::Schedule elementID)
335 {
336 static const QMap<Element::Schedule, QString> elementNames {
337 {Element::Schedule::Payment, QStringLiteral("PAYMENT")},
338 {Element::Schedule::Payments, QStringLiteral("PAYMENTS")}
339 };
340 return elementNames.value(elementID);
341 }
342
attributeName(Attribute::Schedule attributeID)343 QString attributeName(Attribute::Schedule attributeID)
344 {
345 static const QMap<Attribute::Schedule, QString> attributeNames {
346 {Attribute::Schedule::Name, QStringLiteral("name")},
347 {Attribute::Schedule::Type, QStringLiteral("type")},
348 {Attribute::Schedule::Occurrence, QStringLiteral("occurence")}, // krazy:exclude=spelling
349 {Attribute::Schedule::OccurrenceMultiplier, QStringLiteral("occurenceMultiplier")}, // krazy:exclude=spelling
350 {Attribute::Schedule::PaymentType, QStringLiteral("paymentType")},
351 {Attribute::Schedule::Fixed, QStringLiteral("fixed")},
352 {Attribute::Schedule::AutoEnter, QStringLiteral("autoEnter")},
353 {Attribute::Schedule::LastPayment, QStringLiteral("lastPayment")},
354 {Attribute::Schedule::WeekendOption, QStringLiteral("weekendOption")},
355 {Attribute::Schedule::Date, QStringLiteral("date")},
356 {Attribute::Schedule::StartDate, QStringLiteral("startDate")},
357 {Attribute::Schedule::EndDate, QStringLiteral("endDate")},
358 {Attribute::Schedule::LastDayInMonth, QStringLiteral("lastDayInMonth")}
359 };
360 return attributeNames.value(attributeID);
361 }
362
elementName(Element::OnlineJob elementID)363 QString elementName(Element::OnlineJob elementID)
364 {
365 static const QMap<Element::OnlineJob, QString> elementNames {
366 {Element::OnlineJob::OnlineTask, QStringLiteral("onlineTask")}
367 };
368 return elementNames.value(elementID);
369 }
370
attributeName(Attribute::OnlineJob attributeID)371 QString attributeName(Attribute::OnlineJob attributeID)
372 {
373 static const QMap<Attribute::OnlineJob, QString> attributeNames {
374 {Attribute::OnlineJob::Send, QStringLiteral("send")},
375 {Attribute::OnlineJob::BankAnswerDate, QStringLiteral("bankAnswerDate")},
376 {Attribute::OnlineJob::BankAnswerState, QStringLiteral("bankAnswerState")},
377 {Attribute::OnlineJob::IID, QStringLiteral("iid")},
378 {Attribute::OnlineJob::AbortedByUser, QStringLiteral("abortedByUser")},
379 {Attribute::OnlineJob::AcceptedByBank, QStringLiteral("acceptedByBank")},
380 {Attribute::OnlineJob::RejectedByBank, QStringLiteral("rejectedByBank")},
381 {Attribute::OnlineJob::SendingError, QStringLiteral("sendingError")},
382 };
383 return attributeNames.value(attributeID);
384 }
385
attributeName(Attribute::CostCenter attributeID)386 QString attributeName(Attribute::CostCenter attributeID)
387 {
388 static const QMap<Attribute::CostCenter, QString> attributeNames {
389 {Attribute::CostCenter::Name, QStringLiteral("name")},
390 };
391 return attributeNames.value(attributeID);
392 }
393