diff --git a/.~lock.TEST.xlsx# b/.~lock.TEST.xlsx# deleted file mode 100644 index 19bc168..0000000 --- a/.~lock.TEST.xlsx# +++ /dev/null @@ -1 +0,0 @@ -,pc-sviluppo1,pcsviluppo1,10.12.2024 10:17,file:///home/pc-sviluppo1/.config/libreoffice/4; \ No newline at end of file diff --git a/Articoli_Inseriti10-12-2024_09-27.xlsx b/Articoli_Inseriti10-12-2024_09-27.xlsx deleted file mode 100644 index 1c82592..0000000 Binary files a/Articoli_Inseriti10-12-2024_09-27.xlsx and /dev/null differ diff --git a/TEST.xlsx b/TEST.xlsx deleted file mode 100644 index d14f19a..0000000 Binary files a/TEST.xlsx and /dev/null differ diff --git a/__pycache__/connection.cpython-310.pyc b/__pycache__/connection.cpython-310.pyc deleted file mode 100644 index da63a4c..0000000 Binary files a/__pycache__/connection.cpython-310.pyc and /dev/null differ diff --git a/__pycache__/insert.cpython-310.pyc b/__pycache__/insert.cpython-310.pyc deleted file mode 100644 index 177eb66..0000000 Binary files a/__pycache__/insert.cpython-310.pyc and /dev/null differ diff --git a/__pycache__/search.cpython-310.pyc b/__pycache__/search.cpython-310.pyc deleted file mode 100644 index b7ff92d..0000000 Binary files a/__pycache__/search.cpython-310.pyc and /dev/null differ diff --git a/__pycache__/update.cpython-310.pyc b/__pycache__/update.cpython-310.pyc deleted file mode 100644 index f2d0ad5..0000000 Binary files a/__pycache__/update.cpython-310.pyc and /dev/null differ diff --git a/__pycache__/write.cpython-310.pyc b/__pycache__/write.cpython-310.pyc deleted file mode 100644 index 32c317d..0000000 Binary files a/__pycache__/write.cpython-310.pyc and /dev/null differ diff --git a/__pycache__/write_excel_insert.cpython-310.pyc b/__pycache__/write_excel_insert.cpython-310.pyc deleted file mode 100644 index 4938d6a..0000000 Binary files a/__pycache__/write_excel_insert.cpython-310.pyc and /dev/null differ diff --git a/insert.py b/insert.py index 04e262d..04d2b7b 100644 --- a/insert.py +++ b/insert.py @@ -15,11 +15,13 @@ tla = 1 value_insert = [] def insert_records(connection,codice,descrizione,um,costo,sc1,sc2,ricarica,listino,codice_alternativo,codice_barre,art,tsa_codice): try: + print('tipo tsa_codice') + result = [] cursor = connection.cursor() if art == False: - query_art = "INSERT INTO art (codice,DESCRIZIONE1,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) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" - cursor.execute(query_art,(codice,descrizione,um,codice_alternativo,tsa_codice,'0','0','0','22','22','0','0','0','0','0','0')) + query_art = "INSERT INTO art (codice,DESCRIZIONE1,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) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" + cursor.execute(query_art,(codice,descrizione,um,codice_alternativo,tsa_codice,'0','0','0','22','22','0','0','0','0','0','0','0')) count = cursor.rowcount result.append(count) @@ -29,7 +31,6 @@ def insert_records(connection,codice,descrizione,um,costo,sc1,sc2,ricarica,listi result.append(count) if listino == 1: - print('listino รจ uno') query_lsv = "INSERT INTO lsv (ART_CODICE,DATA_FINE,DATA_INIZIO,PREZZO,TSM_CODICE,TRL_CODICE,TLV_CODICE) VALUES (%s,%s,%s,%s,%s,%s,%s)" cursor.execute(query_lsv,(codice,data_fine,formatted_date,costo,sc2,ricarica,listino)) count = cursor.rowcount diff --git a/main.py b/main.py index 3ff7c7e..a47b812 100644 --- a/main.py +++ b/main.py @@ -13,6 +13,7 @@ from update import update_records from insert import insert_records from write import write_excel from write_excel_insert import write_excel_insert +from upload import upload_excel host = "62.86.98.170" @@ -24,7 +25,8 @@ port = 3307 #creo la connessione al database conn = create_connection(host, user, password, database, port) #leggo il file excel -df = pd.read_excel('TEST.xlsx', usecols='A:N') +file_input = upload_excel() +df = pd.read_excel(file_input, usecols='A:N') #leggo le colonne del file excel for index, row in df.iterrows(): @@ -32,6 +34,7 @@ for index, row in df.iterrows(): descrizione = row['DESCRIZIONE'] um = row['UN'] costo = row['COSTO'] + if math.isnan(row['SC1']): sc1 = row['SC1'] @@ -68,10 +71,12 @@ for index, row in df.iterrows(): codice_alternativo = str(row['CODICE ALTERNATIVO']) prezzo = float(row['COSTO']) + if math.isnan(row['TSA_CODICE']): tsa_codice = row['TSA_CODICE'] else: tsa_codice = int(row['TSA_CODICE']) + if conn : if ricarica1 is not None and not math.isnan(ricarica1): @@ -95,7 +100,7 @@ for index, row in df.iterrows(): if value_update is not None: write_excel(value_update) else: ## se non esiste o non esiste con quel listino effettuo l'inserimento - costo = 0.00 + ##costo = 0.00 if descrizione is None : descrizione = ' ' if um is None: @@ -106,12 +111,12 @@ for index, row in df.iterrows(): sc2 = ' ' if math.isnan(ricarica): ricarica = ' ' - if codice_alternativo is None: + if not pd.isna(codice_alternativo): codice_alternativo = ' ' - if codice_barre is None: - codice_barre = ' ' + if not pd.isna(codice_barre): + codice_barre = '0000000000000' if math.isnan(tsa_codice): - tsa_codice = ' ' + tsa_codice = '0' value_insert = insert_records(conn,codice,descrizione,um,costo,sc1,sc2,ricarica,listino,codice_alternativo,codice_barre,art,tsa_codice) write_excel_insert(value_insert) diff --git a/update.py b/update.py index 1680fed..8d8f1c8 100644 --- a/update.py +++ b/update.py @@ -73,7 +73,6 @@ def update_records(connection,codice,prezzo,sc1,sc2,listino,ricarica,codice_barr if math.isnan(ricarica): ricarica = 0 - if math.isnan(codice_barre): codice_barre = 0 diff --git a/upload.py b/upload.py new file mode 100644 index 0000000..6f81614 --- /dev/null +++ b/upload.py @@ -0,0 +1,17 @@ +import pandas as pd +import mysql.connector +import math +import xlsxwriter +import tkinter as tk +from tkinter import filedialog,messagebox +from datetime import datetime +from mysql.connector import Error + +def upload_excel(): + # Crea una finestra di dialogo per selezionare il file + root = tk.Tk() + root.withdraw() # Nasconde la finestra principale + file_path = filedialog.askopenfilename(title="Seleziona un file Excel", + filetypes=[("Tutti i file","*.*")]) + excel_filename = r"{}".format(file_path) + return excel_filename \ No newline at end of file diff --git a/write.py b/write.py index 914e463..a499088 100644 --- a/write.py +++ b/write.py @@ -26,8 +26,10 @@ def write_excel(value_update): for col_index, value in enumerate(row_data): worksheet.write(row_index + 1, col_index, value) + root = tk.Tk() loading_label = tk.Label(root, text="") loading_label.pack(pady=20) loading_label.config(text="Aggiornamento in corso... Attendere...") + workbook.close() \ No newline at end of file