Commit b7fdf7d03f1d7a3a5ea7fafdd95a2be825a8956e
1 parent
67f77f33
api/client/vidange
Showing
2 changed files
with
41 additions
and
1 deletions
Show diff stats
api/client/payer.php
@@ -25,6 +25,7 @@ if (donne("quantite")) { | @@ -25,6 +25,7 @@ if (donne("quantite")) { | ||
25 | $montant = $prixItem * $quantite; | 25 | $montant = $prixItem * $quantite; |
26 | } else { | 26 | } else { |
27 | $montant = floatval($_POST["montant"]); | 27 | $montant = floatval($_POST["montant"]); |
28 | + $quantite = 0; | ||
28 | } | 29 | } |
29 | 30 | ||
30 | if ($montant <= 0) { | 31 | if ($montant <= 0) { |
@@ -52,7 +53,7 @@ if (!$requete->execute()) { | @@ -52,7 +53,7 @@ if (!$requete->execute()) { | ||
52 | retour("erreur_bdd", ["message" => $requete->error]); | 53 | retour("erreur_bdd", ["message" => $requete->error]); |
53 | } | 54 | } |
54 | $requete->close(); | 55 | $requete->close(); |
55 | -$id = transaction(TRANSACTION_PAIEMENT, $_POST["idCarte"], $montant); | 56 | +$id = transaction(TRANSACTION_PAIEMENT, $_POST["idCarte"], $montant, $quantite); |
56 | 57 | ||
57 | 58 | ||
58 | retour("ok", ["id" => $id, "soldeAncien" => $soldeAncien, "soldeNouveau" => $soldeNouveau]); | 59 | retour("ok", ["id" => $id, "soldeAncien" => $soldeAncien, "soldeNouveau" => $soldeNouveau]); |
@@ -0,0 +1,39 @@ | @@ -0,0 +1,39 @@ | ||
1 | +<?php | ||
2 | + | ||
3 | +require_once("../commun.php"); | ||
4 | + | ||
5 | +verifierDroit(2); | ||
6 | + | ||
7 | +if (!(donne("idCarte"))) { | ||
8 | + retour("requete_malformee"); | ||
9 | +} | ||
10 | + | ||
11 | +if (!clientExiste(donne("idCarte"))) { | ||
12 | + retour("client_inconnu"); | ||
13 | +} | ||
14 | + | ||
15 | +$requete = $db->prepare("SELECT solde FROM Clients WHERE idCarte=?"); | ||
16 | +$requete->bind_param("s", $_POST["idCarte"]); | ||
17 | +$requete->bind_result($soldeAncien); | ||
18 | +if (!$requete->execute()) { | ||
19 | + retour("erreur_bdd", ["message" => $requete->error]); | ||
20 | +} | ||
21 | +$requete->fetch(); | ||
22 | +$requete->close(); | ||
23 | + | ||
24 | +if ($soldeAncien <= 0) { | ||
25 | + retour("solde_negatif"); | ||
26 | +} | ||
27 | + | ||
28 | +$requete = $db->prepare("UPDATE Clients SET solde=0 WHERE idCarte=?"); | ||
29 | +$requete->bind_param("s", $_POST["idCarte"]); | ||
30 | +if (!$requete->execute()) { | ||
31 | + retour("erreur_bdd", ["message" => $requete->error]); | ||
32 | +} | ||
33 | +$requete->close(); | ||
34 | +$id = transaction(TRANSACTION_VIDANGE, $_POST["idCarte"], $soldeAncien); | ||
35 | + | ||
36 | + | ||
37 | +retour("ok", ["id" => $id, "soldeAncien" => $soldeAncien]); | ||
38 | + | ||
39 | +?> |