Skip to content

Commit 394d9a5

Browse files
committed
Major progress on account management
1 parent a772c83 commit 394d9a5

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

java/App.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import dbdatabase.*;
2+
import jdk.vm.ci.meta.Local;
23

34
import java.io.File;
45
import java.time.LocalDateTime;
@@ -199,14 +200,31 @@ public static void main(String[] args) {
199200
accno = sb.toString();
200201
} while (a.doesAccountExist(accno));
201202
a.createNewAccount(custname,accno);
203+
a.appendAccountLog(accno,"DBDatabase: New account for Customer ID: "+custname+" created with Number: "+accno);
202204
a.editAccountDetail(accno,"name",accname);
205+
String time = "" + LocalDateTime.now();
206+
a.editAccountDetail(accno,"createdon",time.substring(0,time.indexOf("T")) + " " + time.substring(time.indexOf("T") + 1,time.lastIndexOf(".")).replace(':','@'));
207+
a.editAccountDetail(accno,"balance","0.0");
203208
a.editAccountDetail(accno,"type",acctype);
204209
return "<h4></h4><h6>Successfully Created Account with Account Number: " + accno;
205210
});
211+
212+
post("/getaccountpage", (req, res) -> {
213+
String accno = req.queryParams("accno");
214+
boolean admin = req.queryParams("privileged").equals("1");
215+
return Templates.accountpage(accno,admin,a);
216+
});
217+
218+
post("/alterbalance", (req, res) -> {
219+
String accno = req.queryParams("accno");
220+
String balance = req.queryParams("balance");
221+
a.editAccountDetail(accno,"balance",balance);
222+
return " ";
223+
});
206224
}
207225

208226
static String getCustomerManagementButton(String custname, CustomerDB c){
209-
return "<button onclick=\'loadCustomerDetails(\"" + custname + "\")\'><div>Customer ID: " + custname + "</div><div>Access Level: " +
227+
return "<button onclick=\'loadCustomerDetails(\"" + custname + "\")\'><div><h5>Customer ID: " + custname + "</h5></div><div>Access Level: " +
210228
(c.getCustomerDetail(custname,"accessLevel").equals("1")?"Administrator":"Regular") +
211229
"</div><div>Status: " + (c.isCustomerDeactivated(custname)?"Deactive":"Active") +
212230
"</div></button>";

java/Templates.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import dbdatabase.AccountDB;
2+
13
public class Templates {
24
static String administrator = "<button onclick=\"login()\" class=\"btn btn-warning\">Reset</button>\n" +
35
"<h5 style=\"display: inline-block; vertical-align: middle; margin-left: 25px; margin-right: 25px; margin-top: 28px; font-size: 32px; border: 3px solid #FFFFFF; padding-bottom: 6px; padding-top: 3px; padding-left: 8px; padding-right: 8px; border-radius: 20px\">Admin</h5>\n" +
@@ -12,7 +14,8 @@ public class Templates {
1214
"<div id=\"admin-dynamic-2\"></div>\n" +
1315
"<div id=\"admin-dynamic-3\"></div>\n" +
1416
"<div id=\"admin-dynamic-4\"></div>\n" +
15-
"<div id=\"admin-dynamic-5\"></div>";
17+
"<div id=\"admin-dynamic-5\"></div>\n" +
18+
"<div id=\"admin-dynamic-6\"></div>";
1619

1720
static String loginfail = "\n" +
1821
"<h4 style=\"display: block; margin-bottom: 50px\">Incorrect Credentials</h4>\n" +
@@ -40,4 +43,20 @@ static String createaccount(String custname){
4043
"<div></div>" +
4144
"<button onclick=\"submitCreateAccount(\'" + custname + "\')\">Create</button>";
4245
}
46+
47+
static String accountpage(String accno, boolean admin, AccountDB a){
48+
return "<h4>Account Number: " + accno + "</h4>\n" +
49+
"<h5>Name: " + a.getAccountDetail(accno,"name") + "</h5>" +
50+
"<h6>Created: " + a.getAccountDetail(accno,"createdon").replace('@',':') + "</h6>" +
51+
"<h6>Type: " + a.getAccountDetail(accno,"type") + "</h6>" +
52+
"<h6>Status: " + (a.isAccountOpen(accno)?"Open":"Closed") + "</h6>" +
53+
"<h5>Balance: ₹ " + a.getAccountDetail(accno,"balance") + "</h6>" +
54+
"<h4>Options</h4>" +
55+
(admin? "<button class=\"accmanbtns\" onclick=\'alterAccountBalance(\"" + accno + "\")\'>Alter Balance</button>" +
56+
"<button class=\"accmanbtns\" onclick=\'reopenAccount(\"" + accno + "\")\'>Reopen Account</button>"
57+
:"") +
58+
"<button class=\"accmanbtns\" onclick=\'changeAccountName(\"" + accno + "\")\'>Change Name</button>" +
59+
(a.isAccountOpen(accno)?"<button class=\"accmanbtns\" onclick=\'closeAccount(\"" + accno + "\")\'>Close Account</button>":"") +
60+
"<button class=\"accmanbtns\" onclick=\'transferFundsFrom(\"" + accno + "\")\'>Transfer Funds</button>";
61+
}
4362
}

resources/public/scripts/app.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,41 @@ function submitCreateAccount(custname){
273273

274274
function loadAccountDetails(accno){
275275
$('.accbtns').prop('disabled', true);
276+
var form = {
277+
'accno' : accno
278+
'privileged' : '1'
279+
}
280+
$.ajax({
281+
type: 'POST',
282+
url: '/getaccountpage',
283+
data: form,
284+
success: function(response){
285+
$('#admin-dynamic-4').html(response);
286+
}
287+
});
288+
}
289+
290+
function alterAccountBalance(accno){
291+
$('.accmanbtns').prop('disabled', true);
292+
$('#admin-dynamic-5').html("<h4></h4>"+
293+
"<input type=\"number\" step=\"any\" name=\"alterbalance\" placeholder=\"New Balance\"</input>"+
294+
+"<button onclick=\"alterBalance('" + accno + "')\">Change</button>");
295+
}
296+
297+
function alterBalance(accno){
298+
var newbalance = $("[name='alterbalance']")[0].value;
299+
var form = {
300+
'accno' : accno,
301+
'balance' : newbalance
302+
};
303+
$.ajax({
304+
type: 'POST',
305+
url: '/alterbalance',
306+
data: form,
307+
success: function(response){
308+
$('#admin-dynamic-6').html("<h4></h4><h6>Successfully Changed Balance for Account Number: "+accno+" to: ₹ "+newbalance+"</h6>");
309+
}
310+
});
276311
}
277312

278313
function getTransferPage(custname){

0 commit comments

Comments
 (0)