File size: 6,088 Bytes
0fadcb9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from pathlib import Path
from typing import TypedDict
from PyPDFForm import PdfWrapper

from utils.date_utils import get_today_date_as_dd_mm_yyyy
from utils.parsing_utils import find_and_parse_date, find_and_parse_phone_number


def build_form_data_from_answers(answers: dict[int, str], categories: list[str], signature: str | None = None):
    form_data = {}
    for category in categories:
        form_data[form_fields_map[category]] = True
    form_data[form_fields_map["minor_work"]] = True
    form_data[form_fields_map["signed_by"]] = answers[0]
    form_data[form_fields_map["community"]] = answers[2]
    form_data[form_fields_map["building_name"]] = answers[3]
    form_data[form_fields_map["unit_no"]] = answers[4]
    form_data[form_fields_map["owner" if "owner" in answers[5].lower() else "tenant"]] = True
    form_data[form_fields_map["start_date"]] = find_and_parse_date(answers[6])
    form_data[form_fields_map["end_date"]] = find_and_parse_date(answers[7])
    form_data[form_fields_map["contact_number"]] = find_and_parse_phone_number(answers[8])
    form_data[form_fields_map["contractor_name"]] = answers[9]
    form_data[form_fields_map["contractor_contact_number"]] = answers[10]
    form_data[form_fields_map["contractor_email"]] = answers[11]
    form_data[form_fields_map["email"]] = answers[12]
    form_data[form_fields_map["occupant_name"]] = answers[0]
    form_data[form_fields_map["signature_date"]] = get_today_date_as_dd_mm_yyyy()
    if signature:
        form_data[form_fields_map["signature"]] = signature
    return form_data

def write_pdf_form(form_data: dict[str, str | bool | int], output_path:Path):
    base_form_path = Path(__file__, "..", "form.pdf")
    with open(base_form_path, "rb") as blank_form:
        filled_form = PdfWrapper(blank_form).fill(form_data)
    with open(output_path, "wb+") as filled_form_file:
        filled_form_file.write(filled_form.read())

class FormFields(TypedDict, total=True):
    start_date: str
    end_date: str
    signed_by: str
    signature_date: str
    community: str
    email: str
    unit_no: str
    contact_number: str
    building_name: str
    contractor_name: str
    contractor_email: str
    contractor_contact_number: str
    occupant_name: str
    civil: str
    electrical_AC: str
    furniture_delivery: str
    handyman: str
    pest_control: str
    sail_shade: str
    wardrobes: str
    wooden_flooring: str
    plumbing_sanitary: str
    safety_systems: str
    soft_landscaping: str
    balcony_tiles: str
    bathroom_toilet_refurbish: str
    staircase_railing: str
    storage_box: str
    tiling_works: str
    doors_door_frames: str
    gypsum_ceiling: str
    kitchen_refurbish: str
    lights_and_sockets: str
    painting_wallpapering: str
    seating_area_barbecuing_fountain: str
    other_work_checkbox: str
    owner: str
    tenant: str
    signature: str
    minor_work: str


form_fields_map: FormFields = {"start_date": "From", "end_date": "to", "signed_by": "name-10",
                               "signature_date": "From--1", "community": "Name-2", "email": "Name-3",
                               "unit_no": "Name-4", "contact_number": "Name-5", "building_name": "Name-6",
                               "contractor_name": "Name-7", "contractor_email": "name-8",
                               "contractor_contact_number": "name-9", "occupant_name": "name-1",
                               "other_work": "name-19", "civil": "3", "electrical_AC": "10", "furniture_delivery": "14",
                               "handyman": "18", "pest_control": "21", "sail_shade": "12", "wardrobes": "16",
                               "wooden_flooring": "24",
                               "plumbing_sanitary": "4", "safety_systems": "4", "soft_landscaping": "9",
                               "balcony_tiles": "13", "bathroom_toilet_refurbish": "20",
                               "staircase_railing": "17", "storage_box": "11", "tiling_works": "15",
                               "doors_door_frames": "6", "gypsum_ceiling": "22", "kitchen_refurbish": "7",
                               "lights_and_sockets": "23", "painting_wallpapering": "19",
                               "seating_area_barbecuing_fountain": "8",
                               "other_work_checkbox": "69", "owner": "Check Box4", "tenant": "Check Box3",
                               "signature": "Signature2", "minor_work": "2"}
work_categories = {"other_work": "other work", "civil": "Civil work, masonry",
                   "electrical_AC": "electrical / AC / air conditioning", "furniture_delivery": "furniture delivery",
                   "handyman": "handyman work, repairs, furniture assembly, furniture installation", "pest_control": "pest control",
                   "sail_shade": "sail shade, curtains", "wardrobes": "wardrobes",
                   "wooden_flooring": "wooden flooring",
                   "plumbing_sanitary": "plumbing / sanitary / bathroom works such as repairing a sink, tap, toilet, shower or bathtub",
                   "safety_systems": "safety systems, surveillance systems installation",
                   "soft_landscaping": "soft landscaping", "balcony_tiles": "installation and fixing of balcony tiles",
                   "bathroom_toilet_refurbish": "bathroom or toilet refurbishment or renovation",
                   "staircase_railing": "staircase rails, handrails", "storage_box": "storage box",
                   "tiling_works": "tiles installation or repair",
                   "doors_door_frames": "work related to doors and door frames",
                   "gypsum_ceiling": "gypsum ceiling installation or maintenance",
                   "kitchen_refurbish": "kitchen renovation or refurbishment",
                   "lights_and_sockets": "installation of lights, ceiling lights, power sockets",
                   "painting_wallpapering": "painting, wallpaper installation",
                   "seating_area_barbecuing_fountain": "installation or renovation of outdoor structures such as seating area, barbecuing area or fountains"}