action ?? "") != ""){ include 'dbase.php'; $mys = ConexDB(); $info = $body->info; switch($body->action) { case "Codebar": $r = ""; $max = 5; while($r == "" && $max > 0) { $r = "E".rand(1000000000, 2147483647); $result = Query($mys, "select count(*) as c from InventoryRegistry where carga = ?", array($r)); if(!$result || $result[0]["c"] != 0) { $r = ""; $max -= 1; } } if($r == "") echo json_encode(array("error" => "Imposible generar el codigo de barra!")); else echo json_encode(array("bar" => $r)); break; case "FindProductsOut": $result = Query($mys, "select * from Inventory where refference = ? OR bcode = ?", array($info->find ?? "ignore", $info->find ?? "ignore")); if(!$result || count($result) == 0) echo json_encode(array("error" => "Producto no encontrado! Verifique!")); else echo json_encode(array("prods" => $result)); break; case "FindProductsIn": $result = Query($mys, "select i.*, COUNT(ir.id) as c, SUM(ir.dispatch) as dispatch from Inventory i join InventoryRegistry ir ON i.id = ir.prod_id where ir.carga = ? and type = 'OUT' and (i.refference = ? OR i.bcode = ?)", array($info->load_cbar ?? "ignore", $info->find ?? "ignore", $info->find ?? "ignore")); if(!$result || $result[0]["c"] == 0) echo json_encode(array("error" => "Producto no encontrado en la carga! Verifique!")); else echo json_encode(array("prods" => $result)); break; case "FindLoad": $result = Query($mys, "select count(*) as c from InventoryRegistry where carga = ?", array($info->find ?? "ignore")); if(!$result || $result[0]["c"] == 0) echo json_encode(array("error" => "Carga no encontrada! Verifique!")); else echo json_encode(array("ok" => true)); break; case "SaveReg": $d = date("Y-m-d H:i:s"); $result = Save($mys, "insert into InventoryRegistry( sysdate_registred, check_registred, user, warehouse, prod_id, type, dispatch, received, difference, carga, comments, hashcode) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)", array($d, $info->date_reg, $_SESSION["user"], $info->whouse, $info->prod_id, $info->type, $info->dispatch, $info->received ?? "0", $info->difference ?? "0", $info->load_cbar, $info->observation, md5($info->load_cbar.$info->prod_id.$d) )); if(!$result) echo json_encode(array("error" => "Error al insertar la información!")); else echo json_encode(array("msg" => "ok", "document" => md5($info->load_cbar.$info->prod_id.$d))); break; case "SaveFull": $d = date("Y-m-d H:i:s"); $result = Save($mys, "insert into InventoryRegistry( sysdate_registred, check_registred, user, warehouse, prod_id, type, dispatch, received, difference, carga, comments, hashcode) SELECT ?, ?, ?, ?, prod_id, 'IN', dispatch, dispatch, 0, carga, 'AUTOCOMPLETADO POR CARGA INTACTA', MD5(CONCAT(carga, prod_id, ?)) FROM `InventoryRegistry` WHERE carga = ? and type = 'OUT'", array($d, $info->date_reg, $_SESSION["user"], $info->whouse, $info->load_cbar, $info->load_cbar )); if(!$result) echo json_encode(array("error" => "Error al insertar la información!")); else echo json_encode(array("msg" => "ok")); break; case "ReportMov": $result = Query($mys, "select (@i:=IFNULL(@i,0) +1) as row, carga, user, IF(type = 'OUT', 'SALIDA', 'ENTRADA') AS type, warehouse, i.name, check_registred, IF(type = 'OUT', dispatch, received) as quantity from InventoryRegistry ir join Inventory i ON ir.prod_id = i.id where ? IN (ir.type, 'ALL') AND ? IN (i.refference, i.bcode, ir.carga) ORDER BY ir.check_registred DESC LIMIT 100", array($info->type_movement, $info->find_rep)); if(!$result || count($result) == 0) echo json_encode(array("count" => "0")); else echo json_encode(array("count" => count($result), "data" => $result)); break; default: echo json_encode(array("error" => "Bad request!")); break; } die(); } ?> Auditoria