"ERR", "message" => "Http Error : " . curl_error($ch), ]); curl_close($ch); exit(); } curl_close($ch); return $result; } function reply($resp) { echo json_encode($resp); } public function getdata_nat_test($table, $lastdownload) { $this->db->trans_begin(); $lastdownload_full = $lastdownload . " 00:00:00"; $sql = "SELECT * FROM $table WHERE Nat_TestLastUpdated > ?"; $qry = $this->db->query($sql, [ $lastdownload_full ]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("Failed get name tabel", $this->db); exit; } $rows = $qry->result_array(); $dataparam = json_encode(array( "table" => $table, "data" => $rows )); if (count($rows) > 0) { $z_param = gzcompress($dataparam, 9); $url = "https://" . $this->hostname . "/one-api-lab/tools/synctable/update"; $resp = $this->post($url, $z_param); $j_resp = json_decode($resp, true); sleep(2); if ($j_resp["status"] == "OK") { $this->db->trans_commit(); $this->reply([ "status" => "OK", "message" => 'Proses sync tabel ' . $table . ' berhasil', "total received" => $j_resp['total_received'], "total success" => $j_resp['total_success'] ]); } else { $this->db->trans_rollback(); $this->reply([ "status" => "ERR", 'message' => "Gagal sync pada tabel " . $table, 'debug' => print_r($resp, true) ]); } } else { $this->db->trans_rollback(); $this->reply([ "status" => "OK", 'message' => "Tidak Ada Data Pada Tabel " . $table ]); } } public function getdata_t_test($table, $lastdownload) { $this->db->trans_begin(); $lastdownload_full = $lastdownload . " 00:00:00"; $sql = "SELECT * FROM $table WHERE T_TestLastUpdated > ?"; $qry = $this->db->query($sql, [ $lastdownload_full ]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("Failed get name tabel", $this->db); exit; } $rows = $qry->result_array(); $dataparam = json_encode(array( "table" => $table, "data" => $rows )); if (count($rows) > 0) { $z_param = gzcompress($dataparam, 9); $url = "https://" . $this->hostname . "/one-api-lab/tools/synctable/update"; $resp = $this->post($url, $z_param); $j_resp = json_decode($resp, true); sleep(2); if ($j_resp["status"] == "OK") { $this->db->trans_commit(); $this->reply([ "status" => "OK", "message" => 'Proses sync tabel ' . $table . ' berhasil', "total received" => $j_resp['total_received'], "total success" => $j_resp['total_success'] ]); } else { $this->db->trans_rollback(); $this->reply([ "status" => "ERR", 'message' => "Gagal sync pada tabel " . $table, 'debug' => print_r($resp, true) ]); } } else { $this->db->trans_rollback(); $this->reply([ "status" => "OK", 'message' => "Tidak Ada Data Pada Tabel " . $table ]); } } public function getdata_nat_normalvalue($table, $lastdownload) { $this->db->trans_begin(); $lastdownload_full = $lastdownload . " 00:00:00"; $sql = "SELECT * FROM $table WHERE Nat_NormalValueLastUpdated > ?"; $qry = $this->db->query($sql, [ $lastdownload_full ]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("Failed get name tabel", $this->db); exit; } $rows = $qry->result_array(); $dataparam = json_encode(array( "table" => $table, "data" => $rows )); if (count($rows) > 0) { $z_param = gzcompress($dataparam, 9); $url = "https://" . $this->hostname . "/one-api-lab/tools/synctable/update"; $resp = $this->post($url, $z_param); $j_resp = json_decode($resp, true); sleep(2); if ($j_resp["status"] == "OK") { $this->db->trans_commit(); $this->reply([ "status" => "OK", "message" => 'Proses sync tabel ' . $table . ' berhasil', "total received" => $j_resp['total_received'], "total success" => $j_resp['total_success'] ]); } else { $this->db->trans_rollback(); $this->reply([ "status" => "ERR", 'message' => "Gagal sync pada tabel " . $table, 'debug' => print_r($resp, true) ]); } } else { $this->db->trans_rollback(); $this->reply([ "status" => "OK", 'message' => "Tidak Ada Data Pada Tabel " . $table ]); } } public function getdata_nat_subgroup($table, $lastdownload) { $this->db->trans_begin(); $lastdownload_full = $lastdownload . " 00:00:00"; $sql = "SELECT * FROM $table WHERE Nat_SubGroupLastUpdated > ?"; $qry = $this->db->query($sql, [ $lastdownload_full ]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("Failed get name tabel", $this->db); exit; } $rows = $qry->result_array(); $dataparam = json_encode(array( "table" => $table, "data" => $rows )); if (count($rows) > 0) { $z_param = gzcompress($dataparam, 9); $url = "https://" . $this->hostname . "/one-api-lab/tools/synctable/update"; $resp = $this->post($url, $z_param); $j_resp = json_decode($resp, true); sleep(2); if ($j_resp["status"] == "OK") { $this->db->trans_commit(); $this->reply([ "status" => "OK", "message" => 'Proses sync tabel ' . $table . ' berhasil', "total received" => $j_resp['total_received'], "total success" => $j_resp['total_success'] ]); } else { $this->db->trans_rollback(); $this->reply([ "status" => "ERR", 'message' => "Gagal sync pada tabel " . $table, 'debug' => print_r($resp, true) ]); } } else { $this->db->trans_rollback(); $this->reply([ "status" => "OK", 'message' => "Tidak Ada Data Pada Tabel " . $table ]); } } public function getdata_t_sampletype($table, $lastdownload) { $this->db->trans_begin(); $lastdownload_full = $lastdownload . " 00:00:00"; $sql = "SELECT * FROM $table WHERE T_SampleTypeLastUpdated > ?"; $qry = $this->db->query($sql, [ $lastdownload_full ]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("Failed get name tabel", $this->db); exit; } $rows = $qry->result_array(); $dataparam = json_encode(array( "table" => $table, "data" => $rows )); if (count($rows) > 0) { $z_param = gzcompress($dataparam, 9); $url = "https://" . $this->hostname . "/one-api-lab/tools/synctable/update"; $resp = $this->post($url, $z_param); $j_resp = json_decode($resp, true); sleep(2); if ($j_resp["status"] == "OK") { $this->db->trans_commit(); $this->reply([ "status" => "OK", "message" => 'Proses sync tabel ' . $table . ' berhasil', "total received" => $j_resp['total_received'], "total success" => $j_resp['total_success'] ]); } else { $this->db->trans_rollback(); $this->reply([ "status" => "ERR", 'message' => "Gagal sync pada tabel " . $table, 'debug' => print_r($resp, true) ]); } } else { $this->db->trans_rollback(); $this->reply([ "status" => "OK", 'message' => "Tidak Ada Data Pada Tabel " . $table ]); } } public function getdata_t_bahan($table, $lastdownload) { $this->db->trans_begin(); $lastdownload_full = $lastdownload . " 00:00:00"; $sql = "SELECT * FROM $table WHERE T_BahanLastUpdated > ?"; $qry = $this->db->query($sql, [ $lastdownload_full ]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("Failed get name tabel", $this->db); exit; } $rows = $qry->result_array(); $dataparam = json_encode(array( "table" => $table, "data" => $rows )); if (count($rows) > 0) { $z_param = gzcompress($dataparam, 9); $url = "https://" . $this->hostname . "/one-api-lab/tools/synctable/update"; $resp = $this->post($url, $z_param); $j_resp = json_decode($resp, true); sleep(2); if ($j_resp["status"] == "OK") { $this->db->trans_commit(); $this->reply([ "status" => "OK", "message" => 'Proses sync tabel ' . $table . ' berhasil', "total received" => $j_resp['total_received'], "total success" => $j_resp['total_success'] ]); } else { $this->db->trans_rollback(); $this->reply([ "status" => "ERR", 'message' => "Gagal sync pada tabel " . $table, 'debug' => print_r($resp, true) ]); } } else { $this->db->trans_rollback(); $this->reply([ "status" => "OK", 'message' => "Tidak Ada Data Pada Tabel " . $table ]); } } public function getdata_nat_methode($table, $lastdownload) { $this->db->trans_begin(); $lastdownload_full = $lastdownload . " 00:00:00"; $sql = "SELECT * FROM $table WHERE Nat_MethodeLastUpdated > ?"; $qry = $this->db->query($sql, [ $lastdownload_full ]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("Failed get name tabel", $this->db); exit; } $rows = $qry->result_array(); $dataparam = json_encode(array( "table" => $table, "data" => $rows )); if (count($rows) > 0) { $z_param = gzcompress($dataparam, 9); $url = "https://" . $this->hostname . "/one-api-lab/tools/synctable/update"; $resp = $this->post($url, $z_param); $j_resp = json_decode($resp, true); sleep(2); if ($j_resp["status"] == "OK") { $this->db->trans_commit(); $this->reply([ "status" => "OK", "message" => 'Proses sync tabel ' . $table . ' berhasil', "total received" => $j_resp['total_received'], "total success" => $j_resp['total_success'] ]); } else { $this->db->trans_rollback(); $this->reply([ "status" => "ERR", 'message' => "Gagal sync pada tabel " . $table, 'debug' => print_r($resp, true) ]); } } else { $this->db->trans_rollback(); $this->reply([ "status" => "OK", 'message' => "Tidak Ada Data Pada Tabel " . $table ]); } } public function getdata_nat_instrument($table, $lastdownload) { $this->db->trans_begin(); $lastdownload_full = $lastdownload . " 00:00:00"; $sql = "SELECT * FROM $table WHERE Nat_InstrumentLastUpdated > ?"; $qry = $this->db->query($sql, [ $lastdownload_full ]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("Failed get name tabel", $this->db); exit; } $rows = $qry->result_array(); $dataparam = json_encode(array( "table" => $table, "data" => $rows )); if (count($rows) > 0) { $z_param = gzcompress($dataparam, 9); $url = "https://" . $this->hostname . "/one-api-lab/tools/synctable/update"; $resp = $this->post($url, $z_param); $j_resp = json_decode($resp, true); sleep(2); if ($j_resp["status"] == "OK") { $this->db->trans_commit(); $this->reply([ "status" => "OK", "message" => 'Proses sync tabel ' . $table . ' berhasil', "total received" => $j_resp['total_received'], "total success" => $j_resp['total_success'] ]); } else { $this->db->trans_rollback(); $this->reply([ "status" => "ERR", 'message' => "Gagal sync pada tabel " . $table, 'debug' => print_r($resp, true) ]); } } else { $this->db->trans_rollback(); $this->reply([ "status" => "OK", 'message' => "Tidak Ada Data Pada Tabel " . $table ]); } } public function getdata_m_instrumentmethode($table, $lastdownload) { $this->db->trans_begin(); $lastdownload_full = $lastdownload . " 00:00:00"; $sql = "SELECT * FROM $table WHERE M_InstrumentMethodeLastUpdated > ?"; $qry = $this->db->query($sql, [ $lastdownload_full ]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("Failed get name tabel", $this->db); exit; } $rows = $qry->result_array(); $dataparam = json_encode(array( "table" => $table, "data" => $rows )); if (count($rows) > 0) { $z_param = gzcompress($dataparam, 9); $url = "https://" . $this->hostname . "/one-api-lab/tools/synctable/update"; $resp = $this->post($url, $z_param); $j_resp = json_decode($resp, true); sleep(2); if ($j_resp["status"] == "OK") { $this->db->trans_commit(); $this->reply([ "status" => "OK", "message" => 'Proses sync tabel ' . $table . ' berhasil', "total received" => $j_resp['total_received'], "total success" => $j_resp['total_success'] ]); } else { $this->db->trans_rollback(); $this->reply([ "status" => "ERR", 'message' => "Gagal sync pada tabel " . $table, 'debug' => print_r($resp, true) ]); } } else { $this->db->trans_rollback(); $this->reply([ "status" => "OK", 'message' => "Tidak Ada Data Pada Tabel " . $table ]); } } public function getdata_nat_unit($table, $lastdownload) { $this->db->trans_begin(); $lastdownload_full = $lastdownload . " 00:00:00"; $sql = "SELECT * FROM $table WHERE Nat_UnitLastUpdated > ?"; $qry = $this->db->query($sql, [ $lastdownload_full ]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("Failed get name tabel", $this->db); exit; } $rows = $qry->result_array(); $dataparam = json_encode(array( "table" => $table, "data" => $rows )); if (count($rows) > 0) { $z_param = gzcompress($dataparam, 9); $url = "https://" . $this->hostname . "/one-api-lab/tools/synctable/update"; $resp = $this->post($url, $z_param); $j_resp = json_decode($resp, true); sleep(2); if ($j_resp["status"] == "OK") { $this->db->trans_commit(); $this->reply([ "status" => "OK", "message" => 'Proses sync tabel ' . $table . ' berhasil', "total received" => $j_resp['total_received'], "total success" => $j_resp['total_success'] ]); } else { $this->db->trans_rollback(); $this->reply([ "status" => "ERR", 'message' => "Gagal sync pada tabel " . $table, 'debug' => print_r($resp, true) ]); } } else { $this->db->trans_rollback(); $this->reply([ "status" => "OK", 'message' => "Tidak Ada Data Pada Tabel " . $table ]); } } public function get_update($lastdownload) { $this->getdata_nat_test('nat_test', $lastdownload); echo "\n"; $this->getdata_t_test('t_test', $lastdownload); echo "\n"; $this->getdata_nat_normalvalue('nat_normalvalue', $lastdownload); echo "\n"; $this->getdata_nat_subgroup('nat_subgroup', $lastdownload); echo "\n"; $this->getdata_t_sampletype('t_sampletype', $lastdownload); echo "\n"; $this->getdata_t_bahan('t_bahan', $lastdownload); echo "\n"; $this->getdata_nat_methode('nat_methode', $lastdownload); echo "\n"; $this->getdata_nat_instrument('nat_instrument', $lastdownload); echo "\n"; $this->getdata_m_instrumentmethode('m_instrumentmethode', $lastdownload); echo "\n"; $this->getdata_nat_unit('nat_unit', $lastdownload); } public function getdata_bkp($table, $colupdated, $lastdownload) { $sql = "SELECT * FROM $table WHERE $colupdated > ?"; $qry = $this->db->query($sql, [ $lastdownload ]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("Failed get name tabel", $this->db); exit; } $rows = $qry->result_array(); $result = array( "total" => count($rows), "record" => $rows ); $this->sys_ok($result); } }