public function actionCreateparent()
 {
     $model = new Kategoricus();
     if ($model->load(Yii::$app->request->post())) {
         $data = Kategoricus::find()->count();
         if ($data == 0) {
             $model->CUST_KTG_PARENT = 1;
         } else {
             $datax = Kategoricus::find()->MAX('CUST_KTG');
             $model->CUST_KTG_PARENT = $datax + 1;
         }
         if ($model->validate()) {
             $model->CREATED_BY = Yii::$app->user->identity->username;
             $model->CREATED_AT = date("Y-m-d H:i:s");
             if ($model->save()) {
                 echo 1;
             } else {
                 echo 0;
             }
         }
     } else {
         return $this->renderAjax('_formparent', ['model' => $model]);
     }
 }
 /**
  * Create  Kategoricus model.
  * Create  parent Kategoricus.
  * @author wawan
  * @since 1.1.0
  * @return mixed
  */
 public function actionCreateparent()
 {
     $model = new Kategoricus();
     $post = Yii::$app->request->post();
     $val = $post['Kategoricus']['parentnama'];
     if ($model->load(Yii::$app->request->post())) {
         if ($val) {
             $transaction = Kategoricus::getDb()->beginTransaction();
             try {
                 $model->STATUS = 1;
                 $model->CREATED_BY = Yii::$app->user->identity->username;
                 $model->CREATED_AT = date("Y-m-d H:i:s");
                 $model->save();
                 Kategoricus::getDb()->createCommand()->update('c0001k', ['CUST_KTG_PARENT' => $model->CUST_KTG], ['CUST_KTG' => $model->CUST_KTG])->execute();
                 // ...other DB operations...
                 $transaction->commit();
             } catch (\Exception $e) {
                 $transaction->rollBack();
                 throw $e;
             }
         } else {
             $model->STATUS = 1;
             $model->CREATED_BY = Yii::$app->user->identity->username;
             $model->CREATED_AT = date("Y-m-d H:i:s");
             $model->save();
         }
         // $data = Kategoricus::find()->count();
         // if($data == 0)
         // {
         //     $model->CUST_KTG_PARENT = 1;
         // }
         // else{
         //     $datax = Kategoricus::find()->MAX('CUST_KTG');
         //       $model->CUST_KTG_PARENT = $datax+1;
         // }
         //   if($model->validate())
         //   {
         //       $model->CREATED_BY =  Yii::$app->user->identity->username;
         //       $model->CREATED_AT = date("Y-m-d H:i:s");
         //       $model->save();
         //   }
         return $this->redirect(['esm-index-kategori']);
     } else {
         return $this->renderAjax('_formparent', ['model' => $model, 'parent' => self::AryParent()]);
     }
 }