Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

paptod

Caludaora cada situação um calculo diferente

Recommended Posts

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd"
    >
<htmL>

    <head>
        <title>Calculadora EuImport</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="https://code.jquery.com/jquery-2.1.0.min.js"></script>
        <script>
            $(function() {
                $("#form-calcular").submit(function(e) {
                    var cotacao_dolar = 2.37;
                    e.preventDefault();
                    var peso = $("#peso").val();
                    peso = roundWeight(peso);
                    var invoice = $("#total-invoice").val().replace(",", ".");
                    var total = invoice / 4 + (peso * 2.2 / 100);
                    $("#total-servico-us").val("U$ " + total.formatMoney(2, ',', '.'));
                    var total_br = total * cotacao_dolar;
                    total_br = total_br.formatMoney(2, ',', '.');
                    $("#total-servico-br").val("R$ " + total_br);
                });
            });

            function roundWeight(w) {
                if (w.length > 2) {
                    var t = w.length - 2;
                    var l = parseInt(w % 20);
                    if (l > 0) {
                        roundedResult = parseInt(w.substr(0, t));
                        roundedResult++;
                        roundedResult = roundedResult * 100;
                        return roundedResult;
                    } else
                        return w;
                } else {
                    return 100;
                }
            }

            Number.prototype.formatMoney = function(c, d, t) {
                var n = this,
                    c = isNaN(c = Math.abs(c)) ? 2 : c,
                    d = d == undefined ? "," : d,
                    t = t == undefined ? "." : t,
                    s = n < 0 ? "-" : "",
                    i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
                    j = (j = i.length) > 3 ? j % 3 : 0;
                return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
            };
        </script>
    </head>
    <style type="text/css">
        #wrapper {
            width:343px;
            margin:0 auto;
            font-family:Verdana, sans-serif;
        }
        label {
            cursor:pointer;
        }
        legend {
            color:#0481b1;
            font-size:16px;
            padding:0 10px;
            background:#fff;
            -moz-border-radius:4px;
            box-shadow: 0 1px 5px rgba(4, 129, 177, 0.5);
            padding:5px 10px;
            text-transform:uppercase;
            font-family:Helvetica, sans-serif;
            font-weight:bold;
        }
        fieldset {
            border-radius:4px;
            background: #fff;
            background: -moz-linear-gradient(#fff, #f9fdff);
            background: -o-linear-gradient(#fff, #f9fdff);
            background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#fff), to(#f9fdff));
            / background: -webkit-linear-gradient(#fff, #f9fdff);
            padding:20px;
            border-color:rgba(4, 129, 177, 0.4);
        }
        input, textarea {
            color: #000000;
            background: #fff;
            border: 1px solid #CCCCCC;
            color: #aaa;
            font-size: 14px;
            line-height: 1.2em;
            margin-bottom:15px;
            -moz-border-radius:4px;
            -webkit-border-radius:4px;
            border-radius:4px;
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1) inset, 0 1px 0 rgba(255, 255, 255, 0.2);
        }
        input[type="text"], input[type="password"] {
            padding: 8px 6px;
            height: 22px;
            width:280px;
        }
        input[type="submit"] {
            background: #222;
            border: none;
            text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.3);
            text-transform:uppercase;
            color: #eee;
            cursor: pointer;
            font-size: 15px;
            margin: 5px 0;
            padding: 5px 22px;
            -moz-border-radius: 4px;
            border-radius: 4px;
            -webkit-border-radius:4px;
            -webkit-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.3);
            -moz-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.3);
            box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.3);
        }
        textarea {
            padding:3px;
            width:96%;
            height:100px;
        }
        textarea:focus {
            background:#ebf8fd;
            text-indent: 0;
            z-index: 1;
            color: #373737;
            opacity:0.6;
            box-shadow:0 0 5px rgba(4, 129, 177, 0.5);
            border-color:#ccc;
        }
        .small {
            line-height:14px;
            font-size:12px;
            color:#999898;
            margin-bottom:3px;
        }
    </style>

    <body>
        <div id="wrapper">
            <form id="form-calcular">
                <fieldset>
                    <legend>Cálculo Frete USA-BRA</legend>
                    <div>
                        <label for="peso">Peso Total em Gramas</label>
                        <br />
                        <input type="text" name="peso" id="peso" />
                    </div>
                    <div>
                        <label for="total-invoice">Valor Total da Invoice U$</label>
                        <br />
                        <input type="text" name="total-invoice" id="total-invoice" />
                    </div>
                    <div>
                        <label for="dolar-atual">Cota褯 do Dolar em 21/07/2014</label>
                        <input type="text" id="dolar-atual" readonly value="R$ 2,37" />
                    </div>
                    <div>
                        <label for="total-servico-us">Total do Servi诠em U$</label>
                        <input type="text" name="total-servico-us" id="total-servico-us" readonly/>
                    </div>
                    <div>
                        <label for="total-servico-br">Total do Servi诠em R$</label>
                        <input type="text" name="total-servico-br" id="total-servico-br" readonly/>
                    </div>
                    <input type="submit" name="submit" value="Calcular" />
                </fieldset>
            </form>
            <p style="color:red; text-align:center;"><strong>Aten褯:</strong> O valor do frete nacional ainda n䯠estᡩnclu no servi诼/p>
        </div>

    </body>

