calcul du rendu de monnaie OK

This commit is contained in:
Florian Ehr 2021-02-16 10:39:58 +01:00
parent d6b4cdfe22
commit c1eee4227e
3 changed files with 95 additions and 7 deletions

View file

@ -0,0 +1,63 @@
#back {
margin: 5.5% auto auto auto;
}
#warningBlock {
background-color: black;
border-radius: 20px;
}
#moneyBlock {
margin-top: 20vh;
background-color: black;
border-radius: 20px;
height: 30vh;
width: 40vw;
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
}
#recuBlock {
display: flex;
flex-direction: column;
align-items: center;
}
#textBlock {
font-size: 1.5vw;
color: white;
}
#inputsBlock {
display: flex;
justify-content: center;
}
#inputsBlock input {
max-width: 10vw;
background: rgba(84, 84, 84, 0.65);
border-radius:2vw;
padding:0.4vw 1vw 0.4vw 3.2vw;
font-size: 1.5vw;
border: 0.2vw solid black;
box-shadow: 0.4vw 0.8vw 0.4vw rgba(0, 0, 0, 0.82);
font-family: 'Wellfleet', cursive;
}
#inputsBlock input:focus{
max-width: 15vw;
outline:none;
background: rgba(84, 84, 84, 1);
border-radius:2vw;
padding:0.4vw 1vw 0.4vw 3.2vw;
font-size: 1.5vw;
border-color: white;
color:white
}
#renduBlock {
font-size: 1.8vw;
color: red;
}

View file

@ -6,22 +6,35 @@ class Money extends Component {
constructor(props){
super(props)
this.state = {
renduTxt: "Rendu"
}
this.handleMoneyChange = this.handleMoneyChange.bind(this);
}
componentDidMount() {
}
is
handleMoneyChange() {
let eurosInput = document.getElementById("euros");
let centsInput = document.getElementById("centimes");
let regex = /^[0-9]+$/; //1 ou plusieurs chiffres à la suite
let lengthCents = centsInput.value.length;
let lengthEuros = eurosInput.value.length;
let result = parseInt(eurosInput.value) + parseInt(centsInput.value)*10**-lengthCents;
if (centsInput.value.match(regex) && eurosInput.value.match(regex)) {
this.setState({renduTxt: (this.props.totalPrice - result).toPrecision(lengthEuros + lengthCents)});
}
}
render() {
return (
<div id="transp">
<div id="formBody">
<div id="back">
{this.props.empty ?
<div id="warningBlock">
<div id="warningBox">
@ -35,10 +48,22 @@ class Money extends Component {
</div>
</div>
:
// A faire : input pour rentrer la somme en espèce + Affichage de la différence avec le prix
// A faire : input pour rentrer la somme en espèce + Affichage de la différence avec le prix
<div id="moneyBlock">
<div id="recuBlock">
<div id="textBlock">
Monnaie Reçue :
</div>
<div id="inputsBlock">
<input id="euros" placeholder='€' onChange={this.handleMoneyChange}/>
<input id="centimes" placeholder='cents' onChange={this.handleMoneyChange}/>
</div>
</div>
<div id="renduBlock">
<p id="renduText">{this.state.renduTxt}</p>
</div>
</div>
<>
</>
}
</div>
</div>

View file

@ -195,7 +195,7 @@ export default class Stock extends React.Component {
<BarcodeReader onScan={this.handleScan}/>
<SearchBar/>
{this.state.onMoney &&
<Money empty={this.state.empty} handleCloseAbove={this.handleCloseMoney}/>
<Money empty={this.state.empty} handleCloseAbove={this.handleCloseMoney} totalPrice={this.state.totalPrice}/>
}
{this.state.onNotInBdd &&
<NotInBdd handleCloseAbove={this.closeNotInBdd}/>