MERGE_UAT_CLAIM_PDF_MERGE&SALES_CR
This commit is contained in:
commit
2c2ab81ab8
@ -21,14 +21,14 @@ if (! function_exists('merge_ticket_pdfs')) {
|
|||||||
* - ticket_id = $ticket_master_id
|
* - ticket_id = $ticket_master_id
|
||||||
* - is_active = 1
|
* - is_active = 1
|
||||||
* - mime_type IN $opts['include_mime_types'] (default PDF/JPG/PNG)
|
* - 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 int $ticket_master_id
|
||||||
* @param array $opts {
|
* @param array $opts {
|
||||||
* @var bool $replace Default true. Soft-delete previous merged row before re-creating.
|
* @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 $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 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'].
|
* @var array $include_mime_types Default ['application/pdf', 'image/jpeg', 'image/png'].
|
||||||
* }
|
* }
|
||||||
* @return array {status, merged_file_id, file_name, pages, source_count, message}
|
* @return array {status, merged_file_id, file_name, pages, source_count, message}
|
||||||
@ -39,7 +39,7 @@ if (! function_exists('merge_ticket_pdfs')) {
|
|||||||
'replace' => true,
|
'replace' => true,
|
||||||
'created_by' => null,
|
'created_by' => null,
|
||||||
'ticket_type' => 1,
|
'ticket_type' => 1,
|
||||||
'include_file_types' => [2, 3],
|
'include_file_types' => [1, 2],
|
||||||
'include_mime_types' => ['application/pdf', 'image/jpeg', 'image/png'],
|
'include_mime_types' => ['application/pdf', 'image/jpeg', 'image/png'],
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -107,6 +107,16 @@ if (! function_exists('merge_ticket_pdfs')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$result['source_count'] = count($sourceFiles);
|
$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';
|
$tempDir = rtrim(WRITEPATH, '/\\') . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'mpdf';
|
||||||
if (! is_dir($tempDir)) {
|
if (! is_dir($tempDir)) {
|
||||||
@ -135,9 +145,11 @@ if (! function_exists('merge_ticket_pdfs')) {
|
|||||||
$mpdf->useTemplate($tplId, 0, 0, null, null, true);
|
$mpdf->useTemplate($tplId, 0, 0, null, null, true);
|
||||||
$totalPages++;
|
$totalPages++;
|
||||||
}
|
}
|
||||||
|
log_message('error', "merge_ticket_pdfs | added PDF | file={$src} | pages={$pageCount}");
|
||||||
} elseif (in_array($sourceFile['mime'], ['image/jpeg', 'image/png'], true)) {
|
} elseif (in_array($sourceFile['mime'], ['image/jpeg', 'image/png'], true)) {
|
||||||
if (merge_ticket_pdf_add_image_page($mpdf, $src)) {
|
if (merge_ticket_pdf_add_image_page($mpdf, $src)) {
|
||||||
$totalPages++;
|
$totalPages++;
|
||||||
|
log_message('error', "merge_ticket_pdfs | added image | file={$src} | mime={$sourceFile['mime']}");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log_message('error', "merge_ticket_pdfs | unsupported source mime {$sourceFile['mime']} | {$src}");
|
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];
|
$imageWidthPx = (int) $imageInfo[0];
|
||||||
$imageHeightPx = (int) $imageInfo[1];
|
$imageHeightPx = (int) $imageInfo[1];
|
||||||
|
$imageType = ((int) ($imageInfo[2] ?? 0) === IMAGETYPE_PNG) ? 'png' : 'jpg';
|
||||||
$isLandscape = $imageWidthPx > $imageHeightPx;
|
$isLandscape = $imageWidthPx > $imageHeightPx;
|
||||||
|
|
||||||
$pageWidth = $isLandscape ? 297 : 210;
|
$pageWidth = $isLandscape ? 297 : 210;
|
||||||
@ -291,7 +304,7 @@ if (! function_exists('merge_ticket_pdf_add_image_page')) {
|
|||||||
'margin-footer' => 0,
|
'margin-footer' => 0,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$mpdf->Image($imagePath, $x, $y, $drawWidth, $drawHeight);
|
$mpdf->Image($imagePath, $x, $y, $drawWidth, $drawHeight, $imageType);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user