136 lines
5.2 KiB
Python
136 lines
5.2 KiB
Python
import mysql.connector
|
|
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):
|
|
print('test test')
|
|
cursor = connection.cursor()
|
|
cursor_select = connection.cursor()
|
|
print('cursor test')
|
|
try:
|
|
result = []
|
|
print('test 1')
|
|
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)
|
|
print('test 2')
|
|
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)
|
|
print('test 3')
|
|
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)
|
|
print('test 4')
|
|
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)
|
|
print('test 5')
|
|
if codice_barre is not None:
|
|
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)
|
|
print('test 6')
|
|
if not pd.isna(codice_alternativo):
|
|
query_alt = "UPDATE art SET CODICE_ALTERNATIVO = %s WHERE codice = %s"
|
|
cursor.execute(query_alt, (codice_alternativo, codice))
|
|
count = cursor.rowcount
|
|
result.append(count)
|
|
print('test 7')
|
|
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)
|
|
print('test 8')
|
|
if frn is not None:
|
|
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
|
|
print('test 9')
|
|
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()
|
|
print('result select')
|
|
print(percentuale_totale)
|
|
|
|
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
|
|
print('percentiale totale numero')
|
|
print(percentuale_totale)
|
|
|
|
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() |