Пример #1
0
 /**
  * save the post's account (*3)
  */
 public function saveAccount()
 {
     $this->invest_ids = [];
     $pcs = Terminvest::find()->where(['ID' => $this->INVES_ID])->all();
     if (is_array($this->invest_ids)) {
         foreach ($pcs as $key => $value) {
             $pc = new Termdetail();
             $pc->CUST_KD_PARENT = $this->cus_kd;
             $pc->TERM_ID = $this->term_id;
             $pc->INVES_ID = $value->ID;
             $pc->save();
         }
     }
 }
 public function actionAddNewInvest($kd, $term_id, $cust_kd)
 {
     # code...
     $model = new Rtdetail();
     if ($model->load(Yii::$app->request->post())) {
         $model->TERM_ID = $term_id;
         $model->KD_RIB = $kd;
         $model->ID_INVEST = $model->INVESTASI_TYPE;
         if ($model->save()) {
             $cari_account = Termdetail::find()->where(['TERM_ID' => $model->TERM_ID, 'INVES_ID' => $model->ID_INVEST])->andwhere(['<>', 'STATUS', 2])->one();
             if (!$cari_account) {
                 $termdetail = new Termdetail();
                 $termdetail->CUST_KD_PARENT = $cust_kd;
                 $termdetail->INVES_ID = $model->INVESTASI_TYPE;
                 $termdetail->INVES_TYPE = $termdetail->INVES_ID;
                 $termdetail->TERM_ID = $model->TERM_ID;
                 $termdetail->CORP_ID = Yii::$app->getUserOpt->Profile_user()->emp->EMP_CORP_ID;
                 $termdetail->STATUS = 2;
                 $termdetail->CREATE_BY = Yii::$app->user->identity->username;
                 $termdetail->CREATE_AT = date('Y-m-d');
                 $termdetail->save();
             }
         }
         return $this->redirect(['/purchasing/request-term/edit?kd=' . $model->KD_RIB]);
     } else {
         return $this->renderAjax('_new_invest', ['model' => $model]);
     }
 }