[KDR BISONE] - Update Upload File Lampiran #16

Open
opened 2023-09-01 16:26:41 +07:00 by sindhu · 0 comments
Owner

Pada update ini terdapat tambahan function sbb :

- upload file

public function upload_file_lampiran_by_order_id()
	{
		if (!$this->isLogin) {
			$this->sys_error("Invalid Token");
			exit;
		}

		$userid = $this->sys_user["M_UserID"];
		$inp = $this->sys_input;
		// $order_id = $inp['orderid'];
		$order_id = $inp['trx_id'];
		$resultentry = $inp['resultentry'];
		$data = [];

		if ($order_id == "0" || $order_id == 0 || $order_id == "-1" || $order_id < 1) {
			echo json_encode([
				"status" => "ERR",
				"message" => "Tidak Ada Pemeriksaan",
			]);
			exit;
		}

		// $status = "";

		// Valid file extensions
		$valid_extensions = array("jpg", "jpeg", "png", "pdf");

		// echo $orderid;

		$date = date('Y');
		$target_dir_one_media = "/home/one/project/one/one-media/";
		$target_dir_one_attachment = "/home/one/project/one/one-media/one-attachment/";
		$target_dir = "/home/one/project/one/one-media/one-attachment/lampiran-result-entry-$date/";

		// check folder sudah ada apa belum
		// if(!is_dir($target_dir_one_media)){
		// mkdir($target_dir_one_media, 0777, true);
		if (!is_dir($target_dir_one_attachment)) {
			mkdir($target_dir_one_attachment, 0777, true);
			if (!is_dir($target_dir)) {
				// echo json_encode([
				// 	"status" => "ERR",
				// 	"message" => "ERR : Folder Upload Di Server Belum Ada",
				// ]);
				// exit;
				mkdir($target_dir, 0777, true);
			}
		}
		// }

		$config['upload_path'] = $target_dir;
		// if(!is_dir($config['upload_path'])) mkdir($target_dir, 0777, TRUE);
		$config['allowed_types'] = 'jpg|jpeg|png|pdf';
		$config['max_size'] = '10000';
		$this->load->library('upload', $config);

		// yang diupload hanya lab
		if (!empty($_FILES['fileNonLab']['name'])) {
			// $status = "lab";
			$resx = $this->proses_upload_non_lab(
				$_FILES,
				$config,
				$valid_extensions,
				$order_id,
				$date,
				$userid,
				$target_dir,
				$resultentry
			);
			if ($resx['status'] == "OK") {
				$data['totalFiles'] = $resx['data'];
				$result = array(
					"total" => count($data['totalFiles']),
					"records" =>  $data['totalFiles'],
				);
				$this->sys_ok($result);
			} else {
				echo json_encode([
					"status" => "ERR",
					"message" => $resx['message'],
					"error" => $resx['error'],
					"path" => $resx['path']
				]);
			}
		}


		// jika di upload lab dan non lab
		// if (!empty($_FILES['fileNonLab']['name'])) {
		// 	// $status = "nonlab";
		// 	$resx = $this->proses_upload_non_lab(
		// 		$_FILES,
		// 		$config,
		// 		$valid_extensions,
		// 		$order_id,
		// 		$date,
		// 		$userid,
		// 		$target_dir
		// 	);

		// 	// echo $resx['status'];

		// 	if ($resx['status'] == "OK") {
		// 		// $data['totalFiles'] = $resx[0]['data'];
		// 		// $result = array(
		// 		// 	"total" => count($data['totalFiles']),
		// 		// 	"records" =>  $data['totalFiles'],
		// 		// );
		// 		// $this->sys_ok($result);

		// 		if (empty($_FILES['fileLab']['name'])) {
		// 			$data['totalFiles'] = $resx['data'];
		// 			$result = array(
		// 				"total" => count($data['totalFiles']),
		// 				"records" =>  $data['totalFiles'],
		// 			);
		// 			$this->sys_ok($result);
		// 		} else {
		// 			// check lab dan upload
		// 			if (!empty($_FILES['fileLab']['name'])) {
		// 				$resx_lab = $this->proses_upload_lab(
		// 					$_FILES,
		// 					$config,
		// 					$valid_extensions,
		// 					$order_id,
		// 					$date,
		// 					$userid,
		// 					$target_dir
		// 				);
		// 				if ($resx_lab['status'] == "OK") {
		// 					$data['totalFiles'] = $resx_lab['data'];
		// 					$result = array(
		// 						"total" => count($data['totalFiles']),
		// 						"records" =>  $data['totalFiles'],
		// 					);
		// 					$this->sys_ok($result);
		// 				} else {
		// 					echo json_encode([
		// 						"status" => "ERR",
		// 						"message" => $resx_lab['message'],
		// 						"error" => $resx_lab['error'],
		// 						"path" => $resx_lab['path']
		// 					]);
		// 				}
		// 			}
		// 		}
		// 	} else {
		// 		echo json_encode([
		// 			"status" => "ERR",
		// 			"message" => $resx['message'],
		// 			"error" => $resx['error'],
		// 			"path" => $resx['path']
		// 		]);
		// 	}
		// } else {
		// 	if (!empty($_FILES['fileLab']['name'])) {
		// 		// $status = "lab";
		// 		$resx_lab = $this->proses_upload_lab(
		// 			$_FILES,
		// 			$config,
		// 			$valid_extensions,
		// 			$order_id,
		// 			$date,
		// 			$userid,
		// 			$target_dir
		// 		);
		// 		if ($resx_lab['status'] == "OK") {
		// 			// $data['totalFiles'] = $resx_lab['data'];
		// 			// $result = array(
		// 			// 	"total" => count($data['totalFiles']),
		// 			// 	"records" =>  $data['totalFiles'],
		// 			// );
		// 			// $this->sys_ok($result);

		// 			if (empty($_FILES['fileNonLab']['name'])) {
		// 				$data['totalFiles'] = $resx_lab['data'];
		// 				$result = array(
		// 					"total" => count($data['totalFiles']),
		// 					"records" =>  $data['totalFiles'],
		// 				);
		// 				$this->sys_ok($result);
		// 			} else {
		// 				// check non lab dan upload
		// 				if (!empty($_FILES['fileNonLab']['name'])) {
		// 					$resx = $this->proses_upload_non_lab(
		// 						$_FILES,
		// 						$config,
		// 						$valid_extensions,
		// 						$order_id,
		// 						$date,
		// 						$userid,
		// 						$target_dir
		// 					);

		// 					if ($resx['status'] == "OK") {
		// 						$data['totalFiles'] = $resx['data'];
		// 						$result = array(
		// 							"total" => count($data['totalFiles']),
		// 							"records" =>  $data['totalFiles'],
		// 						);
		// 						$this->sys_ok($result);
		// 					} else {
		// 						echo json_encode([
		// 							"status" => "ERR",
		// 							"message" => $resx['message'],
		// 							"error" => $resx['error'],
		// 							"path" => $resx['path']
		// 						]);
		// 					}
		// 				}
		// 			}
		// 		} else {
		// 			echo json_encode([
		// 				"status" => "ERR",
		// 				"message" => $resx_lab['message'],
		// 				"error" => $resx_lab['error'],
		// 				"path" => $resx_lab['path']
		// 			]);
		// 		}
		// 	}
		// }
	}

