<?php

    if(isset($_GET['kode'])){
        $sql_cek = "SELECT p.nik, p.nama, p.tempat_lh, p.tgl_lh, p.jekel, p.desa, p.rt, p.rw, p.agama, p.kawin, p.pekerjaan,
        d.tgl_pindah, d.alasan, k.no_kk, k.kepala 
        FROM tb_pindah d 
        JOIN tb_pdd p ON d.id_pdd=p.id_pend 
        LEFT JOIN tb_anggota a ON p.id_pend=a.id_pend 
        LEFT JOIN tb_kk k ON a.id_kk=k.id_kk 
        WHERE d.id_pindah ='".$_GET['kode']."'";
        $query_cek = mysqli_query($koneksi, $sql_cek);
        
        if (!$query_cek) {
            die('Error Query: ' . mysqli_error($koneksi));
        }
        
        $data_cek = mysqli_fetch_array($query_cek,MYSQLI_BOTH);

        if (!$data_cek) {
            echo "Data tidak ditemukan! Kemungkinan data penduduk induk telah dihapus atau ID salah.";
            exit;
        }
    }
?>

<div class="card card-success">
	<div class="card-header">
		<h3 class="card-title">
			<i class="fa fa-user"></i> Detail Data Pindah</h3>
		<div class="card-tools">
		</div>
	</div>
	<div class="card-body p-0">
		<table class="table">
			<tbody>
                <tr>
                    <td colspan="2">
                        <h4><i class="fa fa-users"></i> Asal Keluarga (KK)</h4>
                    </td>
                </tr>
                <tr>
					<td style="width: 150px">
						<b>No KK</b>
					</td>
					<td>:
						<?php echo $data_cek['no_kk']; ?>
					</td>
				</tr>
                <tr>
					<td style="width: 150px">
						<b>Kepala Keluarga</b>
					</td>
					<td>:
						<?php echo $data_cek['kepala']; ?>
					</td>
				</tr>
                <tr>
                    <td colspan="2">
                        <h4><i class="fa fa-user"></i> Data Individu</h4>
                    </td>
                </tr>
				<tr>
					<td style="width: 150px">
						<b>NIK</b>
					</td>
					<td>:
						<?php echo $data_cek['nik']; ?>
					</td>
				</tr>
				<tr>
					<td style="width: 150px">
						<b>Nama</b>
					</td>
					<td>:
						<?php echo $data_cek['nama']; ?>
					</td>
				</tr>
				<tr>
					<td style="width: 150px">
						<b>TTL</b>
					</td>
					<td>:
						<?php echo $data_cek['tempat_lh']; ?>
						/
						<?php echo $data_cek['tgl_lh']; ?>
					</td>
				</tr>
				<tr>
					<td style="width: 150px">
						<b>Jenis Kelamin</b>
					</td>
					<td>:
						<?php echo $data_cek['jekel']; ?>
					</td>
				</tr>
				<tr>
					<td style="width: 150px">
						<b>Alamat</b>
					</td>
					<td>:
						<?php echo $data_cek['desa']; ?>, RT
						<?php echo $data_cek['rt']; ?>/ RW
						<?php echo $data_cek['rw']; ?>
					</td>
				</tr>
                <tr>
                    <td colspan="2">
                        <h4><i class="fa fa-truck"></i> Data Kepindahan</h4>
                    </td>
                </tr>
                <tr>
					<td style="width: 150px">
						<b>Tanggal Pindah</b>
					</td>
					<td>:
						<?php echo $data_cek['tgl_pindah']; ?>
					</td>
				</tr>
                <tr>
					<td style="width: 150px">
						<b>Alasan</b>
					</td>
					<td>:
						<?php echo $data_cek['alasan']; ?>
					</td>
				</tr>
			</tbody>
		</table>
		<div class="card-footer">
			<a href="?page=data-pindah" class="btn btn-warning">Kembali</a>
		</div>
	</div>
</div>
