I have a routine to update the status and balance of a document, this is the jquery code
$("#invBtnPay").on("click", function (event) {
alertify.confirm("Pagar Factura", "El Saldo de la Factura es de $" + $("#idt_saldo").text(),
function () {
var invoiceStatus = {
'inv_id': $("#inv_id").val(),
'inv_status': "Pagada",
'inv_pay': $("#idt_saldo").text(),
};
$.ajax({
type: 'POST',
url: './core/invoiceStatus.php',
data: invoiceStatus,
dataType: 'json',
encode: true
})
.done(function (invoiceStatus) {
if (invoiceStatus.success) {
$('#inv_status').addClass('badge badge-warning');
$('#inv_status').text(invoiceStatus.status);
window.location.href = "account.php?page=adm_add_invoice&title=Facturacion";
}
else {
alertify.error(invoiceStatus.message);
}
});
},
function () {
alertify.warning('Accion Cancelada!');
}).set('labels', { ok: 'Hacer el Pago', cancel: 'Cancelar' });
and this is the php code
<?php
require_once("../config.php");
$inv_id = $_POST['inv_id'];
$inv_status = $_POST['inv_status'];
$inv_pay = (!isset($_POST['inv_pay']) ? 0 : $_POST['inv_pay']); //toma el valor y lo divide entre 1000
$update = "UPDATE doc_master SET balance = balance - ?, status = ? WHERE id = ? LIMIT 1";
$stmt = $conn->prepare($update);
$stmt->bindParam(1, $inv_pay, PDO::PARAM_STR);
$stmt->bindParam(2, $inv_status, PDO::PARAM_STR);
$stmt->bindParam(3, $inv_id, PDO::PARAM_INT);
$stmt->execute();
$invoiceStatus = [];
if($update){
$invoiceStatus ['success'] = true;
$invoiceStatus ['invoiceId'] = $inv_id;
$invoiceStatus ['message'] = "Factura ".$inv_status." con Exito!";
$invoiceStatus ['status'] = $inv_status;
echo json_encode($invoiceStatus);
}
else
{
$invoiceStatus ['success'] = false;
$invoiceStatus ['message'] = "Algo salio mal, No fue posible actualizar en estado de la Factura!";
echo json_encode($invoiceStatus);
}
?>
As you can see, I send the id of the document ($inv_id)
, the new state ($inv_status)
and the value to discount ($inv_pay)
and this is where the problem is, it happens that the value is sent 5,300.00 and php arrives 5.3 and this is a value that deducts from the total of the document in such a way that the balance remains at 5,294.70
in the image you see how the values are after the payment
How can I solve this problem?
Thanks for your help.