Skip to content

Commit

Permalink
fix set aggragation calculation of 95 traf (#181)
Browse files Browse the repository at this point in the history
* fix set aggragation calculation of 95 traf

* rename isOveruse95Traf => isServer95Traf

Co-authored-by: Yurii Myronchuk <bladeroot@hiqdev.com>
  • Loading branch information
bladeroot and Yurii Myronchuk committed Sep 21, 2020
1 parent b14a13e commit f7bdb96
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/collections/PricesCollection.php
Expand Up @@ -51,6 +51,30 @@ public function load($data = null)
return parent::load($data);
}

/**
* {@inheritdoc}
*/
public function collectData($attributes = null)
{
$data = [];
foreach ($this->models as $model) {
if ($this->dataCollector instanceof Closure) {
[$key, $row] = call_user_func($this->dataCollector, $model, $this);
} else {
$key = $model->getPrimaryKey();
$row = $model->getAttributes($this->isConsistent() ? $attributes : $model->activeAttributes());
}

if ($key) {
$data[$key] = $row;
} else {
$data[] = $row;
}
}

return $data;
}

private function dataToBeLoadedExistsInPostRequest()
{
$request = Yii::$app->request->post();
Expand Down
5 changes: 5 additions & 0 deletions src/controllers/PriceController.php
Expand Up @@ -100,6 +100,11 @@ public function actions()
'collection' => ['class' => PricesCollection::class],
'success' => Yii::t('hipanel.finance.price', 'Prices were successfully updated'),
'scenario' => 'update',
'on beforeSave' => function (Event $event) {
/** @var \hipanel\actions\Action $action */
$action = $event->sender;
$action->collection->load();
},
'on beforeFetch' => function (Event $event) {
/** @var \hipanel\actions\SearchAction $action */
$action = $event->sender;
Expand Down
5 changes: 4 additions & 1 deletion src/grid/presenters/price/PricePresenter.php
Expand Up @@ -95,10 +95,13 @@ public function renderInfo(Price $price, string $attribute = 'quantity'): string
]);
}
if ($price->isOveruse()) {
return Yii::t('hipanel:finance', '{coins}&nbsp;&nbsp;{amount,number} {unit}', [
return Yii::t('hipanel:finance', '{coins}&nbsp;&nbsp;{amount,number} {unit}{aggregated}', [
'coins' => Html::tag('i', '', ['class' => 'fa fa-money', 'title' => Yii::t('hipanel.finance.price', 'Prepaid amount')]),
'amount' => $price->{$attribute},
'unit' => $price->getUnitLabel(),
'aggregated' => $price->hasAttribute('count_aggregated_traffic') && $price->count_aggregated_traffic
? Html::tag('span', Yii::t('hipanel.finance.price', 'Aggregated'), ['class' => 'label bg-olive pull-right'])
: '',
]);
}

Expand Down
3 changes: 3 additions & 0 deletions src/messages/ru/hipanel.finance.price.php
Expand Up @@ -65,4 +65,7 @@
'Formula usage examples' => 'Примеры использования формул',
'Applicable for overuse prices. The example will compensate up to 5 TB of overuse as discount. Make sure to use appropriate unit, such as <code>items</code>, <code>gbps</code> or <code>hours</code>.' => 'Применим для цен на перебор. Этот пример компенсирует до 5 Тб перебора в виде скидки. Убедитесь, что использете единицу измерения, которая соответствует типу цены, например <code>items</code>, <code>gbps</code> или <code>hours</code>.',
'Applicable for overuse prices. Will compensate up to 5 TB of overuse as a separate Compensation bill. You can use any other bill type in option <code>.as()</code>, such as <code>deposit,creditnote</code> or <code>correction,positive</code>.' => 'Применим для цен на перебор. Этот пример компенсирует до 5 Тб перебора в виде отдельного счёта "Компенсация". Вы можете указывать любой другой тип счёта в опции <code>.as()</code>, например <code>deposit,creditnote</code> или <code>correction,positive</code>.',
'Calculate aggregated traffic' => 'Считать агрегировано траффик',
'(reasonable for grouping tariffs only)' => 'применимо только для группирующих тарифов',
'Aggregated' => 'Агрегирован',
];
12 changes: 12 additions & 0 deletions src/models/OveruseServerPrice.php
Expand Up @@ -9,6 +9,11 @@ class OveruseServerPrice extends Price
{
use ModelTrait;

public static function tableName()
{
return 'price';
}

/**
* @return array
*/
Expand All @@ -29,4 +34,11 @@ public function attributeLabels(): array
'count_aggregated_traffic' => Yii::t('hipanel.finance.price', 'Calculate aggregated traffic'),
]);
}

/** {@inheritdoc} */
public function isServer95Traf()
{
return strpos($this->type, 'overuse,server_traf95_max') === 0;
}

}
5 changes: 5 additions & 0 deletions src/models/Price.php
Expand Up @@ -198,6 +198,11 @@ public function isOveruse()
return strpos($this->type, 'overuse,') === 0;
}

public function isServer95Traf()
{
return false;
}

public function getSubtype()
{
[, $subtype] = explode(',', $this->type);
Expand Down
1 change: 1 addition & 0 deletions src/models/factories/PriceModelFactory.php
Expand Up @@ -37,6 +37,7 @@ class PriceModelFactory
'RatePrice' => RatePrice::class,
'TemplatePrice' => TemplatePrice::class,
'RateTemplatePrice' => TemplatePrice::class,
'OveruseServerPrice' => OveruseServerPrice::class,
'SinglePrice' => [
'domain,*' => DomainZonePrice::class,
'feature,*' => DomainServicePrice::class,
Expand Down
2 changes: 1 addition & 1 deletion src/views/price/formRow/simple.php
Expand Up @@ -110,7 +110,7 @@ function(params) {
<i class="glyphicon glyphicon-minus"></i>
</button>
</div>
<?php if ($model->hasAttribute('count_aggregated_traffic')) : ?>
<?php if ($model->isServer95Traf()) : ?>
<div class="col-md-12 col-md-offset-2" style="margin-top: -1em">
<?= $form->field($model, "[$i]count_aggregated_traffic")->checkbox()->hint(Yii::t('hipanel.finance.price', '(reasonable for grouping tariffs only)')) ?>
</div>
Expand Down

0 comments on commit f7bdb96

Please sign in to comment.