Files
BE_IBL/application/controllers/tools/Merge_report.php
2026-05-29 16:33:00 +07:00

63 lines
2.2 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Merge_report extends MY_Controller {
public function __construct() {
parent::__construct();
$this->load->library('Ibl_merge_report_gateway');
}
public function get($id = null) {
$this->preview($id);
}
public function preview_qr($id = null) {
if ($id === null || !is_numeric($id)) {
header('Content-Type: application/json');
echo json_encode(['status' => 'ERR', 'message' => 'T_ORDER_HEADER_ID_INVALID - ID tidak valid.']);
return;
}
$result = $this->ibl_merge_report_gateway->stream_from_qr_printout((int) $id);
if ($result['status'] !== 'OK') {
header('Content-Type: application/json');
echo json_encode(['status' => 'ERR', 'message' => $result['code'] . ' - ' . $result['message']]);
return;
}
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="' . $result['data']['payload']['name'] . '"');
echo $result['data']['body'];
}
public function preview($id = null) {
if ($id === null || !is_numeric($id)) {
header('Content-Type: application/json');
echo json_encode([
'status' => 'ERR',
'message' => 'MERGE_REQUEST_ID_INVALID - mergeRequestID tidak valid.'
]);
return;
}
$labNumber = isset($_GET['T_OrderHeaderLabNumber']) ? trim($_GET['T_OrderHeaderLabNumber']) : '';
if ($labNumber === '' && isset($_GET['nolab'])) {
$labNumber = trim($_GET['nolab']);
}
$result = $this->ibl_merge_report_gateway->stream_merge_request((int) $id, $labNumber);
if ($result['status'] !== 'OK') {
header('Content-Type: application/json');
echo json_encode([
'status' => 'ERR',
'message' => $result['code'] . ' - ' . $result['message']
]);
return;
}
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="' . $result['data']['payload']['name'] . '"');
echo $result['data']['body'];
}
}