Fix codice a barre + fix fornitore + fix codice alternativo
This commit is contained in:
0
utils/__init__.py
Normal file
0
utils/__init__.py
Normal file
23
utils/connection.py
Normal file
23
utils/connection.py
Normal file
@ -0,0 +1,23 @@
|
||||
import mysql.connector
|
||||
from mysql.connector import Error
|
||||
|
||||
def create_connection(host_name, user_name, user_password, db_name,port):
|
||||
connection = None
|
||||
try:
|
||||
connection = mysql.connector.connect(
|
||||
host=host_name,
|
||||
user=user_name,
|
||||
password=user_password,
|
||||
database=db_name,
|
||||
port=port,
|
||||
ssl_disabled=True
|
||||
)
|
||||
print("Connessione al database riuscita!")
|
||||
except Error as e:
|
||||
print(f"Errore: {e}")
|
||||
return connection
|
||||
|
||||
def close_connection(connection):
|
||||
if connection is not None and connection.is_connected():
|
||||
connection.close()
|
||||
print("Connessione al database chiusa.")
|
||||
90
utils/insert.py
Normal file
90
utils/insert.py
Normal file
@ -0,0 +1,90 @@
|
||||
from mysql.connector import Error
|
||||
import datetime
|
||||
|
||||
today = datetime.date.today()
|
||||
formatted_date = today.strftime("%Y-%m-%d")
|
||||
|
||||
data_str = "2999-12-31"
|
||||
data_fine = datetime.datetime.strptime(data_str, "%Y-%m-%d").date()
|
||||
|
||||
tla = 1
|
||||
|
||||
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()
|
||||
40
utils/search.py
Normal file
40
utils/search.py
Normal file
@ -0,0 +1,40 @@
|
||||
|
||||
|
||||
def search_article(connection, codice, listino):
|
||||
cursor_1 = connection.cursor(buffered=True)
|
||||
cursor_2 = connection.cursor(buffered=True)
|
||||
query_executed_cursor_2 = False # Variabile per controllare se la query è stata eseguita
|
||||
try:
|
||||
query = "SELECT codice FROM art WHERE codice = %s"
|
||||
cursor_1.execute(query, (codice,))
|
||||
result_1 = cursor_1.fetchone()
|
||||
|
||||
if result_1: # se l'articolo esiste
|
||||
query_lsv = "SELECT TLV_CODICE FROM lsv WHERE ART_CODICE = %s AND TLV_CODICE = %s"
|
||||
cursor_2.execute(query_lsv, (codice, listino))
|
||||
result_2 = cursor_2.fetchone()
|
||||
query_executed_cursor_2 = True
|
||||
|
||||
if result_2:
|
||||
print('codice listino trovato')
|
||||
return True
|
||||
else:
|
||||
print('codice listino non trovato')
|
||||
return 'not code art'
|
||||
else:
|
||||
print('codice non esiste')
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"Errore durante la ricerca: {e}")
|
||||
return None
|
||||
|
||||
finally:
|
||||
|
||||
if cursor_1:
|
||||
cursor_1.close()
|
||||
if cursor_2 and query_executed_cursor_2:
|
||||
cursor_2.fetchall()
|
||||
cursor_2.close()
|
||||
|
||||
|
||||
134
utils/update.py
Normal file
134
utils/update.py
Normal file
@ -0,0 +1,134 @@
|
||||
|
||||
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
|
||||
|
||||
|
||||
prezzo_netto = (prezzo * percentuale_totale) / 100
|
||||
print(prezzo_netto)
|
||||
ris = prezzo_netto + (prezzo_netto * ricarica) / 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()
|
||||
12
utils/upload.py
Normal file
12
utils/upload.py
Normal file
@ -0,0 +1,12 @@
|
||||
import xlsxwriter
|
||||
import tkinter as tk
|
||||
from tkinter import filedialog
|
||||
|
||||
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
|
||||
36
utils/write.py
Normal file
36
utils/write.py
Normal file
@ -0,0 +1,36 @@
|
||||
|
||||
import xlsxwriter
|
||||
import tkinter as tk
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
|
||||
def write_excel(value_update):
|
||||
today = datetime.now().strftime('%d-%m-%Y_%H-%M')
|
||||
filename = f'Articoli_Modificati{today}.xlsx'
|
||||
workbook = xlsxwriter.Workbook(filename)
|
||||
worksheet = workbook.add_worksheet()
|
||||
|
||||
worksheet.write('A1', 'CODICE (ART_CODICE)')
|
||||
worksheet.write('B1', 'COSTO (PREZZO)')
|
||||
worksheet.write('C1', 'CODICE LISTINO (TLV/TLA_CODICE)')
|
||||
worksheet.write('D1', 'SC1 (TSM_CODICE)')
|
||||
worksheet.write('E1', 'RICARICA1 (TRL_CODICE)')
|
||||
worksheet.write('F1', 'CODICE BARRE')
|
||||
worksheet.write('G1', 'CODICE ALTERNATIVO')
|
||||
worksheet.write('H1', 'TSM_CODICE_LSV')
|
||||
worksheet.write('I1', 'TSA_CODICE')
|
||||
worksheet.write('J1', 'FORNITORE')
|
||||
|
||||
for row_index, row_data in enumerate(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()
|
||||
36
utils/write_excel_insert.py
Normal file
36
utils/write_excel_insert.py
Normal file
@ -0,0 +1,36 @@
|
||||
|
||||
import xlsxwriter
|
||||
import tkinter as tk
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
|
||||
def write_excel_insert(value_insert):
|
||||
today = datetime.now().strftime('%d-%m-%Y_%H-%M')
|
||||
filename = f'Articoli_Inseriti{today}.xlsx'
|
||||
workbook = xlsxwriter.Workbook(filename)
|
||||
worksheet = workbook.add_worksheet()
|
||||
|
||||
worksheet.write('A1', 'CODICE (ART_CODICE)')
|
||||
worksheet.write('B1', 'DESCRIZIONE')
|
||||
worksheet.write('C1', 'UM')
|
||||
worksheet.write('D1', 'COSTO')
|
||||
worksheet.write('E1', 'SC1')
|
||||
worksheet.write('F1', 'SC2')
|
||||
worksheet.write('G1', 'RICARICA')
|
||||
worksheet.write('H1', 'CODICE_ALTERNATIVO')
|
||||
worksheet.write('I1', 'CODICE_BARRE')
|
||||
worksheet.write('L1', 'TSA_CODICE')
|
||||
worksheet.write('M1', 'FORNITORE')
|
||||
|
||||
|
||||
for row_index, row_data in enumerate(value_insert):
|
||||
|
||||
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()
|
||||
Reference in New Issue
Block a user