diff --git a/application/controllers/map/CoaMapInventaris.php b/application/controllers/map/CoaMapInventaris.php new file mode 100644 index 0000000..89b8266 --- /dev/null +++ b/application/controllers/map/CoaMapInventaris.php @@ -0,0 +1,58 @@ +isLogin) { + throw new Exception(message: 'invalid token', code: 1); + } + $para = $this->sys_input; + $user = $this->sys_user; + + $this->db->trans_begin(); + $sql = "INSERT INTO coa_map_inventaris ( + CoaMapInventarisM_ItemID, + CoaMapInventarisHutangCoaID, + CoaMapInventarisHutangCoaNo, + CoaMapInventarisHutangCoaDesc, + CoaMapInventarisCreated, + CoaMapInventarisUserID + ) VALUES (?,?,?,?,NOW(),?)"; + $que = $this->db->query($sql, [ + $para['itemID'], + $para['HutangCoaID'], + $para['HutangCoaNo'], + $para['HutangCoaDesc'], + $user['M_UserID'] + ]); + if (!$que) { + $this->db->trans_rollback(); + throw new Exception(message: 'failed insert data', code: 2); + } + + $this->db->trans_commit(); + $this->sys_ok("OK"); + } catch (Exception $e) { + $message = "[Error] " . $e->getMessage(); + $code = $e->getCode(); + if ($code == 1) { + $this->sys_error($message); + } else { + $this->sys_error_db($message); + } + exit; + } + } +} diff --git a/application/controllers/map/Faclass.php b/application/controllers/map/Faclass.php new file mode 100644 index 0000000..a6fc672 --- /dev/null +++ b/application/controllers/map/Faclass.php @@ -0,0 +1,580 @@ +db_onedev = $this->load->database("onedev", true); + } + + // search + function search() + { + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $prm = $this->sys_input; + $search = isset($prm["search"]) ? trim($prm["search"]) : ''; + $search = ($search !== '') ? "%$search%" : "%%"; + + // $number_offset = ($prm["current_page"] > 0) ? ($prm["current_page"] - 1) * 20 : 0; + // $number_limit = 2; + $number_limit = 10; + $number_offset = ($prm["current_page"] > 0) ? ($prm["current_page"] - 1) * $number_limit : 0; + + $sql = "SELECT + f.Fa_ClassID, + IFNULL(f.Fa_ClassName, '') AS Fa_ClassName, + IFNULL(f.Fa_ClassCoaID, '') AS Fa_ClassCoaID, + IFNULL(f.Fa_ClassCoaAccountNo, '') AS Fa_ClassCoaAccountNo, + IFNULL(f.Fa_ClassCoaDesc, '') AS Fa_ClassCoaDesc, + IFNULL(f.Fa_ClassDepreCorp, 0.00) AS Fa_ClassDepreCorp, + IFNULL(f.Fa_ClassDepreGov, 0.00) AS Fa_ClassDepreGov, + IFNULL(f.Fa_ClassAccumDepreCoaID, 0) AS Fa_ClassAccumDepreCoaID, + IFNULL(f.Fa_ClassAccumDepreCoaAccountNo, '') AS Fa_ClassAccumDepreCoaAccountNo, + IFNULL(f.Fa_ClassAccumDepreCoaDesc, '') AS Fa_ClassAccumDepreCoaDesc, + IFNULL(f.Fa_ClassAccumNote, '') AS Fa_ClassAccumNote, + IFNULL(f.Fa_ClassAccumCreated, CURRENT_TIMESTAMP) AS Fa_ClassAccumCreated, + IFNULL(f.Fa_ClassAccumLastUpdated, CURRENT_TIMESTAMP) AS Fa_ClassAccumLastUpdated, + IFNULL(f.Fa_ClassIsActive, 'N') AS Fa_ClassIsActive, + IFNULL(f.Fa_ClassM_UserID, 0) AS Fa_ClassM_UserID, + + -- Data dari tabel coa untuk Class CoA + IFNULL(c_class.coaID, 0) AS ClassCoaID, + IFNULL(c_class.coaAccountNo, '') AS ClassCoaAccountNo, + IFNULL(c_class.coaDescription, '') AS ClassCoaDescription, + + -- Data dari tabel coa untuk Accumulated Depreciation CoA + IFNULL(c_accum.coaID, 0) AS AccumDepreCoaID, + IFNULL(c_accum.coaAccountNo, '') AS AccumDepreCoaAccountNo, + IFNULL(c_accum.coaDescription, '') AS AccumDepreCoaDescription + + FROM fa_class f + LEFT JOIN coa c_class + ON f.Fa_ClassCoaID = c_class.coaID + AND c_class.coaIsActive = 'Y' + AND c_class.coaIsInput = 'Y' + LEFT JOIN coa c_accum + ON f.Fa_ClassAccumDepreCoaID = c_accum.coaID + AND c_accum.coaIsActive = 'Y' + AND c_accum.coaIsInput = 'Y' + WHERE f.Fa_ClassIsActive = 'Y' + AND ( + f.Fa_ClassName LIKE CONCAT('%', '$search', '%') + OR f.Fa_ClassCoaAccountNo LIKE CONCAT('%', '$search', '%') + OR f.Fa_ClassCoaDesc LIKE CONCAT('%', '$search', '%') + OR f.Fa_ClassAccumDepreCoaAccountNo LIKE CONCAT('%', '$search', '%') + OR f.Fa_ClassAccumDepreCoaDesc LIKE CONCAT('%', '$search', '%') + OR f.Fa_ClassAccumNote LIKE CONCAT('%', '$search', '%') + OR f.Fa_ClassDepreCorp LIKE CONCAT('%', '$search', '%') + ) + ORDER BY f.Fa_ClassID ASC"; + + $sql_total = "SELECT count(*) as total FROM ($sql) as x"; + $qry_total = $this->db_onedev->query($sql_total); + + $totalCount = 0; + $totalPage = 0; + if ($qry_total) { + $totalCount = $qry_total->result_array()[0]["total"]; + $totalPage = ceil($totalCount / $number_limit); + } else { + $this->sys_error_db("select fa_class count error", $this->db_onedev);; + exit; + } + + $sql_select = $sql . " LIMIT $number_limit OFFSET $number_offset"; + + $qry = $this->db_onedev->query($sql_select); + if ($qry) { + $rows = $qry->result_array(); + } else { + $this->db_onedev->trans_rollback(); + $this->sys_error_db("select fa_class error", $this->db_onedev); + exit; + } + + $response = [ + "total" => $totalPage, + "totalFilter" => $totalCount, + "records" => $rows, + "sql" => $this->db_onedev->last_query() + ]; + + $this->sys_ok($response); + } catch (Exception $exc) { + $this->sys_error($exc->getMessage()); + } + } + + // ac getAcAccumDepre + function getAcAccumDepre() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $search = $prm['search']; + // $where_search = "%%"; + $where_search_desc = '%'.$search.'%'; + $where_search_acc = "$search%"; + + $sql = "SELECT + coaID, + coaAccountNo, + coaDescription, + coaSubDescription, + coaAccountType, + coaSpecialAccountType, + coaIsInput, + coaReportSchedule, + coaCurrencyCode, + coaCashFlowCategory, + coaCreated, + coaLastUpdated, + coaIsActive, + coaLevel + FROM coa + WHERE coaIsInput = 'Y' + AND coaIsActive = 'Y' + AND + ( + coaDescription LIKE '$where_search_desc' + OR coaAccountNo LIKE '$where_search_acc' + )"; + + // echo $sql; + // die(); + $qry = $this->db_onedev->query($sql, array()); + + if (!$qry) { + // $this->db->trans_rollback(); + $this->sys_error_db("Error get coa pendapatan"); + exit; + } + $result = $qry->result_array(); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // ac getAcCoa + function getAcCoa() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $search = $prm['search']; + // $where_search = "%%"; + $where_search_desc = '%'.$search.'%'; + $where_search_acc = "$search%"; + + $sql = "SELECT + coaID, + coaAccountNo, + coaDescription, + coaSubDescription, + coaAccountType, + coaSpecialAccountType, + coaIsInput, + coaReportSchedule, + coaCurrencyCode, + coaCashFlowCategory, + coaCreated, + coaLastUpdated, + coaIsActive, + coaLevel + FROM coa + WHERE coaIsInput = 'Y' + AND coaIsActive = 'Y' + AND + ( + coaDescription LIKE '$where_search_desc' + OR coaAccountNo LIKE '$where_search_acc' + )"; + + // echo $sql; + // die(); + $qry = $this->db_onedev->query($sql, array()); + + if (!$qry) { + // $this->db->trans_rollback(); + $this->sys_error_db("Error get coa pendapatan"); + exit; + } + $result = $qry->result_array(); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // addData + function addData() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $this->db_onedev->trans_begin(); + $userid = $this->sys_user['M_UserID']; + $a_classname = $prm['a_classname']; + $a_coa = $prm['a_coa']; + $a_deprecorp = $prm['a_deprecorp']; + $a_coa_accum_depre = $prm['a_coa_accum_depre']; + $a_note = $prm['a_note']; + + // defined variable + $Fa_ClassIsActive = "Y"; + $Fa_ClassAccumCreated = date('Y-m-d H:i:s'); + $Fa_ClassAccumLastUpdated = date('Y-m-d H:i:s'); + + // a_classname + $Fa_ClassName = isset($a_classname) ? $a_classname : ""; + + // coa + $Fa_ClassCoaID = isset($a_coa['coaID']) ? $a_coa['coaID'] : 0; + $Fa_ClassCoaAccountNo = isset($a_coa['coaAccountNo']) ? $a_coa['coaAccountNo'] : ''; + $Fa_ClassCoaDesc = isset($a_coa['coaDescription']) ? $a_coa['coaDescription'] : ''; + + // a_deprecorp + $Fa_ClassDepreCorp = isset($a_deprecorp) ? $a_deprecorp : 0.00; + + // accum depre + $Fa_ClassAccumDepreCoaID = isset($a_coa_accum_depre['coaID']) ? $a_coa_accum_depre['coaID'] : 0; + $Fa_ClassAccumDepreCoaAccountNo = isset($a_coa_accum_depre['coaAccountNo']) ? $a_coa_accum_depre['coaAccountNo'] : ''; + $Fa_ClassAccumDepreCoaDesc = isset($a_coa_accum_depre['coaDescription']) ? $a_coa_accum_depre['coaDescription'] : ''; + + // note + $Fa_ClassAccumNote = isset($a_note) ? $a_note : ""; + + // mulai insert + $sql = "INSERT INTO fa_class ( + Fa_ClassName, + Fa_ClassCoaID, + Fa_ClassCoaAccountNo, + Fa_ClassCoaDesc, + Fa_ClassDepreCorp, + Fa_ClassDepreGov, + Fa_ClassAccumDepreCoaID, + Fa_ClassAccumDepreCoaAccountNo, + Fa_ClassAccumDepreCoaDesc, + Fa_ClassAccumNote, + Fa_ClassAccumCreated, + Fa_ClassAccumLastUpdated, + Fa_ClassIsActive, + Fa_ClassM_UserID + ) VALUES ( + '$Fa_ClassName', + '$Fa_ClassCoaID', + '$Fa_ClassCoaAccountNo', + '$Fa_ClassCoaDesc', + '$Fa_ClassDepreCorp', + '0.00', + '$Fa_ClassAccumDepreCoaID', + '$Fa_ClassAccumDepreCoaAccountNo', + '$Fa_ClassAccumDepreCoaDesc', + '$Fa_ClassAccumNote', + '$Fa_ClassAccumCreated', + '$Fa_ClassAccumLastUpdated', + '$Fa_ClassIsActive', + '$userid' + ) + "; + + // echo $sql; + + $qry = $this->db_onedev->query($sql); + if (!$qry) { + $this->db_onedev->trans_rollback(); + $error = array( + "message" => $this->db_onedev->error()["message"], + // "sql" => $last_qry + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $this->db_onedev->trans_commit(); + $result = array("total" => 1); + $this->sys_ok($result); + + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // get_by_id + function get_by_id() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + // fa_class + $Fa_ClassID = isset($prm['Fa_ClassID']) ? $prm['Fa_ClassID'] : 0; + + $sql_m = "SELECT * FROM fa_class where Fa_ClassID = '$Fa_ClassID'"; + + $qry_m = $this->db_onedev->query($sql_m); + if (!$qry_m) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_m = $qry_m->result_array(); + + // coa start + $Fa_ClassCoaID = isset($prm['Fa_ClassCoaID']) ? $prm['Fa_ClassCoaID'] : 0; + $sql_u = "SELECT * FROM coa where coaID = '$Fa_ClassCoaID' + AND coaIsInput = 'Y' + AND coaIsActive = 'Y' + "; + + $qry_u = $this->db_onedev->query($sql_u); + if (!$qry_u) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_u = $qry_u->result_array(); + + // empty $rows_u + if (empty($rows_u)) { + $rows_u = [[ + "coaID" => 0, + "coaAccountNo" => '', + "coaDescription" => '', + "coaSubDescription" => '', + "coaAccountType" => '', + "coaSpecialAccountType" => '', + "coaIsInput" => 'N', + "coaReportSchedule" => '', + "coaCurrencyCode" => '', + "coaCashFlowCategory" => '', + "coaCreated" => '', + "coaLastUpdated" => '', + "coaIsActive" => 'Y', + "coaLevel" => 1 + ]]; + } + + // coa end + + // accum depre start + $Fa_ClassAccumDepreCoaID = $prm['Fa_ClassAccumDepreCoaID']; + $sql_h = "SELECT * FROM coa where coaID = '$Fa_ClassAccumDepreCoaID' + AND coaIsInput = 'Y' + AND coaIsActive = 'Y'"; + + $qry_h = $this->db_onedev->query($sql_h); + if (!$qry_h) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_h = $qry_h->result_array(); + // empty $rows_h + if (empty($rows_h)) { + $rows_h = [[ + "coaID" => 0, + "coaAccountNo" => '', + "coaDescription" => '', + "coaSubDescription" => '', + "coaAccountType" => '', + "coaSpecialAccountType" => '', + "coaIsInput" => 'N', + "coaReportSchedule" => '', + "coaCurrencyCode" => '', + "coaCashFlowCategory" => '', + "coaCreated" => '', + "coaLastUpdated" => '', + "coaIsActive" => 'Y', + "coaLevel" => 1 + ]]; + } + // accum depre end + + + + $response = [ + "record_fa_class" => $rows_m, + "records_coa" => $rows_u, + "records_accum_depre" => $rows_h, + "sql" => $this->db_onedev->last_query() + ]; + + $this->sys_ok($response); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // editData + function editData() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $this->db_onedev->trans_begin(); + $userid = $this->sys_user['M_UserID']; + + $Fa_ClassID = $prm['Fa_ClassID']; + $e_classname = $prm['e_classname']; + $e_coa = $prm['e_coa']; + $e_deprecorp = $prm['e_deprecorp']; + $e_coa_accum_depre = $prm['e_coa_accum_depre']; + $e_note = $prm['e_note']; + + // defined variable + $Fa_ClassIsActive = "Y"; + $Fa_ClassAccumLastUpdated = date('Y-m-d H:i:s'); + + // e_classname + $Fa_ClassName = isset($e_classname) ? $e_classname : ""; + + // coa + $Fa_ClassCoaID = isset($e_coa['coaID']) ? $e_coa['coaID'] : 0; + $Fa_ClassCoaAccountNo = isset($e_coa['coaAccountNo']) ? $e_coa['coaAccountNo'] : ''; + $Fa_ClassCoaDesc = isset($e_coa['coaDescription']) ? $e_coa['coaDescription'] : ''; + + // e_deprecorp + $Fa_ClassDepreCorp = isset($e_deprecorp) ? $e_deprecorp : 0.00; + + // accum depre + $Fa_ClassAccumDepreCoaID = isset($e_coa_accum_depre['coaID']) ? $e_coa_accum_depre['coaID'] : 0; + $Fa_ClassAccumDepreCoaAccountNo = isset($e_coa_accum_depre['coaAccountNo']) ? $e_coa_accum_depre['coaAccountNo'] : ''; + $Fa_ClassAccumDepreCoaDesc = isset($e_coa_accum_depre['coaDescription']) ? $e_coa_accum_depre['coaDescription'] : ''; + + // note + $Fa_ClassAccumNote = isset($e_note) ? $e_note : ""; + + $sql = "UPDATE fa_class SET + Fa_ClassName = '$Fa_ClassName', + Fa_ClassCoaID = '$Fa_ClassCoaID', + Fa_ClassCoaAccountNo = '$Fa_ClassCoaAccountNo', + Fa_ClassCoaDesc = '$Fa_ClassCoaDesc', + Fa_ClassDepreCorp = '$Fa_ClassDepreCorp', + Fa_ClassDepreGov = '0.00', + Fa_ClassAccumDepreCoaID = '$Fa_ClassAccumDepreCoaID', + Fa_ClassAccumDepreCoaAccountNo = '$Fa_ClassAccumDepreCoaAccountNo', + Fa_ClassAccumDepreCoaDesc = '$Fa_ClassAccumDepreCoaDesc', + Fa_ClassAccumNote = '$Fa_ClassAccumNote', + Fa_ClassAccumLastUpdated = '$Fa_ClassAccumLastUpdated', + Fa_ClassIsActive = '$Fa_ClassIsActive', + Fa_ClassM_UserID = '$userid' + WHERE Fa_ClassID = '$Fa_ClassID' + "; + + + // echo $sql; + + $qry = $this->db_onedev->query($sql); + if (!$qry) { + $this->db_onedev->trans_rollback(); + $error = array( + "message" => $this->db_onedev->error()["message"], + // "sql" => $last_qry + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $this->db_onedev->trans_commit(); + $result = array("total" => 1); + $this->sys_ok($result); + + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // deleteData + function deleteData() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $this->db_onedev->trans_begin(); + $userid = $this->sys_user['M_UserID']; + + $Fa_ClassID = $prm['Fa_ClassID']; + + $Fa_ClassAccumLastUpdated = date('Y-m-d H:i:s'); + + $sql = "UPDATE fa_class + SET + Fa_ClassIsActive = 'N', + Fa_ClassAccumLastUpdated = '$Fa_ClassAccumLastUpdated', + Fa_ClassM_UserID = '$userid' + WHERE Fa_ClassID = '$Fa_ClassID'"; + + $qry = $this->db_onedev->query($sql); + if (!$qry) { + $this->db_onedev->trans_rollback(); + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $last_qry + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $this->db_onedev->trans_commit(); + $result = array("total" => 1); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } +} +?> \ No newline at end of file diff --git a/application/controllers/map/Faclassv2.php b/application/controllers/map/Faclassv2.php new file mode 100644 index 0000000..1982463 --- /dev/null +++ b/application/controllers/map/Faclassv2.php @@ -0,0 +1,697 @@ +db_onedev = $this->load->database("onedev", true); + } + + // search + function search() + { + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $prm = $this->sys_input; + $search = isset($prm["search"]) ? trim($prm["search"]) : ''; + $search = ($search !== '') ? "%$search%" : "%%"; + + // $number_offset = ($prm["current_page"] > 0) ? ($prm["current_page"] - 1) * 20 : 0; + // $number_limit = 2; + $number_limit = 10; + $number_offset = ($prm["current_page"] > 0) ? ($prm["current_page"] - 1) * $number_limit : 0; + + $sql = "SELECT + f.Fa_ClassID, + IFNULL(f.Fa_ClassName, '') AS Fa_ClassName, + IFNULL(f.Fa_ClassCoaID, '') AS Fa_ClassCoaID, + IFNULL(f.Fa_ClassCoaAccountNo, '') AS Fa_ClassCoaAccountNo, + IFNULL(f.Fa_ClassCoaDesc, '') AS Fa_ClassCoaDesc, + IFNULL(f.Fa_ClassDepreCorp, 0.00) AS Fa_ClassDepreCorp, + IFNULL(f.Fa_ClassDepreGov, 0.00) AS Fa_ClassDepreGov, + IFNULL(f.Fa_ClassAccumDepreCoaID, 0) AS Fa_ClassAccumDepreCoaID, + IFNULL(f.Fa_ClassAccumDepreCoaAccountNo, '') AS Fa_ClassAccumDepreCoaAccountNo, + IFNULL(f.Fa_ClassAccumDepreCoaDesc, '') AS Fa_ClassAccumDepreCoaDesc, + IFNULL(f.Fa_ClassAccumNote, '') AS Fa_ClassAccumNote, + IFNULL(f.Fa_ClassAccumCreated, CURRENT_TIMESTAMP) AS Fa_ClassAccumCreated, + IFNULL(f.Fa_ClassAccumLastUpdated, CURRENT_TIMESTAMP) AS Fa_ClassAccumLastUpdated, + IFNULL(f.Fa_ClassIsActive, 'N') AS Fa_ClassIsActive, + IFNULL(f.Fa_ClassM_UserID, 0) AS Fa_ClassM_UserID, + IFNULL(f.Fa_ClassAgeAsset, 0.00) AS Fa_ClassAgeAsset, + + -- Data dari tabel coa untuk Class CoA + IFNULL(c_class.coaID, 0) AS ClassCoaID, + IFNULL(c_class.coaAccountNo, '') AS ClassCoaAccountNo, + IFNULL(c_class.coaDescription, '') AS ClassCoaDescription, + + -- Data dari tabel coa untuk Accumulated Depreciation CoA + IFNULL(c_accum.coaID, 0) AS AccumDepreCoaID, + IFNULL(c_accum.coaAccountNo, '') AS AccumDepreCoaAccountNo, + IFNULL(c_accum.coaDescription, '') AS AccumDepreCoaDescription, + + -- Data dari tabel coa untuk Biaya Depresiasi CoA + IFNULL(c_cost.coaID, 0) AS DepreCostCoaID, + IFNULL(c_cost.coaAccountNo, '') AS DepreCostCoaAccountNo, + IFNULL(c_cost.coaDescription, '') AS DepreCostCoaDescription + + FROM fa_class f + LEFT JOIN coa c_class + ON f.Fa_ClassCoaID = c_class.coaID + AND c_class.coaIsActive = 'Y' + AND c_class.coaIsInput = 'Y' + LEFT JOIN coa c_accum + ON f.Fa_ClassAccumDepreCoaID = c_accum.coaID + AND c_accum.coaIsActive = 'Y' + AND c_accum.coaIsInput = 'Y' + LEFT JOIN coa c_cost + ON f.Fa_ClassAccumDepreCostCoaID = c_cost.coaID + AND c_cost.coaIsActive = 'Y' + AND c_cost.coaIsInput = 'Y' + WHERE f.Fa_ClassIsActive = 'Y' + AND ( + f.Fa_ClassName LIKE CONCAT('%', '$search', '%') + OR f.Fa_ClassCoaAccountNo LIKE CONCAT('%', '$search', '%') + OR f.Fa_ClassCoaDesc LIKE CONCAT('%', '$search', '%') + OR f.Fa_ClassAccumDepreCoaAccountNo LIKE CONCAT('%', '$search', '%') + OR f.Fa_ClassAccumDepreCoaDesc LIKE CONCAT('%', '$search', '%') + OR f.Fa_ClassAccumNote LIKE CONCAT('%', '$search', '%') + OR f.Fa_ClassDepreCorp LIKE CONCAT('%', '$search', '%') + ) + ORDER BY f.Fa_ClassID ASC"; + + $sql_total = "SELECT count(*) as total FROM ($sql) as x"; + $qry_total = $this->db_onedev->query($sql_total); + + $totalCount = 0; + $totalPage = 0; + if ($qry_total) { + $totalCount = $qry_total->result_array()[0]["total"]; + $totalPage = ceil($totalCount / $number_limit); + } else { + $this->sys_error_db("select fa_class count error", $this->db_onedev);; + exit; + } + + $sql_select = $sql . " LIMIT $number_limit OFFSET $number_offset"; + + $qry = $this->db_onedev->query($sql_select); + if ($qry) { + $rows = $qry->result_array(); + } else { + $this->db_onedev->trans_rollback(); + $this->sys_error_db("select fa_class error", $this->db_onedev); + exit; + } + + $response = [ + "total" => $totalPage, + "totalFilter" => $totalCount, + "records" => $rows, + "sql" => $this->db_onedev->last_query() + ]; + + $this->sys_ok($response); + } catch (Exception $exc) { + $this->sys_error($exc->getMessage()); + } + } + + // ac getAcAccumDepre + function getAcAccumDepre() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $search = $prm['search']; + // $where_search = "%%"; + $where_search_desc = '%'.$search.'%'; + $where_search_acc = "$search%"; + + $sql = "SELECT + coaID, + coaAccountNo, + coaDescription, + coaSubDescription, + coaAccountType, + coaSpecialAccountType, + coaIsInput, + coaReportSchedule, + coaCurrencyCode, + coaCashFlowCategory, + coaCreated, + coaLastUpdated, + coaIsActive, + coaLevel + FROM coa + WHERE coaIsInput = 'Y' + AND coaIsActive = 'Y' + AND + ( + coaDescription LIKE '$where_search_desc' + OR coaAccountNo LIKE '$where_search_acc' + )"; + + // echo $sql; + // die(); + $qry = $this->db_onedev->query($sql, array()); + + if (!$qry) { + // $this->db->trans_rollback(); + $this->sys_error_db("Error get coa pendapatan"); + exit; + } + $result = $qry->result_array(); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + function getAcDepreCost() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $search = $prm['search']; + // $where_search = "%%"; + $where_search_desc = '%'.$search.'%'; + $where_search_acc = "$search%"; + + $sql = "SELECT + coaID, + coaAccountNo, + coaDescription, + coaSubDescription, + coaAccountType, + coaSpecialAccountType, + coaIsInput, + coaReportSchedule, + coaCurrencyCode, + coaCashFlowCategory, + coaCreated, + coaLastUpdated, + coaIsActive, + coaLevel + FROM coa + WHERE coaIsInput = 'Y' + AND coaIsActive = 'Y' + AND + ( + coaDescription LIKE '$where_search_desc' + OR coaAccountNo LIKE '$where_search_acc' + )"; + + // echo $sql; + // die(); + $qry = $this->db_onedev->query($sql, array()); + + if (!$qry) { + // $this->db->trans_rollback(); + $this->sys_error_db("Error get coa pendapatan"); + exit; + } + $result = $qry->result_array(); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + // ac getAcCoa + function getAcCoa() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $search = $prm['search']; + // $where_search = "%%"; + $where_search_desc = '%'.$search.'%'; + $where_search_acc = "$search%"; + + $sql = "SELECT + coaID, + coaAccountNo, + coaDescription, + coaSubDescription, + coaAccountType, + coaSpecialAccountType, + coaIsInput, + coaReportSchedule, + coaCurrencyCode, + coaCashFlowCategory, + coaCreated, + coaLastUpdated, + coaIsActive, + coaLevel + FROM coa + WHERE coaIsInput = 'Y' + AND coaIsActive = 'Y' + AND + ( + coaDescription LIKE '$where_search_desc' + OR coaAccountNo LIKE '$where_search_acc' + )"; + + // echo $sql; + // die(); + $qry = $this->db_onedev->query($sql, array()); + + if (!$qry) { + // $this->db->trans_rollback(); + $this->sys_error_db("Error get coa pendapatan"); + exit; + } + $result = $qry->result_array(); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // addData + function addData() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $this->db_onedev->trans_begin(); + $userid = $this->sys_user['M_UserID']; + $a_classname = $prm['a_classname']; + $a_coa = $prm['a_coa']; + $a_deprecorp = $prm['a_deprecorp']; + $a_age = $prm['a_age']; + $a_coa_accum_depre = $prm['a_coa_accum_depre']; + $a_coa_depre_cost = $prm['a_coa_depre_cost']; + $a_note = $prm['a_note']; + + // defined variable + $Fa_ClassIsActive = "Y"; + $Fa_ClassAccumCreated = date('Y-m-d H:i:s'); + $Fa_ClassAccumLastUpdated = date('Y-m-d H:i:s'); + + // a_classname + $Fa_ClassName = isset($a_classname) ? $a_classname : ""; + + // coa + $Fa_ClassCoaID = isset($a_coa['coaID']) ? $a_coa['coaID'] : 0; + $Fa_ClassCoaAccountNo = isset($a_coa['coaAccountNo']) ? $a_coa['coaAccountNo'] : ''; + $Fa_ClassCoaDesc = isset($a_coa['coaDescription']) ? $a_coa['coaDescription'] : ''; + + // a_deprecorp + $Fa_ClassDepreCorp = isset($a_deprecorp) ? $a_deprecorp : 0.00; + + // a_deprecorp + $Fa_ClassAgeAsset = isset($a_age) ? $a_age : 0; + + // accum depre + $Fa_ClassAccumDepreCoaID = isset($a_coa_accum_depre['coaID']) ? $a_coa_accum_depre['coaID'] : 0; + $Fa_ClassAccumDepreCoaAccountNo = isset($a_coa_accum_depre['coaAccountNo']) ? $a_coa_accum_depre['coaAccountNo'] : ''; + $Fa_ClassAccumDepreCoaDesc = isset($a_coa_accum_depre['coaDescription']) ? $a_coa_accum_depre['coaDescription'] : ''; + + $Fa_ClassAccumDepreCostCoaID = isset($a_coa_depre_cost['coaID']) ? $a_coa_depre_cost['coaID'] : 0; + + // note + $Fa_ClassAccumNote = isset($a_note) ? $a_note : ""; + + // mulai insert + $sql = "INSERT INTO fa_class ( + Fa_ClassName, + Fa_ClassCoaID, + Fa_ClassCoaAccountNo, + Fa_ClassCoaDesc, + Fa_ClassDepreCorp, + Fa_ClassDepreGov, + Fa_ClassAccumDepreCoaID, + Fa_ClassAccumDepreCoaAccountNo, + Fa_ClassAccumDepreCoaDesc, + Fa_ClassAccumNote, + Fa_ClassAccumCreated, + Fa_ClassAccumLastUpdated, + Fa_ClassIsActive, + Fa_ClassM_UserID, + Fa_ClassAccumDepreCostCoaID + ) VALUES ( + '$Fa_ClassName', + '$Fa_ClassCoaID', + '$Fa_ClassCoaAccountNo', + '$Fa_ClassCoaDesc', + '$Fa_ClassDepreCorp', + '0.00', + '$Fa_ClassAccumDepreCoaID', + '$Fa_ClassAccumDepreCoaAccountNo', + '$Fa_ClassAccumDepreCoaDesc', + '$Fa_ClassAccumNote', + '$Fa_ClassAccumCreated', + '$Fa_ClassAccumLastUpdated', + '$Fa_ClassIsActive', + '$userid', + '$Fa_ClassAccumDepreCostCoaID' + ) + "; + + // echo $sql; + + $qry = $this->db_onedev->query($sql); + if (!$qry) { + $this->db_onedev->trans_rollback(); + $error = array( + "message" => $this->db_onedev->error()["message"], + // "sql" => $last_qry + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $this->db_onedev->trans_commit(); + $result = array("total" => 1); + $this->sys_ok($result); + + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // get_by_id + function get_by_id() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + // fa_class + $Fa_ClassID = isset($prm['Fa_ClassID']) ? $prm['Fa_ClassID'] : 0; + + $sql_m = "SELECT * FROM fa_class where Fa_ClassID = '$Fa_ClassID'"; + + $qry_m = $this->db_onedev->query($sql_m); + if (!$qry_m) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_m = $qry_m->result_array(); + + // coa start + $Fa_ClassCoaID = isset($prm['Fa_ClassCoaID']) ? $prm['Fa_ClassCoaID'] : 0; + $sql_u = "SELECT * FROM coa where coaID = '$Fa_ClassCoaID' + AND coaIsInput = 'Y' + AND coaIsActive = 'Y' + "; + + $qry_u = $this->db_onedev->query($sql_u); + if (!$qry_u) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_u = $qry_u->result_array(); + + // empty $rows_u + if (empty($rows_u)) { + $rows_u = [[ + "coaID" => 0, + "coaAccountNo" => '', + "coaDescription" => '', + "coaSubDescription" => '', + "coaAccountType" => '', + "coaSpecialAccountType" => '', + "coaIsInput" => 'N', + "coaReportSchedule" => '', + "coaCurrencyCode" => '', + "coaCashFlowCategory" => '', + "coaCreated" => '', + "coaLastUpdated" => '', + "coaIsActive" => 'Y', + "coaLevel" => 1 + ]]; + } + + // coa end + + // accum depre start + $Fa_ClassAccumDepreCoaID = $prm['Fa_ClassAccumDepreCoaID']; + $sql_h = "SELECT * FROM coa where coaID = '$Fa_ClassAccumDepreCoaID' + AND coaIsInput = 'Y' + AND coaIsActive = 'Y'"; + + $qry_h = $this->db_onedev->query($sql_h); + if (!$qry_h) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_h = $qry_h->result_array(); + // empty $rows_h + if (empty($rows_h)) { + $rows_h = [[ + "coaID" => 0, + "coaAccountNo" => '', + "coaDescription" => '', + "coaSubDescription" => '', + "coaAccountType" => '', + "coaSpecialAccountType" => '', + "coaIsInput" => 'N', + "coaReportSchedule" => '', + "coaCurrencyCode" => '', + "coaCashFlowCategory" => '', + "coaCreated" => '', + "coaLastUpdated" => '', + "coaIsActive" => 'Y', + "coaLevel" => 1 + ]]; + } + // accum depre end + + // depre cost start + $Fa_ClassAccumDepreCostCoaID = $prm['Fa_ClassAccumDepreCostCoaID']; + $sql_c = "SELECT * FROM coa where coaID = '$Fa_ClassAccumDepreCostCoaID' + AND coaIsInput = 'Y' + AND coaIsActive = 'Y'"; + + $qry_c = $this->db_onedev->query($sql_c); + if (!$qry_c) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_c = $qry_c->result_array(); + // empty $rows_h + if (empty($rows_c)) { + $rows_c = [[ + "coaID" => 0, + "coaAccountNo" => '', + "coaDescription" => '', + "coaSubDescription" => '', + "coaAccountType" => '', + "coaSpecialAccountType" => '', + "coaIsInput" => 'N', + "coaReportSchedule" => '', + "coaCurrencyCode" => '', + "coaCashFlowCategory" => '', + "coaCreated" => '', + "coaLastUpdated" => '', + "coaIsActive" => 'Y', + "coaLevel" => 1 + ]]; + } + // accum depre end + + $response = [ + "record_fa_class" => $rows_m, + "records_coa" => $rows_u, + "records_accum_depre" => $rows_h, + "records_depre_cost" => $rows_c, + "sql" => $this->db_onedev->last_query() + ]; + + $this->sys_ok($response); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // editData + function editData() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $this->db_onedev->trans_begin(); + $userid = $this->sys_user['M_UserID']; + + $Fa_ClassID = $prm['Fa_ClassID']; + $e_classname = $prm['e_classname']; + $e_coa = $prm['e_coa']; + $e_deprecorp = $prm['e_deprecorp']; + $e_coa_accum_depre = $prm['e_coa_accum_depre']; + $e_note = $prm['e_note']; + $e_age = $prm['e_age']; + $e_coa_depre_cost = $prm['e_coa_depre_cost']; + + // defined variable + $Fa_ClassIsActive = "Y"; + $Fa_ClassAccumLastUpdated = date('Y-m-d H:i:s'); + + // e_classname + $Fa_ClassName = isset($e_classname) ? $e_classname : ""; + + // coa + $Fa_ClassCoaID = isset($e_coa['coaID']) ? $e_coa['coaID'] : 0; + $Fa_ClassCoaAccountNo = isset($e_coa['coaAccountNo']) ? $e_coa['coaAccountNo'] : ''; + $Fa_ClassCoaDesc = isset($e_coa['coaDescription']) ? $e_coa['coaDescription'] : ''; + + // e_deprecorp + $Fa_ClassDepreCorp = isset($e_deprecorp) ? $e_deprecorp : 0.00; + + $Fa_ClassAgeAsset = isset($e_age) ? $e_age : 0; + + // accum depre + $Fa_ClassAccumDepreCoaID = isset($e_coa_accum_depre['coaID']) ? $e_coa_accum_depre['coaID'] : 0; + $Fa_ClassAccumDepreCoaAccountNo = isset($e_coa_accum_depre['coaAccountNo']) ? $e_coa_accum_depre['coaAccountNo'] : ''; + $Fa_ClassAccumDepreCoaDesc = isset($e_coa_accum_depre['coaDescription']) ? $e_coa_accum_depre['coaDescription'] : ''; + + $Fa_ClassAccumDepreCostCoaID = isset($e_coa_depre_cost['coaID']) ? $e_coa_depre_cost['coaID'] : 0; + + // note + $Fa_ClassAccumNote = isset($e_note) ? $e_note : ""; + + $sql = "UPDATE fa_class SET + Fa_ClassName = '$Fa_ClassName', + Fa_ClassCoaID = '$Fa_ClassCoaID', + Fa_ClassCoaAccountNo = '$Fa_ClassCoaAccountNo', + Fa_ClassCoaDesc = '$Fa_ClassCoaDesc', + Fa_ClassDepreCorp = '$Fa_ClassDepreCorp', + Fa_ClassAgeAsset = '$Fa_ClassAgeAsset', + Fa_ClassDepreGov = '0.00', + Fa_ClassAccumDepreCostCoaID = '$Fa_ClassAccumDepreCostCoaID', + Fa_ClassAccumDepreCoaID = '$Fa_ClassAccumDepreCoaID', + Fa_ClassAccumDepreCoaAccountNo = '$Fa_ClassAccumDepreCoaAccountNo', + Fa_ClassAccumDepreCoaDesc = '$Fa_ClassAccumDepreCoaDesc', + Fa_ClassAccumNote = '$Fa_ClassAccumNote', + Fa_ClassAccumLastUpdated = '$Fa_ClassAccumLastUpdated', + Fa_ClassIsActive = '$Fa_ClassIsActive', + Fa_ClassM_UserID = '$userid' + WHERE Fa_ClassID = '$Fa_ClassID' + "; + + + // echo $sql; + + $qry = $this->db_onedev->query($sql); + if (!$qry) { + $this->db_onedev->trans_rollback(); + $error = array( + "message" => $this->db_onedev->error()["message"], + // "sql" => $last_qry + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $this->db_onedev->trans_commit(); + $result = array("total" => 1); + $this->sys_ok($result); + + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // deleteData + function deleteData() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $this->db_onedev->trans_begin(); + $userid = $this->sys_user['M_UserID']; + + $Fa_ClassID = $prm['Fa_ClassID']; + + $Fa_ClassAccumLastUpdated = date('Y-m-d H:i:s'); + + $sql = "UPDATE fa_class + SET + Fa_ClassIsActive = 'N', + Fa_ClassAccumLastUpdated = '$Fa_ClassAccumLastUpdated', + Fa_ClassM_UserID = '$userid' + WHERE Fa_ClassID = '$Fa_ClassID'"; + + $qry = $this->db_onedev->query($sql); + if (!$qry) { + $this->db_onedev->trans_rollback(); + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $last_qry + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $this->db_onedev->trans_commit(); + $result = array("total" => 1); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } +} +?> \ No newline at end of file diff --git a/application/controllers/map/Natgroup.php b/application/controllers/map/Natgroup.php new file mode 100644 index 0000000..b665584 --- /dev/null +++ b/application/controllers/map/Natgroup.php @@ -0,0 +1,968 @@ +db_onedev = $this->load->database("onedev", true); + } + + // lookup nat_group + function getNatGroup() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $sql = "SELECT Nat_GroupID, + Nat_GroupCode, + Nat_GroupName + FROM nat_group + WHERE Nat_GroupIsActive ='Y'"; + $qry = $this->db_onedev->query($sql, array()); + + if (!$qry) { + // $this->db->trans_rollback(); + $this->sys_error_db("Error get nat_group"); + exit; + } + $result = $qry->result_array(); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // ac uang muka + function getAcUangMuka() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $search = $prm['search']; + // $where_search = "%%"; + $where_search_desc = '%'.$search.'%'; + $where_search_acc = "$search%"; + + $sql = "SELECT + coaID, + coaAccountNo, + coaDescription, + coaSubDescription, + coaAccountType, + coaSpecialAccountType, + coaIsInput, + coaReportSchedule, + coaCurrencyCode, + coaCashFlowCategory, + coaCreated, + coaLastUpdated, + coaIsActive, + coaLevel + FROM coa + WHERE coaIsInput = 'Y' + AND coaIsActive = 'Y' + AND + ( + coaDescription LIKE '$where_search_desc' + OR coaAccountNo LIKE '$where_search_acc' + )"; + + // echo $sql; + // die(); + $qry = $this->db_onedev->query($sql, array()); + + if (!$qry) { + // $this->db->trans_rollback(); + $this->sys_error_db("Error get coa pendapatan"); + exit; + } + $result = $qry->result_array(); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // ac hutang + function getAcHutang() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $search = $prm['search']; + // $where_search = "%%"; + $where_search_desc = '%'.$search.'%'; + $where_search_acc = "$search%"; + + $sql = "SELECT + coaID, + coaAccountNo, + coaDescription, + coaSubDescription, + coaAccountType, + coaSpecialAccountType, + coaIsInput, + coaReportSchedule, + coaCurrencyCode, + coaCashFlowCategory, + coaCreated, + coaLastUpdated, + coaIsActive, + coaLevel + FROM coa + WHERE coaIsInput = 'Y' + AND coaIsActive = 'Y' + AND + ( + coaDescription LIKE '$where_search_desc' + OR coaAccountNo LIKE '$where_search_acc' + )"; + + // echo $sql; + // die(); + $qry = $this->db_onedev->query($sql, array()); + + if (!$qry) { + // $this->db->trans_rollback(); + $this->sys_error_db("Error get coa pendapatan"); + exit; + } + $result = $qry->result_array(); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // ac disc pendapatan + function getAcDiscPendapatan() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $search = $prm['search']; + // $where_search = "%%"; + $where_search_desc = '%'.$search.'%'; + $where_search_acc = "$search%"; + + $sql = "SELECT + coaID, + coaAccountNo, + coaDescription, + coaSubDescription, + coaAccountType, + coaSpecialAccountType, + coaIsInput, + coaReportSchedule, + coaCurrencyCode, + coaCashFlowCategory, + coaCreated, + coaLastUpdated, + coaIsActive, + coaLevel + FROM coa + WHERE coaIsInput = 'Y' + AND coaIsActive = 'Y' + AND + ( + coaDescription LIKE '$where_search_desc' + OR coaAccountNo LIKE '$where_search_acc' + )"; + + // echo $sql; + // die(); + $qry = $this->db_onedev->query($sql, array()); + + if (!$qry) { + // $this->db->trans_rollback(); + $this->sys_error_db("Error get coa pendapatan"); + exit; + } + $result = $qry->result_array(); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // ac retur pendapatan + function getAcReturPendapatan() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $search = $prm['search']; + // $where_search = "%%"; + $where_search_desc = '%'.$search.'%'; + $where_search_acc = "$search%"; + + $sql = "SELECT + coaID, + coaAccountNo, + coaDescription, + coaSubDescription, + coaAccountType, + coaSpecialAccountType, + coaIsInput, + coaReportSchedule, + coaCurrencyCode, + coaCashFlowCategory, + coaCreated, + coaLastUpdated, + coaIsActive, + coaLevel + FROM coa + WHERE coaIsInput = 'Y' + AND coaIsActive = 'Y' + AND + ( + coaDescription LIKE '$where_search_desc' + OR coaAccountNo LIKE '$where_search_acc' + )"; + + // echo $sql; + // die(); + $qry = $this->db_onedev->query($sql, array()); + + if (!$qry) { + // $this->db->trans_rollback(); + $this->sys_error_db("Error get coa pendapatan"); + exit; + } + $result = $qry->result_array(); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // search + function search() + { + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $prm = $this->sys_input; + $search = isset($prm["search"]) ? trim($prm["search"]) : ''; + $search = ($search !== '') ? "%$search%" : "%%"; + + // $number_offset = ($prm["current_page"] > 0) ? ($prm["current_page"] - 1) * 20 : 0; + // $number_limit = 2; + $number_limit = 10; + $number_offset = ($prm["current_page"] > 0) ? ($prm["current_page"] - 1) * $number_limit : 0; + + $sql = "SELECT + IFNULL(m.MapNatGroup_ID, 0) AS MapNatGroup_ID, + IFNULL(m.MapNatGroup_NatGroupID, 0) AS MapNatGroup_NatGroupID, + + -- Nat Group + IFNULL(g.Nat_GroupCode, '') AS Nat_GroupCode, + IFNULL(g.Nat_GroupName, '') AS Nat_GroupName, + + -- Discount + IFNULL(m.MapNatGroup_Disc_coaID, 0) AS MapNatGroup_Disc_coaID, + IFNULL(m.MapNatGroup_Disc_coaAccNo, '') AS MapNatGroup_Disc_coaAccNo, + IFNULL(m.MapNatGroup_Disc_coaDesc, '') AS MapNatGroup_Disc_coaDesc, + IFNULL(c_disc.coaAccountNo, '') AS Disc_coaAccountNo, + IFNULL(c_disc.coaDescription, '') AS Disc_coaDescription, + + -- Retur + IFNULL(m.MapNatGroup_Retur_coaID, 0) AS MapNatGroup_Retur_coaID, + IFNULL(m.MapNatGroup_Retur_coaAccNo, '') AS MapNatGroup_Retur_coaAccNo, + IFNULL(m.MapNatGroup_Retur_coaDesc, '') AS MapNatGroup_Retur_coaDesc, + IFNULL(c_retur.coaAccountNo, '') AS Retur_coaAccountNo, + IFNULL(c_retur.coaDescription, '') AS Retur_coaDescription, + + -- DP + IFNULL(m.MapNatGroup_Dp_coaID, 0) AS MapNatGroup_Dp_coaID, + IFNULL(m.MapNatGroup_Dp_coaAccNo, '') AS MapNatGroup_Dp_coaAccNo, + IFNULL(m.MapNatGroup_Dp_coaDesc, '') AS MapNatGroup_Dp_coaDesc, + IFNULL(c_dp.coaAccountNo, '') AS Dp_coaAccountNo, + IFNULL(c_dp.coaDescription, '') AS Dp_coaDescription, + + -- hutang + IFNULL(m.MapNatGroup_Debt_coaID, 0) AS MapNatGroup_Debt_coaID, + IFNULL(m.MapNatGroup_Debt_coaAccNo, '') AS MapNatGroup_Debt_coaAccNo, + IFNULL(m.MapNatGroup_Debt_coaDesc, '') AS MapNatGroup_Debt_coaDesc, + IFNULL(c_debt.coaAccountNo, '') AS Debt_coaAccountNo, + IFNULL(c_debt.coaDescription, '') AS Debt_coaDescription + FROM map_nat_group m + LEFT JOIN nat_group g + ON m.MapNatGroup_NatGroupID = g.Nat_GroupID + AND g.Nat_GroupIsActive = 'Y' + + LEFT JOIN coa c_disc + ON m.MapNatGroup_Disc_coaID = c_disc.coaID + AND c_disc.coaIsInput = 'Y' + AND c_disc.coaIsActive = 'Y' + + LEFT JOIN coa c_retur + ON m.MapNatGroup_Retur_coaID = c_retur.coaID + AND c_retur.coaIsInput = 'Y' + AND c_retur.coaIsActive = 'Y' + + LEFT JOIN coa c_dp + ON m.MapNatGroup_Dp_coaID = c_dp.coaID + AND c_dp.coaIsInput = 'Y' + AND c_dp.coaIsActive = 'Y' + + LEFT JOIN coa c_debt + ON m.MapNatGroup_Debt_coaID = c_debt.coaID + AND c_debt.coaIsInput = 'Y' + AND c_debt.coaIsActive = 'Y' + WHERE m.MapNatGroup_IsActive = 'Y' + AND ( + g.Nat_GroupName LIKE '$search' OR + m.MapNatGroup_Disc_coaAccNo LIKE '$search' OR + m.MapNatGroup_Disc_coaDesc LIKE '$search' OR + m.MapNatGroup_Retur_coaAccNo LIKE '$search' OR + m.MapNatGroup_Retur_coaDesc LIKE '$search' OR + m.MapNatGroup_Dp_coaAccNo LIKE '$search' OR + m.MapNatGroup_Dp_coaDesc LIKE '$search' OR + m.MapNatGroup_Debt_coaAccNo LIKE '$search' OR + m.MapNatGroup_Debt_coaDesc LIKE '$search' + ) + ORDER BY m.MapNatGroup_ID ASC"; + + $sql_total = "SELECT count(*) as total FROM ($sql) as x"; + $qry_total = $this->db_onedev->query($sql_total); + + $totalCount = 0; + $totalPage = 0; + if ($qry_total) { + $totalCount = $qry_total->result_array()[0]["total"]; + $totalPage = ceil($totalCount / $number_limit); + } else { + $this->sys_error_db("select coa count error", $this->db_onedev);; + exit; + } + + $sql_select = $sql . " LIMIT $number_limit OFFSET $number_offset"; + + $qry = $this->db_onedev->query($sql_select); + if ($qry) { + $rows = $qry->result_array(); + } else { + $this->db_onedev->trans_rollback(); + $this->sys_error_db("select coa error", $this->db_onedev); + exit; + } + + $response = [ + "total" => $totalPage, + "totalFilter" => $totalCount, + "records" => $rows, + "sql" => $this->db_onedev->last_query() + ]; + + $this->sys_ok($response); + } catch (Exception $exc) { + $this->sys_error($exc->getMessage()); + } + } + + // addData + function addData() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $this->db_onedev->trans_begin(); + $a_nat_group = $prm['a_nat_group']; + $a_coa_uang_muka = $prm['a_coa_uang_muka']; + $a_coa_hutang = $prm['a_coa_hutang']; + $a_coa_disc_pendapatan = $prm['a_coa_disc_pendapatan']; + $a_coa_retur_pendapatan = $prm['a_coa_retur_pendapatan']; + + // defined variable + $MapNatGroup_IsActive = "Y"; + $MapNatGroup_CreatedAt = date('Y-m-d H:i:s'); + $MapNatGroup_LastUpdatedAt = date('Y-m-d H:i:s'); + + // nat_group + $MapNatGroup_NatGroupID = isset($a_nat_group['Nat_GroupID']) ? $a_nat_group['Nat_GroupID'] : 0; + + // disc pendaptan + $MapNatGroup_Disc_coaID = isset($a_coa_disc_pendapatan['coaID']) ? $a_coa_disc_pendapatan['coaID'] : 0; + $MapNatGroup_Disc_coaAccNo = isset($a_coa_disc_pendapatan['coaAccountNo']) ? $a_coa_disc_pendapatan['coaAccountNo'] : ''; + $MapNatGroup_Disc_coaDesc = isset($a_coa_disc_pendapatan['coaDescription']) ? $a_coa_disc_pendapatan['coaDescription'] : ''; + + // retur pendapatan + $MapNatGroup_Retur_coaID = isset($a_coa_retur_pendapatan['coaID']) ? $a_coa_retur_pendapatan['coaID'] : 0; + $MapNatGroup_Retur_coaAccNo = isset($a_coa_retur_pendapatan['coaAccountNo']) ? $a_coa_retur_pendapatan['coaAccountNo'] : ''; + $MapNatGroup_Retur_coaDesc = isset($a_coa_retur_pendapatan['coaDescription']) ? $a_coa_retur_pendapatan['coaDescription'] : ''; + + // uang muka + $MapNatGroup_Dp_coaID = isset($a_coa_uang_muka['coaID']) ? $a_coa_uang_muka['coaID'] : 0; + $MapNatGroup_Dp_coaAccNo = isset($a_coa_uang_muka['coaAccountNo']) ? $a_coa_uang_muka['coaAccountNo'] : ''; + $MapNatGroup_Dp_coaDesc = isset($a_coa_uang_muka['coaDescription']) ? $a_coa_uang_muka['coaDescription'] : ''; + + // hutang + $MapNatGroup_Debt_coaID = isset($a_coa_hutang['coaID']) ? $a_coa_hutang['coaID'] : 0; + $MapNatGroup_Debt_coaAccNo = isset($a_coa_hutang['coaAccountNo']) ? $a_coa_hutang['coaAccountNo'] : ''; + $MapNatGroup_Debt_coaDesc = isset($a_coa_hutang['coaDescription']) ? $a_coa_hutang['coaDescription'] : ''; + + // check jika sudah ada MapNatGroup_NatGroupID maka tidak boleh insert + $sql_gn = "SELECT * + FROM nat_group + WHERE Nat_GroupID = '$MapNatGroup_NatGroupID' + AND Nat_GroupIsActive = 'Y'"; + + $qry_gn = $this->db_onedev->query($sql_gn); + if (!$qry_gn) { + $this->db_onedev->trans_rollback(); + $error = array( + "message" => $this->db_onedev->error()["message"], + // "sql" => $last_qry + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + $rows_gn = $qry_gn->result(); + $grup_name = ""; + $grup_name .= $rows_gn[0]->Nat_GroupName; + + $sql_c = "SELECT * from map_nat_group WHERE MapNatGroup_NatGroupID = '$MapNatGroup_NatGroupID' + AND MapNatGroup_IsActive = 'Y'"; + $qry_c = $this->db_onedev->query($sql_c); + if (!$qry_c) { + $this->db_onedev->trans_rollback(); + $error = array( + "message" => $this->db_onedev->error()["message"], + // "sql" => $last_qry + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_c = $qry_c->result(); + if(count($rows_c) > 0){ + $this->db_onedev->trans_rollback(); + $this->sys_error("Group Name dengan nama $grup_name, sudah ada"); + exit; + } + + // mulai insert + $sql = "INSERT INTO map_nat_group ( + MapNatGroup_NatGroupID, + MapNatGroup_Disc_coaID, + MapNatGroup_Disc_coaAccNo, + MapNatGroup_Disc_coaDesc, + MapNatGroup_Retur_coaID, + MapNatGroup_Retur_coaAccNo, + MapNatGroup_Retur_coaDesc, + MapNatGroup_Dp_coaID, + MapNatGroup_Dp_coaAccNo, + MapNatGroup_Dp_coaDesc, + MapNatGroup_Debt_coaID, + MapNatGroup_Debt_coaAccNo, + MapNatGroup_Debt_coaDesc, + MapNatGroup_IsActive, + MapNatGroup_CreatedAt, + MapNatGroup_LastUpdatedAt + ) + VALUES ( + '$MapNatGroup_NatGroupID', + '$MapNatGroup_Disc_coaID', + '$MapNatGroup_Disc_coaAccNo', + '$MapNatGroup_Disc_coaDesc', + '$MapNatGroup_Retur_coaID', + '$MapNatGroup_Retur_coaAccNo', + '$MapNatGroup_Retur_coaDesc', + '$MapNatGroup_Dp_coaID', + '$MapNatGroup_Dp_coaAccNo', + '$MapNatGroup_Dp_coaDesc', + '$MapNatGroup_Debt_coaID', + '$MapNatGroup_Debt_coaAccNo', + '$MapNatGroup_Debt_coaDesc', + '$MapNatGroup_IsActive', + '$MapNatGroup_CreatedAt', + '$MapNatGroup_LastUpdatedAt' + )"; + + // echo $sql; + + $qry = $this->db_onedev->query($sql); + if (!$qry) { + $this->db_onedev->trans_rollback(); + $error = array( + "message" => $this->db_onedev->error()["message"], + // "sql" => $last_qry + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $this->db_onedev->trans_commit(); + $result = array("total" => 1); + $this->sys_ok($result); + + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // deleteData + function deleteData() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $this->db_onedev->trans_begin(); + $MapNatGroup_ID = $prm['MapNatGroup_ID']; + $MapNatGroup_LastUpdatedAt = date('Y-m-d H:i:s'); + + $sql = "UPDATE map_nat_group + SET + MapNatGroup_IsActive = 'N', + MapNatGroup_LastUpdatedAt = '$MapNatGroup_LastUpdatedAt' + WHERE MapNatGroup_ID = '$MapNatGroup_ID'"; + + $qry = $this->db_onedev->query($sql); + if (!$qry) { + $this->db_onedev->trans_rollback(); + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $last_qry + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $this->db_onedev->trans_commit(); + $result = array("total" => 1); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // get_by_id + function get_by_id() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + // map_nat_group + // $MapNatGroup_ID = $prm['MapNatGroup_ID']; + $MapNatGroup_ID = isset($prm['MapNatGroup_ID']) ? $prm['MapNatGroup_ID'] : 0; + + $sql_m = "SELECT * FROM map_nat_group where MapNatGroup_ID = '$MapNatGroup_ID'"; + + $qry_m = $this->db_onedev->query($sql_m); + if (!$qry_m) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_m = $qry_m->result_array(); + + // group start + // $MapNatGroup_NatGroupID = $prm['MapNatGroup_NatGroupID']; + + $MapNatGroup_NatGroupID = isset($prm['MapNatGroup_NatGroupID']) ? $prm['MapNatGroup_NatGroupID'] : 0; + $sql_g = "SELECT * FROM nat_group where Nat_GroupID = '$MapNatGroup_NatGroupID'"; + + $qry_g = $this->db_onedev->query($sql_g); + if (!$qry_g) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_g = $qry_g->result_array(); + + // empty rows_g + if (empty($rows_m)) { + $rows_m = [[ + "MapNatGroup_ID" => 0, + "MapNatGroup_NatGroupID" => 0, + "MapNatGroup_Disc_coaID" => 0, + "MapNatGroup_Disc_coaAccNo" => '', + "MapNatGroup_Disc_coaDesc" => '', + "MapNatGroup_Retur_coaID" => 0, + "MapNatGroup_Retur_coaAccNo"=> '', + "MapNatGroup_Retur_coaDesc" => '', + "MapNatGroup_Dp_coaID" => 0, + "MapNatGroup_Dp_coaAccNo" => '', + "MapNatGroup_Dp_coaDesc" => '', + "MapNatGroup_Debt_coaID" => 0, + "MapNatGroup_Debt_coaAccNo" => '', + "MapNatGroup_Debt_coaDesc" => '', + "MapNatGroup_IsActive" => 'Y', + "MapNatGroup_CreatedAt" => '', + "MapNatGroup_LastUpdatedAt" => '' + ]]; + } + + $sql_gx = "SELECT * FROM nat_group where Nat_GroupIsActive = 'Y'"; + + $qry_gx = $this->db_onedev->query($sql_gx); + if (!$qry_g) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_gx = $qry_gx->result_array(); + + // empty $rows_gx + if (empty($rows_gx)) { + $rows_gx = [[ + "Nat_GroupID" => 0, + "Nat_GroupCode" => '', + "Nat_GroupName" => '', + "Nat_GroupCreated" => '', + "Nat_GroupLastUpdated"=> '', + "Nat_GroupIsActive" => 'Y' + ]]; + } + + // group end + + // uang muka start + // $MapNatGroup_Dp_coaID = $prm['MapNatGroup_Dp_coaID']; + $MapNatGroup_Dp_coaID = isset($prm['MapNatGroup_Dp_coaID']) ? $prm['MapNatGroup_Dp_coaID'] : 0; + $sql_u = "SELECT * FROM coa where coaID = '$MapNatGroup_Dp_coaID' + AND coaIsInput = 'Y' + AND coaIsActive = 'Y' + "; + + $qry_u = $this->db_onedev->query($sql_u); + if (!$qry_u) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_u = $qry_u->result_array(); + + // empty $rows_u + if (empty($rows_u)) { + $rows_u = [[ + "coaID" => 0, + "coaAccountNo" => '', + "coaDescription" => '', + "coaSubDescription" => '', + "coaAccountType" => '', + "coaSpecialAccountType" => '', + "coaIsInput" => 'N', + "coaReportSchedule" => '', + "coaCurrencyCode" => '', + "coaCashFlowCategory" => '', + "coaCreated" => '', + "coaLastUpdated" => '', + "coaIsActive" => 'Y', + "coaLevel" => 1 + ]]; + } + + // uang muka end + + // hutang start + $MapNatGroup_Debt_coaID = $prm['MapNatGroup_Debt_coaID']; + $sql_h = "SELECT * FROM coa where coaID = '$MapNatGroup_Debt_coaID' + AND coaIsInput = 'Y' + AND coaIsActive = 'Y'"; + + $qry_h = $this->db_onedev->query($sql_h); + if (!$qry_h) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_h = $qry_h->result_array(); + // empty $rows_h + if (empty($rows_h)) { + $rows_h = [[ + "coaID" => 0, + "coaAccountNo" => '', + "coaDescription" => '', + "coaSubDescription" => '', + "coaAccountType" => '', + "coaSpecialAccountType" => '', + "coaIsInput" => 'N', + "coaReportSchedule" => '', + "coaCurrencyCode" => '', + "coaCashFlowCategory" => '', + "coaCreated" => '', + "coaLastUpdated" => '', + "coaIsActive" => 'Y', + "coaLevel" => 1 + ]]; + } + // hutang end + + // disc. pendapatan start + $MapNatGroup_Disc_coaID = $prm['MapNatGroup_Disc_coaID']; + $sql_d = "SELECT * FROM coa where coaID = '$MapNatGroup_Disc_coaID' + AND coaIsInput = 'Y' + AND coaIsActive = 'Y'"; + + $qry_d = $this->db_onedev->query($sql_d); + if (!$qry_d) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_d = $qry_d->result_array(); + + // empty $rows_d + if (empty($rows_d)) { + $rows_d = [[ + "coaID" => 0, + "coaAccountNo" => '', + "coaDescription" => '', + "coaSubDescription" => '', + "coaAccountType" => '', + "coaSpecialAccountType" => '', + "coaIsInput" => 'N', + "coaReportSchedule" => '', + "coaCurrencyCode" => '', + "coaCashFlowCategory" => '', + "coaCreated" => '', + "coaLastUpdated" => '', + "coaIsActive" => 'Y', + "coaLevel" => 1 + ]]; + } + // disc. pendapatan end + + // retur start + $MapNatGroup_Retur_coaID = $prm['MapNatGroup_Retur_coaID']; + $sql_r = "SELECT * FROM coa where coaID = '$MapNatGroup_Retur_coaID' + AND coaIsInput = 'Y' + AND coaIsActive = 'Y'"; + + $qry_r = $this->db_onedev->query($sql_r); + if (!$qry_r) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_r = $qry_r->result_array(); + + // empty $rows_r + if (empty($rows_r)) { + $rows_r = [[ + "coaID" => 0, + "coaAccountNo" => '', + "coaDescription" => '', + "coaSubDescription" => '', + "coaAccountType" => '', + "coaSpecialAccountType" => '', + "coaIsInput" => 'N', + "coaReportSchedule" => '', + "coaCurrencyCode" => '', + "coaCashFlowCategory" => '', + "coaCreated" => '', + "coaLastUpdated" => '', + "coaIsActive" => 'Y', + "coaLevel" => 1 + ]]; + } + // retur end + + $response = [ + "records_group_all" => $rows_gx, + "record_map_nat_group" => $rows_m, + "records_group" => $rows_g, + "records_uang_muka" => $rows_u, + "records_hutang" => $rows_h, + "records_disc" => $rows_d, + "records_retur" => $rows_r, + "sql" => $this->db_onedev->last_query() + ]; + + $this->sys_ok($response); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // editData + function editData() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $this->db_onedev->trans_begin(); + $e_nat_group = $prm['e_nat_group']; + $e_coa_uang_muka = $prm['e_coa_uang_muka']; + $e_coa_hutang = $prm['e_coa_hutang']; + $e_coa_disc_pendapatan = $prm['e_coa_disc_pendapatan']; + $e_coa_retur_pendapatan = $prm['e_coa_retur_pendapatan']; + $MapNatGroup_ID = $prm['MapNatGroup_ID']; + + // defined variable + + $MapNatGroup_LastUpdatedAt = date('Y-m-d H:i:s'); + + // // nat_group + // $MapNatGroup_NatGroupID = $e_nat_group['Nat_GroupID']; + + // // disc pendaptan + // $MapNatGroup_Disc_coaID = $e_coa_disc_pendapatan['coaID']; + // $MapNatGroup_Disc_coaAccNo = $e_coa_disc_pendapatan['coaAccountNo']; + // $MapNatGroup_Disc_coaDesc = $e_coa_disc_pendapatan['coaDescription']; + + // // retur pendapatan + // $MapNatGroup_Retur_coaID = $e_coa_retur_pendapatan['coaID']; + // $MapNatGroup_Retur_coaAccNo = $e_coa_retur_pendapatan['coaAccountNo']; + // $MapNatGroup_Retur_coaDesc = $e_coa_retur_pendapatan['coaDescription']; + + // // uang muka + // $MapNatGroup_Dp_coaID = $e_coa_uang_muka['coaID']; + // $MapNatGroup_Dp_coaAccNo = $e_coa_uang_muka['coaAccountNo']; + // $MapNatGroup_Dp_coaDesc = $e_coa_uang_muka['coaDescription']; + + // // hutang + // $MapNatGroup_Debt_coaID = $e_coa_hutang['coaID']; + // $MapNatGroup_Debt_coaAccNo = $e_coa_hutang['coaAccountNo']; + // $MapNatGroup_Debt_coaDesc = $e_coa_hutang['coaDescription']; + + + // nat_group + $MapNatGroup_NatGroupID = isset($e_nat_group['Nat_GroupID']) ? $e_nat_group['Nat_GroupID'] : 0; + + // disc pendapatan + $MapNatGroup_Disc_coaID = isset($e_coa_disc_pendapatan['coaID']) ? $e_coa_disc_pendapatan['coaID'] : 0; + $MapNatGroup_Disc_coaAccNo = isset($e_coa_disc_pendapatan['coaAccountNo']) ? $e_coa_disc_pendapatan['coaAccountNo'] : ''; + $MapNatGroup_Disc_coaDesc = isset($e_coa_disc_pendapatan['coaDescription']) ? $e_coa_disc_pendapatan['coaDescription'] : ''; + + // retur pendapatan + $MapNatGroup_Retur_coaID = isset($e_coa_retur_pendapatan['coaID']) ? $e_coa_retur_pendapatan['coaID'] : 0; + $MapNatGroup_Retur_coaAccNo = isset($e_coa_retur_pendapatan['coaAccountNo']) ? $e_coa_retur_pendapatan['coaAccountNo'] : ''; + $MapNatGroup_Retur_coaDesc = isset($e_coa_retur_pendapatan['coaDescription']) ? $e_coa_retur_pendapatan['coaDescription'] : ''; + + // uang muka + $MapNatGroup_Dp_coaID = isset($e_coa_uang_muka['coaID']) ? $e_coa_uang_muka['coaID'] : 0; + $MapNatGroup_Dp_coaAccNo = isset($e_coa_uang_muka['coaAccountNo']) ? $e_coa_uang_muka['coaAccountNo'] : ''; + $MapNatGroup_Dp_coaDesc = isset($e_coa_uang_muka['coaDescription']) ? $e_coa_uang_muka['coaDescription'] : ''; + + // hutang + $MapNatGroup_Debt_coaID = isset($e_coa_hutang['coaID']) ? $e_coa_hutang['coaID'] : 0; + $MapNatGroup_Debt_coaAccNo = isset($e_coa_hutang['coaAccountNo']) ? $e_coa_hutang['coaAccountNo'] : ''; + $MapNatGroup_Debt_coaDesc = isset($e_coa_hutang['coaDescription']) ? $e_coa_hutang['coaDescription'] : ''; + + $sql = "UPDATE map_nat_group + SET + MapNatGroup_NatGroupID = '$MapNatGroup_NatGroupID', + MapNatGroup_Disc_coaID = '$MapNatGroup_Disc_coaID', + MapNatGroup_Disc_coaAccNo = '$MapNatGroup_Disc_coaAccNo', + MapNatGroup_Disc_coaDesc = '$MapNatGroup_Disc_coaDesc', + MapNatGroup_Retur_coaID = '$MapNatGroup_Retur_coaID', + MapNatGroup_Retur_coaAccNo = '$MapNatGroup_Retur_coaAccNo', + MapNatGroup_Retur_coaDesc = '$MapNatGroup_Retur_coaDesc', + MapNatGroup_Dp_coaID = '$MapNatGroup_Dp_coaID', + MapNatGroup_Dp_coaAccNo = '$MapNatGroup_Dp_coaAccNo', + MapNatGroup_Dp_coaDesc = '$MapNatGroup_Dp_coaDesc', + MapNatGroup_Debt_coaID = '$MapNatGroup_Debt_coaID', + MapNatGroup_Debt_coaAccNo = '$MapNatGroup_Debt_coaAccNo', + MapNatGroup_Debt_coaDesc = '$MapNatGroup_Debt_coaDesc', + MapNatGroup_LastUpdatedAt = '$MapNatGroup_LastUpdatedAt' + WHERE MapNatGroup_ID = '$MapNatGroup_ID'"; + + // echo $sql; + + $qry = $this->db_onedev->query($sql); + if (!$qry) { + $this->db_onedev->trans_rollback(); + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $last_qry + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $this->db_onedev->trans_commit(); + $result = array("total" => 1); + $this->sys_ok($result); + + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + +} +?> \ No newline at end of file diff --git a/application/controllers/map/Natsubgroup.php b/application/controllers/map/Natsubgroup.php new file mode 100644 index 0000000..13a5759 --- /dev/null +++ b/application/controllers/map/Natsubgroup.php @@ -0,0 +1,960 @@ +db_onedev = $this->load->database("onedev", true); + } + + // lookup nat_group + function getNatGroup() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $sql = "SELECT Nat_GroupID, + Nat_GroupCode, + Nat_GroupName + FROM nat_group + WHERE Nat_GroupIsActive ='Y'"; + $qry = $this->db_onedev->query($sql, array()); + + if (!$qry) { + // $this->db->trans_rollback(); + $this->sys_error_db("Error get nat_group"); + exit; + } + $result = $qry->result_array(); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // lookup nat_sub_group + function getNatSubGroup() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $sql = "SELECT + p.Nat_GroupName, + c.Nat_SubGroupID, + c.Nat_SubGroupNat_GroupID, + c.Nat_SubGroupCode, + c.Nat_SubGroupName, + c.Nat_SubGroupLangName, + c.Nat_SubGroupIsResult, + c.Nat_SubGroupReportTitle, + c.Nat_SubGroupCreated, + c.Nat_SubGroupLastUpdated, + c.Nat_SubGroupIsActive, + CONCAT(p.Nat_GroupName,' - ',c.Nat_SubGroupName) as display + FROM nat_subgroup AS c + JOIN nat_group AS p + ON c.Nat_SubGroupNat_GroupID = p.Nat_GroupID + AND c.Nat_SubGroupIsActive = 'Y' + AND p.Nat_GroupIsActive = 'Y'"; + $qry = $this->db_onedev->query($sql, array()); + + if (!$qry) { + // $this->db->trans_rollback(); + $this->sys_error_db("Error get nat_subgroup"); + exit; + } + $result = $qry->result_array(); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // ac pendapatan + function getAcPendapatan() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $search = $prm['search']; + // $where_search = "%%"; + $where_search_desc = '%'.$search.'%'; + $where_search_acc = "$search%"; + + $sql = "SELECT + coaID, + coaAccountNo, + coaDescription, + coaSubDescription, + coaAccountType, + coaSpecialAccountType, + coaIsInput, + coaReportSchedule, + coaCurrencyCode, + coaCashFlowCategory, + coaCreated, + coaLastUpdated, + coaIsActive, + coaLevel + FROM coa + WHERE coaIsInput = 'Y' + AND coaIsActive = 'Y' + AND + ( + coaDescription LIKE '$where_search_desc' + OR coaAccountNo LIKE '$where_search_acc' + )"; + + // echo $sql; + // die(); + $qry = $this->db_onedev->query($sql, array()); + + if (!$qry) { + // $this->db->trans_rollback(); + $this->sys_error_db("Error get coa pendapatan"); + exit; + } + $result = $qry->result_array(); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // ac biaya + function getAcBiaya() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $search = $prm['search']; + // $where_search = "%%"; + $where_search_desc = '%'.$search.'%'; + $where_search_acc = "$search%"; + + $sql = "SELECT + coaID, + coaAccountNo, + coaDescription, + coaSubDescription, + coaAccountType, + coaSpecialAccountType, + coaIsInput, + coaReportSchedule, + coaCurrencyCode, + coaCashFlowCategory, + coaCreated, + coaLastUpdated, + coaIsActive, + coaLevel + FROM coa + WHERE coaIsInput = 'Y' + AND coaIsActive = 'Y' + AND + ( + coaDescription LIKE '$where_search_desc' + OR coaAccountNo LIKE '$where_search_acc' + )"; + + // echo $sql; + // die(); + $qry = $this->db_onedev->query($sql, array()); + + if (!$qry) { + // $this->db->trans_rollback(); + $this->sys_error_db("Error get coa pendapatan"); + exit; + } + $result = $qry->result_array(); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // ac persediaan + function getAcPersediaan() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $search = $prm['search']; + // $where_search = "%%"; + $where_search_desc = '%'.$search.'%'; + $where_search_acc = "$search%"; + + $sql = "SELECT + coaID, + coaAccountNo, + coaDescription, + coaSubDescription, + coaAccountType, + coaSpecialAccountType, + coaIsInput, + coaReportSchedule, + coaCurrencyCode, + coaCashFlowCategory, + coaCreated, + coaLastUpdated, + coaIsActive, + coaLevel + FROM coa + WHERE coaIsInput = 'Y' + AND coaIsActive = 'Y' + AND + ( + coaDescription LIKE '$where_search_desc' + OR coaAccountNo LIKE '$where_search_acc' + )"; + + // echo $sql; + // die(); + $qry = $this->db_onedev->query($sql, array()); + + if (!$qry) { + // $this->db->trans_rollback(); + $this->sys_error_db("Error get coa pendapatan"); + exit; + } + $result = $qry->result_array(); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // addData + function addData() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $this->db_onedev->trans_begin(); + + $a_nat_group = $prm['a_nat_group']; + $a_nat_subgroup = $prm['a_nat_subgroup']; + $a_coa_pendapatan = $prm['a_coa_pendapatan']; + $a_coa_biaya = $prm['a_coa_biaya']; + $a_coa_persediaan = $prm['a_coa_persediaan']; + + $MapNatSub_IsActive = 'Y'; + $MapNatSub_CreatedAt = date('Y-m-d H:i:s'); + $MapNatSub_LastUpdatedAt = date('Y-m-d H:i:s'); + + // nat_group + $MapNatSub_NatGroupID = isset($a_nat_group['Nat_GroupID']) ? $a_nat_group['Nat_GroupID'] : 0; + + // nat_subgroup + $MapNatSub_NatSubGroupID = isset($a_nat_subgroup['Nat_SubGroupID']) ? $a_nat_subgroup['Nat_SubGroupID'] : 0; + $MapNatSub_NatSubGroupCode = isset($a_nat_subgroup['Nat_SubGroupCode']) ? $a_nat_subgroup['Nat_SubGroupCode'] : ''; + + // pendapatan + $MapNatSub_PendapatanCoaID = isset($a_coa_pendapatan['coaID']) ? $a_coa_pendapatan['coaID'] : 0; + $MapNatSub_PendapatanCoaAccountNo = isset($a_coa_pendapatan['coaAccountNo']) ? $a_coa_pendapatan['coaAccountNo'] : ''; + $MapNatSub_PendapatanCoaDescription = isset($a_coa_pendapatan['coaDescription']) ? $a_coa_pendapatan['coaDescription'] : ''; + + // biaya + $MapNatSub_BiayaCoaID = isset($a_coa_biaya['coaID']) ? $a_coa_biaya['coaID'] : 0; + $MapNatSub_BiayaCoaAccountNo = isset($a_coa_biaya['coaAccountNo']) ? $a_coa_biaya['coaAccountNo'] : ''; + $MapNatSub_BiayaCoaDescription = isset($a_coa_biaya['coaDescription']) ? $a_coa_biaya['coaDescription'] : ''; + + // persediaan + $MapNatSub_PersediaanCoaID = isset($a_coa_persediaan['coaID']) ? $a_coa_persediaan['coaID'] : 0; + $MapNatSub_PersediaanCoaAccountNo = isset($a_coa_persediaan['coaAccountNo']) ? $a_coa_persediaan['coaAccountNo'] : ''; + $MapNatSub_PersediaanCoaDescription = isset($a_coa_persediaan['coaDescription']) ? $a_coa_persediaan['coaDescription'] : ''; + + // check jika sudah ada MapNatSub_NatGroupID AND MapNatSub_NatSubGroupID maka tidak boleh insert + $sql_gn = "SELECT * + FROM nat_group + WHERE Nat_GroupID = '$MapNatSub_NatGroupID' + AND Nat_GroupIsActive = 'Y'"; + + $qry_gn = $this->db_onedev->query($sql_gn); + if (!$qry_gn) { + $this->db_onedev->trans_rollback(); + $error = array( + "message" => $this->db_onedev->error()["message"], + // "sql" => $last_qry + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + $rows_gn = $qry_gn->result(); + $grup_name = ""; + $grup_name .= $rows_gn[0]->Nat_GroupName; + + // sub group + + $sql_sub = "SELECT * + FROM nat_subgroup + WHERE Nat_SubGroupID = '$MapNatSub_NatSubGroupID' + AND Nat_SubGroupIsActive = 'Y'"; + + $qry_sub = $this->db_onedev->query($sql_sub); + if (!$qry_sub) { + $this->db_onedev->trans_rollback(); + $error = array( + "message" => $this->db_onedev->error()["message"], + // "sql" => $last_qry + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + $rows_sub = $qry_sub->result(); + $sub_grup_name = ""; + $sub_grup_name .= $rows_sub[0]->Nat_SubGroupName; + + $sql_c = "SELECT * from map_nat_subgroup + where MapNatSub_IsActive = 'Y' + AND MapNatSub_NatGroupID = '$MapNatSub_NatGroupID' + AND MapNatSub_NatSubGroupID ='$MapNatSub_NatSubGroupID'"; + + $qry_c = $this->db_onedev->query($sql_c); + if (!$qry_c) { + $this->db_onedev->trans_rollback(); + $error = array( + "message" => $this->db_onedev->error()["message"], + // "sql" => $last_qry + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_c = $qry_c->result_array(); + if(count($rows_c) > 0) { + $this->db_onedev->trans_rollback(); + $this->sys_error("Group Name dengan nama $grup_name, Sub Group dengan nama $sub_grup_name, sudah ada"); + exit; + } + + // mulai insert + $sql = "INSERT INTO map_nat_subgroup + ( + MapNatSub_NatGroupID, + MapNatSub_NatSubGroupID, + MapNatSub_NatSubGroupCode, + MapNatSub_IsActive, + MapNatSub_CreatedAt, + MapNatSub_LastUpdatedAt, + MapNatSub_PendapatanCoaID, + MapNatSub_PendapatanCoaAccountNo, + MapNatSub_PendapatanCoaDescription, + MapNatSub_BiayaCoaID, + MapNatSub_BiayaCoaAccountNo, + MapNatSub_BiayaCoaDescription, + MapNatSub_PersediaanCoaID, + MapNatSub_PersediaanCoaAccountNo, + MapNatSub_PersediaanCoaDescription + ) + VALUES ( + '$MapNatSub_NatGroupID', + '$MapNatSub_NatSubGroupID', + '$MapNatSub_NatSubGroupCode', + '$MapNatSub_IsActive', + '$MapNatSub_CreatedAt', + '$MapNatSub_LastUpdatedAt', + '$MapNatSub_PendapatanCoaID', + '$MapNatSub_PendapatanCoaAccountNo', + '$MapNatSub_PendapatanCoaDescription', + '$MapNatSub_BiayaCoaID', + '$MapNatSub_BiayaCoaAccountNo', + '$MapNatSub_BiayaCoaDescription', + '$MapNatSub_PersediaanCoaID', + '$MapNatSub_PersediaanCoaAccountNo', + '$MapNatSub_PersediaanCoaDescription' + )"; + + // echo $sql; + + $qry = $this->db_onedev->query($sql); + if (!$qry) { + $this->db_onedev->trans_rollback(); + $error = array( + "message" => $this->db_onedev->error()["message"], + // "sql" => $last_qry + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $this->db_onedev->trans_commit(); + $result = array("total" => 1); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // search + function search() + { + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $prm = $this->sys_input; + $search = isset($prm["search"]) ? trim($prm["search"]) : ''; + $search = ($search !== '') ? "%$search%" : "%%"; + + // $number_offset = ($prm["current_page"] > 0) ? ($prm["current_page"] - 1) * 20 : 0; + // $number_limit = 2; + $number_limit = 10; + $number_offset = ($prm["current_page"] > 0) ? ($prm["current_page"] - 1) * $number_limit : 0; + + $sql = "SELECT + IFNULL(m.MapNatSub_ID, 0) AS MapNatSub_ID, + IFNULL(m.MapNatSub_NatGroupID, 0) AS MapNatSub_NatGroupID, + IFNULL(m.MapNatSub_NatSubGroupID, 0) AS MapNatSub_NatSubGroupID, + IFNULL(m.MapNatSub_NatSubGroupCode, '') AS MapNatSub_NatSubGroupCode, + IFNULL(m.MapNatSub_IsActive, '') AS MapNatSub_IsActive, + IFNULL(m.MapNatSub_CreatedAt, '') AS MapNatSub_CreatedAt, + IFNULL(m.MapNatSub_LastUpdatedAt, '') AS MapNatSub_LastUpdatedAt, + IFNULL(m.MapNatSub_PendapatanCoaID, 0) AS MapNatSub_PendapatanCoaID, + IFNULL(m.MapNatSub_PendapatanCoaAccountNo, '') AS MapNatSub_PendapatanCoaAccountNo, + IFNULL(m.MapNatSub_PendapatanCoaDescription, '') AS MapNatSub_PendapatanCoaDescription, + IFNULL(m.MapNatSub_BiayaCoaID, 0) AS MapNatSub_BiayaCoaID, + IFNULL(m.MapNatSub_BiayaCoaAccountNo, '') AS MapNatSub_BiayaCoaAccountNo, + IFNULL(m.MapNatSub_BiayaCoaDescription, '') AS MapNatSub_BiayaCoaDescription, + IFNULL(m.MapNatSub_PersediaanCoaID, 0) AS MapNatSub_PersediaanCoaID, + IFNULL(m.MapNatSub_PersediaanCoaAccountNo, '') AS MapNatSub_PersediaanCoaAccountNo, + IFNULL(m.MapNatSub_PersediaanCoaDescription, '') AS MapNatSub_PersediaanCoaDescription, + IFNULL(g.Nat_GroupID, 0) AS Nat_GroupID, + IFNULL(g.Nat_GroupName, '') AS Nat_GroupName, + IFNULL(g.Nat_GroupIsActive, '') AS Nat_GroupIsActive, + IFNULL(s.Nat_SubGroupID, 0) AS Nat_SubGroupID, + IFNULL(s.Nat_SubGroupCode, '') AS Nat_SubGroupCode, + IFNULL(s.Nat_SubGroupName, '') AS Nat_SubGroupName, + IFNULL(s.Nat_SubGroupLangName, '') AS Nat_SubGroupLangName, + IFNULL(s.Nat_SubGroupIsResult, '') AS Nat_SubGroupIsResult, + IFNULL(s.Nat_SubGroupReportTitle, '') AS Nat_SubGroupReportTitle, + IFNULL(s.Nat_SubGroupCreated, '') AS Nat_SubGroupCreated, + IFNULL(s.Nat_SubGroupLastUpdated, '') AS Nat_SubGroupLastUpdated, + IFNULL(s.Nat_SubGroupIsActive, '') AS Nat_SubGroupIsActive, + IFNULL(c_pendapatan.coaID, 0) AS PendapatanCoaID, + IFNULL(c_pendapatan.coaAccountNo, '') AS PendapatanCoaAccountNo, + IFNULL(c_pendapatan.coaDescription, '') AS PendapatanCoaDescription, + IFNULL(c_biaya.coaID, 0) AS BiayaCoaID, + IFNULL(c_biaya.coaAccountNo, '') AS BiayaCoaAccountNo, + IFNULL(c_biaya.coaDescription, '') AS BiayaCoaDescription, + IFNULL(c_persediaan.coaID, 0) AS PersediaanCoaID, + IFNULL(c_persediaan.coaAccountNo, '') AS PersediaanCoaAccountNo, + IFNULL(c_persediaan.coaDescription, '') AS PersediaanCoaDescription + FROM map_nat_subgroup m + LEFT JOIN nat_group g + ON m.MapNatSub_NatGroupID = g.Nat_GroupID + AND g.Nat_GroupIsActive = 'Y' + LEFT JOIN nat_subgroup s + ON m.MapNatSub_NatSubGroupID = s.Nat_SubGroupID + AND s.Nat_SubGroupIsActive = 'Y' + LEFT JOIN coa c_pendapatan + ON m.MapNatSub_PendapatanCoaID = c_pendapatan.coaID + AND c_pendapatan.coaIsInput = 'Y' + AND c_pendapatan.coaIsActive = 'Y' + LEFT JOIN coa c_biaya + ON m.MapNatSub_BiayaCoaID = c_biaya.coaID + AND c_biaya.coaIsInput = 'Y' + AND c_biaya.coaIsActive = 'Y' + LEFT JOIN coa c_persediaan + ON m.MapNatSub_PersediaanCoaID = c_persediaan.coaID + AND c_persediaan.coaIsInput = 'Y' + AND c_persediaan.coaIsActive = 'Y' + WHERE m.MapNatSub_IsActive = 'Y' + AND ( + g.Nat_GroupName LIKE '$search' OR + s.Nat_SubGroupName LIKE '$search' OR + m.MapNatSub_NatSubGroupCode LIKE '$search' OR + m.MapNatSub_PendapatanCoaAccountNo LIKE '$search' OR + m.MapNatSub_PendapatanCoaDescription LIKE '$search' OR + m.MapNatSub_BiayaCoaAccountNo LIKE '$search' OR + m.MapNatSub_BiayaCoaDescription LIKE '$search' OR + m.MapNatSub_PersediaanCoaAccountNo LIKE '$search' OR + m.MapNatSub_PersediaanCoaDescription LIKE '$search' + ) + ORDER BY m.MapNatSub_ID ASC"; + + $sql_total = "SELECT count(*) as total FROM ($sql) as x"; + $qry_total = $this->db_onedev->query($sql_total); + + $totalCount = 0; + $totalPage = 0; + if ($qry_total) { + $totalCount = $qry_total->result_array()[0]["total"]; + $totalPage = ceil($totalCount / $number_limit); + } else { + $this->sys_error_db("select map_nat_subgroup count error", $this->db_onedev);; + exit; + } + + $sql_select = $sql . " LIMIT $number_limit OFFSET $number_offset"; + + $qry = $this->db_onedev->query($sql_select); + if ($qry) { + $rows = $qry->result_array(); + } else { + $this->db_onedev->trans_rollback(); + $this->sys_error_db("select map_nat_subgroup error", $this->db_onedev); + exit; + } + + $response = [ + "total" => $totalPage, + "totalFilter" => $totalCount, + "records" => $rows, + "sql" => $this->db_onedev->last_query() + ]; + + $this->sys_ok($response); + } catch (Exception $exc) { + $this->sys_error($exc->getMessage()); + } + } + + // get_by_id + function get_by_id() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + // map_nat_subgroup + $MapNatSub_ID = isset($prm['MapNatSub_ID']) ? $prm['MapNatSub_ID'] : 0; + + $sql_m = "SELECT * FROM map_nat_subgroup where MapNatSub_ID = '$MapNatSub_ID'"; + + $qry_m = $this->db_onedev->query($sql_m); + if (!$qry_m) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_m = $qry_m->result_array(); + + // empty rows_m + if (empty($rows_m)) { + $rows_m = [[ + "MapNatSub_ID" => 0, + "MapNatSub_NatGroupID" => 0, + "MapNatSub_NatSubGroupID" => 0, + "MapNatSub_NatSubGroupCode" => '', + "MapNatSub_IsActive" => 'Y', + "MapNatSub_CreatedAt" => '', + "MapNatSub_LastUpdatedAt" => '', + "MapNatSub_PendapatanCoaID" => 0, + "MapNatSub_PendapatanCoaAccountNo" => '', + "MapNatSub_PendapatanCoaDescription" => '', + "MapNatSub_BiayaCoaID" => 0, + "MapNatSub_BiayaCoaAccountNo" => '', + "MapNatSub_BiayaCoaDescription" => '', + "MapNatSub_PersediaanCoaID" => 0, + "MapNatSub_PersediaanCoaAccountNo" => '', + "MapNatSub_PersediaanCoaDescription" => '' + ]]; + } + + // nat group + $MapNatSub_NatGroupID = isset($prm['MapNatSub_NatGroupID']) ? $prm['MapNatSub_NatGroupID'] : 0; + $sql_g = "SELECT * FROM nat_group where Nat_GroupID = '$MapNatSub_NatGroupID'"; + + $qry_g = $this->db_onedev->query($sql_g); + if (!$qry_g) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_g = $qry_g->result_array(); + + if (empty($rows_g)) { + $rows_g = [[ + "Nat_GroupID" => 0, + "Nat_GroupCode" => '', + "Nat_GroupName" => '', + "Nat_GroupCreated" => '', + "Nat_GroupLastUpdated"=> '', + "Nat_GroupIsActive" => 'Y' + ]]; + } + + $sql_gx = "SELECT * FROM nat_group where Nat_GroupIsActive = 'Y'"; + + $qry_gx = $this->db_onedev->query($sql_gx); + if (!$qry_gx) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_gx = $qry_gx->result_array(); + + // nat sub group + $MapNatSub_NatSubGroupID = isset($prm['MapNatSub_NatSubGroupID']) ? $prm['MapNatSub_NatSubGroupID'] : 0; + $sql_sg = "SELECT c.*, + CONCAT(p.Nat_GroupName,' - ',c.Nat_SubGroupName) as display + FROM nat_subgroup c + JOIN nat_group AS p + ON c.Nat_SubGroupNat_GroupID = p.Nat_GroupID + AND c.Nat_SubGroupIsActive = 'Y' + AND p.Nat_GroupIsActive = 'Y' + where Nat_SubGroupID = '$MapNatSub_NatSubGroupID'"; + + $qry_sg = $this->db_onedev->query($sql_sg); + if (!$qry_sg) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_sg = $qry_sg->result_array(); + + if (empty($rows_sg)) { + $rows_sg = [[ + "Nat_SubGroupID" => 0, + "Nat_SubGroupNat_GroupID" => 0, + "Nat_SubGroupCode" => '', + "Nat_SubGroupName" => '', + "Nat_SubGroupLangName" => '', + "Nat_SubGroupIsResult" => 'N', + "Nat_SubGroupReportTitle" => '', + "Nat_SubGroupCreated" => '', + "Nat_SubGroupLastUpdated" => '', + "Nat_SubGroupIsActive" => 'Y', + "display" => '' + ]]; + } + + $sql_sgx = "SELECT c.*, + CONCAT(p.Nat_GroupName,' - ',c.Nat_SubGroupName) as display + FROM nat_subgroup c + JOIN nat_group AS p + ON c.Nat_SubGroupNat_GroupID = p.Nat_GroupID + AND c.Nat_SubGroupIsActive = 'Y' + AND p.Nat_GroupIsActive = 'Y'"; + + $qry_sgx = $this->db_onedev->query($sql_sgx); + if (!$qry_sgx) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_sgx = $qry_sgx->result_array(); + + // pendapatan + $MapNatSub_PendapatanCoaID = isset($prm['MapNatSub_PendapatanCoaID']) ? $prm['MapNatSub_PendapatanCoaID'] : 0; + $sql_p = "SELECT * FROM coa where coaID = '$MapNatSub_PendapatanCoaID' + AND coaIsInput = 'Y' + AND coaIsActive = 'Y' + "; + + $qry_p = $this->db_onedev->query($sql_p); + if (!$qry_p) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_p = $qry_p->result_array(); + + if (empty($rows_p)) { + $rows_p = [[ + "coaID" => 0, + "coaAccountNo" => '', + "coaDescription" => '', + "coaSubDescription" => '', + "coaAccountType" => '', + "coaSpecialAccountType" => '', + "coaIsInput" => 'N', + "coaReportSchedule" => '', + "coaCurrencyCode" => '', + "coaCashFlowCategory" => '', + "coaCreated" => '', + "coaLastUpdated" => '', + "coaIsActive" => 'Y', + "coaLevel" => 1 + ]]; + } + + // biaya + $MapNatSub_BiayaCoaID = isset($prm['MapNatSub_BiayaCoaID']) ? $prm['MapNatSub_BiayaCoaID'] : 0; + $sql_b = "SELECT * FROM coa where coaID = '$MapNatSub_BiayaCoaID' + AND coaIsInput = 'Y' + AND coaIsActive = 'Y' + "; + + $qry_b = $this->db_onedev->query($sql_b); + if (!$qry_b) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_b = $qry_b->result_array(); + + if (empty($rows_b)) { + $rows_b = [[ + "coaID" => 0, + "coaAccountNo" => '', + "coaDescription" => '', + "coaSubDescription" => '', + "coaAccountType" => '', + "coaSpecialAccountType" => '', + "coaIsInput" => 'N', + "coaReportSchedule" => '', + "coaCurrencyCode" => '', + "coaCashFlowCategory" => '', + "coaCreated" => '', + "coaLastUpdated" => '', + "coaIsActive" => 'Y', + "coaLevel" => 1 + ]]; + } + + // psd + $MapNatSub_PersediaanCoaID = isset($prm['MapNatSub_PersediaanCoaID']) ? $prm['MapNatSub_PersediaanCoaID'] : 0; + $sql_psd = "SELECT * FROM coa where coaID = '$MapNatSub_PersediaanCoaID' + AND coaIsInput = 'Y' + AND coaIsActive = 'Y' + "; + + $qry_psd = $this->db_onedev->query($sql_psd); + if (!$qry_psd) { + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $this->db_onedev->last_query() + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $rows_psd = $qry_psd->result_array(); + + if (empty($rows_psd)) { + $rows_psd = [[ + "coaID" => 0, + "coaAccountNo" => '', + "coaDescription" => '', + "coaSubDescription" => '', + "coaAccountType" => '', + "coaSpecialAccountType" => '', + "coaIsInput" => 'N', + "coaReportSchedule" => '', + "coaCurrencyCode" => '', + "coaCashFlowCategory" => '', + "coaCreated" => '', + "coaLastUpdated" => '', + "coaIsActive" => 'Y', + "coaLevel" => 1 + ]]; + } + + // response + $response = [ + "record_map_nat_subgroup" => $rows_m, + "records_group" => $rows_g, + "records_group_all" => $rows_gx, + "records_sub_group" => $rows_sg, + "records_sub_group_all" => $rows_sgx, + "records_pendapatan" => $rows_p, + "records_biaya" => $rows_b, + "records_persediaan" => $rows_psd, + "sql" => $sql_sg + ]; + + $this->sys_ok($response); + + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // editData + function editData() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $this->db_onedev->trans_begin(); + $e_nat_group = $prm['e_nat_group']; + $e_nat_subgroup = $prm['e_nat_subgroup']; + $e_coa_biaya = $prm['e_coa_biaya']; + $e_coa_pendapatan = $prm['e_coa_pendapatan']; + $e_coa_persediaan = $prm['e_coa_persediaan']; + + $MapNatSub_ID = $prm['MapNatSub_ID']; + + // defined variable + + $MapNatSub_LastUpdatedAt = date('Y-m-d H:i:s'); + + // nat_group + $MapNatSub_NatGroupID = isset($e_nat_group['Nat_GroupID']) ? $e_nat_group['Nat_GroupID'] : 0; + + // nat sub grup + $MapNatSub_NatSubGroupID = isset($e_nat_subgroup['Nat_SubGroupID']) ? $e_nat_subgroup['Nat_SubGroupID'] : 0; + $MapNatSub_NatSubGroupCode = isset($e_nat_subgroup['Nat_SubGroupCode']) ? $e_nat_subgroup['Nat_SubGroupCode'] : ''; + + // pendapatan + $MapNatSub_PendapatanCoaID = isset($e_coa_pendapatan['coaID']) ? $e_coa_pendapatan['coaID'] : 0; + $MapNatSub_PendapatanCoaAccountNo = isset($e_coa_pendapatan['coaAccountNo']) ? $e_coa_pendapatan['coaAccountNo'] : ''; + $MapNatSub_PendapatanCoaDescription = isset($e_coa_pendapatan['coaDescription']) ? $e_coa_pendapatan['coaDescription'] : ''; + + // biaya + $MapNatSub_BiayaCoaID = isset($e_coa_biaya['coaID']) ? $e_coa_biaya['coaID'] : 0; + $MapNatSub_BiayaCoaAccountNo = isset($e_coa_biaya['coaAccountNo']) ? $e_coa_biaya['coaAccountNo'] : ''; + $MapNatSub_BiayaCoaDescription = isset($e_coa_biaya['coaDescription']) ? $e_coa_biaya['coaDescription'] : ''; + + // persediaan + $MapNatSub_PersediaanCoaID = isset($e_coa_persediaan['coaID']) ? $e_coa_persediaan['coaID'] : 0; + $MapNatSub_PersediaanCoaAccountNo = isset($e_coa_persediaan['coaAccountNo']) ? $e_coa_persediaan['coaAccountNo'] : ''; + $MapNatSub_PersediaanCoaDescription = isset($e_coa_persediaan['coaDescription']) ? $e_coa_persediaan['coaDescription'] : ''; + + $sql = "UPDATE map_nat_subgroup + SET + MapNatSub_NatGroupID = '$MapNatSub_NatGroupID', + MapNatSub_NatSubGroupID = '$MapNatSub_NatSubGroupID', + MapNatSub_NatSubGroupCode = '$MapNatSub_NatSubGroupCode', + MapNatSub_IsActive = 'Y', + MapNatSub_LastUpdatedAt = '$MapNatSub_LastUpdatedAt', + MapNatSub_PendapatanCoaID = '$MapNatSub_PendapatanCoaID', + MapNatSub_PendapatanCoaAccountNo = '$MapNatSub_PendapatanCoaAccountNo', + MapNatSub_PendapatanCoaDescription = '$MapNatSub_PendapatanCoaDescription', + MapNatSub_BiayaCoaID = '$MapNatSub_BiayaCoaID', + MapNatSub_BiayaCoaAccountNo = '$MapNatSub_BiayaCoaAccountNo', + MapNatSub_BiayaCoaDescription = '$MapNatSub_BiayaCoaDescription', + MapNatSub_PersediaanCoaID = '$MapNatSub_PersediaanCoaID', + MapNatSub_PersediaanCoaAccountNo = '$MapNatSub_PersediaanCoaAccountNo', + MapNatSub_PersediaanCoaDescription = '$MapNatSub_PersediaanCoaDescription' + WHERE MapNatSub_ID = '$MapNatSub_ID'"; + + // echo $sql; + + $qry = $this->db_onedev->query($sql); + if (!$qry) { + $this->db_onedev->trans_rollback(); + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $last_qry + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $this->db_onedev->trans_commit(); + $result = array("total" => 1); + $this->sys_ok($result); + + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + + // deleteData + function deleteData() + { + $prm = $this->sys_input; + try { + if (! $this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + + $this->db_onedev->trans_begin(); + $MapNatSub_ID = $prm['MapNatSub_ID']; + $MapNatSub_LastUpdatedAt = date('Y-m-d H:i:s'); + + $sql = "UPDATE map_nat_subgroup + SET + MapNatSub_IsActive = 'N', + MapNatSub_LastUpdatedAt = '$MapNatSub_LastUpdatedAt' + WHERE MapNatSub_ID = '$MapNatSub_ID'"; + + $qry = $this->db_onedev->query($sql); + if (!$qry) { + $this->db_onedev->trans_rollback(); + $error = array( + "message" => $this->db_onedev->error()["message"], + "sql" => $last_qry + ); + $this->sys_error_db($error, $this->db_onedev); + exit; + } + + $this->db_onedev->trans_commit(); + $result = array("total" => 1); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } +} +?> \ No newline at end of file