Exemple #1
0
 public function beforeDelete()
 {
     if (parent::beforeDelete()) {
         BudgetHistory::deleteAll(['budget_id' => $this->id]);
         return true;
     } else {
         return false;
     }
 }
 public function searchItems($budget_id, $type, $params)
 {
     $query = BudgetHistory::baseQuery();
     $query->joinWith(['budgetItem']);
     $query->andWhere(['budget_history.budget_id' => $budget_id]);
     $query->andWhere(['budget_item.type_budget_item_id' => $type]);
     $query->orderBy(['date' => SORT_ASC]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     return $dataProvider;
 }
Exemple #3
0
<?php

/**
 * @var \app\models\Budget $budgetModel
 */
?>
<div class="well well-sm">
    <div class="row">
        <div class="col-sm-12">
            <div class="col-sm-4">
                <b>Итого:</b>
            </div>
            <div class="col-sm-6">
                <b><?php 
$total = \app\models\BudgetHistory::getTotalSum($budgetModel->id, $type);
echo $total['RUB'] . ' ₽<br>';
if (isset($total['USD'])) {
    echo $total['USD'] . '  $<br>';
    echo '<small>Сумма в рублях: ' . $total['TOTAL_RUB'] . ' ₽</small>';
}
?>
</b>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12">

            <?php 
if ($budgetModel->costs_limit && isset($total['TOTAL_RUB']) && $total['TOTAL_RUB'] > $budgetModel->costs_limit) {
    echo "<span class='alert-danger'>Превышение лимита расходов на " . ($total['TOTAL_RUB'] - $budgetModel->costs_limit) . " ₽</span>";
Exemple #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBudgetHistories()
 {
     return $this->hasMany(\app\models\BudgetHistory::className(), ['budget_id' => 'id']);
 }
Exemple #5
0
 public static function baseQuery()
 {
     $query = BudgetHistory::find();
     $query->where(['budget_history.user_id' => CurrentUser::getId()]);
     return $query;
 }
 public function actionDeleteHistory($id)
 {
     if (($model = BudgetHistory::findOne($id)) !== null) {
         try {
             $model->delete();
             return $this->redirect(Url::previous());
         } catch (\Exception $e) {
             $msg = isset($e->errorInfo[2]) ? $e->errorInfo[2] : $e->getMessage();
             \Yii::$app->getSession()->setFlash('error', $msg);
             return $this->redirect(Url::previous());
         }
     } else {
         throw new HttpException(404, 'The requested page does not exist.');
     }
 }