Example #1
0
 /**
  * Creates a new Sales model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $sales = new Sales();
     if ($sales->load(Yii::$app->request->post())) {
         $sales->loadDefaultValues();
         $sales->save();
         if ($sales->save()) {
             $entp = new EntpSales();
             $entp->sales_id = $this->id;
             $entp->entrepreneur_id = Yii::$app->user->id;
             $entp->link('sales', $sales);
         }
         Yii::$app->session->setFlash('success', 'New Product Add');
         $searchModel = new EntpSalesSearch();
         $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
         return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
     } else {
         return $this->render('create', ['model' => $sales]);
     }
 }
Example #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $id = Yii::$app->user->id;
     $query = EntpSales::find();
     $query->joinWith(['entrepreneur', 'sales'])->where('entp_sales.entrepreneur_user_id=' . $id);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->attributes['total'] = ['asc' => ['sales.total' => SORT_ASC], 'desc' => ['sales.total' => SORT_DESC]];
     $dataProvider->sort->attributes['reason'] = ['asc' => ['sales.reason' => SORT_ASC], 'desc' => ['sales.reason' => SORT_DESC]];
     $dataProvider->sort->attributes['created_at'] = ['asc' => ['sales.created_at' => SORT_ASC], 'desc' => ['sales.created_at' => SORT_DESC]];
     $dataProvider->sort->attributes['updated_at'] = ['asc' => ['sales.updated_at' => SORT_ASC], 'desc' => ['sales.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, 'sales_id' => $this->sales_id]);
     $query->andFilterWhere(['like', 'sales.total', $this->total])->andFilterWhere(['like', 'sales.reason', $this->reason])->andFilterWhere(['like', 'sales.created_at', $this->created_at])->andFilterWhere(['like', 'sales.updated_at', $this->updated_at]);
     return $dataProvider;
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getEntpSales()
 {
     return $this->hasMany(EntpSales::className(), ['entrepreneur_id' => 'id']);
 }
Example #4
0
 /**
  * Finds the EntpSales 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 $sales_id
  * @return EntpSales the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($entrepreneur_user_id, $sales_id)
 {
     if (($model = EntpSales::findOne(['entrepreneur_user_id' => $entrepreneur_user_id, 'sales_id' => $sales_id])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }