Beispiel #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Income::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, 'cost' => $this->cost, 'money' => $this->money, 'profit' => $this->profit, 'uid' => Yii::$app->user->id]);
     $query->andFilterWhere(['like', 'remark', $this->remark])->andFilterWhere(['like', 'who', $this->who]);
     return $dataProvider;
 }
Beispiel #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIncomes()
 {
     return $this->hasMany(Income::className(), ['type_income_id' => 'id']);
 }
Beispiel #3
0
 /**
  * Finds the Income model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Income the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Income::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIncome()
 {
     return $this->hasOne(Income::className(), ['id' => 'income_id']);
 }
Beispiel #5
0
 /**
  * Приходы
  * @return string
  */
 public function actionIncomes()
 {
     if (Yii::$app->getRequest()->getQueryParam('user')) {
         // $start_day = strtotime('now 00:00:00');
         $user = MarkUser::findOne(Yii::$app->getRequest()->getQueryParam('user'));
         if (!$user) {
             return 'Доступ запрещен!';
         }
         if (Yii::$app->getRequest()->getQueryParam('name') && Yii::$app->getRequest()->getQueryParam('value') !== null) {
             if (Income::find()->where(['name' => Yii::$app->getRequest()->getQueryParam('name')])) {
                 $income = Income::find()->where(['name' => Yii::$app->getRequest()->getQueryParam('name')])->one();
             } else {
                 return 'Ошибка при наборе';
             }
             $act = new DiaryActs();
             $act->model_id = 9;
             $act->user_id = $user->id;
             //return var_dump($act);
             if ($act->save(false)) {
                 $incomes = new Incomes();
                 try {
                     $incomes->income_id = $income->id;
                 } catch (\ErrorException $e) {
                     return 'Такой статьи в базе нет!';
                 }
                 $incomes->act_id = $act->id;
                 $incomes->user_id = $act->user_id;
                 $incomes->money = (double) Yii::$app->getRequest()->getQueryParam('value');
                 if (!$incomes->validate()) {
                     return 'Данные введены некорректно';
                 } else {
                     if ($incomes->save()) {
                         $all_incomes_grouped = Incomes::find()->select(['income_id, COUNT(*) as cnt, SUM(money) as sum '])->groupBy('income_id')->orderBy('sum DESC')->all();
                         //var_dump($all_incomes_grouped);
                         $not_curr_sum = Incomes::find()->select('SUM(money)')->where("income_id  IN (1,2,7,10)")->scalar();
                         $dollar = Incomes::find()->select('SUM(money)')->where("income_id  = 8")->scalar();
                         $euro = Incomes::find()->select('SUM(money)')->where("income_id  = 9")->scalar();
                         $bal_sum = $not_curr_sum + Helper::currencyAdapter($dollar, 11) + Helper::currencyAdapter($euro, 12);
                         return $this->renderPartial('all_incomes', ['user' => $user, 'incomes' => $all_incomes_grouped, 'bal_sum' => $bal_sum]);
                     } else {
                         return 'Ошибка сохранения';
                     }
                 }
             }
         }
         $all_incomes_grouped = Incomes::find()->select(['income_id, COUNT(*) as cnt, SUM(money) as sum '])->groupBy('income_id')->orderBy('sum DESC')->all();
         //var_dump($all_incomes_grouped);
         $not_curr_sum = Incomes::find()->select('SUM(money)')->where("income_id  IN (1,2,7,10)")->scalar();
         $dollar = Incomes::find()->select('SUM(money)')->where("income_id  = 8")->scalar();
         $euro = Incomes::find()->select('SUM(money)')->where("income_id  = 9")->scalar();
         $bal_sum = $not_curr_sum + Helper::currencyAdapter($dollar, 11) + Helper::currencyAdapter($euro, 12);
         //sreturn Helper::currencyAdapter($dollar, 11);
         return $this->renderPartial('income', ['user' => $user, 'incomes' => $all_incomes_grouped, 'bal_sum' => $bal_sum]);
     } else {
         return 'Ошибка';
     }
 }
Beispiel #6
0
 /**
  * добавление нового дохода
  * @return string
  */
 public function actionAdd()
 {
     $errors = [];
     $message = null;
     $user_id = Yii::$app->user->getId();
     $model = new IncomeForm();
     if (Yii::$app->request->isPost) {
         $model->setAttributes(Yii::$app->request->post("IncomeForm"));
         if ($model->datetime) {
             $date = DateComponent::PeopleDateToDate($model->datetime);
             $model->datetime = $date;
         }
         if (!$model->datetime || date("Y-m-d") >= $model->datetime) {
             $purse = Purse::find()->where(['id' => $model->purse_id])->one();
             if ($purse) {
                 if ($model->validate()) {
                     $purse_minus = new Income();
                     $purse_minus->setAttributes($model->getAttributes());
                     $type = $model->getType($user_id);
                     if ($type) {
                         $purse_minus->type_income_id = $type;
                         $save = $purse_minus->save();
                         if ($save) {
                             $purse->balance += $model->money;
                             $purse->save();
                             $message = '<div class="alert alert-success" role="alert">Новый доход добавлен</div>';
                             $model = new IncomeForm();
                         }
                     } else {
                         $errors = $model->getErrors();
                     }
                 } else {
                     $errors = $model->getErrors();
                 }
             }
         } else {
             $message = '<div class="alert alert-danger" role="alert">Дата не должна быть позже сегодняшней</div>';
         }
     }
     $purses = Purse::find()->where(['user_id' => $user_id])->orderBy('active DESC')->all();
     $categories = TypeIncome::find()->where(['user_id' => $user_id])->orderBy('id desc')->all();
     return $this->render('add', ['purses' => $purses, 'categories' => $categories, 'message' => $message, 'model' => $model, 'errors' => $errors]);
 }