示例#1
0
 public function addOperation()
 {
     if ($this->currency_id != '1') {
         $course = new Course();
         if (!$course->checkCourse($this->currency_id)) {
             $course->currency_id = $this->currency_id;
             $currency = Currency::findOne($this->currency_id);
             $course->course = $course->getCourse($currency->iso);
             if (!$course->save()) {
                 throw new ErrorException('Курс не обновлен' . var_dump($course));
             }
         }
     }
     $operation = new Operation();
     $operation->user_id = Yii::$app->getUser()->id;
     $operation->category_id = $this->category_id === '' ? 1 : $this->category_id;
     $operation->currency_id = $this->currency_id === '' ? 1 : $this->currency_id;
     $operation->summ = $this->operation_type == 'income' ? $this->summ * 100 : $this->summ * -100;
     $operation->description = $this->description;
     return $operation->save() ? $operation : null;
 }
示例#2
0
 public function actionReport()
 {
     $this->layout = 'main';
     $model = new Operation();
     if (Yii::$app->request->post('Operation')) {
         $dates = Yii::$app->request->post('Operation');
         $model->date_from = $dates['date_from'];
         $model->date_to = $dates['date_to'];
         $report = $model->getReportByDates();
         return $this->render('report', ['model' => $model, 'report' => $report, 'date_from' => $dates['date_from'], 'date_to' => $dates['date_to']]);
     }
     return $this->render('report', ['model' => $model]);
 }
示例#3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $pars = 0)
 {
     $query = Operation::find();
     if ($pars) {
         $query->andFilterWhere(['pars' => $pars]);
     }
     $query->orderBy("id desc");
     $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, 'pars' => $this->pars, 'created' => $this->created]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'state', $this->state])->andFilterWhere(['like', 'city', $this->city])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'site', $this->site])->andFilterWhere(['like', 'img', $this->img]);
     return $dataProvider;
 }
示例#4
0
文件: Catalog.php 项目: kllakk/money
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getOperation()
 {
     return $this->hasOne(Operation::className(), ['id' => 'operation_id']);
 }
示例#5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getOperations()
 {
     return $this->hasMany(Operation::className(), ['resource_id' => 'resource_id']);
 }
示例#6
0
 /**
  * Просмотр истории входящих операций по id пользователя
  * @param int $id
  * @return string
  */
 public function actionHistoryincoming($id = 0)
 {
     if (!isset(Yii::$app->user->id) || !Yii::$app->user->identity->getAttribute('user_type') && $id != 0) {
         Log::writeLog('historyincoming');
         $this->goHome();
     }
     //        если не админ
     if (!Yii::$app->user->identity->getAttribute('user_type') || $id == 0) {
         $id = Yii::$app->user->id;
     }
     $operation = Operation::getListOperationByIdInc($id);
     return $this->render('historyinc', ['operation' => $operation['list'], 'pages' => $operation['pages']]);
 }
示例#7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getOperations()
 {
     return $this->hasMany(Operation::className(), ['id' => 'operation'])->viaTable('{{%operation_category_join}}', ['category' => 'id']);
 }
示例#8
0
 /**
  * Finds the Operation model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Operation the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Operation::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * @Post("/editoperation")
  *
  */
 public function posteditoperation(Request $request)
 {
     $et = Operation::find($request->get('id'));
     // $et->nom = "000";
     //  $et->montant += 100 ;
     $user = User::find(Auth::user()->id);
     if ($et->type_dr == "depense" and $et->mode_paiement == "poche") {
         $user->solde_poche = $user->solde_poche + $request->montant;
         $user->solde_totale = $user->solde_totale + $request->montant;
         $user->save();
     }
     if ($et->type_dr == "revenue" and $et->mode_paiement == "bank") {
         $user->soldebancaire = $user->soldebancaire - $request->montant;
         $user->solde_totale = $user->solde_totale - $request->montant;
         $user->save();
     }
     if ($et->type_dr == "depense" and $et->mode_paiement == "bank") {
         $user->soldebancaire = $user->soldebancaire + $request->montant;
         $user->solde_totale = $user->solde_totale + $request->montant;
         $user->save();
     }
     if ($et->type_dr == "revenue" and $et->mode_paiement == "poche") {
         $user->solde_poche = $user->solde_poche - $request->montant;
         $user->solde_totale = $user->solde_totale - $request->montant;
         $user->save();
     }
     $et->nom = $request->nom;
     $et->type_dr = $request->type_dr;
     $et->montant = $request->montant;
     $et->mode_paiement = $request->mode_paiement;
     $et->description = $request->description;
     $et->etiquette_id = $request->etiquette;
     $et->categorie_id = $request->categorie;
     if ($et->type_dr == "depense" and $et->mode_paiement == "poche") {
         $user->solde_poche = $user->solde_poche - $request->montant;
         $user->solde_totale = $user->solde_totale - $request->montant;
         $user->save();
     }
     if ($et->type_dr == "revenue" and $et->mode_paiement == "bank") {
         $user->soldebancaire = $user->soldebancaire + $request->montant;
         $user->solde_totale = $user->solde_totale + $request->montant;
         $user->save();
     }
     if ($et->type_dr == "depense" and $et->mode_paiement == "bank") {
         $user->soldebancaire = $user->soldebancaire - $request->montant;
         $user->solde_totale = $user->solde_totale - $request->montant;
         $user->save();
     }
     if ($et->type_dr == "revenue" and $et->mode_paiement == "poche") {
         $user->solde_poche = $user->solde_poche + $request->montant;
         $user->solde_totale = $user->solde_totale + $request->montant;
         $user->save();
     }
     $et->save();
     return redirect('/operations')->with(['etiquette' => Etiquette::all(), 'categorie' => Categorie::all(), 'operations' => Operation::where('user_id', \Auth::user()->id)->with('etiquette', 'categorie')->get()]);
 }