Add raw mPDF input debugger
This commit is contained in:
parent
ebf23b93e8
commit
53b79b5297
|
|
@ -417,6 +417,7 @@ $routes->get('Ipd_discharge/search_patient', 'Ipd_discharge::search_patient', ['
|
|||
$routes->get('Ipd_discharge/search_patient_ajax', 'Ipd_discharge::search_patient_ajax', ['filter' => 'permission:ipd_discharge.view,ipd_discharge.manage']);
|
||||
$routes->get('Ipd_discharge/debug_ipd_fields/(:num)', 'Ipd_discharge::debug_ipd_fields/$1', ['filter' => 'permission:admin.access,admin.settings']);
|
||||
$routes->get('Ipd_discharge/debug_discharge_html/(:num)', 'Ipd_discharge::debug_discharge_html/$1', ['filter' => 'permission:admin.access,admin.settings']);
|
||||
$routes->get('Ipd_discharge/debug_mpdf_input/(:num)/(:num)', 'Ipd_discharge::debug_mpdf_input/$1/$2', ['filter' => 'permission:template.discharge,ipd_discharge.view,billing.access']);
|
||||
$routes->get('Ipd_discharge/placeholder_preview', 'Ipd_discharge::placeholder_preview', ['filter' => 'permission:ipd_discharge.view,ipd_discharge.manage']);
|
||||
$routes->get('Ipd_discharge/placeholder_preview/(:num)', 'Ipd_discharge::placeholder_preview/$1', ['filter' => 'permission:ipd_discharge.view,ipd_discharge.manage']);
|
||||
$routes->match(['GET', 'POST'], 'Ipd_discharge/ipd_select/(:num)', 'Ipd_discharge::ipd_select/$1', ['filter' => 'permission:ipd_discharge.manage']);
|
||||
|
|
|
|||
|
|
@ -5555,6 +5555,24 @@ class Ipd_discharge extends BaseController
|
|||
);
|
||||
}
|
||||
|
||||
public function debug_mpdf_input(int $ipdId, int $templateId = 0)
|
||||
{
|
||||
if ($resp = $this->requireAnyPermission(['template.discharge', 'ipd_discharge.view', 'billing.access'])) {
|
||||
return $resp;
|
||||
}
|
||||
|
||||
$file = WRITEPATH . 'debug' . DIRECTORY_SEPARATOR . 'discharge_mpdf_input_' . $ipdId . '_' . $templateId . '.html';
|
||||
if (! is_file($file)) {
|
||||
return $this->response->setStatusCode(404)->setBody('Generate the PDF first, then reopen this debug view.');
|
||||
}
|
||||
|
||||
return view('ipd_discharge/mpdf_raw_html', [
|
||||
'ipd_id' => $ipdId,
|
||||
'template_id' => $templateId,
|
||||
'html' => (string) file_get_contents($file),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Placeholder preview page: shows each placeholder and resolved content for an IPD.
|
||||
* Access via: /Ipd_discharge/placeholder_preview/{ipdId}?tpl={templateId}
|
||||
|
|
@ -7398,6 +7416,14 @@ class Ipd_discharge extends BaseController
|
|||
|
||||
$pdfHtml .= $renderedHtml;
|
||||
$pdfHtml = mpdf_normalize_font_weight_css($pdfHtml);
|
||||
|
||||
$debugDirectory = WRITEPATH . 'debug';
|
||||
if (! is_dir($debugDirectory)) {
|
||||
mkdir($debugDirectory, 0755, true);
|
||||
}
|
||||
$debugTemplateId = (int) ($templatePack['selected_template_id'] ?? 0);
|
||||
file_put_contents($debugDirectory . DIRECTORY_SEPARATOR . 'discharge_mpdf_input_' . $ipdId . '_' . $debugTemplateId . '.html', $pdfHtml, LOCK_EX);
|
||||
|
||||
$pdfBinary = $this->runMpdfWithTolerantWarnings(static function () use ($mpdf, $pdfHtml, $fileName): string {
|
||||
$mpdf->WriteHTML($pdfHtml);
|
||||
|
||||
|
|
|
|||
|
|
@ -157,6 +157,7 @@ $placeholders = [
|
|||
<button type="button" class="btn btn-outline-primary btn-sm" id="btn_preview">Preview</button>
|
||||
<button type="button" class="btn btn-outline-danger btn-sm" id="btn_pdf">PDF</button>
|
||||
<button type="button" class="btn btn-outline-secondary btn-sm" id="btn_debug_html" title="Show raw HTML sent to mPDF">Debug HTML</button>
|
||||
<button type="button" class="btn btn-outline-dark btn-sm" id="btn_mpdf_input" title="View exact HTML saved immediately before WriteHTML">mPDF Input</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -267,6 +268,12 @@ $placeholders = [
|
|||
window.open('<?= base_url('Ipd_discharge/show_discharge') ?>/' + ipdId + '/1?html=1' + (editId > 0 ? '&tpl=' + editId : ''), '_blank');
|
||||
});
|
||||
|
||||
document.getElementById('btn_mpdf_input').addEventListener('click', function () {
|
||||
var ipdId = parseInt(val('preview_ipd_id'), 10);
|
||||
if (!ipdId || !editId) { alert('Save the template and enter IPD ID first.'); return; }
|
||||
window.open('<?= base_url('Ipd_discharge/debug_mpdf_input') ?>/' + ipdId + '/' + editId, '_blank');
|
||||
});
|
||||
|
||||
/* Placeholder click-to-copy */
|
||||
document.querySelectorAll('.ph-chip').forEach(function (chip) {
|
||||
chip.addEventListener('click', function () {
|
||||
|
|
|
|||
17
app/Views/ipd_discharge/mpdf_raw_html.php
Normal file
17
app/Views/ipd_discharge/mpdf_raw_html.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
$ipdId = (int) ($ipd_id ?? 0);
|
||||
$templateId = (int) ($template_id ?? 0);
|
||||
$templateName = (string) ($template_name ?? '');
|
||||
$html = (string) ($html ?? '');
|
||||
?>
|
||||
<section class="content">
|
||||
<div class="card">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<strong>Exact HTML passed to mPDF WriteHTML()</strong>
|
||||
<span class="small text-muted">IPD <?= $ipdId ?> | Template <?= $templateId ?>: <?= esc($templateName) ?></span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<pre style="white-space:pre-wrap;word-break:break-word;font-family:Consolas,monospace;font-size:12px;margin:0;"><?= esc($html) ?></pre>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
Loading…
Reference in New Issue
Block a user