I have 3 tables and this is the scheme for this table
the first one is the product that has all products and the price and the margin of this product
the sconde one is the general bill that have information about the client and the total
The 3rd one is the problem;
I have to enter the id of the product in products
And number of products
And the prix should be extracted from the product table and multiplied by the number of products
the same for margin
and the general bill id have to be the same as the general_bill
and after that update the general bill with information about the total and total profit that have the same id from the table detail bill
for now I only figure out the simplest thing
import sqlite3
import time, datetime
from datetime import timedelta
class Crud_db:
def __init__(self, database = 'database.db'):
self.database = database
def connect(self):
self.connection = sqlite3.connect(self.database)
self.cursor = self.connection.cursor()
print('connect seccesfully')
def execute(self, query):
self.query = query
self.cursor.execute(self.query)
def close(self):
self.connection.commit()
self.connection.close()
def create_tables(self):
# create all tables
def insert_new_bill(self):
self.connect()
date_f = str(datetime.date.today())
time_f = str(datetime.datetime.now().time())
client_name = input('client name: ')
query01 = 'INSERT INTO general_bill (client_name, date_g, time_g) VALUES (?, ?, ?)'
data = (client_name,date_f, time_f)
self.cursor.execute(query01,data)
self.close()
print('added to general bill ..!')
def add_product(self):
self.connect()
product_name = input('product name: ')
prix = float(input('the price : '))
royltie = float(input('profit: '))
product_discreption = input('discreption: ')
product_query = 'INSERT INTO product (product_name, prix, royltie, product_descreption) VALUES (?,?,?,?)'
data_set = [product_name,prix,royltie,product_discreption]
self.cursor.execute(product_query,data_set)
self.close()
print(f'product {product_name} added to database')
question = input('do you wana add more products ?(yes/no): ')
if question.lower() == 'yes':
self.add_product()
else:
pass