MERGE_TEST_CLAIM_PDF_MERGE&SALES_CR

This commit is contained in:
Ubuntu 2026-05-12 10:12:36 +05:30
commit 169ff8c1ca

View File

@ -21,14 +21,14 @@ if (! function_exists('merge_ticket_pdfs')) {
* - ticket_id = $ticket_master_id
* - is_active = 1
* - mime_type IN $opts['include_mime_types'] (default PDF/JPG/PNG)
* - file_type IN $opts['include_file_types'] (default [2, 3])
* - file_type IN $opts['include_file_types'] (default [1, 2, 3])
*
* @param int $ticket_master_id
* @param array $opts {
* @var bool $replace Default true. Soft-delete previous merged row before re-creating.
* @var int $created_by Override created_by user id on the inserted row.
* @var int $ticket_type Default 1. Stored on the inserted claim_files row.
* @var array $include_file_types Default [2, 3].
* @var array $include_file_types Default [1, 2, 3].
* @var array $include_mime_types Default ['application/pdf', 'image/jpeg', 'image/png'].
* }
* @return array {status, merged_file_id, file_name, pages, source_count, message}
@ -39,7 +39,7 @@ if (! function_exists('merge_ticket_pdfs')) {
'replace' => true,
'created_by' => null,
'ticket_type' => 1,
'include_file_types' => [2, 3],
'include_file_types' => [1, 2],
'include_mime_types' => ['application/pdf', 'image/jpeg', 'image/png'],
];
@ -107,6 +107,16 @@ if (! function_exists('merge_ticket_pdfs')) {
}
$result['source_count'] = count($sourceFiles);
log_message(
'error',
'merge_ticket_pdfs | source files resolved | ticket_id=' . $ticket_master_id . ' | sources=' . json_encode(array_map(static function ($sourceFile) {
return [
'id' => $sourceFile['id'],
'mime' => $sourceFile['mime'],
'file' => basename($sourceFile['path']),
];
}, $sourceFiles))
);
$tempDir = rtrim(WRITEPATH, '/\\') . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'mpdf';
if (! is_dir($tempDir)) {
@ -135,9 +145,11 @@ if (! function_exists('merge_ticket_pdfs')) {
$mpdf->useTemplate($tplId, 0, 0, null, null, true);
$totalPages++;
}
log_message('error', "merge_ticket_pdfs | added PDF | file={$src} | pages={$pageCount}");
} elseif (in_array($sourceFile['mime'], ['image/jpeg', 'image/png'], true)) {
if (merge_ticket_pdf_add_image_page($mpdf, $src)) {
$totalPages++;
log_message('error', "merge_ticket_pdfs | added image | file={$src} | mime={$sourceFile['mime']}");
}
} else {
log_message('error', "merge_ticket_pdfs | unsupported source mime {$sourceFile['mime']} | {$src}");
@ -266,6 +278,7 @@ if (! function_exists('merge_ticket_pdf_add_image_page')) {
$imageWidthPx = (int) $imageInfo[0];
$imageHeightPx = (int) $imageInfo[1];
$imageType = ((int) ($imageInfo[2] ?? 0) === IMAGETYPE_PNG) ? 'png' : 'jpg';
$isLandscape = $imageWidthPx > $imageHeightPx;
$pageWidth = $isLandscape ? 297 : 210;
@ -291,7 +304,7 @@ if (! function_exists('merge_ticket_pdf_add_image_page')) {
'margin-footer' => 0,
]);
$mpdf->Image($imagePath, $x, $y, $drawWidth, $drawHeight);
$mpdf->Image($imagePath, $x, $y, $drawWidth, $drawHeight, $imageType);
return true;
}
}