Problems insert is inserted twice

QuestionsProblems insert is inserted twice
Sergio Pulido asked 4 years ago

Editing, cloned, deletion works well, using the model, master detail in a window, but to insert a record two are inserted.
To insert I do so by the function:

$e["on_insert"] = array("add_client", null, true);
$grid->set_events($e);

function add_client(&$data)
{
$id = intval($_GET["rowid"]);
$data["params"]["IdDiario"] = $id;

$FechaDelMovimiento = date("Y-m-d");

$sql ="INSERT INTO `logistic_almacen`.`diario_detalle_entradas` (`IdDetalleEntrada`, `IdDiario`, `IdProducto`, `FechaCaducidad`, `Lote`, `Cantidad`, `UnidadCaja`, `Total`, `UBICACION`, `IGIC`, `Almacen`)
VALUES
(NULL, '{$data["params"]["IdDiario"]}', '{$data["params"]["IdProducto"]}', '{$data["params"]["FechaCaducidad"]}', '{$data["params"]["Lote"]}', '{$data["params"]["Cantidad"]}', '{$data["params"]["UnidadCaja"]}',
'{$data["params"]["Total"]}', '{$data["params"]["UBICACION"]}', '3', '1')";

mysql_query($sql);

$sqlTotal = "select max(IdDetalleEntrada) as Contador From diario_detalle_entradas";
$rs = mysql_fetch_assoc(mysql_query($sqlTotal));
//phpgrid_error("Error en la consulta del máximo id");
//echo $rs['Contador'];

$sql2 = "INSERT INTO `Trazabilidad`
(`IdTraza`, `IdEntrada`, `Idproducto`, `FCaducidad`, `Cantidad`, `UnidadCaja`, `Total`, `Lote`, `Tipo`, `UBI`, `FMOVI`, `Almacen`)
VALUES
(NULL,".$rs['Contador'].", '{$data["params"]["IdProducto"]}', '{$data["params"]["FechaCaducidad"]}', '{$data["params"]["Cantidad"]}', '{$data["params"]["UnidadCaja"]}',
'{$data["params"]["Total"]}', '{$data["params"]["Lote"]}', 'E', '{$data["params"]["UBICACION"]}', '".$FechaDelMovimiento."', '1')";
mysql_query($sql2);
//phpgrid_error("Error en la consulta de la trazabilidad…".$sql2);

}

1 Answers
Abu Ghufran answered 4 years ago

If your complete insert logic is in event handler, then your can force stop the default insert of grid by setting 3rd argument to false.

$e["on_insert"] = array("add_client", null, false);

Your Answer

11 + 15 =

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating / 5. Vote count:

We are sorry that this post was not useful for you!

Let us improve this post!