feat: separate fusion field service and LTC into standalone modules, update core modules
- fusion_claims: separated field service logic, updated controllers/views - fusion_tasks: updated task views and map integration - fusion_authorizer_portal: added page 11 signing, schedule booking, migrations - fusion_shipping: new standalone shipping module (Canada Post, FedEx, DHL, Purolator) - fusion_ltc_management: new standalone LTC management module
This commit is contained in:
@@ -51,19 +51,25 @@ class PDFTemplateFiller:
|
||||
for page_idx in range(num_pages):
|
||||
page = original.getPage(page_idx)
|
||||
page_num = page_idx + 1 # 1-based page number
|
||||
page_w = float(page.mediaBox.getWidth())
|
||||
page_h = float(page.mediaBox.getHeight())
|
||||
mb = page.mediaBox
|
||||
page_w = float(mb.getWidth())
|
||||
page_h = float(mb.getHeight())
|
||||
origin_x = float(mb.getLowerLeft_x())
|
||||
origin_y = float(mb.getLowerLeft_y())
|
||||
|
||||
fields = fields_by_page.get(page_num, [])
|
||||
|
||||
if fields:
|
||||
# Create a transparent overlay for this page
|
||||
overlay_buf = BytesIO()
|
||||
c = canvas.Canvas(overlay_buf, pagesize=(page_w, page_h))
|
||||
c = canvas.Canvas(
|
||||
overlay_buf,
|
||||
pagesize=(origin_x + page_w, origin_y + page_h),
|
||||
)
|
||||
|
||||
for field in fields:
|
||||
PDFTemplateFiller._draw_field(
|
||||
c, field, context, signatures, page_w, page_h
|
||||
c, field, context, signatures,
|
||||
page_w, page_h, origin_x, origin_y,
|
||||
)
|
||||
|
||||
c.save()
|
||||
@@ -80,7 +86,8 @@ class PDFTemplateFiller:
|
||||
return result.getvalue()
|
||||
|
||||
@staticmethod
|
||||
def _draw_field(c, field, context, signatures, page_w, page_h):
|
||||
def _draw_field(c, field, context, signatures,
|
||||
page_w, page_h, origin_x=0, origin_y=0):
|
||||
"""Draw a single field onto the reportlab canvas.
|
||||
|
||||
Args:
|
||||
@@ -90,6 +97,8 @@ class PDFTemplateFiller:
|
||||
signatures: dict of {field_key: binary} for signature fields
|
||||
page_w: page width in PDF points
|
||||
page_h: page height in PDF points
|
||||
origin_x: mediaBox lower-left X (accounts for non-zero origin)
|
||||
origin_y: mediaBox lower-left Y (accounts for non-zero origin)
|
||||
"""
|
||||
field_key = field.get('field_key') or field.get('field_name', '')
|
||||
field_type = field.get('field_type', 'text')
|
||||
@@ -98,11 +107,12 @@ class PDFTemplateFiller:
|
||||
if not value and field_type != 'signature':
|
||||
return
|
||||
|
||||
# Convert percentage positions to absolute PDF coordinates
|
||||
# pos_x/pos_y are 0.0-1.0 ratios from top-left
|
||||
# PDF coordinate system: origin at bottom-left, Y goes up
|
||||
abs_x = field['pos_x'] * page_w
|
||||
abs_y = page_h - (field['pos_y'] * page_h) # flip Y axis
|
||||
# Convert percentage positions to absolute PDF coordinates.
|
||||
# pos_x/pos_y are 0.0-1.0 ratios from top-left of the visible page.
|
||||
# PDF coordinate system: origin at bottom-left, Y goes up.
|
||||
# origin_x/origin_y account for PDFs whose mediaBox doesn't start at (0,0).
|
||||
abs_x = field['pos_x'] * page_w + origin_x
|
||||
abs_y = (origin_y + page_h) - (field['pos_y'] * page_h)
|
||||
|
||||
font_name = field.get('font_name', 'Helvetica')
|
||||
font_size = field.get('font_size', 10.0)
|
||||
@@ -124,10 +134,22 @@ class PDFTemplateFiller:
|
||||
|
||||
elif field_type == 'checkbox':
|
||||
if value:
|
||||
c.setFont('ZapfDingbats', font_size)
|
||||
# Draw a cross mark (✗) that fills the checkbox box
|
||||
cb_w = field.get('width', 0.015) * page_w
|
||||
cb_h = field.get('height', 0.018) * page_h
|
||||
cb_y = abs_y - cb_h + (cb_h - font_size) / 2
|
||||
c.drawString(abs_x, cb_y, '4')
|
||||
# Inset slightly so the cross doesn't touch the box edges
|
||||
pad = min(cb_w, cb_h) * 0.15
|
||||
x1 = abs_x + pad
|
||||
y1 = abs_y - cb_h + pad
|
||||
x2 = abs_x + cb_w - pad
|
||||
y2 = abs_y - pad
|
||||
c.saveState()
|
||||
c.setStrokeColorRGB(0, 0, 0)
|
||||
c.setLineWidth(1.5)
|
||||
# Draw X (two diagonal lines)
|
||||
c.line(x1, y1, x2, y2)
|
||||
c.line(x1, y2, x2, y1)
|
||||
c.restoreState()
|
||||
|
||||
elif field_type == 'signature':
|
||||
sig_data = signatures.get(field_key)
|
||||
|
||||
Reference in New Issue
Block a user