-
Notifications
You must be signed in to change notification settings - Fork 0
/
financialmutations.cpp
59 lines (44 loc) · 1.54 KB
/
financialmutations.cpp
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
#include "financialmutations.h"
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
QString FinancialMutation::getFinancialAccountID(FinancialAccount account)
{
switch (account) {
case (FinancialAccount::BankAccount):
return "157734015254660172";
case (FinancialAccount::CashBook):
return "158511091531383924";
default:
return "";
}
}
GetUnprocessedFinancialMutations::GetUnprocessedFinancialMutations()
{
moneybird->GET("financial_mutations.json?filter=state:unprocessed");
}
GetUnprocessedFinancialMutations::~GetUnprocessedFinancialMutations()
{
}
void GetUnprocessedFinancialMutations::receiveParsedReply(QJsonDocument reply)
{
QJsonArray mutationArray = reply.array();
QVector<FinancialMutation*> mutations;
for(int i = 0; i < mutationArray.size(); i++)
{
QJsonObject mutationJson = mutationArray[i].toObject();
QString message = mutationJson["message"].toString().section("/",-3,-3);
QString name = mutationJson["contra_account_name"].toString();
if (name == "ABN AMRO BANK INZ TIKKIE")
{
name = message.section(",", 2);
message = message.section(",", 1, 1);
}
FinancialMutation *mutation = new FinancialMutation(mutationJson["amount"].toString(), message, mutationJson["date"].toString());
mutation->setName(name);
mutation->setID(mutationJson["id"].toString());
mutation->setFinancialAccountID(mutationJson["financial_account_id"].toString());
mutations.append(mutation);
}
emit UnprocessedFinancialMutationsReady(mutations);
}