KissCount

KissCount Commit Details

Date:2013-02-17 18:58:32 (7 years 5 months ago)
Author:Grégory Soutadé
Branch:dev, master, qt5
Commit:e0efe42b14e69b003312abfc4eb34c4aef79aa2e
Parents: fcc7d090714e24fe56d870e9c0ac65d38ca84f6d
Message:Simplify UpdateNextMonths function Add "create_if_not_exsits" to Database::GetAccountAmount

Changes:
MChangeLog (2 diffs)
Msrc/controller/KissCount.cpp (1 diff)
Msrc/controller/KissCount.hpp (1 diff)
Msrc/model/Database.cpp (2 diffs)
Msrc/model/Database.hpp (1 diff)
Msrc/view/AccountPanel.cpp (2 diffs)

File differences

ChangeLog
1
1
22
33
44
......
88
99
1010
11
12
1113
1214
1315
v0.4 (17/01/2013)
v0.4 (17/02/2013)
** User **
Add icons for low resolution
Sort categories using translated names
** Dev **
Primitive handle of low resolutions
Rework GridAccount
Simplify UpdateNextMonths function
Add "create_if_not_exsits" to Database::GetAccountAmount
** Bugs **
Remove some bugs in GridAccount
src/controller/KissCount.cpp
9999
100100
101101
102
102
103103
104
104
105105
106106
107107
return _user;
}
int KissCount::GetAccountAmount(int id, int month, int year, bool* had_value)
int KissCount::GetAccountAmount(int id, int month, int year, bool* had_value, bool create_if_not_exsits)
{
return _db->GetAccountAmount(id, month, year, had_value);
return _db->GetAccountAmount(id, month, year, had_value, create_if_not_exsits);
}
int KissCount::CalcAccountAmount(int id, int month, int year, bool* had_values)
src/controller/KissCount.hpp
7777
7878
7979
80
80
8181
8282
8383
int MetaAmount(int id);
int MetaPositiveAmount(int id);
int GetAccountAmount(int id, int month, int year, bool* had_values=0);
int GetAccountAmount(int id, int month, int year, bool* had_values=0, bool create_if_not_exsits=true);
void SetAccountAmount(int accountId, int month, int year, int value);
int CalcAccountAmount(int id, int month, int year, bool* had_values);
src/model/Database.cpp
379379
380380
381381
382
382
383383
384384
385385
......
400400
401401
402402
403
403
404
404405
405406
406407
query.clear();
}
int Database::GetAccountAmount(int id, int month, int year, bool* had_value)
int Database::GetAccountAmount(int id, int month, int year, bool* had_value, bool create_if_not_exsits)
{
QSqlRecord set;
QString req;
}
else
{
SetAccountAmount(id, month, year, 0);
if (create_if_not_exsits)
SetAccountAmount(id, month, year, 0);
if (had_value)
*had_value = false;
}
src/model/Database.hpp
113113
114114
115115
116
116
117117
118118
119119
int MetaAmount(int id);
int MetaPositiveAmount(int id);
int GetAccountAmount(int id, int month, int year, bool* had_value=0);
int GetAccountAmount(int id, int month, int year, bool* had_value=0, bool create_if_not_exsits=true);
void SetAccountAmount(int accountId, int month, int year, int amount);
int CalcAccountAmount(int id, int month, int year, bool* had_values);
src/view/AccountPanel.cpp
10541054
10551055
10561056
1057
1058
1057
10591058
1060
1061
1062
1059
1060
1061
1062
10631063
1064
10651064
1065
10661066
1067
1067
1068
10681069
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
10811070
10821071
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1072
1073
11011074
11021075
1103
1104
1105
1106
1107
1108
1109
11101076
11111077
1112
1113
1114
1115
1116
1117
1118
1119
1120
1078
11211079
11221080
11231081
1124
1125
1126
1127
1128
1082
1083
1084
1085
11291086
11301087
1131
1088
11321089
1133
1090
1091
1092
1093
1094
1095
1096
11341097
11351098
11361099
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
11471113
1148
1149
1150
1151
11521114
11531115
1154
1155
1156
1157
1158
1159
1160
1161
1162
11631116
11641117
11651118
......
11691122
11701123
11711124
1172
11731125
11741126
11751127
void AccountPanel::OnUpdateNextMonths()
{
int* deltas, *cur_amounts, amount;
int i, a;
int *cur_amounts, amount, i;
User* user = _kiss->GetUser();
bool had_values, accounts_updated = false;
int last_month = 0, last_year = 0, account_updated = 0;
std::map<int, std::vector<int> > operations;
bool has_values, accounts_updated = false;
int cur_month = 0, cur_year = 0, delta_computed = 0;
int last_month, last_year;
bool *valid_account;
deltas = new int[user->_accounts.size()] ;
cur_amounts = new int[user->_accounts.size()] ;
valid_account = new bool[user->_accounts.size()] ;
operations = _kiss->GetAllOperations();
cur_month = _curMonth;
cur_year = _curYear;
if (_curMonth == 11)
{
last_month = 0;
last_year = _curYear+1;
}
else
{
last_month = _curMonth+1;
last_year = _curYear;
}
// Compute deltas
for (i=0; i<(int)user->_accounts.size(); i++)
{
deltas[i] = _kiss->GetAccountAmount(user->_accounts[i].id, _curMonth, _curYear);
cur_amounts[i] = deltas[i] += _kiss->CalcAccountAmount(user->_accounts[i].id, _curMonth, _curYear, &had_values);
for (a=0; a<(int)operations[last_year].size(); a++)
if (operations[last_year][a] == last_month) break;
if (a == (int)operations[last_year].size())
{
deltas[i] = 0;
continue;
}
amount = _kiss->GetAccountAmount(user->_accounts[i].id, last_month, last_year);
deltas[i] -= amount;
if (deltas[i])
account_updated++;
cur_amounts[i] = _kiss->GetAccountAmount(user->_accounts[i].id, cur_month, cur_year, &has_values, false);
valid_account[i] = has_values;
}
if (!account_updated)
goto end;
last_month = _curMonth;
last_year = _curYear;
// Apply deltas
while (1)
{
account_updated = 0;
if (last_month == 11)
{
last_month = 0;
last_year = last_year+1;
}
else
last_month++;
delta_computed = 0;
for (i=0; i<(int)user->_accounts.size(); i++)
{
if (deltas[i] == 0.0) continue;
_kiss->CalcAccountAmount(user->_accounts[i].id, last_month, last_year, &had_values);
if (had_values)
account_updated++;
if (!valid_account[i]) continue;
cur_amounts[i] += _kiss->CalcAccountAmount(user->_accounts[i].id, cur_month, cur_year, &has_values);
if (has_values)
delta_computed++;
}
if (!account_updated) break;
if (!delta_computed) break;
account_updated = 0;
if (cur_month == 11)
{
cur_month = 0;
cur_year++;
}
else
cur_month++;
for (i=0; i<(int)user->_accounts.size(); i++)
{
if (deltas[i] == 0.0) continue;
amount = _kiss->GetAccountAmount(user->_accounts[i].id, last_month, last_year);
if ((cur_amounts[i] - amount) != deltas[i]) continue;
cur_amounts[i] = amount + deltas[i];
_kiss->SetAccountAmount(user->_accounts[i].id, last_month, last_year, cur_amounts[i]);
cur_amounts[i] += _kiss->CalcAccountAmount(user->_accounts[i].id, last_month, last_year, &had_values);
account_updated++;
if (!valid_account[i]) continue;
amount = _kiss->GetAccountAmount(user->_accounts[i].id, cur_month, cur_year, &has_values, false);
if (!has_values)
{
valid_account[i] = false;
continue;
}
if (amount != cur_amounts[i])
{
accounts_updated = true;
_kiss->SetAccountAmount(user->_accounts[i].id, cur_month, cur_year, cur_amounts[i]);
last_month = cur_month; last_year = cur_year;
}
}
if (!account_updated) break;
accounts_updated = true;
}
if (last_month == 0)
{
last_month = 11;
last_year--;
}
else
last_month--;
end:
if (accounts_updated)
{
QString message = _("Accounts updated until ") + wxUI::months[last_month] + " " + QString::number(last_year);
else
QMessageBox::information(0, "KissCount", _("Any account updated !"));
delete[] deltas;
delete[] cur_amounts;
}

Archive Download the corresponding diff file