public function addInvoice() { if ($this->validate()) { $invoice = new Invoice(); $invoice->invoice_no = $this->invoice_no; $invoice->due_date = $this->due_date; $invoice->bank_name = $this->bank_name; $invoice->account_no = $this->account_no; $invoice->customer = $this->customer; $invoice->address = $this->address; $invoice->telephone = $this->telephone; $invoice->fax = $this->fax; $invoice->pic = $this->pic; $invoice->mobile = $this->mobile; if ($invoice->save()) { $entpinvoice = new EntpInvoice(); $entpinvoice->entrepreneur_user_id = Yii::$app->user->id; $entpinvoice->link('invoice', $invoice); } return $invoice; } return null; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $id = Yii::$app->user->id; $query = EntpInvoice::find(); $query->joinWith(['invoice'])->where('entp_invoice.entrepreneur_user_id=' . $id); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->sort->attributes['invoice_no'] = ['asc' => ['invoice.invoice_no' => SORT_ASC], 'desc' => ['invoice.invoice_no' => SORT_DESC]]; $dataProvider->sort->attributes['created_at'] = ['asc' => ['invoice.created_at' => SORT_ASC], 'desc' => ['invoice.created_at' => SORT_DESC]]; $dataProvider->sort->attributes['updated_at'] = ['asc' => ['invoice.updated_at' => SORT_ASC], 'desc' => ['invoice.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, 'invoice_id' => $this->invoice_id]); $query->andFilterWhere(['like', 'invoice.invoice_no', $this->invoice_no])->andFilterWhere(['like', 'invoice.created_at', $this->created_at])->andFilterWhere(['like', 'invoice.updated_at', $this->updated_at]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getEntpInvoices() { return $this->hasMany(EntpInvoice::className(), ['invoice_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getEntpInvoices() { return $this->hasMany(EntpInvoice::className(), ['entrepreneur_user_id' => 'user_id']); }
/** * Finds the EntpInvoice model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $entrepreneur_user_id * @param integer $invoice_id * @return EntpInvoice the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($entrepreneur_user_id, $invoice_id) { if (($model = EntpInvoice::findOne(['entrepreneur_user_id' => $entrepreneur_user_id, 'invoice_id' => $invoice_id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }