diff --git a/.gitignore b/.gitignore index 5582c47..901ecf9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ vendor/ .cursor/ .DS_Store composer.phar +.env diff --git a/application/controllers/ais/Masterdata.php b/application/controllers/ais/Masterdata.php index 89e3220..961e216 100644 --- a/application/controllers/ais/Masterdata.php +++ b/application/controllers/ais/Masterdata.php @@ -3,6 +3,7 @@ class Masterdata extends MY_Controller { var $db_onedev; + private $force_debug_ais_payload = false; public function index() { echo "Resultentry API"; @@ -40,6 +41,41 @@ class Masterdata extends MY_Controller return true; } + public function build_curl_command($url, $data = array(), $headers = array(), $method = 'POST') + { + $default_headers = array('Content-Type: application/json'); + $final_headers = array_merge($default_headers, $headers); + $body = json_encode($data); + $parts = array('curl', '-X', $method, escapeshellarg($url)); + foreach ($final_headers as $h) { + $parts[] = '-H'; + $parts[] = escapeshellarg($h); + } + $parts[] = '-d'; + $parts[] = escapeshellarg($body); + return implode(' ', $parts); + } + + private function should_debug_ais_payload() + { + return $this->force_debug_ais_payload === true; + } + + private function debug_ais_payload_response($sourceEndpoint, $method, $url, $headers, $payload) + { + $this->sys_ok(array( + 'status' => 'debug', + 'message' => 'Debug payload only, request not sent to AIS', + 'source_endpoint' => $sourceEndpoint, + 'target_method' => $method, + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $payload, + 'curl_command' => $this->build_curl_command($url, $payload, $headers, $method) + )); + exit; + } + /** * Generic POST request function * @param string $url API endpoint URL @@ -202,6 +238,17 @@ class Masterdata extends MY_Controller public function post_auth() { $dt_config = $this->get_config(); + if ($this->should_debug_ais_payload()) { + return array( + 'success' => true, + 'debug' => true, + 'message' => 'Debug payload only, auth request not sent to AIS', + 'data' => array( + 'username' => $dt_config['AisConfigUsername'], + 'base_url' => $dt_config['AisConfigBaseUrl'] + ) + ); + } $baseUrl = $dt_config['AisConfigBaseUrl']; $url = $baseUrl . '/api/auth/auth.php'; $headers = array( @@ -315,8 +362,9 @@ class Masterdata extends MY_Controller public function post_cost_center() { $userid = 999; + $debugPayload = $this->should_debug_ais_payload(); // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log(array('fn_name' => 'post_cost_center', 'message' => 'failed auth', 'query' => '', 'json' => json_encode($login)), 999); $errors = array('status' => 'error', 'message' => 'Gagal Login'); @@ -365,6 +413,24 @@ class Masterdata extends MY_Controller ); foreach ($raw_data as $row) { $data = $row; + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_cost_center', + 'debug_steps' => array( + array( + 'step' => 'post_cost_center', + 'target_method' => 'POST', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'POST') + ) + ) + )); + exit; + } $result = $this->post_request($url, $data, $headers); if (!$result['success']) { $this->error_log(array('fn_name' => 'post_profit_center', 'message' => 'profit_center insert', 'query' => $this->db_onedev->last_query(), 'json' => json_encode($result)), 999); @@ -388,8 +454,9 @@ class Masterdata extends MY_Controller public function post_profit_center() { $userid = 999; + $debugPayload = $this->should_debug_ais_payload(); // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log(array('fn_name' => 'post_profit_center', 'message' => 'failed auth', 'query' => '', 'json' => json_encode($login)), 999); $errors = array('status' => 'error', 'message' => 'Gagal Login'); @@ -424,6 +491,24 @@ class Masterdata extends MY_Controller 'status' => 'active' ); + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_profit_center', + 'debug_steps' => array( + array( + 'step' => 'post_profit_center', + 'target_method' => 'POST', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'POST') + ) + ) + )); + exit; + } $result = $this->post_request($url, $data, $headers); if (!$result['success']) { $this->error_log(array('fn_name' => 'post_profit_center', 'message' => 'profit_center insert', 'query' => $this->db_onedev->last_query(), 'json' => json_encode($result)), 999); @@ -452,8 +537,9 @@ class Masterdata extends MY_Controller public function post_jenis_layanan() { $userid = 999; + $debugPayload = $this->should_debug_ais_payload(); // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log(array('fn_name' => 'post_jenis_layanan', 'message' => 'failed auth', 'query' => '', 'json' => json_encode($login)), 999); $errors = array('status' => 'error', 'message' => 'Gagal Login'); @@ -489,6 +575,24 @@ class Masterdata extends MY_Controller 'TanggalBuat' => $row['Nat_GroupCreated'] ); + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_jenis_layanan', + 'debug_steps' => array( + array( + 'step' => 'post_jenis_layanan', + 'target_method' => 'POST', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'POST') + ) + ) + )); + exit; + } $result = $this->post_request($url, $data, $headers); if (!$result['success']) { $this->error_log(array('fn_name' => 'post_jenis_layanan', 'message' => 'jenislayanan insert', 'query' => $this->db_onedev->last_query(), 'json' => json_encode($result)), 999); @@ -536,8 +640,9 @@ class Masterdata extends MY_Controller public function post_tipe_bayar() { $userid = 999; + $debugPayload = $this->should_debug_ais_payload(); // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log(array('fn_name' => 'post_tipe_bayar', 'message' => 'failed auth', 'query' => '', 'json' => json_encode($login)), 999); $errors = array('status' => 'error', 'message' => 'Gagal Login'); @@ -620,6 +725,24 @@ class Masterdata extends MY_Controller $errors = array(); //echo json_encode($datas); exit; foreach ($datas as $data) { + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_tipe_bayar', + 'debug_steps' => array( + array( + 'step' => 'post_tipe_bayar', + 'target_method' => 'POST', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'POST') + ) + ) + )); + exit; + } $result = $this->post_request($url, $data, $headers); $status = 'success'; if (!$result['success']) { @@ -733,8 +856,9 @@ class Masterdata extends MY_Controller public function post_jenis_perusahaan() { $userid = 999; + $debugPayload = $this->should_debug_ais_payload(); // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log(array('fn_name' => 'post_jenis_perusahaan_auth', 'message' => 'failed auth', 'query' => '', 'json' => json_encode($login)), 999); $errors = array('status' => 'error', 'message' => 'Gagal Login'); @@ -768,6 +892,24 @@ class Masterdata extends MY_Controller 'TanggalBuat' => $row['CorporateTypeCreated'] ); + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_jenis_perusahaan', + 'debug_steps' => array( + array( + 'step' => 'post_jenis_perusahaan', + 'target_method' => 'POST', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'POST') + ) + ) + )); + exit; + } $result = $this->post_request($url, $data, $headers); if (!$result['success']) { $this->error_log(array('fn_name' => 'post_jenis_perusahaan', 'message' => 'failed insert jenis perusahaan', 'query' => $this->db_onedev->last_query(), 'json' => json_encode($result)), 999); @@ -784,8 +926,9 @@ class Masterdata extends MY_Controller public function post_pillar() { $userid = 999; + $debugPayload = $this->should_debug_ais_payload(); // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log(array('fn_name' => 'post_pillar_auth', 'message' => 'failed auth', 'query' => '', 'json' => json_encode($login)), 999); $errors = array('status' => 'error', 'message' => 'Gagal Login'); @@ -819,6 +962,24 @@ class Masterdata extends MY_Controller 'status' => 'active' ); + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_pillar', + 'debug_steps' => array( + array( + 'step' => 'post_pillar', + 'target_method' => 'POST', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'POST') + ) + ) + )); + exit; + } $result = $this->post_request($url, $data, $headers); if (!$result['success']) { $this->error_log(array('fn_name' => 'post_pillar', 'message' => 'failed insert pillar', 'query' => $this->db_onedev->last_query(), 'json' => json_encode($result)), 999); @@ -880,8 +1041,9 @@ class Masterdata extends MY_Controller public function post_branch() { $userid = 999; + $debugPayload = $this->should_debug_ais_payload(); // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log(array('fn_name' => 'post_branch_auth', 'message' => 'failed auth', 'query' => '', 'json' => json_encode($login)), 999); $errors = array('status' => 'error', 'message' => 'Gagal Login'); @@ -917,6 +1079,24 @@ class Masterdata extends MY_Controller 'status' => 'active' ); + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_branch', + 'debug_steps' => array( + array( + 'step' => 'post_branch', + 'target_method' => 'POST', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'POST') + ) + ) + )); + exit; + } $result = $this->post_request($url, $data, $headers); if (!$result['success']) { $this->error_log(array('fn_name' => 'post_pillar', 'message' => 'failed insert pillar', 'query' => $this->db_onedev->last_query(), 'json' => json_encode($result)), 999); @@ -940,11 +1120,11 @@ class Masterdata extends MY_Controller public function post_perusahaan_by_code() { $userid = 999; - + $debugPayload = $this->should_debug_ais_payload(); $prm = $this->sys_input; $corporate_code = $prm['corporate_code'] ?? null; // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log(array('fn_name' => 'post_perusahaan_auth', 'message' => 'failed auth', 'query' => '', 'json' => json_encode($login)), 999); $errors = array('status' => 'error', 'message' => 'Gagal Login'); @@ -1016,6 +1196,24 @@ class Masterdata extends MY_Controller "TanggalBuat" => $row['CorporateCreated'] ); + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_perusahaan_by_code', + 'debug_steps' => array( + array( + 'step' => 'post_perusahaan', + 'target_method' => 'POST', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'POST') + ) + ) + )); + exit; + } $result = $this->post_request($url, $data, $headers); if (!$result['success']) { $errors[] = array('PerusahaanID' => $row['CorporateCode'], 'error' => $result['message']); @@ -1057,11 +1255,11 @@ class Masterdata extends MY_Controller public function re_post_perusahaan_by_code() { $userid = 999; - + $debugPayload = $this->should_debug_ais_payload(); $prm = $this->sys_input; $corporate_code = $prm['corporate_code'] ?? null; // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log(array('fn_name' => 're_post_perusahaan_auth', 'message' => 'failed auth', 'query' => '', 'json' => json_encode($login)), 999); $errors = array('status' => 'error', 'message' => 'Gagal Login'); @@ -1124,6 +1322,24 @@ class Masterdata extends MY_Controller "TanggalBuat" => $row['CorporateCreated'] ); + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/re_post_perusahaan_by_code', + 'debug_steps' => array( + array( + 'step' => 'put_perusahaan', + 'target_method' => 'PUT', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'PUT') + ) + ) + )); + exit; + } $result = $this->put_request($url, $data, $headers); if (!$result['success']) { $errors[] = array('PerusahaanID' => $row['CorporateCode'], 'error' => $result['message']); @@ -1180,9 +1396,10 @@ class Masterdata extends MY_Controller public function post_perusahaan_all() { $userid = 999; + $debugPayload = $this->should_debug_ais_payload(); // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log(array('fn_name' => 'post_perusahaan_auth', 'message' => 'failed auth', 'query' => '', 'json' => json_encode($login)), 999); $errors = array('status' => 'error', 'message' => 'Gagal Login'); @@ -1272,6 +1489,26 @@ class Masterdata extends MY_Controller ); // Use PUT request if perusahaan exists, otherwise use POST request + if ($debugPayload) { + $dbgMethod = $is_existing ? 'PUT' : 'POST'; + $dbgStep = $is_existing ? 'put_perusahaan' : 'post_perusahaan'; + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_perusahaan_all', + 'debug_steps' => array( + array( + 'step' => $dbgStep, + 'target_method' => $dbgMethod, + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, $dbgMethod) + ) + ) + )); + exit; + } if ($is_existing) { $result = $this->put_request($url, $data, $headers); $type = 'UPDATE'; @@ -1352,9 +1589,10 @@ class Masterdata extends MY_Controller public function post_perusahaan_bulk() { $userid = 999; + $debugPayload = $this->should_debug_ais_payload(); // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log([ 'fn_name' => 'post_perusahaan_bulk_auth', @@ -1500,6 +1738,24 @@ class Masterdata extends MY_Controller } // Kirim ke API + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_perusahaan_bulk', + 'debug_steps' => array( + array( + 'step' => 'post_perusahaan_bulk', + 'target_method' => 'POST', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $payload, + 'curl_command' => $this->build_curl_command($url, $payload, $headers, 'POST') + ) + ) + )); + exit; + } $result = $this->post_request($url, $payload, $headers); if (!$result['success']) { @@ -1554,12 +1810,13 @@ class Masterdata extends MY_Controller public function edit_perusahaan() { $userid = 999; + $debugPayload = $this->should_debug_ais_payload(); $prm = $this->sys_input; $id = $prm['PerusahaanID']; // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log([ 'fn_name' => 'post_perusahaan_bulk_auth', @@ -1638,6 +1895,24 @@ class Masterdata extends MY_Controller ); + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/edit_perusahaan', + 'debug_steps' => array( + array( + 'step' => 'put_perusahaan', + 'target_method' => 'PUT', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'PUT') + ) + ) + )); + exit; + } $result = $this->put_request($url, $data, $headers); if (!$result['success']) { $this->error_log(array('fn_name' => 'put_perusahaan', 'message' => 'failed edit perusahaan', 'query' => $this->db_onedev->last_query(), 'json' => json_encode($result)), $userid); @@ -1695,9 +1970,10 @@ class Masterdata extends MY_Controller public function post_jenislayanan() { $userid = 999; + $debugPayload = $this->should_debug_ais_payload(); // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log(array('fn_name' => 'post_jenis_layanan_auth', 'message' => 'failed auth', 'query' => '', 'json' => json_encode($login)), $userid); $errors = array('status' => 'error', 'message' => 'Gagal Login'); @@ -1751,6 +2027,24 @@ class Masterdata extends MY_Controller "TanggalBuat" => $row['Nat_TestCreated'] ); + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_jenislayanan', + 'debug_steps' => array( + array( + 'step' => 'post_jenislayanan', + 'target_method' => 'POST', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'POST') + ) + ) + )); + exit; + } $result = $this->post_request($url, $data, $headers); echo json_encode($result); exit; @@ -1855,12 +2149,12 @@ class Masterdata extends MY_Controller public function post_layanan_by_code() { $userid = 999; - + $debugPayload = $this->should_debug_ais_payload(); $prm = $this->sys_input; $layanan_code = $prm['layanan_code'] ?? null; // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log([ 'fn_name' => 'post_layanan_auth', @@ -1924,6 +2218,24 @@ class Masterdata extends MY_Controller "SubGroupLayanan2ID" => $row['T_TestSasCode'] ]; + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_layanan_by_code', + 'debug_steps' => array( + array( + 'step' => 'post_layanan', + 'target_method' => 'POST', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'POST') + ) + ) + )); + exit; + } $result = $this->post_request($url, $data, $headers); if ($result['error'] == null && $result['success'] == true) { $result_data[] = $data; @@ -1976,12 +2288,12 @@ class Masterdata extends MY_Controller public function re_post_layanan_by_code() { $userid = 999; - + $debugPayload = $this->should_debug_ais_payload(); $prm = $this->sys_input; $layanan_code = $prm['layanan_code'] ?? null; // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log([ 'fn_name' => 're_post_layanan_auth', @@ -2045,6 +2357,24 @@ class Masterdata extends MY_Controller "SubGroupLayanan2ID" => $row['T_TestSasCode'] ]; + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/re_post_layanan_by_code', + 'debug_steps' => array( + array( + 'step' => 'put_layanan', + 'target_method' => 'PUT', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'PUT') + ) + ) + )); + exit; + } $result = $this->put_request($url, $data, $headers); if ($result['error'] == null && $result['success'] == true) { $result_data[] = $data; @@ -2098,9 +2428,10 @@ class Masterdata extends MY_Controller public function post_layanan_all() { $userid = 999; + $debugPayload = $this->should_debug_ais_payload(); // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log([ 'fn_name' => 'post_layanan_auth', @@ -2163,6 +2494,24 @@ class Masterdata extends MY_Controller "SubGroupLayanan2ID" => $row['T_TestSasCode'] ]; + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_layanan_all', + 'debug_steps' => array( + array( + 'step' => 'post_layanan', + 'target_method' => 'POST', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'POST') + ) + ) + )); + exit; + } $result = $this->post_request($url, $data, $headers); if ($result['error'] == null && $result['success'] == true) { $result_data[] = $data; @@ -2215,12 +2564,12 @@ class Masterdata extends MY_Controller public function edit_layanan() { $userid = 999; - + $debugPayload = $this->should_debug_ais_payload(); $prm = $this->sys_input; $layanan_code = $prm['layanan_code'] ?? null; // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log([ 'fn_name' => 'post_layanan_auth', @@ -2281,6 +2630,24 @@ class Masterdata extends MY_Controller "SubGroupLayanan2ID" => $row['T_TestSasCode'] ]; + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/edit_layanan', + 'debug_steps' => array( + array( + 'step' => 'put_layanan', + 'target_method' => 'PUT', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'PUT') + ) + ) + )); + exit; + } $result = $this->put_request($url, $data, $headers); if ($result['error'] == null && $result['success'] == true) { $result_data[] = $data; @@ -2367,9 +2734,10 @@ class Masterdata extends MY_Controller public function post_grouplayanan() { $userid = 999; + $debugPayload = $this->should_debug_ais_payload(); // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log([ 'fn_name' => 'post_grouplayanan_auth', @@ -2425,6 +2793,24 @@ class Masterdata extends MY_Controller "TanggalBuat" => $row['Nat_GroupCreated'] ]; + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_grouplayanan', + 'debug_steps' => array( + array( + 'step' => 'post_grouplayanan', + 'target_method' => 'POST', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'POST') + ) + ) + )); + exit; + } $result = $this->post_request($url, $data, $headers); if (!$result['success']) { @@ -2520,9 +2906,10 @@ class Masterdata extends MY_Controller public function post_departemen() { $userid = 999; + $debugPayload = $this->should_debug_ais_payload(); // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log([ 'fn_name' => 'post_departemen_auth', @@ -2586,6 +2973,24 @@ class Masterdata extends MY_Controller "TanggalBuat" => $row['DepartemenTanggalBuat'] ]; + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_departemen', + 'debug_steps' => array( + array( + 'step' => 'post_departemen', + 'target_method' => 'POST', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'POST') + ) + ) + )); + exit; + } $result = $this->post_request($url, $data, $headers); if (!$result['success']) { @@ -2649,7 +3054,7 @@ class Masterdata extends MY_Controller $dt_config = $this->get_config(); $baseUrl = $dt_config['AisConfigBaseUrl']; - $url = $baseUrl . 'api/paket?id=' . $packet_code; + $url = $baseUrl . '/api/paket?id=' . $packet_code; $result = $this->get_request($url); @@ -2685,7 +3090,7 @@ class Masterdata extends MY_Controller $dt_config = $this->get_config(); $baseUrl = $dt_config['AisConfigBaseUrl']; - $url = $baseUrl . 'api/paket?id=' . $packet_code; + $url = $baseUrl . '/api/paket?id=' . $packet_code; $result = $this->get_request($url); @@ -2714,11 +3119,12 @@ class Masterdata extends MY_Controller try { $userid = 999; + $debugPayload = $this->should_debug_ais_payload(); $prm = $this->sys_input; $packet_code = $prm['packet_code'] ?? null; // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!isset($login['success']) || !$login['success']) { ob_clean(); // Clear any output $this->error_log([ @@ -2806,6 +3212,26 @@ class Masterdata extends MY_Controller $rst = $this->get_packet_by_code_private($row['T_PacketSasCode']); + if ($debugPayload) { + ob_clean(); + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_packet_all', + 'debug_steps' => array( + array( + 'step' => 'post_packet', + 'target_method' => 'POST', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'POST') + ) + ) + ), JSON_UNESCAPED_UNICODE); + exit; + } + if (!$rst) $result = $this->post_request($url, $data, $headers); @@ -2881,11 +3307,12 @@ class Masterdata extends MY_Controller try { $userid = 999; + $debugPayload = $this->should_debug_ais_payload(); $prm = $this->sys_input; //$packet_code = $prm['packet_code'] ?? null; // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!isset($login['success']) || !$login['success']) { ob_clean(); // Clear any output $this->error_log([ @@ -2971,6 +3398,25 @@ class Masterdata extends MY_Controller "TanggalBuat" => isset($row['T_PacketCreated']) ? $row['T_PacketCreated'] : "" ]; + if ($debugPayload) { + ob_clean(); + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_packet_by_code_private', + 'debug_steps' => array( + array( + 'step' => 'post_packet', + 'target_method' => 'POST', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'POST') + ) + ) + ), JSON_UNESCAPED_UNICODE); + exit; + } $result = $this->post_request($url, $data, $headers); if (!isset($result['success']) || !$result['success']) { @@ -3042,11 +3488,12 @@ class Masterdata extends MY_Controller try { $userid = 999; + $debugPayload = $this->should_debug_ais_payload(); $prm = $this->sys_input; $packet_code = $prm['packet_code'] ?? null; // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!isset($login['success']) || !$login['success']) { ob_clean(); // Clear any output $this->error_log([ @@ -3132,6 +3579,25 @@ class Masterdata extends MY_Controller "TanggalBuat" => isset($row['T_PacketCreated']) ? $row['T_PacketCreated'] : "" ]; + if ($debugPayload) { + ob_clean(); + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_packet_by_code', + 'debug_steps' => array( + array( + 'step' => 'post_packet', + 'target_method' => 'POST', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'POST') + ) + ) + ), JSON_UNESCAPED_UNICODE); + exit; + } $result = $this->post_request($url, $data, $headers); //echo $url; //echo json_encode($result); @@ -3217,11 +3683,12 @@ class Masterdata extends MY_Controller try { $userid = 999; + $debugPayload = $this->should_debug_ais_payload(); $prm = $this->sys_input; $packet_code = $prm['packet_code'] ?? null; // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!isset($login['success']) || !$login['success']) { ob_clean(); // Clear any output $this->error_log([ @@ -3307,6 +3774,25 @@ class Masterdata extends MY_Controller "TanggalBuat" => isset($row['T_PacketCreated']) ? $row['T_PacketCreated'] : "" ]; + if ($debugPayload) { + ob_clean(); + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/re_post_packet_by_code', + 'debug_steps' => array( + array( + 'step' => 'put_packet', + 'target_method' => 'PUT', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'PUT') + ) + ) + ), JSON_UNESCAPED_UNICODE); + exit; + } $result = $this->put_request($url, $data, $headers); if (!isset($result['success']) || !$result['success']) { @@ -3386,11 +3872,12 @@ class Masterdata extends MY_Controller try { $userid = 999; + $debugPayload = $this->should_debug_ais_payload(); $prm = $this->sys_input; //$packet_code = $prm['packet_code'] ?? null; // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!isset($login['success']) || !$login['success']) { ob_clean(); // Clear any output $this->error_log([ @@ -3474,6 +3961,25 @@ class Masterdata extends MY_Controller "TanggalBuat" => isset($row['T_PacketCreated']) ? $row['T_PacketCreated'] : "" ]; + if ($debugPayload) { + ob_clean(); + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/re_post_packet_by_code_private', + 'debug_steps' => array( + array( + 'step' => 'put_packet', + 'target_method' => 'PUT', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'PUT') + ) + ) + ), JSON_UNESCAPED_UNICODE); + exit; + } $result = $this->put_request($url, $data, $headers); if (!isset($result['success']) || !$result['success']) { @@ -3532,13 +4038,27 @@ class Masterdata extends MY_Controller } + private function fetch_doctor_from_ais($doctor_code, $baseUrl, $headers) + { + $url = $baseUrl . '/api/dokter?id=' . $doctor_code; + $result = $this->get_request($url, $headers); + if (!$result['success']) { + return null; + } + $data = $result['response']['data'] ?? null; + if (empty($data)) { + return null; + } + return $data; + } + public function post_doctor_all() { $userid = 555; - + $debugPayload = $this->should_debug_ais_payload(); // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log([ 'fn_name' => 'post_doctor_all_auth', @@ -3598,6 +4118,31 @@ class Masterdata extends MY_Controller "Email" => $row['M_DoctorEmail'] ]; + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_doctor_all', + 'debug_steps' => array( + array( + 'step' => 'post_doctor', + 'target_method' => 'POST', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'POST') + ) + ) + )); + exit; + } + + $existing = $this->fetch_doctor_from_ais($row['M_DoctorCode'], $baseUrl, $headers); + if (!empty($existing)) { + $return_data[] = array_merge($data, ['_ais_status' => 'skipped', '_ais_note' => 'dokter sudah ada di AIS']); + continue; + } + $result = $this->post_request($url, $data, $headers); $status = $result['error'] == null ? 'success' : 'error'; @@ -3641,11 +4186,12 @@ class Masterdata extends MY_Controller public function re_post_doctor_by_code() { $userid = 555; + $debugPayload = $this->should_debug_ais_payload(); $prm = $this->sys_input; $doctor_code = $prm['doctor_code'] ?? null; // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log([ 'fn_name' => 're_post_doctor_by_code_auth', @@ -3705,6 +4251,24 @@ class Masterdata extends MY_Controller "Email" => $row['M_DoctorEmail'] ]; + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/re_post_doctor_by_code', + 'debug_steps' => array( + array( + 'step' => 'put_doctor', + 'target_method' => 'PUT', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'PUT') + ) + ) + )); + exit; + } $result = $this->put_request($url, $data, $headers); $status = $result['error'] == null ? 'success' : 'error'; @@ -3748,11 +4312,12 @@ class Masterdata extends MY_Controller public function post_doctor_by_code() { $userid = 555; + $debugPayload = $this->should_debug_ais_payload(); $prm = $this->sys_input; $doctor_code = $prm['doctor_code'] ?? null; // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log([ 'fn_name' => 'post_doctor_by_code_auth', @@ -3778,7 +4343,7 @@ class Masterdata extends MY_Controller FROM m_doctor LEFT JOIN m_specialist ON M_DoctorM_SpecialistID = M_SpecialistID AND M_SpecialistIsActive = 'Y' LEFT JOIN cpone_log.ais_doctor ON m_doctor.M_DoctorID = ais_doctor.Ais_DoctorM_DoctorID - WHERE M_DoctorIsActive = 'Y' AND ais_doctor.Ais_DoctorM_DoctorID IS NULL AND M_DoctorCode = ? LIMIT 1"; + WHERE M_DoctorIsActive = 'Y' AND M_DoctorCode = ? LIMIT 1"; $qry = $this->db_onedev->query($sql, [$doctor_code]); if (!$qry) { $this->error_log([ @@ -3812,6 +4377,24 @@ class Masterdata extends MY_Controller "Email" => $row['M_DoctorEmail'] ]; + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_doctor_by_code', + 'debug_steps' => array( + array( + 'step' => 'post_doctor', + 'target_method' => 'POST', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'POST') + ) + ) + )); + exit; + } $result = $this->post_request($url, $data, $headers); $status = $result['error'] == null ? 'success' : 'error'; @@ -3868,7 +4451,7 @@ class Masterdata extends MY_Controller $dt_config = $this->get_config(); $baseUrl = $dt_config['AisConfigBaseUrl']; - $url = $baseUrl . 'api/dokter?id=' . $doctor_code; + $url = $baseUrl . '/api/dokter?id=' . $doctor_code; $result = $this->get_request($url); @@ -3906,7 +4489,7 @@ class Masterdata extends MY_Controller $dt_config = $this->get_config(); $baseUrl = $dt_config['AisConfigBaseUrl']; - $url = $baseUrl . 'api/medrec?id=' . $noreg; + $url = $baseUrl . '/api/medrec?id=' . $noreg; $result = $this->get_request($url); @@ -3929,12 +4512,12 @@ class Masterdata extends MY_Controller public function post_medrec_by_noreg() { $userid = 999; - + $debugPayload = $this->should_debug_ais_payload(); $prm = $this->sys_input; $noreg = $prm['noreg'] ?? null; // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log([ 'fn_name' => 'post_medrec_auth', @@ -4008,6 +4591,24 @@ class Masterdata extends MY_Controller ]; + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_medrec_by_noreg', + 'debug_steps' => array( + array( + 'step' => 'post_medrec', + 'target_method' => 'POST', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'POST') + ) + ) + )); + exit; + } $result = $this->post_request($url, $data, $headers); @@ -4056,12 +4657,12 @@ class Masterdata extends MY_Controller public function re_post_medrec_by_noreg() { $userid = 999; - + $debugPayload = $this->should_debug_ais_payload(); $prm = $this->sys_input; $noreg = $prm['noreg'] ?? null; // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log([ 'fn_name' => 're_post_medrec_auth', @@ -4135,6 +4736,24 @@ class Masterdata extends MY_Controller ]; + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/re_post_medrec_by_noreg', + 'debug_steps' => array( + array( + 'step' => 'put_medrec', + 'target_method' => 'PUT', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'PUT') + ) + ) + )); + exit; + } $result = $this->put_request($url, $data, $headers); @@ -4228,10 +4847,10 @@ class Masterdata extends MY_Controller public function post_transaction() { $userid = 999; - + $debugPayload = $this->should_debug_ais_payload(); // Auth Login - $login = $this->post_auth(); + $login = $debugPayload ? array('success' => true) : $this->post_auth(); if (!$login['success']) { $this->error_log([ 'fn_name' => 'post_transaction_auth', @@ -4434,6 +5053,24 @@ class Masterdata extends MY_Controller "PaketDispenser" => null ]; + if ($debugPayload) { + echo json_encode(array( + 'status' => 'debug', + 'message' => 'Debug outbound AIS requests only, nothing sent', + 'source_endpoint' => 'masterdata/post_transaction', + 'debug_steps' => array( + array( + 'step' => 'post_transaction', + 'target_method' => 'POST', + 'target_url' => $url, + 'target_headers' => array_merge(array('Content-Type: application/json'), $headers), + 'target_payload' => $data, + 'curl_command' => $this->build_curl_command($url, $data, $headers, 'POST') + ) + ) + )); + exit; + } $result = $this->post_request($url, $data, $headers); if (!$result['success']) {