Refactoring codice
This commit is contained in:
236
main.py
236
main.py
@ -1,14 +1,21 @@
|
||||
import pandas as pd
|
||||
import math
|
||||
from utils.connection import create_connection
|
||||
from utils.connection import close_connection
|
||||
from utils.search import search_article
|
||||
from utils.update import update_records
|
||||
from utils.insert import insert_records
|
||||
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.write_excel_insert import write_excel_insert
|
||||
from utils.upload import upload_excel
|
||||
|
||||
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'
|
||||
|
||||
host = "62.86.98.170"
|
||||
user = "root"
|
||||
@ -17,118 +24,143 @@ database = "arc_rumo"
|
||||
port = 3307
|
||||
|
||||
#creo la connessione al database
|
||||
conn = create_connection(host, user, password, database, port)
|
||||
connection = create_connection(host, user, password, database, port)
|
||||
#leggo il file excel
|
||||
file_input = upload_excel()
|
||||
df = pd.read_excel(file_input, usecols='A:O', dtype={'FORNITORE': str, 'CODICE ALTERNATIVO': str})
|
||||
df = pd.read_excel(file_input, usecols='A:O', dtype={'CODICE': str, 'DESCRIZIONE': str, 'UN':str, 'SC1': str, 'RICARICA1': str, 'RICARICA2': str, 'RICARICA3': str, 'RICARICA4': str, 'SC2': str, 'CODICE_BARRE': str, 'CODICE ALTERNATIVO': str, 'GRUPPO STATISTICO': str, 'FORNITORE': str,})
|
||||
|
||||
updated_rows = []
|
||||
i=0
|
||||
#leggo le colonne del file excel
|
||||
for index, row in df.iterrows():
|
||||
codice = row['CODICE']
|
||||
descrizione = row['DESCRIZIONE']
|
||||
um = row['UN']
|
||||
costo = row['COSTO']
|
||||
|
||||
|
||||
if math.isnan(row['SC1']):
|
||||
sc1 = row['SC1']
|
||||
else:
|
||||
sc1 = int(row['SC1']) ## tsm_codice per la tabella lsa
|
||||
codice_articolo = '' if pd.isna(row['CODICE']) else row['CODICE']
|
||||
descrizione = '' if pd.isna(row['DESCRIZIONE']) else row['DESCRIZIONE']
|
||||
um = '' if pd.isna(row['UN']) else row['UN']
|
||||
costo = '' if pd.isna(row['COSTO']) else float(row['COSTO'])
|
||||
sc1 = '' if pd.isna(row['SC1']) else row['SC1']
|
||||
|
||||
if math.isnan(row['SC2']):
|
||||
sc2 = row['SC2']
|
||||
else :
|
||||
sc2 = int(row['SC2'])
|
||||
ricarica = {"1" : "", "2" : "", "4" : ""}
|
||||
|
||||
if math.isnan(row['RICARICA1']):
|
||||
ricarica1 = row['RICARICA1']
|
||||
else:
|
||||
ricarica1 = int(row['RICARICA1']) ## trl_codice per codice listino 1
|
||||
if not pd.isna(row['RICARICA1']):
|
||||
ricarica['1'] = row['RICARICA1']
|
||||
if not pd.isna(row['RICARICA2']):
|
||||
ricarica['2'] = row['RICARICA2']
|
||||
#if not pd.isna(row['RICARICA3']):
|
||||
# ricarica['3'] = row['RICARICA3']
|
||||
if not pd.isna(row['RICARICA4']):
|
||||
ricarica['4'] = row['RICARICA4']
|
||||
|
||||
if math.isnan(row['RICARICA2']):
|
||||
ricarica2 = row['RICARICA2']
|
||||
else:
|
||||
ricarica2 = int(row['RICARICA2']) ## trl_codice per codice listino 2
|
||||
|
||||
if math.isnan(row['RICARICA3']):
|
||||
ricarica3 = row['RICARICA3']
|
||||
else:
|
||||
ricarica3 = int(row['RICARICA3']) ## trl_codice per codice listino 3
|
||||
sc2 = '' if pd.isna(row['SC2']) else row['SC2']
|
||||
prezzo_pubblico = '' if pd.isna(row['PREZZO PUBBLICO']) else float(row['PREZZO PUBBLICO'])
|
||||
codice_barre = '' if pd.isna(row['CODICE_BARRE']) else row['CODICE_BARRE']
|
||||
codice_alternativo = '' if pd.isna(row['CODICE ALTERNATIVO']) else row['CODICE ALTERNATIVO']
|
||||
tsa_codice = '' if pd.isna(row['GRUPPO STATISTICO']) else row['GRUPPO STATISTICO']
|
||||
frn_codice = '' if pd.isna(row['FORNITORE']) else row['FORNITORE']
|
||||
|
||||
|
||||
if math.isnan(row['RICARICA4']):
|
||||
ricarica4 = row['RICARICA4']
|
||||
else:
|
||||
ricarica4 = int(row['RICARICA4']) ## trl_codice per codice listino 4
|
||||
|
||||
codice_barre = str(row['CODICE_BARRE'])
|
||||
codice_alternativo = str(row['CODICE ALTERNATIVO'])
|
||||
prezzo = float(row['COSTO'])
|
||||
|
||||
|
||||
if math.isnan(row['GRUPPO STATISTICO']):
|
||||
tsa_codice = row['GRUPPO STATISTICO']
|
||||
else:
|
||||
tsa_codice = int(row['GRUPPO STATISTICO'])
|
||||
|
||||
frn = str(row['FORNITORE'])
|
||||
|
||||
descrizione2 = ' '
|
||||
descrizione2 = ''
|
||||
## se decrizione supera 40
|
||||
len_descrizione = len(descrizione)
|
||||
if len_descrizione > 40 :
|
||||
if len(descrizione) > 40 :
|
||||
descrizione1 = descrizione [: 40]
|
||||
#print(descrizione1)
|
||||
descrizione2 = descrizione [40 :]
|
||||
#print(descrizione2)
|
||||
descrizione = descrizione1
|
||||
|
||||
if conn :
|
||||
if ricarica1 is not None and not math.isnan(ricarica1):
|
||||
listino = 1
|
||||
ricarica = ricarica1
|
||||
elif ricarica2 is not None and not math.isnan(ricarica2):
|
||||
listino = 2
|
||||
ricarica = ricarica2
|
||||
elif ricarica3 is not None and not math.isnan(ricarica3):
|
||||
listino = 3
|
||||
ricarica = ricarica3
|
||||
elif ricarica4 is not None and not math.isnan(ricarica4):
|
||||
listino = 4
|
||||
ricarica = ricarica4
|
||||
|
||||
art = search_article(conn,codice,listino) #cerco codice articolo
|
||||
updated_rows.append({'ART_CODICE': [0, codice_articolo], 'TUM_CODICE': [0, um], 'CODICE_BARRE': [0, codice_barre], 'LSA_ID': [0, ''], 'LSV_ID': {'1': [0, ''], '2': [0, ''], '4': [0, '']}})
|
||||
|
||||
if art == True : ## se l'atricolo esiste eseguo l'update dei valori
|
||||
value_update = update_records(conn,codice,prezzo,sc1,sc2,listino,ricarica,codice_barre,codice_alternativo,tsa_codice,frn)
|
||||
|
||||
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
|
||||
if descrizione is None :
|
||||
descrizione = ' '
|
||||
if um is None:
|
||||
um = ' '
|
||||
if math.isnan(sc1):
|
||||
sc1 = ' '
|
||||
if math.isnan(sc2):
|
||||
sc2 = ' '
|
||||
if math.isnan(ricarica):
|
||||
ricarica = ' '
|
||||
if pd.isna(codice_alternativo):
|
||||
codice_alternativo = ' '
|
||||
if pd.isna(codice_barre):
|
||||
codice_barre = '0000000000000'
|
||||
if math.isnan(tsa_codice):
|
||||
tsa_codice = '0'
|
||||
if pd.isna(frn):
|
||||
frn = ' '
|
||||
|
||||
value_insert = insert_records(conn,codice,descrizione,descrizione2,um,prezzo,sc1,sc2,ricarica,listino,codice_alternativo,codice_barre,art,tsa_codice,frn)
|
||||
write_excel_insert(value_insert)
|
||||
|
||||
if conn :
|
||||
conn.close()
|
||||
if connection :
|
||||
|
||||
if search_um(connection, um) or um == '':
|
||||
updated_rows[i]['TUM_CODICE'] = [2, um]
|
||||
|
||||
if codice_articolo != '' and descrizione != '':
|
||||
if search_article(connection, codice_articolo):
|
||||
print(bcolors.OKGREEN+'Articolo trovato: '+codice_articolo, end =" -> ")
|
||||
|
||||
if update_article(connection, codice_articolo, descrizione, descrizione2, um, codice_alternativo, tsa_codice, frn_codice):
|
||||
print(bcolors.OKGREEN + 'Aggiornato')
|
||||
updated_rows[i]['ART_CODICE'] = [2, codice_articolo]
|
||||
else:
|
||||
print(bcolors.FAIL + "Aggiornamento non riuscito")
|
||||
updated_rows[i]['ART_CODICE'] = [0, codice_articolo]
|
||||
else:
|
||||
print(bcolors.WARNING+'Articolo non trovato: '+codice_articolo, end =" -> ")
|
||||
if insert_article(connection, codice_articolo, descrizione, descrizione2, um, codice_alternativo, tsa_codice, frn_codice):
|
||||
print(bcolors.OKGREEN + 'Inserito')
|
||||
updated_rows[i]['ART_CODICE'] = [1, codice_articolo]
|
||||
else:
|
||||
print(bcolors.FAIL + "Inserimento non riuscito")
|
||||
updated_rows[i]['ART_CODICE'] = [0, codice_articolo]
|
||||
continue
|
||||
else:
|
||||
continue
|
||||
else:
|
||||
print(bcolors.FAIL + 'Unità di misura non presente nel gestionale: ' + um)
|
||||
updated_rows[i]['ART_CODICE'] = [0, codice_articolo]
|
||||
updated_rows[i]['TUM_CODICE'] = [0, um]
|
||||
continue
|
||||
|
||||
|
||||
if codice_barre != '':
|
||||
if not search_barcode(connection, codice_articolo, codice_barre):
|
||||
print(bcolors.WARNING + 'Barcode non trovato: ' + codice_barre, end=" -> ")
|
||||
if insert_barcode(connection, codice_articolo, codice_barre):
|
||||
print(bcolors.OKGREEN + 'Inserito')
|
||||
updated_rows[i]['CODICE_BARRE'] = [1, codice_barre]
|
||||
else:
|
||||
print(bcolors.FAIL + "Inserimento non riuscito")
|
||||
updated_rows[i]['CODICE_BARRE'] = [0, codice_barre]
|
||||
else:
|
||||
print(bcolors.OKGREEN + 'Barcode già inserito: ' + codice_barre)
|
||||
updated_rows[i]['CODICE_BARRE'] = [2, codice_barre]
|
||||
|
||||
if costo != '':
|
||||
id_lsa = search_lsa(connection, codice_articolo, sc1)
|
||||
if id_lsa:
|
||||
print(bcolors.OKGREEN + 'Listino di acquisto trovato', end=" -> ")
|
||||
if update_lsa(connection, id_lsa[0], costo):
|
||||
print(bcolors.OKGREEN + 'Aggiornato')
|
||||
updated_rows[i]['LSA_ID'] = [2, id_lsa[0]]
|
||||
else:
|
||||
print(bcolors.FAIL + "Aggiornamento non riuscito")
|
||||
updated_rows[i]['LSA_ID'] = [0, id_lsa[0]]
|
||||
else:
|
||||
print(bcolors.WARNING + 'Listino di acquisto non trovato', end=" -> ")
|
||||
id_lsa = insert_listino_acquisto(connection, codice_articolo, costo, sc1)
|
||||
if id_lsa:
|
||||
print(bcolors.OKGREEN + 'Inserito')
|
||||
updated_rows[i]['LSA_ID'] = [1, id_lsa]
|
||||
else:
|
||||
print(bcolors.FAIL + "Inserimento non riuscito")
|
||||
|
||||
|
||||
for key, value in ricarica.items():
|
||||
id_lsv = search_lsv(connection, codice_articolo, value, key)
|
||||
if id_lsv:
|
||||
print(bcolors.OKGREEN + 'Listino di vendita trovato', end=" -> ")
|
||||
if update_lsv(connection, id_lsv[0], costo, prezzo_pubblico, key, sc1, sc2, value):
|
||||
print(bcolors.OKGREEN + 'Aggiornato')
|
||||
updated_rows[i]['LSV_ID'][key] = [2, id_lsv[0]]
|
||||
else:
|
||||
print(bcolors.FAIL + "Aggiornamento non riuscito")
|
||||
updated_rows[i]['LSV_ID'][key] = [0, id_lsv[0]]
|
||||
else:
|
||||
if value != '':
|
||||
print(bcolors.WARNING + 'Listino di vendita non trovato', end=" -> ")
|
||||
id_lsv = insert_listino_vendita(connection, codice_articolo, costo, prezzo_pubblico, key, sc1, sc2, value)
|
||||
if id_lsv:
|
||||
print(bcolors.OKGREEN + 'Inserito')
|
||||
updated_rows[i]['LSV_ID'][key] = [1, id_lsv]
|
||||
else:
|
||||
print(bcolors.FAIL + "Inserimento non riuscito")
|
||||
|
||||
connection.commit()
|
||||
|
||||
i += 1
|
||||
|
||||
write_excel(updated_rows)
|
||||
|
||||
if connection :
|
||||
connection.close()
|
||||
|
||||
|
||||
|
||||
304
utils/insert.py
304
utils/insert.py
@ -1,90 +1,236 @@
|
||||
from mysql.connector import Error
|
||||
import datetime
|
||||
|
||||
today = datetime.date.today()
|
||||
formatted_date = today.strftime("%Y-%m-%d")
|
||||
from datetime import datetime, date
|
||||
|
||||
data_str = "2999-12-31"
|
||||
data_fine = datetime.datetime.strptime(data_str, "%Y-%m-%d").date()
|
||||
data_fine = 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):
|
||||
|
||||
# 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'
|
||||
OKCYAN = '\033[96m'
|
||||
OKGREEN = '\033[92m'
|
||||
WARNING = '\033[93m'
|
||||
FAIL = '\033[91m'
|
||||
ENDC = '\033[0m'
|
||||
BOLD = '\033[1m'
|
||||
UNDERLINE = '\033[4m'
|
||||
|
||||
|
||||
def insert_article(connection, codice_articolo, descrizione, descrizione2, um, codice_alternativo, tsa_codice, frn_codice):
|
||||
cursor_insert = connection.cursor()
|
||||
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)
|
||||
|
||||
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,
|
||||
CASE WHEN %s != '' THEN %s ELSE NULL END,
|
||||
%s,
|
||||
CASE WHEN %s != '' THEN %s ELSE NULL END,
|
||||
%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,
|
||||
CASE WHEN %s != '' THEN %s ELSE NULL END
|
||||
)
|
||||
"""
|
||||
cursor_insert.execute(query_art, (
|
||||
codice_articolo, descrizione, descrizione2, um, um, codice_alternativo, tsa_codice, tsa_codice, '0', '0', '0', '22',
|
||||
'22', '0', '0', '0',
|
||||
'0', '0', '0', '0', frn_codice, frn_codice))
|
||||
|
||||
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
|
||||
if cursor_insert.rowcount > 0:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
except Error as e:
|
||||
print(f"Errore durante l'inserimento: {e}")
|
||||
print(bcolors.FAIL+f"Errore durante l'inserimento: {e}")
|
||||
finally:
|
||||
cursor.close()
|
||||
cursor_insert.close()
|
||||
|
||||
def insert_barcode(connection,codice,codice_barre):
|
||||
cursor_insert = connection.cursor()
|
||||
try:
|
||||
query_bar = "INSERT INTO bar (ART_CODICE, CODICE_BARRE) VALUES (%s,%s)"
|
||||
cursor_insert.execute(query_bar, (codice, codice_barre))
|
||||
|
||||
if cursor_insert.rowcount > 0:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
except Error as e:
|
||||
print(bcolors.FAIL+f"Errore durante l'inserimento: {e}")
|
||||
finally:
|
||||
cursor_insert.close()
|
||||
|
||||
|
||||
def insert_listino_acquisto(connection,codice,prezzo,sc1):
|
||||
cursor_insert = connection.cursor()
|
||||
try:
|
||||
query_lsa = """
|
||||
INSERT INTO lsa (ART_CODICE, TLA_CODICE, DATA_INIZIO, DATA_FINE, PREZZO, TSM_CODICE)
|
||||
VALUES (%s,%s,%s,%s,%s,
|
||||
CASE WHEN %s != '' THEN %s ELSE NULL END
|
||||
)
|
||||
"""
|
||||
cursor_insert.execute(query_lsa, (codice, '1', date.today().strftime("%Y-%m-%d"), data_fine, prezzo, sc1, sc1))
|
||||
|
||||
if cursor_insert.rowcount > 0:
|
||||
return cursor_insert.lastrowid
|
||||
else:
|
||||
return False
|
||||
|
||||
except Error as e:
|
||||
print(bcolors.FAIL+f"Errore durante l'inserimento: {e}")
|
||||
finally:
|
||||
cursor_insert.close()
|
||||
|
||||
|
||||
def insert_listino_vendita(connection,codice,prezzo,prezzo_pubblico,listino,sc1,sc2,ricarica):
|
||||
cursor_insert = 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 = """
|
||||
INSERT INTO lsv (ART_CODICE,TLV_CODICE,DATA_INIZIO,DATA_FINE,PREZZO,TSM_CODICE,TRL_CODICE)
|
||||
VALUES (%s,%s,%s,%s,%s,
|
||||
CASE WHEN %s != '' THEN %s ELSE NULL END,
|
||||
CASE WHEN %s != '' THEN %s ELSE NULL END
|
||||
)
|
||||
"""
|
||||
|
||||
cursor_insert.execute(query_lsv, (codice, listino, date.today().strftime("%Y-%m-%d"), data_fine, prezzo, sc2, sc2, ricarica, ricarica))
|
||||
|
||||
if cursor_insert.rowcount > 0:
|
||||
return cursor_insert.lastrowid
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
except Error as e:
|
||||
print(bcolors.FAIL+f"Errore durante l'inserimento: {e}")
|
||||
return None
|
||||
finally:
|
||||
cursor_insert.close()
|
||||
cursor_select_sc1.close()
|
||||
cursor_select_sc2.close()
|
||||
cursor_select_ricarica.close()
|
||||
132
utils/search.py
132
utils/search.py
@ -1,40 +1,120 @@
|
||||
from datetime import date
|
||||
|
||||
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 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
|
||||
def search_article(connection, codice_articolo):
|
||||
cursor_art = connection.cursor(buffered=True)
|
||||
try:
|
||||
query = "SELECT codice FROM art WHERE codice = %s"
|
||||
cursor_1.execute(query, (codice,))
|
||||
result_1 = cursor_1.fetchone()
|
||||
cursor_art.execute(query, (codice_articolo,))
|
||||
result = cursor_art.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'
|
||||
if result:
|
||||
return True
|
||||
else:
|
||||
print('codice non esiste')
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"Errore durante la ricerca: {e}")
|
||||
print(bcolors.FAIL+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()
|
||||
if cursor_art:
|
||||
cursor_art.close()
|
||||
|
||||
|
||||
def search_barcode(connection, codice_articolo, codice_barre):
|
||||
cursor_bar = connection.cursor(buffered=True)
|
||||
try:
|
||||
query = "SELECT ID FROM bar WHERE ART_CODICE = %s AND CODICE_BARRE= %s"
|
||||
cursor_bar.execute(query, (codice_articolo, codice_barre))
|
||||
result = cursor_bar.fetchone()
|
||||
|
||||
if result:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(bcolors.FAIL+f"Errore durante la ricerca: {e}")
|
||||
return None
|
||||
|
||||
finally:
|
||||
if cursor_bar:
|
||||
cursor_bar.close()
|
||||
|
||||
|
||||
def search_um(connection, um):
|
||||
cursor_um = connection.cursor(buffered=True)
|
||||
try:
|
||||
query = "SELECT codice FROM tum WHERE codice = %s"
|
||||
cursor_um.execute(query, (um,))
|
||||
result = cursor_um.fetchone()
|
||||
|
||||
if result:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(bcolors.FAIL+f"Errore durante la ricerca: {e}")
|
||||
return None
|
||||
|
||||
finally:
|
||||
if cursor_um:
|
||||
cursor_um.close()
|
||||
|
||||
|
||||
def search_lsv(connection, codice_articolo, ricarica, listino):
|
||||
cursor_lsv = connection.cursor(buffered=True)
|
||||
try:
|
||||
query = "SELECT ID FROM lsv WHERE ART_CODICE = %s AND TLV_CODICE = %s AND DATA_FINE > %s ORDER BY DATA_INIZIO DESC"
|
||||
cursor_lsv.execute(query, (codice_articolo, listino, date.today().strftime("%Y-%m-%d")))
|
||||
result = cursor_lsv.fetchone()
|
||||
|
||||
if result: # se il listino esiste
|
||||
return result
|
||||
else:
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(bcolors.FAIL+f"Errore durante la ricerca: {e}")
|
||||
return None
|
||||
|
||||
finally:
|
||||
if cursor_lsv:
|
||||
cursor_lsv.close()
|
||||
|
||||
def search_lsa(connection, codice_articolo, tsm_codice):
|
||||
cursor_lsa = connection.cursor(buffered=True)
|
||||
try:
|
||||
if tsm_codice != '':
|
||||
query = "SELECT ID FROM lsa WHERE ART_CODICE = %s AND TSM_CODICE = %s AND TLA_CODICE = '1' AND DATA_FINE > %s ORDER BY DATA_INIZIO DESC"
|
||||
cursor_lsa.execute(query, (codice_articolo, tsm_codice, date.today().strftime("%Y-%m-%d")))
|
||||
else:
|
||||
query = "SELECT ID FROM lsa WHERE ART_CODICE = %s AND TLA_CODICE = '1' AND DATA_FINE > %s ORDER BY DATA_INIZIO DESC"
|
||||
cursor_lsa.execute(query, (codice_articolo, date.today().strftime("%Y-%m-%d")))
|
||||
|
||||
result = cursor_lsa.fetchone()
|
||||
|
||||
if result: # se il listino esiste
|
||||
return result
|
||||
else:
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(bcolors.FAIL+f"Errore durante la ricerca: {e}")
|
||||
return None
|
||||
|
||||
finally:
|
||||
if cursor_lsa:
|
||||
cursor_lsa.close()
|
||||
|
||||
343
utils/update.py
343
utils/update.py
@ -5,132 +5,249 @@ 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()
|
||||
|
||||
# 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:
|
||||
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)
|
||||
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))
|
||||
|
||||
#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 cursor_update.rowcount > 0:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
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
|
||||
|
||||
except Error as e:
|
||||
print(bcolors.FAIL+f"Errore durante l'aggiornamento: {e}")
|
||||
finally:
|
||||
cursor_update.close()
|
||||
|
||||
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))
|
||||
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
|
||||
|
||||
connection.commit()
|
||||
except Error as e:
|
||||
print(bcolors.FAIL+f"Errore durante l'aggiornamento: {e}")
|
||||
finally:
|
||||
cursor_update.close()
|
||||
|
||||
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
|
||||
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)
|
||||
|
||||
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
|
||||
try:
|
||||
percentuale_totale_sc1 = percentuale_totale_sc2 = percentuale_ricarica = 0
|
||||
|
||||
row = [codice,prezzo,listino,sc1,ricarica,codice_barre,codice_alternativo,sc2,tsa_codice,frn]
|
||||
value_update.append(row)
|
||||
return value_update
|
||||
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:
|
||||
print(f"Record aggiornati per ART_CODICE: {codice}")
|
||||
|
||||
return False
|
||||
|
||||
except Error as e:
|
||||
print(f"Errore durante l'aggiornamento: {e}")
|
||||
print(bcolors.FAIL+f"Errore durante l'aggiornamento: {e}")
|
||||
finally:
|
||||
cursor.close()
|
||||
cursor_select.close()
|
||||
cursor_update.close()
|
||||
@ -10,22 +10,43 @@ def write_excel(value_update):
|
||||
filename = f'Articoli_Modificati{today}.xlsx'
|
||||
workbook = xlsxwriter.Workbook(filename)
|
||||
worksheet = workbook.add_worksheet()
|
||||
updated_format = workbook.add_format({'bg_color': '#D9EAD3'})
|
||||
created_format = workbook.add_format({'bg_color': '#FFF2CC'})
|
||||
error_format = workbook.add_format({'bg_color': '#F4CCCC'})
|
||||
|
||||
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')
|
||||
worksheet.set_column(0, 0, 30)
|
||||
worksheet.set_column(2, 6, 30)
|
||||
|
||||
worksheet.write('A1', 'ARTICOLO')
|
||||
worksheet.write('B1', 'UM')
|
||||
worksheet.write('C1', 'CODICE A BARRE')
|
||||
worksheet.write('D1', 'LISTINO DI ACQUISTO (ID LSA)')
|
||||
worksheet.write('E1', 'LISTINO DI VENDITA 1 (ID LSV)')
|
||||
worksheet.write('F1', 'LISTINO DI VENDITA 2 (ID LSV)')
|
||||
worksheet.write('G1', 'LISTINO DI VENDITA 4 (ID LSV)')
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
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)
|
||||
|
||||
|
||||
root = tk.Tk()
|
||||
|
||||
Reference in New Issue
Block a user