Commit 1dc9797dde3ddc34d1fef988b863a677eb12d3b3

Authored by Geoffrey PREUD'HOMME
1 parent dac984ec

Reste des transactions

Showing 3 changed files with 54 additions and 15 deletions   Show diff stats
api/client/payer.php
@@ -65,6 +65,6 @@ $requete->close(); @@ -65,6 +65,6 @@ $requete->close();
65 $idTransaction = transaction(TRANSACTION_PAIEMENT, $_POST["idCarte"], $montant, $quantite); 65 $idTransaction = transaction(TRANSACTION_PAIEMENT, $_POST["idCarte"], $montant, $quantite);
66 66
67 67
68 -retour("ok", ["idTransaction" => $idTransaction, "soldeAncien" => $soldeAncien, "soldeNouveau" => $soldeNouveau]); 68 +retour("ok", ["idTransaction" => $idTransaction, "montant" => $montant, "soldeAncien" => $soldeAncien, "soldeNouveau" => $soldeNouveau]);
69 69
70 ?> 70 ?>
@@ -118,7 +118,7 @@ @@ -118,7 +118,7 @@
118 <input type="number" name="solde" v-model="solde"> 118 <input type="number" name="solde" v-model="solde">
119 <label for="solde">Solde initial (€)</label> 119 <label for="solde">Solde initial (€)</label>
120 </div> 120 </div>
121 - <button :disabled="!solde || (!PEUT_NFC && !idCarte)">Créer</button> 121 + <button type="submit" :disabled="!solde || (!PEUT_NFC && !idCarte)">Créer</button>
122 </form> 122 </form>
123 </div> 123 </div>
124 <div id="rechargement"> 124 <div id="rechargement">
@@ -134,12 +134,12 @@ @@ -134,12 +134,12 @@
134 <input type="number" name="credit" v-model="credit"> 134 <input type="number" name="credit" v-model="credit">
135 <label for="credit">Crédit (€)</label> 135 <label for="credit">Crédit (€)</label>
136 </div> 136 </div>
137 - <button :disabled="!credit || (!PEUT_NFC && !idCarte)">Créer</button> 137 + <button type="submit" :disabled="!credit || (!PEUT_NFC && !idCarte)">Recharger</button>
138 </form> 138 </form>
139 </div> 139 </div>
140 <div id="paiement"> 140 <div id="paiement">
141 <h4>Vendre à un client</h4> 141 <h4>Vendre à un client</h4>
142 - <form @submit="payer"> 142 + <form>
143 <div class="input-field" v-if="!PEUT_NFC"> 143 <div class="input-field" v-if="!PEUT_NFC">
144 <i class="material-icons prefix">credit_card</i> 144 <i class="material-icons prefix">credit_card</i>
145 <input type="text" name="idCarte" length="8" v-model="idCarte"> 145 <input type="text" name="idCarte" length="8" v-model="idCarte">
@@ -150,7 +150,7 @@ @@ -150,7 +150,7 @@
150 </div> 150 </div>
151 <div id="grilleBieres"> 151 <div id="grilleBieres">
152 <div> 152 <div>
153 - <div v-for="i in [1, 2, 3, 4, 5, 6]"><button :disabled="!PEUT_NFC && !idCarte">{{ i }}</button></div> 153 + <div v-for="i in [1, 2, 3, 4, 5, 6]"><button type="button" @click="payer(i)" :disabled="prix || (!PEUT_NFC && !idCarte)">{{ i }}</button></div>
154 </div> 154 </div>
155 </div> 155 </div>
156 <div class="row"> 156 <div class="row">
@@ -161,7 +161,7 @@ @@ -161,7 +161,7 @@
161 <input type="number" name="prix" v-model="prix"> 161 <input type="number" name="prix" v-model="prix">
162 <label for="prix">Prix (€)</label> 162 <label for="prix">Prix (€)</label>
163 </div> 163 </div>
164 - <button :disabled="!prix || (!PEUT_NFC && !idCarte)">Payer</button> 164 + <button type="submit" @click="payer" :disabled="!prix || (!PEUT_NFC && !idCarte)">Payer</button>
165 </form> 165 </form>
166 </div> 166 </div>
167 <div id="vidange"> 167 <div id="vidange">
@@ -172,7 +172,7 @@ @@ -172,7 +172,7 @@
172 <input type="text" name="idCarte" length="8" v-model="idCarte"> 172 <input type="text" name="idCarte" length="8" v-model="idCarte">
173 <label for="idCarte">Identifiant de la carte</label> 173 <label for="idCarte">Identifiant de la carte</label>
174 </div> 174 </div>
175 - <button :disabled="!PEUT_NFC && !idCarte">Vider</button> 175 + <button type="submit" :disabled="!PEUT_NFC && !idCarte">Vider</button>
176 </form> 176 </form>
177 </div> 177 </div>
178 </div> 178 </div>
@@ -56,7 +56,6 @@ var app = new Vue({ @@ -56,7 +56,6 @@ var app = new Vue({
56 }, 56 },
57 // Fonctionnement 57 // Fonctionnement
58 connecter: function() { 58 connecter: function() {
59 - console.log(57)  
60 var that = this; 59 var that = this;
61 this.apiBrute("utilisateur/connexion", {login: this.login , mdp: this.mdp} , function(retour, donnees) { 60 this.apiBrute("utilisateur/connexion", {login: this.login , mdp: this.mdp} , function(retour, donnees) {
62 that.mdp = '' 61 that.mdp = ''
@@ -70,10 +69,6 @@ var app = new Vue({ @@ -70,10 +69,6 @@ var app = new Vue({
70 that.page = 'operations' 69 that.page = 'operations'
71 break; 70 break;
72 71
73 - case "identifiants_invalides":  
74 - that.toast("Identifiants invalides")  
75 - break;  
76 -  
77 default: 72 default:
78 that.erreur(retour, donnees); 73 that.erreur(retour, donnees);
79 break; 74 break;
@@ -89,8 +84,18 @@ var app = new Vue({ @@ -89,8 +84,18 @@ var app = new Vue({
89 that.toast("Client " + that.idCarte + " crée avec un solde de " + that.solde + " €") 84 that.toast("Client " + that.idCarte + " crée avec un solde de " + that.solde + " €")
90 break; 85 break;
91 86
92 - case "solde_negatif":  
93 - that.toast("Solde négatif") 87 + default:
  88 + that.erreur(retour, donnees);
  89 + break;
  90 + }
  91 + });
  92 + },
  93 + recharger: function() {
  94 + var that = this
  95 + this.api("client/recharger", {idCarte: this.idCarte, montant: this.credit}, function(retour, donnees) {
  96 + switch(retour) {
  97 + case "ok":
  98 + that.toast("Client " + that.idCarte + " rechargé : " + donnees.soldeAncien + " + " + that.credit + " → " + donnees.soldeNouveau + " €")
94 break; 99 break;
95 100
96 default: 101 default:
@@ -98,7 +103,41 @@ var app = new Vue({ @@ -98,7 +103,41 @@ var app = new Vue({
98 break; 103 break;
99 } 104 }
100 }); 105 });
101 - } 106 + },
  107 + payer: function(quantite) {
  108 + var that = this
  109 + var options = {idCarte: this.idCarte}
  110 + if (typeof(quantite) == 'number') {
  111 + options.quantite = quantite
  112 + } else {
  113 + options.montant = that.prix
  114 + }
  115 + this.api("client/payer", options, function(retour, donnees) {
  116 + switch(retour) {
  117 + case "ok":
  118 + that.toast("Client " + that.idCarte + " débité : " + donnees.soldeAncien + " - " + donnees.montant + " → " + donnees.soldeNouveau + " €")
  119 + break;
  120 +
  121 + default:
  122 + that.erreur(retour, donnees);
  123 + break;
  124 + }
  125 + });
  126 + },
  127 + vidanger: function() {
  128 + var that = this
  129 + this.api("client/vidange", {idCarte: this.idCarte}, function(retour, donnees) {
  130 + switch(retour) {
  131 + case "ok":
  132 + that.toast("Client " + that.idCarte + " vidé : " + donnees.soldeAncien + " → 0 €")
  133 + break;
  134 +
  135 + default:
  136 + that.erreur(retour, donnees);
  137 + break;
  138 + }
  139 + });
  140 + },
102 }, 141 },
103 computed: { 142 computed: {
104 timer: function() { 143 timer: function() {