コード例 #1
0
 /**
  * @return array
  */
 public static function getListAccounts()
 {
     $result = [];
     $accounts = Accounts::find()->all();
     if (isset($accounts)) {
         foreach ($accounts as $account) {
             /** @var $account Accounts */
             $result[$account->id] = $account->name . ' (' . $account->valuta . ')';
         }
     }
     return $result;
 }
コード例 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Accounts::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, 'user_id' => $this->user_id, 'sort' => $this->sort, 'amount' => $this->amount, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'color', $this->color]);
     return $dataProvider;
 }
コード例 #3
0
ファイル: EditAction.php プロジェクト: TF03/yii2-advanced-def
 /**
  * Edits an existing Transaction model.
  * If edit is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  * @throws NotFoundHttpException if the model cannot be found
  */
 public function run($id)
 {
     /** @var Transaction $model */
     $model = $this->controller->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $transaction2Category = '';
         if (isset(Yii::$app->request->post('Transaction')['categoryIds'])) {
             $transaction2Category = Yii::$app->request->post('Transaction')['categoryIds'];
         }
         if ($model->save()) {
             if (!empty($transaction2Category)) {
                 TransactionHelper::saveTransaction2Category($transaction2Category, $model->id);
             }
             Yii::$app->getSession()->setFlash('success', 'Транзакция изменена.');
             return $this->controller->redirect(['/transaction']);
         }
     }
     /** @var Accounts $account */
     $account = Accounts::find()->andWhere(['id' => $model->accounts])->one();
     $model->categoryIds = $model->getTransaction2CategoryList();
     return $this->controller->render('_forms/_edit', ['model' => $model, 'account' => $account]);
 }
コード例 #4
0
 /**
  * @param $model \common\models\Transaction
  */
 private function _calculateAccountAmount($model)
 {
     /** @var Accounts $account */
     $account = Accounts::find()->andWhere(['id' => $model->accounts])->one();
     if ($account) {
         if ($model->type_id == TransactionHelper::TYPE_TRANSFER) {
             $params = new stdClass();
             $params->type_id = TransactionHelper::TYPE_EXPENSE;
             $params->accountAmount = $account->amount;
             $params->transactionAmount = $model->total;
             $account->amount = $this->_getAccountAmount($params, true);
             $account->save();
             /** @var Accounts $accountTransfer */
             $accountTransfer = Accounts::find()->andWhere(['id' => $model->accountTransfer])->one();
             $params->type_id = TransactionHelper::TYPE_INCOME;
             $params->accountAmount = $accountTransfer->amount;
             $params->transactionAmount = $model->totalTransfer;
             $accountTransfer->amount = $this->_getAccountAmount($params, true);
             $accountTransfer->save();
         } else {
             $params = new stdClass();
             $params->type_id = $model->type_id;
             $params->accountAmount = $account->amount;
             $params->transactionAmount = $model->total;
             $account->amount = $this->_getAccountAmount($params, true);
             $account->save();
         }
     }
 }
コード例 #5
0
 /**
  * @param $model Transaction
  *
  * @return string
  */
 public static function getFullAmount(Transaction $model)
 {
     $amount = '';
     $currency = '';
     /** @var Accounts $account */
     $account = Accounts::find()->andWhere(['id' => $model->accounts])->one();
     if (isset($account)) {
         $amount = explode('.', $model->total);
         $rest = Html::tag('div', $amount[1], ['class' => 'transaction-currency-rest']);
         $amount = Html::tag('div', $amount[0] . '.' . $rest, ['class' => 'transaction-currency-' . self::getClassesForType($model->type_id)]);
         $currency = Html::tag('div', $account->valuta, ['class' => 'unit']);
     }
     return $amount . $currency;
 }