Exemple #1
0
 public static function getTotalSum($budget_id, $type)
 {
     $query = self::baseQuery();
     $query->joinWith(['budgetItem']);
     $query->andWhere(['budget_history.budget_id' => $budget_id]);
     $query->andWhere(['budget_item.type_budget_item_id' => $type]);
     $history = $query->all();
     $result = ['RUB' => 0];
     if ($history) {
         $sum = 0;
         $totalRub = 0;
         $totalCurrency = 0;
         foreach ($history as $one) {
             $currency = $one->currency;
             // rub
             if ($currency && (int) $currency->code == 643) {
                 $totalRub += floatval($one->ammount);
                 $result['RUB'] = $totalRub;
             } elseif ($currency) {
                 $totalCurrency += floatval($one->ammount);
                 $result = array_merge($result, [$currency->chCode => $totalCurrency]);
                 $sum += CurrencyConverter::currencyAsRub($currency->id, $one->ammount);
             }
             $result = array_merge($result, ['TOTAL_RUB' => $sum + $totalRub]);
         }
     }
     return $result;
 }
Exemple #2
0
<?php

use yii\helpers\Html;
/**
 * @var \app\models\BudgetHistory $model
 */
?>
<div class="well well-sm">
    <div class="row">
        <div class="col-sm-12">
            <div class="col-sm-4">
                <?php 
if ($rel = $model->getBudgetItem()->one()) {
    echo Html::a($rel->name, ['budget-item/view', 'id' => $rel->id], ['data-pjax' => 0]);
    $relAmmount = \app\components\helpers\CurrencyConverter::currencyAsRub($rel->currency_id, $rel->ammount);
    $modelAmmount = \app\components\helpers\CurrencyConverter::currencyAsRub($model->currency_id, $model->ammount);
    if ($rel->ammount && $modelAmmount > $relAmmount) {
        echo "<br><span class='alert-danger'>Превышение лимита по статье на " . ($modelAmmount - $relAmmount) . " ₽</span>";
    }
} else {
    return '';
}
?>
            </div>
            <div class="col-sm-3">
                <?php 
echo $model->ammount;
?>
                <?php 
echo \app\models\Currency::getSign($model->currency_id);
?>
Exemple #3
0
            </div>
            <div class="col-sm-3">
                <?php 
if ($rel = $historyModel->budgetItem) {
    $class = $rel->type_budget_item_id == 1 ? 'text-success' : 'text-danger';
}
if ($model->currency_id == 1) {
    if ($historyModel->currency_id == 1) {
        echo '<span class="' . $class . '">' . $historyModel->ammount . '</span>';
    } else {
        echo '<span class="' . $class . '">' . CurrencyConverter::currencyAsRub($historyModel->currency_id, $historyModel->ammount) . '</span>';
    }
} else {
    if ($historyModel->currency_id != 1) {
        echo '<span class="' . $class . '">' . $historyModel->ammount . '</span>';
    } else {
        echo '<span class="' . $class . '">' . number_format(CurrencyConverter::rubAsCurrency($model->currency_id, $historyModel->ammount), 2) . '</span>';
    }
}
?>
                <?php 
echo \app\models\Currency::getSign($model->currency_id);
?>
            </div>
            <div class="col-sm-3"><?php 
echo Yii::$app->formatter->asDate($historyModel->date);
?>
</div>
        </div>
    </div>
</div>