Commit a8a2acf5 authored by Leo Peron's avatar Leo Peron
Browse files

Updating files

parent 88c80188
from typing import List
class Display:
def __init__(self, req):
self.req = req
self.account_type = ["courant", "revolving", "epargne"]
self.operation_type = ["cartebleue", "virement", "chequier", "guichet"]
def printOperation(self, raw: List[str], type: str) -> None:
if not raw:
return print('Opération non trouvée')
if type == 'virement':
print(
f"ID: {raw[0]}, Date: {raw[6]}, Montant: {raw[5]}, ID-Compte: {raw[1] or raw[2] or raw[3]}, Etat: {raw[7]}")
elif type == 'cartebleue':
print(f"ID: {raw[0]}, Date: {raw[5]}, Montant: {raw[4]}, ID-Compte: {raw[1] or raw[2]}, Etat: {raw[6]}")
elif type == 'cheque':
print(f"ID: {raw[0]}, Date: {raw[5]}, Montant: {raw[4]}, ID-Compte: {raw[1] or raw[2]}, Etat: {raw[6]}")
elif type == 'guichet':
print(
f"ID: {raw[0]}, Date: {raw[6]}, Montant: {raw[5]}, ID-Compte: {raw[1] or raw[2] or raw[3]}, Etat: {raw[7]}")
else:
print("Bug")
def printAccount(self, raw: List[str], type: str, join: bool) -> None:
if not raw:
return print('Compte non trouvé')
d = 0
if join:
d = 4
if type == 'courant':
print(
f"ID: {raw[0 + d]}, Statut: {raw[2 + d]} Solde: {raw[5 + d]}, Decouvert autorisé: {raw[6 + d]}, Début découvert: {raw[7 + d]}")
elif type == 'epargne':
print(
f"ID: {raw[0 + d]}, Statut: {raw[2 + d]}, Solde: {raw[5 + d]}, Interet: {raw[3 + d]}, Plafond: {raw[4 + d]}")
elif type == 'revolving':
print(
f"ID: {raw[0 + d]}, Statut: {raw[2 + d]}, Solde: {raw[5 + d]}, Taux: {raw[3 + d]}, Montant négocié: {raw[4 + d]}")
else:
print("Bug")
def displayUserAccounts(self, num: int):
raws=[]
for type in self.account_type:
raws = self.req.getUserAccounts(num, type)
print(f'---------- Compte {type} ----------')
if raws:
for raw in raws:
self.printAccount(raw, type, True)
def displayUserOperations(self, num: int):
raws=[]
for type in self.operation_type:
raws = self.req.getUserOperations(num, type)
print(f'---------- Opérations {type} ----------')
if raws:
for raw in raws:
self.printOperation(raw, type)
def displayAllAccounts(self):
raws = []
for type in self.account_type:
raws = self.req.getAccountsByType(type)
print(f'---------- Compte {type} ----------')
if raws:
for raw in raws:
self.printAccount(raw, type, False)
import requests as r
from typing import List
import display as d
req = r.Requests()
disp = d.Display(req)
def main():
i=0
while i != 3:
while i != 5:
print("GESTION DE COMPTES BANCAIRES")
print("---------------------------- \n")
print("Selectionnez l'action souhaitée")
print("1.Connectez vous")
print("2.Inscrivez vous")
print("3.Arreter le programme")
print("3. Modifier un profil")
print("4. Supprimer un profil")
print("5.Arreter le programme")
i = int(input())
......@@ -37,147 +41,120 @@ def main():
print("Le client a bien été crée")
else:
print("Client déjà existant")
elif i == 3:
modifyProfile(num)
elif i==4:
deleteProfile(num)
def userInterface(raw: List[str]):
i = 0
while i != 7:
while i != 10:
print("---------------------------------------")
print(
f"Bonjour {raw[1]}, \n Numéro de téléphone: {raw[0]} \n Adresse: {raw[2]}"
)
print("---------------------------------------")
print("1. Voir vos comptes et réaliser des opérations")
print("1. Voir vos comptes")
print("2. Voir vos opérations")
print("3. Ajouter un compte")
print("4. Retirer un compte")
print("6. Modifier votre profil")
print("7. Supprimer votre profil")
print("8. Se Deconnecter")
print("5. Réaliser une opération")
print("6. Rechercher une opération")
print("7. Rechercher un compte")
print("8. Créer un compte")
i = int(input("Choississez l'option: "))
print("10. Se Deconnecter")
i = int(input("Choississez l'option: "))
if i == 1:
displayAccount(raw[0], 'courant')
disp.displayUserAccounts(raw[0])
elif i==2:
displayAccount(raw[0], 'epargne')
elif i==3:
displayAccount(raw[0], 'revolving')
elif i==4:
type = str(input("Quel type d'opération voulez-vous afficher ? "))
elif i==12:
accountsInterface(raw)
disp.displayUserOperations(raw[0])
elif i == 3:
disp.displayAllAccounts()
addUser(raw[0])
elif i == 4:
disp.displayUserAccounts(raw[0])
removeAccount(raw[0])
elif i==5:
makeOperation(raw[0])
pass
elif i==6:
modifyProfile(raw[0])
findOperation()
elif i==7:
deleteProfile(raw[0])
def accountsInterface(user: List[str]):
print('-----------------------------------------')
print('Compte Courants:')
print('-----------------------------------------')
raws = req.getCourantAccounts()
for raw in raws:
printAccount(raw, 'courant', False)
print('-----------------------------------------')
print('Compte Epargne:')
print('-----------------------------------------')
raws = req.getEpargneAccounts()
for raw in raws:
printAccount(raw, 'epargne', False)
print('-----------------------------------------')
print('Compte Revolving:')
print('-----------------------------------------')
raws = req.getRevolvingAccounts()
for raw in raws:
printAccount(raw, 'revolving', False)
print('-----------------------------------------')
type = str(input("Quel type de compte voulez-vous ajouter à l'utilisateur ? "))
id = str(input("Quel est l'ID de ce compte ? "))
result = req.addUserToAccount(raw[0], id, type)
findCompte()
elif i==8:
creerCompte(raw[0])
# CONNEXION
def modifyProfile(num: int):
nom = str(input("Entrez votre prénom et votre nom"))
adresse = str(input("Entrez votre adresse"))
result = req.modifyUser(num, nom, adresse)
if result:
print("L'utilisateur a bien été ajouté")
print("La modification a fonctionné")
else:
print("Erreur dans l'ajout de l'utilisateur")
def userAccountsInterface(num: int, ):
displayAccount(num, 'courant')
displayAccount(num, 'epargne')
displayAccount(num, 'revolving')
def displayAccount(num: int, type: str):
raws = []
if type == 'courant':
raws = req.getUserCourantAccounts(num)
elif type == 'epargne':
raws = req.getUserEpargneAccounts(num)
elif type == 'revolving':
raws = req.getUserRevolvingAccounts(num)
if not raws:
return print(f'Auncun compte {type} trouvé')
for raw in raws:
print(f'---------- Compte {type}')
printAccount(raw, type, True)
def printAccount(raw: List[str], type: str, join: bool) -> None:
d=0
if join:
d = 4
if type == 'courant':
print(f"ID: {raw[0+d]}, Statut: {raw[2+d]} Solde: {raw[5+d]}, Decouvert autorisé: {raw[6+d]}, Début découvert: {raw[7+d]}")
elif type == 'epargne':
print(f"ID: {raw[0+d]}, Statut: {raw[2+d]}, Solde: {raw[5+d]}, Interet: {raw[3+d]}, Plafond: {raw[4+d]}")
elif type == 'revolving':
print(f"ID: {raw[0+d]}, Statut: {raw[2+d]}, Solde: {raw[5+d]}, Taux: {raw[3+d]}, Montant négocié: {raw[4+d]}")
print("La modification n'a pas fonctionné")
pass
def deleteProfile(num: int):
result = req.deleteUser(num)
if result:
print("Votre compte a bien été supprimé")
else:
print("Bug")
print("Votre compte n'a pas être supprimé")
def makeOperation(num: int):
pass
# INTERFACE DE COMPTE
def addAccount(num: int, id: int):
result = req.addUserToAccount(num, id, 'courant')
def addUser(num: int):
type = str(input("A quel type de compte voulez-vous être ajouté ? "))
id = str(input("Quel est l'id de ce compte ? "))
result = req.addUserToAccount(num, id, type)
if result:
return print("Vous avez bien été ajouté à ce compte")
else:
return print("Ce compte n'existe pas ou il vous appartient déjà")
def removeAccount(num: int):
result = req.removeUserFromAccount(num, id, 'courant')
type = str(input("A quel type de compte voulez-vous être retiré ? "))
id = str(input("Quel est l'id de ce compte ? "))
result = req.removeUserFromAccount(num, id, type)
if result:
return print("Vous avez bien été retiré de ce compte")
else:
return print("Ce compte n'existe pas ou il ne vous appartient pas")
def findOperation():
type = str(input("Quel type d'opération cherchez-vous ? "))
date = str(input("Quelle est la date de cette opération ? "))
result = req.getOperationByDate(date, type)
disp.printOperation(result, type)
def modifyProfile(num: int):
nom = str(input("Entrez votre prénom et votre nom"))
adresse = str(input("Entrez votre adresse"))
result = req.modifyUser(num, nom, adresse)
if result:
print("La modification a fonctionné")
else:
print("La modification n'a pas fonctionné")
pass
def findCompte():
type = str(input("Quel type de compte cherchez-vous ? "))
id = str(input("Quel est l'id de ce compte ? "))
result = req.getAccountById(id)
disp.printAccount(result, result, type, False)
def deleteProfile(num: int):
result = req.deleteUser(num)
def makeOperation(num: int):
typeOperation = str(input("Quel type d'opération voulez-vous faire ? "))
montant = int(input("Quel est le montant de l'opération ? "))
disp.displayUserAccounts(num)
typeCompte = str(input("Sur quel type de compte voulez-vous faire l'opération ? "))
id = int(input("Quel est l'id du compte ? "))
result = req.createOperation(id, num, typeOperation, typeCompte, montant)
if result:
print("Votre compte a bien été supprimé")
return print("L'opération a bien été effectué")
else:
print("Votre compte n'a pas être supprimé")
return print("Erreur dans la réalisation de l'opération")
def creerCompte(num: int):
type = str(input("Quel type d'opération cherchez-vous ? "))
pass
if __name__ == "__main__":
main()
......@@ -15,7 +15,7 @@ class Requests:
self.account_state = ["Ouvert", "Bloqué", "Fermé"]
self.operation_state = ["Traitée", "Non Traitée"]
self.account_type = ["courant", "revolving", "epargne"]
self.operation_type = ["cartebleu", "virement", "chequier", "espece"]
self.operation_type = ["cartebleue", "virement", "chequier", "guichet"]
def __connect(self):
try:
......@@ -33,26 +33,12 @@ class Requests:
else:
return None
# GESTION D'UN UTILISATEUR
def getUserByNum(self, num: int) -> List[str]:
self.cur.execute("SELECT * FROM clients WHERE telephone = %s", (num,))
return self.cur.fetchone()
def getUserAccountsId(self, num: int):
self.cur.execute(
"SELECT Courant, Revolving, Epargne FROM Appartenance WHERE client = %s",
(num,),
)
return self.__getAccounts(self.cur.fetchall())
def __getAccounts(self, ids):
accounts = []
for elem, id in zip(self.account_type, ids):
self.cur.execute(f"SELECT * FROM {elem} WHERE id = {id}")
accounts.append(self.cur.fetchone())
return accounts
# GESTION D'UN UTILISATEUR
def createUser(self, num: int, prenom: str, adresse: str) -> bool:
try:
self.cur.execute(
......@@ -82,42 +68,32 @@ class Requests:
self.utils.writeLogs(e)
return False
def getUserCourantAccounts(self, num: int):
try:
self.cur.execute(
"SELECT * FROM appartenance INNER JOIN comptescourant ON appartenance.courant = comptescourant.id WHERE client=%s",
(num,),
)
return self.cur.fetchall()
except sql.Error as e:
self.utils.writeLogs(e)
def getUserAccounts(self, num: int, type: str) -> List[List[str]]:
if type not in self.account_type:
return None
def getUserEpargneAccounts(self, num: int):
try:
self.cur.execute(
"SELECT * FROM appartenance INNER JOIN comptesepargne ON appartenance.epargne = comptesepargne.id WHERE client=%s",
(num,),
"SELECT * FROM appartenance INNER JOIN %s ON appartenance.%s = %s.id WHERE client=%s",
(AsIs("comptes"+type), AsIs(type),AsIs("comptes"+type), num),
)
return self.cur.fetchall()
except sql.Error as e:
self.utils.writeLogs(e)
return None
def getUserRevolvingAccounts(self, num: int):
def getUserOperations(self, num: int, type: str) -> List[List[str]]:
if type not in self.operation_type:
return None
try:
self.cur.execute(
"SELECT * FROM appartenance INNER JOIN comptescrevolving ON appartenance.revolving = comptesrevolving.id WHERE client=%s",
(num,),
"SELECT * FROM %s WHERE client=%s",
(AsIs("operations" + type), num)
)
return self.cur.fetchall()
except sql.Error as e:
self.utils.writeLogs(e)
return None
def getUserOperations(self, num: int, type: str) -> List[List[str]]:
if type not in self.operation_type:
return None
# CREATION DES COMPTES BANCAIRES
......@@ -198,32 +174,16 @@ class Requests:
# RECUPERATION DES COMPTES BANCAIRES
def getCourantAccounts(self):
try:
self.cur.execute("SELECT * FROM comptescourant")
return self.cur.fetchall()
except sql.Error as e:
self.utils.writeLogs(e)
return False
def getEpargneAccounts(self):
try:
self.cur.execute("SELECT * FROM comptesepargne")
return self.cur.fetchall()
except sql.Error as e:
self.utils.writeLogs(e)
return False
def getRevolvingAccounts(self):
def getAccountsByType(self, type: str):
if type not in self.account_type:
return None
try:
self.cur.execute("SELECT * FROM comptesrevolving")
self.cur.execute("SELECT * FROM comptes%s", (AsIs(type),))
return self.cur.fetchall()
except sql.Error as e:
self.utils.writeLogs(e)
return False
# SUPPRESION D'UN COMPTE
def deleteAccount(self, id: int):
......@@ -254,16 +214,25 @@ class Requests:
return False
pass
def operationCheque(self):
pass
def getOperationByDate(self, date: str, type: str):
if type not in self.operation_type:
return None
try:
self.cur.execute(
"SELECT * FROM %s WHERE date=%s",
(AsIs("operations" + type), date)
)
return self.cur.fetchone()
except sql.Error as e:
self.utils.writeLogs(e)
return None
def operationGuichet(self):
pass
pass
# GESTION DES RELATIONS COMPTES - CLIENTS
def addUserToAccount(self, num: int, id: int, type: str) -> bool:
if type not in self.account_type:
return None
try:
self.cur.execute(
"INSERT INTO appartenance (client, %s) VALUES (%s, %s)",
......@@ -274,6 +243,8 @@ class Requests:
return False
def removeUserFromAccount(self, num: int, id: int, type: str) -> bool:
if type not in self.account_type:
return None
try:
self.cur.execute(
"DELETE FROM appartenance WHERE client=%s AND %s=%s",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment