Finance manager
Лабораторна робота №2 - Документація коду
Loading...
Searching...
No Matches
Budget.h
Go to the documentation of this file.
1#pragma once
2#include <string>
3#include <vector>
4#include "Transaction.h"
5
6
7class Budget {
8public:
9 std::string id;
10 std::string userId;
11 std::string categoryId;
12 double amount = 0.0; // period amount
13 std::string period; // monthly | weekly | yearly
14 std::vector<std::string> rules;
15 std::string note;
16
17
18 void applyBudgetRules(const std::vector<Transaction>& txs);
19 double suggestSavings(const std::vector<Transaction>& txs) const;
20};
21
22
23inline void Budget::applyBudgetRules(const std::vector<Transaction>& txs) {
24
25 (void)txs;
26}
27inline double Budget::suggestSavings(const std::vector<Transaction>& txs) const {
28 double spent = 0.0;
29 for (const auto &t : txs) if (t.categoryId == categoryId) spent += t.amount;
30 double over = spent - amount;
31 return over > 0.0 ? over : 0.0;
32}
Оголошення класу Transaction, що представляє одну фінансову операцію.
Definition Budget.h:7
void applyBudgetRules(const std::vector< Transaction > &txs)
Definition Budget.h:23
std::string userId
Definition Budget.h:10
std::string note
Definition Budget.h:15
double suggestSavings(const std::vector< Transaction > &txs) const
Definition Budget.h:27
std::string id
Definition Budget.h:9
std::string categoryId
Definition Budget.h:11
std::vector< std::string > rules
Definition Budget.h:14
std::string period
Definition Budget.h:13
double amount
Definition Budget.h:12