def delete_reports(post_id=None):
       x = 'delete from kpi.kpi_cabecera  where  Id='+str(post_id)
       rv = metodos.set_insert(x,app.config['HOST'] ,app.config['USER'] ,app.config['PASSWORD'],app.config['DB'])
       x = 'delete from kpi.kpi_detalle where id_kpi='+str(post_id)
       rv = metodos.set_insert(x,app.config['HOST'] ,app.config['USER'] ,app.config['PASSWORD'],app.config['DB'])
       if rv != None :
              return rv
       return jsonify({"type":"error","status":401,"data":None})
def update_reporte_detalle():
       print request.form
       x="call sp_save_detalleReport("+str(request.form['id'])+","+str(request.form['id_kpi'])+",'"+request.form['hoja']+"','"+request.form['col']+"','"+request.form['fil']+"','"+request.form['query'].decode('utf8')+"','"+request.form['id_servidor']+"','"+request.form['nivel_2']+"','"+request.form['query_nivel2']+"','"+request.form['table_temp']+"','"+request.form['id_servidor_2']+"')"
       rv=metodos.set_insert(x,app.config['HOST'] ,app.config['USER'] ,app.config['PASSWORD'],app.config['DB'])
       if rv != None :
              return rv
       return jsonify({"type":"error","status":401,"data":None})
def update_correo():
       print request.form
       x="call sp_save_correo("+str(request.form['id'])+",'"+request.form['correos']+"','"+request.form['plantilla'].decode('utf8')+"','"+request.form['name_correo']+"')"
       rv=metodos.set_insert(x,app.config['HOST'] ,app.config['USER'] ,app.config['PASSWORD'],app.config['DB'])
       if rv != None :
              return rv
       return jsonify({"type":"error","status":401,"data":None})
def duplicate_reports(post_id=None):
       x = 'call duplicate_report('+str(post_id)+');'
       print x
       rv = metodos.set_insert(x,app.config['HOST'] ,app.config['USER'] ,app.config['PASSWORD'],app.config['DB'])
       if rv != None :
              return rv
       return jsonify({"type":"error","status":401,"data":None})
def uploader():
 if request.method == 'POST':
  # obtenemos el archivo del input "archivo"
  f = request.files['archivo']
  filename = secure_filename(f.filename)
  x = "insert into kpi.kpi_plantillas(name_plantilla)values('"+filename+"');"
  rv = metodos.set_insert(x,app.config['HOST'] ,app.config['USER'] ,app.config['PASSWORD'],app.config['DB'])
  f.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
  # Retornamos una respuesta satisfactoria
  return render_template('formulario.html') 
def delete_plantilla(post_id=None):
       x = 'delete from kpi.kpi_plantillas where Id='+str(post_id)
       rv = metodos.set_insert(x,app.config['HOST'] ,app.config['USER'] ,app.config['PASSWORD'],app.config['DB'])
       if rv != None :
              return rv
       return jsonify({"type":"error","status":401,"data":None})
def update_reporte():
       x="call sp_save_reportes("+str(request.form['id'])+",'"+request.form['ruc']+"','"+request.form['razon']+"','"+request.form['name_reporte']+"','"+request.form['plantilla']+"','"+request.form['id_correo']+"')"
       rv=metodos.set_insert(x,app.config['HOST'] ,app.config['USER'] ,app.config['PASSWORD'],app.config['DB'])
       if rv != None :
              return rv
       return jsonify({"type":"error","status":401,"data":None})
def update_servidores():
       x="call sp_save_servidores("+str(request.form['id'])+",'"+request.form['db']+"','"+request.form['host']+"','"+request.form['user']+"','"+request.form['password']+"','"+request.form['name_servidor']+"')"
       rv=metodos.set_insert(x,app.config['HOST'] ,app.config['USER'] ,app.config['PASSWORD'],app.config['DB'])
       if rv != None :
              return rv
       return jsonify({"type":"error","status":401,"data":None})