prezzo lsv/tsa/fornitore
This commit is contained in:
1
.~lock.TEST.xlsx#
Normal file
1
.~lock.TEST.xlsx#
Normal file
@ -0,0 +1 @@
|
||||
,pc-sviluppo1,pcsviluppo1,12.12.2024 11:09,file:///home/pc-sviluppo1/.config/libreoffice/4;
|
||||
58
insert.py
58
insert.py
@ -13,43 +13,81 @@ data_fine = datetime.datetime.strptime(data_str, "%Y-%m-%d").date()
|
||||
tla = 1
|
||||
|
||||
value_insert = []
|
||||
def insert_records(connection,codice,descrizione,um,costo,sc1,sc2,ricarica,listino,codice_alternativo,codice_barre,art,tsa_codice):
|
||||
def insert_records(connection,codice,descrizione,um,prezzo,sc1,sc2,ricarica,listino,codice_alternativo,codice_barre,art,tsa_codice,frn):
|
||||
try:
|
||||
print('tipo tsa_codice')
|
||||
|
||||
cursor_select = connection.cursor()
|
||||
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,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'))
|
||||
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,FRN_CODICE) VALUES (%s,%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',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:
|
||||
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))
|
||||
query_lsv = "INSERT INTO lsv (ART_CODICE,DATA_FINE,DATA_INIZIO,TSM_CODICE,TRL_CODICE,TLV_CODICE) VALUES (%s,%s,%s,%s,%s,%s)"
|
||||
cursor.execute(query_lsv,(codice,data_fine,formatted_date,sc2,ricarica,listino))
|
||||
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,costo,sc1))
|
||||
cursor.execute(query_lsa,(codice,tla,formatted_date,data_fine,prezzo,sc1))
|
||||
count = cursor.rowcount
|
||||
result.append(count)
|
||||
|
||||
##sggiungere aggiunta prezzo lsv sia per listino 1 che per listino diverso
|
||||
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*ricarica)/100
|
||||
|
||||
prezzo_lsv = (ris*22)/100
|
||||
|
||||
query_price = "INSERT INTO lsv (PREZZO) VALUES (%s)"
|
||||
cursor.execute(query_price, (prezzo_lsv,))
|
||||
|
||||
|
||||
else :
|
||||
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))
|
||||
|
||||
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*ricarica)/100
|
||||
prezzo_lsv = ris
|
||||
if listino == 4:
|
||||
prezzo_lsv = (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,costo,sc1,sc2,ricarica,codice_alternativo,codice_barre,tsa_codice]
|
||||
row = [codice,descrizione,um,prezzo,sc1,sc2,ricarica,codice_alternativo,codice_barre,tsa_codice,frn]
|
||||
value_insert.append(row)
|
||||
return value_insert
|
||||
|
||||
|
||||
14
main.py
14
main.py
@ -26,7 +26,7 @@ port = 3307
|
||||
conn = create_connection(host, user, password, database, port)
|
||||
#leggo il file excel
|
||||
file_input = upload_excel()
|
||||
df = pd.read_excel(file_input, usecols='A:N')
|
||||
df = pd.read_excel(file_input, usecols='A:O')
|
||||
|
||||
#leggo le colonne del file excel
|
||||
for index, row in df.iterrows():
|
||||
@ -72,11 +72,13 @@ for index, row in df.iterrows():
|
||||
prezzo = float(row['COSTO'])
|
||||
|
||||
|
||||
if math.isnan(row['TSA_CODICE']):
|
||||
if math.isnan(row['GRUPPO STATISTICO']):
|
||||
tsa_codice = row['TSA_CODICE']
|
||||
else:
|
||||
tsa_codice = int(row['TSA_CODICE'])
|
||||
|
||||
frn = row['FORNITORE']
|
||||
|
||||
|
||||
if conn :
|
||||
if ricarica1 is not None and not math.isnan(ricarica1):
|
||||
@ -95,8 +97,8 @@ for index, row in df.iterrows():
|
||||
art = search_article(conn,codice,listino) #cerco codice articolo
|
||||
|
||||
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)
|
||||
print(value_update)
|
||||
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
|
||||
@ -117,8 +119,10 @@ for index, row in df.iterrows():
|
||||
codice_barre = '0000000000000'
|
||||
if math.isnan(tsa_codice):
|
||||
tsa_codice = '0'
|
||||
if not pd.isna(frn):
|
||||
frn = ' '
|
||||
|
||||
value_insert = insert_records(conn,codice,descrizione,um,costo,sc1,sc2,ricarica,listino,codice_alternativo,codice_barre,art,tsa_codice)
|
||||
value_insert = insert_records(conn,codice,descrizione,um,prezzo,sc1,sc2,ricarica,listino,codice_alternativo,codice_barre,art,tsa_codice,frn)
|
||||
write_excel_insert(value_insert)
|
||||
|
||||
if conn :
|
||||
|
||||
@ -14,17 +14,13 @@ def search_article(connection,codice,listino):
|
||||
cursor_1.execute(query,(codice,))
|
||||
result_1 = cursor_1.fetchone()
|
||||
|
||||
print('result')
|
||||
print(result_1)
|
||||
|
||||
if result_1: ## se l'articolo esiste creco per codice listino
|
||||
print('articlo esiste')
|
||||
print(listino)
|
||||
|
||||
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()
|
||||
print('ricerca per listino')
|
||||
print(result_2)
|
||||
|
||||
if result_2: ## se il codice listino è stato trovato
|
||||
print('codice listino trovato')
|
||||
return True ## esistono sia articolo che codice listino
|
||||
|
||||
37
update.py
37
update.py
@ -5,11 +5,12 @@ import math
|
||||
|
||||
value_update = []
|
||||
|
||||
def update_records(connection,codice,prezzo,sc1,sc2,listino,ricarica,codice_barre,codice_alternativo,tsa_codice):
|
||||
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'"
|
||||
@ -53,6 +54,36 @@ def update_records(connection,codice,prezzo,sc1,sc2,listino,ricarica,codice_barr
|
||||
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*ricarica)/100
|
||||
print(ris)
|
||||
prezzo_lsv = ris
|
||||
if listino == 1 or listino == 4:
|
||||
prezzo_lsv = (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):
|
||||
@ -81,8 +112,10 @@ def update_records(connection,codice,prezzo,sc1,sc2,listino,ricarica,codice_barr
|
||||
|
||||
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]
|
||||
row = [codice,prezzo,listino,sc1,ricarica,codice_barre,codice_alternativo,sc2,tsa_codice,frn]
|
||||
value_update.append(row)
|
||||
return value_update
|
||||
|
||||
|
||||
1
write.py
1
write.py
@ -20,6 +20,7 @@ def write_excel(value_update):
|
||||
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):
|
||||
|
||||
|
||||
@ -21,6 +21,7 @@ def write_excel_insert(value_insert):
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user