don770omr commited on
Commit
c08c57c
·
verified ·
1 Parent(s): 414b86f

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +27 -42
utils.py CHANGED
@@ -8,6 +8,7 @@ from convertion import convert_feet_to_inches,convert_inches_to_feet
8
  from convertion import convert_meters_to_unit, convert_to_meters
9
 
10
 
 
11
  # Common function for shutter and glass calculations
12
  def calculate_reduced_dimensions(width, height, unit, selection, object_item_value, item_type="Door"):
13
  # Use the selected unit for the width and height reduction
@@ -40,7 +41,7 @@ def calculate_area_and_frame(width, height, unit, item_type="Door"):
40
 
41
  return area, frame_area
42
 
43
- def generate_pdf(dfs, company_name, address, unit, items):
44
  buffer = BytesIO()
45
 
46
  # Create a canvas for the PDF
@@ -57,55 +58,39 @@ def generate_pdf(dfs, company_name, address, unit, items):
57
  c.setLineWidth(1)
58
  c.line(30, height - 70, width - 30, height - 70) # Draw line under the address
59
 
60
-
61
  # Title
62
  c.setFont("Helvetica-Bold", 16)
63
  c.drawString(30, height - 100, f"Dimensions Calculation Results: for units ({unit})")
64
 
65
  # Calculate the y-position to avoid overlapping
66
- y_position = height - 150
67
-
68
- # Iterate over each item in the items list
69
- for i, item in enumerate(items):
70
- # Add a new page if the y-position gets too low
71
- if y_position < 100:
72
  c.showPage()
73
  y_position = height - 40 # Reset the y-position
74
-
75
- # Display item label (e.g., Item 1, Item 2)
76
- c.setFont("Helvetica-Bold", 12)
77
- c.drawString(30, y_position, f"Item {i+1}: {item}")
78
- y_position -= 130 # Move down after the label
79
-
80
- # Retrieve the corresponding dataframe for this item
81
- df = dfs[i]
82
-
83
- # Create and style the table
84
- data = [["Dimension", "Outer Frame", "Shutter", "Glass"]] # Table Header
85
- for index, row in df.iterrows():
86
- data.append([index] + [str(value) for value in row]) # Use row values directly for each column
87
-
88
- # Create the table
89
- table = Table(data, colWidths=[100, 100, 100, 100], rowHeights=30)
90
- table.setStyle(TableStyle([
91
- ('TEXTCOLOR', (0, 0), (-1, 0), (0, 0, 0)),
92
- ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
93
- ('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
94
- ('BOTTOMPADDING', (0, 0), (-1, 0), 12),
95
- ('BACKGROUND', (0, 0), (-1, 0), (0.7, 0.7, 0.7)),
96
- ('GRID', (0, 0), (-1, -1), 0.5, (0, 0, 0))
97
- ]))
98
-
99
- # Position the table just below the item label
100
- table.wrapOn(c, width, height)
101
- table.drawOn(c, 30, y_position)
102
-
103
- # Adjust the y-position for the next table
104
- y_position -= len(data) + 20 # Move down for next table
105
- c.line(30, y_position , width - 30, y_position) # Draw line under the address
106
-
107
  # Save the PDF
108
  c.save()
109
 
110
  buffer.seek(0)
111
- return buffer
 
 
8
  from convertion import convert_meters_to_unit, convert_to_meters
9
 
10
 
11
+
12
  # Common function for shutter and glass calculations
13
  def calculate_reduced_dimensions(width, height, unit, selection, object_item_value, item_type="Door"):
14
  # Use the selected unit for the width and height reduction
 
41
 
42
  return area, frame_area
43
 
44
+ def generate_pdf(df_combined, company_name, address, unit):
45
  buffer = BytesIO()
46
 
47
  # Create a canvas for the PDF
 
58
  c.setLineWidth(1)
59
  c.line(30, height - 70, width - 30, height - 70) # Draw line under the address
60
 
 
61
  # Title
62
  c.setFont("Helvetica-Bold", 16)
63
  c.drawString(30, height - 100, f"Dimensions Calculation Results: for units ({unit})")
64
 
65
  # Calculate the y-position to avoid overlapping
66
+ y_position = height - 200
67
+
68
+ if y_position < 100:
 
 
 
69
  c.showPage()
70
  y_position = height - 40 # Reset the y-position
71
+ # Create and style the table
72
+ data = [["Sl no", "Type", "Outer Frame", "Shutter", "Glass", "Area"]] # Table Header
73
+ for index, row in df_combined.iterrows():
74
+ data.append([row['Sl no'], row['Type'], row['Outer Frame'], row['Shutter'], row['Glass'], row['Area']])
75
+
76
+ # Create the table
77
+ table = Table(data, colWidths=[50, 100, 100, 100, 100, 100], rowHeights=30)
78
+ table.setStyle(TableStyle([
79
+ ('TEXTCOLOR', (0, 0), (-1, 0), (0, 0, 0)),
80
+ ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
81
+ ('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
82
+ ('BOTTOMPADDING', (0, 0), (-1, 0), 12),
83
+ ('BACKGROUND', (0, 0), (-1, 0), (0.7, 0.7, 0.7)),
84
+ ('GRID', (0, 0), (-1, -1), 0.5, (0, 0, 0))
85
+ ]))
86
+
87
+ # Position the table just below the title
88
+ table.wrapOn(c, width, height)
89
+ table.drawOn(c, 30, y_position)
90
+
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  # Save the PDF
92
  c.save()
93
 
94
  buffer.seek(0)
95
+ return buffer
96
+