Build T_SendEmailReports from qr_printout with id/url/result format

Done.php send_email_v2: query qr_printout to build structured reports
array [{"id","url","result"}] using QR_PrintOutGroup_ResultName instead
of relying on client-supplied reports param.

send_email.php: parse both old (URL string) and new (object) formats;
use result field as PDF attachment filename.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
sas.fajri
2026-05-24 21:52:31 +07:00
parent 69772125b5
commit 1c588f1d7d
2 changed files with 40 additions and 12 deletions

View File

@@ -283,8 +283,21 @@ foreach ($rows as $row) {
$attachments = [];
$tmp_files = [];
foreach ($reports as $idx => $url) {
log_msg(" Downloading attachment " . ($idx + 1) . ": {$url}");
foreach ($reports as $idx => $entry) {
// Support both formats:
// old: ["http://..."]
// new: [{"id":"1","url":"http://...","result":"LAB"}]
if (is_array($entry)) {
$url = $entry['url'] ?? '';
$result = $entry['result'] ?? ('hasil_lab_' . ($idx + 1));
} else {
$url = (string) $entry;
$result = 'hasil_lab_' . ($idx + 1);
}
if (empty($url)) continue;
log_msg(" Downloading attachment " . ($idx + 1) . " [{$result}]: {$url}");
$pdf = download_pdf($url);
if ($pdf === false) {
@@ -313,9 +326,10 @@ foreach ($rows as $row) {
}
}
$safe_result = preg_replace('/[^a-zA-Z0-9_\-]/', '_', $result);
$attachments[] = [
'path' => $final,
'name' => 'hasil_lab_' . ($idx + 1) . '.pdf',
'name' => $safe_result . '.pdf',
];
}