From 447471387b26a2ffd20c2ed1fcb51ac86f2a94c0 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 11 Jan 2017 19:24:03 +0200 Subject: [PATCH] -Default statistics done --- controllers/StatisticsController.php | 53 +++++++++++++++++++++++++++++++++++++++-------------- views/statistics/index.php | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- 2 files changed, 167 insertions(+), 43 deletions(-) diff --git a/controllers/StatisticsController.php b/controllers/StatisticsController.php index 0c4cb96..cd991ab 100755 --- a/controllers/StatisticsController.php +++ b/controllers/StatisticsController.php @@ -19,18 +19,18 @@ if (!empty($date_range)) { $arr = []; preg_match('@(.*)\s:\s(.*)@', $date_range, $arr); - $dateFilter = [ - 'between', - 'created_at', - strtotime($arr[1]), - strtotime($arr[2]), - ]; + $dateFilter = [ + 'between', + 'created_at', + strtotime($arr[ 1 ]), + strtotime($arr[ 2 ]), + ]; } else { $dateFilter = []; } if (!empty($label)) { - $labelFilter = ['label' => $label]; + $labelFilter = [ 'label' => $label ]; } else { $labelFilter = []; } @@ -57,20 +57,45 @@ /** * @var Label $model */ - return $model->getStatistics($dateFilter);} + return $model->getStatistics($dateFilter); + } ); - $dataProvider = new ActiveDataProvider([ - 'query' => Order::find()->filterWhere($dateFilter)->andFilterWhere($labelFilter), - ]); + $dataProvider = new ActiveDataProvider( + [ + 'query' => Order::find() + ->filterWhere($dateFilter) + ->andFilterWhere($labelFilter), + ] + ); + $chartData = []; + foreach ($labelStatistics as $statistic) { + $chartData[] = $statistic[ 'sum' ]; + } + $chartLabels = []; + foreach ($labelStatistics as $name => $statistic) { + $chartLabels[] = $name; + } + $labelChartData = [ + 'labels' => $chartLabels, + 'datasets' => [ + [ + 'label' => 'На сумму, грн.', + 'data' => $chartData, + ], + ], + ]; return $this->render( 'index', [ - 'labels' => $labels, - 'labelStatistics' => $labelStatistics, + 'labels' => $labels, + 'labelStatistics' => $labelStatistics, 'rejectionStatistics' => Order::getRejectionStatistics($dateFilter), - 'dataProvider' => $dataProvider, + 'dataProvider' => $dataProvider, + 'labelChartData' => $labelChartData, + 'dateValue' => empty($date_range) ? '' : $date_range, + 'dataLabel' => empty($label) ? false : $label, ] ); } diff --git a/views/statistics/index.php b/views/statistics/index.php index 27dbc71..6b25c1a 100644 --- a/views/statistics/index.php +++ b/views/statistics/index.php @@ -1,19 +1,25 @@ @@ -35,6 +41,7 @@ 'date_range', + 'value' => $dateValue, 'pluginOptions' => [ 'locale' => [ 'format' => 'DD-MM-Y', @@ -48,6 +55,7 @@ 'label', + 'value' => $dataLabel, 'data' => ArrayHelper::map( $labels, function($model) { @@ -60,6 +68,9 @@ 'options' => [ 'placeholder' => 'Все', ], + 'pluginOptions' => [ + 'allowClear' => true, + ], ] ) ?> @@ -94,16 +105,40 @@ $statistic) { - ?> - - - - - - - - + echo Html::tag( + 'tr', + Html::tag('td', $name) . Html::tag('td', $statistic[ 'count' ]) . Html::tag( + 'td', + $statistic[ 'sum' ] + ) . Html::tag('td', $statistic[ 'products' ]) . Html::tag('td', $statistic[ 'unique' ]) + ); + } ?> + + 'bar', + 'options' => [ + 'height' => 200, + 'width' => 600, + ], + 'data' => $labelChartData, + 'clientOptions' => [ + 'title' => [ + 'display' => true, + 'text' => 'Custom Chart Title', + ], + 'scales' => [ + 'xAxes' => [ + [ + 'display' => false, + ], + ], + ], + ], + ] + ); ?> + @@ -123,24 +158,88 @@ $statistic) { - ?> - - - - - - + echo Html::tag( + 'tr', + Html::tag('td', $name) . Html::tag('td', $statistic[ 'count' ]) . Html::tag( + 'td', + $statistic[ 'sum' ] + ) + ); + } + ?> - $dataProvider, - 'columns' => [ - 'id', - 'created_at:datetime', - 'name', - 'city', - + $dataProvider, + 'columns' => [ + 'id', + 'created_at:datetime', + 'name', + 'city', + [ + 'attribute' => 'orderLabel.label', + 'label' => 'Метка', + ], + 'total', + [ + 'attribute' => 'reason', + 'content' => function($model) { + /** + * @var Order $model + */ + if (empty($model->reason)) { + return ''; + } else { + return Order::REASONS[ $model->reason ]; + } + }, + ], + [ + 'attribute' => 'manager.username', + 'label' => 'Менеджер', + ], + [ + 'attribute' => 'body', + 'content' => function($model) { + /** + * @var Order $model + */ + if (empty($model->body)) { + return ''; + } else { + return Html::a( + StringHelper::truncate($model->body, 10, '...'), + '#', + [ + 'data-toggle' => 'tooltip', + 'title' => $model->body, + 'onclick' => 'event.preventDefault();', + ] + ); + } + }, + ], + [ + 'content' => function($model) { + /** + * @var Order $model + */ + return Html::a( + Html::tag('i', '', [ 'class' => 'glyphicon glyphicon-eye-open' ]), + [ + '/ecommerce/order/view', + 'id' => $model->id, ], - ])?> + [ + 'target' => '_blank', + 'data-pjax' => '0', + ] + ); + }, + ], + ], + ] +) ?> -- libgit2 0.21.4