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["decliner"] = { label: "Décliner", callback: it => { } }; | ||||
|     let conf = { | ||||
|       title: venteData.acheteur? venteData.acheteur.name + " - " + actionAchat : actionAchat, | ||||
|       title: venteData.acheteur ? venteData.acheteur.name + " - " + actionAchat : actionAchat, | ||||
|       content: html, | ||||
|       default: actionAchat, | ||||
|       buttons: buttons | ||||
| @@ -56,11 +56,11 @@ export class DialogItemAchat extends Dialog { | ||||
|   static prepareVenteData(buttonAcheter, vendeurId, vendeur, acheteur) { | ||||
|     const jsondata = buttonAcheter.attributes['data-jsondata']?.value; | ||||
|     const prixLot = parseInt(buttonAcheter.attributes['data-prixLot']?.value ?? 0); | ||||
|     let venteData = { | ||||
|     return { | ||||
|       item: JSON.parse(jsondata), | ||||
|       vendeurId: vendeurId, | ||||
|       vendeur: vendeur, | ||||
|       acheteur:acheteur, | ||||
|       acheteur: acheteur, | ||||
|       tailleLot: parseInt(buttonAcheter.attributes['data-tailleLot']?.value ?? 1), | ||||
|       quantiteIllimite: buttonAcheter.attributes['data-quantiteIllimite']?.value == 'true', | ||||
|       quantiteNbLots: parseInt(buttonAcheter.attributes['data-quantiteNbLots']?.value), | ||||
| @@ -73,7 +73,6 @@ export class DialogItemAchat extends Dialog { | ||||
|       prixTotal: prixLot, | ||||
|       isVente: prixLot > 0 | ||||
|     }; | ||||
|     return venteData; | ||||
|   } | ||||
|  | ||||
|   async onAchat() { | ||||
| @@ -87,7 +86,7 @@ export class DialogItemAchat extends Dialog { | ||||
|       choix: this.venteData.choix | ||||
|     }); | ||||
|   } | ||||
|    | ||||
|  | ||||
|   async onAchatConsommer() { | ||||
|     this.venteData.choix.consommer = true; | ||||
|     await this.onAchat(); | ||||
| @@ -106,8 +105,12 @@ export class DialogItemAchat extends Dialog { | ||||
|   } | ||||
|  | ||||
|   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); | ||||
|     $(".nombreLots").val(this.venteData.choix.nombreLots); | ||||
|     $(".prixTotal").text(this.venteData.prixTotal); | ||||
|   } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user