- proses upload non lab

public function proses_upload_non_lab(
		$filex,
		$config,
		$valid_extensions,
		$order_id,
		$date,
		$userid,
		$target_dir,
		$resultentry
	) {
		$_FILES = $filex;
		$data = [];

		$dir_file = "/home/one/project/one/";
		$sql_get_file = "select T_OrderAttachmentUrl 
		from t_order_attachment
		WHERE T_OrderAttachmentIsActive = 'Y'
		AND T_OrderAttachmentT_OrderHeaderID = {$order_id} 
		";

		$qry_get_file = $this->db_onedev->query($sql_get_file);
		if (!$qry_get_file) {
			$this->db_onedev->trans_rollback();
			$this->sys_error_db("select t_order_attachment lab for get file failed");
			exit;
		}

		$rows_get_file = $qry_get_file->result_array();
		$location_file = "";
		if (count($rows_get_file) > 0) {
			$location_file = $dir_file . $rows_get_file[0]['T_OrderAttachmentUrl'];
			if (file_exists($location_file)) {
				// remove file in server, if exists
				if (unlink($location_file)) {
					// update old data
					$sql_update_old = "UPDATE t_order_attachment SET 
						T_OrderAttachmentIsActive = 'N',
						T_OrderAttachmentUserID = {$userid}
					WHERE
						T_OrderAttachmentT_OrderHeaderID = {$order_id} 
						AND T_OrderAttachmentIsActive = 'Y'
						AND T_OrderAttachmentType = 'NonLab'";

					$qry_update_old = $this->db_onedev->query($sql_update_old);
					if (!$qry_update_old) {
						$this->db_onedev->trans_rollback();
						$this->sys_error_db("update t_order_attachment lab failed");
						exit;
					}
				}
			}
		}

		// update old data
		$sql_update_old = "UPDATE t_order_attachment SET 
			T_OrderAttachmentIsActive = 'N',
			T_OrderAttachmentUserID = {$userid}
		WHERE
			T_OrderAttachmentT_OrderHeaderID = {$order_id} 
			AND T_OrderAttachmentIsActive = 'Y'
			AND T_OrderAttachmentType = 'NonLab'";

		$qry_update_old = $this->db_onedev->query($sql_update_old);
		if (!$qry_update_old) {
			$this->db_onedev->trans_rollback();
			$this->sys_error_db("update t_order_attachment non lab failed");
			exit;
		}

		if (!empty($_FILES['fileNonLab']['name'])) {
			$filenameNonLab = $_FILES['fileNonLab']['name'];
			$extension_NonLab = pathinfo($filenameNonLab, PATHINFO_EXTENSION);
			if (!in_array(strtolower($extension_NonLab), $valid_extensions)) {
				echo json_encode([
					"status" => "ERR",
					"message" => "Ekstensi file yang diperbolehkan .jpg, .png, jpeg, .pdf"
				]);
			}

			// $filenameNonLab = $order_id . '-' . 'NonLab' . '-' . date('Y') . '-' . $this->generateRandomString(5);
			$filenameNonLab = $order_id . '-' . $resultentry . '-' . date('Y') . $this->generateRandomString(5);

			$_FILES['file']['name'] = $filenameNonLab;
			$_FILES['file']['type'] = $_FILES['fileNonLab']['type'][0];
			$_FILES['file']['tmp_name'] = $_FILES['fileNonLab']['tmp_name'][0];
			$_FILES['file']['error'] = $_FILES['fileNonLab']['error'][0];
			$_FILES['file']['size'] = $_FILES['fileNonLab']['size'][0];

			$config['file_name'] =  $filenameNonLab;
			$this->upload->initialize($config);

			if ($this->upload->do_upload('fileNonLab')) {
				$uploadData = $this->upload->data();
				$filename = $uploadData['file_name'];
				$url_nonlab = "/one-media/one-attachment/lampiran-result-entry-$date/" . $filename;

				// insert non lab
				$sql = "INSERT INTO t_order_attachment (
					T_OrderAttachmentT_OrderHeaderID,
                    T_OrderAttachmentName,
                    T_OrderAttachmentUrl,
                    T_OrderAttachmentType,
                    T_OrderAttachmentCreated,
                    T_OrderAttachmentUserID
                )
                VALUES(
                    {$order_id},
					'{$filename}',
					'{$url_nonlab}',
                    'NonLab',
                    NOW(),
                    {$userid}
                )";

				$qry_insert = $this->db_onedev->query($sql);
				if (!$qry_insert) {
					$this->db_onedev->trans_rollback();
					$this->sys_error_db("insert t_order_attachment nonlab failed : " . $this->db_onedev->last_query());
					exit;
				}

				$xlast_id = $this->db_onedev->insert_id();
				$data['totalFiles'][] = array(
					'xid' => $xlast_id,
					'type' => "NonLab",
					'image_url' => "/one-media/one-attachment/lampiran-result-entry-$date/" . $filename,
				);

				return [
					"status" => "OK",
					"data" => $data
				];

				// echo json_encode([
				// 	"status" => "ERR",
				// 	"message" => $sql,
				// ]);
				// exit;
			} else {
				$error = array('error' => $this->upload->display_errors());
				// echo json_encode([
				// 	"status" => "ERR",
				// 	"message" => "Gagal Upload File Non Lab : $error",
				// 	"error" => $error,
				// 	"path" => $target_dir
				// ]);
				// exit;

				$e = $error['error'];

				return ([
					"status" => "ERR",
					"message" => "Gagal Upload File Non Lab : $e",
					"error" => $error,
					"path" => $target_dir
				]);
			}
		}
	}

