Commit b40335a8a5fbe5b115baf7051994459ee20e0ec9
1 parent
ecee29d1
api/client/ajouter 1/2
Showing
3 changed files
with
16 additions
and
4 deletions
Show diff stats
BDD.sql
@@ -27,10 +27,10 @@ CREATE TABLE Prix ( | @@ -27,10 +27,10 @@ CREATE TABLE Prix ( | ||
27 | CREATE TABLE Transactions ( | 27 | CREATE TABLE Transactions ( |
28 | id serial PRIMARY KEY, | 28 | id serial PRIMARY KEY, |
29 | type char(15), | 29 | type char(15), |
30 | + client char(8) REFERENCES Client(idCarte), | ||
30 | date datetime DEFAULT CURRENT_TIMESTAMP, | 31 | date datetime DEFAULT CURRENT_TIMESTAMP, |
31 | montant float(7,2), | 32 | montant float(7,2), |
32 | quantite integer(2), | 33 | quantite integer(2), |
33 | utilisateur char(30) REFERENCES Utilisateur(login), | 34 | utilisateur char(30) REFERENCES Utilisateur(login), |
34 | - client char(30) REFERENCES Client(loginLille1), | ||
35 | - valide boolean | 35 | + valide boolean DEFAULT true |
36 | ); | 36 | ); |
api/client/ajouter.php
@@ -27,13 +27,14 @@ if ($solde < 0 && !$decouvert) { | @@ -27,13 +27,14 @@ if ($solde < 0 && !$decouvert) { | ||
27 | 27 | ||
28 | 28 | ||
29 | $requete = $db->prepare("INSERT INTO Clients (idCarte, solde, decouvert) VALUES (?, ?, ?)"); | 29 | $requete = $db->prepare("INSERT INTO Clients (idCarte, solde, decouvert) VALUES (?, ?, ?)"); |
30 | -$requete->bind_param("sss", $_POST["idCarte"], $_POST["solde"], $decouvert); | 30 | +$requete->bind_param("sss", $_POST["idCarte"], $solde, $decouvert); |
31 | if (!$requete->execute()) { | 31 | if (!$requete->execute()) { |
32 | retour("erreur_bdd", ["message" => $requete->error]); | 32 | retour("erreur_bdd", ["message" => $requete->error]); |
33 | } | 33 | } |
34 | $requete->close(); | 34 | $requete->close(); |
35 | +$id = transaction(1, $_POST["idCarte"], $solde); | ||
35 | 36 | ||
36 | 37 | ||
37 | -retour("ok"); | 38 | +retour("ok", ["id" => $id]); |
38 | 39 | ||
39 | ?> | 40 | ?> |
api/commun.php
@@ -92,6 +92,17 @@ function clientExiste($idCarte) { | @@ -92,6 +92,17 @@ function clientExiste($idCarte) { | ||
92 | $requete->close(); | 92 | $requete->close(); |
93 | } | 93 | } |
94 | 94 | ||
95 | +function transaction($type, $client, $montant = 0, $quantite = 0) { | ||
96 | + global $db, $login; | ||
97 | + $requete = $db->prepare("INSERT INTO Transactions (type, client, montant, quantite, utilisateur) VALUES (?, ?, ?, ?, ?)"); | ||
98 | + $requete->bind_param("sssss", $type, $client, $montant, $quantite, $login); | ||
99 | + if (!$requete->execute()) { | ||
100 | + retour("erreur_bdd", ["message" => $requete->error]); | ||
101 | + } | ||
102 | + $requete->close(); | ||
103 | + return $db->insert_id; | ||
104 | +} | ||
105 | + | ||
95 | // Variables globales | 106 | // Variables globales |
96 | 107 | ||
97 | $login = ""; | 108 | $login = ""; |