Commit 10d13e86 authored by Philippe Lefebvre's avatar Philippe Lefebvre
Browse files

Merge branch 'phlefebv-main-patch-68351' into 'main'

Added a bunch of operations and failsafes

See merge request !1
parents 7f1bcb54 e749725b
......@@ -58,6 +58,15 @@ class Display:
for raw in raws:
self.printOperation(raw, type)
def displayUntreatedUserOperations(self, num: int):
raws=[]
for type in self.operation_type:
raws = self.req.getUntreatedUserOperations(num, type)
print(f'---------- Opérations {type} non traitées ----------')
if raws:
for raw in raws:
self.printOperation(raw, type)
def displayAllAccounts(self):
raws = []
print("---- Affichage de tous les comptes bancaires ----")
......
......@@ -5,7 +5,6 @@ import display as d
req = r.Requests()
disp = d.Display(req)
def main():
i = 0
......@@ -21,7 +20,7 @@ def main():
print("4. Supprimer un profil")
print("5. Arreter le programme")
i = int(input())
i = int(input("Choississez l'option: "))
if i == 5:
return
......@@ -44,10 +43,9 @@ def main():
req.close()
def userInterface(raw: List[str]):
i = 0
while i != 10:
while i != 12:
print("---------------------------------------")
print(
f"Bonjour {raw[1]}, \n Numéro de téléphone: {raw[0]} \n Adresse: {raw[2]}"
......@@ -55,14 +53,17 @@ def userInterface(raw: List[str]):
print("---------------------------------------")
print("1. Voir vos comptes")
print("2. Voir vos opérations")
print("3. Ajouter un compte")
print("4. Retirer un compte")
print("3. Déclarer l'appartenance d'un compte")
print("4. Retirer l'appartenance d'un compte")
print("5. Réaliser une opération")
print("6. Rechercher une opération")
print("7. Rechercher un compte")
print("8. Créer un compte")
print("9. Supprimer un compte")
print("10. Traiter une opération")
print("11. Modifier l'état d'un compte")
print("10. Se Deconnecter")
print("12. Se Deconnecter")
i = int(input("Choississez l'option: "))
......@@ -85,6 +86,15 @@ def userInterface(raw: List[str]):
findCompte()
elif i==8:
creerCompte(raw[0])
elif i==9:
disp.displayUserAccounts(raw[0])
supprimerCompte(raw[0])
elif i==10:
disp.displayUntreatedUserOperations(raw[0])
traiterOperation(raw[0])
elif i==11:
disp.displayUserAccounts(raw[0])
modifierStatutCompte(raw[0])
# CONNEXION
......@@ -105,7 +115,6 @@ def modifyProfile(num: int):
print("La modification a fonctionné")
else:
print("La modification n'a pas fonctionné")
pass
def deleteProfile(num: int):
result = req.deleteUser(num)
......@@ -186,5 +195,39 @@ def creerCompte(num: int):
else:
print("La création du compte a echoué")
def supprimerCompte(num: int):
typeCompte = str(input("Quel type de compte? "))
id = str(input("Quel est l'id du compte à supprimer? "))
result = req.deleteAccount(num, typeCompte, id)
if result:
print("Compte supprimé avec succès")
else:
print("Le compte n'existe pas ou la suppression du compte a échouée")
def traiterOperation(num: int):
typeOperation = str(input("Quel est le type d'opération? "))
id = int(input("Quel est l'id de l'opération? "))
result = req.treatOperation(num, typeOperation, id)
if result:
print("L'opération a été traitée")
else:
confirmation = str(input("Le traitement a échoué. Souhaitez vous supprimer l'opération (O/N)? "))
if confirmation in ["O", "o"]:
result = req.deleteOperation(num, typeOperation, id)
def modifierStatutCompte(num: int):
typeCompte = str(input("Quel type de compte voulez-vous modifier ? "))
id = str(input("Quel est l'id de ce compte ? "))
statut = str(input("Quel est le nouvel état du compte (Ouvert, Bloqué, Fermé) ? "))
result = req.modifyAccountStatus(num, typeCompte, id, statut)
if result:
return print("Le statut du compte a bien été modifé")
else:
return print("Ce compte n'existe pas ou le changement de statut a échoué")
if __name__ == "__main__":
main()
......@@ -13,7 +13,7 @@ class Requests:
self.conn.autocommit = True
self.cur = self.__getCursor()
self.account_state = ["Ouvert", "Bloqué", "Fermé"]
self.operation_state = ["Traitée", "Non Traitée"]
self.operation_state = ["Non Traitée", "Traitée"]
self.account_type = ["courant", "revolving", "epargne"]
self.operation_type = ["cartebleue", "virement", "cheque", "guichet"]
......@@ -40,7 +40,7 @@ class Requests:
# GESTION D'UN UTILISATEUR
def getUserByNum(self, num: int) -> List[str]:
self.cur.execute("SELECT * FROM clients WHERE telephone = %s", (num,))
self.cur.execute("SELECT * FROM clients WHERE telephone=%s", (num,))
return self.cur.fetchone()
def createUser(self, num: int, prenom: str, adresse: str) -> bool:
......@@ -86,8 +86,10 @@ class Requests:
return None
def getUserOperations(self, num: int, type: str) -> List[List[str]]:
if type not in self.operation_type:
return None
if (type not in self.operation_type):
print("Type d'opération invalide")
return False
try:
self.cur.execute(
"SELECT * FROM %s WHERE client=%s",
......@@ -98,6 +100,21 @@ class Requests:
self.utils.writeLogs(e)
return None
def getUntreatedUserOperations(self, num: int, type: str) -> List[List[str]]:
if (type not in self.operation_type):
print("Type d'opération invalide")
return False
try:
self.cur.execute(
"SELECT * FROM %s WHERE client=%s AND etat=%s",
(AsIs("operations" + type), num, self.operation_state[0])
)
return self.cur.fetchall()
except sql.Error as e:
self.utils.writeLogs(e)
return None
# CREATION DES COMPTES BANCAIRES
......@@ -114,9 +131,7 @@ class Requests:
self.utils.writeLogs(e)
return False
def createRevolvingAccount(
self, num: int, solde: int, taux: int, montant: int
) -> bool:
def createRevolvingAccount(self, num: int, solde: int, taux: int, montant: int) -> bool:
id = self.__generateAccountId()
try:
self.cur.execute(
......@@ -129,9 +144,7 @@ class Requests:
self.utils.writeLogs(e)
return False
def createEpargneAccount(
self, num: int, interet: int, plafond: int, solde: int
) -> bool:
def createEpargneAccount(self, num: int, interet: int, plafond: int, solde: int) -> bool:
id = self.__generateAccountId()
try:
self.cur.execute(
......@@ -149,7 +162,7 @@ class Requests:
def modifyCourantAccount(self, id: int, decouvert: int) -> bool:
try:
self.cur.execute(
"UPDATE comptescourant SET decouvert=%s WHERE id=%s", (decouvert, id)
"UPDATE comptescourant SET decouvert=%s WHERE id=%s AND id IN (SELECT courant FROM appartenance WHERE client=%s)", (decouvert, id, num)
)
return True
except sql.Error as e:
......@@ -159,7 +172,7 @@ class Requests:
def modifyRevolvingAccount(self, id: int, taux: int) -> bool:
try:
self.cur.execute(
"UPDATE comptesrevolving SET taux=%s WHERE id=%s", (id, taux)
"UPDATE comptesrevolving SET taux=%s WHERE id=%s AND id IN (SELECT courant FROM appartenance WHERE client=%s)", (id, taux, num)
)
return True
except sql.Error as e:
......@@ -169,18 +182,37 @@ class Requests:
def modifyEpargneAccount(self, num: int, interet: int) -> bool:
try:
self.cur.execute(
"UPDATE comptesrevolving SET interet=%s WHERE id=%s", (id, interet)
"UPDATE comptesrevolving SET interet=%s WHERE id=%s AND id IN (SELECT revolving FROM appartenance WHERE client=%s)", (id, interet, num)
)
return True
except sql.Error as e:
self.utils.writeLogs(e)
return False
def modifyAccountStatus(self, num: int, type: str, id: int, statut: str) -> bool:
if (type not in self.account_type):
print("Type de compte invalide")
return False
if (statut not in self.account_state):
print("Etat de compte invalide")
return False
try:
self.cur.execute("UPDATE comptes%s SET statut=%s WHERE id=%s AND id IN (SELECT %s FROM appartenance WHERE client=%s)", (AsIs(type), statut, id, AsIs(type), num))
return True
except sql.Error as e:
self.utils.writeLogs(e)
return False
# RECUPERATION DES COMPTES BANCAIRES
def getAccountsByType(self, type: str):
if type not in self.account_type:
return None
if (type not in self.account_type):
print("Type de compte invalide")
return False
try:
self.cur.execute("SELECT * FROM comptes%s", (AsIs(type),))
return self.cur.fetchall()
......@@ -190,12 +222,29 @@ class Requests:
# SUPPRESION D'UN COMPTE
def deleteAccount(self, id: int):
pass
def deleteAccount(self, num: int, type: str, id: int):
if (type not in self.account_type):
print("Type de compte invalide")
return False
try:
self.cur.execute("DELETE FROM comptes%s WHERE id=%s AND id IN (SELECT %s FROM appartenance WHERE client=%s)", (AsIs(type), id, AsIs(type), num))
return True
except sql.Error as e:
self.utils.writeLogs(e)
return False
# Insertion d'une opération
def createOperation(self, compte: int, client: int, op_type: str, acc_type: str, montant: int):
if (acc_type not in self.account_type):
print("Type de compte invalide")
return False
if (op_type not in self.operation_type):
print("Type d'opération invalide")
return False
id = self.__generateOperationId()
try:
self.cur.execute(
......@@ -210,17 +259,17 @@ class Requests:
client
),
)
self.__updateSoldById(compte, acc_type, montant)
return True
except sql.Error as e:
print(e)
self.utils.writeLogs(e)
return False
pass
def getOperationByDate(self, date: str, type: str):
if type not in self.operation_type:
return None
if (type not in self.operation_type):
print("Type d'opération invalide")
return False
try:
self.cur.execute(
"SELECT * FROM %s WHERE date=%s",
......@@ -231,12 +280,51 @@ class Requests:
self.utils.writeLogs(e)
return None
# TRAITEMENT D'UNE OPERATION
def treatOperation(self, num: int, id: str, type: str):
if (type not in self.operation_type):
print("Type d'opération invalide")
return False
try:
self.cur.execute("SELECT * FROM operations%s WHERE id=%s AND etat=%s AND client=%s", (AsIs(type), id, operation_state[0], num))
operation = self.cur.fetchone()
if operation:
result = self.__updateSoldById(compte, acc_type, montant)
if result:
self.cur.execute("UPDATE operations%s SET etat=%s WHERE id=%s", (AsIs(type), operation_state[1], id))
return True
else:
print("Mise à jour du solde a échoué")
return False
else:
print("Aucune opération trouvée")
return False
except sql.Error as e:
self.utils.writeLogs(e)
return False
def deleteOperation(self, num: int, type: str, id: int):
if (type not in self.account_type):
print("Type de compte invalide")
return False
try:
self.cur.execute("DELETE FROM operations%s WHERE id=%s AND client=%s", (AsIs(type), id, num))
return True
except sql.Error as e:
self.utils.writeLogs(e)
return False
# GESTION DES RELATIONS COMPTES - CLIENTS
def addUserToAccount(self, num: int, id: int, type: str) -> bool:
if type not in self.account_type:
return None
if (type not in self.account_type):
print("Type de compte invalide")
return False
try:
self.cur.execute(
"INSERT INTO appartenance (client, %s) VALUES (%s, %s)",
......@@ -244,11 +332,14 @@ class Requests:
)
return True
except sql.Error as e:
self.utils.writeLogs(e)
return False
def removeUserFromAccount(self, num: int, id: int, type: str) -> bool:
if type not in self.account_type:
return None
if (type not in self.account_type):
print("Type de compte invalide")
return False
try:
self.cur.execute(
"DELETE FROM appartenance WHERE client=%s AND %s=%s",
......@@ -256,6 +347,7 @@ class Requests:
)
return True
except sql.Error as e:
self.utils.writeLogs(e)
return False
# GENERATIONS CLES COMPTES ET OPERATIONS
......@@ -293,5 +385,5 @@ class Requests:
)
return True
except sql.Error as e:
print(e)
self.utils.writeLogs(e)
return False
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