- proses upload lab

	public function proses_upload_lab(
		$filex,
		$config,
		$valid_extensions,
		$order_id,
		$date,
		$userid,
		$target_dir,
		$resultentry
	) {
		$_FILES = $filex;
		$data = [];

		$dir_file = "/home/one/project/one/";

		$sql_get_file = "select T_OrderAttachmentUrl 
		from t_order_attachment
		WHERE T_OrderAttachmentIsActive = 'Y'
		AND T_OrderAttachmentT_OrderHeaderID = {$order_id} 
		";

		$qry_get_file = $this->db_onedev->query($sql_get_file);
		if (!$qry_get_file) {
			$this->db_onedev->trans_rollback();
			$this->sys_error_db("select t_order_attachment lab for get file failed");
			exit;
		}

		$rows_get_file = $qry_get_file->result_array();
		$location_file = "";
		if (count($rows_get_file) > 0) {
			$location_file = $dir_file . $rows_get_file[0]['T_OrderAttachmentUrl'];
			if (file_exists($location_file)) {
				// remove file in server, if exists
				if (unlink($location_file)) {
					// update old data
					$sql_update_old = "UPDATE t_order_attachment SET 
						T_OrderAttachmentIsActive = 'N',
						T_OrderAttachmentUserID = {$userid}
					WHERE
						T_OrderAttachmentT_OrderHeaderID = {$order_id} 
						AND T_OrderAttachmentIsActive = 'Y'
						AND T_OrderAttachmentType = 'Lab'";

					$qry_update_old = $this->db_onedev->query($sql_update_old);
					if (!$qry_update_old) {
						$this->db_onedev->trans_rollback();
						$this->sys_error_db("update t_order_attachment lab failed");
						exit;
					}
				}
			}
		}

		// update old data
		$sql_update_old = "UPDATE t_order_attachment SET 
			T_OrderAttachmentIsActive = 'N',
			T_OrderAttachmentUserID = {$userid}
		WHERE
			T_OrderAttachmentT_OrderHeaderID = {$order_id} 
			AND T_OrderAttachmentIsActive = 'Y'
			AND T_OrderAttachmentType = 'Lab'";

		$qry_update_old = $this->db_onedev->query($sql_update_old);
		if (!$qry_update_old) {
			$this->db_onedev->trans_rollback();
			$this->sys_error_db("update t_order_attachment lab failed");
			exit;
		}

		if (!empty($_FILES['fileLab']['name'])) {
			$filenameLab = $_FILES['fileLab']['name'];
			$extension_Lab = pathinfo($filenameLab, PATHINFO_EXTENSION);
			if (!in_array(strtolower($extension_Lab), $valid_extensions)) {
				echo json_encode([
					"status" => "ERR",
					"message" => "Ekstensi file yang diperbolehkan .jpg, .png, jpeg, .pdf"
				]);
			}

			$filenameLab = $order_id . '-' . 'Lab' . '-' . date('Y') . '-' . $this->generateRandomString(5);
			$_FILES['file']['name'] = $filenameLab;
			$_FILES['file']['type'] = $_FILES['fileLab']['type'][0];
			$_FILES['file']['tmp_name'] = $_FILES['fileLab']['tmp_name'][0];
			$_FILES['file']['error'] = $_FILES['fileLab']['error'][0];
			$_FILES['file']['size'] = $_FILES['fileLab']['size'][0];

			$config['file_name'] =  $filenameLab;
			$this->upload->initialize($config);

			if ($this->upload->do_upload('fileLab')) {
				$uploadData = $this->upload->data();
				$filename = $uploadData['file_name'];
				$url_Lab = "/one-media/one-attachment/lampiran-result-entry-$date/" . $filename;

				// insert non lab
				$sql = "INSERT INTO t_order_attachment (
					T_OrderAttachmentT_OrderHeaderID,
					T_OrderAttachmentName,
					T_OrderAttachmentUrl,
					T_OrderAttachmentType,
					T_OrderAttachmentCreated,
					T_OrderAttachmentUserID
				)
				VALUES(
					{$order_id},
					'{$filename}',
					'{$url_Lab}',
					'Lab',
					NOW(),
					{$userid}
				)";

				$qry_insert = $this->db_onedev->query($sql);
				if (!$qry_insert) {
					$this->db_onedev->trans_rollback();
					$this->sys_error_db("insert t_order_attachment Lab failed : " . $this->db_onedev->last_query());
					exit;
				}

				$xlast_id = $this->db_onedev->insert_id();
				$data['totalFiles'][] = array(
					'xid' => $xlast_id,
					'type' => "Lab",
					'image_url' => "/one-media/one-attachment/lampiran-result-entry-$date/" . $filename,
				);

				return [
					"status" => "OK",
					"data" => $data
				];

				// echo json_encode([
				// 	"status" => "ERR",
				// 	"message" => $sql,
				// ]);
				// exit;
			} else {
				$error = array('error' => $this->upload->display_errors());
				// echo json_encode([
				// 	"status" => "ERR",
				// 	"message" => "Gagal Upload File Lab : $error",
				// 	"error" => $error,
				// 	"path" => $target_dir
				// ]);
				// exit;

				$e = $error['error'];
				return ([
					"status" => "ERR",
					"message" => "Gagal Upload File Lab : $e",
					"error" => $error,
					"path" => $target_dir
				]);
			}
		}
	}

