Percentage javascript or php

0

I have these 3 buttons, a cost value - profit margin - sales value. I need it to calculate the value of automatic sale, I place the value of the cost I place the profit margin it shows within the field value of sale automatically, someone knows how to do it?

I tried to do with

function porcentagem_xn ( $porcentagem, $total ) {
    return ( $porcentagem / 100 ) * $total;
}

But I can not call the field I want, and the result does not appear automatically in the sales value field

<div type="text" class="col-lg-2 ">
    <label >Valor de Custo:</label>
    <input type="int" name="txt_custo" class="form-control number_format">          
</div> 
<div type="text" class="col-lg-1  ">
    <label >Margem(%):</label>
    <input type="int" name="txt_margem" class="form-control"  > 
</div> 
<div type="text" class="col-lg-2  ">
    <label >Valor de Venda:</label>
    <input type="int"  name="txt_venda" class="form-control">           
</div>
    
asked by anonymous 04.05.2018 / 16:16

2 answers

0

I think this should be used to calculate.

$('.valor').blur(function(){ // uso a classe valor para chamar o blur por mais de um campo
    var custo = $("input[name=txt_custo]").val() || 0;
    var margem = $("input[name=txt_margem]").val() || 0;
    var valor_total = 0;

    valor_total = ( margem / 100 ) * custo ;
    $("#txt_venda").val(parseFloat(valor_total));
});
    
04.05.2018 / 17:47
0

To calculate Profit you can do it that way. In the call of this function pass the value of Cost and the percentage of profit desired.

function calculaValor(valorCusto, percentualLucro){
   return (valorCusto + (valorCusto * (percentualLucro / 100)));
}
    
04.05.2018 / 17:58