128 lines
4.8 KiB
Python
128 lines
4.8 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):
|
|
|
|
try:
|
|
result = []
|
|
cursor = connection.cursor()
|
|
cursor_select = connection.cursor()
|
|
|
|
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 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)
|
|
|
|
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)
|
|
|
|
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 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
|
|
|
|
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"
|
|
cursor_select.execute(select_percentuale_totale,(sc1, ))
|
|
percentuale_totale = cursor_select.fetchone()
|
|
print('result select')
|
|
print(percentuale_totale)
|
|
percentuale_totale = percentuale_totale[0]
|
|
percentuale_totale = float(percentuale_totale)
|
|
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() |