payment now stores a pointer to a negative value
This commit is contained in:
parent
ecac206fce
commit
40089ad861
@ -24,8 +24,8 @@ bool DateMoney::operator>=(const DateMoney &rhs) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &os, const DateMoney &money) {
|
std::ostream &operator<<(std::ostream &os, const DateMoney &money) {
|
||||||
os << "value: " << *money.value << " date: " << money.date->tm_mon + 1 << "/" << money.date->tm_mday << "/"
|
os << "Value: " << *money.value << " Date: " << money.date->tm_mon + 1 << "/" << money.date->tm_mday << "/"
|
||||||
<< money.date->tm_year;
|
<< money.date->tm_year+1900;
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
17
src/main.cpp
17
src/main.cpp
@ -74,11 +74,20 @@ int main(int argc, char *argv[]) {
|
|||||||
if (a != accounts.end()) {
|
if (a != accounts.end()) {
|
||||||
int value = a->second.getAccount()->getValue();
|
int value = a->second.getAccount()->getValue();
|
||||||
std::vector<DateMoney> timeline = a->second.getAccount()->getTimeline();
|
std::vector<DateMoney> timeline = a->second.getAccount()->getTimeline();
|
||||||
printf("Account value: %n\n", &value);
|
printf("Account value: %d\n", value);
|
||||||
printf("Last 10 payments:\n");
|
printf("Last 10 transactions:\n");
|
||||||
for (auto transaction : timeline) {
|
for (int i = 0; i < timeline.size() && i < 10; i++) {
|
||||||
|
const int *amount = timeline[i].getValue();
|
||||||
|
const tm *date = timeline[i].getDate();
|
||||||
|
if (*amount <= 0) {
|
||||||
|
printf("Value: \033[31m%d\033[0m, ", *amount);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("Value: \033[32m%d\033[0m, ", *amount);
|
||||||
|
}
|
||||||
|
printf("Date: %d/%d/%d ", date->tm_mon+1, date->tm_mday, date->tm_year+1900);
|
||||||
}
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (accountOptHandler.getSetOpts()->del) {
|
if (accountOptHandler.getSetOpts()->del) {
|
||||||
|
@ -29,7 +29,7 @@ int Account::getValue() {
|
|||||||
std::vector<DateMoney> Account::getTimeline() {
|
std::vector<DateMoney> Account::getTimeline() {
|
||||||
std::vector<DateMoney> timeline;
|
std::vector<DateMoney> timeline;
|
||||||
for (auto &payment : payments) {
|
for (auto &payment : payments) {
|
||||||
timeline.emplace_back(&payment.value, payment.getDate());
|
timeline.emplace_back(payment.getValue(), payment.getDate());
|
||||||
}
|
}
|
||||||
for (auto &earning : earnings) {
|
for (auto &earning : earnings) {
|
||||||
timeline.emplace_back(&earning.value, earning.getDate());
|
timeline.emplace_back(&earning.value, earning.getDate());
|
||||||
|
@ -6,8 +6,14 @@
|
|||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
Payment::Payment(const int value, Receipt receipt, std::tm date) : Transaction(value, date), receipt(std::move(receipt)) {}
|
Payment::Payment(const int value, Receipt receipt, std::tm date) : Transaction(value, date), receipt(std::move(receipt)) {
|
||||||
|
negativeValue = -value;
|
||||||
|
}
|
||||||
|
|
||||||
Receipt &Payment::getReceipt() {
|
Receipt &Payment::getReceipt() {
|
||||||
return receipt;
|
return receipt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int *Payment::getValue() {
|
||||||
|
return &negativeValue;
|
||||||
|
}
|
||||||
|
@ -15,8 +15,12 @@ public:
|
|||||||
|
|
||||||
Receipt &getReceipt();
|
Receipt &getReceipt();
|
||||||
|
|
||||||
|
const int *getValue();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Receipt receipt;
|
Receipt receipt;
|
||||||
|
|
||||||
|
int negativeValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user