132 lines
3.9 KiB
Python
132 lines
3.9 KiB
Python
import pandas as pd
|
|
import mysql.connector
|
|
import math
|
|
import xlsxwriter
|
|
import tkinter as tk
|
|
from tkinter import filedialog,messagebox
|
|
from datetime import datetime
|
|
from mysql.connector import Error
|
|
from connection import create_connection
|
|
from connection import close_connection
|
|
from search import search_article
|
|
from update import update_records
|
|
from insert import insert_records
|
|
from write import write_excel
|
|
from write_excel_insert import write_excel_insert
|
|
from upload import upload_excel
|
|
|
|
|
|
host = "62.86.98.170"
|
|
user = "root"
|
|
password = "masterkey"
|
|
database = "arc_rumo"
|
|
port = 3307
|
|
|
|
#creo la connessione al database
|
|
conn = create_connection(host, user, password, database, port)
|
|
#leggo il file excel
|
|
file_input = upload_excel()
|
|
df = pd.read_excel(file_input, usecols='A:O')
|
|
|
|
#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
|
|
|
|
if math.isnan(row['SC2']):
|
|
sc2 = row['SC2']
|
|
else :
|
|
sc2 = int(row['SC2'])
|
|
|
|
if math.isnan(row['RICARICA1']):
|
|
ricarica1 = row['RICARICA1']
|
|
else:
|
|
ricarica1 = int(row['RICARICA1']) ## trl_codice per codice listino 1
|
|
|
|
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
|
|
|
|
|
|
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['TSA_CODICE']
|
|
else:
|
|
tsa_codice = int(row['TSA_CODICE'])
|
|
|
|
frn = row['FORNITORE']
|
|
|
|
|
|
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
|
|
|
|
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 not pd.isna(codice_alternativo):
|
|
codice_alternativo = ' '
|
|
if not pd.isna(codice_barre):
|
|
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,prezzo,sc1,sc2,ricarica,listino,codice_alternativo,codice_barre,art,tsa_codice,frn)
|
|
write_excel_insert(value_insert)
|
|
|
|
if conn :
|
|
conn.close()
|
|
|
|
|