forked from public/foundryvtt-reve-de-dragon
		
	Fix: pas plus de lots que disponibles
On pouvait saisir à la main un nombre de lots plus grand que le nombre disponible, ce qui multipliait la quantité par ce nombre de lots
This commit is contained in:
		| @@ -39,7 +39,7 @@ export class DialogItemAchat extends Dialog { | |||||||
|     buttons[actionAchat] = { label: actionAchat, callback: it => { this.onAchat(); } }; |     buttons[actionAchat] = { label: actionAchat, callback: it => { this.onAchat(); } }; | ||||||
|     buttons["decliner"] = { label: "Décliner", callback: it => { } }; |     buttons["decliner"] = { label: "Décliner", callback: it => { } }; | ||||||
|     let conf = { |     let conf = { | ||||||
|       title: venteData.acheteur? venteData.acheteur.name + " - " + actionAchat : actionAchat, |       title: venteData.acheteur ? venteData.acheteur.name + " - " + actionAchat : actionAchat, | ||||||
|       content: html, |       content: html, | ||||||
|       default: actionAchat, |       default: actionAchat, | ||||||
|       buttons: buttons |       buttons: buttons | ||||||
| @@ -56,11 +56,11 @@ export class DialogItemAchat extends Dialog { | |||||||
|   static prepareVenteData(buttonAcheter, vendeurId, vendeur, acheteur) { |   static prepareVenteData(buttonAcheter, vendeurId, vendeur, acheteur) { | ||||||
|     const jsondata = buttonAcheter.attributes['data-jsondata']?.value; |     const jsondata = buttonAcheter.attributes['data-jsondata']?.value; | ||||||
|     const prixLot = parseInt(buttonAcheter.attributes['data-prixLot']?.value ?? 0); |     const prixLot = parseInt(buttonAcheter.attributes['data-prixLot']?.value ?? 0); | ||||||
|     let venteData = { |     return { | ||||||
|       item: JSON.parse(jsondata), |       item: JSON.parse(jsondata), | ||||||
|       vendeurId: vendeurId, |       vendeurId: vendeurId, | ||||||
|       vendeur: vendeur, |       vendeur: vendeur, | ||||||
|       acheteur:acheteur, |       acheteur: acheteur, | ||||||
|       tailleLot: parseInt(buttonAcheter.attributes['data-tailleLot']?.value ?? 1), |       tailleLot: parseInt(buttonAcheter.attributes['data-tailleLot']?.value ?? 1), | ||||||
|       quantiteIllimite: buttonAcheter.attributes['data-quantiteIllimite']?.value == 'true', |       quantiteIllimite: buttonAcheter.attributes['data-quantiteIllimite']?.value == 'true', | ||||||
|       quantiteNbLots: parseInt(buttonAcheter.attributes['data-quantiteNbLots']?.value), |       quantiteNbLots: parseInt(buttonAcheter.attributes['data-quantiteNbLots']?.value), | ||||||
| @@ -73,7 +73,6 @@ export class DialogItemAchat extends Dialog { | |||||||
|       prixTotal: prixLot, |       prixTotal: prixLot, | ||||||
|       isVente: prixLot > 0 |       isVente: prixLot > 0 | ||||||
|     }; |     }; | ||||||
|     return venteData; |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   async onAchat() { |   async onAchat() { | ||||||
| @@ -87,7 +86,7 @@ export class DialogItemAchat extends Dialog { | |||||||
|       choix: this.venteData.choix |       choix: this.venteData.choix | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
|    |  | ||||||
|   async onAchatConsommer() { |   async onAchatConsommer() { | ||||||
|     this.venteData.choix.consommer = true; |     this.venteData.choix.consommer = true; | ||||||
|     await this.onAchat(); |     await this.onAchat(); | ||||||
| @@ -106,8 +105,12 @@ export class DialogItemAchat extends Dialog { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   setNombreLots(nombreLots) { |   setNombreLots(nombreLots) { | ||||||
|     this.venteData.choix.nombreLots = nombreLots; |     if (nombreLots > this.venteData.quantiteNbLots) { | ||||||
|  |       ui.notifications.warn(`Seulement ${this.venteData.quantiteNbLots} lots disponibles, vous ne pouvez pas en prendre ${nombreLots}`) | ||||||
|  |     } | ||||||
|  |     this.venteData.choix.nombreLots = Math.min(nombreLots, this.venteData.quantiteNbLots); | ||||||
|     this.venteData.prixTotal = (nombreLots * this.venteData.prixLot).toFixed(2); |     this.venteData.prixTotal = (nombreLots * this.venteData.prixLot).toFixed(2); | ||||||
|  |     $(".nombreLots").val(this.venteData.choix.nombreLots); | ||||||
|     $(".prixTotal").text(this.venteData.prixTotal); |     $(".prixTotal").text(this.venteData.prixTotal); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user