Пример #1
0
 /**
  * Finds the Request model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Request the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Request::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #2
0
 /**
  * Creates a new Request model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Request();
     if (isset($_GET["type"])) {
         $model->requestTypeId = $_GET["type"];
     }
     $requestDetail = new \app\models\science\RequestDetail();
     if (isset($_POST["Request"]["searchText"]) && !empty($_POST["Request"]["searchText"])) {
         $dataProvider = new ActiveDataProvider(['query' => \app\models\science\Parcel::find()->where("par_name like '" . $_POST["Request"]["searchText"] . "%%'")]);
     } else {
         $dataProvider = new ActiveDataProvider(['query' => \app\models\science\Parcel::find()->where("par_total>'0' order by par_id")]);
     }
     if (isset(Yii::$app->user->identity->user_id)) {
         //save in to request
         if (isset($_POST["Request"]["reason"]) && !empty($_POST["Request"]["reason"])) {
             if (isset($_POST["selection"])) {
                 $model = new \app\models\science\Request();
                 $model->reason = $_POST["Request"]["reason"];
                 $model->date = date('Y-m-d h:i:s');
                 $model->status = "wait";
                 $model->requestTypeId = $_GET["type"];
                 $model->userId = Yii::$app->user->identity->user_id;
                 $model->save();
                 if ($model->save()) {
                     $requestId = Yii::$app->db->lastInsertID;
                     foreach ($_POST["selection"] as $selectItem) {
                         if (isset($_POST["number"][$selectItem]) && !empty($_POST["number"][$selectItem])) {
                             $requestDetail = new \app\models\science\RequestDetail();
                             $requestDetail->requestId = $requestId;
                             $requestDetail->parcelId = $selectItem;
                             $requestDetail->numberRequest = $_POST["number"][$selectItem];
                             $detail = \app\models\science\parcel::find()->where("par_id='" . $selectItem . "'")->one();
                             $requestDetail->parcelName = $detail->par_name;
                             $requestDetail->typeId = $detail->type_id;
                             $requestDetail->parSize = $detail->par_size;
                             $requestDetail->parUnit = $detail->par_unit;
                             $requestDetail->parPrice = $detail->par_price;
                             $requestDetail->parTotal = $detail->par_total;
                             $requestDetail->status = "wait";
                             $requestDetail->requestTypeId = $_GET["type"];
                             $requestDetail->save();
                         }
                     }
                     $dataProvider = new ActiveDataProvider(['query' => \app\models\science\Parcel::find()]);
                     $model = new \app\models\science\Request();
                 }
             } else {
             }
         }
     }
     return $this->render('create', ['model' => $model, 'requestDetail' => $requestDetail, 'dataProvider' => $dataProvider]);
 }