/** * Creates a new Requestorder model. * If creation is successful, the browser will be redirected to the 'view' page. * @author ptrnov <*****@*****.**> * @since 1.1 */ public function actionCreate() { $model = new Requesttermheader(); //t0001header $model->scenario = 'simpan'; $radiorqt = Yii::$app->request->post(); $term_invest = new Rtdetail(); //t0001detail if ($model->load(Yii::$app->request->post()) && $term_invest->load(Yii::$app->request->post())) { $radioterm = $radiorqt['Requesttermheader']['NEW']; if ($radioterm == 1) { $kode = Yii::$app->ambilkonci->getRtiCode($model->KD_CORP); $model->KD_RIB = $kode; } else { $kode = Yii::$app->ambilkonci->getRtbCode($model->KD_CORP); $model->KD_RIB = $kode; } $cari_term = Yii::$app->db_esm->createCommand('SELECT TERM_ID from t0000header where CUST_KD_PARENT ="' . $model->CUST_ID_PARENT . '"')->queryScalar(); // $cari_term = Requesttermheader::find()->where(['CUST_ID_PARENT'=>$model->CUST_ID_PARENT])->one(); $model->TERM_ID = $cari_term; $model->CREATED_AT = date('Y-m-d'); $model->ID_USER = Yii::$app->getUserOpt->Profile_user()->EMP_ID; $model->save(); $term_invest->KD_RIB = $model->KD_RIB; $term_invest->INVESTASI_TYPE = $term_invest->ID_INVEST; $term_invest->CREATED_AT = date('Y-m-d'); $term_invest->CREATED_BY = Yii::$app->user->identity->username; // $term_invest->ID_INVEST = $term_invest->ID_INVEST; $term_invest->TERM_ID = $cari_term; if ($term_invest->save()) { $cari_account = Termdetail::find()->where(['TERM_ID' => $model->TERM_ID, 'INVES_ID' => $term_invest->ID_INVEST])->andwhere(['<>', 'STATUS', 2])->one(); if (!$cari_account) { $termdetail = new Termdetail(); $termdetail->CUST_KD_PARENT = $model->CUST_ID_PARENT; $termdetail->INVES_ID = $term_invest->INVESTASI_TYPE; $termdetail->INVES_TYPE = $termdetail->INVES_ID; $termdetail->TERM_ID = $model->TERM_ID; $termdetail->CORP_ID = $model->KD_CORP; $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('_form', ['model' => $model, 'term_invest' => $term_invest]); } }
/** * Creates a new Requestorder model. * If creation is successful, the browser will be redirected to the 'view' page. * @author ptrnov <*****@*****.**> * @since 1.1 */ public function actionCreate() { $model = new Requesttermheader(); //t0001header $model->scenario = 'simpan'; $radiorqt = Yii::$app->request->post(); $term_invest = new Rtdetail(); //t0001detail if ($model->load(Yii::$app->request->post()) && $term_invest->load(Yii::$app->request->post())) { $radioterm = $radiorqt['Requesttermheader']['NEW']; if ($radioterm == 1) { $kode = Yii::$app->ambilkonci->getRtiCode($model->KD_CORP); $model->KD_RIB = $kode; } else { $kode = Yii::$app->ambilkonci->getRtbCode($model->KD_CORP); $model->KD_RIB = $kode; } $explode = explode('-', $model->CUST_ID_PARENT); $model->CUST_ID_PARENT = $explode[1]; $model->TERM_ID = $explode[0]; $model->CREATED_AT = date('Y-m-d'); $model->ID_USER = Yii::$app->getUserOpt->Profile_user()->EMP_ID; $model->KD_DEP = Yii::$app->getUserOpt->Profile_user()->emp->DEP_ID; $model->save(); $term_invest->KD_RIB = $model->KD_RIB; $term_invest->INVESTASI_TYPE = $term_invest->ID_INVEST; $term_invest->CREATED_AT = date('Y-m-d'); $term_invest->CREATED_BY = Yii::$app->user->identity->username; $term_invest->PERIODE_START = $model->PERIOD_START; $term_invest->PERIODE_END = $model->PERIOD_END; // $term_invest->ID_INVEST = $term_invest->ID_INVEST; $term_invest->TERM_ID = $cari_term; if ($term_invest->save()) { $cari_account = Termdetail::find()->where(['TERM_ID' => $model->TERM_ID, 'INVES_ID' => $term_invest->ID_INVEST])->andwhere(['<>', 'STATUS', 2])->one(); if (!$cari_account) { $termdetail = new Termdetail(); $termdetail->CUST_KD_PARENT = $model->CUST_ID_PARENT; $termdetail->INVES_ID = $term_invest->INVESTASI_TYPE; $termdetail->INVES_TYPE = $termdetail->INVES_ID; $termdetail->TERM_ID = $model->TERM_ID; $termdetail->CORP_ID = $model->KD_CORP; $termdetail->STATUS = 2; $termdetail->CREATE_BY = Yii::$app->user->identity->username; $termdetail->CREATE_AT = date('Y-m-d'); $termdetail->PERIODE_START = $model->PERIOD_START; $termdetail->PERIODE_END = $model->PERIOD_END; $termdetail->save(); } } return $this->redirect(['/purchasing/request-term/edit?kd=' . $model->KD_RIB]); } else { return $this->renderAjax('_form', ['model' => $model, 'term_invest' => $term_invest, 'cus_data' => self::ary_cus_term(), 'corp' => Yii::$app->getUserOpt->Profile_user()->emp->EMP_CORP_ID, 'data_invest' => self::ary_invets()]); } }