I have a kind of purchase page where the income of the products to the stores is registered:
The suppliers table has a data called 'retencion'
which is the withholding percentage that has to be subtracted from the total to pay, it can be 0%, 75% or 100%; Now, when I change the select option, I need it to bring me the retention and perform the calculation, but it is not doing it, instead it places a value NaN
that I understand means 'not a number'.
My controller Proveedor
has this:
public function get_proveedor_by_id(Request $request)
{
if ($request->ajax()) {
$proveedors = Proveedor::findOrFail($request->proveedor_id);
return response()->json($proveedors);
}
}
My functions:
var proveedor_id = $('#proveedor_id');
proveedor_id.change(function() {
$.ajax({
url: "{{ route('get_proveedor_by_id') }}",
method: 'GET',
data: {
proveedor_id: proveedor_id.val(),
},
success: function(data) {
$("#retencion").val(data.retencion);
}
});
});
To calculate totals:
function totales() {
$("#subtotal").html("$ " + subtotalapagar.toFixed(2));
subtotal_pagar = subtotalapagar;
$("#subtotal_pagar_html").html("$ " + subtotal_pagar.toFixed(2));
$("#subtotal_pagar").val(subtotal_pagar.toFixed(2));
retencion = $("#retencion").val;
retencionapagar = subtotal * (retencion / 100);
$("#retencion").html("$ " + retencionapagar.toFixed(2));
$("#retencion_pagar_html").html("$ " + retencionapagar.toFixed(2));
$("#retencion_pagar").val(retencionapagar.toFixed(2));
impuesto = subtotalapagar * 0.16;
$("#impuesto").html("$ " + impuesto.toFixed(2));
impuesto_pagar = impuesto;
$("#impuesto_pagar_html").html("$ " + impuesto_pagar.toFixed(2));
$("#impuesto_pagar").val(impuesto_pagar.toFixed(2));
$("#total").html("$ " + total.toFixed(2));
total_pagar = total + impuesto;
$("#total_pagar_html").html("$ " + total_pagar.toFixed(2));
$("#total_pagar").val(total_pagar.toFixed(2));
tasa = $("#tasabs").val();
total_pagarbs = tasa * total_pagar;
$("#totalbs").html("Bs. " + total_pagarbs.toFixed(2));
$("#total_pagar_htmlbs").html("Bs. " + total_pagarbs.toFixed(2));
$("#total_pagarbs").val(total_pagarbs.toFixed(2));
}
What am I doing wrong?
I inspected the page and it turns out I was getting this error:
Target class [App\Http\Controllers\Request] does not exist.
So what I did in my
PedidoController
was to reference:Which is explained on this page of the Laravel documentation and the error was fixed, it already performs all the functions.