-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBalanceManager.cpp
More file actions
324 lines (271 loc) · 12.4 KB
/
Copy pathBalanceManager.cpp
File metadata and controls
324 lines (271 loc) · 12.4 KB
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#include "BalanceManager.h"
void BalanceManager::addIncome() {
Income income;
system("cls");
cout << " >>> DODAWANIE NOWEGO PRZYCHODU <<<" << endl << endl;
income = enterNewInfoAboutIncome();
incomes.push_back(income);
if (incomeFile.appendIncomeToFile(income))
cout << endl << "Nowy przychod zostal dodany" << endl << endl;
else
cout << "Blad. Nie udalo sie dodac nowego przychodu do pliku." << endl;
system("pause");
}
void BalanceManager::addExpense() {
Expense expense;
system("cls");
cout << " >>> DODAWANIE NOWEGO WYDATKU <<<" << endl << endl;
expense = enterNewInfoAboutExpense();
expenses.push_back(expense);
if (expensesFile.appendExpenseToFile(expense))
cout << endl << "Nowy wydatek zostal dodany" << endl << endl;
else
cout << "Blad. Nie udalo sie dodac nowego wydatku do pliku." << endl;
system("pause");
}
Income BalanceManager::enterNewInfoAboutIncome() {
Income income;
char choice;
string date, item, amount;
income.setUserId(ID_OF_LOGGED_USER);
income.setIncomeId(incomeFile.getIdOfLastIncome()+1);
cout << "czy przychod dotyczy dnia dzisiejszego, tak lube nie (t/n)? ";
do {
choice = AdjuvantMethods::loadMark();
switch (choice) {
case 't':
date = AdjuvantMethods::getCurrentDate();
income.setDate(date);
break;
case 'n':
cout << "podaj date w formacie rrrr-mm-dd np. 2017-11-01: ";
date = AdjuvantMethods::readLine();
if (AdjuvantMethods::checkIfDateIsCorrect(date) == true) {
income.setDate(date);
break;
} else {
cout << endl << "wprowadzona data jest niepoprawna " << endl;
choice = ' ';
}
default:
cout << "sprobuj ponownie wybierajac (t/n) ";
}
} while(choice != 't' && choice != 'n');
cout << endl << "Napisz czego dotyczyl przychod: ";
item = AdjuvantMethods::readLine();
income.setItem(item);
cout << endl << "Podaj wysokosc przychodu: ";
amount = AdjuvantMethods::readLine();
amount = AdjuvantMethods::changeCommaToDot(amount);
income.setAmount(amount);
return income;
}
Expense BalanceManager::enterNewInfoAboutExpense() {
Expense expense;
char choice;
string date, item, amount;
expense.setUserId(ID_OF_LOGGED_USER);
expense.setExpenseId(expensesFile.getIdOfLastExpense()+1);
cout << "czy wydatek dotyczy dnia dzisiejszego, tak lube nie (t/n)? ";
do {
choice = AdjuvantMethods::loadMark();
switch (choice) {
case 't':
date = AdjuvantMethods::getCurrentDate();
expense.setDate(date);
break;
case 'n':
cout << "podaj date w formacie rrrr-mm-dd np. 2017-11-01: ";
date = AdjuvantMethods::readLine();
if (AdjuvantMethods::checkIfDateIsCorrect(date) == true) {
expense.setDate(date);
break;
} else {
cout << endl << "wprowadzona data jest niepoprawna " << endl;
choice = ' ';
}
default:
cout << "sprobuj ponownie wybierajac (t/n) ";
}
} while(choice != 't' && choice != 'n');
cout << endl << "Napisz czego dotyczyl wydatek: ";
item = AdjuvantMethods::readLine();
expense.setItem(item);
cout << endl << "Podaj wysokosc wydatku: ";
amount = AdjuvantMethods::readLine();
amount = AdjuvantMethods::changeCommaToDot(amount);
expense.setAmount(amount);
return expense;
}
void BalanceManager::showIncomeData() {
balance = 0;
double sumOfIncomes = 0;
int AmountOfDaysFromCurrentMonth = AdjuvantMethods::getAmountOfDaysFromCurrentMonth();
int lastDateInInt = AdjuvantMethods::getDateOfLastDayFromCurrentMonthInInt();
int dateFromVector = 0;
sort(incomes.begin(),incomes.end());
for (int i = 0; i < incomes.size(); i++) {
dateFromVector = AdjuvantMethods::convertDateToInt(incomes[i].getDate());
if ( (dateFromVector <= lastDateInInt) && (dateFromVector >= lastDateInInt - AmountOfDaysFromCurrentMonth)) {
cout << endl << "Id przychodu: " << incomes[i].getIncomeId() << endl;
cout << "Data uzyskania przychodu: " << incomes[i].getDate() << endl;
cout << "Przychod z tytulu: " << incomes[i].getItem() << endl;
cout << "Kwota przychodu: " << incomes[i].getAmount() << endl;
sumOfIncomes += atof(incomes[i].getAmount().c_str());
}
}
cout << endl << "Suma przychodow w tym miesiacu wynosi: " << sumOfIncomes <<" zl" << endl;
balance = sumOfIncomes;
}
void BalanceManager::showExpensesData() {
double sumOfExpenses = 0;
int AmountOfDaysFromCurrentMonth = AdjuvantMethods::getAmountOfDaysFromCurrentMonth();
int lastDateInInt = AdjuvantMethods::getDateOfLastDayFromCurrentMonthInInt();
int dateFromVector = 0;
sort(expenses.begin(),expenses.end());
for (int i = 0; i < expenses.size(); i++) {
dateFromVector = AdjuvantMethods::convertDateToInt(expenses[i].getDate());
if ( (dateFromVector <= lastDateInInt) && (dateFromVector >= lastDateInInt - AmountOfDaysFromCurrentMonth)) {
cout << endl << "Id wydatku: " << expenses[i].getExpenseId() << endl;
cout << "Data wydatku: " << expenses[i].getDate() << endl;
cout << "Wydatek z tytulu: " << expenses[i].getItem() << endl;
cout << "Kwota wydatku: " << expenses[i].getAmount() << endl;
sumOfExpenses += atof(expenses[i].getAmount().c_str());
}
}
cout << endl << "Suma wydatkow w tym miesiacu wynosi: " << sumOfExpenses <<" zl";
balance -= sumOfExpenses;
}
void BalanceManager::showBilanceFromCurrentMonth() {
system("cls");
cout << " >>> BILANS Z BIEZACEGO MIESIACA <<<" << endl;
cout << "-----------------------------------------------" << endl;
cout << " >>> PRZYCHODY <<<" << endl;
showIncomeData();
cout << endl;
cout << " >>> WYDATKI <<<" << endl;
showExpensesData();
cout << endl;
cout << "-----------------------------------------------" << endl;
cout << " >>> BILANS <<<" << endl << endl;
cout << balance << "zl" << endl << endl;
if (balance > 0)
cout << "Twoj bilans jest dodatni, trzymaj tak dalej" << endl << endl;
else
cout << "Twoj bilans jest ujemny, uwazaj na wydatki" << endl;
balance = 0;
system("pause");
}
void BalanceManager::showBilanceFromLastMonth() {
system("cls");
cout << " >>> BILANS Z OSTATNIEGO MIESIACA <<<" << endl;
cout << "-----------------------------------------------" << endl;
cout << " >>> PRZYCHODY <<<" << endl;
showIncomeDataFromLastMonth();
cout << endl;
cout << "-----------------------------------------------" << endl;
cout << " >>> WYDATKI <<<" << endl;
showExpensesDataFromLastMonth();
cout << endl;
cout << "-----------------------------------------------" << endl;
cout << " >>> BILANS <<<" << endl << endl;
cout << balance << "zl" << endl << endl;
if (balance > 0)
cout << "Twoj bilans jest dodatni, trzymaj tak dalej" << endl << endl;
else
cout << "Twoj bilans jest ujemny, uwazaj na wydatki" << endl;
balance = 0;
system("pause");
}
void BalanceManager::showIncomeDataFromLastMonth() {
balance = 0;
double sumOfIncomes = 0;
int AmountOfDaysFromLastMonth = AdjuvantMethods::getAmountOfDaysFromLastMonth();
int lastDateInInt = AdjuvantMethods::getDateOfLastDayFromLastMonthInInt();
int dateFromVector = 0;
sort(incomes.begin(),incomes.end());
for (int i = 0; i < incomes.size(); i++) {
dateFromVector = AdjuvantMethods::convertDateToInt(incomes[i].getDate());
if ( (dateFromVector <= lastDateInInt) && (dateFromVector >= lastDateInInt - AmountOfDaysFromLastMonth)) {
cout << endl << "Id przychodu: " << incomes[i].getIncomeId() << endl;
cout << "Data uzyskania przychodu: " << incomes[i].getDate() << endl;
cout << "Przychod z tytulu: " << incomes[i].getItem() << endl;
cout << "Kwota przychodu: " << incomes[i].getAmount() << endl;
sumOfIncomes += atof(incomes[i].getAmount().c_str());
}
}
cout << endl << "Suma przychodow w ostatnim miesiacu wyniosla: " << sumOfIncomes <<" zl" << endl;
balance = sumOfIncomes;
}
void BalanceManager::showExpensesDataFromLastMonth() {
double sumOfExpenses = 0;
int AmountOfDaysFromLastMonth = AdjuvantMethods::getAmountOfDaysFromLastMonth();
int lastDateInInt = AdjuvantMethods::getDateOfLastDayFromLastMonthInInt();
int dateFromVector = 0;
sort(expenses.begin(),expenses.end());
for (int i = 0; i < expenses.size(); i++) {
dateFromVector = AdjuvantMethods::convertDateToInt(expenses[i].getDate());
if ( (dateFromVector <= lastDateInInt) && (dateFromVector >= lastDateInInt - AmountOfDaysFromLastMonth)) {
cout << endl << "Id wydatku: " << expenses[i].getExpenseId() << endl;
cout << "Data wydatku: " << expenses[i].getDate() << endl;
cout << "Wydatek z tytulu: " << expenses[i].getItem() << endl;
cout << "Kwota wydatku: " << expenses[i].getAmount() << endl;
sumOfExpenses += atof(expenses[i].getAmount().c_str());
}
}
cout << endl << "Suma wydatkow w tym miesiacu wynosi: " << sumOfExpenses <<" zl";
balance -= sumOfExpenses;
}
void BalanceManager::showBalanceFromSelectedPeriodOfTime() {
string firstDate, lastDate;
double sumOfIncomes = 0;
double sumOfExpenses = 0;
balance = 0;
system("cls");
cout << " >>> BILANS Z WYBRANEGO OKRESU <<<" << endl;
cout << "-----------------------------------------------" << endl;
cout << "Podaj, od jakiego dnia policzyc bilans (rrrr-mm-dd np. 2017-11-01): ";
firstDate = AdjuvantMethods::readLine();
if (AdjuvantMethods::checkIfDateIsCorrect(firstDate) == true) {
cout << endl << "Podaj, do jakiego dnia policzyc bilans (rrrr-mm-dd np. 2017-11-01): " ;
lastDate = AdjuvantMethods::readLine();
if (AdjuvantMethods::checkIfDateIsCorrect(lastDate) == true) {
sort(incomes.begin(),incomes.end());
sort(expenses.begin(),expenses.end());
cout << endl << " >>> PRZYCHODY <<<" << endl;
for (int i = 0; i < incomes.size(); i++) {
if ( (incomes[i].getDate() >= firstDate) && (incomes[i].getDate() <= lastDate) ) {
cout << endl << "Id przychodu: " << incomes[i].getIncomeId() << endl;
cout << "Data przychodu: " << incomes[i].getDate() << endl;
cout << "Przychod z tytulu: " << incomes[i].getItem() << endl;
cout << "Kwota przychodu: " << incomes[i].getAmount() << endl;
sumOfIncomes += atof(incomes[i].getAmount().c_str());
}
}
cout << endl << " >>> WYDATKI <<<" << endl;
for (int i = 0; i < expenses.size(); i++) {
if ( (expenses[i].getDate() >= firstDate) && (expenses[i].getDate() <= lastDate) ) {
cout << endl << "Id wydatku: " << expenses[i].getExpenseId() << endl;
cout << "Data wydatku: " << expenses[i].getDate() << endl;
cout << "Wydatek z tytulu: " << expenses[i].getItem() << endl;
cout << "Kwota wydatku: " << expenses[i].getAmount() << endl;
sumOfExpenses += atof(expenses[i].getAmount().c_str());
}
}
}
balance = sumOfIncomes - sumOfExpenses;
cout << endl;
cout << "-----------------------------------------------" << endl;
cout << " >>> BILANS <<<" << endl << endl;
cout << balance << "zl" << endl << endl;
if (balance > 0)
cout << "Twoj bilans jest dodatni, trzymaj tak dalej" << endl << endl;
else
cout << "Twoj bilans jest ujemny, uwazaj na wydatki" << endl;
balance = 0;
system("pause");
} else {
cout << "Wprowadzona data jest nieprawidlowa, sprobuj ponownie pozniej" << endl;
system("pause");
}
}