/** * Creates a new Keluarga model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Keluarga(); if ($model->load(Yii::$app->request->post())) { $no_kk = substr($model->kepala_keluarga, 0, 6) . Yii::$app->formatter->asDate('now', 'ddMMyy') . $model->id; $model->id = $no_kk; $model->tanggal_terbit = date('Y-m-d'); $model->tanggal_pembaruan = date('Y-m-d'); $model->status = 1; $updatable = BaseUpdatable::findOne($model->kepala_keluarga); $updatable->no_kk = $no_kk; $updatable->status_keluarga = 1; //echo var_dump($model); if ($model->save() && $updatable->save()) { $this->writeLog("Membuat kartu keluarga dengan nomor KK {$keluarga->id}"); return $this->redirect(['view', 'id' => $model->id]); } else { VarDumper::dump($model->getErrors(), 5678, true); //return $this->actionIndex(); } } else { return $this->renderAjax('create', ['model' => $model]); } }
/* @var $model common\models\Keluarga */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="keluarga-form"> <?php $form = ActiveForm::begin(['layout' => 'horizontal']); ?> <?php echo $form->field($model, 'id')->input('number', ['min' => 0, 'placeholder' => 'Masukkan Empat Digit Terakhir'])->label('Empat Digit Terakhir'); ?> <?php $data = ArrayHelper::map(BaseUpdatable::find()->where(['no_kk' => 0])->asArray()->all(), 'nik', 'nik'); ?> <?php echo $form->field($model, 'kepala_keluarga')->widget(Select2::classname(), ['data' => $data, 'language' => 'id', 'options' => ['placeholder' => 'Masukkan NIK Kepala Keluarga'], 'pluginOptions' => ['allowClear' => true]])->label('NIK Kepala Keluarga'); ?> <div class="form-group"> <div class="col-md-3"></div> <div class="col-md-6"> <strong>Catatan : </strong>NIK Kepala Keluarga harus sudah terdaftar </div> <div class="col-md-3"></div> </div> <div class="form-group text-center"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
/** * Finds the BaseUpdatable model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return BaseUpdatable the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModelUpdatable($id) { if (($model = BaseUpdatable::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Logs in a user. * * @return mixed */ public function actionUser($id) { $user = \common\models\BaseUpdatable::findOne($id)->foto; echo '<img src="' . $user . '" width="320px"/>'; }
?> </h1> </div> <div class="box-body"> <p> <?php echo Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']); ?> <?php echo Html::a('Delete', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Are you sure you want to delete this item?', 'method' => 'post']]); ?> </p> <?php $data = BaseUpdatable::find()->select('nik')->where(['no_kk' => $model->id, 'status_keluarga' => 3])->asArray()->all(); $istri = BaseUpdatable::find()->select('nik')->where(['no_kk' => $model->id, 'status_keluarga' => 2])->one()['nik']; $nik = ""; foreach ($data as $val) { if ($nik != "") { $nik .= ","; } $nik .= $val['nik']; } if (!empty($nik)) { $dataNama = DataManagement::find()->select('nama')->where('nik in (' . $nik . ')')->asArray()->all(); } else { $dataNama = []; } $namaIstri = DataManagement::findOne($istri)['nama']; $nama = ""; foreach ($dataNama as $val) {
/** * Get Data * @param string $nik * @return BaseUpdatable */ public function getData($nik) { return BaseUpdatable::findOne($nik); }