Пример #1
0
    def get(self):
        try:
            parser = reqparse.RequestParser()
            parser.add_argument('fecha',
                                type=str,
                                required=True,
                                help="Debe indicar id prestador",
                                
                                )
            parser.add_argument('id_sucursal',
                                type=str,
                                required=True,
                                help="Debe indicar id prestador",
                                
                                )
            parser.add_argument('estado',
                                type=str,
                                required=True,
                                help="Debe indicar id prestador",
                                
                                )
            data = parser.parse_args()
            Info = Orden.ordenFullInfoData(data["id_sucursal"], data["fecha"], data["estado"])

            return Info
        except Exception as e:
            print(" ## Error ## \n")
            print(e)
            print("\n")
            return {"message": "Ha ocurrido un error de conexión."}, 500      
Пример #2
0
    def post(self):
        try:
            ordenes = Orden.ordenToNotify()
            if len(ordenes) > 0:
                for x in ordenes:
                    msj ="Hola, tienes una orden pendiente por atender "
                    msj+="http://rypsystems.cl:5000/imprimir-orden/"+str(x["id"])
                    bot.send_message(5036077655, msj)
                    bot.send_message(5090328284, msj)

                    Orden.update_data(x["id"], {"informada": 1})
                    
            return ordenes
        except Exception as e:
            print(" ## Error ## \n")
            print(e)
            print("\n")
            return {"message": "Ha ocurrido un error de conexión."}, 500      
Пример #3
0
def imprime(_id):
    from aplicacion.modelos.Orden import Orden
    info = Orden.ordenFullInfo(_id)
    deff = 0
    for tot in info[0]["detalle"]:
        deff = deff + tot["precio_total"]

    info[0]["total_orden"] = deff + info[0]["delivery"]
    info[0][
        "paga"] = info[0]["pago"][0]["monto"] + info[0]["pago"][0]["vuelto"]
    # return info[0]

    return render_template("orden.html", data=info)
Пример #4
0
 def put(self):
     try:
        
         dataJson = request.get_json()      
         edit = Orden.update_data(dataJson["id"], dataJson)
         if edit:
             return {"estado" : 1, "orden" : edit}
            
         return {"estado" : 0, "msj": "Ha ocurrido un error"}
     except Exception as e:
         exc_type, exc_obj, exc_tb = sys.exc_info()
         fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
         msj = 'Error: '+ str(exc_obj) + ' File: ' + fname +' linea: '+ str(exc_tb.tb_lineno)
         return {'mensaje': str(msj)},500
Пример #5
0
def mailing(_id):
    from aplicacion.modelos.Orden import Orden
    info = Orden.ordenFullInfo(_id)
    deff = 0
    for tot in info[0]["detalle"]:
        deff = deff + tot["precio_total"]

    info[0]["total_orden"] = deff + info[0]["delivery"]
    info[0][
        "paga"] = info[0]["pago"][0]["monto"] + info[0]["pago"][0]["vuelto"]
    # return info[0]
    body = render_template("mail_orden.html", data=info)
    mail = Utilidades.send_mail(info[0]["correo"], 'Orden ' + str(_id), body)
    return info[0]
Пример #6
0
    def get(self):
        menu = []
        try:
            datos = Orden.getAll()
            if datos:
                for row in datos:
                    sucursal = Sucursal.get_data(row.id_sucursal)
                    data = {
                        "id": row.id,
                        "id_persona": row.id_persona,
                        "id_sucursal": row.id_sucursal,
                        "id_creador": row.id_creador,
                        "id_direccion": row.id_direccion,
                        "id_tipo_entrega": row.id_tipo_entrega,
                        "hora_recepcion": str(row.hora_recepcion),
                        "hora_salida": str(row.hora_salida),
                        "created_at": str(row.created_at),
                        "updated_at": str(row.updated_at),
                        "datos_sucursal" : sucursal,
                        "empresa_full_data" : Persona.get_data(sucursal[0]["id_cliente"]),
                        "datos_creador" : Persona.get_data(row.id_creador),
                        "datos_tipo_entrega" : TipoEntrega.get_data(row.id_tipo_entrega),
                        "datos_cliente": Persona.get_data(row.id_persona),
                        "direccion_cliente" : PersonaDireccion.DireccionByPersona(row.id_persona),
                        "telefono_cliente" : Telefono.get_data_by_persona(row.id_persona),
                        "correo_cliente" : Correo.get_data_by_persona(row.id_persona),
                        "datos_repartidor" : OrdenRepartidor.RepartidorByOrden(row.id),
                        "detalle_orden" : OrdenDetalle.DetalleByOrden(row.id)
                    }
                    
                    menu.append(data)
                        
            return {  "response":{"data": { "info": menu }}}, 200
            

        except Exception as e:
            print(" ## Error ## \n")
            print(e)
            print("\n")
            return {"message": "Ha ocurrido un error de conexión."}, 500
