-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbank_management_system
264 lines (221 loc) · 7.4 KB
/
bank_management_system
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/bin/bash
# Function to display the main menu
menu()
{
echo "================================================================================"
echo " Bank Management System "
echo "================================================================================"
echo "Enter 1 to Create a new account."
echo "Enter 2 to Deposit."
echo "Enter 3 to Withdraw."
echo "Enter 4 to View account."
echo "Enter 5 to Check balance."
echo "Enter 6 to Delete account."
echo "Enter 7 to Exit."
}
# Function to create a new account
newaccount()
{
# Checking if the info.csv file exists, if not, creating it
if [ ! -f info.csv ]
then
touch info.csv
fi
# Getting account details from user
echo "Enter account no: "
read accno
# Validating account number input
while ! [[ $accno =~ [0-9]+$ ]]
do
echo "Please Enter a valid no:"
read accno
done
# Getting user account information
echo "Please Enter Full Name : "
read name
echo
echo "Enter Date of Birth: (Year-Month-Day)"
read bday
echo
echo "Enter Email Address: "
read email
echo
echo "Enter CNIC/ID Number :"
read id
echo
echo "Enter City Name : "
read city
echo
echo "Enter Phone Number : "
read phone
echo
echo "Select Account Type:"
echo "1. Saving"
echo "2. Current"
read accountType
# Validating account type input
case $accountType in
1) accountType="saving" ;;
2) accountType="current" ;;
*)
echo " Please Enter a valid option! "
read accountType
esac
# Getting initial deposit amount from user
echo "Enter How much money you want to deposit: "
read amount
# Validating deposit amount input
while ! [[ $amount =~ [0-9]+$ ]]
do
echo "Please Enter a valid amount:"
read amount
done
# Appending account details to info.csv file
echo "$accno, $name, $bday, $id, $email, $city, $phone, $accountType, $amount" >> info.csv
echo " The account has been created successfully"
}
# Function to view account details
viewaccount()
{
echo "Enter 1 to View Specific Account Details"
echo "Enter 2 to View all existing accounts."
read input
if [ "$input" == "1" ]
then
echo
echo "Input the ID number of the account:"
read id_num
echo "Here is the Details of the Customer: $id_num "
echo ""ID","Name","DOB","CNIC","Email","City","PhoneNo","AccountType","Amount""
awk -F"," -v num=$id_num '$1 == num' info.csv
elif [ "$input" == "2" ]
then
echo
echo "Here is the data of all accounts"
awk '{print}' | column -t info.csv
else
echo "false"
fi
}
# Function to delete an account
deleteaccount()
{
echo "Please Enter ID Of account to Delete"
read id_num
# Removing account with given ID from info.csv
awk -F"," -v num=$id_num '$1 != num' info.csv > delfile.csv
cp delfile.csv info.csv
echo "You have successfully deleted the account $id_num"
}
# Function to deposit money into an account
deposit()
{
echo "Enter ID Number"
read id_num
echo "Enter Amount You want to deposit"
read amount
# Validating deposit amount input
while ! [[ $amount =~ [0-9]+$ ]]
do
echo "Please Enter a valid amount:"
read amount
done
# Retrieving account details
acno=$(awk -F"," -v num=$id_num '$1 == num' info.csv | awk -F"," '{print $1}')
namee=$(awk -F"," -v num=$id_num '$1 == num' info.csv | awk -F"," '{print $2}')
dob=$(awk -F"," -v num=$id_num '$1 == num' info.csv | awk -F"," '{print $3}')
cnic=$(awk -F"," -v num=$id_num '$1 == num' info.csv | awk -F"," '{print $4}')
mail=$(awk -F"," -v num=$id_num '$1 == num' info.csv | awk -F"," '{print $5}')
cty=$(awk -F"," -v num=$id_num '$1 == num' info.csv | awk -F"," '{print $6}')
phne=$(awk -F"," -v num=$id_num '$1 == num' info.csv | awk -F"," '{print $7}')
acctype=$(awk -F"," -v num=$id_num '$1 == num' info.csv | awk -F"," '{print $8}')
currentBalance=$(awk -F"," -v num=$id_num '$1 == num' info.csv | awk -F"," '{print $9}')
# Displaing current balance and calculating new balance after deposit
echo "Current balance: $currentBalance"
newBalance=$(( currentBalance + amount ))
echo "New Balance: $newBalance"
# Removing account from info.csv file
awk -F"," -v num=$id_num '$1 != num' info.csv > delfile.csv
cp delfile.csv info.csv
# Appending updated account details to info.csv file
echo "$acno, $namee, $dob, $cnic, $mail, $cty, $phne, $acctype, $newBalance" >> info.csv
}
# Function to withdraw money from an account
withdraw()
{
echo "Enter ID Number"
read id_num
echo "Enter Amount You want to withdraw"
read amount
# Validating withdrawal amount input
while ! [[ $amount =~ [0-9]+$ ]]
do
echo "Please Enter a valid amount:"
read amount
done
# Retrieving account details
acno=$(awk -F"," -v num=$id_num '$1 == num' info.csv | awk -F"," '{print $1}')
namee=$(awk -F"," -v num=$id_num '$1 == num' info.csv | awk -F"," '{print $2}')
dob=$(awk -F"," -v num=$id_num '$1 == num' info.csv | awk -F"," '{print $3}')
cnic=$(awk -F"," -v num=$id_num '$1 == num' info.csv | awk -F"," '{print $4}')
mail=$(awk -F"," -v num=$id_num '$1 == num' info.csv | awk -F"," '{print $5}')
cty=$(awk -F"," -v num=$id_num '$1 == num' info.csv | awk -F"," '{print $6}')
phne=$(awk -F"," -v num=$id_num '$1 == num' info.csv | awk -F"," '{print $7}')
acctype=$(awk -F"," -v num=$id_num '$1 == num' info.csv | awk -F"," '{print $8}')
currentBalance=$(awk -F"," -v num=$id_num '$1 == num' info.csv | awk -F"," '{print $9}')
echo "Old balance: $currentBalance"
# Checking if withdrawal amount exceeds current balance
if [ $amount -le $currentBalance ]
then
newBalance=$(( currentBalance - amount ))
echo "New Balance: $newBalance"
# Removing account from info.csv file
awk -F"," -v num=$id_num '$1 != num' info.csv > delfile.csv
cp delfile.csv info.csv
# Appending updated account details to info.csv
echo "$acno, $namee, $dob, $cnic, $mail, $cty, $phne, $acctype, $newBalance" >> info.csv
else
echo "insufficient funds."
fi
}
# Function to check balance of an account
checkbalance()
{
echo "Please Enter ID Of account to check balance:"
read id_num
# Retrieving current balance from info.csv file and displaying it
currentBalance=$(awk -F"," -v num=$id_num '$1 == num' info.csv | awk -F"," '{print $9}')
echo "Current balance: $currentBalance"
}
# Main loop to display menu and execute selected operations
while [ "$option" != "7" ]
do
menu
echo "Enter option: "
read option
case $option in
1) newaccount
read temp
clear;;
2) deposit
read temp
clear;;
3) withdraw
read temp
clear;;
4) viewaccount
read temp
clear;;
5) checkbalance
read temp
clear;;
6) deleteaccount
read temp
clear;;
7) exit;;
*)
echo "Select a Valid Option"
read temp
clear;;
esac
done