/**
  * Creates a new InvoiceItem model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new InvoiceItem();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function actionAdditem($entrepreneur_user_id, $invoice_id)
 {
     $model = new InvoiceItem();
     if (Yii::$app->request->post()) {
         $x = Yii::$app->request->post();
         $item = $x['EntpInvoice']['item'];
         $code = $x['EntpInvoice']['code'];
         $qty = $x['EntpInvoice']['qty'];
         $price = $x['EntpInvoice']['price'];
         $invoice = $x['EntpInvoice']['invoice_id'];
         $entp = $x['EntpInvoice']['entrepreneur_user_id'];
         $model->code = $code;
         $model->item = $item;
         $model->price = $price;
         $model->qty = $qty;
         $model->save();
         //if($model->save()){
         $item = new EntpInvoiceItem();
         $item->invoice_item_id = $model->id;
         $item->invoice_id = intval($invoice);
         $item->save();
         //}
         Yii::$app->session->setFlash('success', 'New Item Added');
         $model = $this->findModel($entp, $invoice);
         $query = $model->invoice->getInvoiceItems();
         $dataProvider = new ActiveDataProvider(['query' => $query]);
         return $this->render('view', ['model' => $model, 'dataProvider' => $dataProvider]);
     } else {
         $model = $this->findModel($entrepreneur_user_id, $invoice_id);
         $query = $model->invoice->getInvoiceItems();
         $dataProvider = new ActiveDataProvider(['query' => $query]);
         return $this->render('view', ['model' => $model, 'dataProvider' => $dataProvider]);
     }
 }