diff --git a/src/main/java/com/aninfo/model/Account.java b/src/main/java/com/aninfo/model/Account.java index e9e683bc..248c4309 100644 --- a/src/main/java/com/aninfo/model/Account.java +++ b/src/main/java/com/aninfo/model/Account.java @@ -59,4 +59,12 @@ public ArrayList getTransactions() { return transactions; } + public Double getPromo() { + return promo; + } + + public void setPromo(Double promo) { + this.promo = promo; + } + } diff --git a/src/main/java/com/aninfo/service/AccountService.java b/src/main/java/com/aninfo/service/AccountService.java index 12846a3d..3ff22524 100644 --- a/src/main/java/com/aninfo/service/AccountService.java +++ b/src/main/java/com/aninfo/service/AccountService.java @@ -78,6 +78,14 @@ public Account deposit(Long cbu, Double sum) { account.setBalance(account.getBalance() + sum); account.addTransaction(new Transaction(sum, TransactionType.DEPOSIT)); + + if (sum >= 2000 && account.getPromo() > 0){ + Double promoApplied = Math.min(sum * 0.1, account.getPromo()); + account.setBalance(account.getBalance() + promoApplied); + account.setPromo(account.getPromo() - promoApplied); + account.addTransaction(new Transaction(promoApplied, TransactionType.PROMO)); + } + accountRepository.save(account); return account;