Beispiel #1
0
bool
Budget::ChangeDate(string category, string oldtimestamp, string newtimestamp)
{
  if (!_CategoryExists(category)) {
    return false;
  }
  
  Category* c = _categories.find(category)->second;
  
  // Don't do anything if the old timestamp doesn't exist
  if (c->Transactions()->count(oldtimestamp) == 0) {
    return false;
  }
  
  // Don't do anything if the new timestamp already exists
  if (c->Transactions()->count(newtimestamp) > 0) {
    return false;
  }
  
  // Temporarily remove the transaction
  Transaction* t = c->Transactions()->find(oldtimestamp)->second;
  c->Transactions()->erase(oldtimestamp);
  
  // Rename it
  t->SetTimestamp(newtimestamp);
  c->AddTransaction(t);
  
  return true;
}
Beispiel #2
0
void
Budget::AddTransaction(string category, string timestamp, string reason, float amount, string action)
{
  if (!_CategoryExists(category)) {
    _categories[category] = new Category(category);
  }
  
  Category* c = _categories.find(category)->second;
  
  // Create the new transaction
  Transaction* t = new Transaction(timestamp, reason, amount, action);
  
  c->AddTransaction(t);
}
Beispiel #3
0
void
Budget::AddCategory(string category, float amount)
{
  // Don't do anything if the category already exists
  if (_CategoryExists(category)) {
    return;
  }
  
  Category* c = new Category(category);
  
  // Set the initial amount
  // TODO: Set the timestamp to current time
  Transaction* t = new Transaction("2011030111123", "Initial amount",
    amount, Transaction::ADD);
  
  c->AddTransaction(t);
  
  _categories[category] = c;
}