Skip to content

Commit

Permalink
greatly improved Bill index page
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Sep 23, 2015
1 parent 046d239 commit d0b12d1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
53 changes: 46 additions & 7 deletions src/grid/BillGridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace hipanel\modules\finance\grid;

use hipanel\widgets\ArraySpoiler;
use Yii;
use yii\helpers\Html;

class BillGridView extends \hipanel\grid\BoxedGridView
{
Expand All @@ -24,20 +26,48 @@ public static function defaultColumns()
'filterAttribute' => 'bill_like',
],
'time' => [
'format' => 'date',
'filter' => false,
'format' => 'html',
'filter' => false,
'contentOptions' => ['class' => 'text-nowrap'],
'value' => function ($model) {
list($date, $time) = explode(' ',$model->time,2);
return $time=='00:00:00' ? Yii::$app->formatter->asDate($date) : Yii::$app->formatter->asDateTime($model->time);
},
],
'sum' => [
'class' => 'hipanel\grid\CurrencyColumn',
'attribute' => 'sum',
'nameAttribute' => 'sum',
'class' => 'hipanel\grid\CurrencyColumn',
'attribute' => 'sum',
'colors' => ['danger' => 'warning'],
'nameAttribute' => 'sum',
'headerOptions' => ['class' => 'text-right'],
'contentOptions' => function ($model) {
return ['class' => 'text-right' . ($model->sum>0 ? ' text-bold' : '')];
}
],
'balance' => [
'class' => 'hipanel\grid\CurrencyColumn',
'class' => 'hipanel\grid\CurrencyColumn',
'headerOptions' => ['class' => 'text-right'],
'contentOptions' => function ($model, $key, $index) {
return ['class' => 'text-right' . ($index ? '' : ' text-bold')];
}
],
'gtype' => [
'attribute' => 'gtype',
],
'type_label' => [
'attribute' => 'type_label',
'headerOptions' => ['class' => 'text-right'],
'filterOptions' => ['class' => 'text-right'],
'contentOptions' => function ($model) {
static $colors = [
'correction' => 'normal',
'exchange' => 'warning',
'deposit' => 'success',
];
$color = $colors[$model->gtype] ?: 'muted';
return ['class' => "text-right text-bold text-$color"];
},
],
/* XXX didn't find Description column or widget
'descriptionOld' => [
'class' => Description::className(),
Expand All @@ -57,9 +87,18 @@ public static function defaultColumns()
'attribute' => 'descr',
'format' => 'raw',
'value' => function ($model) {
return strpos($model->descr, ',')===false ? $model->descr : ArraySpoiler::widget(['data' => $model->descr]);
$qty = $model->type=='support_time' ? Yii::t('app', '{0, time, HH:mm}', ceil($model->quantity * 3600)) :
( $model->type=='ip_num' ? $model->quantity : '');
$qty = $qty ? Html::tag('b', $qty . ' - ', ['class' => 'text-primary']) : '';
$descr = $model->descr ?: $model->label;
$text = mb_strlen($descr)>70 ? ArraySpoiler::widget(['data' => $descr]) : $descr;
$tariff = $model->tariff ? Html::tag('b', Yii::t('app', 'Tariff')) . ': ' . $model->tariff : '';
return $qty . $text . ($text && $tariff ? '<br>' : '') . $tariff;
},
],
'tariff' => [
'attribute' => 'tariff',
],
];
}
}
8 changes: 5 additions & 3 deletions src/models/Bill.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ public function rules()
[['domain', 'server'], 'safe'],
[['time'], 'date'],
[['sum', 'balance', 'quantity'], 'number'],
[['currency', 'label', 'type'], 'safe'],
[['gtype', 'descr','type_label'], 'safe'],
[['currency', 'label', 'descr'], 'safe'],
[['object', 'domains', 'tariff'], 'safe'],
[['type', 'gtype'], 'safe'],
[['type_label', 'gtype_label'], 'safe'],

];
}
Expand All @@ -44,7 +45,8 @@ public function rules()
public function attributeLabels()
{
return $this->mergeAttributeLabels([
'gtype' => Yii::t('app', 'Type'),
'gtype' => Yii::t('app', 'Type'),
'gtype_label' => Yii::t('app', 'Type'),
]);
}
}
5 changes: 2 additions & 3 deletions src/views/bill/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@
'dataProvider' => $dataProvider,
'filterModel' => $model,
'columns' => [
'checkbox',
'seller_id', 'client_id',
'time', 'sum', 'balance', 'gtype', 'description',
'checkbox', 'client_id', 'time', 'sum', 'balance',
'type_label', 'description',
],
]) ?>
<?php $box->endBulkForm() ?>

0 comments on commit d0b12d1

Please sign in to comment.