public function actionBayar($id) { $this->layout = 'form'; $modDetails = PinjampegdetT::model()->findAll("pinjamanpeg_id = '{$id}' AND penerimaankas_id is null LIMIT 1"); // echo print_r($modDetails) if (count($modDetails) == 1 && empty($modDetails[0]->penerimaankas_id)) { $model = new PenerimaankasT(); // $model->penerimaankas_id; $pegawai = LoginpemakaiK::model()->findByPk(Yii::app()->user->id); $model->peg_penerima = isset($pegawai->karyawan_id) ? $pegawai->karyawan->nama_karyawan : ""; // $model->peg_penerima = LoginpemakaiK::model()->findByPk(Yii::app()->user->id)->karyawan->nama_karyawan; $model->pinjampegdet_id = $modDetails[0]->pinjampegdet_id; $model->tglpenerimaan = date('Y-m-d H:i:s'); $model->nostruk = Params::noBayarCicilan(); $model->jmlbayar = $modDetails[0]->jmlcicilan; $model->uangditerima = 0; $model->uangkembalian = 0; if (isset($_POST["PenerimaankasT"])) { $model->attributes = $_POST['PenerimaankasT']; // // echo '<pre>'; // echo print_r($model->attributes); // // exit(); if ($model->validate()) { if ($model->save()) { Yii::app()->user->setFlash('success', '<strong>Berhasil!</strong> Data berhasil disimpan.'); $modPinjam = PinjamanpegT::model()->findByPk($id); $modPinjam->sisapinjaman -= $model->jmlbayar; $modPinjam->save(); // $url = Yii::app()->createUrl($this->module->id.'/'.$this->id.'/admin'); // $jsReload = '<script>$(document).ready(function(){window.top.location.href = "'.$url.'";});</script>'; // echo $jsReload; $modDetails[0]->penerimaankas_id = $model->penerimaankas_id; $modDetails[0]->isbayar = true; if ($modDetails[0]->save()) { $url = Yii::app()->createUrl($this->module->id . '/' . $this->id . '/admin'); $jsReload = '<script>window.top.location.href = "' . $url . '";</script>'; echo $jsReload; Yii::app()->end(); // $this->refresh(true, '#'); // '<script> // js:function(){$.fn.yiiGridView.update("pinjamanpeg-t-grid")} // </script>'; } } } else { Yii::app()->user->setFlash('error', "Data gagal disimpan "); } } $this->render('_bayar', array('model' => $model, 'modDetails' => $modDetails)); } else { $model = PenerimaankasT::model()->findByPk($modDetails->penerimaankas_id); } // $this->render('_bayar', array('model'=>$model, 'modDetails'=>$modDetails)); }