Sistema de Pizzaria
á baixo temos o cod que pega automaticamente o valor da pizza e faz a soma com outros sabores de valor diferente, bem essa parte está tudo ok.
<label> <input type="checkbox" name="ch[]" value="23,00" />Mussarela</label>
<label><input type="checkbox" name="ch[]" value="22,00" />Calabresa</label>
<label><input type="checkbox" name="ch[]" value="23,00" />Brasileira</label>
<label><input type="checkbox" name="ch[]" value="27,00" />Atun</label>
<label><input type="checkbox" name="ch[]" value="28,00" />Bahiana</label>
<label><input type="checkbox" name="ch[]" value="26,00" />Frango com </label>
<label><input type="checkbox" name="ch[]" value="27,00" />Alhite</label>
<label><input type="checkbox" name="ch[]" value="28,00" />4 Queijos</label>
<label><input type="checkbox" name="ch[]" value="36,00" />Moda da Casa</label>
<label><input type="checkbox" name="ch[]" value="32,00" />Chocolate</label>
<label>Resultado: <input type="text" name="result" id="result" value="R$ 0,00" /></label>
<label>Dinheiro: <input type="text" name="moeda" ></label>
<label><input type="submit" name="nota" value="Gerar Pedido"></label>
<!-- Inicio do codigo de controle automatico de valores por itens-->
<script>
String.prototype.formatMoney = function() {
var v = this;
if(v.indexOf('.') === -1) {
v = v.replace(/([\d]+)/, "$1,00");
}
v = v.replace(/([\d]+)\.([\d]{1})$/, "$1,$20");
v = v.replace(/([\d]+)\.([\d]{2})$/, "$1,$2");
v = v.replace(/([\d]+)([\d]{3}),([\d]{2})$/, "$1.$2,$3");
return v;
};
String.prototype.toFloat = function() {
var v = this;
if (!v) return 0;
return parseFloat(v.replace(/[\D]+/g, '' ).replace(/([\d]+)(\d{2})$/, "$1.$2"));
};
(function(){
"use strict";
var $chs = document.querySelectorAll('input[name="ch[]"]'),
$result = document.getElementById('result'),
chsArray = Array.prototype.slice.call($chs);
chsArray.forEach(function(element, index, array){
element.addEventListener("click", function(){
var v = this.value,
result = 0;
v = v.toFloat();
if (this.checked === true) {
result = $result.value.toFloat() + parseFloat(v);
} else {
result = $result.value.toFloat() - parseFloat(v);
}
$result.value = " " + String(result).formatMoney();
});
});
}());
</script>
Mas preciso pegar o sabor da pizza para fazer á nota fiscal, sobre pegar o valor eu já consigo pegar ele o meu caso é somente pegar o sabor para colocar na nota.
Alguem te uma ideia?Discussão (2)
Carregando comentários...