def show(): id_primary = int(session['id_user']) #take all the query from table personal_books in_shop = 1 mycursor = mydb.cursor() sql = "SELECT * FROM personal_books INNER JOIN credentials ON personal_books.id_user=credentials.id where in_shop=%s" val = (in_shop, ) mycursor.execute(sql, val) result = mycursor.fetchall() username = session['user'] password = session['password'] if username == 'admin' and password == 'admin': admin_page = 1 else: admin_page = 0 if request.method == 'POST': if request.form.get('add_to_mybooks'): id_to_move = request.form.get('id_to_move') sql = "SELECT * FROM personal_books where id=%s" val = (id_to_move, ) mycursor.execute(sql, val) result = mycursor.fetchall() id_user = id_primary in_shop = 0 book_name = result[0][3] author = result[0][4] nr_page = result[0][5] review = result[0][6] sql = "INSERT INTO personal_books(id_user, in_shop, book_name, author, nr_page, review) VALUES (%s,%s,%s, %s, %s, %s) " val = (id_user, in_shop, book_name, author, nr_page, review) mycursor.execute(sql, val) mydb.commit() return redirect('shop') if request.method == 'POST': if request.form.get('delete_book'): id_to_delete = request.form.get('id_to_delete') shop_val = 0 sql = "UPDATE personal_books SET in_shop = %s WHERE id = %s" val = ( shop_val, id_to_delete, ) mycursor.execute(sql, val) mydb.commit() return redirect('shop') return render_template('shop.html', result=result, admin_page=admin_page)
def show(): errors = {"fail": ''} if request.method == 'POST': if request.form.get('register'): username = request.form.get('username') password = request.form.get('password') # put data in the table <credentials> mycursor = mydb.cursor() sql = "INSERT INTO credentials (username, password) VALUES(%s, %s)" val = (username, password) mycursor.execute(sql, val) mydb.commit() return redirect('/logpage') return render_template('register.html')
def show(): #take all the query from table personal_books id_primary = int(session['id_user']) mycursor = mydb.cursor() sql = "SELECT * FROM personal_books where id_user=%s" val = (id_primary, ) mycursor.execute(sql, val) result = mycursor.fetchall() #delete a book if request.method == 'POST': if request.form.get('delete_book'): id_to_delete = request.form.get('id_to_delete') #delete a query(book) sql = "DELETE FROM personal_books WHERE id=%s" val = (id_to_delete, ) mycursor.execute(sql, val) mydb.commit() return redirect('books') #add a book to the shop if request.method == 'POST': if request.form.get('add_to_shop'): id_to_move = request.form.get('id_to_move') shop_val = 1 sql = "UPDATE personal_books SET in_shop = %s WHERE id = %s" val = ( shop_val, id_to_move, ) mycursor.execute(sql, val) mydb.commit() return redirect('books') return render_template('books.html', result=result) #return session['id_user']
def show(): errors = {"fail": ''} if request.method == 'POST': if request.form.get('add'): book_name = request.form.get('book_name') author = request.form.get('author') nr_page = request.form.get('nr_page') review = request.form.get('review') id_user = int(session['id_user']) in_shop = 0 mycursor = mydb.cursor() sql = "INSERT INTO personal_books(id_user, in_shop, book_name, author, nr_page, review) VALUES (%s,%s,%s, %s, %s, %s) " val = (id_user, in_shop, book_name, author, nr_page, review) mycursor.execute(sql, val) mydb.commit() return redirect('books') return render_template('addbooks.html', errors=errors)
def show(): if request.method == 'POST': if request.form.get('submit'): email = request.form.get('email') message = request.form.get('message') date = request.form.get('date') #put the data into the table mycursor = mydb.cursor() sql = "INSERT INTO contact(email, message, date) VALUES (%s, %s, %s) " val = ( email, message, date, ) mycursor.execute(sql, val) mydb.commit() return redirect('/') return render_template('index.html')
def show(): #take the stored data mycursor = mydb.cursor() sql = "SELECT * FROM credentials" mycursor.execute(sql) result = mycursor.fetchall() #take the data from the contact tabel mycursor = mydb.cursor() sql = "SELECT * FROM contact" mycursor.execute(sql) result_contact = mycursor.fetchall() #checking the form for deleting an user if request.method == 'POST': if request.form.get('delete'): username = request.form.get('username') password = request.form.get('password') id_to_delete = request.form.get('id_to_delete') #delete the query sql = "DELETE FROM credentials WHERE id=%s" val = (id_to_delete, ) mycursor.execute(sql, val) mydb.commit() #delete the books that corespond to the user sql = "DELETE FROM personal_books WHERE id_user=%s" val = (id_to_delete, ) mycursor.execute(sql, val) mydb.commit() return redirect('adminpage') return render_template('adminpage.html', result=result, result_contact=result_contact)
def show(): mycursor = mydb.cursor() sql = "SELECT * FROM restaurant" #val = (id ) mycursor.execute(sql) restaurante = mycursor.fetchall() # selectam toate detaliile despre angajati mycursor = mydb.cursor() sql = "SELECT * FROM angajat inner join detalii_angajat on (id_angajat=angajat_id_angajat);" #val = (id ) mycursor.execute(sql) angajati = mycursor.fetchall() #print("id_man " + str(angajati[0][9])) # selectam toate detaliile despre managerii restaurantelor mycursor = mydb.cursor() sql = "SELECT * FROM angajat inner join detalii_angajat on (id_angajat=angajat_id_angajat) where pozitie='manager';" #val = (id ) mycursor.execute(sql) manageri = mycursor.fetchall() # for res in result: # print(res) # print(result[0][0]) # print(result[0][1]) # print(result[0][2]) # print(result[0][3]) # print(result[0][4]) # print(result[0][5]) # print(result[0][6]) # modificam detaliile despre angajat if request.method == 'POST': if request.form.get('modifica_angajat'): id_angajat = request.form.get('id_angajat') nume = request.form.get('nume') prenume = request.form.get('prenume') telefon = request.form.get('telefon') id_restaurant = request.form.get('id_restaurant') adresa = request.form.get('adresa') pozitie = request.form.get('pozitie') id_manager = request.form.get('id_manager') #data_angajare = request.form.get('data_angajare') email = request.form.get('email') # actualizam datele in tabela angajat sql = "UPDATE angajat SET nume=%s, prenume=%s, restaurant_id_restaurant=%s, telefon=%s, email=%s where id_angajat=%s;" val = ( nume, prenume, id_restaurant, telefon, email, id_angajat, ) mycursor.execute(sql, val) mydb.commit() # actualizam datele in tabela detalii_angajat sql = "UPDATE detalii_angajat SET angajat_id_angajat=%s, adresa=%s, pozitie=%s, id_manager=%s where angajat_id_angajat=%s" val = (id_angajat, adresa, pozitie, id_manager, id_angajat) mycursor.execute(sql, val) mydb.commit() return redirect('restaurant_angajati') # stergem un angajat if request.method == 'POST': if request.form.get('sterge_angajat'): id_angajat = request.form.get('id_angajat') sql = "DELETE FROM detalii_angajat where angajat_id_angajat=%s" val = (id_angajat, ) mycursor.execute(sql, val) mydb.commit() sql = "DELETE FROM angajat where id_angajat=%s" val = (id_angajat, ) mycursor.execute(sql, val) mydb.commit() return redirect('restaurant_angajati') # adaugam un nou restaurant if request.method == 'POST': if request.form.get('adauga_angajat'): nume = request.form.get('nume') prenume = request.form.get('prenume') telefon = request.form.get('telefon') id_restaurant = request.form.get('id_restaurant') adresa = request.form.get('adresa') pozitie = request.form.get('pozitie') id_manager = request.form.get('id_manager') #data_angajare = request.form.get('data_angajare') email = request.form.get('email') # print("nume " + str(nume)) # print("id_restaurant " + str(id_restaurant)) #print("data " + str(data_angajare)) #print("aici " + str(adresa)) # inseram datele in tabela angajat sql = "INSERT INTO angajat(nume, prenume, restaurant_id_restaurant, telefon, email) VALUES(%s, %s, %s, %s, %s)" val = ( nume, prenume, id_restaurant, telefon, email, ) mycursor.execute(sql, val) mydb.commit() # selectam angajatul introdus sql = "SELECT * FROM angajat order by id_angajat desc" #val = (nume, prenume, id_restaurant, telefon, email, ) mycursor.execute(sql) angajat_temp = mycursor.fetchall() id_angajat_temp = angajat_temp[0][0] if (id_manager == None): id_manager = id_angajat_temp # inseram datele in tabela detalii_angajat sql = "INSERT INTO detalii_angajat(angajat_id_angajat, adresa, pozitie, id_manager) VALUES(%s, %s, %s, %s)" val = ( id_angajat_temp, adresa, pozitie, id_manager, ) mycursor.execute(sql, val) mydb.commit() return redirect('restaurant_angajati') return render_template('restaurant_angajati.html', restaurante=restaurante, angajati=angajati, manageri=manageri)
def show(): errors = {"cantitate": ' ', "id_produs": ' '} # selectam produsele pentru a le afisa in tabel id_produs = 2 mycursor = mydb.cursor() sql = "SELECT * FROM produs where stoc > 0 and restaurant_id_restaurant=(select restaurant_id_restaurant from comanda order by id_comanda desc limit 1)" val = (id_produs, ) mycursor.execute(sql) produse = mycursor.fetchall() # selectam numarul de telefon si adresa sql = "SELECT id_restaurant, telefon, adresa FROM restaurant where oras='Iasi'" #de modificat Iasi mycursor.execute(sql) detalii_resturant = mycursor.fetchall() # adaugam produsul in tabela comanda_detalii if request.method == 'POST': if request.form.get('adauga_produs'): cantitate = request.form.get('cantitate_val') id_produs = request.form.get('id_produs') id_comanda = request.form.get('id_comanda') # stabilim toate conditiile necesare validarii formularului conditie = 0 # toate campurile sunt corecte # verificare cantitate cantitate_validare = re.match('^[0-9]*$', cantitate) if (cantitate_validare == None): print('cantitate invalid') errors['cantitate'] = 'cantitate invalida' errors['id_produs'] = int(id_produs) conditie = 1 if (conditie == 0): if (int(cantitate) > 0): #verificam daca sunt suficiente produse in stoc sql = "SELECT stoc from produs where id_produs=%s" val = (id_produs, ) mycursor.execute(sql, val) produs = mycursor.fetchall() stoc_cantitate = produs[0][0] if (int(cantitate) <= int(stoc_cantitate)): # adaugam produsul in comanda status = 1 sql = "INSERT INTO comanda_detalii(cantitate, produs_id_produs, status) VALUES(%s, %s, %s);" val = ( cantitate, id_produs, status, ) mycursor.execute(sql, val) mydb.commit() # actualizam stocurile pentru produsul adaugat noua_cantitate = int(stoc_cantitate) - int(cantitate) sql = "UPDATE produs SET stoc=%s where id_produs=%s" val = ( noua_cantitate, id_produs, ) mycursor.execute(sql, val) mydb.commit() errors['cantitate'] = '' errors['id_produs'] = '' return redirect('meniu') else: print( "mesag de informare, cantitate insuficienta in stoc!!" ) errors['cantitate'] = 'cantitate prea mare!' errors['id_produs'] = int(id_produs) else: print("\ncantiate nula\n") else: print('cantitate inv') print(errors['cantitate']) # creeam o inregistrare pentru comanda si asignam comenzii toate produsele adaugate pana acum(care au status=1) if request.method == 'POST': if request.form.get('comanda_produse'): id_restaurant = detalii_resturant[0][0] # creeam comanda si punem id-ul restaurantului in ea sql = "INSERT INTO comanda(restaurant_id_restaurant) VALUES(%s);" val = (id_restaurant, ) mycursor.execute(sql, val) mydb.commit() ###### ------ secventa pentru evitarea crearii mai multor comenzi fara a fi terminate ------####### # extragem id-ul comenzii create mai sus sql = "SELECT id_comanda FROM comanda order by id_comanda desc;" mycursor.execute(sql) comanda = mycursor.fetchall() print("\n comanda_id : " + str(comanda[1][0])) id_comanda = comanda[0][0] print("len = " + str(len(comanda))) if (len(comanda) == 1): # pentru tabela comanda, setam campul status pe valoarea 1 ( va fi setata pe valoarea 0 la terminarea comenzii) status_comanda_modificat = 1 sql = "UPDATE comanda SET status=%s where id_comanda=%s;" val = ( status_comanda_modificat, id_comanda, ) mycursor.execute(sql, val) mydb.commit() else: # extragem statusul penultimei comenzi pentru a vedea daca este terminata(status=0) sql = "SELECT status from comanda where id_comanda=%s;" val = (comanda[1][0], ) mycursor.execute(sql, val) temp = mycursor.fetchall() status_temp = temp[0][0] if (int(status_temp) == 0): # validam ultima inregistrare # pentru tabela comanda, setam campul status pe valoarea 1 ( va fi setata pe valoarea 0 la terminarea comenzii) status_comanda_modificat = 1 sql = "UPDATE comanda SET status=%s where id_comanda=%s;" val = ( status_comanda_modificat, id_comanda, ) mycursor.execute(sql, val) mydb.commit() else: # penultima comanda este in desfasurare si ultima inregistrare trebuie stearsa sql = "DELETE from comanda where id_comanda=%s;" val = (id_comanda, ) mycursor.execute(sql, val) mydb.commit() ###### ------ terminare secventa ------####### # extragem id-ul comnezii create mai sus sql = "SELECT id_comanda FROM comanda order by id_comanda desc limit 1;" mycursor.execute(sql) comanda = mycursor.fetchall() print("\n comanda_id : " + str(comanda[0][0])) # facem update pe toate inregistrarile din comanda_detalii care au staus=1 status_modificat = 0 sql = "UPDATE comanda_detalii SET comanda_id_comanda=%s, status=%s where status=1;" val = (comanda[0][0], status_modificat) mycursor.execute(sql, val) mydb.commit() #return redirect('comanda_client') return redirect('client') return render_template('meniu.html', produse=produse, detalii_resturant=detalii_resturant, errors=errors)
def show(): mycursor = mydb.cursor() sql = "SELECT SYSDATE()"; mycursor.execute(sql) data_preluare = mycursor.fetchall() print("data aeste : ", data_preluare[0][0]) print("data aeste : ", data_preluare[0][0].year) print("data aeste : ", data_preluare[0][0].second) # array folosit pentru mesajele de eroare in cazul valorilor invalide din formular errors = {"telefon": ' ', "adresa": ' ', "email": ' '} # array folost in cazul in care se introduc date invalide(pentru a nu se reseta campurile(a nu se sterge datele din campuri)) detalii_formular_invalid = {"nume":'', "telefon":'', "adresa": '', "email": '', "conditie":'0'} # aflam id-ul comenzii sql = "SELECT id_comanda from comanda order by id_comanda desc limit 1"; mycursor.execute(sql) id_comanda = mycursor.fetchall() print("comanda id : " + str(id_comanda[0][0])) # actualizam pretul comenzii (il setam) sql = "UPDATE comanda SET suma_totala = (select sum(p.pret*d.cantitate) from produs p join comanda_detalii d on (d.comanda_id_comanda=%s and d.produs_id_produs=p.id_produs)) where id_comanda=%s" val = (id_comanda[0][0], id_comanda[0][0], ) mycursor.execute(sql, val) mydb.commit() # extragem pretul comenzii pentru a-l afisa sql = "SELECT suma_totala from comanda where id_comanda=%s"; val = (id_comanda[0][0],) mycursor.execute(sql, val) pret = mycursor.fetchall() # [(pret, )] if(pret == None): pret = 0 print("pret 1 = ", pret) pret = pret[0][0] # extragem doar valoarea pretului din tupla print("pret 2 = ", pret) # selectam produsele care apartin comenzii pentru a le afisa in tabel sql = "SELECT * from produs inner join comanda_detalii on (id_produs=produs_id_produs) where comanda_id_comanda = %s;" #de modificat Iasi val = (id_comanda[0][0], ) mycursor.execute(sql, val) result = mycursor.fetchall() print("resukl = ", result) # selectam numarul de telefon si adresa sql = "SELECT id_restaurant, telefon, adresa FROM restaurant where oras='Iasi'" #de modificat Iasi mycursor.execute(sql) detalii_resturant = mycursor.fetchall() # stergem produsul din tabela comanda_detalii if request.method == 'POST': if request.form.get('sterge_produs'): id_comanda_detalii = request.form.get('id_comanda_detalii') # stergem produsul sql = "DELETE FROM comanda_detalii where id_comanda_detalii = %s " val = (id_comanda_detalii, ) mycursor.execute(sql, val) mydb.commit() ## ------ actualizam stocul pentru produsul sters ----- # aflam cantitatea deja existenta pentru produs id_produs = request.form.get('id_produs') sql = "SELECT stoc from produs where id_produs=%s" val = (id_produs, ) mycursor.execute(sql, val) produs = mycursor.fetchall() stoc_cantitate = produs[0][0] # actualizam stocul pentru produs cantitate_de_sters = request.form.get('cantitate') noua_cantitate = int(stoc_cantitate) + int(cantitate_de_sters) sql = "UPDATE produs SET stoc=%s where id_produs=%s" val = (noua_cantitate, id_produs, ) mycursor.execute(sql, val) mydb.commit() # actualizam pretul comenzii (il setam) sql = "UPDATE comanda SET suma_totala = (select sum(p.pret*d.cantitate) from produs p join comanda_detalii d on (d.comanda_id_comanda=%s and d.produs_id_produs=p.id_produs)) where id_comanda=%s" val = (id_comanda[0][0], id_comanda[0][0], ) mycursor.execute(sql, val) mydb.commit() # extragem pretul comenzii pentru a-l afisa sql = "SELECT suma_totala from comanda where id_comanda=%s"; val = (id_comanda[0][0],) mycursor.execute(sql, val) pret = mycursor.fetchall() # [(pret, )] pret = pret[0][0] # extragem doar valoarea pretului din tupla if(pret == None): pret = 0 # selectam produsele care apartin comenzii pentru a le afisa in tabel sql = "SELECT * from produs inner join comanda_detalii on (id_produs=produs_id_produs) where comanda_id_comanda = %s;" #de modificat Iasi val = (id_comanda[0][0], ) mycursor.execute(sql, val) result = mycursor.fetchall() return render_template('client.html', pret=pret, detalii_formular_invalid=detalii_formular_invalid, result=result, detalii_resturant=detalii_resturant, errors=errors) # creeam o inregistrare in tabela client if request.method == 'POST': if request.form.get('termina_comanda'): id_restaurant = detalii_resturant[0][0] nume = request.form.get('nume') telefon = request.form.get('telefon') adresa = request.form.get('adresa') email = request.form.get('email') # stabilim toate conditiile necesare validarii formularului conditie = 0 # toate campurile sunt corecte # verificare numar telefon #telefon_validare = re.match('^0(2|7)\d{8}$', telefon) # alta varianta temp = re.compile('^0(2|7)\d{8}$') telefon_validare = temp.match(telefon) print("te : " , telefon_validare) if (telefon_validare == None): print('telefon invalid') errors['telefon'] = 'telefon invalid' conditie = 1 # vericare adresa locatie if (len(adresa) == 0): print('adresa invalid') errors['adresa'] = 'adresa invalida' conditie = 1 # vericare adresa email email_validare = re.match('[a-z0-9._%-]+@[a-z0-9._%-]+\.[a-z]{2,4}', email) if (email_validare == None and len(email)>0): print('email invalid') errors['email'] = 'adresa de email invalida' conditie = 1 # array folost in cazul in care se introduc date invalide(pentru a nu se reseta campurile(a nu se sterge datele din campuri)) detalii_formular_invalid['nume'] = nume detalii_formular_invalid['telefon'] = telefon detalii_formular_invalid['adresa'] = adresa detalii_formular_invalid['email'] = email detalii_formular_invalid['conditie'] = conditie if(conditie == 0): # datele sunt valide # selectam data curenta pentru a o folosi in campul data_preluare sql = "SELECT SYSDATE()"; mycursor.execute(sql) data_preluare = mycursor.fetchall() #creeam o inregistrare pentru client sql = "INSERT INTO client(nume, telefon, adresa, email) VALUES(%s, %s, %s, %s);" val = (nume, telefon, adresa, email,) mycursor.execute(sql, val) mydb.commit() # extragem id-ul clientului creat mai sus sql = "SELECT id_client FROM client order by id_client desc limit 1;" mycursor.execute(sql) client = mycursor.fetchall() print("\n client_id : " + str(client[0][0])) # extragem id-ul comenzii sql = "SELECT id_comanda FROM comanda order by id_comanda desc limit 1;" mycursor.execute(sql) comanda = mycursor.fetchall() id_comanda = comanda[0][0] print("\n comanda_id : " + str(comanda[0][0])) # adaugam id-ul clientului in tabela comanda [si data_prelucrare !!!!! ( de facut)] sql = "UPDATE comanda SET client_id_client=%s, data_preluare=%s where id_comanda=%s" val = (client[0][0], data_preluare[0][0], comanda[0][0]) mycursor.execute(sql, val) mydb.commit() # setam statusul comenzii ca fiind incheiat (status=0) status_incheiat = 0; sql = "UPDATE comanda SET status=%s where id_comanda=%s;" val = (status_incheiat, id_comanda, ) mycursor.execute(sql, val) mydb.commit() errors['telefon'] = '' errors['adresa'] = '' errors['email'] = '' detalii_formular_invalid['nume'] = '' detalii_formular_invalid['telefon'] = '' detalii_formular_invalid['adresa'] = '' detalii_formular_invalid['email'] = '' detalii_formular_invalid['conditie'] = '' return redirect('/') else: return render_template('client.html', pret=pret, detalii_formular_invalid=detalii_formular_invalid, result=result, detalii_resturant=detalii_resturant, errors=errors) return render_template('client.html', pret=pret, result=result, detalii_resturant=detalii_resturant, errors=errors, detalii_formular_invalid=detalii_formular_invalid)
def show(): mycursor = mydb.cursor() # selectam toate restaurantele id_produs = 2 sql = "SELECT * FROM restaurant " val = () mycursor.execute(sql) restaurante = mycursor.fetchall() # selectam produsele pentru a le afisa in tabel sql = "SELECT * FROM produs where stoc > 0 and restaurant_id_restaurant=(select id_restaurant from restaurant where oras='Suceava')" #de modificat Iasi val = (id_produs, ) mycursor.execute(sql) result = mycursor.fetchall() # selectam comenzile pentru a le afisa in tabel sql = "SELECT * FROM comanda;" val = (id_produs, ) mycursor.execute(sql) comenzi = mycursor.fetchall() for comanda in comenzi: print(comanda[1]) # selectam clientii pentru a-i afisa in tabel sql = "SELECT * FROM client;" val = (id_produs, ) mycursor.execute(sql) clienti = mycursor.fetchall() #print(clienti) # selectam toate detaliile despre angajati mycursor = mydb.cursor() sql = "SELECT * FROM angajat inner join detalii_angajat on (id_angajat=angajat_id_angajat) where pozitie = 'curier';" #val = (id ) mycursor.execute(sql) angajati = mycursor.fetchall() # selectam toate comenzile cu detaliile lo id_produs = 2 sql = "select id_comanda, comanda_id_comanda, produs.denumire, ingrediente, cantitate, pret from comanda inner join comanda_detalii on (id_comanda=comanda_id_comanda) inner join produs on (id_produs=produs_id_produs);" #val = (,) mycursor.execute(sql) detalii_comanda = mycursor.fetchall() # adaugam produsul in tabela comanda_detalii if request.method == 'POST': if request.form.get('actualizeaza_comanda'): id_comanda = request.form.get('id_comanda') status_livrare = request.form.get('gata_de_livrare') id_produs = request.form.get('id_produs') #print("status: ", status_livrare) if (status_livrare == 'on' ): # status primit de la butonul de check (Gata de livrare) status_db = 1 else: status_db = 1 sql = "UPDATE comanda SET status_livrare=%s where id_comanda=%s" val = ( status_db, id_comanda, ) mycursor.execute(sql, val) mydb.commit() return redirect('comenzi') # asignam comanda unui curier if request.method == 'POST': if request.form.get('preia_comanda'): id_angajat = request.form.get('id_angajat') id_comanda = request.form.get('id_comanda') sql = "UPDATE comanda SET angajat_id_angajat=%s where id_comanda=%s" val = ( id_angajat, id_comanda, ) mycursor.execute(sql, val) mydb.commit() return redirect('comenzi') #finalizam comanda si adaugam data de livrare if request.method == 'POST': if request.form.get('marcheaza_ca_livrata'): id_comanda = request.form.get('id_comanda') status_livrare = request.form.get('gata_de_livrare') id_produs = request.form.get('id_produs') # selectam data curenta pentru a o folosi in campul data_livrare sql = "SELECT SYSDATE()" mycursor.execute(sql) data_livrare = mycursor.fetchall() sql = "UPDATE comanda SET data_livrare=%s where id_comanda=%s" val = ( data_livrare[0][0], id_comanda, ) mycursor.execute(sql, val) mydb.commit() return redirect('comenzi') return render_template('comenzi.html', detalii_comanda=detalii_comanda, result=result, clienti=clienti, angajati=angajati, restaurante=restaurante, comenzi=comenzi)
def show(): mycursor = mydb.cursor() # selectam detaliile despre restaurante sql = "SELECT * from restaurant;" mycursor.execute(sql) restaurante = mycursor.fetchall() # select id_comanda pentru care status=1 sql = "SELECT id_comanda from comanda where status=1;" mycursor.execute(sql) id_comanda = mycursor.fetchall() print(len(id_comanda)) if (id_comanda): print("in comanda") # stergem produsele care apartin comenzii in desfasurare(a fost stearsa mai sus din tabela comanda) sql = "DELETE FROM comanda_detalii where comanda_id_comanda=%s;" val = (id_comanda[0][0], ) mycursor.execute(sql, val) mydb.commit() # stergem inregistrarea cu status=1 sql = "DELETE FROM comanda where status=1;" mycursor.execute(sql) mydb.commit() # stergem toate produsele cu status=1 sql = "DELETE FROM comanda_detalii where status=1;" mycursor.execute(sql) mydb.commit() # creeam o inregistrare pentru comanda si asignam comenzii toate produsele adaugate pana acum(care au status=1) if request.method == 'POST': if request.form.get('alege_restaurant'): #id_restaurant = request.form.get('id_restaurant') oras_temp = request.form.get('alege_restaurant') # extragem id-ul restaurantului ales sql = "SELECT id_restaurant FROM restaurant where oras = %s" val = (oras_temp, ) mycursor.execute(sql, val) restaurant_temp = mycursor.fetchall() id_restaurant = restaurant_temp[0][0] # creeam comanda si punem id-ul restaurantului in ea sql = "INSERT INTO comanda(restaurant_id_restaurant) VALUES(%s);" val = (id_restaurant, ) mycursor.execute(sql, val) mydb.commit() ###### ------ secventa pentru evitarea crearii mai multor comenzi fara a fi terminate ------####### # extragem id-ul comenzii create mai sus sql = "SELECT id_comanda FROM comanda order by id_comanda desc;" mycursor.execute(sql) comanda = mycursor.fetchall() #print("\n comanda_id : " + str(comanda[1][0])) id_comanda = comanda[0][0] print("len = " + str(len(comanda))) if (len(comanda) == 1): # pentru tabela comanda, setam campul status pe valoarea 1 ( va fi setata pe valoarea 0 la terminarea comenzii) status_comanda_modificat = 1 sql = "UPDATE comanda SET status=%s where id_comanda=%s;" val = ( status_comanda_modificat, id_comanda, ) mycursor.execute(sql, val) mydb.commit() else: # extragem statusul penultimei comenzi pentru a vedea daca este terminata(status=0) sql = "SELECT status from comanda where id_comanda=%s;" val = (comanda[1][0], ) mycursor.execute(sql, val) temp = mycursor.fetchall() status_temp = temp[0][0] print("sadsd ", status_temp) if (status_temp == None): status_temp = 0 if (int(status_temp) == 0): # validam ultima inregistrare # pentru tabela comanda, setam campul status pe valoarea 1 ( va fi setata pe valoarea 0 la terminarea comenzii) status_comanda_modificat = 1 sql = "UPDATE comanda SET status=%s where id_comanda=%s;" val = ( status_comanda_modificat, id_comanda, ) mycursor.execute(sql, val) mydb.commit() else: # penultima comanda este in desfasurare si ultima inregistrare trebuie stearsa sql = "DELETE from comanda where id_comanda=%s;" val = (id_comanda, ) mycursor.execute(sql, val) mydb.commit() ###### ------ terminare secventa ------####### return redirect('meniu') return render_template('index.html', restaurante=restaurante)
def show(): # selectam toate detaliile despre restaurante mycursor = mydb.cursor() sql = "SELECT * FROM restaurant" #val = (id ) mycursor.execute(sql) result = mycursor.fetchall() # modificam detaliile despre restaurant if request.method == 'POST': if request.form.get('modifica_restaurant'): id_restaurant = request.form.get('id_restaurant') nume = request.form.get('nume') adresa = request.form.get('adresa') telefon = request.form.get('telefon') email = request.form.get('email') program = request.form.get('program') oras = request.form.get('oras') sql = "UPDATE restaurant SET nume=%s, adresa=%s, telefon=%s, email=%s, program=%s, oras=%s where id_restaurant=%s" val = ( nume, adresa, telefon, email, program, oras, id_restaurant, ) mycursor.execute(sql, val) mydb.commit() return redirect('restaurant_admin') # stergem un restaurant if request.method == 'POST': if request.form.get('sterge_restaurant'): id_restaurant = request.form.get('id_restaurant') sql = "DELETE FROM restaurant where id_restaurant=%s" val = (id_restaurant, ) mycursor.execute(sql, val) mydb.commit() return redirect('restaurant_admin') # adaugam un nou restaurant if request.method == 'POST': if request.form.get('adauga_restaurant'): nume = request.form.get('nume') adresa = request.form.get('adresa') telefon = request.form.get('telefon') email = request.form.get('email') program = request.form.get('program') oras = request.form.get('oras') sql = "INSERT INTO restaurant(nume, adresa, telefon, email, program, oras) VALUES(%s, %s, %s, %s, %s, %s)" val = ( nume, adresa, telefon, email, program, oras, ) mycursor.execute(sql, val) mydb.commit() return redirect('restaurant_admin') return render_template('restaurant_admin.html', result=result)
def show(): # selectam toate detaliile despre restaurante mycursor = mydb.cursor() #sql = "SELECT * FROM produs inner join restaurant on (id_restaurant=restaurant_id_restaurant)" sql = "SELECT * FROM produs;" #val = (id ) mycursor.execute(sql) result = mycursor.fetchall() # selectam toate restaurantele mycursor = mydb.cursor() sql = "SELECT * FROM restaurant" #val = (id ) mycursor.execute(sql) restaurante = mycursor.fetchall() # for res in result: # print(res) # print(result[0][0]) # print(result[0][1]) # print(result[0][2]) # print(result[0][3]) # print(result[0][4]) # print(result[0][5]) # print(result[0][6]) # modificam detaliile despre restaurant if request.method == 'POST': if request.form.get('modifica_produs'): id_produs = request.form.get('id_produs') denumire = request.form.get('denumire') ingrediente = request.form.get('ingrediente') pret = request.form.get('pret') gramaj = request.form.get('gramaj') tip = request.form.get('tip') stoc = request.form.get('stoc') oras_restaurant_id = request.form.get('oras_restaurant_id') sql = "UPDATE produs SET denumire=%s, ingrediente=%s, pret=%s, gramaj=%s, tip=%s, stoc=%s, restaurant_id_restaurant=%s where id_produs=%s" val = ( denumire, ingrediente, pret, gramaj, tip, stoc, oras_restaurant_id, id_produs, ) mycursor.execute(sql, val) mydb.commit() return redirect('restaurant_produse') # stergem un restaurant if request.method == 'POST': if request.form.get('sterge_produs'): id_produs = request.form.get('id_produs') print("das ", id_produs) sql = "DELETE FROM produs where id_produs=%s" val = (id_produs, ) mycursor.execute(sql, val) mydb.commit() return redirect('restaurant_produse') # adaugam un nou produs if request.method == 'POST': if request.form.get('adauga_produs'): denumire = request.form.get('denumire') ingrediente = request.form.get('ingrediente') pret = request.form.get('pret') gramaj = request.form.get('gramaj') tip = request.form.get('tip') stoc = request.form.get('stoc') oras_restaurant_id = request.form.get('oras_restaurant_id') sql = "INSERT INTO produs(denumire, ingrediente, pret, gramaj, tip, stoc, restaurant_id_restaurant) VALUES(%s, %s, %s, %s, %s, %s, %s)" val = ( denumire, ingrediente, pret, gramaj, tip, stoc, oras_restaurant_id, ) mycursor.execute(sql, val) mydb.commit() return redirect('restaurant_produse') return render_template('restaurant_produse.html', result=result, restaurante=restaurante)