</html>

Criei esta calculador que o usuário irá digitar um valor em g no primeiro e um valor em dólar no segundo. Ela pega o valor do primeiro campo e multiplica por 2.20, pega o valor do segundo campo e multiplica por 25%, em seguida soma os dois valores.

 

Gostaria que quando o usuário digitasse um valor <=150,00 fosse pego o peso * 2,30 e invoice * 35%. Caso o valor fosse >=151,00 e <401, peso *2,30, invocie *30%. Será se alguém pode dar uma luz?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Queria que se o usuário digitar um valor =<150,00 fosse pego o peso * 2,30 e invoice * 35%. Caso o valor fosse >=151,00 e <401, peso *2,30, invocie *30%. Ou seja terá 2 condições. Já quebrei a cabeça. Tentei inserir um se mais nao deu certo

Compartilhar este post


Link para o post
Compartilhar em outros sites

Calculos matemáticos eu sei. O


Calculos matemáticos eu sei fazer. Porém estou tendo problemas com a função "SE". Não estou sabendo em certo onde devo inseri-la. Fiz assim, mais nao deu certo:

<head>
<title>Calculadora EuImport</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="https://code.jquery.com/jquery-2.1.0.min.js"></script>
<script>
$(function() {
$("#form-calcular").submit(function(e) {
var cotacao_dolar = 2.37;
e.preventDefault();
var peso = $("#peso").val();
peso = roundWeight(peso);
var invoice = $("#total-invoice").val().replace(",", ".");

Se (invoice <= 150){
var total = (invoice * 35)/100 + (peso * 2.2 / 100);
$("#total-servico-us").val("U$ " + total.formatMoney(2, ',', '.'));
var total_br = total * cotacao_dolar;
total_br = total_br.formatMoney(2, ',', '.');
$("#total-servico-br").val("R$ " + total_br);

}

Se(invoice <= 401){

var total = (invoice * 30)/100 + (peso * 2.3 / 100);
$("#total-servico-us").val("U$ " + total.formatMoney(2, ',', '.'));
var total_br = total * cotacao_dolar;
total_br = total_br.formatMoney(2, ',', '.');
$("#total-servico-br").val("R$ " + total_br);

}

Se(invoice > 401){

var total = (invoice * 25)/100 + (peso * 2.3 / 100);
$("#total-servico-us").val("U$ " + total.formatMoney(2, ',', '.'));
var total_br = total * cotacao_dolar;
total_br = total_br.formatMoney(2, ',', '.');
$("#total-servico-br").val("R$ " + total_br);

}

Porém não esta dando certo. Onde estou errando?

});
});

function roundWeight(w) {
if (w.length > 2) {
var t = w.length - 2;
var l = parseInt(w % 20);
if (l > 0) {
roundedResult = parseInt(w.substr(0, t));
roundedResult++;
roundedResult = roundedResult * 100;
return roundedResult;
} else
return w;
} else {
return 100;
}
}

Number.prototype.formatMoney = function(c, d, t) {
var n = this,
c = isNaN(c = Math.abs(c)) ? 2 : c,
d = d == undefined ? "," : d,
t = t == undefined ? "." : t,
s = n < 0 ? "-" : "",
i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};
</script>
</head>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Muito obrigado com a ajuda de vocês consegui. Não estava conseguindo porque não estava inciando as variaveis.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd"
    >