lokasi update code di devkedungdoro

API
elektromedis
/home/one/project/one/one-api/application/controllers/mockup/resultentrysoelectromedis-v6

radiodiagnostik
/home/one/project/one/one-api/application/controllers/mockup/resultentrysoxray-v6

resut entry
/home/one/project/one/one-api/application/controllers/mockup/process/resultentry-v105

result validation
/home/one/project/one/one-api/application/controllers/mockup/process/resultvalidation-v105

result verification
/home/one/project/one/one-api/application/controllers/mockup/process/resultverification-v104

UI
result verif 104
/home/one/project/one/one-ui/test/vuex/one-process-resultverification-v104

result validation
/home/one/project/one/one-ui/test/vuex/one-process-resultvalidation-v105

result entry
/home/one/project/one/one-ui/test/vuex/one-process-resultentry-v105

radiodiagnostik
/home/one/project/one/one-ui/test/vuex/one-resultentry-so-xray-v6

elektromedis
/home/one/project/one/one-ui/test/vuex/one-resultentry-so-electromedis-v5

URL
elektromedis (nonlab)
http://devkedungdoro.aplikasi.web.id/one-ui/test/vuex/one-resultentry-so-electromedis-v5/

radiodiagnostik (nonlab)
http://devkedungdoro.aplikasi.web.id/one-ui/test/vuex/one-resultentry-so-xray-v6/

