/**
  * @param integer $transactionId
  *
  * @return boolean
  */
 public static function deleteTransaction2CategoryByTransactionId($transactionId)
 {
     return Transaction2Category::deleteAll('transaction_id = :transaction_id', [':transaction_id' => $transactionId]);
 }
 /**
  *
  */
 public function deleteTransaction2Category()
 {
     /** @var \common\models\Category $model */
     $model = $this->owner;
     Transaction2Category::deleteAll(['category_id' => $model->id]);
 }
 /**
  * @param Query $query
  * @param array $params
  * @return Query
  */
 protected function additionalFilter($query, $params)
 {
     if (!isset($params['sort'])) {
         $query->orderBy(['date' => SORT_DESC, 'created_at' => SORT_DESC, 'id' => SORT_DESC]);
     } else {
         switch ($params['sort']) {
             case 'total':
                 $query->orderBy(['type_id' => SORT_DESC, 'total' => SORT_ASC]);
                 break;
             case '-total':
                 $query->orderBy(['type_id' => SORT_ASC, 'total' => SORT_DESC]);
                 break;
         }
     }
     $period = Yii::$app->request->get('period');
     if (isset($period)) {
         switch ($period) {
             case 'today':
                 $today = Yii::$app->getFormatter()->asDate('now', "php:Y-m-d");
                 $query->andFilterWhere(['like', 'date', $today]);
                 break;
             case 'yesterday':
                 $yesterday = date('Y-m-d', strtotime(date('Y-m-d') . " - 1 day"));
                 $query->andFilterWhere(['like', 'date', $yesterday]);
                 break;
             case 'current_month':
                 $query = $this->setDefaultPeriod($query);
                 break;
             case 'all':
                 break;
             default:
                 $query = $this->setDefaultPeriod($query);
                 break;
         }
     } else {
         $query = $this->setDefaultPeriod($query);
     }
     if (isset($params['category'])) {
         $query->leftJoin(Transaction2Category::tableName(), 'transaction_id = id');
         $query->andWhere(['transaction2category.category_id' => $params['category']]);
     }
     return $query;
 }