Пример #7
0
    def post(self):
        try:

            documento = 39
            fecha_emision = datetime.now()
            id_comprador = None
            estado = 2
            dataJson = request.get_json()
            if 'id_tipo_documento' in dataJson and dataJson["id_tipo_documento"]:
                documento = dataJson["id_tipo_documento"]
            if 'fecha_emision' in dataJson and dataJson["fecha_emision"]:
                fecha_emision = dataJson["fecha_emision"]
            if 'id_comprador' in dataJson and dataJson["id_comprador"]:
                id_comprador = dataJson["id_comprador"]
            
            jsonOrden = {
                "id_persona" : dataJson["id_persona"],
                "id_creador" : dataJson["id_creador"],
                "id_tipo_entrega" : dataJson["id_tipo_entrega"],
                "id_sucursal" : dataJson["id_sucursal"],
                "id_direccion" : dataJson["id_direccion"],           
                "hora_salida" : None,  
                "delivery": dataJson["delivery"],
                "kilometros": dataJson["kilometros"]

            }
            insert = Orden.insert(jsonOrden)
            if insert:
                for producto in dataJson["detalle"]:
                    sin =None
                    eleccion = None            
                    if 'detalle' in producto and producto['detalle'] is not None:
                        sin = producto["detalle"]
                    if 'eleccion' in producto and producto['eleccion'] is not None:
                        eleccion = producto["eleccion"]

                    jsonOrdenDetalle = {
                        "id_orden": insert,
                        "id_producto": producto['id'],
                        "cantidad" : producto['cantidad'],
                        "detalle" : sin,
                        "eleccion": eleccion,
                        "precio_unitario" :  producto['precio'],
                        "precio_extendido" :  producto['precio_bruto'],
                        "precio_total" : producto['sub_total'],
                        "precio_iva" : producto['iva']
                    }
                    insertDetalle = OrdenDetalle.insert(jsonOrdenDetalle)
                if "estado" in dataJson["pago"]:
                    estado = dataJson["pago"]['estado']

                if dataJson["pago"]['id_tipo_pago'] == 1 or dataJson["pago"]['id_tipo_pago'] == "1":
                    estado = 3

                if 'vuelto' not in dataJson["pago"] or dataJson["pago"]["vuelto"] is None:
                    vuelto = 0
                else:
                    vuelto = dataJson["pago"]['vuelto']

                jsonOrdenPago = {
                    "id_orden" : insert,
                    "id_tipo_pago" : dataJson["pago"]['id_tipo_pago'],
                    "monto":  dataJson["pago"]['monto'],
                    "voucher" : dataJson["pago"]['voucher'],
                    "comprobante" : dataJson["pago"]['comprobante'],
                    "vuelto" : vuelto,
                    "estado" : estado
                }

                insertOrdenPago = OrdenPago.insert(jsonOrdenPago)

                jsonDocumento = {
                    "folio" : 84555,
                    "id_orden": insert,
                    "id_tipo_documento" : documento,
                    "fecha_emision" : fecha_emision,
                    "estado": 1,
                    "id_persona" : id_comprador
                }
                insertDocu = Documento.insert(jsonDocumento)

                return {"estado" : 1, "orden" : insert}
                
            return {"estado" : 0, "msj": "Ha ocurrido un error"}
        except Exception as e:
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            msj = 'Error: '+ str(exc_obj) + ' File: ' + fname +' linea: '+ str(exc_tb.tb_lineno)
            return {'mensaje': str(msj)},500
