Exemplo n.º 1
0
 /**
  * Creates a new Emiten model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Emiten();
     $ajax = Yii::$app->request->isAjax;
     if ($model->load(Yii::$app->request->post())) {
         try {
             //$model->SALDOR1 = (float) @($model->SALDO / $model->JMLSAHAM);
             $model->SALDOR1 = 0;
             $model->JMLLOTB = $model->JMLLOT;
             $model->JMLSAHAMB = $model->JMLSAHAM;
             $model->SALDOB = $model->SALDO;
             if ($model->save()) {
                 Yii::$app->session->setFlash('success', 'Data berhasil disimpan.');
                 $model = new Emiten();
             } else {
                 Yii::$app->session->setFlash('error', 'Data gagal disimpan.');
             }
             if ($ajax) {
                 return $this->renderAjax('create', ['model' => $model, 'lotshare' => $this->getLotshare()]);
             } else {
                 return $this->render('create', ['model' => $model, 'lotshare' => $this->getLotshare()]);
             }
         } catch (Exception $e) {
             Yii::$app->session->setFlash('error', 'Kode sudah ada, silahkan pilih kode lain.');
             return $this->renderAjax('create', ['model' => $model, 'lotshare' => $this->getLotshare()]);
         }
         //return $this->redirect(['view', 'id' => $model->KODE]);
     } else {
         if ($ajax) {
             return $this->renderAjax('create', ['model' => $model, 'lotshare' => $this->getLotshare()]);
         } else {
             return $this->render('create', ['model' => $model, 'lotshare' => $this->getLotshare()]);
         }
     }
 }