Blame view

api/client/vidange.php 926 Bytes
b7fdf7d0   Geoffrey PREUD'HOMME   api/client/vidange
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  <?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=?");
  $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=?");
  $requete->bind_param("s", $_POST["idCarte"]);
  if (!$requete->execute()) {
      retour("erreur_bdd", ["message" => $requete->error]);
  }
  $requete->close();
207a98d5   Geoffrey PREUD'HOMME   id → idTransaction
34
  $idTransaction = transaction(TRANSACTION_VIDANGE, $_POST["idCarte"], $soldeAncien);
b7fdf7d0   Geoffrey PREUD'HOMME   api/client/vidange
35
36
  
  
207a98d5   Geoffrey PREUD'HOMME   id → idTransaction
37
  retour("ok", ["idTransaction" => $idTransaction, "soldeAncien" => $soldeAncien]);
b7fdf7d0   Geoffrey PREUD'HOMME   api/client/vidange
38
39
  
  ?>