/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Loan::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20], 'sort' => ['defaultOrder' => ['dateApplied' => 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(['loanId' => $this->loanId, 'userId' => $this->userId, 'amount' => $this->amount, 'interest' => $this->interest, 'duration' => $this->duration, 'dateApplied' => !empty($this->dateApplied) ? date("Y-m-d", strtotime($this->dateApplied)) : null, 'dateLoanEnds' => !empty($this->dateLoanEnds) ? date("Y-m-d", strtotime($this->dateLoanEnds)) : null, 'isDeleted' => false]);
     return $dataProvider;
 }
 /**
  * Finds the Loan model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Loan the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Loan::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getLoans()
 {
     return $this->hasMany(Loan::className(), ['userId' => 'userId'])->inverseOf('user');
 }
 /**
  * View loan information and extensions for a certain loan.
  *
  * @param  int $id
  *
  * @return \Illuminate\View\View
  */
 public function view($id)
 {
     $loan = Loan::with('historyRecords')->findOrFail($id);
     $loan->historyRecords->each(function ($history) use($loan) {
         $history->start_date = $loan->start_date;
         $history->amount = $loan->amount;
         $history->history_record_id = $history->id;
     });
     return view('view', ['loan' => $loan->toJson()]);
 }