Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -33,6 +33,7 @@ def generate_pdf(company_name):
|
|
33 |
pdf_file_path = "/content/invoice_records.pdf" # Define the file path
|
34 |
|
35 |
try:
|
|
|
36 |
# Create PDF
|
37 |
pdf = FPDF()
|
38 |
pdf.add_page()
|
@@ -43,6 +44,8 @@ def generate_pdf(company_name):
|
|
43 |
pdf.cell(200, 10, txt=f"Report Date: {current_date}", ln=True, align="C")
|
44 |
pdf.ln(10)
|
45 |
|
|
|
|
|
46 |
# Table headers
|
47 |
pdf.cell(50, 10, txt="Company Name", border=1, align="C")
|
48 |
pdf.cell(40, 10, txt="Name", border=1, align="C")
|
@@ -52,6 +55,8 @@ def generate_pdf(company_name):
|
|
52 |
|
53 |
# Add filtered data for the company
|
54 |
filtered_data = invoice_data[invoice_data["Company Name"] == company_name]
|
|
|
|
|
55 |
for index, row in filtered_data.iterrows():
|
56 |
pdf.cell(50, 10, txt=str(row['Company Name']), border=1, align="C")
|
57 |
pdf.cell(40, 10, txt=str(row['Name']), border=1, align="C")
|
@@ -64,6 +69,8 @@ def generate_pdf(company_name):
|
|
64 |
pdf.cell(160, 10, txt="Total Amount", border=1, align="R")
|
65 |
pdf.cell(30, 10, txt=str(total_amount), border=1, ln=True, align="C")
|
66 |
|
|
|
|
|
67 |
# Save PDF file
|
68 |
pdf.output(pdf_file_path)
|
69 |
|
@@ -72,6 +79,7 @@ def generate_pdf(company_name):
|
|
72 |
print(f"PDF successfully created at {pdf_file_path}")
|
73 |
return pdf_file_path
|
74 |
else:
|
|
|
75 |
return "Error: PDF not generated."
|
76 |
|
77 |
except Exception as e:
|
@@ -114,4 +122,3 @@ with gr.Blocks() as app:
|
|
114 |
# Launch the app
|
115 |
app.launch(share=True)
|
116 |
|
117 |
-
|
|
|
33 |
pdf_file_path = "/content/invoice_records.pdf" # Define the file path
|
34 |
|
35 |
try:
|
36 |
+
print(f"Generating PDF for company: {company_name}")
|
37 |
# Create PDF
|
38 |
pdf = FPDF()
|
39 |
pdf.add_page()
|
|
|
44 |
pdf.cell(200, 10, txt=f"Report Date: {current_date}", ln=True, align="C")
|
45 |
pdf.ln(10)
|
46 |
|
47 |
+
# Log the generation process
|
48 |
+
print("Adding table headers to the PDF")
|
49 |
# Table headers
|
50 |
pdf.cell(50, 10, txt="Company Name", border=1, align="C")
|
51 |
pdf.cell(40, 10, txt="Name", border=1, align="C")
|
|
|
55 |
|
56 |
# Add filtered data for the company
|
57 |
filtered_data = invoice_data[invoice_data["Company Name"] == company_name]
|
58 |
+
print(f"Number of rows for {company_name}: {len(filtered_data)}")
|
59 |
+
|
60 |
for index, row in filtered_data.iterrows():
|
61 |
pdf.cell(50, 10, txt=str(row['Company Name']), border=1, align="C")
|
62 |
pdf.cell(40, 10, txt=str(row['Name']), border=1, align="C")
|
|
|
69 |
pdf.cell(160, 10, txt="Total Amount", border=1, align="R")
|
70 |
pdf.cell(30, 10, txt=str(total_amount), border=1, ln=True, align="C")
|
71 |
|
72 |
+
# Log that we're saving the PDF
|
73 |
+
print(f"Saving PDF to {pdf_file_path}")
|
74 |
# Save PDF file
|
75 |
pdf.output(pdf_file_path)
|
76 |
|
|
|
79 |
print(f"PDF successfully created at {pdf_file_path}")
|
80 |
return pdf_file_path
|
81 |
else:
|
82 |
+
print("Error: PDF file not found.")
|
83 |
return "Error: PDF not generated."
|
84 |
|
85 |
except Exception as e:
|
|
|
122 |
# Launch the app
|
123 |
app.launch(share=True)
|
124 |
|
|