/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Reimbursement::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false, 'sort' => ['defaultOrder' => ['id' => SORT_ASC]]]); $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(['tech_id' => $this->tech_id, 'purchase_id' => $this->purchase_id, 'amount' => $this->amount, 'reimbursed' => $this->reimbursed]); return $dataProvider; }
/** * Finds the Reimbursement model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Reimbursement the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Reimbursement::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return ReimbursementQuery */ public function getReimbursements() { return $this->hasMany(Reimbursement::className(), ['tech_id' => 'contact_id']); }
public function actionReimbursement($id) { $purchasedItem = $this->findModel($id); $model = new Reimbursement(); $model->loadDefaultValues(); $model->scenario = $model::SCENARIO_PURCHASE; $model->created_by = Yii::$app->user->id; $model->purchase_id = $purchasedItem->id; if ($model->load(Yii::$app->request->post())) { $model->receiptImg = UploadedFile::getInstance($model, 'receiptImg'); if ($model->save()) { return $this->redirect(['/reimbursement/view', 'id' => $model->id]); } } if (!Yii::$app->request->isPost) { $model->load(Yii::$app->request->get()); } if (Yii::$app->request->isAjax) { return $this->renderAjax('/reimbursement/_form', ['model' => $model]); } return $this->render('/reimbursement/create', ['model' => $model]); }
/** * @return ReimbursementQuery */ public function getReimbursements() { return $this->hasMany(Reimbursement::className(), ['purchase_id' => 'id'])->inverseOf('purchasedItem'); }