/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $id = Yii::$app->user->id; $query = EntpProduct::find(); $query->joinWith(['entrepreneur', 'product'])->where('entp_product.entrepreneur_user_id=' . $id); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->sort->attributes['product'] = ['asc' => ['product.product' => SORT_ASC], 'desc' => ['product.product' => SORT_DESC]]; $dataProvider->sort->attributes['code'] = ['asc' => ['product.code' => SORT_ASC], 'desc' => ['product.code' => SORT_DESC]]; $dataProvider->sort->attributes['qty'] = ['asc' => ['product.qty' => SORT_ASC], 'desc' => ['product.qty' => SORT_DESC]]; $dataProvider->sort->attributes['created_at'] = ['asc' => ['product.created_at' => SORT_ASC], 'desc' => ['product.created_at' => SORT_DESC]]; $dataProvider->sort->attributes['updated_at'] = ['asc' => ['product.updated_at' => SORT_ASC], 'desc' => ['product.updated_at' => SORT_DESC]]; $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['entrepreneur_user_id' => $this->entrepreneur_user_id, 'product_id' => $this->product_id]); $query->andFilterWhere(['like', 'product.code', $this->code])->andFilterWhere(['like', 'product.qty', $this->qty])->andFilterWhere(['like', 'product.product', $this->product])->andFilterWhere(['like', 'product.created_at', $this->created_at])->andFilterWhere(['like', 'product.updated_at', $this->updated_at]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getEntpProducts() { return $this->hasMany(EntpProduct::className(), ['entrepreneur_user_id' => 'user_id']); }
/** * @return \yii\db\ActiveQuery */ public function getEntpProducts() { return $this->hasMany(EntpProduct::className(), ['product_id' => 'id']); }
/** * Finds the EntpProduct model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $entrepreneur_id * @param integer $product_id * @return EntpProduct the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($entrepreneur_user_id, $product_id) { if (($model = EntpProduct::findOne(['entrepreneur_user_id' => $entrepreneur_user_id, 'product_id' => $product_id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
?> <?php echo $form->field($model, 'item')->hiddenInput(['id' => 'item'])->label(false); ?> <?php echo $form->field($model, 'code')->hiddenInput(['id' => 'code'])->label(false); ?> <?php echo $form->field($model, 'price')->hiddenInput(['id' => 'price'])->label(false); ?> <div class="row"> <div class="col-lg-5"> <?php echo $form->field($model, 'productSelect')->label('Select Product')->dropDownList(ArrayHelper::map(EntpProduct::find()->joinWith('product')->where('entp_product.entrepreneur_user_id=' . $id)->all(), 'product.id', 'product.product'), ['style' => 'width:230px;', 'tabindex' => '3', 'prompt' => '', 'id' => 'productSelect']); ?> <div id="hehe"> </div> </div> <div class="col-lg-2"> <?php echo $form->field($model, 'qty')->textInput(['id' => 'qty', 'style' => 'width:50px;'])->label('Qty'); ?> </div> <br> <div class="col-lg-3"> <div class="form-group"> <?php