b7fdf7d0
Geoffrey PREUD'HOMME
api/client/vidange
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<?php
require_once("../commun.php");
verifierDroit(2);
if (!(donne("idCarte"))) {
retour("requete_malformee");
}
if (!clientExiste(donne("idCarte"))) {
retour("client_inconnu");
}
$requete = $db->prepare("SELECT solde FROM Clients WHERE idCarte=?");
|
0b7b1139
Geoffrey PREUD'HOMME
erreur_bdd_prepare
|
16
17
18
|
if (!$requete) {
retour("erreur_bdd_preparee", ["message" => $db->error]);
}
|
b7fdf7d0
Geoffrey PREUD'HOMME
api/client/vidange
|
19
20
21
22
23
24
25
26
27
28
29
30
31
|
$requete->bind_param("s", $_POST["idCarte"]);
$requete->bind_result($soldeAncien);
if (!$requete->execute()) {
retour("erreur_bdd", ["message" => $requete->error]);
}
$requete->fetch();
$requete->close();
if ($soldeAncien <= 0) {
retour("solde_negatif");
}
$requete = $db->prepare("UPDATE Clients SET solde=0 WHERE idCarte=?");
|
0b7b1139
Geoffrey PREUD'HOMME
erreur_bdd_prepare
|
32
33
34
|
if (!$requete) {
retour("erreur_bdd_preparee", ["message" => $db->error]);
}
|
b7fdf7d0
Geoffrey PREUD'HOMME
api/client/vidange
|
35
36
37
38
39
|
$requete->bind_param("s", $_POST["idCarte"]);
if (!$requete->execute()) {
retour("erreur_bdd", ["message" => $requete->error]);
}
$requete->close();
|
207a98d5
Geoffrey PREUD'HOMME
id → idTransaction
|
40
|
$idTransaction = transaction(TRANSACTION_VIDANGE, $_POST["idCarte"], $soldeAncien);
|
b7fdf7d0
Geoffrey PREUD'HOMME
api/client/vidange
|
41
42
|
|
207a98d5
Geoffrey PREUD'HOMME
id → idTransaction
|
43
|
retour("ok", ["idTransaction" => $idTransaction, "soldeAncien" => $soldeAncien]);
|
b7fdf7d0
Geoffrey PREUD'HOMME
api/client/vidange
|
44
45
|
?>
|