dorset_fill.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. declare(strict_types=1);
  3. use setasign\Fpdi\Fpdi;
  4. /**
  5. * @return string|null Absolute path to the generated Dorset PDF, or null on failure
  6. */
  7. function generate_dorset_application(string $job, array $vars, array $cfg, string $templatePath, string $outPath): ?string {
  8. if (!is_file($templatePath)) return null;
  9. // Property Details
  10. $addr = $vars['property']['address'] ?? '';
  11. $title = 'Title: ' . ($vars['property']['title'] ?? '') . ' PID: ' . ($vars['property']['pid'] ?? '');
  12. // Owner
  13. $ownerName = $vars['client']['name'] ?? '';
  14. $ownerEmail = $vars['client']['email'] ?? '';
  15. $ownerPhone = $vars['client']['phone'] ?? '';
  16. $ownerAddr = $vars['client']['address'] ?? '';
  17. $sigOwnerPng = __DIR__ . "/loa/{$job}/{$job}_signature.png";
  18. // Applicant (your business)
  19. $appName = ($cfg['dev_name'] ?? '') . ' - ' . ($cfg['dev_company'] ?? '') ?? 'Benjamin Harris - Modulos Design';
  20. $appEmail = $cfg['dev_email'] ?? 'drafting@modulosdesign.com.au';
  21. $appPhone = $cfg['dev_phone'] ?? '0402 984 082';
  22. $appAddress = $cfg['dev_address'] ?? '34 Coplestone St, Scottsdale, Tas 7260';
  23. $sigAppPng = __DIR__ . "/applicant_signature.png";
  24. $today = date('d/m/Y');
  25. $pdf = new Fpdi();
  26. $pdf->AddPage();
  27. $pdf->setSourceFile($templatePath);
  28. $tpl = $pdf->importPage(1);
  29. $pdf->useTemplate($tpl, 0, 0, 210); // A4 width in mm
  30. $pdf->SetFont('Helvetica','',11);
  31. // helpers
  32. $T = function($x,$y,$t) use($pdf){ $pdf->SetXY($x,$y); $pdf->Cell(0,5,(string)$t,0,0); };
  33. $MB = function($x,$y,$w,$t) use($pdf){ $pdf->SetFont('Helvetica','B',12); $pdf->SetXY($x,$y); $pdf->MultiCell($w,5,(string)$t,0,'L'); $pdf->SetFont('Helvetica','',11); };
  34. $X = function($x,$y) use($pdf){ $pdf->Text($x,$y,'X'); };
  35. // --- Map to fields (adjust if your copy’s baseline differs) ---
  36. $MB(58, 133, 122, $addr); // Full Address 45, 95
  37. $MB(58, 140, 122, $title); // PID/Title 55, 103
  38. // Applicant (your business)
  39. $T(58, 159, $appName);
  40. $T(58, 167, $appAddress);
  41. $T(70, 174, $appPhone);
  42. $T(128,174, $appEmail);
  43. if (is_file($sigAppPng)) $pdf->Image($sigAppPng, 60, 179, 30); // Signature of Owner
  44. $T(128, 182, $today); // Date
  45. // Owner Authorisation
  46. $T(58, 203, $ownerName);
  47. $T(58, 210, $ownerAddr);
  48. $T(70, 217, $ownerPhone);
  49. $T(128, 217, $ownerEmail);
  50. if (is_file($sigOwnerPng)) $pdf->Image($sigOwnerPng, 60, 220, 50); // Signature of Owner
  51. $T(128, 226, $today);
  52. // Information Requested – default ticks (tweak to taste / make UI later)
  53. $X(107, 95); // Planning Permit & Associated Docs
  54. $X(185, 95); // Occupancy & Completion Certificates
  55. $X(107, 102); // Building Plans…
  56. $X(185, 102); // Building/Plumbing Notices & Orders
  57. $X(107, 109); // Plumbing Plans…
  58. $pdf->Output('F', $outPath);
  59. return is_file($outPath) ? $outPath : null;
  60. }