<htmL>

    <head>
        <title>Calculadora EuImport</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="https://code.jquery.com/jquery-2.1.0.min.js"></script>
        <script>
            $(function() {
                $("#form-calcular").submit(function(e) {
                  var cotacao_dolar = 2.40;
                    e.preventDefault();
                  var peso = $("#peso").val();
                    peso = roundWeight(peso);
                    var invoice = $("#total-invoice").val().replace(",", ".");
                    
                    //logica do problema imasters
                    var taxaInvoice = 0;
                    var taxaPeso = 0;
                    var total = 0
                    
                    if(invoice <= 150) {
                       taxaPeso = (peso * 2.3)/100;
                       taxaInvoice = (invoice * 35)/100;
                    }
                    
                    if(invoice >= 151 && invoice <= 400) {
                      taxaPeso = (peso * 2.3)/100;
                      taxaInvoice = (invoice * 30)/100;
                    }
                    else{
                    taxaPeso = (peso * 2.20)/100
                    taxaInvoice = (invoice * 25)/100;
                    }
                    total =  taxaInvoice +  taxaPeso;
                    $("#total-servico-us").val("U$ " + total.formatMoney(2, ',', '.'));
                    var total_br = total * cotacao_dolar;
                    total_br = total_br.formatMoney(2, ',', '.');
                    $("#total-servico-br").val("R$ " + total_br);
                });
            });

            function roundWeight(w) {
                if (w.length > 2) {
                    var t = w.length - 2;
                    var l = parseInt(w % 20);
                    if (l > 0) {
                        roundedResult = parseInt(w.substr(0, t));
                        roundedResult++;
                        roundedResult = roundedResult * 100;
                        return roundedResult;
                    } else
                        return w;
                } else {
                    return 100;
                }
            }

            Number.prototype.formatMoney = function(c, d, t) {
                var n = this,
                    c = isNaN(c = Math.abs(c)) ? 2 : c,
                    d = d == undefined ? "," : d,
                    t = t == undefined ? "." : t,
                    s = n < 0 ? "-" : "",
                    i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
                    j = (j = i.length) > 3 ? j % 3 : 0;
                return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
            };
        </script>
    </head>
    <style type="text/css">
        #wrapper {
            width:343px;
            margin:0 auto;
            font-family:Verdana, sans-serif;
        }
        label {
            cursor:pointer;
        }
        legend {
            color:#0481b1;
            font-size:16px;
            padding:0 10px;
            background:#fff;
            -moz-border-radius:4px;
            box-shadow: 0 1px 5px rgba(4, 129, 177, 0.5);
            padding:5px 10px;
            text-transform:uppercase;
            font-family:Helvetica, sans-serif;
            font-weight:bold;
        }
        fieldset {
            border-radius:4px;
            background: #fff;
            background: -moz-linear-gradient(#fff, #f9fdff);
            background: -o-linear-gradient(#fff, #f9fdff);
            background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#fff), to(#f9fdff));
            / background: -webkit-linear-gradient(#fff, #f9fdff);
            padding:20px;
            border-color:rgba(4, 129, 177, 0.4);
        }
        input, textarea {
            color: #000000;
            background: #fff;
            border: 1px solid #CCCCCC;
            color: #aaa;
            font-size: 14px;
            line-height: 1.2em;
            margin-bottom:15px;
            -moz-border-radius:4px;
            -webkit-border-radius:4px;
            border-radius:4px;
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1) inset, 0 1px 0 rgba(255, 255, 255, 0.2);
        }
        input[type="text"], input[type="password"] {
            padding: 8px 6px;
            height: 22px;
            width:280px;
        }
        input[type="submit"] {
            background: #222;
            border: none;
            text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.3);
            text-transform:uppercase;
            color: #eee;
            cursor: pointer;
            font-size: 15px;
            margin: 5px 0;
            padding: 5px 22px;
            -moz-border-radius: 4px;
            border-radius: 4px;
            -webkit-border-radius:4px;
            -webkit-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.3);
            -moz-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.3);
            box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.3);
        }
        textarea {
            padding:3px;
            width:96%;
            height:100px;
        }
        textarea:focus {
            background:#ebf8fd;
            text-indent: 0;
            z-index: 1;
            color: #373737;
            opacity:0.6;
            box-shadow:0 0 5px rgba(4, 129, 177, 0.5);
            border-color:#ccc;
        }
        .small {
            line-height:14px;
            font-size:12px;
            color:#999898;
            margin-bottom:3px;
        }
    </style>

    <body>
        <div id="wrapper">
            <form id="form-calcular">
                <fieldset>
                    <legend>Cálculo Frete USA-BRA</legend>
                    <div>
                        <label for="peso">Peso Total em Gramas</label>
                        <br />
                        <input type="text" name="peso" id="peso" />
                    </div>
                    <div>
                        <label for="total-invoice">Valor Total da Invoice U$</label>
                        <br />
                        <input type="text" name="total-invoice" id="total-invoice" />
                    </div>
                    <div>
                        <label for="dolar-atual">Cota褯 do Dolar em 21/07/2014</label>
                        <input type="text" id="dolar-atual" readonly value="R$ 2,40" />
                    </div>
                    <div>
                        <label for="total-servico-us">Total do Servi诠em U$</label>
                        <input type="text" name="total-servico-us" id="total-servico-us" readonly/>
                    </div>
                    <div>
                        <label for="total-servico-br">Total do Servi诠em R$</label>
                        <input type="text" name="total-servico-br" id="total-servico-br" readonly/>
                    </div>
                    <input type="submit" name="submit" value="Calcular" />
                </fieldset>
            </form>
            <p style="color:red; text-align:center;"><strong>Aten褯:</strong> O valor do frete nacional ainda n䯠estᡩnclu no servi诼/p>
        </div>

    </body>

</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Esse é um exemplo clássico do pattern Strategy :lol:

 

Se ninguém implementar, eu volto e posto aqui.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Já está paptod, eu coloquei.

 

Existe um botão "Marcar como Resolvido", ao lado de cada post. Onde vc pode escolher qual foi o post que te ajudou a resolver o problema.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.