Пример #8
0
def webpay():
    from aplicacion.helpers.transbank import transbank
    from aplicacion.modelos.Orden import Orden
    from aplicacion.modelos.OrdenPago import OrdenPago
    try:

        if request.method == 'GET':

            parser = reqparse.RequestParser()
            parser.add_argument('token',
                                type=str,
                                required=True,
                                help="Debe indicar una atención")
            # parser.add_argument('amount',
            #                     type=str,
            #                     required=True,
            #                     help="Debe indicar una atención"
            #                     )
            # parser.add_argument('order',
            #                     type=str,
            #                     required=True,
            #                     help="Debe indicar una atención"
            #                     )
            data = parser.parse_args()
            token = data["token"]
            data = base64.b64decode(data["token"])
            data = json.loads(data)
            infoOrden = Orden.ordenFullInfo(data["order"])
            if len(infoOrden) == 0:
                return {
                    "estado": 0,
                    "msj": "La orden que desea pagar no esta registrada"
                }
            deff = 0
            for tot in infoOrden[0]["detalle"]:
                deff = deff + tot["precio_total"]

            infoOrden[0]["total_orden"] = deff + infoOrden[0]["delivery"]
            monto = infoOrden[0]["total_orden"]

            body = {
                "order":
                data["order"],
                "session":
                datetime.now().timestamp(),
                "amount":
                monto,
                "url_return":
                "http://rypsystems.cl:5000/webpayresponse?token=" + str(token)
            }

            result = transbank.crearToken(body)
            upOp = {
                "url_redirect": data["url_return"],
                "tb_token": result["token"]
            }
            OrdenPago.update_data_by_orden(data["order"], upOp)
            result["method"] = "POST"
            return render_template('redirect.html', data=result)
        if request.method == 'POST':
            dataJson = request.get_json()
            token = json.dumps(dataJson).encode('utf-8')
            token = base64.b64encode(token)
            token = str(token).replace("b'", "")
            token = token.replace("'", "")
            return {"token": token}
    except Exception as e:
        print("=======================E")
        print(e)
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        msj = 'Error: ' + str(exc_obj) + ' File: ' + fname + ' linea: ' + str(
            exc_tb.tb_lineno)
        return msj
Пример #9
0
    def put(self):
        exist = None
        try:            
            first = 'Hola, que orden deseas consultar'
            r = requests.get(
                'https://api.telegram.org/bot1285646573:AAG8TM4f1ghE9rCU8DoP66s-SWVN63NcFYM/getUpdates')
            
            info = r.json()
            for x in info["result"]:
                msj = x["message"]["text"].strip()
                if msj.upper() == 'ENTRAR':
                    entro = Asistencia.entrada()
                    indicador = x["message"]["from"]["id"]
                    respondido = Telegram.get_data(x["update_id"])
                    
                    if not respondido:
                        bot.send_message(indicador, entro)
                        
                        ins = {
                            "id_update" : x["update_id"],
                            "id_chat" : x["message"]["from"]["id"]
                        }
                        Telegram.insert(ins)
                elif msj.upper() == 'SALIR':
                    salgo = Asistencia.salida()
                    indicador = x["message"]["from"]["id"]
                    respondido = Telegram.get_data(x["update_id"])
                    
                    if not respondido:
                        bot.send_message(indicador, salgo)
                        ins = {
                            "id_update" : x["update_id"],
                            "id_chat" : x["message"]["from"]["id"]
                        }
                        Telegram.insert(ins)
                else:
                    orden = x["message"]["text"].split(" ")
                    if len(orden) > 1:
                        if orden[1]:
                            try:
                                exist = Orden.ordenFullInfo(orden[1])
            
                            except Exception as e:
                                exc_type, exc_obj, exc_tb = sys.exc_info()
                                fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
                                msj = 'Error: '+ str(exc_obj) + ' File: ' + fname +' linea: '+ str(exc_tb.tb_lineno)
                                return {'mensaje': str(msj) }, 500

                            if exist:
                                first ="Nombre= " + str(exist[0]["nombre"]) +" \n"
                                first +="Teléfono= " + str(exist[0]["telefono"]) +" \n"
                                first +="Dirección= " + str(exist[0]["direccion"]) +" \n"
                                llamar = exist[0]["telefono"]
                            if orden[0] == 'o' or orden[0] == 'O' and exist:
                                indicador = x["message"]["from"]["id"]
                                respondido = Telegram.get_data(x["update_id"])
                                
                                if not respondido:
                                    bot.send_message(indicador, first)
                                    bot.send_message(indicador, llamar)
                                    ins = {
                                        "id_update" : x["update_id"],
                                        "id_chat" : x["message"]["from"]["id"]
                                    }
                                    Telegram.insert(ins)

            return r.json()
        except Exception as e:
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            msj = 'Error: '+ str(exc_obj) + ' File: ' + fname +' linea: '+ str(exc_tb.tb_lineno)
            return {'mensaje': str(msj) }, 500