/**
  * Action REVIEW | Prosess Checked and Approval
  * @param string $id
  * @author ptrnov  <*****@*****.**>
  * @since 1.1
  */
 public function actionReview($id, $stt)
 {
     if ($stt == 0) {
         //CREATE KODE_REF
         $modelSoT2 = SoT2::find()->where("ID='" . $id . "' AND SO_TYPE=10")->one();
         $getSoType = 10;
         $getTGL = $modelSoT2->TGL;
         $setTGL = $modelSoT2->WAKTU_INPUT_INVENTORY;
         $getCUST_KD = $modelSoT2->CUST_KD;
         $getUSER_ID = $modelSoT2->USER_ID;
         $connect = Yii::$app->db_esm;
         $kode = Yii::$app->ambilkonci->getSMO();
         $transaction = $connect->beginTransaction();
         try {
             //SO HEADER
             $connect->createCommand()->insert('so_0001', ['KD_SO' => $kode, 'TGL' => $setTGL, 'USER_SIGN1' => $getUSER_ID, 'CUST_ID' => $getCUST_KD])->execute();
             //SO DETAIL -  STOCK
             $connect->createCommand()->update('so_t2', ['KODE_REF' => $kode], ['SO_TYPE' => $getSoType, 'TGL' => $getTGL, 'CUST_KD' => $getCUST_KD, 'USER_ID' => $getUSER_ID])->execute();
             //STATUS PROCESS
             $connect->createCommand()->insert('so_0002', ['KD_SO' => $kode, 'ID_USER' => $getUSER_ID, 'STT_PROCESS' => '0'])->execute();
             // ...other DB operations...
             $transaction->commit();
         } catch (\Exception $e) {
             $transaction->rollBack();
             throw $e;
         }
         $this->redirect(['/purchasing/salesman-order/review', 'id' => $kode, 'stt' => 1]);
         //PR create Generate Code dari komponent. Tabel so_0001.
         //Save kode generate  Tabel so_0001.
         //Update SoT2 KODE_REF where ($getSoType,getTGL,getCUST_KD,getUSER_ID).
         //Editing editable : SUBMIT_QTY,SUBMIT_PRICE
     } else {
         //VIEW KODE_REF
         $modelSoT2 = SoT2::find()->with('cust')->where("KODE_REF='" . $id . "' AND SO_TYPE=10")->one();
         $soHeaderData = SoHeader::find()->with('cust')->where(['KD_SO' => $id])->one();
         $getSoType = 10;
         $getTGL = $modelSoT2->TGL;
         $getCUST_KD = $modelSoT2->CUST_KD;
         $getUSER_ID = $modelSoT2->USER_ID;
         // $status_sign = SoStatus::find()->where(['KD_SO'=>$id])->count();
         $searchModelDetail = new SoDetailSearch(['KODE_REF' => $id, 'CUST_KD' => $getCUST_KD, 'USER_ID' => $getUSER_ID]);
         $aryProviderSoDetail = $searchModelDetail->searchDetail(Yii::$app->request->queryParams);
         /*
          * Process Editable Row [Columm SQTY]
          * @author ptrnov  <*****@*****.**>
          * @since 1.1
          **/
         if (Yii::$app->request->post('hasEditable')) {
             $id = Yii::$app->request->post('editableKey');
             $model = SoT2::findOne($id);
             $out = Json::encode(['output' => '', 'message' => '']);
             $post = [];
             $posted = current($_POST['SoT2']);
             $post['SoT2'] = $posted;
             if ($model->load($post)) {
                 $model->save();
                 $output = '';
                 if (isset($posted['SUBMIT_PRICE'])) {
                     $output = $model->SUBMIT_PRICE;
                 }
                 if (isset($posted['SUBMIT_QTY'])) {
                     $output = $model->SUBMIT_QTY;
                 }
                 if (isset($posted['TGL'])) {
                     $output = $model->TGL;
                 }
                 $out = Json::encode(['output' => $output, 'message' => '']);
             }
             // return ajax json encoded response and exit
             echo $out;
             return;
         }
         // return $this->render('_actionReview',[
         // 	'aryProviderSoDetail'=>$aryProviderSoDetail,
         // 	'kode_SO'=>$modelSoT2->KODE_REF,
         // 	'cust_kd'=>$getCUST_KD,
         // 	'tgl'=>$getTGL,
         // 	'user_id'=>$getUSER_ID,
         // 	'searchModelDetail'=>$searchModelDetail,
         // 	'model_cus'=>$modelSoT2->cust,
         // 	'soHeaderData'=>$soHeaderData
         // ]);
         return $this->render('_actionReview', ['aryProviderSoDetail' => $aryProviderSoDetail, 'kode_SO' => $soHeaderData->KD_SO, 'cust_kd' => $soHeaderData->CUST_ID, 'cust_nmx' => $soHeaderData->cust->CUST_NM, 'tgl' => $soHeaderData->TGL, 'user_id' => $soHeaderData->USER_SIGN1, 'searchModelDetail' => $searchModelDetail, 'model_cus' => $modelSoT2->cust, 'soHeaderData' => $soHeaderData]);
     }
 }
 public function actionDeleteSoDetail()
 {
     if (Yii::$app->request->isAjax) {
         $request = Yii::$app->request;
         $id = $request->post('id');
         //\Yii::$app->response->format = Response::FORMAT_JSON;
         $soDetail = SoT2::findOne($id);
         $soDetail->STATUS = 3;
         //$ro->NM_BARANG=''
         $soDetail->save();
         return true;
     }
 }
 /**
  * Finds the SoT2 model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return SoT2 the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = SoT2::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }