Prechádzať zdrojové kódy

Update account balance when a transaction is added.

Lee Morgan 10 mesiacov pred
rodič
commit
578a73a57b
1 zmenil súbory, kde vykonal 9 pridanie a 0 odobranie
  1. 9 0
      src/views/js/data/Account.js

+ 9 - 0
src/views/js/data/Account.js

@@ -187,6 +187,15 @@ export default class Account{
 
     addTransaction(transaction){
         this._transactions.push(transaction);
+
+        console.log(transaction.category.type);
+        if(transaction.category.type === "Income"){
+            this._balance += transaction.amount;
+        }else{
+            this._balance -= transaction.amount;
+        }
+
+        this.save();
         this.sortTransactions();
     }