File size: 3,911 Bytes
9700fe0
 
 
3757aac
9700fe0
 
 
 
 
 
c08c57c
9700fe0
 
 
 
 
 
 
 
 
5fbaf75
 
 
ff24736
9700fe0
ff24736
 
0a02f32
 
9700fe0
 
 
 
ff24736
 
 
 
9ec7c02
9700fe0
ff24736
9700fe0
 
 
c08c57c
9700fe0
 
 
 
 
101650b
 
9700fe0
 
101650b
 
 
9700fe0
 
101650b
9700fe0
 
101650b
9700fe0
 
101650b
9700fe0
101650b
9700fe0
 
101650b
c08c57c
 
 
 
 
 
 
c29c961
 
c08c57c
 
 
 
 
 
 
 
 
 
 
f04d03a
c08c57c
9700fe0
 
 
 
c08c57c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from io import BytesIO
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
from reportlab.lib import colors
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle
from convertion import convert_feet_to_inches,convert_inches_to_feet
from convertion import convert_meters_to_unit, convert_to_meters



# Common function for shutter and glass calculations
def calculate_reduced_dimensions(width, height, unit, selection, object_item_value, item_type="Door"):
    # Use the selected unit for the width and height reduction
    if unit == 'Feet':
        reduction_width = convert_inches_to_feet(object_item_value[selection][item_type]['width'])
        reduction_height = convert_inches_to_feet(object_item_value[selection][item_type]['height'])
    else: 
        reduction_width = object_item_value[selection][item_type]['width']
        reduction_height = object_item_value[selection][item_type]['height']
    selection_div = "divider_sh" if selection == 'shutter' else 'divider_gl'
    divider_h = object_item_value[selection_div][item_type]['height']
    divider_w = object_item_value[selection_div][item_type]['width']

    # Calculate the reduced dimensions based on the width and height
    reduced_width = (width - reduction_width) / divider_w
    reduced_height = (height - reduction_height) / divider_h
    area,_ = calculate_area_and_frame(reduced_width,reduced_height,unit,item_type=item_type)
    return reduced_width, reduced_height, area

# Functions for door and window area/frame calculation
def calculate_area_and_frame(width, height, unit, item_type="Door"):
    # Convert width and height to meters for area and frame calculation
    if unit == 'Inches':
        width = convert_inches_to_feet(width)
        height = convert_inches_to_feet(height)

    area = width * height
    frame_thickness = {'Door': 0.1, 'Window': 0.05}
    frame_area = 2 * (width + height) * frame_thickness.get(item_type, 0.1)
    
    return area, frame_area

def generate_pdf(df_combined, company_name, address, unit):
    buffer = BytesIO()
    
    # Create a canvas for the PDF
    c = canvas.Canvas(buffer, pagesize=letter)
    width, height = letter

    y_position = height - 40
    # Company details
    c.setFont("Helvetica", 12)
    c.drawString(30, y_position, f"Company Name: {company_name}")
    y_position -= 20
    c.drawString(30, y_position, f"Address: {address}")
    
    # Draw a line under the address
    y_position -= 10
    c.setStrokeColor(colors.black)
    c.setLineWidth(1)
    c.line(30, y_position, width - 30, y_position)  # Draw line under the address

    # Title
    y_position -= 30
    c.setFont("Helvetica-Bold", 16)
    c.drawString(30, y_position, f"Dimensions Calculation Results: for units ({unit})")
    
    # Calculate the y-position to avoid overlapping
    y_position -= 20

    # Create and style the table
    data = [["Sl no", "Type", "Outer Frame", "Shutter", "Glass", "Area"]]  # Table Header
    for index, row in df_combined.iterrows():
        data.append([row['Sl no'], row['Type'], row['Outer Frame'], row['Shutter'], row['Glass'], row['Area']])
    
    # Create the table
    row_height = 30
    table = Table(data, colWidths=[50, 100, 100, 100, 100, 100], rowHeights=row_height)
    table.setStyle(TableStyle([
        ('TEXTCOLOR', (0, 0), (-1, 0), (0, 0, 0)),
        ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
        ('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
        ('BOTTOMPADDING', (0, 0), (-1, 0), 12),
        ('BACKGROUND', (0, 0), (-1, 0), (0.7, 0.7, 0.7)),
        ('GRID', (0, 0), (-1, -1), 0.5, (0, 0, 0))
    ]))
    
    # Position the table just below the title
    table.wrapOn(c, width, height)
    table.drawOn(c, 30, y_position-(len(df_combined)+1)*row_height)
    
    # Save the PDF
    c.save()
    
    buffer.seek(0)
    return buffer