Beispiel #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Keluarga::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $dataProvider->query->joinWith(['kepalaKeluarga' => function ($q) {
         $q->from('base');
     }]);
     // grid filtering conditions
     $query->andFilterWhere(['tanggal_terbit' => $this->tanggal_terbit, 'tanggal_pembaruan' => $this->tanggal_pembaruan, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'id', $this->id]);
     $query->andFilterWhere(['like', 'tanggal_terbit', $this->tanggal_terbit]);
     $query->andFilterWhere(['like', 'base.nama', $this->kepala_keluarga]);
     $query->andFilterWhere(['like', 'status', $this->status]);
     return $dataProvider;
 }
Beispiel #2
0
 public function actionNoKkList($q = null, $id = null)
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $out = ['results' => ['id' => '', 'text' => '']];
     if (!is_null($q)) {
         $query = new \yii\db\Query();
         $query->select('id, id AS text')->from('keluarga')->where(['like', 'id', $q])->limit(20);
         $command = $query->createCommand();
         $data = $command->queryAll();
         $out['results'] = array_values($data);
     } elseif ($id > 0) {
         $out['results'] = ['id' => $id, 'text' => Keluarga::find($id)->id];
     }
     return $out;
 }
    private function exportKeluarga()
    {
        $isi = Keluarga::find()->asArray()->all();
        $filename = 'Data_Keluarga-' . date('YmdGis') . '.xls';
        header("Content-type: application/vnd.ms-excel");
        header("Content-Disposition: attachment; filename=\"{$filename}\"");
        header("Pragma: no-cache");
        header("Expires: 0");
        echo "<style> .str{ mso-number-format:\\@; } </style>";
        echo '<table border="1" width="100%">
			<thead>
				<tr>
					<th>Nomor KK</th>
					<th>Nama Kepala Keluarga</th>
					<th>Alamat</th>
					<th>RT</th>
					<th>RW</th>
					<th>Desa/Kelurahan</th>
					<th>Kecamatan</th>
					<th>Kabupaten/Kota</th>
					<th>Provinsi</th>
					<th>Dikeluarkan Tanggal</th>
					<th>Nama Lengkap</th>
					<th>NIK</th>
					<th>Jenis Kelamin</th>
					<th>Tempat Lahir</th>
					<th>Tanggal Lahir</th>
					<th>Agama</th>
					<th>Pendidikan Terakhir</th>
					<th>Pekerjaan</th>
					<th>Status Perkawinan</th>
					<th>Status Hubungan Dalam Keluarga</th>
					<th>Kewarganegaraan</th>
					<th>Nama Ayah</th>
					<th>Nama Ibu</th>
				</tr>
			</thead>
			<tbody>';
        $i = 0;
        foreach ($isi as $data) {
            $subData = BaseUpdatable::find()->where('status_keluarga = "1" and no_kk = "' . $data['id'] . '"')->one();
            $base = DataManagement::findOne($subData['nik']);
            $domisili = TabelDomisili::find()->where('nik = ' . $subData['nik'])->one();
            //echo var_dump($subData->nik);
            //echo var_dump($subData);
            $rawNikKeluarga = BaseUpdatable::find()->where('no_kk = ' . $data['id'])->asArray()->all();
            $nikKeluarga = "";
            foreach ($rawNikKeluarga as $val) {
                if ($nikKeluarga != null) {
                    $nikKeluarga .= ",";
                }
                $nikKeluarga .= $val['nik'];
            }
            $dataKeluarga = DataManagement::find()->joinWith('baseUpdatable')->where('base.nik in (' . $nikKeluarga . ')')->asArray()->all();
            $count = count($dataKeluarga);
            echo '
					<tr>
						<td class="str" rowspan="' . $count . '">' . $data['id'] . '</td>
						<td rowspan="' . $count . '">' . $base['nama'] . '</td>
						<td rowspan="' . $count . '">' . $domisili['alamat'] . '</td>
						<td rowspan="' . $count . '">' . $domisili['rt'] . '</td>
						<td rowspan="' . $count . '">' . $domisili['rw'] . '</td>
						<td rowspan="' . $count . '">' . Villages::findOne($domisili['kelurahan'])->name . '</td>
						<td rowspan="' . $count . '">' . Districts::findOne(substr($domisili['kelurahan'], 0, strlen($domisili['kelurahan']) - 3))->name . '</td>
						<td rowspan="' . $count . '">' . Regencies::findOne(substr($domisili['kelurahan'], 0, strlen($domisili['kelurahan']) - 6))->name . '</td>
						<td rowspan="' . $count . '">' . Provinces::findOne(substr($domisili['kelurahan'], 0, strlen($domisili['kelurahan']) - 8))->name . '</td>
						<td rowspan="' . $count . '">' . Keluarga::findOne($data['id'])->tanggal_terbit . '</td>';
            foreach ($dataKeluarga as $value) {
                $jk = $value['jenis_kelamin'] == 1 ? 'Laki-laki' : 'Perempuan';
                //echo var_dump($value['baseUpdatable']['agama']);
                switch ($value['baseUpdatable']['agama']) {
                    case '1':
                        $agama = 'Islam';
                        break;
                    case '2':
                        $agama = 'Kristen';
                        break;
                    case '3':
                        $agama = 'Katholik';
                        break;
                    case '4':
                        $agama = 'Hindu';
                        break;
                    case '5':
                        $agama = 'Budha';
                        break;
                    case '6':
                        $agama = 'Konghucu';
                        break;
                    case '7':
                        $agama = 'Lainnya';
                        break;
                }
                switch ($value['baseUpdatable']['pendidikan_terakhir']) {
                    case '1':
                        $pend = 'SD';
                        break;
                    case '2':
                        $pend = 'SMP';
                        break;
                    case '3':
                        $pend = 'SMA';
                        break;
                    case '4':
                        $pend = 'D 1';
                        break;
                    case '5':
                        $pend = 'D 2';
                        break;
                    case '6':
                        $pend = 'D 3';
                        break;
                    case '7':
                        $pend = 'Sarjana S 1/D 4';
                        break;
                    case '8':
                        $pend = 'Pasca Sarjana S 2';
                        break;
                    case '9':
                        $pend = 'Pasca Sarjana S 3';
                        break;
                }
                if ($value['baseUpdatable']['status_perkawinan'] == 0) {
                    $status_perkawinan = 'Belum Menikah';
                } elseif ($value['baseUpdatable']['status_perkawinan'] == 1) {
                    $status_perkawinan = 'Menikah';
                } elseif ($value['baseUpdatable']['status_perkawinan'] == 2) {
                    $status_perkawinan = 'Cerai';
                } elseif ($value['baseUpdatable']['status_perkawinan'] == 3) {
                    $status_perkawinan = 'Cerai Ditinggal Mati';
                }
                $status_keluarga = $value['baseUpdatable']['status_keluarga'];
                //echo var_dump($status_keluarga);
                if ($status_keluarga == 1) {
                    $statusKeluarga = 'Kepala Keluarga';
                } elseif ($status_keluarga == 2) {
                    $statusKeluarga = 'Istri';
                } elseif ($status_keluarga == 3) {
                    $statusKeluarga = 'Anak';
                }
                if (TabelKewarganegaraan::findOne($value['nik']) !== null) {
                    $kewarganegaraan = 'WNA';
                } else {
                    $kewarganegaraan = 'WNI';
                }
                echo '
								<td>' . $value['nama'] . '</td>
								<td>' . $value['nik'] . '</td>
								<td>' . $jk . '</td>
								<td>' . $value['tempat_lahir'] . '</td>
								<td>' . $value['tanggal_lahir'] . '</td>
								<td>' . $agama . '</td>
								<td>' . $pend . '</td>
								<td>' . $value['baseUpdatable']['pekerjaan'] . '</td>
								<td>' . $status_perkawinan . '</td>
								<td>' . $statusKeluarga . '</td>
								<td>' . $kewarganegaraan . '</td>
								<td>' . DataManagement::findOne(BaseUpdatable::findOne($value['nik'])->ayah)['nama'] . '</td>
								<td>' . DataManagement::findOne(BaseUpdatable::findOne($value['nik'])->ibu)['nama'] . '</td>
							';
                if ($i < $count - 1) {
                    echo '</tr><tr>';
                } else {
                    echo '</tr>';
                }
                $i++;
            }
            echo '</tbody>';
        }
        echo '</table>';
        return true;
    }