public function actionIndex() { //return $this->render('index'); $model = Invoice::findOne(1); echo 'fdsaf'; echo "<pre>"; print_r(Invoice::className()); echo "</pre>"; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Invoice::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $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(['id' => $this->id, 'invoice_time' => $this->invoice_time, 'subtotal' => $this->subtotal, 'customer_id' => $this->customer_id]); $query->andFilterWhere(['like', 'invoice_number', $this->invoice_number])->andFilterWhere(['like', 'comment', $this->comment])->andFilterWhere(['like', 'attribute1', $this->attribute1]); return $dataProvider; }
/** * Displays a single Customer model. * @param string $id * @return mixed */ public function actionView($id) { $model = $this->findModel($id); $searchModel = new InvoiceSearch(); $dataProvider = $searchModel->search(['InvoiceSearch' => ['customer_id' => $id]]); $extraInfor = ['revenues' => Invoice::getRevenuesFormInvoiceList($dataProvider->getModels()), 'transactionCount' => $dataProvider->getTotalCount(), 'debit' => $model->getDebitCurrency()]; if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('kv-detail-success', yii::t('backend/modules/customer', 'Saved record successfully')); // Multiple alerts can be set like below // Yii::$app->session->setFlash('kv-detail-warning', 'A last warning for completing all data.'); // Yii::$app->session->setFlash('kv-detail-info', '<b>Note:</b> You can proceed by clicking <a href="#">this link</a>.'); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('view', ['model' => $model, 'dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'extraInfor' => $extraInfor]); } }
/** * @return \yii\db\ActiveQuery */ public function getInvoices() { return $this->hasMany(Invoice::className(), ['customer_id' => 'id']); }
/** * Finds the Invoice model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Invoice the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Invoice::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getInvoices() { return $this->hasMany(Invoice::className(), ['id' => 'invoice_id'])->viaTable('invoices_items', ['item_id' => 'id']); }