result valid
http://devkedungdoro.aplikasi.web.id/one-ui/test/vuex/one-process-resultvalidation-v105/

result entry (lab)
http://devkedungdoro.aplikasi.web.id/one-ui/test/vuex/one-process-resultentry-v105/

result verif
http://devkedungdoro.aplikasi.web.id/one-ui/test/vuex/one-process-resultverification-v104/

Update di database

  • tabel t_order_attachment
Pada update ini terdapat tambahan function sbb : **- upload file** ``` public function upload_file_lampiran_by_order_id() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; $inp = $this->sys_input; // $order_id = $inp['orderid']; $order_id = $inp['trx_id']; $resultentry = $inp['resultentry']; $data = []; if ($order_id == "0" || $order_id == 0 || $order_id == "-1" || $order_id < 1) { echo json_encode([ "status" => "ERR", "message" => "Tidak Ada Pemeriksaan", ]); exit; } // $status = ""; // Valid file extensions $valid_extensions = array("jpg", "jpeg", "png", "pdf"); // echo $orderid; $date = date('Y'); $target_dir_one_media = "/home/one/project/one/one-media/"; $target_dir_one_attachment = "/home/one/project/one/one-media/one-attachment/"; $target_dir = "/home/one/project/one/one-media/one-attachment/lampiran-result-entry-$date/"; // check folder sudah ada apa belum // if(!is_dir($target_dir_one_media)){ // mkdir($target_dir_one_media, 0777, true); if (!is_dir($target_dir_one_attachment)) { mkdir($target_dir_one_attachment, 0777, true); if (!is_dir($target_dir)) { // echo json_encode([ // "status" => "ERR", // "message" => "ERR : Folder Upload Di Server Belum Ada", // ]); // exit; mkdir($target_dir, 0777, true); } } // } $config['upload_path'] = $target_dir; // if(!is_dir($config['upload_path'])) mkdir($target_dir, 0777, TRUE); $config['allowed_types'] = 'jpg|jpeg|png|pdf'; $config['max_size'] = '10000'; $this->load->library('upload', $config); // yang diupload hanya lab if (!empty($_FILES['fileNonLab']['name'])) { // $status = "lab"; $resx = $this->proses_upload_non_lab( $_FILES, $config, $valid_extensions, $order_id, $date, $userid, $target_dir, $resultentry ); if ($resx['status'] == "OK") { $data['totalFiles'] = $resx['data']; $result = array( "total" => count($data['totalFiles']), "records" => $data['totalFiles'], ); $this->sys_ok($result); } else { echo json_encode([ "status" => "ERR", "message" => $resx['message'], "error" => $resx['error'], "path" => $resx['path'] ]); } } // jika di upload lab dan non lab // if (!empty($_FILES['fileNonLab']['name'])) { // // $status = "nonlab"; // $resx = $this->proses_upload_non_lab( // $_FILES, // $config, // $valid_extensions, // $order_id, // $date, // $userid, // $target_dir // ); // // echo $resx['status']; // if ($resx['status'] == "OK") { // // $data['totalFiles'] = $resx[0]['data']; // // $result = array( // // "total" => count($data['totalFiles']), // // "records" => $data['totalFiles'], // // ); // // $this->sys_ok($result); // if (empty($_FILES['fileLab']['name'])) { // $data['totalFiles'] = $resx['data']; // $result = array( // "total" => count($data['totalFiles']), // "records" => $data['totalFiles'], // ); // $this->sys_ok($result); // } else { // // check lab dan upload // if (!empty($_FILES['fileLab']['name'])) { // $resx_lab = $this->proses_upload_lab( // $_FILES, // $config, // $valid_extensions, // $order_id, // $date, // $userid, // $target_dir // ); // if ($resx_lab['status'] == "OK") { // $data['totalFiles'] = $resx_lab['data']; // $result = array( // "total" => count($data['totalFiles']), // "records" => $data['totalFiles'], // ); // $this->sys_ok($result); // } else { // echo json_encode([ // "status" => "ERR", // "message" => $resx_lab['message'], // "error" => $resx_lab['error'], // "path" => $resx_lab['path'] // ]); // } // } // } // } else { // echo json_encode([ // "status" => "ERR", // "message" => $resx['message'], // "error" => $resx['error'], // "path" => $resx['path'] // ]); // } // } else { // if (!empty($_FILES['fileLab']['name'])) { // // $status = "lab"; // $resx_lab = $this->proses_upload_lab( // $_FILES, // $config, // $valid_extensions, // $order_id, // $date, // $userid, // $target_dir // ); // if ($resx_lab['status'] == "OK") { // // $data['totalFiles'] = $resx_lab['data']; // // $result = array( // // "total" => count($data['totalFiles']), // // "records" => $data['totalFiles'], // // ); // // $this->sys_ok($result); // if (empty($_FILES['fileNonLab']['name'])) { // $data['totalFiles'] = $resx_lab['data']; // $result = array( // "total" => count($data['totalFiles']), // "records" => $data['totalFiles'], // ); // $this->sys_ok($result); // } else { // // check non lab dan upload // if (!empty($_FILES['fileNonLab']['name'])) { // $resx = $this->proses_upload_non_lab( // $_FILES, // $config, // $valid_extensions, // $order_id, // $date, // $userid, // $target_dir // ); // if ($resx['status'] == "OK") { // $data['totalFiles'] = $resx['data']; // $result = array( // "total" => count($data['totalFiles']), // "records" => $data['totalFiles'], // ); // $this->sys_ok($result); // } else { // echo json_encode([ // "status" => "ERR", // "message" => $resx['message'], // "error" => $resx['error'], // "path" => $resx['path'] // ]); // } // } // } // } else { // echo json_encode([ // "status" => "ERR", // "message" => $resx_lab['message'], // "error" => $resx_lab['error'], // "path" => $resx_lab['path'] // ]); // } // } // } } ``` **- proses upload non lab** ``` public function proses_upload_non_lab( $filex, $config, $valid_extensions, $order_id, $date, $userid, $target_dir, $resultentry ) { $_FILES = $filex; $data = []; $dir_file = "/home/one/project/one/"; $sql_get_file = "select T_OrderAttachmentUrl from t_order_attachment WHERE T_OrderAttachmentIsActive = 'Y' AND T_OrderAttachmentT_OrderHeaderID = {$order_id} "; $qry_get_file = $this->db_onedev->query($sql_get_file); if (!$qry_get_file) { $this->db_onedev->trans_rollback(); $this->sys_error_db("select t_order_attachment lab for get file failed"); exit; } $rows_get_file = $qry_get_file->result_array(); $location_file = ""; if (count($rows_get_file) > 0) { $location_file = $dir_file . $rows_get_file[0]['T_OrderAttachmentUrl']; if (file_exists($location_file)) { // remove file in server, if exists if (unlink($location_file)) { // update old data $sql_update_old = "UPDATE t_order_attachment SET T_OrderAttachmentIsActive = 'N', T_OrderAttachmentUserID = {$userid} WHERE T_OrderAttachmentT_OrderHeaderID = {$order_id} AND T_OrderAttachmentIsActive = 'Y' AND T_OrderAttachmentType = 'NonLab'"; $qry_update_old = $this->db_onedev->query($sql_update_old); if (!$qry_update_old) { $this->db_onedev->trans_rollback(); $this->sys_error_db("update t_order_attachment lab failed"); exit; } } } } // update old data $sql_update_old = "UPDATE t_order_attachment SET T_OrderAttachmentIsActive = 'N', T_OrderAttachmentUserID = {$userid} WHERE T_OrderAttachmentT_OrderHeaderID = {$order_id} AND T_OrderAttachmentIsActive = 'Y' AND T_OrderAttachmentType = 'NonLab'"; $qry_update_old = $this->db_onedev->query($sql_update_old); if (!$qry_update_old) { $this->db_onedev->trans_rollback(); $this->sys_error_db("update t_order_attachment non lab failed"); exit; } if (!empty($_FILES['fileNonLab']['name'])) { $filenameNonLab = $_FILES['fileNonLab']['name']; $extension_NonLab = pathinfo($filenameNonLab, PATHINFO_EXTENSION); if (!in_array(strtolower($extension_NonLab), $valid_extensions)) { echo json_encode([ "status" => "ERR", "message" => "Ekstensi file yang diperbolehkan .jpg, .png, jpeg, .pdf" ]); } // $filenameNonLab = $order_id . '-' . 'NonLab' . '-' . date('Y') . '-' . $this->generateRandomString(5); $filenameNonLab = $order_id . '-' . $resultentry . '-' . date('Y') . $this->generateRandomString(5); $_FILES['file']['name'] = $filenameNonLab; $_FILES['file']['type'] = $_FILES['fileNonLab']['type'][0]; $_FILES['file']['tmp_name'] = $_FILES['fileNonLab']['tmp_name'][0]; $_FILES['file']['error'] = $_FILES['fileNonLab']['error'][0]; $_FILES['file']['size'] = $_FILES['fileNonLab']['size'][0]; $config['file_name'] = $filenameNonLab; $this->upload->initialize($config); if ($this->upload->do_upload('fileNonLab')) { $uploadData = $this->upload->data(); $filename = $uploadData['file_name']; $url_nonlab = "/one-media/one-attachment/lampiran-result-entry-$date/" . $filename; // insert non lab $sql = "INSERT INTO t_order_attachment ( T_OrderAttachmentT_OrderHeaderID, T_OrderAttachmentName, T_OrderAttachmentUrl, T_OrderAttachmentType, T_OrderAttachmentCreated, T_OrderAttachmentUserID ) VALUES( {$order_id}, '{$filename}', '{$url_nonlab}', 'NonLab', NOW(), {$userid} )"; $qry_insert = $this->db_onedev->query($sql); if (!$qry_insert) { $this->db_onedev->trans_rollback(); $this->sys_error_db("insert t_order_attachment nonlab failed : " . $this->db_onedev->last_query()); exit; } $xlast_id = $this->db_onedev->insert_id(); $data['totalFiles'][] = array( 'xid' => $xlast_id, 'type' => "NonLab", 'image_url' => "/one-media/one-attachment/lampiran-result-entry-$date/" . $filename, ); return [ "status" => "OK", "data" => $data ]; // echo json_encode([ // "status" => "ERR", // "message" => $sql, // ]); // exit; } else { $error = array('error' => $this->upload->display_errors()); // echo json_encode([ // "status" => "ERR", // "message" => "Gagal Upload File Non Lab : $error", // "error" => $error, // "path" => $target_dir // ]); // exit; $e = $error['error']; return ([ "status" => "ERR", "message" => "Gagal Upload File Non Lab : $e", "error" => $error, "path" => $target_dir ]); } } } ``` **- proses upload lab** ``` public function proses_upload_lab( $filex, $config, $valid_extensions, $order_id, $date, $userid, $target_dir, $resultentry ) { $_FILES = $filex; $data = []; $dir_file = "/home/one/project/one/"; $sql_get_file = "select T_OrderAttachmentUrl from t_order_attachment WHERE T_OrderAttachmentIsActive = 'Y' AND T_OrderAttachmentT_OrderHeaderID = {$order_id} "; $qry_get_file = $this->db_onedev->query($sql_get_file); if (!$qry_get_file) { $this->db_onedev->trans_rollback(); $this->sys_error_db("select t_order_attachment lab for get file failed"); exit; } $rows_get_file = $qry_get_file->result_array(); $location_file = ""; if (count($rows_get_file) > 0) { $location_file = $dir_file . $rows_get_file[0]['T_OrderAttachmentUrl']; if (file_exists($location_file)) { // remove file in server, if exists if (unlink($location_file)) { // update old data $sql_update_old = "UPDATE t_order_attachment SET T_OrderAttachmentIsActive = 'N', T_OrderAttachmentUserID = {$userid} WHERE T_OrderAttachmentT_OrderHeaderID = {$order_id} AND T_OrderAttachmentIsActive = 'Y' AND T_OrderAttachmentType = 'Lab'"; $qry_update_old = $this->db_onedev->query($sql_update_old); if (!$qry_update_old) { $this->db_onedev->trans_rollback(); $this->sys_error_db("update t_order_attachment lab failed"); exit; } } } } // update old data $sql_update_old = "UPDATE t_order_attachment SET T_OrderAttachmentIsActive = 'N', T_OrderAttachmentUserID = {$userid} WHERE T_OrderAttachmentT_OrderHeaderID = {$order_id} AND T_OrderAttachmentIsActive = 'Y' AND T_OrderAttachmentType = 'Lab'"; $qry_update_old = $this->db_onedev->query($sql_update_old); if (!$qry_update_old) { $this->db_onedev->trans_rollback(); $this->sys_error_db("update t_order_attachment lab failed"); exit; } if (!empty($_FILES['fileLab']['name'])) { $filenameLab = $_FILES['fileLab']['name']; $extension_Lab = pathinfo($filenameLab, PATHINFO_EXTENSION); if (!in_array(strtolower($extension_Lab), $valid_extensions)) { echo json_encode([ "status" => "ERR", "message" => "Ekstensi file yang diperbolehkan .jpg, .png, jpeg, .pdf" ]); } $filenameLab = $order_id . '-' . 'Lab' . '-' . date('Y') . '-' . $this->generateRandomString(5); $_FILES['file']['name'] = $filenameLab; $_FILES['file']['type'] = $_FILES['fileLab']['type'][0]; $_FILES['file']['tmp_name'] = $_FILES['fileLab']['tmp_name'][0]; $_FILES['file']['error'] = $_FILES['fileLab']['error'][0]; $_FILES['file']['size'] = $_FILES['fileLab']['size'][0]; $config['file_name'] = $filenameLab; $this->upload->initialize($config); if ($this->upload->do_upload('fileLab')) { $uploadData = $this->upload->data(); $filename = $uploadData['file_name']; $url_Lab = "/one-media/one-attachment/lampiran-result-entry-$date/" . $filename; // insert non lab $sql = "INSERT INTO t_order_attachment ( T_OrderAttachmentT_OrderHeaderID, T_OrderAttachmentName, T_OrderAttachmentUrl, T_OrderAttachmentType, T_OrderAttachmentCreated, T_OrderAttachmentUserID ) VALUES( {$order_id}, '{$filename}', '{$url_Lab}', 'Lab', NOW(), {$userid} )"; $qry_insert = $this->db_onedev->query($sql); if (!$qry_insert) { $this->db_onedev->trans_rollback(); $this->sys_error_db("insert t_order_attachment Lab failed : " . $this->db_onedev->last_query()); exit; } $xlast_id = $this->db_onedev->insert_id(); $data['totalFiles'][] = array( 'xid' => $xlast_id, 'type' => "Lab", 'image_url' => "/one-media/one-attachment/lampiran-result-entry-$date/" . $filename, ); return [ "status" => "OK", "data" => $data ]; // echo json_encode([ // "status" => "ERR", // "message" => $sql, // ]); // exit; } else { $error = array('error' => $this->upload->display_errors()); // echo json_encode([ // "status" => "ERR", // "message" => "Gagal Upload File Lab : $error", // "error" => $error, // "path" => $target_dir // ]); // exit; $e = $error['error']; return ([ "status" => "ERR", "message" => "Gagal Upload File Lab : $e", "error" => $error, "path" => $target_dir ]); } } } ``` lokasi update code di devkedungdoro **API** elektromedis /home/one/project/one/one-api/application/controllers/mockup/resultentrysoelectromedis-v6 radiodiagnostik /home/one/project/one/one-api/application/controllers/mockup/resultentrysoxray-v6 resut entry /home/one/project/one/one-api/application/controllers/mockup/process/resultentry-v105 result validation /home/one/project/one/one-api/application/controllers/mockup/process/resultvalidation-v105 result verification /home/one/project/one/one-api/application/controllers/mockup/process/resultverification-v104 **UI** result verif 104 /home/one/project/one/one-ui/test/vuex/one-process-resultverification-v104 result validation /home/one/project/one/one-ui/test/vuex/one-process-resultvalidation-v105 result entry /home/one/project/one/one-ui/test/vuex/one-process-resultentry-v105 radiodiagnostik /home/one/project/one/one-ui/test/vuex/one-resultentry-so-xray-v6 elektromedis /home/one/project/one/one-ui/test/vuex/one-resultentry-so-electromedis-v5 **URL** elektromedis (nonlab) http://devkedungdoro.aplikasi.web.id/one-ui/test/vuex/one-resultentry-so-electromedis-v5/ radiodiagnostik (nonlab) http://devkedungdoro.aplikasi.web.id/one-ui/test/vuex/one-resultentry-so-xray-v6/ result valid http://devkedungdoro.aplikasi.web.id/one-ui/test/vuex/one-process-resultvalidation-v105/ result entry (lab) http://devkedungdoro.aplikasi.web.id/one-ui/test/vuex/one-process-resultentry-v105/ result verif http://devkedungdoro.aplikasi.web.id/one-ui/test/vuex/one-process-resultverification-v104/ **Update di database** - tabel t_order_attachment
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sindhu/belajar#16