diff --git a/utils/connection.py b/connection.py similarity index 100% rename from utils/connection.py rename to connection.py diff --git a/utils/insert.py b/insert.py similarity index 60% rename from utils/insert.py rename to insert.py index 3ee58ee..944c705 100644 --- a/utils/insert.py +++ b/insert.py @@ -4,88 +4,6 @@ from datetime import datetime, date data_str = "2999-12-31" data_fine = datetime.strptime(data_str, "%Y-%m-%d").date() - - -# value_insert = [] -# def insert_records(connection,codice,descrizione,descrizione2,um,prezzo,sc1,sc2,ricarica,listino,codice_alternativo,codice_barre,art,tsa_codice,frn): -# try: -# -# cursor_select = connection.cursor() -# result = [] -# cursor = connection.cursor() -# if art == False: -# query_art = "INSERT INTO art (codice, DESCRIZIONE1,DESCRIZIONE2, TUM_CODICE, codice_alternativo, TSA_CODICE, TUB_CODICE, TCM_CODICE, TGM_CODICE, TIV_CODICE_VENDITE, TIV_CODICE_ACQUISTI, TCA_CODICE, TAQ_CODICE, TS3_CODICE, TP2_CODICE, TIN_CODICE, TAA_CODICE, TNI_CODICE,FRN_CODICE) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" -# cursor.execute(query_art,(codice, descrizione,descrizione2,um, codice_alternativo, tsa_codice,'0','0','0','22','22','0','0','0','0','0','0','0',frn)) -# -# count = cursor.rowcount -# result.append(count) -# -# -# query_bar = "INSERT INTO bar (ART_CODICE,CODICE_BARRE) VALUES (%s,%s)" -# cursor.execute(query_bar,(codice,codice_barre)) -# count = cursor.rowcount -# result.append(count) -# -# -# if listino == 1: -# -# select_percentuale_totale = "SELECT PERCENTUALE_TOTALE FROM tsm WHERE CODICE = %s" -# cursor_select.execute(select_percentuale_totale,(sc1, )) -# percentuale_totale = cursor_select.fetchone() -# -# percentuale_totale = percentuale_totale[0] -# percentuale_totale = float(percentuale_totale) -# -# prezzo_netto = (prezzo * percentuale_totale)/100 -# -# ris = prezzo_netto + (prezzo_netto*ricarica)/100 -# -# prezzo_lsv = ris + (ris*22)/100 -# -# query_lsv = "INSERT INTO lsv (ART_CODICE,DATA_FINE,DATA_INIZIO,TSM_CODICE,TRL_CODICE,TLV_CODICE,PREZZO) VALUES (%s,%s,%s,%s,%s,%s,%s)" -# cursor.execute(query_lsv,(codice,data_fine,formatted_date,sc2,ricarica,listino,prezzo_lsv)) -# count = cursor.rowcount -# result.append(count) -# -# query_lsa = "INSERT INTO lsa (ART_CODICE,TLA_CODICE,DATA_INIZIO,DATA_FINE,PREZZO,TSM_CODICE) VALUES (%s,%s,%s,%s,%s,%s)" -# cursor.execute(query_lsa,(codice,tla,formatted_date,data_fine,prezzo,sc1)) -# count = cursor.rowcount -# result.append(count) -# -# else : -# -# select_percentuale_totale = "SELECT PERCENTUALE_TOTALE FROM tsm WHERE CODICE = %s" -# cursor_select.execute(select_percentuale_totale,(sc1, )) -# percentuale_totale = cursor_select.fetchone() -# -# percentuale_totale = percentuale_totale[0] -# percentuale_totale = float(percentuale_totale) -# -# prezzo_netto = (prezzo * percentuale_totale)/100 -# -# ris = prezzo_netto + (prezzo_netto*ricarica)/100 -# prezzo_lsv = ris -# if listino == 4: -# prezzo_lsv = ris + (ris*22)/100 -# -# query_lsv = "INSERT INTO lsv (ART_CODICE,DATA_FINE,DATA_INIZIO,TSM_CODICE,TRL_CODICE,TLV_CODICE,PREZZO) VALUES (%s,%s,%s,%s,%s,%s,%s)" -# cursor.execute(query_lsv,(codice,data_fine,formatted_date,sc2,ricarica,listino,prezzo_lsv)) -# count = cursor.rowcount -# result.append(count) -# -# -# connection.commit() -# -# if any(val != 0 for val in result): -# row = [codice,descrizione,um,prezzo,sc1,sc2,ricarica,codice_alternativo,codice_barre,tsa_codice,frn] -# value_insert.append(row) -# return value_insert -# -# except Error as e: -# print(f"Errore durante l'inserimento: {e}") -# finally: -# cursor.close() - class bcolors: HEADER = '\033[95m' OKBLUE = '\033[94m' diff --git a/main.py b/main.py index 7796fbb..0179400 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,10 @@ import pandas as pd -from utils.connection import create_connection -from utils.search import search_article, search_barcode, search_lsa, search_lsv, search_um -from utils.update import update_article, update_lsa, update_lsv -from utils.insert import insert_barcode, insert_article, insert_listino_acquisto, insert_listino_vendita -from utils.write import write_excel -from utils.upload import upload_excel +from connection import create_connection +from search import search_article, search_barcode, search_lsa, search_lsv, search_um +from update import update_article, update_lsa, update_lsv +from insert import insert_barcode, insert_article, insert_listino_acquisto, insert_listino_vendita +from write import write_excel +from upload import upload_excel class bcolors: HEADER = '\033[95m' diff --git a/utils/search.py b/search.py similarity index 100% rename from utils/search.py rename to search.py diff --git a/update.py b/update.py new file mode 100644 index 0000000..cd8294a --- /dev/null +++ b/update.py @@ -0,0 +1,120 @@ + +from mysql.connector import Error +value_update = [] + +class bcolors: + HEADER = '\033[95m' + OKBLUE = '\033[94m' + OKCYAN = '\033[96m' + OKGREEN = '\033[92m' + WARNING = '\033[93m' + FAIL = '\033[91m' + ENDC = '\033[0m' + BOLD = '\033[1m' + UNDERLINE = '\033[4m' + + +def update_article(connection, codice_art, descrizione1, descrizione2, um, codice_alt, tsa_codice, frn_codice): + cursor_update = connection.cursor() + + try: + query_art = """ + UPDATE art + SET + CODICE_ALTERNATIVO = CASE WHEN %s != '' THEN %s ELSE CODICE_ALTERNATIVO END, + DESCRIZIONE1 = CASE WHEN %s != '' THEN %s ELSE DESCRIZIONE1 END, + DESCRIZIONE2 = CASE WHEN %s != '' THEN %s ELSE DESCRIZIONE2 END, + TUM_CODICE = CASE WHEN %s != '' THEN %s ELSE TUM_CODICE END, + TSA_CODICE = CASE WHEN %s != '' THEN %s ELSE TSA_CODICE END, + FRN_CODICE = CASE WHEN %s != '' THEN %s ELSE FRN_CODICE END + WHERE codice = %s + """ + cursor_update.execute(query_art, (codice_alt, codice_alt, descrizione1, descrizione1, descrizione2, descrizione2, um, um, tsa_codice, tsa_codice, frn_codice, frn_codice, codice_art)) + + if cursor_update.rowcount > 0: + return True + else: + return False + + except Error as e: + print(bcolors.FAIL+f"Errore durante l'aggiornamento: {e}") + finally: + cursor_update.close() + + + +def update_lsa(connection, id_lsa, prezzo): + cursor_update = connection.cursor() + try: + query_lsa = "UPDATE lsa SET PREZZO = %s WHERE ID = %s" + cursor_update.execute(query_lsa, (prezzo, id_lsa)) + + if cursor_update.rowcount > 0: + return True + else: + return False + + except Error as e: + print(bcolors.FAIL+f"Errore durante l'aggiornamento: {e}") + finally: + cursor_update.close() + + +def update_lsv(connection, id_lsv, prezzo, prezzo_pubblico, listino, sc1, sc2, ricarica): + cursor_update = connection.cursor() + cursor_select_sc1 = connection.cursor(buffered=True) + cursor_select_sc2 = connection.cursor(buffered=True) + cursor_select_ricarica = connection.cursor(buffered=True) + + try: + percentuale_totale_sc1 = percentuale_totale_sc2 = percentuale_ricarica = 0 + + if sc1: + select_sc1 = "SELECT PERCENTUALE_TOTALE FROM tsm WHERE CODICE = %s" + cursor_select_sc1.execute(select_sc1, (sc1,)) + result_sc1 = cursor_select_sc1.fetchone() + percentuale_totale_sc1 = float(result_sc1[0]) if result_sc1 else 0 + + if sc2: + select_sc2 = "SELECT PERCENTUALE_TOTALE FROM tsm WHERE CODICE = %s" + cursor_select_sc2.execute(select_sc2, (sc2,)) + result_sc2 = cursor_select_sc2.fetchone() + percentuale_totale_sc2 = float(result_sc2[0]) if result_sc2 else 0 + + if ricarica: + select_ricarica = "SELECT RICARICO FROM trl WHERE CODICE = %s" + cursor_select_ricarica.execute(select_ricarica, (ricarica,)) + result_ricarica = cursor_select_ricarica.fetchone() + percentuale_ricarica = float(result_ricarica[0]) if result_ricarica else 0 + + if ricarica != '0': + if percentuale_totale_sc1 != 0: + prezzo = prezzo * (percentuale_totale_sc1 / 100) + + if percentuale_ricarica != 0: + prezzo += prezzo * (percentuale_ricarica / 100) + + if percentuale_totale_sc2 != 0: + prezzo = prezzo * (percentuale_totale_sc2 / 100) + + if listino == '1' or listino == '4': + prezzo += prezzo * (22 / 100) + + if prezzo_pubblico != '' and listino == '1': + prezzo = prezzo_pubblico + + query_lsv = "UPDATE lsv SET PREZZO = %s, TRL_CODICE = %s WHERE ID = %s" + cursor_update.execute(query_lsv, (prezzo, ricarica, id_lsv)) + + if cursor_update.rowcount > 0: + return True + else: + return False + + else: + return False + + except Error as e: + print(bcolors.FAIL+f"Errore durante l'aggiornamento: {e}") + finally: + cursor_update.close() \ No newline at end of file diff --git a/utils/upload.py b/upload.py similarity index 100% rename from utils/upload.py rename to upload.py diff --git a/utils/__init__.py b/utils/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/utils/update.py b/utils/update.py deleted file mode 100644 index 96bc56c..0000000 --- a/utils/update.py +++ /dev/null @@ -1,253 +0,0 @@ - -from mysql.connector import Error -import pandas as pd -import math - -value_update = [] - -# def update_records(connection,codice,prezzo,sc1,sc2,listino,ricarica,codice_barre,codice_alternativo,tsa_codice,frn): -# -# cursor = connection.cursor() -# cursor_select = connection.cursor() -# -# try: -# result = [] -# -# if sc1 is not None and not math.isnan(sc1): -# query_lsa = "UPDATE lsa SET TSM_CODICE = %s WHERE ART_CODICE = %s AND TLA_CODICE = '1'" -# cursor.execute(query_lsa, (sc1, codice)) -# count = cursor.rowcount -# result.append(count) -# -# if sc2 is not None and not math.isnan(sc2): -# query_lsv_tsm = "UPDATE lsv SET TSM_CODICE = %s WHERE ART_CODICE = %s AND TLV_CODICE = %s" -# cursor.execute(query_lsv_tsm, (sc2, codice,listino)) -# count = cursor.rowcount -# result.append(count) -# -# if prezzo is not None and not math.isnan(prezzo): -# query_lsa = "UPDATE lsa SET PREZZO = %s WHERE ART_CODICE = %s AND TLA_CODICE = '1'" -# cursor.execute(query_lsa, (prezzo,codice)) -# count = cursor.rowcount -# result.append(count) -# -# if ricarica is not None and not math.isnan(ricarica): -# query_lsv = "UPDATE lsv SET TRL_CODICE = %s WHERE ART_CODICE = %s AND TLV_CODICE = %s" -# cursor.execute(query_lsv, (ricarica, codice,listino)) -# count = cursor.rowcount -# result.append(count) -# -# if len(codice_barre.strip()) > 0: -# query_bar = "UPDATE bar SET CODICE_BARRE = %s WHERE ART_CODICE = %s" -# cursor.execute(query_bar, (codice_barre, codice)) -# count = cursor.rowcount -# result.append(count) -# -# if len(codice_alternativo.strip()) > 0: -# query_alt = "UPDATE art SET CODICE_ALTERNATIVO = %s WHERE codice = %s" -# cursor.execute(query_alt, (codice_alternativo, codice)) -# count = cursor.rowcount -# result.append(count) -# -# if tsa_codice is not None and not math.isnan(tsa_codice): -# query_tsa = "UPDATE art SET TSA_CODICE = %s WHERE codice = %s" -# cursor.execute(query_tsa, (tsa_codice, codice)) -# count = cursor.rowcount -# result.append(count) -# -# if len(frn.strip()) > 0: -# query_art = "UPDATE art SET FRN_CODICE = %s WHERE codice = %s" -# cursor.execute(query_art, (frn, codice)) -# count = cursor.rowcount -# result.append(count) -# -# #parte nuova prezzo di lsv -# -# if sc1 is not None and not math.isnan(sc1) and prezzo is not None and not math.isnan(prezzo): -# select_percentuale_totale = "SELECT PERCENTUALE_TOTALE FROM tsm WHERE CODICE = %s LIMIT 1;" -# cursor_select.execute(select_percentuale_totale, (sc1,)) -# percentuale_totale = cursor_select.fetchall() -# -# -# if percentuale_totale: # Assicurati che ci sia un risultato -# percentuale_totale = percentuale_totale[0][0] # Accedi al primo elemento della tupla -# percentuale_totale = float(percentuale_totale) # Converti in float -# -# -# if ricarica != '0': -# prezzo_netto = (prezzo * percentuale_totale)/100 -# ris = prezzo_netto + (prezzo_netto*ricarica)/100 -# else: -# ris = prezzo - (prezzo*sc2)/100 -# #print(ris) -# prezzo_lsv = ris -# -# if listino == 1 or listino == 4: -# prezzo_lsv = ris + (ris * 22) / 100 -# print(prezzo_lsv) -# -# query_price = "UPDATE lsv SET PREZZO = %s WHERE ART_CODICE = %s AND TLV_CODICE = %s" -# cursor.execute(query_price, (prezzo_lsv, codice, listino)) -# -# -# -# connection.commit() -# -# if all(value == 0 for value in result): -# print(f"Record non aggiornati per ART_CODICE: {codice}") -# -# if math.isnan(prezzo): -# prezzo = 0 -# -# if math.isnan(listino): -# listino = 0 -# -# if math.isnan(sc1): -# sc1 = 0 -# -# if math.isnan(sc2): -# sc2 = 0 -# -# if math.isnan(ricarica): -# ricarica = 0 -# -# if math.isnan(codice_barre): -# codice_barre = 0 -# -# if pd.isna(codice_alternativo): -# codice_alternativo = 0 -# -# if math.isnan(tsa_codice): -# tsa_codice = 0 -# if math.isnan(frn): -# frn = 0 -# -# row = [codice,prezzo,listino,sc1,ricarica,codice_barre,codice_alternativo,sc2,tsa_codice,frn] -# value_update.append(row) -# return value_update -# -# else: -# print(f"Record aggiornati per ART_CODICE: {codice}") -# -# except Error as e: -# print(f"Errore durante l'aggiornamento: {e}") -# finally: -# cursor.close() -# cursor_select.close() - -class bcolors: - HEADER = '\033[95m' - OKBLUE = '\033[94m' - OKCYAN = '\033[96m' - OKGREEN = '\033[92m' - WARNING = '\033[93m' - FAIL = '\033[91m' - ENDC = '\033[0m' - BOLD = '\033[1m' - UNDERLINE = '\033[4m' - - -def update_article(connection, codice_art, descrizione1, descrizione2, um, codice_alt, tsa_codice, frn_codice): - cursor_update = connection.cursor() - - try: - query_art = """ - UPDATE art - SET - CODICE_ALTERNATIVO = CASE WHEN %s != '' THEN %s ELSE CODICE_ALTERNATIVO END, - DESCRIZIONE1 = CASE WHEN %s != '' THEN %s ELSE DESCRIZIONE1 END, - DESCRIZIONE2 = CASE WHEN %s != '' THEN %s ELSE DESCRIZIONE2 END, - TUM_CODICE = CASE WHEN %s != '' THEN %s ELSE TUM_CODICE END, - TSA_CODICE = CASE WHEN %s != '' THEN %s ELSE TSA_CODICE END, - FRN_CODICE = CASE WHEN %s != '' THEN %s ELSE FRN_CODICE END - WHERE codice = %s - """ - cursor_update.execute(query_art, (codice_alt, codice_alt, descrizione1, descrizione1, descrizione2, descrizione2, um, um, tsa_codice, tsa_codice, frn_codice, frn_codice, codice_art)) - - if cursor_update.rowcount > 0: - return True - else: - return False - - except Error as e: - print(bcolors.FAIL+f"Errore durante l'aggiornamento: {e}") - finally: - cursor_update.close() - - - -def update_lsa(connection, id_lsa, prezzo): - cursor_update = connection.cursor() - try: - query_lsa = "UPDATE lsa SET PREZZO = %s WHERE ID = %s" - cursor_update.execute(query_lsa, (prezzo, id_lsa)) - - if cursor_update.rowcount > 0: - return True - else: - return False - - except Error as e: - print(bcolors.FAIL+f"Errore durante l'aggiornamento: {e}") - finally: - cursor_update.close() - - -def update_lsv(connection, id_lsv, prezzo, prezzo_pubblico, listino, sc1, sc2, ricarica): - cursor_update = connection.cursor() - cursor_select_sc1 = connection.cursor(buffered=True) - cursor_select_sc2 = connection.cursor(buffered=True) - cursor_select_ricarica = connection.cursor(buffered=True) - - try: - percentuale_totale_sc1 = percentuale_totale_sc2 = percentuale_ricarica = 0 - - if sc1: - select_sc1 = "SELECT PERCENTUALE_TOTALE FROM tsm WHERE CODICE = %s" - cursor_select_sc1.execute(select_sc1, (sc1,)) - result_sc1 = cursor_select_sc1.fetchone() - percentuale_totale_sc1 = float(result_sc1[0]) if result_sc1 else 0 - - if sc2: - select_sc2 = "SELECT PERCENTUALE_TOTALE FROM tsm WHERE CODICE = %s" - cursor_select_sc2.execute(select_sc2, (sc2,)) - result_sc2 = cursor_select_sc2.fetchone() - percentuale_totale_sc2 = float(result_sc2[0]) if result_sc2 else 0 - - if ricarica: - select_ricarica = "SELECT RICARICO FROM trl WHERE CODICE = %s" - cursor_select_ricarica.execute(select_ricarica, (ricarica,)) - result_ricarica = cursor_select_ricarica.fetchone() - percentuale_ricarica = float(result_ricarica[0]) if result_ricarica else 0 - - if ricarica != '0': - if percentuale_totale_sc1 != 0: - prezzo = prezzo * (percentuale_totale_sc1 / 100) - - if percentuale_ricarica != 0: - prezzo += prezzo * (percentuale_ricarica / 100) - - if percentuale_totale_sc2 != 0: - prezzo = prezzo * (percentuale_totale_sc2 / 100) - - if listino == '1' or listino == '4': - prezzo += prezzo * (22 / 100) - - if prezzo_pubblico != '' and listino == '1': - prezzo = prezzo_pubblico - - query_lsv = "UPDATE lsv SET PREZZO = %s, TRL_CODICE = %s WHERE ID = %s" - cursor_update.execute(query_lsv, (prezzo, ricarica, id_lsv)) - - if cursor_update.rowcount > 0: - return True - else: - return False - - else: - return False - - except Error as e: - print(bcolors.FAIL+f"Errore durante l'aggiornamento: {e}") - finally: - cursor_update.close() \ No newline at end of file diff --git a/utils/write.py b/write.py similarity index 69% rename from utils/write.py rename to write.py index c4f1cd8..d09d4b3 100644 --- a/utils/write.py +++ b/write.py @@ -31,24 +31,22 @@ def write_excel(value_update): if col_index == 4: for listino, lsv in row_data[value].items(): - match lsv[0]: - case 0: - worksheet.write(row_index + 1, col_index, str(lsv[1]), error_format) - case 1: - worksheet.write(row_index + 1, col_index, str(lsv[1]), created_format) - case 2: - worksheet.write(row_index + 1, col_index, str(lsv[1]), updated_format) + if lsv[0]==0: + worksheet.write(row_index + 1, col_index, str(lsv[1]), error_format) + elif lsv[0]==1: + worksheet.write(row_index + 1, col_index, str(lsv[1]), created_format) + elif lsv[0]==2: + worksheet.write(row_index + 1, col_index, str(lsv[1]), updated_format) col_index+=1 else: - match row_data[value][0]: - case 0: - worksheet.write(row_index + 1, col_index, str(row_data[value][1]), error_format) - case 1: - worksheet.write(row_index + 1, col_index, str(row_data[value][1]), created_format) - case 2: - worksheet.write(row_index + 1, col_index, str(row_data[value][1]), updated_format) + if row_data[value][0]==0: + worksheet.write(row_index + 1, col_index, str(row_data[value][1]), error_format) + elif row_data[value][0]==1: + worksheet.write(row_index + 1, col_index, str(row_data[value][1]), created_format) + elif row_data[value][0]==2: + worksheet.write(row_index + 1, col_index, str(row_data[value][1]), updated_format) + - root = tk.Tk() loading_label = tk.Label(root, text="") loading_label.pack(pady=20) diff --git a/utils/write_excel_insert.py b/write_excel_insert.py similarity index 100% rename from utils/write_excel_insert.py rename to write_excel_insert.py