atifsial123 commited on
Commit
6539c9c
·
verified ·
1 Parent(s): 25ef9d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -54,6 +54,14 @@ def search_by_head(head):
54
  def generate_ledger_pdf(head):
55
  global ledger
56
  try:
 
 
 
 
 
 
 
 
57
  # Use a temporary directory to save the file
58
  with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_file:
59
  pdf_file_path = tmp_file.name # Get the temporary file path
@@ -75,9 +83,7 @@ def generate_ledger_pdf(head):
75
  pdf.cell(30, 10, txt="Date", border=1, align="C")
76
  pdf.cell(50, 10, txt="Amount", border=1, ln=True, align="C")
77
 
78
- # Filter records by head
79
- filtered_ledger = ledger[ledger["Head"] == head]
80
-
81
  for _, row in filtered_ledger.iterrows():
82
  pdf.cell(40, 10, txt=str(row['Company Name']), border=1, align="C")
83
  pdf.cell(40, 10, txt=str(row['SP/Station']), border=1, align="C")
@@ -144,4 +150,3 @@ with gr.Blocks() as app:
144
 
145
  # Launch the app
146
  app.launch(share=True)
147
-
 
54
  def generate_ledger_pdf(head):
55
  global ledger
56
  try:
57
+ # Filter records by head
58
+ filtered_ledger = ledger[ledger["Head"] == head]
59
+
60
+ # Check if there are any records for the specified head
61
+ if filtered_ledger.empty:
62
+ print(f"No records found for {head}")
63
+ return None
64
+
65
  # Use a temporary directory to save the file
66
  with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_file:
67
  pdf_file_path = tmp_file.name # Get the temporary file path
 
83
  pdf.cell(30, 10, txt="Date", border=1, align="C")
84
  pdf.cell(50, 10, txt="Amount", border=1, ln=True, align="C")
85
 
86
+ # Add table rows
 
 
87
  for _, row in filtered_ledger.iterrows():
88
  pdf.cell(40, 10, txt=str(row['Company Name']), border=1, align="C")
89
  pdf.cell(40, 10, txt=str(row['SP/Station']), border=1, align="C")
 
150
 
151
  # Launch the app
152
  app.launch(share=True)