diff --git a/BDD.sql b/BDD.sql index 25173a6..da79fef 100644 --- a/BDD.sql +++ b/BDD.sql @@ -27,10 +27,10 @@ CREATE TABLE Prix ( CREATE TABLE Transactions ( id serial PRIMARY KEY, type char(15), + client char(8) REFERENCES Client(idCarte), date datetime DEFAULT CURRENT_TIMESTAMP, montant float(7,2), quantite integer(2), utilisateur char(30) REFERENCES Utilisateur(login), - client char(30) REFERENCES Client(loginLille1), - valide boolean + valide boolean DEFAULT true ); diff --git a/api/client/ajouter.php b/api/client/ajouter.php index 2f93acd..64bcae6 100644 --- a/api/client/ajouter.php +++ b/api/client/ajouter.php @@ -27,13 +27,14 @@ if ($solde < 0 && !$decouvert) { $requete = $db->prepare("INSERT INTO Clients (idCarte, solde, decouvert) VALUES (?, ?, ?)"); -$requete->bind_param("sss", $_POST["idCarte"], $_POST["solde"], $decouvert); +$requete->bind_param("sss", $_POST["idCarte"], $solde, $decouvert); if (!$requete->execute()) { retour("erreur_bdd", ["message" => $requete->error]); } $requete->close(); +$id = transaction(1, $_POST["idCarte"], $solde); -retour("ok"); +retour("ok", ["id" => $id]); ?> diff --git a/api/commun.php b/api/commun.php index fe76836..898e6f4 100644 --- a/api/commun.php +++ b/api/commun.php @@ -92,6 +92,17 @@ function clientExiste($idCarte) { $requete->close(); } +function transaction($type, $client, $montant = 0, $quantite = 0) { + global $db, $login; + $requete = $db->prepare("INSERT INTO Transactions (type, client, montant, quantite, utilisateur) VALUES (?, ?, ?, ?, ?)"); + $requete->bind_param("sssss", $type, $client, $montant, $quantite, $login); + if (!$requete->execute()) { + retour("erreur_bdd", ["message" => $requete->error]); + } + $requete->close(); + return $db->insert_id; +} + // Variables globales $login = ""; -- libgit2 0.21.2