!C99Shell v. 2.0 [PHP 7 Update] [25.02.2019]!

Software: Apache/2.4.18 (Ubuntu). PHP/7.0.33-0ubuntu0.16.04.16 

uname -a: Linux digifus 3.13.0-57-generic #95-Ubuntu SMP Fri Jun 19 09:28:15 UTC 2015 x86_64 

uid=33(www-data) gid=33(www-data) groups=33(www-data) 

Safe-mode: OFF (not secure)

/var/www/FlaskApp/ahab/   drwxr-xr-x
Free 10.22 GB of 29.4 GB (34.77%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Feedback    Self remove    Logout    


Viewing file:     database_functions.py (5.62 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
import pymysql as mdb
import json

db_host = 'localhost'
db_user = 'db_user'
db_password = 'pacman'
db_database = 'almazen'
qr_store_folder = './qrcodes'
qr_scale = 12

def get_qr_filename_from_product(product_name):
    # return a qr filename for a product id
        with mdb.connect(db_host, db_user, db_password, db_database) as con:
        con.execute("SELECT codigo_qr from productos WHERE nombre='%s'" % product_name)
                row = con.fetchone()
                if row is not None:
            return row[0]
                return None

def create_qr_for_new_product(product_name):
    import pyqrcode
        with mdb.connect(db_host, db_user, db_password, db_database) as con:
        qr = pyqrcode.create('%s' % product_name)
        qr_filename = '%s/%s.png' % (qr_store_folder, product_name)
        qr.png(qr_filename, scale=qr_scale, module_color=[0, 0, 0, 128], background=[0xff, 0xff, 0xcc])
    return qr_filename

def insert_product(name, description, price):
    qr_code = create_qr_for_new_product(name)
    query = "INSERT INTO productos(nombre, descripcion, precio, codigo_qr) VALUES ('%s', '%s', %f, '%s')" % (name, description, price, qr_code)
        with mdb.connect(db_host, db_user, db_password, db_database) as con:
            con.execute(query)
                stock_query = "INSERT INTO stock_productos(nombre_producto, stock) VALUES ('%s', %d)" % (name, 0)
                con.execute(stock_query)

def get_all_products():
    with mdb.connect(db_host, db_user, db_password, db_database) as con:
    con.execute("SELECT nombre, descripcion, precio, codigo_qr, numero from productos")
    products = [dict(name=row[0], description=row[1], price=row[2], qr=row[3], code=row[4]) for row in con.fetchall()]
    return products

def get_product_by_name(product_name):
    with mdb.connect(db_host, db_user, db_password, db_database) as con:
        query = "SELECT nombre, descripcion, precio, numero from productos WHERE nombre='%s'" % product_name
    print query
           con.execute(query)
        product_row = con.fetchone()
        return { 'name': product_row[0], 'description': product_row[1], 'price' : float(product_row[2]), 'code': product_row[3] }

def insert_product_oder(order_id, json_products):
     for product in json_products:      
        with mdb.connect(db_host, db_user, db_password, db_database) as con:
            product_data = get_product_by_name(product['name'])
            seller_price = product_data['price'] 
            insert_query = 'INSERT INTO detalle_pedido(id_pedido, nombre_producto, cantidad, precio_venta) VALUES (%d, "%s", %d, %f)' % (order_id, product['name'], int(product['count']), seller_price)
            con.execute(insert_query)
            update_stock(product['name'], int(product['count']))
            
def update_stock(product_name, count):
   with mdb.connect(db_host, db_user, db_password, db_database) as con:
            query = 'UPDATE stock_productos SET stock=stock -%d WHERE nombre_producto="%s"'% (count, product_name)
            con.execute(query)

def insert_order(seller_id, client_id, date, products):
    import datetime
    total = 0.0
    iva = 1.21
    subtotal = 0.0
    #json_products = json.loads(str(products))
    json_products = products
    for product in json_products:
        # get product info
        product_data = get_product_by_name(product['name'])
        total += product_data['price']*product['count']*iva
        subtotal += product_data['price']*product['count']
    order_id = 1
    with mdb.connect(db_host, db_user, db_password, db_database) as con:
        query = "INSERT INTO pedidos(id_estado, fecha, id_cliente, total, vendedor, cotizador, descuento, subtotal) VALUES (%d, '%s', '%s', %f, '%s', '%s', 0.0, %f)" % (1, str(date), client_id, total, seller_id, seller_id, subtotal)
        con.execute(query)
    order_id = con.lastrowid
    # Insert order detail
    insert_product_oder(order_id, json_products)


####### CLIENTS
def get_all_clients():
    with mdb.connect(host=db_host, user=db_user, passwd=db_password, db=db_database, use_unicode=True) as con:
    con.execute("SELECT id, nombre, razon_social, direccion, localidad, telefono, cuit, mail, provincia, expreso from clientes")
    clients = [dict(id=row[0], name=row[1], business_name=row[2], address=row[3], city=row[4], telephone=row[5], cuit=row[6], mail=row[7], province=row[8], expresso=row[9]) for row in con.fetchall()]
    return clients


def insert_client(name, business_name, address, city, phone, cuit, mail, expresso, province):
    with mdb.connect(db_host, db_user, db_password, db_database) as con:
        insert_query = "INSERT INTO clientes(nombre, razon_social, direccion, localidad, telefono, nombre_comercial, cuit, mail, expreso, provincia) VALUES('%s','%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')" % (name, business_name, address, city, phone, business_name, cuit, mail, expresso, province)
    con.execute(insert_query)
    return {'id' : con.lastrowid, 'business_name': business_name}

def get_client_by_business_name(client_business_name):
    with mdb.connect(db_host, db_user, db_password, db_database) as con:
        query = "SELECT * from clientes WHERE razon_social='%s'" % client_business_name
           con.execute(query)
        row = con.fetchone()
        return { 'id': row[0], 'name': row[1], 'business name': row[2], 'address' : row[3], 'city': row[4], 'phone': row[5], 'cuit': row[7]}

def get_client_by_cuit(client_cuit):
    with mdb.connect(db_host, db_user, db_password, db_database) as con:
        query = "SELECT * from clientes WHERE cuit='%s'" % client_cuit
           con.execute(query)
        row = con.fetchone()
        return { 'id': row[0], 'name': row[1], 'business name': row[2], 'address' : row[3], 'city': row[4], 'phone': row[5], 'cuit': row[7]}

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.0 [PHP 7 Update] [25.02.2019] maintained by KaizenLouie | C99Shell Github | Generation time: 0.0058 ]--