コード例 #1
0
 public function actionMutasi($id)
 {
     $model = $this->loadModel($id);
     $modelm = new KMutasiR();
     $indexTab = 2;
     $modeljs = KJenissuratM::model()->findByPk(Params::JENISSURAT_MUTASI_ID);
     $modelse = KSuratelektronikR::model()->findAll();
     $nosurat = count(KSuratelektronikR::model()->findAll()) + 1;
     $modelm->mutasi_nomorsurat = $modeljs->jenissurat_no . "/" . date('m') . "/" . date('Y') . "/" . str_pad($nosurat, 3, 00, STR_PAD_LEFT);
     if (isset($_POST['KMutasiR'])) {
         $modelm->attributes = $_POST['KMutasiR'];
         $modelm->karyawan_id = $_POST['karyawan_id'];
         $modelser->jenissurat_id = $_POST['jenissurat_id'];
         $valid = $modelm->validate();
         if ($valid) {
             if ($modelm->save()) {
                 $modelm->save() == true ? Yii::app()->user->setFlash('status', 'Berhasil disimpan !') : Yii::app()->user->setFlash('status', 'Gagal disimpan !');
                 $modelser = new KSuratelektronikR();
                 $nosuratelektronik = count(KSuratelektronikR::model()->findAll()) + 1;
                 $modelser->nosurat = $modelm->mutasi_nomorsurat;
                 $modelser->tglsurat = $modelm->tglmutasi;
                 $modelser->judulsurat = $modeljs->jenissurat_judul;
                 $modelser->urutan = $nosuratelektronik;
                 $modelser->jenissurat_id = $modeljs->jenissurat_id;
                 $modelser->mengetahui = $_POST["mengetahui"];
                 $modelser->jmlprint = 1;
                 if ($modelser->validate()) {
                     $modelser->save();
                     //$this->redirect();
                 } else {
                     Yii::app()->user->setFlash('status', 'Surel tidak valid !');
                 }
             }
         }
     }
     $this->render('_formMutasi', array('modelser' => $modelser, 'modelse' => $modelse, 'modeljs' => $modeljs, 'model' => $model, 'modelm' => $modelm, 'id' => $id, 'indexTab' => $indexTab));
 }