/** * Creates a new Requestorder model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $connection = \Yii::$app->db2; $cons = \Yii::$app->db_esm; $model = new Requestorder(); $reqorder = new Roatribute(); $rodetail = new Rodetail(); $rostatus = new Requestorderstatus(); $empId = Yii::$app->user->identity->EMP_ID; $dt = Employe::find()->where(['EMP_ID' => $empId])->all(); // ------------ TAHUN.BULAN.TANGGAL.RO.NO URUT (4DIGIT) == > 2015.06.30.RO.0001 $qwe = Requestorder::find()->select('ID')->orderBy(['ID' => SORT_DESC])->limit(1)->all(); if (count($qwe) == 0) { $lastKd = 0; } else { $lastKd = $qwe[0]['ID']; } $nKD = $lastKd + 1; $pnjg = strlen($nKD); if ($pnjg == 1) { $kd = "000" . $nKD; } else { if ($pnjg == 2) { $kd = "00" . $nKD; } else { if ($pnjg == 3) { $kd = "0" . $nKD; } else { if ($pnjg >= 4) { $kd = $nKD; } } } } $kode = date('Y.m.d') . '.RO.' . $kd; $model->KD_RO = $kode; $model->ID_USER = $empId; $model->KD_DEP = $dt[0]['DEP_ID']; $model->KD_CORP = $dt[0]['EMP_CORP_ID']; $model->CREATED_AT = date("Y-m-d H:i:s"); $jab = $dt[0]['DEP_ID']; $que = "SELECT EMP_ID FROM a0001 WHERE (DEP_ID='GA' OR DEP_ID='{$jab}' ) AND (JAB_ID='MGR' OR JAB_ID='SVR') AND EMP_STS<>'3'"; $modelss = $connection->createCommand($que); $users = $modelss->queryAll(); if (count($users) != 0) { foreach ($users as $usr) { $isi[] = ['KD_RO' => $kode, 'ID_USER' => $usr['EMP_ID'], 'STATUS' => '0']; } $model->save(); $cons->createCommand()->batchInsert(Requestorderstatus::tableName(), ['KD_RO', 'ID_USER', 'STATUS'], $isi)->execute(); return $this->redirect(['buatro', 'id' => $kode]); } return $this->redirect([' ']); // print_r(Yii::$app->user->identity); }