Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
from tkinter import filedialog as fd
from tkinter import messagebox
import pandas as pd
import PyPDF2
import re
class Document:
skusWithQuantities = []
skus = []
extension = ""
filetype = ''
partNumber = ""
def __init__(self,ext,ftype):
self.extension = ext
self.filetype = ftype
self.skusWithQuantities = []
self.skus = []
self.generateFromFile()
def generateFromFile(self): # gets the skus for a quote
currentQuote = open(self.extension,'rb') #open pdf document
pdfReader = PyPDF2.PdfReader(currentQuote) #establish reading connection
self.partNumber = ''
for i in pdfReader.pages: # for each page
pageNotes = str(i.extract_text()) #get all the text
self.skusWithQuantities += re.findall(stringDict[self.filetype],pageNotes) #add all matching SKUs(and quantities)
self.skus = [i[0] for i in self.skusWithQuantities] # find just the SKUs
currentQuote.close() #close pdf document
def readPages(self): #displays what the app can see
currentQuote = open(self.extension,'rb') #open pdf document
pdfReader = PyPDF2.PdfReader(currentQuote) #establish reading connection
for i in pdfReader.pages: # for each page
pageNotes = str(i.extract_text()) #get all the text
print(pageNotes)
currentQuote.close() #close pdf document
class Document:
skusWithQuantities = []
skus = []
extension = ""
filetype = ''
partNumber = ""
def __init__(self,ext,ftype):
self.extension = ext
self.filetype = ftype
self.skusWithQuantities = []
self.skus = []
self.generateFromFile()
def generateFromFile(self): # gets the skus for a quote
currentQuote = open(self.extension,'rb') #open pdf document
pdfReader = PyPDF2.PdfReader(currentQuote) #establish reading connection
self.partNumber = ''
for i in pdfReader.pages: # for each page
pageNotes = str(i.extract_text()) #get all the text
self.skusWithQuantities += re.findall(stringDict[self.filetype],pageNotes) #add all matching SKUs(and quantities)
self.skus = [i[0] for i in self.skusWithQuantities] # find just the SKUs
currentQuote.close() #close pdf document
def readPages(self): #displays what the app can see
currentQuote = open(self.extension,'rb') #open pdf document
pdfReader = PyPDF2.PdfReader(currentQuote) #establish reading connection
for i in pdfReader.pages: # for each page
pageNotes = str(i.extract_text()) #get all the text
print(pageNotes)
currentQuote.close() #close pdf document
class Quote(Document):
total = ""
quoteDate = ""
quoteNumber = ""
def __init__(self,ext,ftype):
Document.__init__(self,ext,ftype)
class EMEAQuote(Quote):
def __init__(self,ext):
Quote.__init__(self,ext,'EMEA')
baseMult = 1
newSkuWQuantity =[]
for sku,mult,count in self.skusWithQuantities:
if count == '':
baseMult = int(mult)
newSkuWQuantity.append((sku,mult))
else:
newSkuWQuantity.append((sku,str(int(count)*baseMult)))#for sku in self.skusWithQuantities
#***********add logic for combining quantities
self.skusWithQuantities = newSkuWQuantity
def getData(self):
currentQuote = open(self.extension,'rb') #open pdf document
pdfReader = PyPDF2.PdfReader(currentQuote) #establish reading connection
pageNotes = str(pdfReader.pages[0].extract_text()) #get all the text
pageTwo = str(pdfReader.pages[1].extract_text())
data1 = re.findall(EMEAQuoteData,pageNotes) #add all matching SKUs(and quantities)
data2 = re.findall(EMEAQuoteData2,pageTwo)
data3 = re.findall(EMEAQuoteData3,pageNotes)
self.quoteDate = data1[0][0]
self.quoteNumber = data1[0][1]
#print(data2)
self.total = data2[0]
self.partNumber = data3[0]
currentQuote.close() #close pdf document
def __str__(self):
self.getData()
retString = 'Emea Quote: ' + self.quoteNumber + 'n'
retString += 'Total: ' + self.total + 'n'
retString += 'Date: ' + self.quoteDate + 'n'
retString += 'Part Number: ' + self.partNumber + 'n'
return retString
class EMEAGIIvsDSAApp:
def __init__(self, master):
self.master = master
master.title("EMEA Gii vs. EMEA Dsa Quote Review")
master.geometry("400x200")
self.label = tk.Label(master, text="Compare EMEA Gii (PDF) and EMEA Dsa (Excel) Quotes")
self.label.pack(pady=10)
self.compare_button = tk.Button(master, text="Select and Compare Quotes", command=self.compare_quotes)
self.compare_button.pack(pady=20)
def compare_quotes(self):
gii_pdf_path = fd.askopenfilename(title='Select EMEA GII Quote (PDF)', filetypes=[("PDF Files", "*.pdf")])
dsa_excel_path = fd.askopenfilename(title='Select EMEA DSA Quote (Excel)', filetypes=[("Excel Files", "*.xlsx", "*.xls")])
if not gii_pdf_path or not dsa_excel_path:
messagebox.showerror("Error", "Both a PDF and an Excel file must be selected")
return
# Extract SKU data from both documents
gii_skus = self.extract_pdf_skus(gii_pdf_path)
dsa_skus, dsa_details = self.read_excel_data(dsa_excel_path)
# Compare SKUs
gii_not_in_dsa, dsa_not_in_gii = self.compare_skus(gii_skus, dsa_skus)
# Display comparison results
self.display_results(dsa_details, gii_not_in_dsa, dsa_not_in_gii)
def extract_pdf_skus(self, filepath): #gets the skus for a quote
gii_pdf_path = open(self.extension,'rb') #open pdf document
pdfReader = PyPDF2.PdfReader(gii_pdf_path) #establish reading connection
self.partNumber = ''
for i in pdfReader.pages: # for each page
pageNotes = str(i.extract_text()) #get all the text
self.skusWithQuantities += re.findall(stringDict[self.filetype],pageNotes) #add all matching SKUs(and quantities)
self.skus = [i[0] for i in self.skusWithQuantities] # find just the SKUs
currentQuote.close() #close pdf document
def read_excel_data(filepath):
"""Reads data from an Excel file, focusing on SKU and quantity extraction."""
df = pd.read_excel(filepath, usecols=["K", "N"]) # Adjust column letters as necessary
skus_with_quantities = df.groupby('K')['N'].sum().to_dict() # Sum quantities for each SKU
return skus_with_quantities
def compare_skus(pdf_skus, excel_skus):
"""Compares SKUs and quantities between PDF and Excel data."""
mismatches = []
for sku, qty in pdf_skus.items():
if sku not in excel_skus:
mismatches.append(f"SKU {sku} present in PDF not in Excel")
elif qty != excel_skus[sku]:
mismatches.append(f"Quantity mismatch for SKU {sku}: PDF has {qty}, Excel has {excel_skus[sku]}")
for sku, qty in excel_skus.items():
if sku not in pdf_skus:
mismatches.append(f"SKU {sku} present in Excel not in PDF")
return mismatches
def display_results(self, dsa_details, gii_not_in_dsa, dsa_not_in_gii):
results_window = tk.Toplevel(self.master)
results_window.title("Comparison Results")
tk.Label(results_window, text=f"EMEA Dsa Quote Details:n{dsa_details}").pack()
tk.Label(results_window, text=f"SKU present in Gii not in Dsa:n{gii_not_in_dsa}").pack()
tk.Label(results_window, text=f"SKU present in Dsa not in Gii:n{dsa_not_in_gii}").pack()
if __name__ == "__main__":
root = tk.Tk()
app = EMEAGIIvsDSAApp(root)
root.mainloop()
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team