diff --git a/src/grid/BillGridView.php b/src/grid/BillGridView.php index 3ea7d781..997ba467 100644 --- a/src/grid/BillGridView.php +++ b/src/grid/BillGridView.php @@ -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 { @@ -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(), @@ -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 ? '
' : '') . $tariff; }, ], + 'tariff' => [ + 'attribute' => 'tariff', + ], ]; } } diff --git a/src/models/Bill.php b/src/models/Bill.php index 43bdfe57..8a1a93ba 100644 --- a/src/models/Bill.php +++ b/src/models/Bill.php @@ -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'], ]; } @@ -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'), ]); } } diff --git a/src/views/bill/index.php b/src/views/bill/index.php index 863f908a..05513e5f 100644 --- a/src/views/bill/index.php +++ b/src/views/bill/index.php @@ -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', ], ]) ?> endBulkForm() ?>