Problems insert is inserted twice

QuestionsProblems insert is inserted twice
Sergio Pulido asked 8 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);

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`)
(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')";


$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`)
(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')";
//phpgrid_error("Error en la consulta de la trazabilidad…".$sql2);


1 Answers
Abu Ghufran answered 8 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

15 + 6 =

Login with your Social Id:

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 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

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

Let us improve this post!

Tell us how we can improve this post?