Commit 78ed38ba83dc5cfca8486ed21dd9a35422fb2281
1 parent
90e646d5
Statistiques
Closes #12
Showing
2 changed files
with
95 additions
and
2 deletions
Show diff stats
@@ -0,0 +1,95 @@ | @@ -0,0 +1,95 @@ | ||
1 | +<?php | ||
2 | + | ||
3 | +require_once("commun.php"); | ||
4 | + | ||
5 | +verifierDroit(2); | ||
6 | + | ||
7 | +// Chiffre d'affaire | ||
8 | +$requete = $db->prepare("SELECT SUM(solde) FROM Clients WHERE solde > 0"); | ||
9 | +if (!$requete) { | ||
10 | + retour("erreur_bdd_preparee", ["message" => $db->error]); | ||
11 | +} | ||
12 | +if (!$requete->execute()) { | ||
13 | + retour("erreur_bdd", ["message" => $requete->error]); | ||
14 | +} | ||
15 | +$requete->bind_result($recettes); | ||
16 | +$requete->fetch(); | ||
17 | +$requete->close(); | ||
18 | + | ||
19 | +$requete = $db->prepare("SELECT SUM(solde) FROM Clients WHERE solde < 0"); | ||
20 | +if (!$requete) { | ||
21 | + retour("erreur_bdd_preparee", ["message" => $db->error]); | ||
22 | +} | ||
23 | +if (!$requete->execute()) { | ||
24 | + retour("erreur_bdd", ["message" => $requete->error]); | ||
25 | +} | ||
26 | +$requete->bind_result($dettes); | ||
27 | +$requete->fetch(); | ||
28 | +$requete->close(); | ||
29 | + | ||
30 | +// Arrondi et calculs | ||
31 | +$recettes = round($recettes, 2); | ||
32 | +$dettes = round($dettes, 2); | ||
33 | +$benefices = $recettes + $dettes; | ||
34 | + | ||
35 | +// Statistiques générales | ||
36 | +$requete = $db->prepare("SELECT COUNT(*) FROM Clients"); | ||
37 | +if (!$requete) { | ||
38 | + retour("erreur_bdd_preparee", ["message" => $db->error]); | ||
39 | +} | ||
40 | +if (!$requete->execute()) { | ||
41 | + retour("erreur_bdd", ["message" => $requete->error]); | ||
42 | +} | ||
43 | +$requete->bind_result($clientsNb); | ||
44 | +$requete->fetch(); | ||
45 | +$requete->close(); | ||
46 | + | ||
47 | +$requete = $db->prepare("SELECT SUM(quantite) FROM Transactions"); | ||
48 | +if (!$requete) { | ||
49 | + retour("erreur_bdd_preparee", ["message" => $db->error]); | ||
50 | +} | ||
51 | +if (!$requete->execute()) { | ||
52 | + retour("erreur_bdd", ["message" => $requete->error]); | ||
53 | +} | ||
54 | +$requete->bind_result($consommationsNb); | ||
55 | +$requete->fetch(); | ||
56 | +$requete->close(); | ||
57 | + | ||
58 | +$requete = $db->prepare("SELECT AVG(solde) FROM Clients WHERE solde > 0"); | ||
59 | +if (!$requete) { | ||
60 | + retour("erreur_bdd_preparee", ["message" => $db->error]); | ||
61 | +} | ||
62 | +if (!$requete->execute()) { | ||
63 | + retour("erreur_bdd", ["message" => $requete->error]); | ||
64 | +} | ||
65 | +$requete->bind_result($soldeMoy); | ||
66 | +$requete->fetch(); | ||
67 | +$requete->close(); | ||
68 | + | ||
69 | +// Facture BDE | ||
70 | + | ||
71 | +// TODO Même si le BDE n'est censé que pouvoir faire des créations de compte, | ||
72 | +// utiliser la fonction de somme de transactions utilisée pour vérifier | ||
73 | +// l'intégrité des soldes pourrait être une bonne idée | ||
74 | +$requete = $db->prepare("SELECT SUM(Transactions.montant) FROM Transactions JOIN Utilisateurs ON Transactions.utilisateur=Utilisateurs.login WHERE droit=1"); | ||
75 | +if (!$requete) { | ||
76 | + retour("erreur_bdd_preparee", ["message" => $db->error]); | ||
77 | +} | ||
78 | +if (!$requete->execute()) { | ||
79 | + retour("erreur_bdd", ["message" => $requete->error]); | ||
80 | +} | ||
81 | +$requete->bind_result($factureBDE); | ||
82 | +$requete->fetch(); | ||
83 | + | ||
84 | + | ||
85 | +retour("ok", [ | ||
86 | + "benefices" => $benefices, | ||
87 | + "recettes" => $recettes, | ||
88 | + "dettes" => $dettes, | ||
89 | + "clientsNb" => $clientsNb, | ||
90 | + "consommationsNb" => $consommationsNb, | ||
91 | + "soldeMoy" => $soldeMoy, | ||
92 | + "factureBDE" => $factureBDE, | ||
93 | +]); | ||
94 | + | ||
95 | +?> |
api/utilisateur/deconnexion.php