use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;
+use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $storeList array */
<?php if (!empty($data)): ?>
<h2>Результаты (Полные данные)</h2>
- <table class="table table-bordered">
- <thead>
- <tr>
- <th>ID товара</th>
- <th>ID чека</th>
- <th>Название</th>
- <th>Себестоимость</th>
- <th>Цена</th>
- <th>Кол-во</th>
- <th>Дата</th>
- </tr>
- </thead>
- <tbody>
- <?php foreach ($data as $item): ?>
- <tr>
- <td><?= Html::encode($item['product_id']) ?></td>
- <td><?= Html::encode($item['check_id']) ?></td>
- <td><?= Html::encode($item['product_name']) ?></td>
- <td><?= Html::encode($item['price']) ?></td>
- <td><?= Html::encode($item['m_price']) ?></td>
- <td><?= Html::encode($item['quantity']) ?></td>
- <td><?= Html::encode($item['date']) ?></td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
+ <?= GridView::widget([
+ 'dataProvider' => new \yii\data\ArrayDataProvider([
+ 'allModels' => $data,
+ 'pagination' => false,
+ ]),
+ 'showFooter' => true,
+ 'columns' => [
+ ['attribute' => 'product_id', 'label' => 'ID товара'],
+ ['attribute' => 'check_id', 'label' => 'ID чека'],
+ ['attribute' => 'product_name', 'label' => 'Название'],
+ ['attribute' => 'm_price', 'label' => 'Цена'],
+ ['attribute' => 'price', 'label' => 'Себестоимость ед'],
+ [
+ 'attribute' => 'quantity',
+ 'label' => 'Кол-во',
+ 'footer' => array_sum(array_column($data, 'quantity')),
+ ],
+ [
+ 'label' => 'Себестоимость итого',
+ 'value' => function ($model) {
+ return $model['price'] * $model['quantity'];
+ },
+ 'footer' => array_sum(array_map(function ($item) {
+ return $item['price'] * $item['quantity'];
+ }, $data)),
+ ],
+ ['attribute' => 'date', 'label' => 'Дата'],
+ ],
+ ]); ?>
+
<h3>Общая стоимость: <?= Html::encode($totalSum) ?></h3>
<h3>Сумма всех товаров: <?= Html::encode($totalProductsSum) ?></h3>
<h2>Результаты (Уникальные товары)</h2>
- <table class="table table-bordered">
- <thead>
- <tr>
- <th>ID товара</th>
- <th>Название</th>
- <th>Цена</th>
- <th>Общее кол-во</th>
- </tr>
- </thead>
- <tbody>
- <?php foreach ($uniqueProductsData as $item): ?>
- <tr>
- <td><?= Html::encode($item['product_id']) ?></td>
- <td><?= Html::encode($item['product_name']) ?></td>
- <td><?= Html::encode($item['price']) ?></td>
- <td><?= Html::encode($item['quantity']) ?></td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
+ <?= GridView::widget([
+ 'dataProvider' => new \yii\data\ArrayDataProvider([
+ 'allModels' => $uniqueProductsData,
+ 'pagination' => false,
+ ]),
+ 'showFooter' => true,
+ 'columns' => [
+ ['attribute' => 'product_id', 'label' => 'ID товара'],
+ ['attribute' => 'product_name', 'label' => 'Название'],
+ ['attribute' => 'price', 'label' => 'Себестоимость ед'],
+ ['attribute' => 'm_price', 'label' => 'Цена ед'],
+ [
+ 'attribute' => 'quantity',
+ 'label' => 'Общее кол-во',
+ 'footer' => array_sum(array_column($uniqueProductsData, 'quantity')),
+ ],
+ [
+ 'label' => 'Себестоимость * Кол-во',
+ 'value' => function ($model) {
+ return $model['price'] * $model['quantity'];
+ },
+ 'footer' => array_sum(array_map(function ($item) {
+ return $item['price'] * $item['quantity'];
+ }, $uniqueProductsData)),
+ ],
+ [
+ 'label' => 'Цена * Кол-во',
+ 'value' => function ($model) {
+ return $model['m_price'] * $model['quantity'];
+ },
+ 'footer' => array_sum(array_map(function ($item) {
+ return $item['m_price'] * $item['quantity'];
+ }, $uniqueProductsData)),
+ ],
+ ],
+ ]); ?>
<?php endif; ?>
</div>
\ No newline at end of file