-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
192 lines (178 loc) · 6.8 KB
/
main.py
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
import time
import getpass
from system.cmd import CMD
from system.database import Database
from system.account import Account
from system.withdraw import Withdraw
from system.transfer import Transfer
from system.deposit import Deposit
class ATM(object):
def __init__(self) -> None:
super().__init__()
self.database = Database("database/database.db")
self.database.connect()
self.cmd = CMD()
self.account = Account()
self.withdraw = Withdraw()
self.tf = Transfer()
self.deposit = Deposit()
self.isLogin = False
self.cardNumber = ""
def login(self):
count = 0
while True:
count += 1
self.cmd.clear()
number = input("Masukan nomor rekening: ")
pin = input("Masukan pin rekening: ")
if (int(len(number)) == 0) or (int(len(pin)) == 0):
print ("[INFO]: Masukan nomor rekening atau pin!")
else:
if self.account.isValidCard(number, pin) is True:
self.isLogin = True
self.cardNumber = number
break
else:
time.sleep(2)
return True
def logout(self):
self.isLogin = False
def tarikTunai(self):
while True:
self.cmd.clear()
nominal = input("Masukan nominal penarikan: ")
withdraw = self.withdraw.get(self.cardNumber, nominal)
if withdraw is True:
while True:
y = getpass.getpass("Tekan enter untuk kembali")
if y == "": return True
else: continue
else:
time.sleep(2)
def infoSaldo(self):
while True:
self.cmd.clear()
data = self.database.get("balance", "card", f"card_number={self.cardNumber}")
print (f"Kamu memiliki saldo sebesar: {data[0][0]}")
y = getpass.getpass("Tekan enter untuk kembali")
if y == "": return True
else: continue
def transfer(self):
while True:
self.cmd.clear()
rekening = input("Masukan rekening tujuan: ")
nominal = input("Masukan nominal: ")
y = input("Apakah tujuan benar? (Y/n): ")
if y.lower() == "y":
if self.tf.transfer(nominal, self.cardNumber, rekening):
while True:
y = getpass.getpass("Tekan enter untuk kembali")
if y == "": return True
else: continue
else: time.sleep(3)
else:
continue
def tambahSaldo(self):
while True:
self.cmd.clear()
nominal = input("Masukan jumlah: ")
if self.deposit.deposit(self.cardNumber, nominal):
while True:
y = getpass.getpass("Tekan enter untuk kembali")
if y == "": return True
else: continue
else: time.sleep(3)
def ubahPin(self):
while True:
self.cmd.clear()
pinLama = input("Masukan pin lama: ")
pinBaru = input("Masukan pin baru: ")
cpinBaru = input("Konfirmasi pin baru: ")
getOldPin = self.database.get("pin", "users", f"pin={pinLama}")
if int(len(getOldPin)) == 0:
print ("[INFO]: Maaf pin salah, silahkan coba lagi")
time.sleep(3)
continue
else:
if int(len(pinBaru)) == 4:
if pinBaru == cpinBaru:
self.database.update("users", f"pin={pinBaru}", f"pin={pinLama}")
self.database.update("card", f"card_pin={pinBaru}", f"card_pin={pinLama}")
print ("[INFO]: Pin berhasil diubah")
while True:
y = getpass.getpass("Tekan enter untuk kembali")
if y == "": return True
else: continue
else:
print ("[INFO]: Pin baru tidak cocok")
time.sleep(3)
continue
else:
print ("[INFO]: Pin terdiri dari 4 digit")
time.sleep(3)
continue
def buatRekening(self):
while True:
self.cmd.clear()
username = input("Masukan nama unik: ")
nama = input("Masukan nama lengkap: ")
pin = input("Masukan pin: ")
if (int(len(username)) == 0) or (int(len(nama)) == 0) or (int(len(pin)) == 0):
print ("[INFO]: Username, nama, pin tidak boleh kosong!")
continue
else:
if self.account.createCredit(username, nama, pin):
while True:
enter = input("[INFO[: Tekan 'enter' untuk kembali")
if enter == "":
return True
y = input("Ulangi? (Y/n): ")
if y.lower() == "y": continue
else: break
def mainmenu(self):
while True:
self.cmd.clear()
menu = ["Tarik tunai", "Info saldo", "Transfer", "Tambah saldo", "Ubah pin"]
print ("Menu: ")
for i in range(0, int(len(menu))):
print (f"\t{i+1}). {menu[i]}")
print ("\t0). Logout")
i = input("Pilih: ")
if i == "1" or i == "01":
self.tarikTunai()
elif i == "2" or i == "02":
self.infoSaldo()
elif i == "3" or i == "03":
self.transfer()
elif i == "4" or i == "04":
self.tambahSaldo()
elif i == "5" or i == "05":
self.ubahPin()
elif i == "0" or i == "00":
self.isLogin = False
break
def main(self):
self.cmd.clear()
print ("""\t ATM:
\t ╔╗╔┬ ┬┌─┐┌─┐┌┐┌┌┬┐┌─┐┬─┐┌─┐
\t ║║║│ │└─┐├─┤│││ │ ├─┤├┬┘├─┤
\t ╝╚╝└─┘└─┘┴ ┴┘└┘ ┴ ┴ ┴┴└─┴ ┴
\t ATM Based CLI""")
time.sleep(5)
while True:
self.cmd.clear()
print ("Menu: ")
print ("\t1). Login")
print ("\t2). Buat rekening")
print ("\t0). Exit")
i = input("Pilih: ")
if i == "1" or i == "01":
if self.login():
self.mainmenu()
elif i == "2" or i == "02":
self.buatRekening()
elif i == "0" or i == "00":
self.cmd.exit(noLog=True)
if __name__ == "__main__":
atm = ATM()
atm.main()