3Z4LPN - ganti flag stemcell ke table baru

- Tambah validasi nat_groupid = 7 di save() walk_in_registration_stemcell/Order.php sebelum transaksi dimulai
- Tambah insert ke t_orderstemcell saat order dari cabang stemcell berhasil disimpan
- Ganti referensi M_BranchIsSteemCell di Transactionv4 dan Transactionv5 ke EXISTS/NOT EXISTS pada t_orderstemcell
- Tambah SQL DDL tabel t_orderstemcell di sql/t_orderstemcell.sql
This commit is contained in:
sas.fajri
2026-06-30 10:38:59 +07:00
parent a6fa405dd4
commit 5e7705ee2e
4 changed files with 84 additions and 22 deletions

View File

@@ -250,7 +250,7 @@ class Order extends MY_Controller
}
$userid = $this->sys_user["M_UserID"];
$sql = "SELECT M_UserLoginM_BranchID as branch_id, M_BranchCodeLab as branch_code_lab, M_BranchCodeBridging as branch_code_bridging
$sql = "SELECT M_UserLoginM_BranchID as branch_id, M_BranchCodeLab as branch_code_lab, M_BranchCodeBridging as branch_code_bridging, M_BranchIsSteemCell as is_stemcell
FROM m_user
JOIN m_branch ON M_UserLoginM_BranchID = M_BranchID AND M_BranchIsActive = 'Y'
WHERE M_UserID = $userid";
@@ -263,6 +263,7 @@ class Order extends MY_Controller
$branch_id = $dt_branch['branch_id'];
$branch_code_lab = $dt_branch['branch_code_lab'];
$branch_code_bridging = $dt_branch['branch_code_bridging'];
$branch_is_stemcell = isset($dt_branch['is_stemcell']) ? $dt_branch['is_stemcell'] : 'N';
$pre_registerid = isset($prm['preid']) ? $prm['preid'] : 0;
$header = $prm['header'];
$header['pre_register_id'] = $pre_registerid;
@@ -311,6 +312,32 @@ class Order extends MY_Controller
}
}
if ($branch_is_stemcell == 'Y') {
$test_ids_to_check = array_values(array_unique(array_map('intval', array_column($details, 't_id'))));
$test_ids_to_check = array_filter($test_ids_to_check, function($id) { return $id > 0; });
if (!empty($test_ids_to_check)) {
$ids_str = implode(',', $test_ids_to_check);
$sql_check = "SELECT T_TestID, T_TestName, T_TestNat_GroupID FROM t_test WHERE T_TestID IN ($ids_str)";
$query_check = $this->db_smartone->query($sql_check);
if (!$query_check) {
$this->sys_error_db(["status" => "ERR", "message" => "check nat_group stemcell | " . $this->db_smartone->error()["message"], "debug" => $this->db_smartone->last_query()]);
exit;
}
$rows_check = $query_check->result_array();
$invalid_tests = [];
foreach ($rows_check as $row_check) {
if ((int)$row_check['T_TestNat_GroupID'] !== 7) {
$invalid_tests[] = $row_check['T_TestName'];
}
}
if (!empty($invalid_tests)) {
$this->sys_error("Cabang dan pemeriksaan tidak sesuai. Cek pemeriksaan, harus group stemcell. Pemeriksaan tidak valid: " . implode(', ', $invalid_tests));
exit;
}
}
}
$this->db_smartone->trans_begin();
$sql = "SELECT M_DoctorID, M_DoctorName, M_DoctorPjIsDefaultPJ
@@ -384,6 +411,24 @@ class Order extends MY_Controller
exit;
}
if ($branch_is_stemcell == 'Y') {
$sql_stemcell = "INSERT INTO t_orderstemcell (
T_OrderStemcellT_OrderHeaderID,
T_OrderStemcellCreated,
T_OrderStemcellCreatedUserID
) VALUES (?, NOW(), ?)";
$query_stemcell = $this->db_smartone->query($sql_stemcell, [$header_id, $userid]);
if (!$query_stemcell) {
$this->db_smartone->trans_rollback();
$this->insert_log_error($this->db_smartone->last_query(), ['INSERT_T_ORDERSTEMCELL', 'order/save'], [
'header_id' => $header_id,
'error' => $this->db_smartone->error()
]);
$this->sys_error_db(["status" => "ERR", "message" => "error insert t_orderstemcell | " . $this->db_smartone->error()["message"], "debug" => $this->db_smartone->last_query()]);
exit;
}
}
$references = [];
if (isset($prm['reference'])) {
$references = $prm['reference'];